pax_global_header00006660000000000000000000000064150731001740014510gustar00rootroot0000000000000052 comment=84b999ae88813b49911ded99c1d7aa0991e3c18a documentdb-0.108-0/000077500000000000000000000000001507310017400140015ustar00rootroot00000000000000documentdb-0.108-0/.devcontainer/000077500000000000000000000000001507310017400165405ustar00rootroot00000000000000documentdb-0.108-0/.devcontainer/Dockerfile000066400000000000000000000111201507310017400205250ustar00rootroot00000000000000FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04 ARG POSTGRES_INSTALL_ARG= ARG PG_VERSION=16 ARG CITUS_VERSION=12 # declare installed PG version and Citus version ENV PG_VERSION=${PG_VERSION} ENV CITUS_VERSION=${CITUS_VERSION} # Install build essentials - Compiler, debugger, make, etc. RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get install -qy \ wget \ curl \ sudo \ gnupg2 \ lsb-release \ tzdata \ build-essential \ pkg-config \ cmake \ git \ locales \ gcc \ gdb \ libipc-run-perl \ unzip \ apt-transport-https \ bison \ flex \ libreadline-dev \ zlib1g-dev \ libkrb5-dev \ software-properties-common \ libtool \ libicu-dev \ libssl-dev \ && rm -rf /var/lib/apt/lists/* # Add pgdg repo RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \ apt-get update && \ rm -rf /var/lib/apt/lists/* # Prepare for running install scripts ENV CLEANUP_SETUP=1 ENV INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup RUN mkdir -p /tmp/install_setup # Copy setup_versions.sh which decides versions of the dependencies to install. COPY scripts/setup_versions.sh /tmp/install_setup/ # Install libbson COPY scripts/install_setup_libbson.sh /tmp/install_setup RUN [ "bin/bash", "-c", "export MAKE_PROGRAM=cmake && /tmp/install_setup/install_setup_libbson.sh" ] # Copy utils.sh COPY scripts/utils.sh /tmp/install_setup/ # Install postgres COPY scripts/install_setup_postgres.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_postgres.sh -d \"/usr/lib/postgresql/${PG_VERSION}\" $POSTGRES_INSTALL_ARG -v ${PG_VERSION}" ] # Install RUM from source COPY scripts/install_setup_rum_oss.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_rum_oss.sh" ] # Install citus COPY scripts/install_setup_citus_core_oss.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_citus_core_oss.sh ${CITUS_VERSION}" ] # Install citus-indent COPY scripts/install_citus_indent.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_citus_indent.sh" ] # Install SYSTEM_ROWS COPY scripts/install_setup_system_rows.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_system_rows.sh" ] # Install PG_CRON COPY scripts/install_setup_pg_cron.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pg_cron.sh" ] # Download Decimal128 Intel library COPY scripts/install_setup_intel_decimal_math_lib.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_intel_decimal_math_lib.sh" ] # Download PCRE2 library COPY scripts/install_setup_pcre2.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_pcre2.sh" ] # Install PG_VECTOR COPY scripts/install_setup_pgvector.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pgvector.sh" ] # Install PostGIS from source RUN apt-get update && \ apt-get install -qy \ libproj-dev \ libxml2-dev \ libjson-c-dev \ libgeos++-dev \ libgeos-dev \ && rm -rf /var/lib/apt/lists/* COPY scripts/install_setup_postgis.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_postgis.sh" ] # locale RUN rm -rf /var/lib/apt/lists/* \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 ENV LANGUAGE en_US # Create documentdb user RUN useradd -ms /bin/bash documentdb -G sudo RUN echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/no-pass-ask # Add postgres to path for sudo commands. # Add path for sudoers RUN cat /etc/sudoers | grep secure_path | sed "s/\:\/bin\:/\:\/bin\:\/usr\/lib\/postgresql\/$PG_VERSION\/bin\:/" >> /etc/sudoers.d/postgres_path # Add PG to the path ENV PATH=$PATH:/usr/lib/postgresql/$PG_VERSION/bin # Install Rust toolchain COPY scripts/install_rustup.sh /tmp/install_setup/ COPY rust-toolchain.toml /tmp/install_setup/ ENV RUSTUP_HOME=/home/documentdb/.rustup \ CARGO_HOME=/home/documentdb/.cargo \ PATH=/home/documentdb/.cargo/bin:$PATH RUN [ "bin/bash", "-c", "/tmp/install_setup/install_rustup.sh" ] RUN chown -R documentdb:documentdb /home/documentdb/.cargo /home/documentdb/.rustup USER documentdb WORKDIR /home/documentdb documentdb-0.108-0/.devcontainer/devcontainer.json000066400000000000000000000043651507310017400221240ustar00rootroot00000000000000{ "build": { "dockerfile": "Dockerfile", "context": "..", "args": { // To include debug symbols for postgres, add -x "POSTGRES_INSTALL_ARG": "-c", "PG_VERSION": "16", "CITUS_VERSION": "v12.1" } }, "customizations": { "vscode": { "extensions": [ "ms-vscode.cpptools", "ms-vscode.cpptools-extension-pack", "rust-lang.rust-analyzer" ], "settings": { "rust-analyzer.linkedProjects": [ "pg_documentdb_gw/Cargo.toml", "pg_documentdb_gw_host/Cargo.toml" ], "rust-analyzer.testExplorer": true, // Performance: use a separate Cargo target directory for rust-analyzer and ad-hoc commands. // This minimizes filesystem locking when executing cargo commands in parallel to VS Code. "rust-analyzer.cargo.targetDir": true, // Code style: use `crate` instead of `super` for rust-analyzer generated imports. "rust-analyzer.imports.prefix": "crate", // Rust-analyzer default behavior skips checking/building some parts of the Rust codebase. // This makes it check and build everything, which can help discover issues sooner, instead of // only in the pull request validation build. It does make the checking/building slower, though. "rust-analyzer.cargo.allTargets": true, "rust-analyzer.check.allTargets": true, // Code style: automatically format Rust code on save to save manual labor. "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer", "editor.formatOnSave": true } } } }, "forwardPorts": [ 9712, 10260 ], "portsAttributes": { "9712": { "label": "PostgresPort", "onAutoForward": "notify", "requireLocalPort": false }, "10260": { "label": "GatewayPort", "onAutoForward": "notify", "requireLocalPort": false } } }documentdb-0.108-0/.gitattributes000066400000000000000000000003041507310017400166710ustar00rootroot00000000000000# all C files (implementation and header) use our style... *.[ch] citus-style pg_documentdb/src/roaring_bitmaps/*.[ch] -citus-style * text=auto *.sh text eol=lf *.md text eol=lf *.sql text eol=lfdocumentdb-0.108-0/.github/000077500000000000000000000000001507310017400153415ustar00rootroot00000000000000documentdb-0.108-0/.github/ISSUE_TEMPLATE/000077500000000000000000000000001507310017400175245ustar00rootroot00000000000000documentdb-0.108-0/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000010771507310017400222230ustar00rootroot00000000000000--- name: Bug report about: Create a report to help us improve title: '' labels: bug, new assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **Environment** - Operating system and version - PostgreSQL version - Architecture **Reproduction Steps** Steps to reproduce the behavior: A code snipped or accessible repository that can reproduce the issue. **Expected behavior** A clear and concise description of what you expected to happen. **Actual behavior** **Additional context** Add any other context about the problem here. documentdb-0.108-0/.github/ISSUE_TEMPLATE/feature_request.md000066400000000000000000000011151507310017400232470ustar00rootroot00000000000000--- name: Feature request about: Suggest an idea for this project title: "[Feature Request]" labels: enhancement assignees: '' --- **Purpose of the feature.** A clear and concise description of the problem space that will be addressed by this feature. **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Description of few scenarios that will help test and validate this feature. documentdb-0.108-0/.github/containers/000077500000000000000000000000001507310017400175065ustar00rootroot00000000000000documentdb-0.108-0/.github/containers/Build-Ubuntu/000077500000000000000000000000001507310017400220255ustar00rootroot00000000000000documentdb-0.108-0/.github/containers/Build-Ubuntu/Dockerfile000066400000000000000000000106611507310017400240230ustar00rootroot00000000000000FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04 ARG POSTGRES_INSTALL_ARG= ARG PG_VERSION=16 ARG CITUS_VERSION=12 # declare installed PG version and Citus version ENV PG_VERSION=${PG_VERSION} ENV CITUS_VERSION=${CITUS_VERSION} # Install build essentials - Compiler, debugger, make, etc. RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get install -qy \ wget \ curl \ sudo \ gnupg2 \ lsb-release \ tzdata \ build-essential \ pkg-config \ cmake \ git \ locales \ gcc \ gdb \ libipc-run-perl \ unzip \ apt-transport-https \ bison \ flex \ libreadline-dev \ zlib1g-dev \ libkrb5-dev \ software-properties-common \ libtool \ libicu-dev \ libssl-dev \ && rm -rf /var/lib/apt/lists/* # Add pgdg repo RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \ apt-get update && \ rm -rf /var/lib/apt/lists/* # Prepare for running install scripts ENV CLEANUP_SETUP=1 ENV INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup RUN mkdir -p /tmp/install_setup # Copy setup_versions.sh which decides versions of the dependencies to install. COPY scripts/setup_versions.sh /tmp/install_setup/ # Install libbson COPY scripts/install_setup_libbson.sh /tmp/install_setup RUN [ "bin/bash", "-c", "export MAKE_PROGRAM=cmake && /tmp/install_setup/install_setup_libbson.sh" ] # Copy utils.sh COPY scripts/utils.sh /tmp/install_setup/ # Install postgres COPY scripts/install_setup_postgres.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_postgres.sh -d \"/usr/lib/postgresql/${PG_VERSION}\" $POSTGRES_INSTALL_ARG -v ${PG_VERSION}" ] # Install RUM from source COPY scripts/install_setup_rum_oss.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_rum_oss.sh" ] # Install citus COPY scripts/install_setup_citus_core_oss.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_citus_core_oss.sh ${CITUS_VERSION}" ] # Install citus-indent COPY scripts/install_citus_indent.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_citus_indent.sh" ] # Install SYSTEM_ROWS COPY scripts/install_setup_system_rows.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_system_rows.sh" ] # Install PG_CRON COPY scripts/install_setup_pg_cron.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pg_cron.sh" ] # Download Decimal128 Intel library COPY scripts/install_setup_intel_decimal_math_lib.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_intel_decimal_math_lib.sh" ] # Download PCRE2 library COPY scripts/install_setup_pcre2.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_pcre2.sh" ] # Install PG_VECTOR COPY scripts/install_setup_pgvector.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pgvector.sh" ] # Install PostGIS from source RUN add-apt-repository -y ppa:ubuntugis/ppa && apt-get update && \ apt-get install -qy \ libproj-dev \ libxml2-dev \ libjson-c-dev \ libgeos-dev \ libgeos++-dev \ && rm -rf /var/lib/apt/lists/* COPY scripts/install_setup_postgis.sh /tmp/install_setup/ RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_postgis.sh" ] # locale RUN rm -rf /var/lib/apt/lists/* \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 ENV LANGUAGE en_US # Create documentdb user RUN useradd -ms /bin/bash documentdb -G sudo RUN echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/no-pass-ask # Add postgres to path for sudo commands. # Add path for sudoers RUN cat /etc/sudoers | grep secure_path | sed "s/\:\/bin\:/\:\/bin\:\/usr\/lib\/postgresql\/$PG_VERSION\/bin\:/" >> /etc/sudoers.d/postgres_path # Add PG to the path ENV PATH=$PATH:/usr/lib/postgresql/$PG_VERSION/bin USER documentdb WORKDIR /home/documentdb LABEL org.opencontainers.image.source=https://github.com/microsoft/documentdb LABEL org.opencontainers.image.description="DocumentDB ubuntu build image" LABEL org.opencontainers.image.licenses=MITdocumentdb-0.108-0/.github/containers/Build-Ubuntu/Dockerfile_gateway000066400000000000000000000062161507310017400255450ustar00rootroot00000000000000# Define a build argument to choose architecture ARG BASE_ARCH=AMD64 ARG BASE_VERSION=0.104.0 # Define the base image dynamically FROM ghcr.io/microsoft/documentdb/documentdb-oss:ubuntu22.04-PG17-${BASE_ARCH}-${BASE_VERSION} AS stage # Install dependencies RUN sudo apt-get update && \ sudo apt-get install -y --no-install-recommends \ jq curl sudo git make build-essential openssl pkg-config libssl-dev \ && sudo rm -rf /var/lib/apt/lists/* USER documentdb WORKDIR /home/documentdb/code COPY . /home/documentdb/code RUN sudo chown -R documentdb:documentdb /home/documentdb/code # Install rustup (which includes rustc and cargo) in user directory ENV RUSTUP_HOME=/home/documentdb/.rustup \ CARGO_HOME=/home/documentdb/.cargo \ PATH=/home/documentdb/.cargo/bin:$PATH RUN . /home/documentdb/code/scripts/install_rustup.sh RUN rustc --version && cargo --version WORKDIR /home/documentdb/code/pg_documentdb_gw # Compile the code RUN cargo build --profile=release-with-symbols #------------------------------------------------------------------------------------------------ # Same logic for the final image ARG BASE_ARCH=AMD64 ARG BASE_VERSION=0.104.0 FROM ghcr.io/microsoft/documentdb/documentdb-oss:ubuntu22.04-PG17-${BASE_ARCH}-${BASE_VERSION} AS final # Set postgres user and group to desired UID/GID RUN sudo groupmod -g 103 postgres && sudo usermod -u 105 -g 103 postgres RUN sudo apt-get update && \ sudo apt-get install -y --no-install-recommends \ jq openssl lsof && \ sudo apt-get upgrade -y && \ sudo rm -rf /var/lib/apt/lists/* ENV LANGUAGE=en_US.UTF-8 \ TERM=xterm-256color ENV CERT_PATH="" \ KEY_FILE="" \ DATA_PATH="/data" \ DOCUMENTDB_PORT="10260" \ ENABLE_TELEMETRY="false" \ LOG_LEVEL="info" \ USERNAME="default_user" \ CREATE_USER="true" \ START_POSTGRESQL="true" \ POSTGRESQL_PORT="9712" \ OWNER="documentdb" \ ALLOW_EXTERNAL_CONNECTIONS="false" \ PATH=/usr/lib/postgresql/16/bin:$PATH RUN sudo mkdir /home/documentdb/gateway COPY --from=stage /home/documentdb/code/pg_documentdb_gw/target/release-with-symbols/documentdb_gateway \ /home/documentdb/gateway/pg_documentdb_gw/target/release-with-symbols/documentdb_gateway COPY --from=stage /home/documentdb/code/pg_documentdb_gw/SetupConfiguration.json /home/documentdb/gateway/pg_documentdb_gw/SetupConfiguration.json COPY --from=stage /home/documentdb/code/scripts/start_oss_server.sh /home/documentdb/gateway/scripts/start_oss_server.sh COPY --from=stage /home/documentdb/code/scripts/build_and_start_gateway.sh /home/documentdb/gateway/scripts/build_and_start_gateway.sh COPY --from=stage /home/documentdb/code/scripts/emulator_entrypoint.sh /home/documentdb/gateway/scripts/emulator_entrypoint.sh COPY --from=stage /home/documentdb/code/scripts/utils.sh /home/documentdb/gateway/scripts/utils.sh COPY --from=stage /home/documentdb/code/scripts/setup_psqlrc.sh /home/documentdb/gateway/scripts/setup_psqlrc.sh RUN sudo chown -R documentdb:documentdb /home/documentdb/gateway WORKDIR /home/documentdb/gateway/scripts ENTRYPOINT ["/bin/bash", "-c", "/home/documentdb/gateway/scripts/emulator_entrypoint.sh \"$@\"", "--"] documentdb-0.108-0/.github/containers/Build-Ubuntu/Dockerfile_prebuild000066400000000000000000000033361507310017400257120ustar00rootroot00000000000000ARG BASE_IMAGE=ubuntu:22.04 FROM ${BASE_IMAGE} ARG DEBIAN_FRONTEND=noninteractive ARG POSTGRES_VERSION=16 ARG DEB_PACKAGE_REL_PATH=packages/postgresql-16-documentdb-1_1.0.0_amd64.deb RUN apt-get update RUN apt-get install -y --no-install-recommends \ wget \ gnupg2 \ lsb-release \ ca-certificates \ locales \ sudo \ && rm -rf /var/lib/apt/lists/* RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 ENV LANGUAGE=en_US ENV LC_COLLATE=en_US.UTF-8 ENV LC_CTYPE=en_US.UTF-8 ENV LANG=en_US.UTF-8 RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main ${POSTGRES_VERSION}" > /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ && rm -rf /var/lib/apt/lists/* # actual dependencies of the package RUN apt-get update && apt-get install -y \ postgresql-${POSTGRES_VERSION} \ postgresql-${POSTGRES_VERSION}-cron \ postgresql-${POSTGRES_VERSION}-pgvector \ postgresql-${POSTGRES_VERSION}-postgis-3 \ postgresql-${POSTGRES_VERSION}-rum \ && rm -rf /var/lib/apt/lists/* WORKDIR /scripts COPY scripts/start_oss_server.sh /scripts/ COPY scripts/utils.sh /scripts/ COPY scripts/setup_psqlrc.sh /scripts/ RUN mkdir -p /tmp/install_setup COPY ${DEB_PACKAGE_REL_PATH} /tmp/install_setup/ RUN dpkg -i /tmp/install_setup/$(basename "$DEB_PACKAGE_REL_PATH") # Create documentdb user RUN useradd -ms /bin/bash documentdb -G sudo RUN echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/no-pass-ask USER documentdb ENV PG_VERSION_USED=${POSTGRES_VERSION} ENTRYPOINT ["/bin/bash", "-c", "/scripts/start_oss_server.sh \"$@\" & tail -f /dev/null", "--"] documentdb-0.108-0/.github/containers/Build-Ubuntu/PrebuildImageList.md000066400000000000000000000052461507310017400257230ustar00rootroot00000000000000# Documentdb Prebuild Docker Images List ## v0.103.0 ### Ubuntu 22.04 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG17-AMD64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 17 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:5c7765af1ac51ff894e2795d5ee8c6bcca7ea90159d38c40b1c164feef18037d - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG17-ARM64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 17 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:98d8abfb65f8dbb23dcd87d819496af0c9955c0234ff542ff18c16a294d6478f - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 16 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:e0f2b7c9115bec5692679fe3afe2eaf1dc268db14282585cc7bae047cd50325c - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-ARM64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 16 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:62e2b4c2f39de9e81c432a889d4268cfc1c335cbe4878517ee0760ea33739477 ### Ubuntu 24.04 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG17-AMD64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 17 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:a6f72e31c9d9b39a7ac201ac41f6d77b439e048d892f6edddcb4b06774cc6292 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG17-ARM64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 17 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:621eb5f5ea380d152a254a2f2d35e169c3ae217cb940f6090fbb07040dcd2c67 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG16-AMD64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 16 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:dc4f0155e545ae14bcf65d31d4b9d21c8fdfee42d467f3419106ced8e141a6bd - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG16-ARM64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 16 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:162df47ba5e8b10f88d7bd0e2e7c5775e764774928920ea532c372c5ee360b24 ## Notes - Ensure each image meets your environment requirements and compatibility needs. - Refer to the official documentation for setup instructions and best practices. documentdb-0.108-0/.github/containers/Build-Ubuntu/README.md000066400000000000000000000011721507310017400233050ustar00rootroot00000000000000# To Build Ubuntu prebuild image E.g. to build for Ubuntu 22.04, PostgreSQL 16, amd64 and documentdb_0.103.0, run: ```sh docker build -t -f .github/containers/Build-Ubuntu/Dockerfile_prebuild \ --platform=linux/amd64 --build-arg BASE_IMAGE=ubuntu:22.04 --build-arg POSTGRES_VERSION=16 \ --build-arg DEB_PACKAGE_REL_PATH=packaging/packages/ubuntu22.04-postgresql-16-documentdb_0.103.0_amd64.deb . ``` ## To use the image Step 1: Running the container in detached mode ```sh docker run -dt docker exec -it bash ``` Step 2: Connect to psql shell ```sh psql -p 9712 -d postgres ``` documentdb-0.108-0/.github/workflows/000077500000000000000000000000001507310017400173765ustar00rootroot00000000000000documentdb-0.108-0/.github/workflows/build_deb_packages.yml000066400000000000000000000126041507310017400236730ustar00rootroot00000000000000name: Build deb packages and prebuild images concurrency: group: build-packages-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true on: workflow_dispatch: push: branches: - 'main' - 'release/**' paths-ignore: - 'docs/**' - '.devcontainer/**' - '*.md' pull_request: types: [opened, reopened, synchronize, ready_for_review] permissions: packages: write contents: read id-token: write jobs: build-deb-packages: runs-on: ${{ matrix.runner }} name: Deb packages for ${{ matrix.os }}-${{ matrix.arch }}-pg${{ matrix.pg_version }} if: github.event.pull_request.draft == false strategy: fail-fast: false matrix: os: ${{ fromJson(github.event_name == 'pull_request' && '["ubuntu22.04"]' || '["deb11","deb12","deb13","ubuntu22.04","ubuntu24.04"]') }} arch: [amd64, arm64] include: - arch: amd64 runner: ubuntu-24.04 - arch: arm64 runner: ubuntu-24.04-arm pg_version: ${{ fromJson(github.event_name == 'pull_request' && '["17"]' || '["16","17"]') }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Extract and Format Default Version id: extract_version run: | DOCUMENTDB_VERSION=$(grep -E "^default_version" pg_documentdb_core/documentdb_core.control | sed -E "s/.*'([0-9]+\.[0-9]+-[0-9]+)'.*/\1/") DOCUMENTDB_VERSION=$(echo $DOCUMENTDB_VERSION | sed "s/-/./g") echo "Extracted Version: $DOCUMENTDB_VERSION" echo "DOCUMENTDB_VERSION=$DOCUMENTDB_VERSION" >> $GITHUB_ENV - name: Build Debian Package run: | ./packaging/build_packages.sh --os ${{ matrix.os }} --pg ${{ matrix.pg_version }} --version ${{ env.DOCUMENTDB_VERSION }} - name: Upload Debian Package as Artifact uses: actions/upload-artifact@v4 with: name: archive-${{ matrix.os }}-${{ matrix.arch }}-pg${{ matrix.pg_version }}-documentdb-${{ env.DOCUMENTDB_VERSION }} path: | packaging/*.deb retention-days: 7 if-no-files-found: error compression-level: 0 - name: Login to GHCR if: startsWith(github.ref, 'refs/tags/') uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up QEMU if: startsWith(github.ref, 'refs/tags/') uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx if: startsWith(github.ref, 'refs/tags/') uses: docker/setup-buildx-action@v3 - name: Extract image build metadata if: startsWith(github.ref, 'refs/tags/') id: image_metadata run: | PACKAGE_NAME=$(ls packaging/*.deb | grep -v dbgsym | head -n1) echo "PACKAGE NAME: $PACKAGE_NAME" echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV case ${{ matrix.os }} in deb11) BASE_IMAGE="debian:bullseye" ;; deb12) BASE_IMAGE="debian:bookworm" ;; ubuntu22.04) BASE_IMAGE="ubuntu:22.04" ;; ubuntu24.04) BASE_IMAGE="ubuntu:24.04" ;; esac echo "BASE_IMAGE NAME: $BASE_IMAGE" echo "BASE_IMAGE=$BASE_IMAGE" >> $GITHUB_ENV - name: Build and Push Docker Image if: startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v6.18.0 env: DOCKER_BUILD_SUMMARY: false with: provenance: false # Disable provenance to avoid unknown/unknown sbom: false # Disable provenance to avoid unknown/unknown context: . push: true platforms: linux/${{ matrix.arch }} file: .github/containers/Build-Ubuntu/Dockerfile_prebuild tags: ghcr.io/${{ github.repository }}/documentdb-oss:PG${{ matrix.pg_version }}-${{ matrix.arch }}-${{ env.DOCUMENTDB_VERSION }} build-args: | BASE_IMAGE=${{ env.BASE_IMAGE }} POSTGRES_VERSION=${{ matrix.pg_version }} DEB_PACKAGE_REL_PATH=${{ env.PACKAGE_NAME }} labels: | org.opencontainers.image.source=https://github.com/microsoft/documentdb org.opencontainers.image.description=Documentdb prebuild image org.opencontainers.image.licenses=MIT - name: Install cosign if: startsWith(github.ref, 'refs/tags/') uses: sigstore/cosign-installer@main - name: Sign manifest (keyless) if: startsWith(github.ref, 'refs/tags/') run: | cosign sign ghcr.io/${{ github.repository }}/documentdb-oss:PG${{ matrix.pg_version }}-${{ matrix.arch }}-${{ env.DOCUMENTDB_VERSION }} -y - name: Verify manifest signature (keyless) if: startsWith(github.ref, 'refs/tags/') run: | run: | cosign verify \ --certificate-identity-regexp "https://github.com/${{ github.repository }}/.github/workflows/build_packages.yml@refs/(heads|tags)/${{ github.ref_name }}" \ --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ ghcr.io/${{ github.repository }}/documentdb-oss:PG${{ matrix.pg_version }}-${{ matrix.arch }}-${{ env.DOCUMENTDB_VERSION }}documentdb-0.108-0/.github/workflows/build_gateway.yml000066400000000000000000000071311507310017400227430ustar00rootroot00000000000000name: Gateway Image - Build and Push to GHCR (Native AMD64 and ARM64) on: workflow_dispatch: inputs: manifest_tag: description: 'Tag for the Docker manifest' required: false base_version: description: 'Base version for the Docker image' required: false push: branches: - 'main' paths-ignore: - '*.md' permissions: packages: write contents: read id-token: write env: DEFAULT_BASE_VERSION: '0.104.0' DEFAULT_MANIFEST_TAG: 'test' IMAGE_NAME: documentdb-local IMAGE_TAG: ${{ github.run_id }}-$(date +'%Y-%m-%d') jobs: build-and-push: name: Build and Push Images strategy: matrix: arch: [amd64, arm64] include: - arch: amd64 base_arch: AMD64 runner: ubuntu-22.04 - arch: arm64 base_arch: ARM64 runner: ubuntu-22.04-arm runs-on: ${{ matrix.runner }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Set Default Values run: | echo "BASE_VERSION=${{ github.event.inputs.base_version || env.DEFAULT_BASE_VERSION }}" >> $GITHUB_ENV - name: Login to GHCR run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - name: Build and Push ${{ matrix.arch }} Image run: | TAG=${{ env.IMAGE_TAG }}-${{ matrix.arch }} docker build \ --build-arg BASE_ARCH=${{ matrix.base_arch }} \ --build-arg BASE_VERSION=${{ env.BASE_VERSION }} \ -t ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:$TAG \ -f .github/containers/Build-Ubuntu/Dockerfile_gateway . docker push ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:$TAG create-manifest: name: Create, Push, Sign & Verify Manifest runs-on: ubuntu-22.04 needs: build-and-push steps: - name: Login to GHCR run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - name: Set Default Values run: | echo "MANIFEST_TAG=${{ github.event.inputs.manifest_tag || env.DEFAULT_MANIFEST_TAG }}" >> $GITHUB_ENV - name: Create and Push Manifest run: | docker manifest create ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.MANIFEST_TAG }} \ --amend ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}-amd64 \ --amend ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}-arm64 docker manifest push ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.MANIFEST_TAG }} - name: Install cosign uses: sigstore/cosign-installer@main - name: Sign manifest (keyless) run: | DIGEST=$(docker buildx imagetools inspect ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.MANIFEST_TAG }} \ | awk '/^Digest:/ { print $2 }') echo "Signing manifest-list@${DIGEST}" cosign sign ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}@${DIGEST} -y - name: Verify manifest signature (keyless) run: | DIGEST=$(docker buildx imagetools inspect ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ env.MANIFEST_TAG }} \ | awk '/^Digest:/ { print $2 }') cosign verify \ --certificate-identity-regexp "https://github.com/${{ github.repository }}/.github/workflows/build_gateway.yml@refs/heads/${{ github.ref_name }}" \ --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}@${DIGEST}documentdb-0.108-0/.github/workflows/build_rpm_packages.yml000066400000000000000000000040541507310017400237370ustar00rootroot00000000000000name: Build rpm packages concurrency: group: build-rpm-packages-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true on: workflow_dispatch: push: branches: - 'main' - 'release/**' paths-ignore: - 'docs/**' - '.devcontainer/**' - '*.md' pull_request: types: [opened, reopened, synchronize, ready_for_review] jobs: build-rpm-packages: runs-on: ${{ matrix.runner }} name: RPM packages for ${{ matrix.os }}-${{ matrix.arch }}-pg${{ matrix.pg_version }} if: github.event.pull_request.draft == false strategy: fail-fast: false matrix: os: ${{ fromJson(github.event_name == 'pull_request' && '["rhel9"]' || '["rhel8","rhel9"]') }} arch: [amd64, arm64] include: - arch: amd64 runner: ubuntu-24.04 - arch: arm64 runner: ubuntu-24.04-arm pg_version: ${{ fromJson(github.event_name == 'pull_request' && '["17"]' || '["16","17"]') }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Extract and Format Default Version id: extract_version run: | DOCUMENTDB_VERSION=$(grep -E "^default_version" pg_documentdb_core/documentdb_core.control | sed -E "s/.*'([0-9]+\.[0-9]+-[0-9]+)'.*/\1/") DOCUMENTDB_VERSION=$(echo $DOCUMENTDB_VERSION | sed "s/-/./g") echo "Extracted Version: $DOCUMENTDB_VERSION" echo "DOCUMENTDB_VERSION=$DOCUMENTDB_VERSION" >> $GITHUB_ENV - name: Build RPM Package run: | ./packaging/build_packages.sh --os ${{ matrix.os }} --pg ${{ matrix.pg_version }} --version ${{ env.DOCUMENTDB_VERSION }} --test-clean-install - name: Upload RPM Package as Artifact uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}-${{ matrix.arch }}-pg${{ matrix.pg_version }}-documentdb-${{ env.DOCUMENTDB_VERSION }} path: | packaging/*.rpm retention-days: 7 if-no-files-found: error compression-level: 0documentdb-0.108-0/.github/workflows/codeql.yml000066400000000000000000000043041507310017400213710ustar00rootroot00000000000000name: "CodeQL" on: schedule: - cron: '59 23 * * 6' workflow_dispatch: jobs: analyze: name: Analyze runs-on: ubuntu-22.04 permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'c-cpp', 'python' ] steps: - name: Checkout repository uses: actions/checkout@v3 - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Install package dependencies run: | # Create the file repository configuration: sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main 16" > /etc/apt/sources.list.d/pgdg.list' # Import the repository signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get install -y --no-install-recommends \ wget \ curl \ sudo \ gnupg2 \ lsb-release \ tzdata \ build-essential \ pkg-config \ cmake \ git \ postgresql-16 \ postgresql-server-dev-16 \ libpq-dev \ libicu-dev \ libkrb5-dev \ postgresql-16-cron \ postgresql-16-pgvector \ postgresql-16-postgis-3 \ postgresql-16-rum export CLEAN_SETUP=1 export INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup mkdir -p /tmp/install_setup cp ./scripts/* /tmp/install_setup sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT MAKE_PROGRAM=cmake /tmp/install_setup/install_setup_libbson.sh sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_setup_pcre2.sh sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_setup_intel_decimal_math_lib.sh sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_citus_indent.sh - name: Configure, Build and Install DocumentDB run: | make sudo make install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3documentdb-0.108-0/.github/workflows/deploy_docs.yml000066400000000000000000000005021507310017400224220ustar00rootroot00000000000000name: Deploy MkDocs on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: 3.x - run: pip install mkdocs mkdocs-material - run: mkdocs gh-deploy --clean --forcedocumentdb-0.108-0/.github/workflows/regress_tests.yml000066400000000000000000000032211507310017400230130ustar00rootroot00000000000000name: DocumentDB sql tests run-name: ${{ github.event.pull_request.title || '' }} concurrency: group: sql-tests-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true on: workflow_dispatch: push: branches: - 'main' paths-ignore: - 'docs/**' - '.devcontainer/**' - '*.md' pull_request: types: [opened, reopened, synchronize, ready_for_review] paths-ignore: - 'docs/**' - '.devcontainer/**' - '*.md' jobs: test-pr: if: github.event_name == 'pull_request' && github.event.pull_request.draft == false strategy: fail-fast: false matrix: include: - pg_version: 15 arch: amd64 runner: ubuntu-22.04 - pg_version: 16 arch: arm64 runner: ubuntu-22.04-arm - pg_version: 17 arch: amd64 runner: ubuntu-22.04 uses: ./.github/workflows/regress_tests_template.yml with: pg_version: ${{ matrix.pg_version }} arch: ${{ matrix.arch }} runner: ${{ matrix.runner }} citus_version: 12 test-full: if: github.event_name != 'pull_request' strategy: fail-fast: false matrix: pg_version: - 15 - 16 - 17 arch: - amd64 - arm64 include: - arch: amd64 runner: ubuntu-22.04 - arch: arm64 runner: ubuntu-22.04-arm uses: ./.github/workflows/regress_tests_template.yml with: pg_version: ${{ matrix.pg_version }} arch: ${{ matrix.arch }} runner: ${{ matrix.runner }} citus_version: 12 documentdb-0.108-0/.github/workflows/regress_tests_template.yml000066400000000000000000000124421507310017400247130ustar00rootroot00000000000000name: Reusable SQL Tests on: workflow_call: inputs: pg_version: required: true type: number arch: required: true type: string runner: required: true type: string citus_version: required: true type: number jobs: test: runs-on: ${{ inputs.runner }} name: Run sql tests on ${{ inputs.runner }} with pg ${{ inputs.pg_version }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Install package dependencies run: | export PG_VERSION=${{ inputs.pg_version }} export CITUS_VERSION=${{ inputs.citus_version }} export LC_ALL=en_US.UTF-8 export LANGUAGE=en_US export LC_COLLATE=en_US.UTF-8 export LC_CTYPE=en_US.UTF-8 # Import the repository signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get install -y --no-install-recommends \ wget \ curl \ sudo \ gnupg2 \ lsb-release \ tzdata \ build-essential \ pkg-config \ cmake \ git \ locales \ gcc \ gdb \ libipc-run-perl \ unzip \ apt-transport-https \ bison \ flex \ libreadline-dev \ zlib1g-dev \ libkrb5-dev \ software-properties-common \ libtool \ libicu-dev \ libssl-dev export CLEAN_SETUP=1 export INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup mkdir -p /tmp/install_setup # Install dependencies cp ./scripts/setup_versions.sh /tmp/install_setup cp ./scripts/install_setup_libbson.sh /tmp/install_setup sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT MAKE_PROGRAM=cmake /tmp/install_setup/install_setup_libbson.sh cp ./scripts/utils.sh /tmp/install_setup cp ./scripts/install_setup_postgres.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_setup_postgres.sh -d /usr/lib/postgresql/${PG_VERSION} $POSTGRES_INSTALL_ARG -v ${PG_VERSION} cp ./scripts/install_setup_rum_oss.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_rum_oss.sh cp ./scripts/install_setup_citus_core_oss.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_citus_core_oss.sh ${CITUS_VERSION} cp ./scripts/install_citus_indent.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_citus_indent.sh cp ./scripts/install_setup_system_rows.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_system_rows.sh cp ./scripts/install_setup_pg_cron.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pg_cron.sh cp ./scripts/install_setup_intel_decimal_math_lib.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_setup_intel_decimal_math_lib.sh cp ./scripts/install_setup_pcre2.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT /tmp/install_setup/install_setup_pcre2.sh cp ./scripts/install_setup_pgvector.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pgvector.sh sudo apt-get update sudo apt-get install -qy \ libproj-dev \ libxml2-dev \ libjson-c-dev \ libgdal-dev \ libgeos++-dev \ libgeos-dev \ cp ./scripts/install_setup_postgis.sh /tmp/install_setup/ sudo INSTALL_DEPENDENCIES_ROOT=$INSTALL_DEPENDENCIES_ROOT PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_postgis.sh - name: Export pg_config PATH run: | echo "/usr/lib/postgresql/${{ inputs.pg_version }}/bin" >> $GITHUB_PATH - name: Configure, Build and Install DocumentDB run: | which pg_config make sudo PATH=$PATH make install - name: Run Tests run: | which pg_config export LC_ALL=en_US.UTF-8 export LANGUAGE=en_US export LC_COLLATE=en_US.UTF-8 export LC_CTYPE=en_US.UTF-8 make check - name: Citus Indent run: | citus_indent --check || (echo ""; echo "citus_indent failed, refer to CONTRIBUTING.md on how to use citus_indent"; exit 1) - name: Validate sanity of files run: | ./scripts/validate_extension_file_state.sh - name: Upload Log Files if: always() uses: actions/upload-artifact@v4 with: name: logs_${{ inputs.runner }}_PG${{ inputs.pg_version }} overwrite: true path: "**/*.log" documentdb-0.108-0/.github/workflows/release_gateway.yml000066400000000000000000000020011507310017400232530ustar00rootroot00000000000000name: Release Gateway on: workflow_dispatch: inputs: source_tag: description: 'Tag in your repo to copy (default: test)' required: true default: 'test' target_tag: description: 'Target tag to apply (default: latest)' required: false default: 'latest' permissions: contents: read packages: write env: REPO_NAME: documentdb-local jobs: copy-and-push-manifest: runs-on: ubuntu-latest steps: - name: Login to GHCR run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - name: Retag existing manifest env: SOURCE_TAG: ${{ github.event.inputs.source_tag }} TARGET_TAG: ${{ github.event.inputs.target_tag }} run: | docker buildx imagetools create \ -t ghcr.io/${{ github.repository }}/${{ env.REPO_NAME }}:${{ env.TARGET_TAG }} \ ghcr.io/${{ github.repository }}/${{ env.REPO_NAME }}:${{ env.SOURCE_TAG }} documentdb-0.108-0/.gitignore000077500000000000000000000014541507310017400160000ustar00rootroot00000000000000# Prerequisites *.d # Object files *.o *.ko *.obj *.elf # Linker output *.ilk *.map *.exp # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo *.bc # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd .tmp_versions/ modules.order Module.symvers Mkfile.old dkms.conf .deps/ build/ # vscode/VS .vscode/* !.vscode/tasks.json .vs/ *.sln # Ignore devcontainer by default. If needed changes can be made by # doing a git add -f .devcontainer/* # txt files *.txt # temp schedules *.tmp # packages *.deb *.rpm site/ # Generated by Cargo # will have compiled files and executables target/ # These are backup files generated by rustfmt **/*.rs.bkdocumentdb-0.108-0/.pipelines/000077500000000000000000000000001507310017400160475ustar00rootroot00000000000000documentdb-0.108-0/.pipelines/documentdb-oss-sync.yml000066400000000000000000000026421507310017400224760ustar00rootroot00000000000000trigger: branches: include: - "main" paths: exclude: - ".github/*" batch: true pool: vmImage: 'windows-2022' variables: tempBranchName: 'temp-branch-for-sync-pipeline' branchName: $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')] steps: - checkout: self persistCredentials: true - powershell: | $ErrorActionPreference = 'Stop' git remote add azure-devops https://$(System.AccessToken)@$(INTERNAL_REPO_URL) git fetch azure-devops | Out-Null git checkout -b $(tempBranchName) Write-Host "Pushing Branch $(branchName) ..." $branchExists = git ls-remote --heads azure-devops $(branchName) if (-not $branchExists) { Write-Host "Branch $(branchName) does not exist in Azure DevOps. Creating it ..." git push -u azure-devops $(tempBranchName):$(branchName) } elseif ("$(branchName)" -eq "main") { Write-Host "Branch $(branchName) is main. Pushing to main ..." git push azure-devops $(tempBranchName):$(branchName) } else { Write-Host "Branch $(branchName) exists in Azure DevOps. Forcing push ..." git push -f azure-devops $(tempBranchName):$(branchName) } displayName: 'Push to Azure DevOps' - task: PoliCheck@2 inputs: targetType: 'F' targetArgument: '$(Build.SourcesDirectory)' result: 'PolicheckOutput' optionsFC: '1' optionsXS: '1' documentdb-0.108-0/.pipelines/static-checks-win.yml000066400000000000000000000005141507310017400221120ustar00rootroot00000000000000trigger: branches: include: - "main" batch: true pr: branches: include: - "main" pool: vmImage: 'windows-2022' steps: - checkout: self - task: PoliCheck@2 inputs: targetType: 'F' targetArgument: '$(Build.SourcesDirectory)' result: 'PolicheckOutput' optionsFC: '1' optionsXS: '1' documentdb-0.108-0/.vscode/000077500000000000000000000000001507310017400153425ustar00rootroot00000000000000documentdb-0.108-0/.vscode/tasks.json000066400000000000000000000005731507310017400173670ustar00rootroot00000000000000{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "Citus Indent", "problemMatcher": [ ], "type": "process", "command": "citus_indent", "args": [ ], "group": "build" } ] }documentdb-0.108-0/CHANGELOG.md000066400000000000000000000141541507310017400156170ustar00rootroot00000000000000### documentdb v0.108-0 (Unreleased) ### * Top-level `let` variables and `$$NOW` supported by default. * Fix collation support on find and aggregation when variableSpec is not available *[Bugfix]*. * Support `dropRole` command *[Feature]* * Support `rolesInfo` command *[Feature]* * Fix concurrent upsert behavior, update the documents in case of conflicts during insert *[Bugfix]* (#295). * Support collation with `$sortArray` aggregation operator *[Feature]* * Add support for keyword `required` in `$jsonSchema` * Fix a segmentation fault when using ordered aggregate such as `$last` with `$setWindowFields` aggregation stage. *[Bugfix]* * Fix crash when building lookup pipeline queries from nested pipelines and $group aggregates *[Bugfix]* * Add basic support for compiling with pg18 *[Feature]* * Drop unused environment variable `ENFORCE_SSL` in dockerfile *[Bugfix]* (#313) * Remove the explicit dependency on the RUM extension (it's now implicit on the .so file). Flip to documentdb_extended_rum for PG18+ *[Feature]* * Use the appropriate GUC for the user_crud_commands.sql *[Bugfix]* (#319) * Provide Rust dev environment in devcontainer *[Feature]* * Add extension that adds a gateway host that's run as a postgres background worker *[Feature]* ### documentdb v0.107-0 (Unreleased) ### * Support sort by _id against the _id index using the enableIndexOrderbyPushdown flag *[Feature]*. * Improvements to explain for various scan types *[Feature]*. * Support schema enforcement with CSFLE integration *[Preview]* * Validate $jsonSchema syntax during rule creation or modification(schema validation) *[Preview]* ### documentdb v0.106-0 (August 29, 2025) ### * Add internal extension that provides extensions to the `rum` index. *[Feature]* * Enable let support for update queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Enable let support for findAndModify queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Add internal extension that provides extensions to the `rum` index. *[Feature]* * Optimized query for `usersInfo` command. * Support collation with `delete` *[Feature]*. Requires `EnableCollation` to be `on`. * Support for index hints for find/aggregate/count/distinct *[Feature]* * Support `createRole` command *[Feature]* * Add schema changes for Role CRUD APIs *[Feature]* * Add support for using EntraId tokens via Plain Auth ### documentdb v0.105-0 (July 28, 2025) ### * Support `$bucketAuto` aggregation stage, with granularity types: `POWERSOF2`, `1-2-5`, `R5`, `R10`, `R20`, `R40`, `R80`, `E6`, `E12`, `E24`, `E48`, `E96`, `E192` *[Feature]* * Support `conectionStatus` command *[Feature]*. ### documentdb v0.104-0 (June 09, 2025) ### * Add string case support for `$toDate` operator * Support `sort` with collation in runtime*[Feature]* * Support collation with `$indexOfArray` aggregation operator. *[Feature]* * Support collation with arrays and objects comparisons *[Feature]* * Support background index builds *[Bugfix]* (#36) * Enable user CRUD by default *[Feature]* * Enable let support for delete queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Enable rum_enable_index_scan as default on *[Perf]* * Add public `documentdb-local` Docker image with gateway to GHCR * Support `compact` command *[Feature]*. Requires `documentdb.enablecompact` GUC to be `on`. * Enable role privileges for `usersInfo` command *[Feature]* ### documentdb v0.103-0 (May 09, 2025) ### * Support collation with aggregation and find on sharded collections *[Feature]* * Support `$convert` on `binData` to `binData`, `string` to `binData` and `binData` to `string` (except with `format: auto`) *[Feature]* * Fix list_databases for databases with size > 2 GB *[Bugfix]* (#119) * Support half-precision vector indexing, vectors can have up to 4,000 dimensions *[Feature]* * Support ARM64 architecture when building docker container *[Preview]* * Support collation with `$documents` and `$replaceWith` stage of the aggregation pipeline *[Feature]* * Push pg_documentdb_gw for documentdb connections *[Feature]* ### documentdb v0.102-0 (March 26, 2025) ### * Support index pushdown for vector search queries *[Bugfix]* * Support exact search for vector search queries *[Feature]* * Inline $match with let in $lookup pipelines as JOIN Filter *[Perf]* * Support TTL indexes *[Bugfix]* (#34) * Support joining between postgres and documentdb tables *[Feature]* (#61) * Support current_op command *[Feature]* (#59) * Support for list_databases command *[Feature]* (#45) * Disable analyze statistics for unique index uuid columns which improves resource usage *[Perf]* * Support collation with `$expr`, `$in`, `$cmp`, `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte` comparison operators (Opt-in) *[Feature]* * Support collation in `find`, aggregation `$project`, `$redact`, `$set`, `$addFields`, `$replaceRoot` stages (Opt-in) *[Feature]* * Support collation with `$setEquals`, `$setUnion`, `$setIntersection`, `$setDifference`, `$setIsSubset` in the aggregation pipeline (Opt-in) *[Feature]* * Support unique index truncation by default with new operator class *[Feature]* * Top level aggregate command `let` variables support for `$geoNear` stage *[Feature]* * Enable Backend Command support for Statement Timeout *[Feature]* * Support type aggregation operator `$toUUID`. *[Feature]* * Support Partial filter pushdown for `$in` predicates *[Perf]* * Support the $dateFromString operator with full functionality *[Feature]* * Support extended syntax for `$getField` aggregation operator. Now the value of 'field' could be an expression that resolves to a string. *[Feature]* ### documentdb v0.101-0 (February 12, 2025) ### * Push $graphlookup recursive CTE JOIN filters to index *[Perf]* * Build pg_documentdb for PostgreSQL 17 *[Infra]* (#13) * Enable support of currentOp aggregation stage, along with collstats, dbstats, and indexStats *[Commands]* (#52) * Allow inlining $unwind with $lookup with `preserveNullAndEmptyArrays` *[Perf]* * Skip loading documents if group expression is constant *[Perf]* * Fix Merge stage not outputing to target collection *[Bugfix]* (#20) ### documentdb v0.100-0 (January 23rd, 2025) ### Initial Release documentdb-0.108-0/CODEOWNERS000066400000000000000000000007351507310017400154010ustar00rootroot00000000000000* @documentdb/documentdb-maintainers /.pipelines/ @safern @visridha @shuaitian-git @lichoil /.github/workflows/ @safern @visridha @shuaitian-git @lichoil /packaging/ @shuaitian-git @lichoil @fatmelon *.csv @documentdb/documentdb-maintainers *.sql @documentdb/documentdb-maintainers Make* @documentdb/documentdb-maintainers /internal/ @documentdb/documentdb-maintainers /pg_documentdb/ @documentdb/documentdb-maintainers /pg_documentdb_core/ @documentdb/documentdb-maintainersdocumentdb-0.108-0/CODE_OF_CONDUCT.md000066400000000000000000000077661507310017400166200ustar00rootroot00000000000000# Code of Conduct **Effective: September 14, 2017** LF Projects, LLC ("LF Projects") supports and hosts open source and open standards projects (each a "Project") and undertakes such other activities as approved by The Linux Foundation. LF Projects, LLC is a Delaware series limited liability company. Projects of LF Projects are formed as separate series of LF Projects (each, a "Series"). References to "Projects" within this Policy include the applicable Series for each Project. ## Our Pledge LF Projects hosts communities where participants choose to work together, and in that process experience differences in language, location, nationality, and experience. In such a diverse environment, misunderstandings and disagreements happen, which in most cases can be resolved informally. In rare cases, however, behavior can intimidate, harass, or otherwise disrupt one or more people in the community, which LF Projects will not tolerate. A Code of Conduct ("Code") is useful to define accepted and acceptable behaviors and to promote high standards of professional practice. It also provides a benchmark for self-evaluation and acts as a vehicle for better identity of the organization. ## Scope This Code applies to any participant of any Project – including without limitation developers, participants in meetings, teleconferences, mailing lists, conferences or functions, and contributors. Note that this Code complements rather than replaces legal rights and obligations pertaining to any particular situation. In addition, with the approval of LF Projects, Projects are free to adopt their own code of conduct in place of the Code. ## Our Standards LF Projects is committed to maintain a positive, professional work environment. This commitment calls for workplaces where participants at all levels behave according to the rules of the following code. A foundational concept of this code is that we all share responsibility for our work environment. **We expect participants to:** - Treat each other with respect, professionalism, fairness, and sensitivity to our many differences and strengths, including in situations of high pressure and urgency. - Never engage in any form of harassment, including but not limited to: - **Harassment** is any conduct, verbal or physical, that has the intent or effect of interfering with an individual, or that creates an intimidating, hostile, or offensive environment. - **Sexual harassment** includes visual displays of degrading sexual images, sexually suggestive conduct, offensive remarks of a sexual nature, requests for sexual favors, unwelcome physical contact, and sexual assault. ## Who This Applies To Anyone from the Public partaking in the LF Projects work environment (e.g. contribute code, comment on our code or specs, email us, attend our conferences, functions, etc.) ## Our Commitment **Respect** is the genuine consideration you have for someone (if only because of their status as participant in LF Projects, like yourself), and that you show by treating them in a polite and kind way. **Summary:** if you are unsure whether something might be welcome or unwelcome, don't do it. ## Reporting To report incidents or to appeal reports of incidents, send email to the Manager of LF Projects, Mike Dolan ([manager@lfprojects.org](mailto:manager@lfprojects.org)). Please include any available relevant information, including links to any publicly accessible material relating to the matter. Every effort will be taken to ensure a safe and collegial environment in which to collaborate on matters relating to the Project. In order to protect the community, the Project reserves the right to take appropriate action, potentially including the removal of an individual from any and all participation in the project. The Project will work towards an equitable resolution in the event of a misunderstanding. ## Attribution This code is based on the W3C's Code of Ethics and Professional Conduct with some additions from the Cloud Foundry's Code of Conduct and the Hyperledger Project Code of Conduct. documentdb-0.108-0/CONTRIBUTING.md000066400000000000000000000072031507310017400162340ustar00rootroot00000000000000# Contributing to DocumentDB Thank you for your interest in contributing to DocumentDB. There are several ways through which contributions to the project can be made and you can get involved. ## Asking Questions [Join us on Discord](https://discord.gg/vH7bYu524D) to engage directly with our team and the community with any questions you may have. Our channel is not only a place for immediate assistance but also a hub for discussing project updates, upcoming features, and technical challenges. We host regular meetings where TSC members and contributors can interact directly to ask questions, share feedback, and discuss their ideas in real time. ## Reporting Issues Before a new issue is created for a bug or feature request, please check the list of open issues to avoid multiple issues being created for the same bug or feature. If one already exists, add a reaction and relevant comments for additional clarity if needed. ## How to Contribute We encourage community members to participate by reporting issues, suggesting new features, or contributing code. ### 1. General Contributions The more descriptive the issue is and the more information that can be provided, the more helpful it will be to the community and the contributors to pick up the issue. For each issue created, please include: - A brief description of the suggestion or issue. - Relevant details such as the operating system you were using, if applicable. - Clear, step-by-step instructions or context that describe how the issue occurred or how the feature would function. - The expected outcome versus the actual result or behavior observed, if relevant. ### Code Contributions For those looking to contribute code, whether for bug fixes or new features, please ensure your issues and pull requests include the following: - A code snippet that reliably reproduces the issue or demonstrates the new feature. - An accessible repository link that can be cloned, built, and run, providing a complete environment for testing and verifying the issue or feature. - Clear documentation or comments in the code explaining the changes made and their purpose. ## Pull Requests We want to ensure all contributions made by the developer community are correctly licensed. To achieve this, DocumentDB uses a Developer Certificate of Origin (DCO). The DCO is a declaration attached to each commit to the project. A message that simply adds a Signed-off-by statement to every commit to DocumentDB is all that is needed and this confirms that the committer agrees to the DCO, which can be located at https://developercertificate.org/. DocumentDB requires every contribution to be signed with a DCO through a known identity. Anonymous names or pseudonyms cannot be used. An example of a DCO signed commit message is: ```bash Commit message Signed-off-by: John Doe ``` Git includes a `-s` command line option to append this line automatically to your commit message (provided you have configured your `user.name` and `user.email` in your git configuration): ```bash git commit -s -m 'Commit message' ``` Commits of any form require a DCO, including revert commits. ## Technical Steering Committee and Maintainers DocumentDB is governed by the Technical Steering Committee, where all decisions are conducted in the open, documented, and voted upon. All code that is checked in is managed by the Maintainers. The list of TSC members and the project's maintainers are listed in the [MAINTAINERS.md](./MAINTAINERS.md) file. ## Discussion Etiquette To provide all members of the community with a safe space for contributions and discussions, we request that comments always be courteous and respectful of others. documentdb-0.108-0/GOVERNANCE.md000066400000000000000000000270031507310017400157540ustar00rootroot00000000000000# Technical Charter (the "Charter") ## for DocumentDB a Series of LF Projects, LLC **Adopted August 21, 2025** This Charter sets forth the responsibilities and procedures for technical contribution to, and oversight of, the DocumentDB open source project, which has been established as DocumentDB a Series of LF Projects, LLC (the "Project"). LF Projects, LLC ("LF Projects") is a Delaware series limited liability company. All contributors (including committers, maintainers, and other technical positions) and other participants in the Project (collectively, "Collaborators") must comply with the terms of this Charter. ## 1. Mission and Scope of the Project a. The mission of the Project is to offer a native implementation of a document-oriented NoSQL database. b. The scope of the Project includes collaborative development under the Project License (as defined herein) supporting the mission, including documentation, testing, integration and the creation of other artifacts that aid the development, deployment, operation or adoption of the open source project. c. This project will base its work on official Postgres versions distributed by the PostgreSQL Community Association of Canada. d. This project has the goal of enabling compatibility with the MongoDB open source drivers, and extending that functionality to the PostgreSQL ecosystem. ## 2. Technical Steering Committee a. The Technical Steering Committee (the "TSC") will be responsible for all technical oversight of the open source Project. b. **Composition.** i. **"Startup Period"**. The voting members of the TSC at the inception of the project (the "Start Date") will be those individuals named in the "MAINTAINERS" file within the Project's code repository. ii. **"Steady State"**. Prior to the date that is 9 months (or such other date as determined by the TSC) from the Start Date, the TSC will determine an alternate structure for TSC composition which will be documented in the "MAINTAINERS" file. iii. At any time the TSC may choose an alternative approach for determining the voting members of the TSC, and any such alternative approach will be documented in the MAINTAINERS file. c. Any meetings of the Technical Steering Committee are intended to be open to the public, and can be conducted electronically, via teleconference, or in person. d. TSC projects generally will involve Contributors and Maintainers. The TSC may adopt or modify roles so long as the roles are documented in the MAINTAINERS file. Unless otherwise documented: i. Contributors include anyone in the technical community that contributes code, documentation, or other technical artifacts to the Project; ii. Maintainers are Contributors who have earned the ability to modify ("commit") source code, documentation or other technical artifacts in a project's repository; and iii. A Contributor may become a Maintainer by a majority approval of the TSC. A Maintainer may be removed by a majority approval of the TSCs. e. Participation in the Project through becoming a Contributor and Maintainer is open to anyone so long as they abide by the terms of this Charter. f. The TSC may (1) establish work flow procedures for the submission, approval, and closure/archiving of projects, (2) set requirements for the promotion of Contributors to Maintainer status, as applicable, and (3) amend, adjust, refine and/or eliminate the roles of Contributors, and Maintainer, and create new roles, and publicly document any TSC roles, as it sees fit. g. The TSC may elect a TSC Chair, who will preside over meetings of the TSC and will serve until their resignation or replacement by the TSC. **Responsibilities:** The TSC will be responsible for all aspects of oversight relating to the Project, which may include: i. coordinating the technical direction of the Project; ii. approving project or system proposals (including, but not limited to, incubation, deprecation, and changes to a sub-project's scope); iii. organizing sub-projects and removing sub-projects; iv. creating sub-committees or working groups to focus on cross-project technical issues and requirements; v. appointing representatives to work with other open source or open standards communities; vi. establishing community norms, workflows, issuing releases, and security issue reporting policies; vii. approving and implementing policies and processes for contributing (to be published in the CONTRIBUTING file) and coordinating with the series manager of the Project (as provided for in the Series Agreement, the "Series Manager") to resolve matters or concerns that may arise as set forth in Section 7 of this Charter; viii. discussions, seeking consensus, and where necessary, voting on technical matters relating to the code base that affect multiple projects; and ix. coordinating any marketing, events, or communications regarding the Project. ## 3. TSC Voting a. While the Project aims to operate as a consensus-based community, if any TSC decision requires a vote to move the Project forward, the voting members of the TSC will vote on a one vote per voting member basis. b. Quorum for TSC meetings requires at least fifty percent of all voting members of the TSC to be present. The TSC may continue to meet if quorum is not met but will be prevented from making any decisions at the meeting. c. Except as provided in Section 7.c. and 8.a, decisions by vote at a meeting require a majority vote of those in attendance, provided quorum is met. Decisions made by electronic vote without a meeting require a majority vote of all voting members of the TSC. d. In the event a vote cannot be resolved by the TSC, any voting member of the TSC may refer the matter to the Series Manager for assistance in reaching a resolution. ## 4. Compliance with Policies a. This Charter is subject to the Series Agreement for the Project and the Operating Agreement of LF Projects. Contributors will comply with the policies of LF Projects as may be adopted and amended by LF Projects, including, without limitation the policies listed at https://lfprojects.org/policies/. b. The TSC may adopt a code of conduct ("CoC") for the Project, which is subject to approval by the Series Manager. In the event that a Project-specific CoC has not been approved, the LF Projects Code of Conduct listed at https://lfprojects.org/policies will apply for all Collaborators in the Project. c. The TSC has adopted a Trademark Policy ("Trademark Policy") for the Project available in the Project's GitHub repository, which supplements the LF Trademark Policy listed at https://lfprojects.org/policies. d. When amending or adopting any policy applicable to the Project, LF Projects will publish such policy, as to be amended or adopted, on its web site at least 30 days prior to such policy taking effect; provided, however, that in the case of any amendment of the Trademark Policy or Terms of Use of LF Projects, any such amendment is effective upon publication on LF Project's web site. e. All Collaborators must allow open participation from any individual or organization meeting the requirements for contributing under this Charter and any policies adopted for all Collaborators by the TSC, regardless of competitive interests. Put another way, the Project community must not seek to exclude any participant based on any criteria, requirement, or reason other than those that are reasonable and applied on a non-discriminatory basis to all Collaborators in the Project community. f. The Project will operate in a transparent, open, collaborative, and ethical manner at all times. The output of all Project discussions, proposals, timelines, decisions, and status should be made open and easily visible to all. Any potential violations of this requirement should be reported immediately to the Series Manager. ## 5. Community Assets a. LF Projects (or an associated hosting entity) will hold title to all trade or service marks used by the Project ("Project Trademarks"), whether based on common law or registered rights. Project Trademarks will be transferred and assigned to LF Projects (or, where applicable, the associated hosting entity) to hold on behalf of the Project. Any use of any Project Trademarks by Collaborators in the Project will (a) either be (i) in a way that constitutes fair use or (ii) in accordance with the license from LF Projects to the Project and the applicable trademark usage guidelines and (b) inure to the benefit of LF Projects (or the associated hosting entity). b. The Project will, as permitted and in accordance with such license from LF Projects, develop and own all Project GitHub and social media accounts, and domain name registrations created by the Project community. c. Under no circumstances will LF Projects be expected or required to undertake any action on behalf of the Project that is inconsistent with the tax-exempt status or purpose, as applicable, of the Joint Development Foundation or LF Projects, LLC. ## 6. General Rules and Operations a. The Project will: i. engage in the work of the Project in a professional manner consistent with maintaining a cohesive community, while also maintaining the goodwill and esteem of LF Projects, Joint Development Foundation and other partner organizations in the open source community; and ii. respect the rights of all trademark owners, including any branding and trademark usage guidelines. ## 7. Intellectual Property Policy a. Collaborators acknowledge that the copyright in all new contributions will be retained by the copyright holder as independent works of authorship and that no contributor or copyright holder will be required to assign copyrights to the Project. b. Except as described in Section 7.c., all contributions to the Project are subject to the following: i. All new inbound code contributions to the Project must be made using MIT License available at https://opensource.org/licenses/MIT (the "Project License"). ii. All new inbound code contributions must also be accompanied by a Developer Certificate of Origin (http://developercertificate.org) sign-off in the source code system that is submitted through a TSC-approved contribution process which will bind the authorized contributor and, if not self-employed, their employer to the applicable license; iii. All outbound code will be made available under the Project License. iv. Documentation will be received and made available by the Project under the Creative Commons Attribution 4.0 International License (available at http://creativecommons.org/licenses/by/4.0/). v. The Project may seek to integrate and contribute back to other open source projects ("Upstream Projects"). In such cases, the Project will conform to all license requirements of the Upstream Projects, including dependencies, leveraged by the Project. Upstream Project code contributions not stored within the Project's main code repository will comply with the contribution process and license terms for the applicable Upstream Project. c. The TSC may approve the use of an alternative license or licenses for inbound or outbound contributions on an exception basis. To request an exception, please describe the contribution, the alternative open source license(s), and the justification for using an alternative open source license for the Project. License exceptions must be approved by a two-thirds vote of the entire TSC. d. Contributed files should contain license information, such as SPDX short form identifiers, indicating the open source license or licenses pertaining to the file. ## 8. Amendments a. This charter may be amended by a two-thirds vote of the entire TSC and is subject to approval by LF Projects. documentdb-0.108-0/LICENSE000066400000000000000000000021021507310017400150010ustar00rootroot00000000000000 MIT License Copyright (c) 2015 - present Microsoft Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE documentdb-0.108-0/MAINTAINERS.md000066400000000000000000000012321507310017400160730ustar00rootroot00000000000000# Technical Steering Committee (TSC) ## Current TSC Members | Member | Organization | | --- | --- | | Abinav Rameesh | Microsoft | | Vinod Sridharan | Microsoft | | Siddhesh Vethe | Microsoft | | Zhe Li | Microsoft | | Rashim Gupta | Amazon | | Norman Townsend | Amazon | | Viktor Tarassov | Amazon | | Maruthi Devarenti | Amazon | | Patrick McLain | AB InBev | | Hari Krishna | Rippling | | Hari Krishna Sunder | YugabyteDB | ## Current Maintainers | Member | Organization | | --- | --- | | Vinod Sridharan | Microsoft | | Santiago Fernandez Madero | Microsoft | ## Current Project Chair | Member | Organization | | --- | --- | | Abinav Rameesh | Microsoft | documentdb-0.108-0/Makefile000066400000000000000000000012501507310017400154370ustar00rootroot00000000000000# Delegate all rules to sub directories. Makefile:; .DEFAULT_GOAL := .DEFAULT .PHONY: % check-no-distributed: $(MAKE) -C pg_documentdb_core check $(MAKE) -C pg_documentdb check install-no-distributed: install-documentdb install-documentdb: $(MAKE) -C pg_documentdb_core install $(MAKE) -C pg_documentdb install $(MAKE) -C pg_documentdb_extended_rum install .DEFAULT: $(MAKE) -C pg_documentdb_core $(MAKE) -C pg_documentdb $(MAKE) -C pg_documentdb_extended_rum $(MAKE) -C internal/pg_documentdb_distributed %: $(MAKE) -C pg_documentdb_core $@ $(MAKE) -C pg_documentdb $@ $(MAKE) -C pg_documentdb_extended_rum $@ $(MAKE) -C internal/pg_documentdb_distributed $@documentdb-0.108-0/Makefile.cflags000066400000000000000000000134111507310017400166770ustar00rootroot00000000000000 LIBBSON := $(shell pkg-config --cflags libbson-static-1.0) INTEL_DECIMAL_MATH_LIB = $(shell pkg-config --cflags intelmathlib) PCRE2_LIB = $(shell pkg-config --cflags libpcre2-8) DOCUMENTDB_CORE_DIR = $(OSS_SRC_DIR)/pg_documentdb_core DOCUMENTDB_DIR = $(OSS_SRC_DIR)/pg_documentdb DOCUMENTDB_DISTRIBUTED_DIR= $(OSS_SRC_DIR)/internal/pg_documentdb_distributed DOCUMENTDB_CORE_INC_DIR = $(DOCUMENTDB_CORE_DIR)/include DOCUMENTDB_INC_DIR = $(DOCUMENTDB_DIR)/include DOCUMENTDB_DISTRIBUTED_INC_DIR = $(DOCUMENTDB_DISTRIBUTED_DIR)/include PG_CPPFLAGS = $(LIBBSON) -I$(libpq_srcdir) $(INTEL_DECIMAL_MATH_LIB) $(PCRE2_LIB) -Isrc -Iinclude -Ibuild/include/ PG_LDFLAGS = $(shell pkg-config --static --libs --cflags libbson-static-1.0) $(shell pkg-config --static --libs --cflags intelmathlib) $(shell pkg-config --static --libs --cflags libpcre2-8) -L/usr/lib PG_LDFLAGS += -Wl,-rpath=$(shell $(PG_CONFIG) --pkglibdir) ifeq ($(USE_DOCUMENTDB_CORE),1) DOCUMENTDB_CORE_LIB = $(DOCUMENTDB_CORE_DIR)/pg_documentdb_core.so PG_CPPFLAGS += -I$(DOCUMENTDB_CORE_INC_DIR) PG_LDFLAGS += -l:pg_documentdb_core.so -L $(DOCUMENTDB_CORE_DIR) endif ifeq ($(USE_DOCUMENTDB),1) DOCUMENTDB_LIB = $(DOCUMENTDB_DIR)/pg_documentdb.so PG_CPPFLAGS += -I$(DOCUMENTDB_INC_DIR) PG_LDFLAGS += -l:pg_documentdb.so -L $(DOCUMENTDB_DIR) endif ifeq ($(USE_DOCUMENTDB_DISTRIBUTED),1) DOCUMENTDB_DISTRIBUTED_LIB = $(DOCUMENTDB_DISTRIBUTED_DIR)/pg_documentdb_distributed.so PG_CPPFLAGS += -I$(DOCUMENTDB_DISTRIBUTED_INC_DIR) PG_LDFLAGS += -l:pg_documentdb_distributed.so -L $(DOCUMENTDB_DISTRIBUTED_DIR) endif ifeq ($(CC),gcc) PG_CFLAGS = -std=gnu99 -Wall -Wextra -Werror -Wno-declaration-after-statement -Wno-unused-parameter -Wno-implicit-fallthrough $(LIBBSON) $(INTEL_DECIMAL_MATH_LIB) $(PCRE2_LIB) else PG_CFLAGS = -std=gnu99 -Wall -Wextra -Werror -Wno-declaration-after-statement -Wno-unused-parameter -Wno-implicit-fallthrough $(LIBBSON) $(INTEL_DECIMAL_MATH_LIB) $(PCRE2_LIB) endif ifneq ($(SKIP_API_SCHEMA),yes) ifndef API_SCHEMA_NAME $(error API_SCHEMA_NAME is not set) endif ifndef API_SCHEMA_NAME_V2 $(error API_SCHEMA_NAME_V2 is not set) endif ifndef API_SCHEMA_INTERNAL_NAME $(error API_SCHEMA_INTERNAL_NAME is not set) endif ifndef API_SCHEMA_INTERNAL_NAME_V2 $(error API_SCHEMA_INTERNAL_NAME_V2 is not set) endif ifndef API_CATALOG_SCHEMA_NAME $(error API_CATALOG_SCHEMA_NAME is not set) endif ifndef API_CATALOG_SCHEMA_NAME_V2 $(error API_CATALOG_SCHEMA_NAME_V2 is not set) endif ifndef API_DATA_SCHEMA_NAME $(error API_DATA_SCHEMA_NAME is not set) endif ifndef API_ADMIN_ROLE $(error API_ADMIN_ROLE is not set) endif ifndef API_ADMIN_ROLE_V2 API_ADMIN_ROLE_V2=$(API_ADMIN_ROLE) endif ifndef API_READONLY_ROLE $(error API_READONLY_ROLE is not set) endif ifndef API_BG_WORKER_ROLE $(error API_BG_WORKER_ROLE is not set) endif ifndef POSTGIS_SCHEMA_NAME $(error POSTGIS_SCHEMA_NAME is not set) endif ifndef API_GUC_PREFIX $(error API_GUC_PREFIX is not set) endif ifndef API_GUC_PREFIX_V2 $(error API_GUC_PREFIX_V2 is not set) endif EXTENSION_SQL_ONLY_DEFINES = -D__API_CATALOG_SCHEMA__=$(API_CATALOG_SCHEMA_NAME) \ -D__API_CATALOG_SCHEMA_V2__=$(API_CATALOG_SCHEMA_NAME_V2) \ -D__API_SCHEMA__=$(API_SCHEMA_NAME) \ -D__API_SCHEMA_V2__=$(API_SCHEMA_NAME_V2) \ -D__API_SCHEMA_INTERNAL__=$(API_SCHEMA_INTERNAL_NAME) \ -D__API_SCHEMA_INTERNAL_V2__=$(API_SCHEMA_INTERNAL_NAME_V2) \ -D__API_DATA_SCHEMA__=$(API_DATA_SCHEMA_NAME) \ -D__API_ADMIN_ROLE__=$(API_ADMIN_ROLE) \ -D__API_ADMIN_ROLE_V2__=$(API_ADMIN_ROLE_V2) \ -D__API_READONLY_ROLE__=$(API_READONLY_ROLE) \ -D__API_BG_WORKER_ROLE__=$(API_BG_WORKER_ROLE) \ -D__POSTGIS_SCHEMA_NAME__=$(POSTGIS_SCHEMA_NAME) \ -D__API_GUC_PREFIX__=$(API_GUC_PREFIX) \ -D__API_GUC_PREFIX_V2__=$(API_GUC_PREFIX_V2) endif ifdef API_DISTRIBUTED_SCHEMA_NAME EXTENSION_SQL_ONLY_DEFINES += -D__API_DISTRIBUTED_SCHEMA__=$(API_DISTRIBUTED_SCHEMA_NAME) endif ifndef CORE_SCHEMA_NAME $(error CORE_SCHEMA_NAME is not set) endif ifndef EXTENSION_OBJECT_PREFIX $(error EXTENSION_OBJECT_PREFIX is not set) endif ifndef EXTENSION_OBJECT_PREFIX_V2 EXTENSION_OBJECT_PREFIX_V2=$(EXTENSION_OBJECT_PREFIX) endif # Use CORE_SCHEMA_NAME_V2 in the SQL file if the internal extension code that shipped # uses the initial public OSS schema for the type. ifndef CORE_SCHEMA_NAME_V2 CORE_SCHEMA_NAME_V2=$(CORE_SCHEMA_NAME) endif ifdef API_OPCLASS_SCHEMA EXTENSION_SQL_ONLY_DEFINES += -D__API_OPCLASS_SCHEMA__=$(API_OPCLASS_SCHEMA) else EXTENSION_SQL_ONLY_DEFINES += -D__API_OPCLASS_SCHEMA__=$(API_CATALOG_SCHEMA_NAME) endif ifdef API_OPCLASS_INTERNAL_SCHEMA EXTENSION_SQL_ONLY_DEFINES += -D__API_OPCLASS_INTERNAL_SCHEMA__=$(API_OPCLASS_INTERNAL_SCHEMA) else EXTENSION_SQL_ONLY_DEFINES += -D__API_OPCLASS_INTERNAL_SCHEMA__=$(API_SCHEMA_INTERNAL_NAME_V2) endif EXTENSION_SQL_ONLY_DEFINES += -D__API_INDEX_PREFIX_NAME__=rum EXTENSION_SQL_ONLY_DEFINES += -D__EXTENSION_OBJECT_PREFIX__=$(EXTENSION_OBJECT_PREFIX) EXTENSION_SQL_ONLY_DEFINES += -D__EXTENSION_OBJECT_PREFIX_V2__=$(EXTENSION_OBJECT_PREFIX_V2) EXTENSION_SQL_ONLY_DEFINES += -D__CORE_SCHEMA__=$(CORE_SCHEMA_NAME) EXTENSION_SQL_ONLY_DEFINES += -D__CORE_SCHEMA_V2__=$(CORE_SCHEMA_NAME_V2) SQL_DEFINES = $(EXTENSION_SQL_ONLY_DEFINES) ifneq ($(EXTRA_INCLUDE),) include $(EXTRA_INCLUDE) endif documentdb-0.108-0/Makefile.docdb000066400000000000000000000026641507310017400165230ustar00rootroot00000000000000 ifeq ($(USE_DOCUMENTDB_CORE),1) $(MODULE_big)$(DLSUFFIX): $(DOCUMENTDB_CORE_LIB) DOCDB_CORE_SOURCES=$(wildcard $(DOCUMENTDB_CORE_DIR)/src/*.c) $(wildcard $(DOCUMENTDB_CORE_DIR)/src/**/*.c) $(DOCUMENTDB_CORE_LIB): $(DOCDB_CORE_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_CORE_DIR) install: install_documentdb_core install_documentdb_core: $(DOCDB_CORE_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_CORE_DIR) install endif ifeq ($(USE_DOCUMENTDB),1) DOCDB_SOURCES=$(wildcard $(DOCUMENTDB_DIR)/src/*.c) $(wildcard $(DOCUMENTDB_DIR)/src/**/*.c) $(MODULE_big)$(DLSUFFIX): $(DOCUMENTDB_LIB) $(DOCUMENTDB_LIB): $(DOCUMENTDB_CORE_LIB) $(DOCDB_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_DIR) install: install_documentdb install_documentdb: $(DOCDB_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_DIR) install endif ifeq ($(USE_DOCUMENTDB_DISTRIBUTED),1) DOCDB_DIST_SOURCES=$(wildcard $(DOCUMENTDB_DISTRIBUTED_DIR)/src/*.c) $(wildcard $(DOCUMENTDB_DISTRIBUTED_DIR)/src/**/*.c) $(MODULE_big)$(DLSUFFIX): $(DOCUMENTDB_DISTRIBUTED_LIB) $(DOCUMENTDB_DISTRIBUTED_LIB): $(DOCUMENTDB_LIB) $(DOCUMENTDB_CORE_LIB) $(DOCDB_DIST_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_DISTRIBUTED_DIR) install: install_documentdb_distributed install_documentdb_distributed: $(DOCDB_DIST_SOURCES) $(MAKE) EXTRA_INCLUDE=$(EXTRA_INCLUDE) -C $(DOCUMENTDB_DISTRIBUTED_DIR) install endif documentdb-0.108-0/Makefile.global000066400000000000000000000007511507310017400167030ustar00rootroot00000000000000 # clean up files generated to measure code coverage EXTRA_CLEAN += $(addprefix src/,*.gcno *.gcda) $(addprefix src/**/,*.gcno *.gcda) EXTRA_CLEAN += build/ .deps/ PG_CONFIG ?= pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) ifeq ($(ALLOW_DEFAULT_VISIBILITY),yes) override LDFLAGS_SL += -fvisibility=default override CFLAGS += -fvisibility=default override CXXFLAGS += -fvisibility=default endif ifneq ($(EXTRA_INCLUDE_MAKEFILE),) include $(EXTRA_INCLUDE_MAKEFILE) endifdocumentdb-0.108-0/Makefile.inc000066400000000000000000000001561507310017400162130ustar00rootroot00000000000000 OSS_COMMON_SQL_HEADER = $(wildcard $(OSS_SRC_DIR)/common_header.sql) include $(OSS_SRC_DIR)/Makefile.cflags documentdb-0.108-0/Makefile.versions000066400000000000000000000012361507310017400173120ustar00rootroot00000000000000INSIDE_GIT_REPO = $(shell git rev-parse --is-inside-work-tree 2>/dev/null || echo "false") ifeq ($(INSIDE_GIT_REPO), false) GIT_INDEX_DIR_VALUE := else GIT_INDEX_DIR_VALUE := $(shell git rev-parse --git-dir) endif ifeq (, $(GIT_INDEX_DIR_VALUE)) GIT_INDEX_FILE = else GIT_INDEX_FILE = $(GIT_INDEX_DIR_VALUE)/index endif build/include/metadata/$(EXTENSION_OBJECT_PREFIX)_extension_version.h: $(version_file_inputs) $(GIT_INDEX_FILE) mkdir -p build/include/metadata $(BUILD_SCRIPT_DIR)scripts/generate_extension_version.sh build/include/metadata/$(EXTENSION_OBJECT_PREFIX)_extension_version.h $(EXTENSION) $(MODULE_big) $(GIT_INDEX_FILE) || exit 1 documentdb-0.108-0/NOTICE000066400000000000000000000030661507310017400147120ustar00rootroot00000000000000This product includes third-party components distributed under various licenses. Full license texts and notices for these components are provided in the 'licenses/' directory. - RUM Extension for PostgreSQL (https://github.com/postgrespro/rum) Licensed under the PostgreSQL License Copyright (c) PostgreSQL Global Development Group - libbson – https://github.com/mongodb/mongo-c-driver Licensed under the Apache License 2.0 (See licenses/LICENSE_libbson.txt for bundled third‑party NOTICE details) - Intel Decimal Floating Point Math Library (https://git.launchpad.net/ubuntu/+source/intelrdfpmath) Licensed under the Intel Simplified Software License Copyright (c) Intel Corporation - PCRE2 (https://github.com/PCRE2Project/pcre2) Licensed under the BSD 3-Clause License Copyright (c) University of Cambridge - PostgreSQL (https://github.com/postgres/postgres) Licensed under the PostgreSQL License Copyright (c) PostgreSQL Global Development Group - pg_cron (https://github.com/citusdata/pg_cron) Licensed under the PostgreSQL License Copyright (c) Citus Data - pgvector (https://github.com/pgvector/pgvector) Licensed under the PostgreSQL License Copyright (c) pgvector contributors - PostGIS (https://download.osgeo.org/postgis/source/postgis-3.1.9.tar.gz and 3.5.2.tar.gz) Licensed under the GNU General Public License, version 2 or later (GPL-2.0+) Copyright (c) Refractions Research, Paul Ramsey, and others - CRoaring (https://github.com/RoaringBitmap/CRoaring) Licensed under the MIT license Copyright 2016-2022 The CRoaring authorsdocumentdb-0.108-0/README.md000066400000000000000000000156161507310017400152710ustar00rootroot00000000000000# Introduction `DocumentDB` is a MongoDB compatible open source document database built on PostgreSQL. It offers a native implementation of a document-oriented NoSQL database, enabling seamless CRUD (Create, Read, Update, Delete) operations on BSON(Binary JSON) data types within a PostgreSQL framework. Beyond basic operations, DocumentDB empowers users to execute complex workloads, including full-text searches, geospatial queries, and vector search, delivering robust functionality and flexibility for diverse data management needs. [PostgreSQL](https://www.postgresql.org/about/) is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. ## Components The project comprises of three components, which work together to support document operations. - **pg_documentdb_core :** PostgreSQL extension introducing BSON datatype support and operations for native Postgres. - **pg_documentdb :** The public API surface for DocumentDB providing CRUD functionality on documents in the store. - **pg_documentdb_gw :** The gateway protocol translation layer that converts the user's MongoDB APIs into PostgreSQL queries. ## Why DocumentDB ? At DocumentDB, we believe in the power of open-source to drive innovation and collaboration. Our commitment to being a fully open-source MongoDB compatible document database means that we are dedicated to transparency, community involvement, and continuous improvement. We are open-sourced under the most permissive [MIT](https://opensource.org/license/mit) license, where developers and organizations alike have no restrictions incorporating the project into new and existing solutions of their own. DocumentDB introduces the BSON data type to PostgreSQL and provides APIs for seamless operation within native PostgreSQL, enhancing efficiency and aligning with operational advantages. DocumentDB also provides a powerful on-premise solution, allowing organizations to maintain full control over their data and infrastructure. This flexibility ensures that you can deploy it in your own environment, meeting your specific security, compliance, and performance requirements. With DocumentDB, you get the best of both worlds: the innovation of open-source and the control of on-premise deployment. ### Based on Postgres We chose PostgreSQL as our platform for several reasons: 1. **Proven Stability and Performance**: PostgreSQL has a long history of stability and performance, making it a trusted choice for mission-critical applications. 2. **Extensibility**: The extensible architecture of PostgreSQL allows us to integrate a DocumentDB API on BSON data type seamlessly, providing the flexibility to handle both relational and document data. 3. **Active Community**: PostgreSQL has a vibrant and active community that continuously contributes to its development, ensuring that it remains at the forefront of database technology. 4. **Advanced Features**: PostgreSQL offers a rich feature set, including advanced indexing, full-text search, and powerful querying capabilities, which enhance the functionality of DocumentDB. 5. **Compliance and Security**: PostgreSQL's robust security features and compliance with various standards makes it an ideal choice for organizations with stringent security and regulatory requirements. ## Get Started [Building From Source](/docs/v1/building.md) ### Prerequisites - Python 3.7+ - pip package manager - Docker - Git (for cloning the repository) Step 1: Install Python ```bash pip install pymongo ``` Step 2. Install optional dependencies ```bash pip install dnspython ``` Step 3. Setup DocumentDB using Docker ```bash # Pull the latest DocumentDB Docker image docker pull ghcr.io/documentdb/documentdb/documentdb-local:latest # Tag the image for convenience docker tag ghcr.io/documentdb/documentdb/documentdb-local:latest documentdb # Run the container with your chosen username and password docker run -dt -p 10260:10260 --name documentdb-container documentdb --username --password docker image rm -f ghcr.io/documentdb/documentdb/documentdb-local:latest || echo "No existing documentdb image to remove" ``` > **Note:** Replace `` and `` with your desired credentials. You must set these when creating the container for authentication to work. > > **Port Note:** Port `10260` is used by default in these instructions to avoid conflicts with other local database services. You can use port `27017` (the standard MongoDB port) or any other available port if you prefer. If you do, be sure to update the port number in both your `docker run` command and your connection string accordingly. Step 4: Initialize the pymongo client with the credentials from the previous step ```python import pymongo from pymongo import MongoClient # Create a MongoDB client and open a connection to DocumentDB client = pymongo.MongoClient( 'mongodb://:@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true' ) ``` Step 5: Create a database and collection ```python quickStartDatabase = client["quickStartDatabase"] quickStartCollection = quickStartDatabase.create_collection("quickStartCollection") ``` Step 6: Insert documents ```python # Insert a single document quickStartCollection.insert_one({ 'name': 'John Doe', 'email': 'john@email.com', 'address': '123 Main St, Anytown, USA', 'phone': '555-1234' }) # Insert multiple documents quickStartCollection.insert_many([ { 'name': 'Jane Smith', 'email': 'jane@email.com', 'address': '456 Elm St, Othertown, USA', 'phone': '555-5678' }, { 'name': 'Alice Johnson', 'email': 'alice@email.com', 'address': '789 Oak St, Sometown, USA', 'phone': '555-8765' } ]) ``` Step 7: Read documents ```python # Read all documents for document in quickStartCollection.find(): print(document) # Read a specific document singleDocumentReadResult = quickStartCollection.find_one({'name': 'John Doe'}) print(singleDocumentReadResult) ``` Step 8: Run aggregation pipeline operation ```python pipeline = [ {'$match': {'name': 'Alice Johnson'}}, {'$project': { '_id': 0, 'name': 1, 'email': 1 }} ] results = quickStartCollection.aggregate(pipeline) print("Aggregation results:") for eachDocument in results: print(eachDocument) ``` ### Helpful Links - Check out our [website](https://documentdb.io) to stay up to date with the latest on the project. - Check out our [docs](https://documentdb.io/docs) for MongoDB API compatibility, quickstarts and more. - Contributors and users can join the [DocumentDB Discord channel](https://discord.gg/vH7bYu524D) for quick collaboration. - Check out [FerretDB](https://github.com/FerretDB/FerretDB) and their integration of DocumentDB as a backend engine. documentdb-0.108-0/SECURITY.md000066400000000000000000000006601507310017400155740ustar00rootroot00000000000000# Reporting a security vulnerability This project has been configured to receive private notifications of security vulnerabilities that may be discovered by the community and ensure a responsible vulnerability disclosure policy. For any security vulnerability that might be discovered, please do NOT create an issue in the repository. Contact the Chair of the DocumentDB project Abinav Rameesh, directly at abramees@microsoft.com. documentdb-0.108-0/common_header.sql000066400000000000000000000014351507310017400173250ustar00rootroot00000000000000-- File that defines macros for our SQL preprocessing #define __CONCAT__(x, y) x##y #define __EXPANDED_EXTENSION_FUNCTION__(PREFIX, NAME) __CONCAT__(PREFIX,NAME) #define __EXTENSION_OBJECT__(NAME) __EXPANDED_EXTENSION_FUNCTION__(__EXTENSION_OBJECT_PREFIX__, NAME) #define __EXTENSION_OBJECT_V2__(NAME) __EXPANDED_EXTENSION_FUNCTION__(__EXTENSION_OBJECT_PREFIX_V2__, NAME) #define __SINGLE_QUOTE_CHAR__ ' #define __CONCAT_3__(x, y, z) x##y##z #define __CONCAT_4__(w, x, y, z) w##x##y##z #define __CONCAT_NAME_FUNCTION__(PREFIX, NAME, SUFFIX) __CONCAT_3__(PREFIX, NAME, SUFFIX) #define __SINGLE_QUOTED_STRING__(x) __CONCAT_NAME_FUNCTION__(__SINGLE_QUOTE_CHAR__, x, __SINGLE_QUOTE_CHAR__) #define __EXTENSION_INDEX_OPCLASS__(NAME, INDEXOPCLASSTYPE) __CONCAT_4__(bson_, NAME, _, INDEXOPCLASSTYPE)documentdb-0.108-0/docs/000077500000000000000000000000001507310017400147315ustar00rootroot00000000000000documentdb-0.108-0/docs/index.md000066400000000000000000000004041507310017400163600ustar00rootroot00000000000000 Redirecting...

If you are not redirected automatically, follow this link to v1/index.md.

documentdb-0.108-0/docs/v1/000077500000000000000000000000001507310017400152575ustar00rootroot00000000000000documentdb-0.108-0/docs/v1/aggregation.md000066400000000000000000000030351507310017400200710ustar00rootroot00000000000000### Perform aggregations `Group by` DocumentDB provides the [documentdb_api.aggregate_cursor_first_page](https://github.com/microsoft/documentdb/wiki/Functions#aggregate_cursor_first_page) function, for performing aggregations over the document store. The example projects an aggregation on number of patients registered over the years. ```sql SELECT cursorpage FROM documentdb_api.aggregate_cursor_first_page('documentdb', '{ "aggregate": "patient", "pipeline": [ { "$group": { "_id": "$registration_year", "count_patients": { "$count": {} } } } ] , "cursor": { "batchSize": 3 } }'); ``` We can perform more complex operations, listing below a few more usage examples. The example demonstrates an aggregation on patients, categorizing them into buckets defined by registration_year boundaries. ```sql SELECT cursorpage FROM documentdb_api.aggregate_cursor_first_page('documentdb', '{ "aggregate": "patient", "pipeline": [ { "$bucket": { "groupBy": "$registration_year", "boundaries": ["2022","2023","2024"], "default": "unknown" } } ], "cursor": { "batchSize": 3 } }'); ``` This query performs an aggregation on the `patient` collection to group documents by `registration_year`. It collects unique patient conditions for each registration year using the `$addToSet` operator. ```sql SELECT cursorpage FROM documentdb_api.aggregate_cursor_first_page('documentdb', '{ "aggregate": "patient", "pipeline": [ { "$group": { "_id": "$registration_year", "conditions": { "$addToSet": { "conditions" : "$conditions" } } } } ], "cursor": { "batchSize": 3 } }'); ``` documentdb-0.108-0/docs/v1/building.md000066400000000000000000000035121507310017400173770ustar00rootroot00000000000000# Building and Running DocumentDB from Source If you want to build and run DocumentDB from source (instead of using Docker), follow these steps. This guide is designed for beginners and works best on Ubuntu/Debian. For other operating systems, package names may differ. ### Prerequisites Install the required dependencies: ```bash sudo apt update sudo apt install build-essential libbson-dev postgresql-server-dev-all pkg-config rustc cargo ``` ### Step 1: Build PostgreSQL Extensions ```bash cd /path/to/documentdb/pg_documentdb_core make sudo make install cd /path/to/documentdb/pg_documentdb make sudo make install ``` ### Step 2: Build the Gateway ```bash cd /path/to/documentdb/pg_documentdb_gw cargo build --profile=release-with-symbols ``` ### Step 3: Start PostgreSQL If PostgreSQL isn’t running, start it: ```bash sudo service postgresql start ``` ### Step 4: Enable Extensions Connect to PostgreSQL and run: ```bash psql -U postgres -d postgres -c "CREATE EXTENSION pg_documentdb_core;" psql -U postgres -d postgres -c "CREATE EXTENSION pg_documentdb;" ``` ### Step 5: Start the Gateway Use the provided script: ```bash cd /path/to/documentdb/scripts ./build_and_start_gateway.sh -u -p ``` Replace `` and `` with your desired credentials. ### Step 6: Connect and Test Use a MongoDB client (like `mongosh`): ```bash mongosh --host localhost --port 10260 ``` Try basic MongoDB commands to verify everything works. ### Troubleshooting - **libbson-static-1.0 not found:** Install `libbson-dev` and check your `PKG_CONFIG_PATH`. - **pg_config not found:** Install `postgresql-server-dev-all`. - **Other errors:** Double-check all dependencies and your OS version. ### Need Help? - Join our [Discord](https://discord.gg/vH7bYu524D) - See [docs](https://documentdb.io/docs) for more detailsdocumentdb-0.108-0/docs/v1/collection-management.md000066400000000000000000000016241507310017400220510ustar00rootroot00000000000000### Collection management We can review for the available collections and databases by querying [documentdb_api.list_collections_cursor_first_page](https://github.com/microsoft/documentdb/wiki/Functions#list_collections_cursor_first_page). ```sql SELECT * FROM documentdb_api.list_collections_cursor_first_page('documentdb', '{ "listCollections": 1 }'); ``` [documentdb_api.list_indexes_cursor_first_page](https://github.com/microsoft/documentdb/wiki/Functions#list_indexes_cursor_first_page) allows reviewing for the existing indexes on a collection. We can find collection_id from `documentdb_api.list_collections_cursor_first_page`. ```sql SELECT documentdb_api.list_indexes_cursor_first_page('documentdb','{"listIndexes": "patient"}'); ``` `ttl` indexes by default gets scheduled through the `pg_cron` scheduler, which could be reviewed by querying the `cron.job` table. ```sql select * from cron.job; ``` documentdb-0.108-0/docs/v1/gateway.md000066400000000000000000000051651507310017400172510ustar00rootroot00000000000000# DocumentDB Gateway ## Overview The DocumentDB Gateway acts as a protocol translation layer between MongoDB clients and a PostgreSQL backend. It interprets MongoDB wire protocol, maps commands to PostgreSQL operations, and manages session handling, transactions, cursor-based paging, and TLS termination. ![DocumentDB Gateway](images/documentdb.gif) --- ## MongoDB Request Translation The gateway converts MongoDB operations into PostgreSQL equivalents. Example: `insertMany` → PostgreSQL `BATCH INSERT`. --- ## Authentication & Session Management - Supports SCRAM authentication. - Authenticates against PostgreSQL credentials. - Translates SCRAM flows to Postgres operations. - Maintains sessions per user to enforce scoped permissions. --- ## User Management - MongoDB commands like `createUser`, `updateUser`, `dropUser` are mapped to PostgreSQL. - Roles supported: `readAnyDatabase`, `readWriteAnyDatabase`. - PostgreSQL enforces access policies. --- ## Transactions - Transactions tied to sessions via `transaction_number`. - Managed through a `TransactionStore`: - Tracks states: `Started`, `Committed`, `Aborted`. - Prevents duplicates/conflicts. - Uses PostgreSQL's `BEGIN`, `COMMIT`, `ROLLBACK`. - Includes auto-cleanup for expired transactions. --- ## Paging & Cursors - Mongo-style cursor paging → PostgreSQL `LIMIT/OFFSET`. - Returns `cursorId` and first result batch. - `getMore` fetches subsequent pages. - `CursorStore` manages cursor lifecycle and cleanup. --- ## Pluggable Telemetry - Supports custom telemetry backends via trait implementation. - Logging, metrics, tracing supported. - OpenTelemetry plugin support planned. --- ## Load Balancing & Failover *(Planned)* - Planned read scaling via replica distribution. - Writes routed to primary. - Failover handling through: - Primary detection - Reconnect logic - Transaction recovery via `RecoveryToken` ## Getting started with DocumentDB Gateway To get started with the DocumentDB Gateway, follow these steps: 1. **Build the Gateway**: Build the DocumentDB Gateway using the provided Dockerfile. ```bash docker build . -f .github/containers/Build-Ubuntu/Dockerfile_gateway -t ``` 2. **Run the Gateway**: Run the DocumentDB Gateway in a Docker container. ```bash docker run -dt -p 10260:10260 -e USERNAME= -e PASSWORD= ``` 3. **Connect to the Gateway**: Use Mongosh to connect to the DocumentDB Gateway. ```bash mongosh localhost:10260 -u -p \ --authenticationMechanism SCRAM-SHA-256 \ --tls \ --tlsAllowInvalidCertificates ```documentdb-0.108-0/docs/v1/get-started.md000066400000000000000000000046251507310017400200330ustar00rootroot00000000000000## Get Started ### Pre-requisite - Ensure [Docker](https://docs.docker.com/engine/install/) is installed on your system. ### Building DocumentDB with Docker Step 1: Clone the DocumentDB repo. ```bash git clone https://github.com/microsoft/documentdb.git ``` Step 2: Create the docker image. Navigate to cloned repo. ```bash docker build . -f .devcontainer/Dockerfile -t documentdb ``` Note: Validate using `docker image ls` Step 3: Run the Image as a container ```bash docker run -v $(pwd):/home/documentdb/code -it documentdb /bin/bash cd code ``` (Aligns local location with docker image created, allows de-duplicating cloning repo again within image).
Note: Validate container is running `docker container ls` Step 4: Build & Deploy the binaries ```bash make ``` Note: Run in case of an unsuccessful build `git config --global --add safe.directory /home/documentdb/code` within image. ```bash sudo make install ``` Note: To run backend postgresql tests after installing you can run `make check`. You are all set to work with DocumentDB. ### Using the Prebuilt Docker Image You can use a [prebuilt docker image](.github\containers\Build-Ubuntu\PrebuildImageList.md) for DocumentDB instead of building it from source. Follow these steps: #### Pull the Prebuilt Image Pull the prebuilt image directly from the Microsoft Container Registry: ```bash docker pull mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0 ``` #### Running the Prebuilt Image To run the prebuilt image, use one of the following commands: 1. Run the container: ```bash docker run -dt mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0 ``` 2. If external access is required, run the container with parameter "-e": ```bash docker run -p 127.0.0.1:9712:9712 -dt mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0 -e ``` This will start the container and map port `9712` from the container to the host. ### Connecting to the Server #### Internal Access Step 1: Run `start_oss_server.sh` to initialize the DocumentDB server and manage dependencies. ```bash ./scripts/start_oss_server.sh ``` Or logging into the container if using prebuild image ```bash docker exec -it bash ``` Step 2: Connect to `psql` shell ```bash psql -p 9712 -d postgres ``` #### External Access Connect to `psql` shell ```bash psql -h localhost --port 9712 -d postgres -U documentdb ```documentdb-0.108-0/docs/v1/images/000077500000000000000000000000001507310017400165245ustar00rootroot00000000000000documentdb-0.108-0/docs/v1/images/documentdb.gif000066400000000000000000001413501507310017400213430ustar00rootroot00000000000000GIF89aAúx!ÿ NETSCAPE2.0!ù,Aú§  1 g&„8sB.8>4O4O5O5O5O4P4P &SVYYZ ]j&x9P«b¿pÏuÓwÖwÖxÖx×x×y×Ù#ˆÝ/’ß3®à5¾á9Ää@ÏìCÔðJÒî`Ëìg¿í^µîY®ò\¥ë\ í\Ÿî[ŸíUìQšèZšÝvœ¿‹ž®•£®ªª§Ö«xè£Tó°`õºmï‚ÙʳÏÊÄÌÊÊÍÌÌÍÌÌÌÌ̵ÐݤÞö­æø»íùÊìùÕíùÛîøßñøàóøãïöåîôçîóéðõëò÷íòöðôöôöööøùøûüüýþþþôþþåþþßþþÚþþÝþþíþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿþþþþþþþþþÿÿÿþG H° Áƒ*\Ȱ¡Ã‡#JœH±¢Å‹3jÜȱ£Ç CŠI²¤É“(Sª\ɲ¥Ë—0cÊœI³¦Í›8sêÜɳ§ÏŸ@ƒ J´¨Ñ£H“*]Ê´©Ó§P£JJµªÕ«X³jÝʵ«×¯`ÊK¶¬Ù³hÓª]˶­Û·pãÊK·®Ý»xóêÝË·¯ß¿€ L¸°áÈ+^̸±ãÇ#KžL¹²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N¼¸qŠDr@0@€çУKŸN½ºõëØ³kßν»÷ïà¥þ €à@"ÇÓ«¿HsóA XnJåäq _Ï¿?B!ÌÝ „ qy¨`zU0Y,8P8 p@fœb¨á@  Ã‡$âVáˆ%Ä!)¶Û @á"AP pÃŒ8¢ã|9 d…= š{< ù#‹B&™‡2*9 ":)¥dUD9%‡N©åb°å(]~)¦aB å”U&8æš!€ä—î±)'_D aQ=T'GxÔÅIØ•ÅûÍé:à è¢Œ6êè£F*©Lè†ÃFåy] uQÀÚuÛ†ª• ¤ªêª¬¶êê«þ°Æºª •Þ†€šDå jA]@,läé®vXêZ7Ȫì²Ì*{«mu"¥k¨y ÀÂ~Jm]„‹͆+n¸DQ›rÒ@lA<€ýp€s €¯ó>Á XÔ.tô9Š;ðÜGä©¿ÀƒsÜ;ÊŸô& ð@_ð`0d „Ræyk–ã–l2¬˜ÎòQÓÔ.}qÀsã9§ý`p ð\þú Àô)3Í>× À£´›ãYð±Ïñ,4Óû:´Ð\lº"“…êÉd—+l‘îºY;ÃØ íàÂÀ¾’/þ´ аԶ;ßY?Çô¿zrÅ(:7Ü/ãÃÀ0Küí+ÖF@Øc1Qöç'“ ÛMfªî¶ZQ€º}Z›ø@/â…ô0΀ÿ½ºäm|øéù 4Ay^Py»¯3>åHAɹX$ƒ.}¸rÏ&@‘x^@ 90Ä{¿…¯Pî³=Êå“ë{ß¼~Úg»´p¦RVð|X9Lïÿ²   ’¢©éàËÓ»â¿Ö S¨–¶¢@÷Áni Ã\ 6žžyð9/˜Øêôuƒ-e€ûû ¸þÇBX €ÀSH 2;„p@˜Yt2P9k†þÄÃ`ӄؽëÜ <Úsº¦Je H@ X°‚° Š=|Þ [ÈÅU½pmÛ:ÛV`$uû™î~è. fðáóšBº°ƒ~/)NtJ¤XÅ>ú±Š,ã±¶ØÅ.~‘e1LˆÎîHE‚¯ -Cß"ÃȾ!jpu7|ˆµ2i”<2E Tü£(ûÈ‚,²¨<¤éÔg×±«:³À¶&éÃPY‹wºb»0·> ooEó‚ƒ'r²(žTJFÉL?>ÒP„D% U™=V¤nÕ£Û¯îf­ Dp_ ßû.&8ÂõÊppÜÛÒܧ:w1, d‚„fÚ³ŠÏþ”S4¥é?jæ*‘ 9Ôšóœ‚jÏéÙVà œ:ϯаtDSV{Ž,s9PzU)ÉaAާLå*ÓØ„JJq[Uà­d E® D‚2›ùÌhÁþJƒá›XõÉ ¬Lã$ÛùÎxÎsž[Å>ûÙϘ]–·ìYÙ¸Ø)S8‚ ÆœæF;ÍknN–C›„Î3†A 6ÍéN{úÓ µ¨7]« šÐÀýñV°ŒàÑ°Žµ™E@(áÉ`±tIæŒéŒú×Àö¦{»žS£ºËRIt ÈìhZ×@ÉD&r’í"»@ÌÌnôjpJoE×$‘r¯…MîrsšØê16¡‘ý,aÙi¦5 Ž „ÅEä C† ´],wÜ#9 Nð‚œàæNx°Ñuo™ÝMa‚ ^æZoW#Whõ¾+Þ{sà"QÂÁþGnp…›\Ô ?ŽÃ{ ñ¥,Ù.óZðHœâfž9œµò´"$º b0ô¢ýèFO:Ò—®ô¦/=åFÑÓjhú¬\Å-OÊ`Žæ×ÉÂ6žóx»*=‰Àƒ>rÌÀíp»ÜãN÷¹ÏÀG¨»Þíîv¨Ek l\Õérõgý(­8ÎeÞ° -ˆ9¼þñŸ`èl78 6ÏùÎ{þó‡A¢úÒ{~ÇNÑZíþ5ø&NgÐÚëþåKõ¨oJá!|x£4Ái&Aî=2v4‹Àìß 2¯yÓ—Ÿ?BŒ°yè;?úTñEõþf{LŽ¢€è|Õúä@ïJkÐ9¦Sv?àÞ… 0ˆ· î÷*¸@ò €A’ àÿ€8€Xx€˜€hð—€JP-P  X8|Ká+7Pà)à+/`L"0:0ÆTCz3-´4FOÁ~på~DÚÖ;çSЋgf0PjX‘v"‘,pB8„DH„hF0zx€¢G4 UKx„ˆJá+µ7yB {îÓ./à…Cô¹3; ÒS²c{¶.V082Øh"ÀmggîVøWf;È@AX„€xT˜€I(… h?þFp€…8…ƒh…I‚í‚‚ž²@c(†`X†j¸…Ť†RцR…¬÷ÖÄ<<|xqØl%ÐKàxJÐðöh{ÈsDqX„ƒx€hˆ¸ˆ½ÈmÙgCš* (‚žB‚°@`ˆ‚ßw:+ØFŸˆj&#ŠÓQŠ †ÿ¦«kòÖIàdOPdú–‡iv‹Yáƒ%[»(„Åø‹3PUP HŒˆ…‚”¸: ‚Ó ƒ‰UW~»‚~ 4 ˜RÚ˜8³S;½ô+ …~!Äzïb-À‰‘È7G`-DÄz¼Ôð˜á(k9W50€dF†þd.)f9¨’ùǃWq’%1R4E>9E%”B9”,ù‹4@”Ai?J€”P0€”D¹cDÀÿuUGY9Ð8xusžX‘‰9@ñü‘X; y•Ñ0Iu°}CôÐNБ‚ÒŠ<¡“7‘’6˜‚yfîØƒP1P9”…x”P™„´Ø˜£W‰”^3•P/hÁ>èó8@h)MÚ(ïRïB;rÔSÓ"//œh†IÀ‰IŽñ7˜¶i›…™“‡9™”GÀ˜HIú•5 iKÀ›”7 E€6U9£HDO‘P8€=¡™J7þ])‘›ÄÒShè‘[#’ƒ~i€y›îi‹8i빈‰œmvOI”ó·”PId.€œ”'‰C]Ò%¢s–š : —rê Šr‘"¡‹’j¡$~–øB E@Ï9 :¢#ŸO(*ª¢‘ùh0zG­PBcö–…¤–´•°É0 )ž[Iž‰ƒ'x%¹óIíùžNJ˜&JKšõiŸG€ù)”ŽÙŸE ”w*J$":0¦czz¦9° jŒò £"¡ Z  JP§n"¡vj§"¡Ô§jZ€jZ5þ—y™Ð±'g‰%ãd~Ó¸¡Ó¸0ªy:¬9¤[y›i’´ù¤œÚh¹)Ÿ»é¥.€J¥%Ã•Ôæ¥É9 :ÀP£6½Ñ YXp£pæÂ Š:.1§,áÁ#!Ø–IŠF€~t‰†èÙFÑ™¤:1¥2ѤúžŸŠv‡IÚº­ÜÚ­¶Ú*zKЭ% KðnÝš®Û*G¯Š¨ÀA©«¡£]D!‰=/!¬Ãj‘˜—¹*Ö¢DJF¤* `/¬!­1A­Õz›×*¥PÑêZ±µÖS fŽÙ­J èj±ÝŠz¯ñº«óÚ«Í’¨ ‹þ%8?—jU¬ û°ƒ±Sq³%A± ›®n¦­¨*fÜ:o%´! ͳ ÑÐ*™Ú8`²A¯þã43£NѬcy7@³{j>ë9«³É³Rq¶#´J›®6PL·JëˆDÑ´N+CÒiSkX;=6C¨:)3¯=“§@¦Š[§‡û«ë%!~êc˜+«á¡$:¢‘¢+º¢YP£\;P9PnËi«¶*ɶQѺ!·v»­;Ø· ²ÄÔè£0C„ )–äžç7~KDHºFk8+=Zû+ 墢kPþÀLй!*™Û½š«"d¾;¡¸{–»¸WÛ§T¾ šº…š«u¨‡K»*ñº°k² ôûM0þû¿À<À\ÀÿÛ»Lñ»t°ÆZ@ÊH¬"d9AJñ¼Ó£µ4+«û¶ŠW6S²±¿(a¿ @kAY“æ¿ìèhùû&ÜýkÀ6|Ã8ú’ÇÌI LJLL<=-‹þ¨[³f9 3l9;sg²Å]Ü»W »ø[Æm{Æk<É8ŒÀKñ·ãIDZ‰A² ›YÙ‰l„Çœ{¬R8Ñ´|¹P«y쀯¬kÅæ5¨È*©Ãy,LÆ©ÈO ÀÌÂ<ÌÄ\ÌÆ|ÌÁlÉJÉ[9ÄB ÄÎÚF –eL­,¥ :9¡·©ŒÀ›׌…\+|a˲†Ë¡5k1ìã¬X€Ìô\Ïö Ìx;Ìü:ÆZ“ÁÍzc—NÎ@‘Í>v <ÇÂË–ÈëÀÇ˯…5Ë[KBÏ#á°­ yÚºËñÆf-°ÀŸ½Ì8øþ*½Ò,ÝÒ.ýÒ0Ó50ÈH±ÏûJ‘ Õ'¸—¼–XÑý]6ÛlÁÀËÀÄ ÑýÐ Ì9Ñ"á°ý6SPÒ¶Ùª£€ƒ&‹c¡nꦜ#AM6C=> /ÎŒAC\Ä€sÄÖ<Ê?Õ!!ÕXVÕî‰ÕŠ·ÕïH‰)Ý…²áRÖ=Ì0pì RÔšüÉ=¢ìÔâ,Ë6Õa×·‰×ýÎM!×*Ñ×ò×€Í,CÍJ™lØ›¼0¬†Šý£ŒýÓ5¡ÙA×TmÕƒiÙzm˜])¦ûZŸ Ú§ ׄÝ=»Äj ÍïÒšÓìÖéØ7áÚÛ“-Û‚IÛ0þ ɳË×hz¦4$c}2¡-HÞØÏE̓­Ôâ×F¬MÌÝÎ= MP›Wí5y=Ý'ÝY¾ö­¥ã[»a5aÓ±ÓHìÐÁÖ¸ÔLsÞ3‘Þá°0E(\qðMvíHÝú;Qpßá¢(¶ßÂ¥jRÑž‘¦¹ÍÎî©Î£hOé©.ÃbÑ A€ááëµYÆáfhmfæ\Åçž. Ò±­âó­­@Þ[äA u(Ö4+o(í™ãÑ è|›$€|?>áAnY…E`äF.PIÞ"ÛOî5/7Æ·ÜqWŽf˜Í îU@ôuçí•ß=RæþÍ‚€(bãY‘æñrNªsAÙp¾âðÜvŽçx.ã3Âç±b#9P°,a7^fUîµ;~›’ýæPšåTºa®¢§©¾ê+*é.Bé­ÒÂs®Ô:sCEâ·y|Cõ´ÈÂq~B)¤B»í&V«µž žE†Nå^Ûº9ì]ë €9à긑ì±Þí}×ð}ÙŒžÙÒ>í(KÅÑ l/j2Ф›Ûœ¡í±Þ[çíß@ÎÕã®|þ, ‘V êÛ¡_ð¢a^°(ònë­è³ýíЪûÎïØØNOßñÿñO¨j _þÝ)Ýù¾×ŸÛÝgSQÈñ _ó6_ðDæ ¯%O'oïïX®ï-oÛ=§W4óLßô9í‡Ñóñó•-ñòMôEOc].Ñ Q°ôMöLŸóc>R/ÜŽò6‰ÕZ}õ,ŸõU1Öz`/övóDÝf¿égVÔñÑí5m¿ò¶ß¼Ø1Š–È|9;Q["c]•t÷”ïôzgå|1‰'ák›EçÎá.ç:ÑðC§ß¼Á‹¿@À4?0rԠܦFhøZ÷•¿ûŸñ{?èî=ƒ¹}øéù&­hJÍîö…=þ{7d6ܽ>ÂkÖòP¼ÖÈúîã)!ôúxLð8Ïï+ I)h[¶9Ïûò_ó—ÿ™9Ûà1å°fâñéBà@0˜ŒB˜PáB† >„QâD-^ÄØ £ºLÐ1!É/¼èh@$É£PŽâàË“y`p’Ð —Gý©ðãHœ£zàùÒ€Ì.Zb„UêTªU­^Å: Ç®]½~VìX®B’VíZ¶mݾ…JVºuíÚ­xWo]&0þ8¢E…IJF Bð¾‰Ü9k^ÉU5þÀÙCÐ$söþùòä‹.Žx4í٨ț9ît @6€§ 5:yt’Ÿ¡}r¬\øpâU·’Ež\¹Y…Wâ>‡î•âÕ­c¤|]{cÇk$Á‚Ðpw‚‹fIRCyÈÚÝÊþÞ¡ÆÜ;9·îöèN—>¿ûŠÂ ¶— äI§Ù2ª(Î`ƒÉ'ù&¤°ÂˆŽS.C »bN!&¤1Ä·²°Äàâ3q/îÈAjpXHŽhÁ…Öc±½+C±DÏx Á4ÎTÛm?H3 µ#dÀ¦Z:0„ú;-¿ÝVÓϧ*3Ìà0ܰLä:L( "Dd3D"²3N«‚”þÓªiÄ3OÇ|¬“.:+ôŒ$œ8£I)žFë &™ µ‰@Š:ð¤a’Ò©£¨LI¤)ûä´Ó¨È43T°ÐLèŠ5ÛD."¨ó´Õ‡þtÕ¢+\гV[raŠXçÓ³¦xâÌ(Ù =tI @ªÉ£(Ї]PBIz´…ܵÛXA5ÜHU¨ŠSSE—ˆ(¼eVv:bÆ[çe‘„,ß…Ê]|·ŒL5&Å7à8Á7TrªŠsÑ‘‰uŽU_ˆº¢…èÅ1\xbb‹$Žõ$ÙdªÌß×ö8å .¸LR¡ƒ¡+^˜á¶ˆ  VVYL'þžÂ⌇n†%zŽèg¤—f:`–[Öðe"s¨Š(˜¨Õœ£°â!+˜ ºi •†¸by‰¾u>ÅNˆl¶ß†[̧¡^n¡(Ò‚¢kˆ°H (°Æ9pÁqf‚ ¿£¨NˆZ‰bͰãvÏm[Q¢†‹ÑÖ³„#v†\rÈ?]»¹é>ó¬µò¾næs½8ÏÆâË1'O„Zеõ×[ç½÷»F'}¬—o†"Šð*³âêšY÷ÈÞ³PÂx¤} j8‚ùÏwo¾{ï¡>ø°H½[U®Ï*‹(†Kûïñê %Z(áò¡]¼± ﹿÿ Ÿø¾2¼èà¬xz›þ¬`µõa-:îûßUø§²)$¡0¨ŸžFð¢ èÛ_E8‹P€2]›·Bœ¡ ‚$”Ê™–…'(á8Ê‘ Z°ÃA MáÿdC"ÆÍ„'—Ýl¶Ä¶¼°ˆâyE)VQeá+Bµ¸E.vÑ‹^L!ÅèD+B„ŠeŒÛѸFo…¯8å#ÉÈÆ…¨‘ŽL³ãõX'7Žq´Ù÷˜Ç=¦Œ…D¤‰ú8´r‰‚Ôã!0INÒ’îY¤pþèÈTAòŽ•¼d·@JR '“Ái$']XJ…Œ’•rå+eI—ðáÀ–·Äe.u¹Ë]*Q•«”e,gþ'aÓ˜R9â øKTy’ŽÅ­ÒNw¢ìG¹ùɶÜé ….ˆdíÊgD¯³ÏàÓŸ"(ZgMÊYA SSH&(×ij%$UA]µQ‰“¢¤³èEA”Ñ2 ±ê(µÞ™PÙ€”§ÌÊ J›²Là²I‰ljCЧjYLARQŠ£tdª±±g¬¬ €–vÕ”×ÌP?e šZqséVN’ÓeÍf¤ ªP @Tw.((UêOgƒþ D›!:(¸"õ]P€W™—Ò-¦c%ë,o©!ÎҀȼôרtä$‹ lN†:’mQ š*TßJØwµ«uMBéZW•z*[lnÖº)d“mß,ƒÊrë²-BH2#,å^Ê í±ˆzWÎ~v&….oF+ÒÓ\u¹¤¬³«@·çÅJc¡&Vྥ¬U,oqf¤$W¶Í}蕊ʛï~& ².=gCÔ¢l7µÝ.Uãš`Ùò¦[ÃEo„©¢Þ–±·½Mœ%›Vãº6 š} géëYú¾€$$û(i©[,Õ>w°¢ë‡ûbþ„4åWolc5"HØÇàãmr,|áµ¼·Š‡i«`‡"Ø®I°ñ“ý›Sëþ7Z4­Èþ*ཱུ°²©-§„€Û—™!XübšÕ F…¤’Èn1²qp%»õ¹ôô)žLÏÄxÊž±•9‹å[\6.¢»«àÀ̆È)+ãæ7³%ÎOÔp!-§,ðxÓŸ rŠCéJ«åÒOD€£AÍG2¯ÚÇ’– ©K-„SQ¨µ«ïR…$Y×›†udd]ê\ñæýõŽl`‹š8ît±aÈk0»D:Àµµ]K^vÛÛ½ló¬1|Ll£UÛïAlµÏ]f þlÈѦ&pÓuÇ ©®7»ƒ\ºp‹»ÈÕ¼Á¼ómoÐyà¯Þ7YÞýfi?1àæ>¸° q„'\, 'r߈ƒ¨›âwÁ¶ª?ŽÞv‹ ãÖø±}€”¯» èøÈ%\òp¼½-/âË€MËü"Yà8Ë}aš‹ÊæÀÅùÇ<€øzè €ä§ÝâϦ¿“.E"È{à êªn(¡¼SÇA«nõ«*ëâÞº‰P^ @uÅ{Þõ¾w¾÷Ýï|à?xÂ^S®Ú×>ó¶»½ßþNKÜ?yÊC®è{û¬%_yÎw¾g—7ÓÑ!»yÏ—þÞôì½Ë2OìÓ·ÞõïKý†D?VÒ¿Þö·Wdã¸zxãÞ÷¿gZì±é[È«åxÀG~òömæ7Ÿù qNñ¯|êWY«4Ä­¿}î“ð·o^U÷Å?þÿaÿÂ#úÕß;q£ýï‡?Ü }Q÷Çßþ÷ïYãÚ 6ü÷ßÿÃý»(uù¿4@|aöá$œáštÀô–¤†aÀ*hÄÀ ì¾Y¿œ2œÃ‰ÎÑÀ4ÁDÁTÁdÁtÁ„Á”Á¤Á´ÁÄÁÔÁäÁôÁ Â!$Â"ô¼¯âúš Ÿ0ŸJ-[´…€#´þÂ_×HÂáXBŸ¨‰Ÿð×+ŸØ”†¨Â+TÃOËÂMѲ¦Ú–Ìh–” dÑgy(&,@*ó+ñ,¡ªñÊB+Ñ2œh§¤3+Ù”!™™Š¡XÃI¦B4Ì`Š&Ù Õ• ­”h'(L„DÞ¨þC—˜iaˆ—ØØh –À QD€ Ø”@”Û Ä^d%K$D‘“áDPt’aŘéÂ(\/D‰  rF* FÙ é°„Z+›HЬòÅqD¤,””3܉B,FU>>@@@AAAAAABBBCCCDDDEEEEEEFFFGGGGGGHHHIIIJJJJJJKKKLLLMMMNNNPPPQQQRRRSSSUUUVVVXXXYYYYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZZZZZZZZZ\\\___aaaccceeegggiiikkkmmmnnnpppqqqssstttuuuvvvwwwxxxyyyyyyzzz{{{{{{{{{{{{|||||||||}}}~~~€€€‚‚‚‚‚‚ƒƒƒ„„„„„„………††††††‡‡‡‡‡‡ˆˆˆ‰‰‰‰‰‰ŠŠŠŒŒŒ’’’““““““”””•••–––——————™™™›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¦¦¦¨¨¨©©©ªªª¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÄÄÄÇÇÇÉÉÉÌÌÌÎÎÎÐÐÐÒÒÒÕÕÕ×××ÙÙÙÚÚÚÜÜÜÝÝÝÞÞÞßßßßßßààààààààààààààààààààààààààààààààààààààààààááááááááááááááááááááááááâââäääåååçççèèèêêêìììïïïòòòõõõøøøùùùûûûûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþ2Í2þ½ŒùGL™lúó‡&Mš„kØ Løoa9s(ꙨП!D‰(BâHp!Å›:u"y²¥Ë—0cÊ$h,ÚÉ…ÊN6kf“¢É„ëØµkç„ñ’Ê“7ïæÌ§P£JJµªÕ«X³jµŠêEQäŒzê´‰¢¥°>ýE‚äˆ""´û蹓Pޏ%žtˆw«_‚2€Áò'Å ûë0† 3&¨ ‚’ÿjÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N¼¸ñ¿ üs@°ÂgFAü+‘°… èi[ ‚½ãɸm`ýË•X÷¼.•53ªî_»Eß½ƒgßñûøyÓGpè:£-!ƒLOÞµ” èQdJnDüA;äð €'©P„iyðÏ Eà†yE߉(¦¨âköüÓÔ!ùÿ,ZX¹ §  !!!!!!"""######$$$%%%&&&&&&'''(((***+++,,,...000111333444666999;;;===@@@BBBEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGHHHHHHHHHIIIJJJJJJKKKLLLMMMNNNOOOPPPRRRSSSUUUWWWYYY[[[^^^```cccfffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ¢¢¢¥¥¥§§§ªªª¬¬¬®®®°°°²²²³³³µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼¼¼¼½½½½½½½½½¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ÀÀÀÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÒÒÒÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÝÝÝàààãããæææéééìììðððôôôõõõööö÷÷÷ùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ™øûG° 2¹ ô7Pá¿7o*dèOŸ> RT¨HÑ¢Œ Ąɡɓ(Sª\ù/šBkÖ®as¸ñ_8‚ãÆ‘£ÙðœBtèxþ[çð<–H“*]Ê´©Ó§P£Jú4†È‚ž< ꤭¯þ$HXbëÔ¡s6¤Ã3g¨Ê5©£à 1b´ýǰ.Á&HŒØÛ÷ß…‚(öWW@Aç˜K¹²å˘3kÞ̹³çÏ)k‚Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒûÎÂX‚ bñôûÆ¿2”‡eNP •WBÃüS{ «‚ÂT!SƵà·pâÆñô4AuD' ŸOÿ¶…«AÏ™3Wþß¶×T#M­’Ê,B‰rÛ@Büã8 8s©p‚„hQ÷`’†õ…(âˆ$¶O@!ùÿ,\X¸ §  !!!!!!!!!"""""""""""""""""""""########################$$$$$$$$$%%%%%%&&&'''((()))***+++,,,---///000333555888;;;===???@@@@@@AAABBBCCCDDDEEEGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyy{{{|||}}}~~~€€€‚‚‚‚‚‚ƒƒƒ„„„………‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““•••–––———˜˜˜˜˜˜™™™™™™ššš››››››œœœžžžŸŸŸ   ¡¡¡£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛàààçççìììðððôôô÷÷÷ùùùúúúûûûüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýùó¯à?1bÆt2XP ÃpàÄYÈÐ!Ã>}þP4h±à¢Œmlèa¦‡(Sª\ɲ忎ΠJ›öÐᶇܸÕ,Ùíá·o;á,gΥѣH“*]Ê´©Ó§P£2íXÐS§Nžv>|ôÈQÖŠ% è+ǰéü›#Ç,I†f¤ÊE)PÌ¿qÜpûÒŸÝ1Xà+p̆ Œì;æC Ä0·²å˘3kÞ̹³çÏ UR Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ ×-0nAÿ$Hд3®8þéØq¬™"ÿŽ\¤úY3[n`wöOØ?cÇ´Ìöo[ÎÞþ5Nèðûøy;ŒÏð=ØjÿHcP3Ë(£C´È‹V¤ˆçQP<0VÿÈ`Ð Xx† ü“À? à!Iæ§âŠ,¶èšC!ùÿ,^X¸ §  !!!!!!"""###$$$%%%&&&((()))***+++---...000222555888;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnoooppprrrssstttuuuuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€€€€‚‚‚ƒƒƒ„„„†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘“““”””•••–––———˜˜˜™™™šššššš›››œœœœœœžžžŸŸŸ   ¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÞÞÞåååëëëðððõõõøøøúúúûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù3ô¯à2dÊè)ÈP Á‚qþÅ‘³á?‡ ÿü $hÅ‹þ2*èè¤+Yºô±¥Ë—0cÊlòÙGjÕPúÛÖ²[7ÞZ~û¦Óå¼™H“*]Ê´©Ó§P£JúTàÇM›4a*ÊÐÑ¿FŒé|¸ñß?}Æ”NEš†Ðœ¡J÷¥ÃkÐx[P`!7XØ£³ÐÇ[ôûQ@Å « ¨K¹²å˘3kÞ̹³çÏ0€Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒûˆèŸèÿ,Œ¸£³¸Å:˜/ö‡ÈˆE'O¤ÓÄmµe2e\?Nrû9ýc¸pâÆ _Ïž·À â¹éœöÏ&³ÉŽ oë߬°¸^mòƒE:䀇N‡0Ø,8]ƒ0TÒÔ`{vèᇭY!ùÿ,ZX½ §  !!!!!!!!!"""""""""""""""""""""""""""##############################$$$$$$$$$%%%%%%&&&'''((())),,,000333666:::===???BBBEEEGGGIIIKKKLLLMMMNNNOOOOOOPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQRRRRRRRRRRRRRRRRRRRRRRRRRRRSSSSSSSSSTTTUUUUUUVVVWWWXXXYYYZZZ]]]bbbeeeiiilllooorrrtttwwwyyyzzz{{{|||}}}~~~€€€€€€€€€‚‚‚ƒƒƒ„„„†††‡‡‡‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’““““““””””””••••••––––––˜˜˜™™™›››œœœžžžŸŸŸ   ¡¡¡¡¡¡¢¢¢£££¤¤¤¤¤¤¥¥¥¦¦¦¦¦¦§§§§§§¨¨¨¨¨¨¨¨¨©©©©©©ªªªªªª««««««¬¬¬¬¬¬­­­­­­®®®®®®¯¯¯°°°±±±²²²³³³µµµ¶¶¶¸¸¸ººº¼¼¼¾¾¾ÀÀÀÃÃÃÅÅÅÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝßßßàààâââåååçççêêêìììîîîðððòòòôôôöööøøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þQü8П?VÑüC“& Á‚²ئ›‡ÿ ²šCçŸ<~ ¨1ÑÀEŒ9zD2"Æ—0cÊœIó¡Ah/­]k 3\8ž/ÏZ³¨Ñ£H“*]Ê´©Ó§P£zh©Šà¦™2Q=IÑ!ª‚üüÃc‡Î9TÛHd³¦íÖ¨pe¬ú°F1o F€€×¦?º èKp.FÇ]̸±ãÇ#KžL¹²ešøð]Þ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëFú e,-xãûŽ9þéÐAÜo,ŒN¬4¯mðŸ1ŒÌšµÔöÒ'ÑtÿÖGý{§y·ùó¯ýnÛZâÄxìºß¿0ÞšuÛà+Œ9àFKÿ dÁ?@0 _¯ð,X˜èUhá…žvŽ!ùÿ,ZX¸ §  !!!"""$$$%%%''')))+++---000222555888999:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYY[[[^^^```ccceeeggghhhjjjkkkmmmnnnoooppppppqqqrrrrrrssssssssstttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvwwwxxxxxxyyyzzz{{{|||}}}~~~€€€ƒƒƒ………‡‡‡‰‰‰ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÅÅÅÆÆÆÈÈÈÉÉÉÉÉÉÊÊÊËËËËËËÌÌÌÍÍÍÍÍÍÎÎÎÏÏÏÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââåååèèèëëëíííïïïñññòòòôôôõõõööö÷÷÷øøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ=hÑò¯`Aþýóbð_˜0 ÿ!D†¦ ›8yüŠ8ñ_¢†ŒqLñŸ¤IKª\ɲ¥Ë’ËFªÄ†MfÉqãl6TÇSç?}/ƒ J´¨Ñ£H“*]Êt¨ R£F*ÜÔð’%© >z䨫T úq̘”MÓFÄAÖ  l"4‘‰¸ç6 @Þƒþè@ø¯ÚÈ+^̸±ãÇ#KÎû¯^½É˜3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íØÜÉ쟊-þ½€aƒwD=~ŒŒÙŠ•+­oá2Z4Ÿâþ#Gn¤ºínD‹[:›Ù¿ÔVS®?gÿ’ý, ØHùÿ^ýcõ/ªÖIq_D6Ô°›{ÌDæåO‚Ö yVhá…¢Õ!ùÿ,[X¹ §  """%%%'''))),,,,,,---------.....................////////////////////////000000000111111222333444555666777888:::;;;===???AAACCCEEEHHHKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««­­­®®®®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÕÕÕ×××ÙÙÙÚÚÚÜÜÜÝÝÝÞÞÞààààààáááâââããããããåååæææçççèèèéééêêêëëëìììíííîîîðððñññóóóõõõöööøøøúúúüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þÿmáÒåŸAƒþü;xÍ?5k"ô‡N¢A>>>>>>>>?????????@@@@@@@@@AAAAAABBBBBBCCCCCCDDDEEEFFFGGGGGGHHHIIIJJJJJJKKKMMMNNNOOOQQQSSSUUUWWWYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››žžžŸŸŸ   ¡¡¡¢¢¢££££££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬¬¬¬­­­®®®°°°±±±²²²³³³´´´µµµ¶¶¶¸¸¸¹¹¹ºººººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÑÑÑÒÒÒÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââãããäääæææçççêêêíííðððóóóõõõ÷÷÷ùùùúúúüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þÿ üçåKºÿü)D(M›ƒúcøOψ%RD„cÂ… -YòH±¤É“(S2lÖÌ™Gÿ®a¸mÛKåÊ 4wîæÄëþ±c×!H•H“*]Ê´©Ó§P£Jê”Ô@PŸ|fb8I’:£G"ô5bXwî”Íxö_š4$©ÊãŒ>)‚øàsƒ† -XÈ;p‚|:ø'`æJžL¹²å˘3kÞ̹³ÊwžC‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀ“J¨€ìÄÿHTÁ¢¸ÙŸÿt<’Ä9[Vfù·å6/_Ö?bB‡öoZµkáaþ3÷ï:t„ƒËŸ¯]Oãÿ¶!¤6->°½ð¢‹O®ü£Ê?§üc•lNü£Ä?G ‘× ¥€B|ü3øô@dÿ P€Ì@߉(¦¨âiøüZ;ç!ùÿ,ZX½ §  """###$$$&&&(((***,,,...111333555888;;;>>>>>>>>>>>>>>>?????????????????????@@@@@@@@@@@@AAAAAAAAAAAABBBBBBBBBCCCCCCCCCDDDDDDEEEEEEFFFFFFGGGGGGHHHHHHHHHIIIJJJJJJKKKNNNRRRUUUXXX[[[^^^aaadddfffhhhkkklllnnnpppqqqrrrsssssstttttttttuuuuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwxxxyyyyyyzzz{{{|||}}}~~~ƒƒƒ„„„†††ˆˆˆ‹‹‹ŽŽŽ’’’•••™™™šššœœœžžžŸŸŸ¡¡¡¢¢¢£££¤¤¤¤¤¤¥¥¥¦¦¦¦¦¦§§§§§§§§§¨¨¨¨¨¨¨¨¨¨¨¨©©©©©©©©©ªªªªªªªªª««««««¬¬¬¬¬¬®®®°°°±±±³³³¶¶¶¸¸¸»»»½½½¿¿¿ÂÂÂÅÅÅÈÈÈÉÉÉÊÊÊËËËÌÌÌÌÌÌÍÍÍÍÍÍÎÎÎÎÎÎÎÎÎÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÑÑÑÑÑÑÑÑÑÑÑÑÒÒÒÒÒÒÓÓÓÓÓÓÔÔÔÕÕÕ×××ÙÙÙÝÝÝáááåååéééîîîóóó÷÷÷úúúûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ¡pùG /Ç ôçO!A2d*dèð"D RT)R¤Œ *¬D²¢É“(Sª¬,Ø0‚ǘQsÈœÂr8ËÑùAtèÒí$¸N!;v+“*]Ê´©Ó§P£JJµjŠO3ab6Ôá¤I\'ò,بQXcÿíÙçlH‡aâV[‘‹‚*R¸ýÇP… ‚%HŒ±·oA  8(ìOÅ¿`옮å˘3kÞ̹³çÏ C'M+º´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N\%–ü“€á¥XäÿNüC‘B…s´ÿn(t"%XWݸþjåú§ëß.^ÞÅ:GŽœNõ>…T§î{ñûøoC (T(ÐsCÙ$Î?Þlà H|‘† .Åì¤Ê?¡ä&Å?LüCDv14øœB&˜P‚†h­`Á?„€ †]Aäçâ‹0ÆÈZCîüƒÔ?!ùÿ,[X¸ §  !!!!!!"""""""""#####################$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%&&&&&&'''((()))***+++,,,---...000111333555777:::===@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz|||}}}~~~€€€€€€‚‚‚ƒƒƒƒƒƒ„„„………†††ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““•••–––———˜˜˜™™™ššš›››œœœœœœžžžžžžŸŸŸ¡¡¡¢¢¢£££¥¥¥¦¦¦§§§¨¨¨¨¨¨©©©ªªª««««««¬¬¬­­­¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜáááåååéééïïïòòòõõõ÷÷÷ùùùúúúûûûüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýùûG° 1­ ¨ðß›7p*d¨Ÿ> R,¸h£Œ ¼Ô°¤É“(Sª\X°YÁhÒnÜV°[7™¿5ç¿q Í[I´¨Ñ£H“*]Ê´©Ó§J7ìÔÉ•O…=²:QdAA‚qÕèõ_:tæŒ ©ð Ô·&ýI)¨#Gkÿ œòEÁ @êõÇBÁ ïE °Å„áJžL¹²å˘3kÞ̹óI©žC‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïß·ZQ!‚U8­Ðøwƒ Ž©’7L²$zWÛs56ÌØÕ†Ü¸M}ïîŸ8 ÀÓ«Ï-°gO‚ß¼yû®Ù2Ÿ¾Ú¢5ëê¨ÙQÑÐ> ×UÍð (l` YþÃÀ? $€Àƒ!E¸Þ†vèáj!ùÿ,]X¸ §  !!!!!!!!!!!!!!!!!!!!!!!!"""""""""######$$$%%%&&&'''((()))+++,,,---...000222444777:::===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxzzz{{{|||}}}~~~~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’”””•••–––———˜˜˜™™™ššš››››››œœœžžžŸŸŸ   ¡¡¡£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÏÏÏÐÐÐÑÑÑÒÒÒÒÒÒÓÓÓÔÔÔÕÕÕ×××ØØØÙÙÙÚÚÚÛÛÛßßßæææìììðððõõõ÷÷÷ùùùûûûüüüüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù«ó¯à¿1cÈ,2XP Á‚pâÄ‘³¡@†~þýTÑàEƒþ9rôˆá¿–Lª\ɲ¥Ë—ýýkf’Z5“·™äÆ §?o*¿}óN¥9y0“*]Ê´©Ó§P£JJõéGƒœ8mÊäÓäHG!-Ê4è ?ŒºœóONœ´béTëR \mÔ€“N †,ðm莆  >YØä‹ýU@·²å˘3kÞ̹³çÏ Yú{º´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ þ[àäÿM €Èç†:tìh.ö9C&N¨Ç´~[ ¯¿þY ûGÌ2µÿ´ýëɳëP†âÄŸOß÷ÕÝò·ûÚ?h!s z Å ¶ d‡A=üÃÊø´ A-”ÐA„bÙ¡À?d€Æ4a}$–h≮ $N@!ùÿ,_X¸ §  !!!"""###$$$%%%'''((()))***,,,---///111444777:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^```aaabbbccccccdddeeeffffffggghhhiiijjjkkkmmmnnnooopppqqqrrrssstttuuuvvvwwwyyyzzz{{{||||||}}}~~~€€€‚‚‚ƒƒƒ………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÞÞÞåååëëëðððõõõøøøúúúûûûüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù»ô¯ ™eΤ)ÈP Á‚rþÍ¡S‡aA‡4ˆÅ-*ØÈÑ#H~\ɲ¥Ë—0W |¶²šµ”þ¸­ìÖ 'Ëoß|ÆJ´¨Ñ£H“*]Ê´©Ó§ýYÜT0&œ–6*¸HÖ‚ úéÃk:åÄóæ+Ô·,Z²a‘Æ 5nj¨€×¢Üômè/«ÅÃ]̸±ãÇ#KžL¹²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÉ35°xBÅœ™èÞ(˜CGœš>>‰rÜokÀþ cxLÙ2ŸÙþmcÈÓgPpÿÂHýGî¶ùóÏ¥ìÙ“›N¿RiZ4VLèGW¬R¦¿Ú㟎9à€N˜¼ð ‰ Á€ðeb ð|¢gá…fÈ™?A!ùÿ,ZX½ §  !!!"""$$$%%%''')))+++---000444999===???AAACCCEEEFFFHHHIIIJJJKKKLLLMMMNNNOOOOOOPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQRRRRRRRRRRRRRRRRRRRRRRRRRRRSSSSSSSSSTTTUUUUUUVVVWWWXXXYYYZZZ\\\]]]___aaaccceeegggiiilllooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒ’’’”””–––˜˜˜šššœœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¥¥¥¦¦¦§§§¨¨¨©©©©©©ªªªªªª«««««««««¬¬¬¬¬¬­­­­­­®®®®®®¯¯¯°°°°°°±±±²²²³³³´´´µµµµµµ¶¶¶¸¸¸¸¸¸¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹ººººººººº»»»»»»¼¼¼½½½½½½¾¾¾¿¿¿ÁÁÁÂÂÂÃÃÃÅÅÅÇÇÇÈÈÈËËËÍÍÍÏÏÏÒÒÒÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßáááâââãããääääääåååæææèèèëëëíííðððóóóõõõ÷÷÷øøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ=˜ùG ?¼®!ȦM›‚þ‹ÑŽˆÿòòCP AƒaÔˆñŸ#G#ý•\ɲ¥Ë—/®¼†-åÊrål–\·N'ÌŸ@ƒ J´¨Ñ£H“*UªBSÊ„ÿ$Œéé¿F%zˆà?}øì±*â7>—ªeI¢ >¬BøÔ!ùÿ,[Xº §  !!!"""###$$$%%%&&&'''((()))***+++,,,---...///000111222333444555666777888999:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÝÝÝàààãããæææéééìììïïïòòòõõõ÷÷÷ùùùúúúûûûüüüüüüüüüýýýýýýýýýýýýýýýýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þÿmáÒÅË¿ƒýù{‡á6 ÿ)d1žˆ#þ;„ãB•,iI²¤É“&™1kæ‘"Bm0[ìæíà·o2ÿ‰wp¹œ(ƒ J´¨Ñ£H“*]Ê´h)R£D…ò˜î_¦†”&QeÑP!ªñÜQš¦hKÒ˜1CÙƒ&þ• ñöà ¨V @á „ êþ @ÚÈ+^̸±ãÇ#K6y.ïä˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íƒ.`À×P¡?)VðFè[£"Ã*DXå-[Xïê•\âòeÿœœV­zñ5qI‚ç}ùíóè]‡ ÎculÿªQs,b/^@>Mä ‘!îEÔ *øÏÿh¸À?†AHéUhá…vö[:æ”!ùÿ,[X¼ §  !!!###$$$%%%%%%&&&'''''''''(((((())))))***+++,,,...///111333444666777999:::<<<>>>@@@AAAAAABBBCCCDDDEEEEEEFFFGGGGGGHHHIIIJJJJJJKKKLLLMMMNNNPPPQQQRRRSSSUUUVVVXXXYYYYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ[[[[[[[[[\\\]]]]]]^^^___```aaabbbccceeefffhhhjjjlllnnnqqqsssvvvyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™šššœœœžžžŸŸŸ   ¡¡¡¢¢¢¢¢¢£££¤¤¤¥¥¥¥¥¥¦¦¦§§§©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÃÃÃÆÆÆÈÈÈËËËÍÍÍÏÏÏÑÑÑÔÔÔÖÖÖØØØÙÙÙÛÛÛÜÜÜÝÝÝÞÞÞÞÞÞßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßààààààààààààààààààààààààáááâââãããåååæææèèèêêêìììïïïòòòõõõøøøùùùûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþ2Í2þ¿üøo lÿù[˜p`: .ô×ðßž=N¬˜(QF… ^ºô±¢É“(SªHŒØ@cÆ %ܨLٲ̚ɔr »íÚ¹›Ù3Þ@yòæ]É´©Ó§P£JJµªÕ«X?yG”bCI‘¸òôš!±{ă-H²çÈ‘ã«]‚2€ñq¢ %~øÐwa 3`¸`¡°¿$@pÀ1付3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ NÜ®ÿ ¬p¡YÃ… þØÂ…ó¥ { rgo[ÿraýãå X÷´ÿŒ%L¦ì RT¨HÑ¢Œ Ąɡɓ(Sª\ùšÂjÕ¬]s¸ñ_8‚ãrÒlhNá9t;ÿ­søË£H“*]Ê´©Ó§P£JuCdÁN‚u ’Ö‰Vÿ $è«Æ°uêÐ1Òá™3SãšÔQp†Œ1@þcH— ‰$DèåûïBÁ û£+  ŠûÊL¹²å˘3kÞ̹³ç“5?‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀ{gñ'd‚ TíRÆ¿2”ƒe®P égÿ…ù'†öÀUÿ´YC–LÙւ߉·³ç¹@ÿ©:1¸ýû¶-X}oÎ\¹óÿdó5ÔL A¨˜ÒJP Ø6s}á€x`ñà\A*˜@áY<dÜlR‡ø•hâ‰(ÂO@!ùÿ,\X¸ §  !!!!!!!!!"""""""""""""""""""""########################$$$$$$$$$%%%%%%&&&'''((()))***+++,,,---///000333555888;;;===???@@@@@@AAABBBCCCDDDEEEGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyy{{{|||}}}~~~€€€‚‚‚‚‚‚ƒƒƒ„„„………‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““•••–––——————˜˜˜™™™™™™ššš››››››œœœžžžŸŸŸ   ¡¡¡£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛàààçççìììðððôôô÷÷÷ùùùúúúûûûüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù+ó¯à?1bÆh2XP ÃpàÄYÈÐ!Ã>}þP4h±à¢Œmlèa¦‡(Sª\ɲ忎ΠJ›öÐᶇܸÕ,Ùíá·o;á,gΥѣH“*]Ê´©Ó§P£2íXÐS§Nœv>|ôÈQÖŠ% è+ǰéü›#Ç,I†f¤ÊE)Ì¿qÜpûÒŸÝ1Xà[÷C û=ÀÀÅæJžL¹²å˘3kÞ̹³JªžC‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïß·ž1០—v·ñÇ?;’ƒ=Säß‘‚K˜H?{f íŽÀþW ûgì˜VƒÙþm˹ÓÛ? à N¿~n‡î²[íŸ4†Ë(sC´È‹V¤|çO\ÿQP<œV\2t‚žÅ`A €@†$mh߈$–hbj!ùÿ,^X¸ §  !!!!!!"""###$$$%%%&&&((()))***+++---...000222555888;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnpppqqqrrrsssssstttuuuvvvvvvxxxyyyzzz{{{|||}}}~~~€€€€€€‚‚‚ƒƒƒ„„„†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÞÞÞåååëëëðððõõõøøøúúúûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù;ô¯à2dÊà)ÈP Á‚pþÅ™³á?‡ ÿü $hÅ‹þ2*èè¤-]Âô±¥Ë—0cÊlòÙGjÕPúÛÖ²[7ÞZ~û¦Óå¼™H“*]Ê´©Ó§P£JúTàÇMÿ4e*ÊÐÑ¿FŒé4Ä0п?~úŒ-8⛉J¦û·îß;ͻӫ½€è?pÿ¼uÛÖ'ÆcÚýþû…±ÖsÛ½‚Q8€Ñ’€Yðè×+>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYY[[[^^^```ccceeeggghhhjjjkkkmmmnnnoooppppppqqqrrrrrrssssssssstttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvwwwxxxxxxyyyzzz{{{|||}}}~~~€€€ƒƒƒ………‡‡‡‰‰‰ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÍÍÍÎÎÎÎÎÎÏÏÏÐÐÐÑÑÑÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââåååèèèëëëíííïïïñññòòòôôôõõõööö÷÷÷øøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ=hÑò¯`Aþ”ýóbð_˜0 ÿ!T†¦ ›8yüŠ8ñ_¢†ŒqLñŸ¤IKª\ɲ¥Ë’ÉFªÄ†MfÉqãl6TÇSçËŸ@ƒ J´¨Ñ£H“*ª‚Ô¨‘175¼d *¤‚9Ú ÕcÃB„ºF3&åÒ³oˆ5(C†Ú†c6$Aâ­Á¸ `÷ ?¹î‹¶°áÈ+^̸±ãÇÖ«7/²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžMû5€6F6û§â_‹/`ä†ëowC=~è.iåÊê[¸F>+ù,šOqÿÆ‘#7RÝ¿vµÃ=‹w­Mìß j«I|wLc…¹¬!«©P­Nr„~D5 w—?õÍE€~g`ŽçàƒFøY=!ùÿ,[X¹ §  """%%%'''))),,,,,,---------.....................////////////////////////000000000111111222333444555666777888:::;;;===???AAACCCEEEHHHKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÕÕÕ×××ÙÙÙÚÚÚÜÜÜÝÝÝÞÞÞààààààáááâââããããããåååæææçççèèèéééêêêëëëìììíííîîîðððñññóóóõõõöööøøøúúúüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þÿmáÒåŸAƒþü¡;xÍ?5k"T(Ñ ž<¢ TÑСŒ+RªT±¤É“(Sª¬¸Œ3 %V«f fEqâÆ<¸ŽÁvív®J´¨Ñ£H“*]Ê´©Ó¤¥HòÜAL+QªZò¡ª~*æÁõâ5OÓ¦ôá£GYƒ!â‚xûOƒÝ 0'@p°àߪüo0j+^̸±ãÇ#KžL¹¤?|ãa¨Ì¹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÎí`êþyø77„Àÿ ùGÄà$À¡ü›r0‹–×¶þåÚ•üà³hÒ¦R%ïöœÁrV%&|o·û÷¶Õ¥9ßàµÕ¨Q£ÿÏØÁ`¿øÂ_E¦”òšÿ$‘}AH4ƒ $ðÇA]ÿdpÁVX¿Áçᇠ†ˆZ<ð!ùÿ,[X¼ § !!!"""###$$$%%%%%%&&&&&&''''''((()))***+++,,,---...000111222333555666777999:::<<<===>>>>>>>>>?????????@@@@@@@@@AAAAAABBBBBBCCCCCCDDDEEEFFFGGGGGGHHHIIIJJJJJJKKKMMMNNNOOOQQQSSSUUUWWWYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››žžžŸŸŸ   ¡¡¡¢¢¢££££££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬¬¬¬­­­®®®°°°±±±²²²³³³´´´µµµ¶¶¶¸¸¸¹¹¹ºººººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÑÑÑÒÒÒÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââãããäääæææçççêêêíííðððóóóõõõ÷÷÷ùùùúúúüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þÿ üçåKºÿü)D(M›ƒúcøOψ%RD„cÂ… -YòH±¤É“(SRlæÌ£Æ×° ܶÍ%Èråš;gsâÀuÿرk‡¤Ê£H“*]Ê´©Ó§P£JmJj ¨O=31œ$©'ÅB„¼2¼sG,Â4iHN];0Æ?/Ìñ¡ç Z°ÐÓÁÀ  èûOÀ°]̸±ãÇ#KžL¹²e•ï.kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸s#•P]Ñ…þ‘ø‡B ßêx$ òŒ ­ Ìòo l^¾žôùÚ¿iÕ®]iùÏÜ¿sèÐÉÕ;}lt<O܆Ú4³Àþõ⥫§«ªüsÊ?U­æÄ?JüsÄã-ôB) Ð wü3Lbÿ P€ÈàÞˆ$–h"høü“Y;ç!ùÿ,ZX½ §  """###$$$&&&(((***,,,...111333666888;;;>>>>>>>>>>>>>>>?????????????????????@@@@@@@@@@@@AAAAAAAAAAAABBBBBBBBBCCCCCCCCCDDDDDDEEEEEEFFFFFFGGGGGGHHHHHHHHHIIIJJJJJJKKKNNNRRRUUUXXX[[[^^^aaadddfffhhhkkklllnnnpppqqqrrrsssssstttttttttuuuuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwxxxyyyyyyzzz{{{|||}}}~~~ƒƒƒ„„„†††ˆˆˆ‹‹‹ŽŽŽ’’’•••™™™šššœœœžžžŸŸŸ¡¡¡¢¢¢£££¤¤¤¤¤¤¥¥¥¦¦¦¦¦¦§§§§§§§§§¨¨¨¨¨¨¨¨¨¨¨¨©©©©©©©©©ªªªªªªªªª««««««¬¬¬­­­¯¯¯°°°²²²´´´¶¶¶¹¹¹»»»½½½¿¿¿ÂÂÂÅÅÅÈÈÈÉÉÉÊÊÊËËËËËËÌÌÌÌÌÌÌÌÌÍÍÍÍÍÍÎÎÎÎÎÎÎÎÎÎÎÎÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÑÑÑÑÑÑÑÑÑÒÒÒÒÒÒÓÓÓÓÓÓÔÔÔÕÕÕ×××ÙÙÙÝÝÝáááåååéééíííñññôôôøøøûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ¡pùG /Ç ôçO!A2d*dèð"D RT)R¤Œ *¬D²¢É“(Sª¬LXAeϬ9dHNa¹›åfŠü‡Ž ºtét\§]»•H“*]Ê´©Ó§P£JJ5Å'‡™0)êpÒ¤­wlÔ¬F±ÿöì‰c6¤Ã0p©Ê­ÈbEA)Úþc¨ÂÁ$FˆÐË·  ö§â_‚,n<·²å˘3kÞ̹³çÏ ‘¢ Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ ®‹]‚ þIÀà2ìq‚(R¨h~öß …N¤Pw«ûÖ¿\ÿtgýÛÅ ׂãȑ˖翠ÕmO¼¾}Üâ¿ç‰îœÐšâüãÍ6Ï,V.·€´—?ªü nRüÃÄ?DX1:=÷ &”€¡süãAðáYþÀ},¶èâ‹«5äÎ?ì!ùÿ,[X¸ §  !!!!!!"""""""""#####################$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%&&&&&&'''((()))***+++,,,---...000111333555777:::===@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz|||}}}~~~€€€€€€‚‚‚ƒƒƒƒƒƒ„„„………†††ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““•••–––———˜˜˜™™™ššš›››œœœœœœžžžžžžŸŸŸ¡¡¡¢¢¢£££¥¥¥¦¦¦§§§¨¨¨¨¨¨©©©ªªª««««««¬¬¬­­­¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜáááåååéééïïïòòòõõõ÷÷÷ùùùúúúûûûüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýùûG° 1¬ ¨ðß›7p*d¨Ÿ> R,¸h£Œ ¼Ô°¤É“(Sª\X°YÁhÒnÜV°[7™¿5ç¿q Í[I´¨Ñ£H“*]Ê´©Ó§J7ìÔ©•O…=²:QdAA‚qÕèõ_:tæŒ ©ð Ô·&ýM)¨#Gkÿ ¤òEÁ @êõÇBÁ ïE °Å„áJžL¹²å˘3kÞ̹óI©žC‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïß·^ù×€ „Rá´Bãß ‚:v(ïj¥a’%ÓÉÚ˜«¡°aÆ®Q6äÆM|ÏpÿÄξ}n={üæÍ›x…Ì–ùô¥Ð­Y8™òÏ(³ TEC?ø]Hþ3Ã?0 °*85ÈÀ? $€…Ô¹çᇠ†ØÚ@!ùÿ,]X¸ §  !!!!!!!!!!!!!!!!!!!!!!!!"""""""""######$$$%%%&&&'''((()))+++,,,---...000222444777:::===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„„„„†††‡‡‡‡‡‡ˆˆˆ‰‰‰ŠŠŠŒŒŒŽŽŽ‘‘‘’’’”””•••–––———˜˜˜™™™ššš››››››œœœžžžŸŸŸ   ¡¡¡£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÏÏÏÐÐÐÑÑÑÒÒÒÒÒÒÓÓÓÔÔÔÕÕÕ×××ØØØÙÙÙÚÚÚÛÛÛßßßæææìììðððõõõ÷÷÷ùùùûûûüüüüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù³ó¯à¿1cÈ(2XP Á‚pâÄ‘³¡@†}þùùSÑàEƒŒþ5rôˆá¿ÿ0™\ɲ¥Ë—0úû×Ì$µj&/n3É[NÞV~ûö3ÜJsòb*]Ê´©Ó§P£JJµ*T”9qÚ”é§IGŽ…´8Ó` ü,òjpÎ?9qÖ’­cµîKtq´QC®GuZ0Ä`Á¯Ì:.P`øä@“tlXe€Ý˘3kÞ̹³çÏ C‹néïÁèÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N¼xpx›þ7¢ŸyêбÃt“LœX']·@^ÿ~\ýö˜1dlÿiûç³§W¢ ʼn3N¿>p¬Ýò»'ûÚ?hÿ0ó2ǤÇP,°ˆ›@wÔÃ?<ìÈOx0ÔB >>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^```aaabbbccccccdddeeeffffffggghhhiiijjjkkkmmmnnnooopppqqqrrrssstttuuuvvvwwwyyyzzz{{{||||||}}}~~~€€€‚‚‚ƒƒƒ………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÄÄÄÅÅÅÇÇÇÈÈÈÉÉÉÊÊÊÊÊÊËËËËËËÌÌÌÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÞÞÞåååëëëðððõõõøøøúúúûûûüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýùÃô¯ ™eΠ)ÈP Á‚rþÍ¡S‡aA‡4ˆÅ-*ØÈÑ#Hþ{ø±¥Ë—0cʼèZËjÖRúãÖ²[7.¿}:³¨Ñ£H“*]Ê´©Ó§P£Ò´¸©`&–4/1lTp‘"Zÿ*è§°uèH”ΰRã¾xɆE3ÒÀµ¨¡‚^‹t?"8ð·¡¿° (,·±ãÇ#KžL¹²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸+ ÔÔÀâ etj²{£`ÁûÓtÄâ“(ɾìß0†Æ’-šíß6†>R÷/Ü¿qär«_?Ýø?¹ñTþÏf³Éþ#Fô£+V)µ—É?=ü£Ã?9àp†N™¼ð ‰ Á‚Ê È @¡a²çᇠ†è™?C!ùÿ,ZX½ §  !!!"""$$$%%%''')))+++---000444999===???AAACCCEEEFFFHHHIIIJJJKKKLLLMMMNNNOOOOOOPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQRRRRRRRRRRRRRRRRRRRRRRRRRRRSSSSSSSSSTTTUUUUUUVVVWWWXXXYYYZZZ\\\]]]___aaaccceeegggiiilllooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒ’’’”””–––˜˜˜šššœœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¥¥¥¦¦¦§§§¨¨¨©©©©©©ªªªªªª«««««««««¬¬¬¬¬¬­­­­­­®®®®®®¯¯¯°°°°°°±±±²²²³³³´´´µµµµµµ¶¶¶¸¸¸¸¸¸¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹ººººººººº»»»»»»¼¼¼½½½½½½¾¾¾¿¿¿ÁÁÁÂÂÂÃÃÃÅÅÅÇÇÇÈÈÈËËËÍÍÍÏÏÏÒÒÒÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßáááâââãããääääääåååæææèèèëëëíííðððóóóõõõ÷÷÷øøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ=˜ùG ?Á®)ئMAƒÿÅyhÇÎÃù!( A„.f¼øÏ‘#‘þHª\ɲ¥K—U^ÆRe¹r5I®[—ó¥ÏŸ@ƒ J´¨Ñ£H“&U¡ %/‚’ F‚äô_£‡Š9 DðŸ>|öT•óð›žJÓ®<øô¡ =ª>|øþW¤à&O\ßÂ¥kyAcÿŽ!óî_º‚ëØJù$4·ùó¬á½sóûÌf1;F ìWÌr[Duʵ @ćCD3È Ã}*üsA<ÐÛ_åPXa‚=ˆÞ…f¨¡hûàSO@!ùÿ,[X» §  !!!"""$$$%%%'''(((******++++++,,,------...///000000111222222333333444555666777888:::<<<===???@@@BBBCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFFFFGGGHHHIIIJJJKKKLLLOOORRRUUUXXX[[[]]]```bbbdddfffgggggghhhiiiiiijjjjjjjjjkkkkkkkkkllllllmmmnnnooopppqqqrrrrrrssstttuuuuuuvvvvvvwwwxxxxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ………‡‡‡‰‰‰‹‹‹ŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââãããäääçççéééìììîîîðððòòòôôô÷÷÷úúúûûûüüüüüüýýýýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þÿmáBðŸAƒþüå;xPM†ÿ.„èçD‰ÿ)ZtQaÆJ–2ŠI²¤É’̘5ë8ñ 6mÛX$GΠ9s2ÿ©[gp»Ž'ƒ J´¨Ñ£H“*]Ê4i)R£D…ê8ï_&†”&QmQQ"ªûì ñÌ™¦hIÖ ACYƒ#þ‰ñÖà ¨.X À ‚êþ#0`@ÚÈ+^̸±ãÇ#K6é.ïä˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íŒ @h1á‡tãš@Á;¡¿Œ?Ox0Ë?-[¶°ÞÕ«êAãÿ–ýsfpZ5ë™Tÿ+÷ç9tà{¿Í¾ýëtèÐ匉í_5j,AìÅ+'ç©IaBt´ÞA+¤`‚eð@ð€ü€A`oîuèᇠfv<í´óO@!ùÿ,[X¼ §  """###$$$&&&''''''((())))))***++++++,,,...///000222333444666777999:::<<<>>>@@@AAAAAABBBCCCDDDEEEEEEFFFGGGGGGHHHIIIJJJJJJKKKLLLMMMNNNPPPQQQRRRSSSUUUVVVXXXYYYYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ[[[[[[[[[\\\]]]]]]^^^___```aaabbbccceeefffhhhjjjlllnnnqqqsssvvvyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™šššœœœžžžŸŸŸ   ¡¡¡¢¢¢¢¢¢£££¤¤¤¥¥¥¥¥¥¦¦¦§§§©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÂÂÂÅÅÅÇÇÇÊÊÊÌÌÌÎÎÎÐÐÐÓÓÓÕÕÕ×××ØØØÚÚÚÛÛÛÜÜÜÝÝÝÝÝÝÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞßßßßßßßßßßßßßßßßßßßßßßßßßßßàààáááãããåååçççéééëëëîîîñññôôôöööøøøúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþ2Í2þ¿üøo ›kÿù[˜p`: .ô×ðßž=N¬˜(QF… ^ºô±¢É“(Sª8ŒØÀbÅž%ܘLٲ̚}ÜHpÝ?víÚÍ ùÞ@yòæ ]É´©Ó§P£JJµªÕ«X?y7”bCI‘¸J$J!±Éă-H¯çÌ‘ã«]‚2Âx±s! %†áv"ˆ 5dÀ`¡ðB$@pÀ±?Èw3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N¼¸] þ9XC³†dQücÑ‚t¸{ b}io[ÿraýãåëW÷±ÿŒ%L–ì|Zu ݽ{wŸñûøwÓw÷/(;ŸcùóÜMÉüsŒ12X‘.¹$˜vÿŒÂ;äà`Z¡PÂ… …ðEà‡ y˜Ðä§âŠ,¶;!ùÿ,ZX¹ §  !!!""""""###$$$%%%%%%&&&&&&'''(((***+++,,,...000111333444666999;;;===@@@BBBEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGHHHHHHHHHIIIJJJJJJKKKLLLMMMNNNOOOPPPRRRSSSUUUWWWYYY[[[^^^```cccfffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~€€€‚‚‚ƒƒƒ„„„………†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœ   £££¥¥¥¨¨¨«««®®®±±±³³³µµµ¶¶¶···¸¸¸¹¹¹ººº»»»»»»»»»¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼½½½½½½½½½½½½½½½½½½½½½½½½½½½½½½¾¾¾ÀÀÀÁÁÁÂÂÂÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉËËËÌÌÌÍÍÍÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖÖÖÖ×××ØØØÙÙÙÚÚÚÜÜÜÞÞÞáááäääçççëëëîîîòòòôôôõõõööö÷÷÷ùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ™øûG° 2µ ô7Pá¿7o*dèOŸ> RT¨HÑ¢Œ Ąɡɓ(Sª\ùšÂjÕ¬]s¸ñ_8‚ãrÒlhNá9t;ÿ­søË£H“*]Ê´©Ó§P£JuCdÁN‚u ’Ö‰Vÿ $è«Æ°uêÐ1R!š3g¦Ê5©£à 1b€üǰ.A%HˆØÛ÷ß…‚*öWW@AûK¹²å˘3kÞ̹³çÏ'k‚Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒûÎâOÈ…2¨Ú)¤ Œ1d,Û\¡*ÓÏþ óOLí«þ[i=†,™²­¿…7ngÏsÿ€þS7t¢ðûøo[° ßœ¹rèý“Í?ÖP3M€¡bJ+ArÛ@Íù…áÅÃs©`B…gñPÐqÀaHægâ‰(¦<!ùÿ,\X¸ §  !!!!!!!!!"""""""""""""""""""""########################$$$$$$$$$%%%%%%&&&'''((()))***+++,,,---///000333555888;;;===???@@@@@@AAABBBCCCDDDEEEGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyy{{{|||}}}~~~€€€‚‚‚‚‚‚ƒƒƒ„„„………‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒ‘‘‘’’’“““”””•••–––———˜˜˜˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛàààçççìììðððôôô÷÷÷ùùùúúúûûûüüüýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù3ó¯à?1bÆh2XP ÃpàÄÉôÐ!Ã>}þPdh±à¢Œm4Øñßȇ(Sª\ÉreGg¥M«èïß¶‡Ü¸Ñü×íá·o4á,g®¥Ñ£H“*]Ê´©Ó§P£JUYòŸ'Nœ6ídè¨ëBŽ5 è+ɰéü›#ÇlC´ÿNK³Ì¿qÜpûO Ý1Xàë÷C û+s€!Š5ÐL¹²å˘3kÞ̹³gªp?‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀq DcÂ? ,Ñ$nãŽ:v(‹¦È¿#—0™~Í–ÚTýöÏØ±­³ÙÌIÓÛ? à N¿¾n‡î²[ å2eèD‹,±ìD xþœQPõÀ&4)(ƒA'h!X ”\xV†ö…(âˆ$®æP@!ùÿ,^X¸ §  !!!!!!"""###$$$%%%&&&((()))***+++---...000222555888;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnpppqqqrrrsssssstttuuuvvvvvvxxxyyyzzz{{{|||}}}~~~€€€€€€‚‚‚ƒƒƒ„„„†††‡‡‡ˆˆˆ‰‰‰ŠŠŠ‹‹‹ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÞÞÞåååëëëðððõõõøøøúúúûûûüüüýýýýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþÿÿÿ2Í2þýù;ô¯à2dÊà)ÈP Á‚pþÅ™³á?‡ ÿü $hÅ‹þ2*èè¤-]Âô±¥Ë—0cÊlòÙGjÕPúÛÖ²[7ÞZ~û¦Óå¼™H“*]Ê´©Ó§P£JúTàÇMÿ4e*ÊÐÑ¿FŒé4Ä0п?~úŒ-8â›PéHŒçÍ›«MÓº4õaaÐŒ!®Lm "@`— [ŒôUK¸°áÈ+^̸±ãÇ0ñáƒL¹²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžMÔAÊW¶ ZðÀåö?ÿrüӡÊïBþqbÅ lƒÿˆý3FY³”ÚVêšîߺï&CÓOõ ÿÀýóÖm[JšÃÙ £¬VÏýá˜‡ó»ø dÁ?@ðŸ_þ¼rÀC p`A:”'á„VÚ9!ùÿ,ZX¸ §  !!!"""$$$%%%''')))+++---000222555888999:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYY[[[^^^```ccceeeggghhhjjjkkkmmmnnnoooppppppqqqrrrrrrssssssssstttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvwwwxxxxxxyyyzzz{{{|||}}}€€€‚‚‚„„„†††‰‰‰ŒŒŒŽŽŽ‘‘‘’’’“““”””•••–––———˜˜˜™™™ššš›››œœœžžžŸŸŸ   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÎÎÎÏÏÏÏÏÏÐÐÐÑÑÑÒÒÒÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââåååèèèëëëíííïïïñññòòòôôôõõõööö÷÷÷øøøùùùúúúûûûüüüüüüýýýýýýþþþþþþþþþþþþþþþþþþþþþþþþþþþ2Í2þ=hÑò¯`Aþ–ýóbð_˜0 ÿ!\†¦ ›8yüŠ8±`"E5â˜0â?I“8š\ɲ¥Ë—&“‘\‰ ÛL“ãÆÝl¨®çN˜@ƒ J´¨Ñ£H“*]JT©Q$•ýÛÔ𒥨 >zä¨kÔ‚ˆ,DèkÄ1cT2]ñ†Yƒ2d¸mˆPjC$æ¬Ûp€zú³[€áÀl+^̸±ãÇ#KžL¹a½zó*kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸g`ƒ¤³*þµø÷Foºþ~7äÑã‡o“V®¼¾…‹$4cEû)îß8räHEªû×.·ùó²Õ¡»Ùý[Am6‘3û'û?aÀHÎ7Èê_*T¯%q„~ÙPÃq{ù³ŸA$P€ ` ÀƒèUhá…ŽVO@!þMade with ScreenToGif;documentdb-0.108-0/docs/v1/index.md000066400000000000000000000077121507310017400167170ustar00rootroot00000000000000# Welcome to DocumentDB **DocumentDB** is a fully open-source document-oriented database engine, built on PostgreSQL. It supports seamless CRUD operations on BSON data types, full-text search, geospatial queries, and vector embeddings — all within the robust PostgreSQL ecosystem. ## Getting Started with DocumentDB A curated collection of guides to help you understand what DocumentDB is, why it matters, and how to get up and running—from initial setup to advanced document operations. - [Introduction](v1/introduction.md) - [Why DocumentDB?](v1/why-documentdb.md) - [DocumentDB Gateway](v1/gateway.md) - [Prebuild Image](v1/prebuild-image.md) - [Getting Started](v1/get-started.md) - [Usage (CRUD)](v1/usage.md) - [Collection Management](v1/collection-management.md) - [Indexing](v1/indexing.md) - [Aggregation](v1/aggregation.md) - [Joins](v1/joins.md) - [Packaging](v1/packaging.md) --- ## 🚀 Features - Native PostgreSQL extension with BSON support - Powerful CRUD and indexing capabilities - Support for full-text search, geospatial data, and vector workloads - Fully open-source under the [MIT License](https://opensource.org/license/mit) - On-premises and cloud-ready deployment --- ## 🧱 Components - `pg_documentdb_core` – PostgreSQL extension for BSON type and operations - `pg_documentdb` – Public API layer enabling document-oriented access - `pg_documentdb_gw` – Gateway for DocumentDB, providing a MongoDB interface --- ## 🳠Quick Start with Docker ### Prebuild Image For DocumentDB There are prebuild images available for different platforms. You can find the list of prebuild images [here](v1/prebuild-image.md). To run the prebuild image, use the following command: ```bash # example for Ubuntu 22.04, PostgreSQL 16, amd64 # Choose the image tag according to your configuration docker run -dt mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0 docker exec -it bash ``` ### Prebuild Image For DocumentDB with Gateway To run the prebuild image with the DocumentDB Gateway, use the following command: ```bash docker run -dt -p 10260:10260 -e USERNAME= -e PASSWORD= ghcr.io/microsoft/documentdb/documentdb-local:latest mongosh localhost:10260 -u -p \ --authenticationMechanism SCRAM-SHA-256 \ --tls \ --tlsAllowInvalidCertificates ``` ### Build DocumentDB from Source ```bash git clone https://github.com/microsoft/documentdb.git cd documentdb docker build -f .devcontainer/Dockerfile -t documentdb . docker run -v $(pwd):/home/documentdb/code -it documentdb /bin/bash make && sudo make install ``` ### Community - Please refer to page for contributing to our [Roadmap list](https://github.com/orgs/microsoft/projects/1407/views/1). - [FerretDB](https://github.com/FerretDB/FerretDB) integration allows using DocumentDB as backend engine. Contributors and users can join the [DocumentDB Discord channel in the Microsoft OSS server](https://aka.ms/documentdb_discord) for quick collaboration. ### How to Contribute To contribute, see these documents: - [Code of Conduct](./CODE_OF_CONDUCT.md) - [Security](./SECURITY.md) - [Contributing](./CONTRIBUTING.md) ### FAQs Q1. While performing `make check` if you encounter error `FATAL: "/home/documentdb/code/pg_documentdb_core/src/test/regress/tmp/data" has wrong ownership`? Please drop the `/home/documentdb/code/pg_documentdb_core/src/test/regress/tmp/` directory and rerun the `make check`. Contributors and users can join the [DocumentDB Discord channel in the Microsoft OSS server](https://aka.ms/documentdb_discord) for quick collaboration. ### License **DocumentDB** is licensed under the MIT License. See [LICENSE](./LICENSE.txt) for details. ### Trademarks This project may use trademarks or logos. Use of Microsoft trademarks must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks). Use of third-party marks is subject to their policies. documentdb-0.108-0/docs/v1/indexing.md000066400000000000000000000022701507310017400174070ustar00rootroot00000000000000 ### Indexing #### Create an Index DocumentDB uses the `documentdb_api.create_indexes_background` function, which allows background index creation without disrupting database operations. The SQL command demonstrates how to create a `single field` index on `age` on the `patient` collection of the `documentdb`. ```sql SELECT * FROM documentdb_api.create_indexes_background('documentdb', '{ "createIndexes": "patient", "indexes": [{ "key": {"age": 1},"name": "idx_age"}]}'); ``` The SQL command demonstrates how to create a `compound index` on fields age and registration_year on the `patient` collection of the `documentdb`. ```sql SELECT * FROM documentdb_api.create_indexes_background('documentdb', '{ "createIndexes": "patient", "indexes": [{ "key": {"registration_year": 1, "age": 1},"name": "idx_regyr_age"}]}'); ``` #### Drop an Index DocumentDB uses the `documentdb_api.drop_indexes` function, which allows you to remove an existing index from a collection. The SQL command demonstrates how to drop the index named `id_ab_1` from the `first_collection` collection of the `documentdb`. ```sql CALL documentdb_api.drop_indexes('documentdb', '{"dropIndexes": "patient", "index":"idx_age"}'); ```documentdb-0.108-0/docs/v1/introduction.md000066400000000000000000000021041507310017400203170ustar00rootroot00000000000000# Introduction `DocumentDB` is the engine powering vCore-based Azure Cosmos DB for MongoDB. It offers a native implementation of document-oriented NoSQL database, enabling seamless CRUD operations on BSON data types within a PostgreSQL framework. Beyond basic operations, DocumentDB empowers you to execute complex workloads, including full-text searches, geospatial queries, and vector embeddings on your dataset, delivering robust functionality and flexibility for diverse data management needs. [PostgreSQL](https://www.postgresql.org/about/) is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. ## Components The project comprises of two primary components, which work together to support document operations. - **pg_documentdb_core :** PostgreSQL extension introducing BSON datatype support and operations for native Postgres. - **pg_documentdb :** The public API surface for DocumentDB providing CRUD functionality on documents in the store.documentdb-0.108-0/docs/v1/joins.md000066400000000000000000000035151507310017400167270ustar00rootroot00000000000000### Join data from multiple collections Let's create an additional collection named `appointment` to demonstrate how a join operation can be performed. ```sql select documentdb_api.insert_one('documentdb','appointment', '{"appointment_id": "A001", "patient_id": "P001", "doctor_name": "Dr. Milind", "appointment_date": "2023-01-20", "reason": "Routine checkup" }'); select documentdb_api.insert_one('documentdb','appointment', '{"appointment_id": "A002", "patient_id": "P001", "doctor_name": "Dr. Moore", "appointment_date": "2023-02-10", "reason": "Follow-up"}'); select documentdb_api.insert_one('documentdb','appointment', '{"appointment_id": "A004", "patient_id": "P003", "doctor_name": "Dr. Smith", "appointment_date": "2024-03-12", "reason": "Allergy consultation"}'); select documentdb_api.insert_one('documentdb','appointment', '{"appointment_id": "A005", "patient_id": "P004", "doctor_name": "Dr. Moore", "appointment_date": "2024-04-15", "reason": "Migraine treatment"}'); select documentdb_api.insert_one('documentdb','appointment', '{"appointment_id": "A007","patient_id": "P001", "doctor_name": "Dr. Milind", "appointment_date": "2024-06-05", "reason": "Blood test"}'); select documentdb_api.insert_one('documentdb','appointment', '{ "appointment_id": "A009", "patient_id": "P003", "doctor_name": "Dr. Smith","appointment_date": "2025-01-20", "reason": "Follow-up visit"}'); ``` The example presents each patient along with the doctors visited. ```sql SELECT cursorpage FROM documentdb_api.aggregate_cursor_first_page('documentdb', '{ "aggregate": "patient", "pipeline": [ { "$lookup": { "from": "appointment","localField": "patient_id", "foreignField": "patient_id", "as": "appointment" } },{"$unwind":"$appointment"},{"$project":{"_id":0,"name":1,"appointment.doctor_name":1,"appointment.appointment_date":1}} ], "cursor": { "batchSize": 3 } }'); ```documentdb-0.108-0/docs/v1/packaging.md000066400000000000000000000006721507310017400175320ustar00rootroot00000000000000# To Build Your Own Debian Packages With Docker Run `./packaging/build_packages.sh -h` and follow the instructions. E.g. to build for Debian 12 and PostgreSQL 16, run: ```sh ./packaging/build_packages.sh --os deb12 --pg 16 ``` Packages can be found at the `packages` directory by default, but it can be configured with the `--output-dir` option. **Note:** The packages do not include pg_documentdb_distributed in the `internal` directory.documentdb-0.108-0/docs/v1/prebuild.md000066400000000000000000000013541507310017400174120ustar00rootroot00000000000000# To Build Ubuntu prebuild image E.g. to build for Ubuntu 22.04, PostgreSQL 16, amd64 and documentdb_0.103.0, run: ```sh docker build -t -f .github/containers/Build-Ubuntu/Dockerfile_prebuild \ --platform=linux/amd64 --build-arg BASE_IMAGE=ubuntu:22.04 --build-arg POSTGRES_VERSION=16 \ --build-arg DEB_PACKAGE_REL_PATH=packaging/packages/ubuntu22.04-postgresql-16-documentdb_0.103.0_amd64.deb . ``` ## To use the image Step 1: Running the container in detached mode ```sh docker run -dt docker exec -it bash ``` Step 2: Connect to psql shell ```sh psql -p 9712 -d postgres ``` ## Prebuild Image List Check the [prebuild image list](./prebuild_image_list.md) for the latest prebuild images.documentdb-0.108-0/docs/v1/prebuild_image_list.md000066400000000000000000000052461507310017400216130ustar00rootroot00000000000000# Documentdb Prebuild Docker Images List ## v0.103.0 ### Ubuntu 22.04 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG17-AMD64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 17 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:5c7765af1ac51ff894e2795d5ee8c6bcca7ea90159d38c40b1c164feef18037d - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG17-ARM64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 17 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:98d8abfb65f8dbb23dcd87d819496af0c9955c0234ff542ff18c16a294d6478f - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-AMD64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 16 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:e0f2b7c9115bec5692679fe3afe2eaf1dc268db14282585cc7bae047cd50325c - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:22.04-PG16-ARM64-0.103.0` - **OS:** Ubuntu 22.04 - **Database:** PostgreSQL 16 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:62e2b4c2f39de9e81c432a889d4268cfc1c335cbe4878517ee0760ea33739477 ### Ubuntu 24.04 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG17-AMD64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 17 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:a6f72e31c9d9b39a7ac201ac41f6d77b439e048d892f6edddcb4b06774cc6292 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG17-ARM64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 17 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:621eb5f5ea380d152a254a2f2d35e169c3ae217cb940f6090fbb07040dcd2c67 - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG16-AMD64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 16 - **Architecture:** AMD64 - **Version:** 0.103.0 - **Digest:** sha256:dc4f0155e545ae14bcf65d31d4b9d21c8fdfee42d467f3419106ced8e141a6bd - **Image Name:** `mcr.microsoft.com/cosmosdb/ubuntu/documentdb-oss:24.04-PG16-ARM64-0.103.0` - **OS:** Ubuntu 24.04 - **Database:** PostgreSQL 16 - **Architecture:** ARM64 - **Version:** 0.103.0 - **Digest:** sha256:162df47ba5e8b10f88d7bd0e2e7c5775e764774928920ea532c372c5ee360b24 ## Notes - Ensure each image meets your environment requirements and compatibility needs. - Refer to the official documentation for setup instructions and best practices. documentdb-0.108-0/docs/v1/usage.md000066400000000000000000000067511507310017400167160ustar00rootroot00000000000000 ## Usage Once you have your `DocumentDB` set up running, you can start with creating collections, indexes and perform queries on them. ### Create a collection DocumentDB provides [documentdb_api.create_collection](https://github.com/microsoft/documentdb/wiki/Functions#create_collection) function to create a new collection within a specified database, enabling you to manage and organize your BSON documents effectively. ```sql SELECT documentdb_api.create_collection('documentdb','patient'); ``` ### Perform CRUD operations #### Insert documents The [documentdb_api.insert_one](https://github.com/microsoft/documentdb/wiki/Functions#insert_one) command is used to add a single document into a collection. ```sql select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P001", "name": "Alice Smith", "age": 30, "phone_number": "555-0123", "registration_year": "2023","conditions": ["Diabetes", "Hypertension"]}'); select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P002", "name": "Bob Johnson", "age": 45, "phone_number": "555-0456", "registration_year": "2023", "conditions": ["Asthma"]}'); select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P003", "name": "Charlie Brown", "age": 29, "phone_number": "555-0789", "registration_year": "2024", "conditions": ["Allergy", "Anemia"]}'); select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P004", "name": "Diana Prince", "age": 40, "phone_number": "555-0987", "registration_year": "2024", "conditions": ["Migraine"]}'); select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P005", "name": "Edward Norton", "age": 55, "phone_number": "555-1111", "registration_year": "2025", "conditions": ["Hypertension", "Heart Disease"]}'); ``` #### Read document from a collection The `documentdb_api.collection` function is used for retrieving the documents in a collection. ```sql SELECT document FROM documentdb_api.collection('documentdb','patient'); ``` Alternatively, we can apply filter to our queries. ```sql SET search_path TO documentdb_api, documentdb_core; SET documentdb_core.bsonUseEJson TO true; SELECT cursorPage FROM documentdb_api.find_cursor_first_page('documentdb', '{ "find" : "patient", "filter" : {"patient_id":"P005"}}'); ``` We can perform range queries as well. ```sql SELECT cursorPage FROM documentdb_api.find_cursor_first_page('documentdb', '{ "find" : "patient", "filter" : { "$and": [{ "age": { "$gte": 10 } },{ "age": { "$lte": 35 } }] }}'); ``` #### Update document in a collection DocumentDB uses the [documentdb_api.update](https://github.com/microsoft/documentdb/wiki/Functions#update) function to modify existing documents within a collection. The SQL command updates the `age` for patient `P004`. ```sql select documentdb_api.update('documentdb', '{"update":"patient", "updates":[{"q":{"patient_id":"P004"},"u":{"$set":{"age":14}}}]}'); ``` Similarly, we can update multiple documents using `multi` property. ```sql SELECT documentdb_api.update('documentdb', '{"update":"patient", "updates":[{"q":{},"u":{"$set":{"age":24}},"multi":true}]}'); ``` #### Delete document from the collection DocumentDB uses the [documentdb_api.delete](https://github.com/microsoft/documentdb/wiki/Functions#delete) function for precise document removal based on specified criteria. The SQL command deletes the document for patient `P002`. ```sql SELECT documentdb_api.delete('documentdb', '{"delete": "patient", "deletes": [{"q": {"patient_id": "P002"}, "limit": 1}]}'); ```documentdb-0.108-0/docs/v1/why-documentdb.md000066400000000000000000000047211507310017400205360ustar00rootroot00000000000000## Why DocumentDB ? At DocumentDB, we believe in the power of open-source to drive innovation and collaboration. Our commitment to being a fully open-source document database means that we are dedicated to transparency, community involvement, and continuous improvement. We are open-sourced under the most permissive [MIT](https://opensource.org/license/mit) license, where developers and organizations alike have no restrictions incorporating the project into new and existing solutions of their own. DocumentDB introduces the BSON data type and provides APIs for seamless operation within native PostgreSQL, enhancing efficiency and aligning with operational advantages. DocumentDB also provides a powerful on-premise solution, allowing organizations to maintain full control over their data and infrastructure. This flexibility ensures that you can deploy it in your own environment, meeting your specific security, compliance, and performance requirements. With DocumentDB, you get the best of both worlds: the innovation of open-source and the control of on-premise deployment. ### Based on Postgres DocumentDB is built on top of PostgreSQL, one of the most advanced and reliable open-source relational database systems available. We chose PostgreSQL as our base layer for several reasons: 1. **Proven Stability and Performance**: PostgreSQL has a long history of stability and performance, making it a trusted choice for mission-critical applications. 2. **Extensibility**: Their extensible architecture allows us to integrate a DocumentDB API on BSON data type seamlessly, providing the flexibility to handle both relational and document data. 3. **Active Community**: PostgreSQL has a vibrant and active community that continuously contributes to its development, ensuring that it remains at the forefront of database technology. 4. **Advanced Features**: PostgreSQL offers a rich set of features, including advanced indexing, full-text search, and powerful querying capabilities, which enhance the functionality of DocumentDB. 5. **Compliance and Security**: PostgreSQL's robust security features and compliance with various standards make it an ideal choice for organizations with stringent security and regulatory requirements. By building on PostgreSQL, DocumentDB leverages these strengths to provide a powerful, flexible, and reliable document database that meets the need of modern applications. DocumentDB will continue to benefit from the advancements brought into the PostgreSQL ecosystem.documentdb-0.108-0/documentdb_errors.csv000066400000000000000000000257471507310017400202550ustar00rootroot00000000000000OrdinalPosition,ErrorName 1,InternalError 2,BadValue 3,GraphContainsCycle 4,FailedToParse 5,TypeMismatch 6,Overflow 7,IllegalOperation 8,AlreadyInitialized 9,NamespaceNotFound 10,IndexNotFound 11,PathNotViable 12,RoleNotFound 13,CannotBackfillArray 14,ConflictingUpdateOperators 15,CursorNotFound 16,NamespaceExists 17,DollarPrefixedFieldName 18,CanNotBeTypeArray 19,NotSingleValueField 20,EmptyFieldName 21,DottedFieldName 22,ShardKeyNotFound 23,ImmutableField 24,CannotCreateIndex 25,IndexAlreadyExists 26,InvalidOptions 27,InvalidNamespace 28,IndexOptionsConflict 29,IndexKeySpecsConflict 30,NotExactValueField 31,CommandNotSupported 32,NamespaceNotSharded 33,ExceededMemoryLimit 34,DurationOverflow 35,ViewDepthLimitExceeded 36,CommandNotSupportedOnView 37,OptionNotSupportedOnView 38,AmbiguousIndexKeyPattern 39,InvalidIndexSpecificationOption 40,QueryFeatureNotAllowed 41,MaxSubPipelineDepthExceeded 42,ConversionFailure 43,OperationNotSupportedInTransaction 44,IndexBuildAborted 45,UnableToFindIndex 46,CollectionUUIDMismatch 47,Location10065 48,BsonObjectTooLarge 49,DuplicateKey 50,BackgroundOperationInProgressForNamespace 51,Location13026 52,Location13027 53,Location13068 54,MergeStageNoMatchingDocument 55,DbAlreadyExists 56,Location13548 57,Location15947 58,Location15952 59,Location15955 60,Location15957 61,Location15958 62,Location15959 63,Location15972 64,Location15976 65,Location15981 66,Location16004 67,Location16006 68,Location16007 69,Location16020 70,Location6045000 71,Location16034 72,Location16035 73,Location16410 74,Location16411 75,Location16433 76,DollarAddNumericOrDateTypes 77,DollarModByZeroProhibited 78,DollarModOnlyNumeric 79,DollarAddOnlyOneDate 80,Location16702 81,Location16747 82,Location16748 83,Location16749 84,Location16755 85,Location16764 86,HashedIndexDoNotSupportArrayValues 87,Location16800 88,Location16801 89,Location16804 90,Location16874 91,Location16875 92,Location16876 93,Location16878 94,Location16879 95,Location16880 96,Location16882 97,Location16883 98,Location16994 99,Location17040 100,Location17041 101,Location17042 102,Location17043 103,Location17044 104,Location17045 105,Location17046 106,Location17047 107,Location17048 108,Location17049 109,DollarCondMissingIfParameter 110,DollarCondMissingThenParameter 111,DollarCondMissingElseParameter 112,DollarCondBadParameter 113,DollarSizeRequiresArray 114,ExactlyOneTextIndex 115,Location17261 116,Location17276 117,Location17308 118,Location17310 119,DocumentAfterUpdateLargerThanMaxSize 120,DocumentToUpsertLargerThanMaxSize 121,Location18628 122,Location18629 123,Location18533 124,Location18534 125,Location18535 126,Location18536 127,Location18537 128,Location28625 129,Location28646 130,Location28647 131,Location28648 132,Location28650 133,Location28651 134,Location28656 135,Location28657 136,Location28664 137,Location51044 138,Location51045 139,Location50989 140,RangeArgumentExpressionArgsOutOfRange 141,DollarAbsCantTakeLongMinValue 142,ArrayOperatorElemAtFirstArgMustBeArray 143,DollarArrayElemAtSecondArgArgMustBeNumeric 144,DollarArrayElemAtSecondArgArgMustBe32Bit 145,DollarSqrtGreaterOrEqualToZero 146,DollarSliceInvalidInput 147,DollarSliceInvalidTypeSecondArg 148,DollarSliceInvalidValueSecondArg 149,DollarSliceInvalidTypeThirdArg 150,DollarSliceInvalidValueThirdArg 151,DollarSliceInvalidSignThirdArg 152,Location28745 153,Location28746 154,Location28747 155,Location28748 156,Location28749 157,DollarLogArgumentMustBeNumeric 158,DollarLogBaseMustBeNumeric 159,DollarLogNumberMustBePositive 160,DollarLogBaseMustBeGreaterThanOne 161,DollarLog10MustBePositiveNumber 162,DollarPowBaseMustBeNumeric 163,DollarPowExponentMustBeNumeric 164,DollarPowExponentInvalidForZeroBase 165,Location28765 166,DollarLnMustBePositiveNumber 167,Location28769 168,Location28803 169,Location28808 170,Location28809 171,Location28810 172,Location28811 173,Location28812 174,Location28818 175,Location28822 176,KeyCannotContainNullByte 177,Location31002 178,Location31022 179,Location31023 180,Location31024 181,Location31034 182,Location31095 183,Location31109 184,Location31119 185,Location31120 186,Location31138 187,Location31249 188,Location31250 189,Location31253 190,Location31254 191,Location31256 192,Location31271 193,Location31276 194,Location31308 195,Location31325 196,Location31393 197,Location31395 198,Location34435 199,Location31441 200,Location34443 201,Location34444 202,Location34445 203,Location34446 204,Location34447 205,Location34448 206,Location34449 207,Location34450 208,Location34451 209,Location34452 210,Location34453 211,Location34454 212,Location34455 213,Location34460 214,Location34461 215,Location34462 216,Location34463 217,Location34464 218,Location34465 219,Location34466 220,Location34467 221,Location34468 222,Location34471 223,Location34473 224,DollarSwitchRequiresObject 225,DollarSwitchRequiresArrayForBranches 226,DollarSwitchRequiresObjectForEachBranch 227,DollarSwitchUnknownArgumentForBranch 228,DollarSwitchRequiresCaseExpressionForBranch 229,DollarSwitchRequiresThenExpressionForBranch 230,DollarSwitchNoMatchingBranchAndNoDefault 231,DollarSwitchBadArgument 232,DollarSwitchRequiresAtLeastOneBranch 233,Location40075 234,Location40076 235,Location40077 236,Location40078 237,Location40079 238,Location40080 239,DollarInRequiresArray 240,Location40085 241,Location40086 242,Location40087 243,Location40090 244,Location40091 245,Location40092 246,Location40093 247,Location40094 248,Location40096 249,Location40097 250,Location40100 251,Location40101 252,Location40102 253,Location40103 254,Location40104 255,Location40105 256,Location40147 257,Location40156 258,Location40158 259,Location40160 260,Location40169 261,Location40177 262,Location40185 263,Location40191 264,Location40192 265,Location40193 266,Location40194 267,Location40195 268,Location40196 269,Location40197 270,Location40198 271,Location40199 272,Location40200 273,Location40201 274,Location40202 275,Location40218 276,Location40228 277,Location40234 278,Location40238 279,Location40272 280,Location40319 281,Location40321 282,Location40323 283,UnrecognizedCommand 284,Location40352 285,DollarArrayToObjectRequiresArray 286,DollarObjectToArrayRequiresObject 287,DollarArrayToObjectAllMustBeObjects 288,DollarArrayToObjectIncorrectNumberOfKeys 289,DollarArrayToObjectRequiresObjectWithKAndV 290,DollarArrayToObjectObjectKeyMustBeString 291,DollarArrayToObjectArrayKeyMustBeString 292,DollarArrayToObjectAllMustBeArrays 293,DollarArrayToObjectIncorrectArrayLength 294,DollarArrayToObjectBadInputTypeFormat 295,DollarMergeObjectsInvalidType 296,Location40414 297,UnknownBsonField 298,Location40485 299,Location40489 300,Location40515 301,Location40516 302,Location40517 303,Location40518 304,Location40519 305,Location40520 306,Location40521 307,Location40522 308,Location40523 309,Location40524 310,Location40525 311,Location40533 312,Location40535 313,Location40536 314,Location40539 315,Location40540 316,Location40541 317,Location40542 318,Location40600 319,Location40601 320,Location40602 321,Location40603 322,Location40235 323,Location40237 324,ChangeStreamBadResumeToken 325,Location40684 326,Location50694 327,Location50695 328,Location50696 329,Location50699 330,Location50700 331,Location50723 332,Location50752 333,Location50759 334,Location51024 335,Location51047 336,Location51074 337,Location51075 338,DollarRoundOverflowInt64 339,DollarRoundFirstArgMustBeNumeric 340,DollarRoundPrecisionMustBeIntegral 341,DollarRoundPrecisionOutOfRange 342,Location51091 343,Location51103 344,Location51104 345,Location51105 346,Location51106 347,Location51107 348,Location51108 349,Location51109 350,Location51110 351,Location51111 352,Location51132 353,Location51134 354,Location51151 355,Location51156 356,Location51178 357,Location51183 358,Location51185 359,Location51186 360,Location51187 361,Location51191 362,Location51246 363,Location51276 364,Location51247 365,Location51743 366,Location51744 367,Location51745 368,Location51746 369,Location51747 370,Location51748 371,Location51749 372,Location51750 373,Location51751 374,Location327391 375,Location327392 376,DollarIfNullRequiresAtLeastTwoArgs 377,DollarRandNonEmptyArgument 378,IntermediateResultTooLarge 379,DollarSetFieldRequiresObject 380,DollarSetFieldUnknownArgument 381,Location2942500 382,Location2942501 383,Location2942502 384,Location2942503 385,Location2942504 386,Location2942505 387,Location2942506 388,Location3041701 389,Location3041702 390,Location3041703 391,Location4161102 392,Location4161103 393,Location4161104 394,Location4161105 395,Location4161106 396,Location4161107 397,Location4161108 398,Location4161109 399,Location4890500 400,Location4940400 401,Location4940401 402,Location5166400 403,Location5166401 404,Location5166402 405,Location5166403 406,Location5166404 407,Location5166405 408,Location5166406 409,Location5107200 410,Location5107201 411,Location5166301 412,Location5166302 413,Location5166303 414,Location5166304 415,Location5166305 416,Location5166307 417,Location5339900 418,Location5339901 419,Location5339902 420,Location5429413 421,Location5429414 422,Location5429513 423,Location5439007 424,Location5439008 425,Location5439009 426,Location5439010 427,Location5439012 428,Location5439013 429,Location5439014 430,Location5439015 431,Location5439016 432,Location5439017 433,Location5439018 434,Location5626500 435,Location5654600 436,Location5654601 437,Location5654602 438,Location5687301 439,Location5687302 440,Location5687400 441,Location5687401 442,Location5746102 443,Location5787801 444,Location5787900 445,Location5787901 446,Location5787902 447,Location5787903 448,Location5787906 449,Location5787907 450,Location5787908 451,Location5788200 452,Location5858203 453,Location5976500 454,Location5371601 455,Location5371602 456,Location5371603 457,DocumentFailedValidation 458,Location605001 459,Location6050106 460,Location16990 461,Location13111 462,Location5788001 463,Location5788002 464,Location5788003 465,Location5788004 466,Location5788005 467,Location5733201 468,Location5733401 469,Location5733402 470,Location5733403 471,Location5733406 472,Location5733408 473,Location5733409 474,Location5876900 475,Location5897900 476,Location5946802 477,Location6007200 478,Location6053600 479,Location6586400 480,Location8993000 481,Location5423900 482,Location5423901 483,Location5423902 484,Location5490710 485,Location5624900 486,Location5624901 487,Location6050202 488,Location6050204 489,Location5788604 490,Location31170 491,Location31465 492,Location40181 493,InvalidLength 494,Location15998 495,Location40229 496,UserCountLimitExceeded 497,Location55 498,Location40236 499,Location17053 500,Location7429703 501,Location7436100 502,Location7750301 503,Location7750302 504,Location7750303 505,Location51003 506,Location7749501 507,Location5860402 508,Location7555701 509,Location7555702 510,Location3041704 511,Location4341107 512,InsufficientPrivilege 513,NotWritablePrimary 514,Location40239 515,Location40240 516,Location40241 517,Location40242 518,Location40243 519,Location40244 520,Location40245 521,Location40246 522,Location40257 523,Location40258 524,Location40260 525,Location40261 526,CursorInUse, 527,Location13103 528,Location17385 529,Location31319 530,Location31320 531,Location31321documentdb-0.108-0/error_mappings.csv000066400000000000000000000303441507310017400175510ustar00rootroot00000000000000ErrorMapping,ErrorName 1,InternalError 2,BadValue 5,GraphContainsCycle 9,FailedToParse 14,TypeMismatch 15,Overflow 16,InvalidLength 20,IllegalOperation 23,AlreadyInitialized 26,NamespaceNotFound 27,IndexNotFound 28,PathNotViable 31,RoleNotFound 34,CannotBackfillArray 40,ConflictingUpdateOperators 43,CursorNotFound 48,NamespaceExists 52,DollarPrefixedFieldName 53,CanNotBeTypeArray 54,NotSingleValueField 55,Location55 56,EmptyFieldName 57,DottedFieldName 61,ShardKeyNotFound 66,ImmutableField 67,CannotCreateIndex 68,IndexAlreadyExists 72,InvalidOptions 73,InvalidNamespace 85,IndexOptionsConflict 86,IndexKeySpecsConflict 111,NotExactValueField 115,CommandNotSupported 118,NamespaceNotSharded 121,DocumentFailedValidation 143,CursorInUse 146,ExceededMemoryLimit 159,DurationOverflow 165,ViewDepthLimitExceeded 166,CommandNotSupportedOnView 167,OptionNotSupportedOnView 181,AmbiguousIndexKeyPattern 197,InvalidIndexSpecificationOption 224,QueryFeatureNotAllowed 232,MaxSubPipelineDepthExceeded 241,ConversionFailure 263,OperationNotSupportedInTransaction 276,IndexBuildAborted 291,UnableToFindIndex 361,CollectionUUIDMismatch 8000,UserCountLimitExceeded 10065,Location10065 10107,NotWritablePrimary 10334,BsonObjectTooLarge 11000,DuplicateKey 12587,BackgroundOperationInProgressForNamespace 13026,Location13026 13027,Location13027 13068,Location13068 13103,Location13103 13111,Location13111 13113,MergeStageNoMatchingDocument 13297,DbAlreadyExists 13548,Location13548 15947,Location15947 15952,Location15952 15955,Location15955 15957,Location15957 15958,Location15958 15959,Location15959 15972,Location15972 15976,Location15976 15981,Location15981 15998,Location15998 16004,Location16004 16006,Location16006 16007,Location16007 16020,Location16020 16034,Location16034 16035,Location16035 16410,Location16410 16411,Location16411 16433,Location16433 16554,DollarAddNumericOrDateTypes 16610,DollarModByZeroProhibited 16611,DollarModOnlyNumeric 16612,DollarAddOnlyOneDate 16702,Location16702 16747,Location16747 16748,Location16748 16749,Location16749 16755,Location16755 16764,Location16764 16766,HashedIndexDoNotSupportArrayValues 16800,Location16800 16801,Location16801 16804,Location16804 16874,Location16874 16875,Location16875 16876,Location16876 16878,Location16878 16879,Location16879 16880,Location16880 16882,Location16882 16883,Location16883 16990,Location16990 16994,Location16994 17040,Location17040 17041,Location17041 17042,Location17042 17043,Location17043 17044,Location17044 17045,Location17045 17046,Location17046 17047,Location17047 17048,Location17048 17049,Location17049 17053,Location17053 17080,DollarCondMissingIfParameter 17081,DollarCondMissingThenParameter 17082,DollarCondMissingElseParameter 17083,DollarCondBadParameter 17124,DollarSizeRequiresArray 17194,ExactlyOneTextIndex 17261,Location17261 17276,Location17276 17308,Location17308 17310,Location17310 17385,Location17385 17419,DocumentAfterUpdateLargerThanMaxSize 17420,DocumentToUpsertLargerThanMaxSize 18533,Location18533 18534,Location18534 18535,Location18535 18536,Location18536 18537,Location18537 18628,Location18628 18629,Location18629 28625,Location28625 28646,Location28646 28647,Location28647 28648,Location28648 28650,Location28650 28651,Location28651 28656,Location28656 28657,Location28657 28664,Location28664 28667,RangeArgumentExpressionArgsOutOfRange 28680,DollarAbsCantTakeLongMinValue 28689,ArrayOperatorElemAtFirstArgMustBeArray 28690,DollarArrayElemAtSecondArgArgMustBeNumeric 28691,DollarArrayElemAtSecondArgArgMustBe32Bit 28714,DollarSqrtGreaterOrEqualToZero 28724,DollarSliceInvalidInput 28725,DollarSliceInvalidTypeSecondArg 28726,DollarSliceInvalidValueSecondArg 28727,DollarSliceInvalidTypeThirdArg 28728,DollarSliceInvalidValueThirdArg 28729,DollarSliceInvalidSignThirdArg 28745,Location28745 28746,Location28746 28747,Location28747 28748,Location28748 28749,Location28749 28756,DollarLogArgumentMustBeNumeric 28757,DollarLogBaseMustBeNumeric 28758,DollarLogNumberMustBePositive 28759,DollarLogBaseMustBeGreaterThanOne 28761,DollarLog10MustBePositiveNumber 28762,DollarPowBaseMustBeNumeric 28763,DollarPowExponentMustBeNumeric 28764,DollarPowExponentInvalidForZeroBase 28765,Location28765 28766,DollarLnMustBePositiveNumber 28769,Location28769 28803,Location28803 28808,Location28808 28809,Location28809 28810,Location28810 28811,Location28811 28812,Location28812 28818,Location28818 28822,Location28822 31002,Location31002 31022,Location31022 31023,Location31023 31024,Location31024 31032,KeyCannotContainNullByte 31034,Location31034 31095,Location31095 31109,Location31109 31119,Location31119 31120,Location31120 31138,Location31138 31170,Location31170 31249,Location31249 31250,Location31250 31253,Location31253 31254,Location31254 31256,Location31256 31271,Location31271 31276,Location31276 31308,Location31308 31319,Location31319 31320,Location31320 31321,Location31321 31325,Location31325 31393,Location31393 31395,Location31395 31441,Location31441 31465,Location31465 34435,Location34435 34443,Location34443 34444,Location34444 34445,Location34445 34446,Location34446 34447,Location34447 34448,Location34448 34449,Location34449 34450,Location34450 34451,Location34451 34452,Location34452 34453,Location34453 34454,Location34454 34455,Location34455 34460,Location34460 34461,Location34461 34462,Location34462 34463,Location34463 34464,Location34464 34465,Location34465 34466,Location34466 34467,Location34467 34468,Location34468 34471,Location34471 34473,Location34473 40060,DollarSwitchRequiresObject 40061,DollarSwitchRequiresArrayForBranches 40062,DollarSwitchRequiresObjectForEachBranch 40063,DollarSwitchUnknownArgumentForBranch 40064,DollarSwitchRequiresCaseExpressionForBranch 40065,DollarSwitchRequiresThenExpressionForBranch 40066,DollarSwitchNoMatchingBranchAndNoDefault 40067,DollarSwitchBadArgument 40068,DollarSwitchRequiresAtLeastOneBranch 40075,Location40075 40076,Location40076 40077,Location40077 40078,Location40078 40079,Location40079 40080,Location40080 40081,DollarInRequiresArray 40085,Location40085 40086,Location40086 40087,Location40087 40090,Location40090 40091,Location40091 40092,Location40092 40093,Location40093 40094,Location40094 40096,Location40096 40097,Location40097 40100,Location40100 40101,Location40101 40102,Location40102 40103,Location40103 40104,Location40104 40105,Location40105 40147,Location40147 40156,Location40156 40158,Location40158 40160,Location40160 40169,Location40169 40177,Location40177 40181,Location40181 40185,Location40185 40191,Location40191 40192,Location40192 40193,Location40193 40194,Location40194 40195,Location40195 40196,Location40196 40197,Location40197 40198,Location40198 40199,Location40199 40200,Location40200 40201,Location40201 40202,Location40202 40218,Location40218 40228,Location40228 40229,Location40229 40234,Location40234 40235,Location40235 40236,Location40236 40237,Location40237 40238,Location40238 40239,Location40239 40240,Location40240 40241,Location40241 40242,Location40242 40243,Location40243 40244,Location40244 40245,Location40245 40246,Location40246 40257,Location40257 40258,Location40258 40260,Location40260 40261,Location40261 40272,Location40272 40319,Location40319 40321,Location40321 40323,Location40323 40324,UnrecognizedCommand 40352,Location40352 40386,DollarArrayToObjectRequiresArray 40390,DollarObjectToArrayRequiresObject 40391,DollarArrayToObjectAllMustBeObjects 40392,DollarArrayToObjectIncorrectNumberOfKeys 40393,DollarArrayToObjectRequiresObjectWithKAndV 40394,DollarArrayToObjectObjectKeyMustBeString 40395,DollarArrayToObjectArrayKeyMustBeString 40396,DollarArrayToObjectAllMustBeArrays 40397,DollarArrayToObjectIncorrectArrayLength 40398,DollarArrayToObjectBadInputTypeFormat 40400,DollarMergeObjectsInvalidType 40414,Location40414 40415,UnknownBsonField 40485,Location40485 40489,Location40489 40515,Location40515 40516,Location40516 40517,Location40517 40518,Location40518 40519,Location40519 40520,Location40520 40521,Location40521 40522,Location40522 40523,Location40523 40524,Location40524 40525,Location40525 40533,Location40533 40535,Location40535 40536,Location40536 40539,Location40539 40540,Location40540 40541,Location40541 40542,Location40542 40600,Location40600 40601,Location40601 40602,Location40602 40603,Location40603 40647,ChangeStreamBadResumeToken 40684,Location40684 42501,InsufficientPrivilege 50694,Location50694 50695,Location50695 50696,Location50696 50699,Location50699 50700,Location50700 50723,Location50723 50752,Location50752 50759,Location50759 50989,Location50989 51003,Location51003 51024,Location51024 51044,Location51044 51045,Location51045 51047,Location51047 51074,Location51074 51075,Location51075 51080,DollarRoundOverflowInt64 51081,DollarRoundFirstArgMustBeNumeric 51082,DollarRoundPrecisionMustBeIntegral 51083,DollarRoundPrecisionOutOfRange 51091,Location51091 51103,Location51103 51104,Location51104 51105,Location51105 51106,Location51106 51107,Location51107 51108,Location51108 51109,Location51109 51110,Location51110 51111,Location51111 51132,Location51132 51134,Location51134 51151,Location51151 51156,Location51156 51178,Location51178 51183,Location51183 51185,Location51185 51186,Location51186 51187,Location51187 51191,Location51191 51246,Location51246 51247,Location51247 51276,Location51276 51743,Location51743 51744,Location51744 51745,Location51745 51746,Location51746 51747,Location51747 51748,Location51748 51749,Location51749 51750,Location51750 51751,Location51751 327391,Location327391 327392,Location327392 605001,Location605001 1257300,DollarIfNullRequiresAtLeastTwoArgs 2942500,Location2942500 2942501,Location2942501 2942502,Location2942502 2942503,Location2942503 2942504,Location2942504 2942505,Location2942505 2942506,Location2942506 3040501,DollarRandNonEmptyArgument 3041701,Location3041701 3041702,Location3041702 3041703,Location3041703 3041704,Location3041704 4031700,IntermediateResultTooLarge 4161100,DollarSetFieldRequiresObject 4161101,DollarSetFieldUnknownArgument 4161102,Location4161102 4161103,Location4161103 4161104,Location4161104 4161105,Location4161105 4161106,Location4161106 4161107,Location4161107 4161108,Location4161108 4161109,Location4161109 4341107,Location4341107 4890500,Location4890500 4940400,Location4940400 4940401,Location4940401 5107200,Location5107200 5107201,Location5107201 5166301,Location5166301 5166302,Location5166302 5166303,Location5166303 5166304,Location5166304 5166305,Location5166305 5166307,Location5166307 5166400,Location5166400 5166401,Location5166401 5166402,Location5166402 5166403,Location5166403 5166404,Location5166404 5166405,Location5166405 5166406,Location5166406 5339900,Location5339900 5339901,Location5339901 5339902,Location5339902 5371601,Location5371601 5371602,Location5371602 5371603,Location5371603 5423900,Location5423900 5423901,Location5423901 5423902,Location5423902 5429413,Location5429413 5429414,Location5429414 5429513,Location5429513 5439007,Location5439007 5439008,Location5439008 5439009,Location5439009 5439010,Location5439010 5439012,Location5439012 5439013,Location5439013 5439014,Location5439014 5439015,Location5439015 5439016,Location5439016 5439017,Location5439017 5439018,Location5439018 5490710,Location5490710 5624900,Location5624900 5624901,Location5624901 5626500,Location5626500 5654600,Location5654600 5654601,Location5654601 5654602,Location5654602 5687301,Location5687301 5687302,Location5687302 5687400,Location5687400 5687401,Location5687401 5733201,Location5733201 5733401,Location5733401 5733402,Location5733402 5733403,Location5733403 5733406,Location5733406 5733408,Location5733408 5733409,Location5733409 5746102,Location5746102 5787801,Location5787801 5787900,Location5787900 5787901,Location5787901 5787902,Location5787902 5787903,Location5787903 5787906,Location5787906 5787907,Location5787907 5787908,Location5787908 5788001,Location5788001 5788002,Location5788002 5788003,Location5788003 5788004,Location5788004 5788005,Location5788005 5788200,Location5788200 5788604,Location5788604 5858203,Location5858203 5860402,Location5860402 5876900,Location5876900 5897900,Location5897900 5946802,Location5946802 5976500,Location5976500 6007200,Location6007200 6045000,Location6045000 6050106,Location6050106 6050202,Location6050202 6050204,Location6050204 6053600,Location6053600 6586400,Location6586400 7429703,Location7429703 7436100,Location7436100 7555701,Location7555701 7555702,Location7555702 7749501,Location7749501 7750301,Location7750301 7750302,Location7750302 7750303,Location7750303 8993000,Location8993000documentdb-0.108-0/internal/000077500000000000000000000000001507310017400156155ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/000077500000000000000000000000001507310017400230315ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/Makefile000077500000000000000000000055311507310017400245000ustar00rootroot00000000000000EXTENSION = documentdb_distributed # compilation configuration MODULE_big = pg_$(EXTENSION) SQL_DEPDIR=.deps/sql SQL_BUILDDIR=build/sql template_sql_files = $(wildcard sql/*.sql) generated_sql_files = $(patsubst %,build/%,$(template_sql_files)) DATA_built = $(generated_sql_files) sql_file_inputs = $(wildcard sql/**/*.sql) BUILD_SCRIPT_DIR = ../../ OSS_SRC_DIR = ../../ OSS_COMMON_SQL_HEADER = $(wildcard $(OSS_SRC_DIR)/common_header.sql) # Extension defines POSTGIS_SCHEMA_NAME=public API_SCHEMA_NAME=documentdb_api API_SCHEMA_NAME_V2=documentdb_api API_SCHEMA_INTERNAL_NAME=documentdb_api_internal API_SCHEMA_INTERNAL_NAME_V2=documentdb_api_internal API_CATALOG_SCHEMA_NAME=documentdb_api_catalog API_CATALOG_SCHEMA_NAME_V2=documentdb_api_catalog CORE_SCHEMA_NAME=documentdb_core CORE_SCHEMA_NAME_V2=documentdb_core API_DISTRIBUTED_SCHEMA_NAME=documentdb_api_distributed API_DATA_SCHEMA_NAME=documentdb_data API_ADMIN_ROLE=documentdb_admin_role API_READONLY_ROLE=documentdb_readonly_role API_BG_WORKER_ROLE=documentdb_bg_worker_role EXTENSION_OBJECT_PREFIX=documentdb API_GUC_PREFIX=documentdb API_GUC_PREFIX_V2=documentdb # TODO: Need to remove this with PG16 and expose only valid exports ALLOW_DEFAULT_VISIBILITY=yes include $(OSS_SRC_DIR)/Makefile.cflags PG_CPPFLAGS += -I$(OSS_SRC_DIR)/pg_documentdb_core/include/ -I$(OSS_SRC_DIR)/pg_documentdb/include/ SOURCES = $(wildcard src/*.c) $(wildcard src/**/*.c) OBJS = $(patsubst %.c,%.o,$(SOURCES)) DEBUG ?= no ifeq ($(DEBUG),yes) PG_CPPFLAGS += -ggdb -O0 -g PG_CFLAGS += -ggdb -O0 -g endif SHLIB_LINK = $(libpq) include $(OSS_SRC_DIR)/Makefile.global clean-sql: rm -rf .deps/ build/ check: $(MAKE) -C src/test all check-dist-minimal: $(MAKE) -C src/test $@ citus-indent: citus_indent analysis: citus-indent check-regress: $(MAKE) -C src/test check-regress # Before installing, trim any files extension*.sql files in the target install directory install: trim_installed_data_files trim_installed_data_files: rm -f $(DESTDIR)$(datadir)/$(datamoduledir)/$(EXTENSION)--*.sql build-sql: $(generated_sql_files) $(generated_sql_files): build/%: % @mkdir -p $(SQL_DEPDIR) $(SQL_BUILDDIR) @# -MF is used to store dependency files(.Po) in another directory for separation @# -MT is used to change the target of the rule emitted by dependency generation. @# -P is used to inhibit generation of linemarkers in the output from the preprocessor. @# -undef is used to not predefine any system-specific or GCC-specific macros. @# -imacros is used to specify a file that defines macros for the global context but its output is thrown away. @# `man cpp` for further information cpp -undef -w $(SQL_DEFINES) -imacros $(OSS_COMMON_SQL_HEADER) -P -MMD -MP -MF$(SQL_DEPDIR)/$(*F).Po -MT$@ $< > $@ include $(OSS_SRC_DIR)/Makefile.versions src/documentdb_extension_version.o : build/include/metadata/documentdb_extension_version.hdocumentdb-0.108-0/internal/pg_documentdb_distributed/NOTICE000066400000000000000000000006461507310017400237430ustar00rootroot00000000000000This product includes third-party components distributed under various licenses. Full license texts and notices for these components are provided in the 'internal/pg_documentdb_distributed/licenses/' directory. --------------------------------------------------------- - citusdata/citus Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE, Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. documentdb-0.108-0/internal/pg_documentdb_distributed/documentdb_distributed.control000077500000000000000000000003311507310017400311610ustar00rootroot00000000000000comment = 'Multi-Node API surface for DocumentDB' default_version = '0.108-0' module_pathname = '$libdir/pg_documentdb_distributed' relocatable = false superuser = true requires = 'citus, documentdb_core, documentdb' documentdb-0.108-0/internal/pg_documentdb_distributed/include/000077500000000000000000000000001507310017400244545ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/include/distributed_hooks.h000066400000000000000000000007201507310017400303510ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/distributed_hooks.h * * The implementation for shard colocation for DocumentDB with citus. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_DISTRIBUTED_HOOKS_H #define DOCUMENTDB_DISTRIBUTED_HOOKS_H void InitializeDocumentDBDistributedHooks(void); #endif documentdb-0.108-0/internal/pg_documentdb_distributed/include/documentdb_distributed_init.h000066400000000000000000000007511507310017400324010ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/documentdb_distributed_init.h * * The implementation for shard colocation for documentdb with citus. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_DISTRIBUTED_INIT_H #define DOCUMENTDB_DISTRIBUTED_INIT_H void InitDocumentDBDistributedConfigurations(const char *prefix); #endif documentdb-0.108-0/internal/pg_documentdb_distributed/include/node_distributed_operations.h000066400000000000000000000007741507310017400324270ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/node_distributed_oeprations.h * * The implementation for node level distributed operations. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_NODE_DISTRIBUTED_OPS_H #define DOCUMENTDB_NODE_DISTRIBUTED_OPS_H void UpdateDistributedPostgresIndex(uint64_t collectionId, int indexId, bool hidden); #endif documentdb-0.108-0/internal/pg_documentdb_distributed/include/shard_colocation.h000066400000000000000000000006501507310017400301410ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/shard_colocation.h * * The implementation for shard colocation for DocumentDB with citus. * *------------------------------------------------------------------------- */ #ifndef SHARD_COLOCATION_H #define SHARD_COLOCATION_H void UpdateColocationHooks(void); #endif documentdb-0.108-0/internal/pg_documentdb_distributed/licenses/000077500000000000000000000000001507310017400246365ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/licenses/LICENSE_citus000066400000000000000000001046241507310017400270610ustar00rootroot00000000000000citusdata/citus GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . NOTICES AND INFORMATION Do Not Translate or Localize This software incorporates material from third parties. Microsoft makes certain open source code available at https://3rdpartysource.microsoft.com, or you may send a check or money order for US $5.00, including the product name, the open source component name, platform, and version number, to: Source Code Compliance Team Microsoft Corporation One Microsoft Way Redmond, WA 98052 USA Notwithstanding any other terms, you may reverse engineer this software to the extent required to debug changes to any libraries licensed under the GNU Lesser General Public License. ---------------------------------------------------------documentdb-0.108-0/internal/pg_documentdb_distributed/sql/000077500000000000000000000000001507310017400236305ustar00rootroot00000000000000documentdb_distributed--0.100-0--0.101-0.sql000066400000000000000000000000001507310017400325230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.101-0--0.102-0.sql000066400000000000000000000000001507310017400325250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.102-0--0.102-1.sql000066400000000000000000000000001507310017400325270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.102-1--0.103-0.sql000066400000000000000000000000001507310017400325300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.103-0--0.104-0.sql000066400000000000000000000000001507310017400325310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.104-0--0.105-0.sql000066400000000000000000000000001507310017400325330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.105-0--0.106-0.sql000066400000000000000000000000001507310017400325350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.106-0--0.107-0.sql000066400000000000000000000000001507310017400325370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb_distributed--0.107-0--0.108-0.sql000066400000000000000000000000761507310017400325560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql #include "udfs/operations/update_postgres_index--0.108-0.sql"documentdb_distributed--0.24-0--0.100-0.sql000066400000000000000000000000001507310017400324470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sqldocumentdb-0.108-0/internal/pg_documentdb_distributed/sql/documentdb_distributed--0.24-0.sql000066400000000000000000000013641507310017400316760ustar00rootroot00000000000000CREATE SCHEMA documentdb_api_distributed; GRANT USAGE ON SCHEMA documentdb_api_distributed TO __API_ADMIN_ROLE__; GRANT USAGE ON SCHEMA documentdb_api_distributed TO __API_READONLY_ROLE__; CREATE TABLE documentdb_api_distributed.documentdb_cluster_data ( metadata __CORE_SCHEMA__.bson ); -- seed the table with a baseline version. INSERT INTO documentdb_api_distributed.documentdb_cluster_data (metadata) VALUES ( '{ "last_deploy_version": "0.0-0" }'::__CORE_SCHEMA__.bson ); #include "udfs/clustermgmt/cluster_operations--0.21-0.sql" #include "udfs/clustermgmt/cluster_version_utils--0.21-0.sql" ALTER TABLE documentdb_api_distributed.documentdb_cluster_data ADD PRIMARY KEY (metadata); #include "udfs/rebalancer/rebalancer_operations--0.24-0.sql" documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/000077500000000000000000000000001507310017400245715ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/clustermgmt/000077500000000000000000000000001507310017400271375ustar00rootroot00000000000000cluster_operations--0.21-0.sql000066400000000000000000000015571507310017400343250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/clustermgmt CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.initialize_cluster() RETURNS void SET search_path TO __API_CATALOG_SCHEMA__, pg_catalog SET citus.enable_ddl_propagation TO on /* * By default, Citus triggers are off as there are potential pitfalls if * not used properly, such as, doing operations on the remote node. We use * them here only for local operations. */ SET citus.enable_unsafe_triggers TO on SET citus.multi_shard_modify_mode TO 'sequential' LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_initialize_cluster$function$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.complete_upgrade() RETURNS bool SET citus.enable_unsafe_triggers TO on SET citus.enable_ddl_propagation TO on SET citus.multi_shard_modify_mode TO 'sequential' LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_complete_upgrade$function$; cluster_operations--latest.sql000066400000000000000000000015571507310017400351040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/clustermgmt CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.initialize_cluster() RETURNS void SET search_path TO __API_CATALOG_SCHEMA__, pg_catalog SET citus.enable_ddl_propagation TO on /* * By default, Citus triggers are off as there are potential pitfalls if * not used properly, such as, doing operations on the remote node. We use * them here only for local operations. */ SET citus.enable_unsafe_triggers TO on SET citus.multi_shard_modify_mode TO 'sequential' LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_initialize_cluster$function$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.complete_upgrade() RETURNS bool SET citus.enable_unsafe_triggers TO on SET citus.enable_ddl_propagation TO on SET citus.multi_shard_modify_mode TO 'sequential' LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_complete_upgrade$function$; cluster_version_utils--0.21-0.sql000066400000000000000000000014231507310017400350370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/clustermgmt CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.invalidate_cached_cluster_versions() RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$invalidate_cluster_version$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.get_current_cached_cluster_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$get_current_cached_cluster_version$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.__CONCAT_NAME_FUNCTION__(update_, __EXTENSION_OBJECT_PREFIX_V2__, _version_data()) RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN RAISE NOTICE 'Invalidating cached cluster version data'; PERFORM __API_SCHEMA_INTERNAL_V2__.invalidate_cached_cluster_versions(); RETURN NULL; END; $function$; cluster_version_utils--latest.sql000066400000000000000000000014231507310017400356160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/clustermgmt CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.invalidate_cached_cluster_versions() RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$invalidate_cluster_version$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.get_current_cached_cluster_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$get_current_cached_cluster_version$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.__CONCAT_NAME_FUNCTION__(update_, __EXTENSION_OBJECT_PREFIX_V2__, _version_data()) RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN RAISE NOTICE 'Invalidating cached cluster version data'; PERFORM __API_SCHEMA_INTERNAL_V2__.invalidate_cached_cluster_versions(); RETURN NULL; END; $function$; documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/operations/000077500000000000000000000000001507310017400267545ustar00rootroot00000000000000update_postgres_index--0.108-0.sql000066400000000000000000000003701507310017400346730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/operations CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.update_postgres_index_worker( p_local_function_arg __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$documentdb_update_postgres_index_worker$$;update_postgres_index--latest.sql000066400000000000000000000003701507310017400353640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/operations CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.update_postgres_index_worker( p_local_function_arg __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$documentdb_update_postgres_index_worker$$;documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/rebalancer/000077500000000000000000000000001507310017400266675ustar00rootroot00000000000000rebalancer_operations--0.24-0.sql000066400000000000000000000011761507310017400344720ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/rebalancer CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_status(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_status$$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_start(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_start$$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_stop(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_stop$$;rebalancer_operations--latest.sql000066400000000000000000000011761507310017400352460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/sql/udfs/rebalancer CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_status(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_status$$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_start(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_start$$; CREATE OR REPLACE FUNCTION __API_DISTRIBUTED_SCHEMA__.rebalancer_stop(p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_rebalancer_stop$$;documentdb-0.108-0/internal/pg_documentdb_distributed/src/000077500000000000000000000000001507310017400236205ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/colocation/000077500000000000000000000000001507310017400257525ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/colocation/shard_colocation.c000066400000000000000000001454601507310017400314430ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/colocation/shard_colocation.c * * Implementation of colocation and distributed placement for the extension. * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "utils/documentdb_errors.h" #include "utils/query_utils.h" #include "metadata/metadata_cache.h" #include "metadata/collection.h" #include "shard_colocation.h" #include "api_hooks_def.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" PG_FUNCTION_INFO_V1(command_get_shard_map); PG_FUNCTION_INFO_V1(command_list_shards); /* * Metadata collected about Citus nodes. * This is the output that we care about collected from * Citus's pg_dist_node. */ typedef struct NodeInfo { /* * The groupId for the node. This has 1 per * server (Coordinator, Worker1, Worker2) */ int32_t groupId; /* * An id for the specific node */ int32_t nodeId; /* * The citus role for the node, be it * Primary or secondary (for replicas) */ const char *nodeRole; /* * The name of the cluster: Default for writes * and the clustername for reads. */ const char *nodeCluster; /* * Whether or not th enode is active (false in * the case it's in the middle of an addnode) */ bool isactive; /* * The formatted node name * uses node__ */ const char *mongoNodeName; /* * The logical shard for the node "shard_" */ const char *mongoShardName; } NodeInfo; static const char * ColocateUnshardedCitusTables(const char *sourceTableName, const char *colocateWithTableName); static int GetShardCountForDistributedTable(Oid relationId); static int GetColocationForTable(Oid tableOid, const char *collectionName, const char *tableName); static void ColocateShardedCitusTablesWithNone(const char *sourceTableName); static void ColocateUnshardedCitusTablesWithNone(const char *sourceTableName); static void MoveShardToDistributedTable(const char *postgresTableToMove, const char *targetShardTable); static void UndistributeAndRedistributeTable(const char *postgresTable, const char *colocateWith, const char *shardKeyValue); /* Handle a colocation scenario for collMod */ static void HandleDistributedColocation(MongoCollection *collection, const bson_value_t *colocationValue); static Query * RewriteListCollectionsQueryForDistribution(Query *source); static Query * RewriteConfigShardsQueryForDistribution(Query *source); static Query * RewriteConfigChunksQueryForDistribution(Query *source); static List * GetShardMapNodes(void); static void WriteShardMap(pgbson_writer *writer, List *groupNodes); static void WriteShardList(pgbson_writer *writer, List *groupNodes); /* * Implements the getShardMap command */ Datum command_get_shard_map(PG_FUNCTION_ARGS) { /* First query pg_dist_node to get the set of nodes in the cluster */ pgbson_writer writer; PgbsonWriterInit(&writer); List *groupNodes = GetShardMapNodes(); if (groupNodes != NIL) { WriteShardMap(&writer, groupNodes); } PgbsonWriterAppendDouble(&writer, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } Datum command_list_shards(PG_FUNCTION_ARGS) { pgbson_writer writer; PgbsonWriterInit(&writer); List *groupNodes = GetShardMapNodes(); if (groupNodes != NIL) { WriteShardList(&writer, groupNodes); } PgbsonWriterAppendDouble(&writer, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } /* * override hooks related to colocation. */ void UpdateColocationHooks(void) { handle_colocation_hook = HandleDistributedColocation; rewrite_list_collections_query_hook = RewriteListCollectionsQueryForDistribution; rewrite_config_shards_query_hook = RewriteConfigShardsQueryForDistribution; rewrite_config_chunks_query_hook = RewriteConfigChunksQueryForDistribution; } /* * Process colocation options for a distributed DocumentDB deployment. */ static void HandleDistributedColocation(MongoCollection *collection, const bson_value_t *colocationValue) { if (collection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("unexpected - collection for colocation was null"))); } if (colocationValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Colocation options must be provided as a document."))); } char *tableWithNamespace = psprintf("%s.%s", ApiDataSchemaName, collection->tableName); bson_iter_t colocationIter; BsonValueInitIterator(colocationValue, &colocationIter); StringView collectionName = { 0 }; bool colocateWithNull = false; while (bson_iter_next(&colocationIter)) { const char *key = bson_iter_key(&colocationIter); if (strcmp(key, "collection") == 0) { if (BSON_ITER_HOLDS_UTF8(&colocationIter)) { collectionName.string = bson_iter_utf8(&colocationIter, &collectionName.length); } else if (BSON_ITER_HOLDS_NULL(&colocationIter)) { colocateWithNull = true; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "colocation.collection must be a string or null. not %s", BsonTypeName(bson_iter_type(&colocationIter))), errdetail_log( "colocation.collection must be a string or null. not %s", BsonTypeName(bson_iter_type(&colocationIter))))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Unrecognized field in colocation.%s", key), errdetail_log("Unrecognized field in colocation.%s", key))); } } if (collectionName.length == 0 && !colocateWithNull) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS), errmsg("Must specify collection for colocation"))); } /* For sharded collections, can only colocate with null: We do this to fix up old tables */ bool isSharded = collection->shardKey != NULL; if (isSharded && !colocateWithNull) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS), errmsg("Cannot colocate a collection that is already sharded."))); } const char *retryTableShardKeyValue = NULL; if (colocateWithNull) { if (isSharded) { retryTableShardKeyValue = "shard_key_value"; ColocateShardedCitusTablesWithNone(tableWithNamespace); } else { ColocateUnshardedCitusTablesWithNone(tableWithNamespace); } } else { const char *targetCollectionName = CreateStringFromStringView(&collectionName); if (strcmp(collection->name.collectionName, targetCollectionName) == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg( "Source and target cannot be the same for colocation"))); } MongoCollection *targetCollection = GetMongoCollectionByNameDatum( CStringGetTextDatum(collection->name.databaseName), CStringGetTextDatum(targetCollectionName), AccessShareLock); if (targetCollection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Namespace %s.%s cannot be found", collection->name.databaseName, targetCollectionName), errdetail_log("Namespace %s.%s cannot be found", collection->name.databaseName, targetCollectionName))); } /* Validate that targetCollection is not colocated with ApiDataSchemaName.changes * (if it is, we fail until it is colocated with null) - this is a back-compat * cleanup decision. */ char *targetWithNamespace = psprintf("%s.%s", ApiDataSchemaName, targetCollection->tableName); int colocationId = GetColocationForTable(targetCollection->relationId, targetCollectionName, targetWithNamespace); /* Get the colocationId of the changes table */ char *documentdbDataWithNamespace = psprintf("%s.changes", ApiDataSchemaName); RangeVar *rangeVar = makeRangeVar(ApiDataSchemaName, "changes", -1); Oid changesRelId = RangeVarGetRelid(rangeVar, AccessShareLock, false); int colocationIdOfChangesTable = GetColocationForTable(changesRelId, "changes", documentdbDataWithNamespace); if (colocationId == colocationIdOfChangesTable) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Colocation for this collection in the current configuration is not supported. " "Please first colocate %s with colocation: null", targetCollectionName)), (errdetail_log( "Colocation for this table in the current configuration is not supported - legacy table"))); } if (targetCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Current collection cannot be colocated with any sharded collection."))); } /* Also check if the colocated source has only 1 shard (otherwise require colocate=null explicitly) */ int shardCount = GetShardCountForDistributedTable(targetCollection->relationId); if (shardCount != 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Colocation for this collection in the current configuration is not supported. " "Please first colocate %s with colocation: null", targetCollectionName)), (errdetail_log( "Colocation for this table in the current configuration is not supported - shard count is not 1: %d", shardCount))); } retryTableShardKeyValue = ColocateUnshardedCitusTables(tableWithNamespace, targetWithNamespace); } /* Colocate retry with the original table */ char *retryTableWithNamespace = psprintf("%s.retry_%ld", ApiDataSchemaName, collection->collectionId); UndistributeAndRedistributeTable(retryTableWithNamespace, tableWithNamespace, retryTableShardKeyValue); } /* * Rewrite/Update the metadata query for distributed information. * The original listCollections query looks like * SELECT bson_dollar_project(row_get_bson(collections), '{ "ns": { "$concat": [ "$database_name", "$collection_name" ], ... }}) FROM ApiCatalogSchema.collections WHERE database_name = 'db'; * * This modifies it to the following: * SELECT bson_dollar_addfields(bson_dollar_project(row_get_bson(collections), '{ "ns": { "$concat": [ "$database_name", "$collection_name" ], ... }}), * bson_repath_and_build('shardcount', pg_dist_colocation.shard_count, 'colocationid', pg_dist_partition.colocationid) FROM ApiCatalogSchema.collections, pg_dist_partition, pg_dist_colocation * WHERE database_name = 'db' * AND pg_dist_partition.colocationid = pg_dist_colocation.colocationid AND textcatany('ApiDataSchema.documents_', collections.collection_id)::regclass = pg_dist_partition.logicalrelid; */ static Query * RewriteListCollectionsQueryForDistribution(Query *source) { if (list_length(source->rtable) != 1) { ereport(ERROR, (errmsg("Unexpected error - source query has more than 1 rte"))); } RangeTblEntry *partitionRte = makeNode(RangeTblEntry); /* add pg_dist_partition to the RTEs */ List *partitionColNames = list_concat(list_make3(makeString("logicalrelid"), makeString("partmethod"), makeString( "partkey")), list_make3(makeString("colocationid"), makeString("repmodel"), makeString( "autoconverted"))); partitionRte->rtekind = RTE_RELATION; partitionRte->alias = partitionRte->eref = makeAlias("partition", partitionColNames); partitionRte->lateral = false; partitionRte->inFromCl = true; partitionRte->relkind = RELKIND_RELATION; partitionRte->functions = NIL; partitionRte->inh = true; partitionRte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar("pg_catalog", "pg_dist_partition", -1); partitionRte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&source->rteperminfos, partitionRte); permInfo->requiredPerms = ACL_SELECT; #else partitionRte->requiredPerms = ACL_SELECT; #endif source->rtable = lappend(source->rtable, partitionRte); /* Add pg_dist_colocation to the RTEs */ RangeTblEntry *colocationRte = makeNode(RangeTblEntry); List *colocationColNames = list_concat(list_make3(makeString("colocationid"), makeString("shardcount"), makeString("replicationfactor")), list_make2(makeString( "distributioncolumntype"), makeString( "distributioncolumncollation"))); colocationRte->rtekind = RTE_RELATION; colocationRte->alias = colocationRte->eref = makeAlias("colocation", colocationColNames); colocationRte->lateral = false; colocationRte->inFromCl = true; colocationRte->relkind = RELKIND_RELATION; colocationRte->functions = NIL; colocationRte->inh = true; colocationRte->rellockmode = AccessShareLock; rangeVar = makeRangeVar("pg_catalog", "pg_dist_colocation", -1); colocationRte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 permInfo = addRTEPermissionInfo(&source->rteperminfos, colocationRte); permInfo->requiredPerms = ACL_SELECT; #else colocationRte->requiredPerms = ACL_SELECT; #endif source->rtable = lappend(source->rtable, colocationRte); RangeTblRef *secondRef = makeNode(RangeTblRef); secondRef->rtindex = 2; RangeTblRef *thirdRef = makeNode(RangeTblRef); thirdRef->rtindex = 3; FromExpr *currentTree = source->jointree; currentTree->fromlist = lappend(currentTree->fromlist, secondRef); currentTree->fromlist = lappend(currentTree->fromlist, thirdRef); /* now add the "join" to the quals */ List *existingQuals = make_ands_implicit((Expr *) currentTree->quals); /* On the collections_table we take the collection_id */ Var *collectionIdVar = makeVar(1, 3, INT8OID, -1, InvalidOid, 0); char *tablePrefixString = psprintf("%s.%s", ApiDataSchemaName, DOCUMENT_DATA_TABLE_NAME_PREFIX); Const *tablePrefix = makeConst(TEXTOID, -1, InvalidOid, -1, CStringGetTextDatum( tablePrefixString), false, false); /* Construct the string */ FuncExpr *concatExpr = makeFuncExpr(F_TEXTANYCAT, TEXTOID, list_make2(tablePrefix, collectionIdVar), InvalidOid, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); FuncExpr *castConcatExpr = makeFuncExpr(F_TO_REGCLASS, OIDOID, list_make1(concatExpr), DEFAULT_COLLATION_OID, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); /* Get the regclass of the join */ Var *regclassVar = makeVar(2, 1, OIDOID, -1, InvalidOid, 0); FuncExpr *oidEqualFunc = makeFuncExpr(F_OIDEQ, BOOLOID, list_make2(regclassVar, castConcatExpr), DEFAULT_COLLATION_OID, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); existingQuals = lappend(existingQuals, oidEqualFunc); List *secondJoinArgs = list_make2( makeVar(2, 4, INT4OID, -1, InvalidOid, 0), makeVar(3, 1, INT4OID, -1, InvalidOid, 0) ); FuncExpr *secondJoin = makeFuncExpr(F_OIDEQ, BOOLOID, secondJoinArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); existingQuals = lappend(existingQuals, secondJoin); currentTree->quals = (Node *) make_ands_explicit(existingQuals); List *repathArgs = list_make4( makeConst(TEXTOID, -1, DEFAULT_COLLATION_OID, -1, CStringGetTextDatum( "colocationId"), false, false), makeVar(2, 4, INT4OID, -1, InvalidOid, 0), makeConst(TEXTOID, -1, DEFAULT_COLLATION_OID, -1, CStringGetTextDatum( "shardCount"), false, false), makeVar(3, 2, INT4OID, -1, InvalidOid, 0)); FuncExpr *colocationArgs = makeFuncExpr(BsonRepathAndBuildFunctionOid(), BsonTypeId(), repathArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); /* Since no dotted paths in projection no need to override */ bool overrideArray = false; Oid addFieldsOid = BsonDollaMergeDocumentsFunctionOid(); TargetEntry *firstEntry = linitial(source->targetList); FuncExpr *addFields = makeFuncExpr(addFieldsOid, BsonTypeId(), list_make3(firstEntry->expr, colocationArgs, MakeBoolValueConst(overrideArray)), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) addFields; return source; } /* * The config.shards query in a distributed query scenario * will end up querying the pg_dist_node table to get the list of shards * and output them in a compatible format. */ static Query * RewriteConfigShardsQueryForDistribution(Query *baseQuery) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; List *valuesList = NIL; pgbson_writer writer; PgbsonWriterInit(&writer); List *groupNodes = GetShardMapNodes(); if (groupNodes != NIL) { WriteShardList(&writer, groupNodes); } pgbson *shardList = PgbsonWriterGetPgbson(&writer); pgbsonelement element; PgbsonToSinglePgbsonElement(shardList, &element); bson_iter_t values; BsonValueInitIterator(&element.bsonValue, &values); while (bson_iter_next(&values)) { pgbson *bsonValue = PgbsonInitFromDocumentBsonValue(bson_iter_value(&values)); valuesList = lappend(valuesList, list_make1(makeConst(BsonTypeId(), -1, InvalidOid, -1, PointerGetDatum(bsonValue), false, false))); } RangeTblEntry *valuesRte = makeNode(RangeTblEntry); valuesRte->rtekind = RTE_VALUES; valuesRte->alias = valuesRte->eref = makeAlias("values", list_make1(makeString( "document"))); valuesRte->lateral = false; valuesRte->values_lists = valuesList; valuesRte->inh = false; valuesRte->inFromCl = true; valuesRte->coltypes = list_make1_oid(INT8OID); valuesRte->coltypmods = list_make1_int(-1); valuesRte->colcollations = list_make1_oid(InvalidOid); query->rtable = list_make1(valuesRte); query->jointree = makeNode(FromExpr); RangeTblRef *valuesRteRef = makeNode(RangeTblRef); valuesRteRef->rtindex = 1; query->jointree->fromlist = list_make1(valuesRteRef); /* Point to the values RTE */ Var *documentEntry = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); return query; } static Oid GetCitusShardSizesFunctionOid(void) { List *functionNameList = list_make2(makeString("pg_catalog"), makeString("citus_shard_sizes")); bool missingOK = false; return LookupFuncName(functionNameList, 0, NULL, missingOK); } /* * Provides the output for the config.chunks query after consulting with Citus. * This will be the query: * WITH coll AS (SELECT database_name, collection_name, ('ApiDataSchemaName.documents_' || collection_id)::regclass AS tableId FROM ApiCatalogSchema.collections) * SELECT database_name, collection_name, shardid, size, shardminvalue, shardmaxvalue FROM coll * JOIN pg_dist_shard dist ON coll.tableId = dist.logicalrelid * JOIN citus_shard_sizes() sz ON dist.shardid = sz.shard_id; */ static Query * RewriteConfigChunksQueryForDistribution(Query *baseQuery) { Query *source = makeNode(Query); source->commandType = CMD_SELECT; source->querySource = QSRC_ORIGINAL; source->canSetTag = true; /* Match spec for ApiCatalogSchemaName.collections function */ RangeTblEntry *rte = makeNode(RangeTblEntry); List *colNames = list_concat(list_make3(makeString("database_name"), makeString( "collection_name"), makeString( "collection_id")), list_make3(makeString("shard_key"), makeString( "collection_uuid"), makeString( "view_definition"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collections", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *sourcePermInfo = addRTEPermissionInfo(&source->rteperminfos, rte); sourcePermInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif source->rtable = list_make1(rte); RangeTblEntry *shardsRte = makeNode(RangeTblEntry); /* add pg_dist_shard to the RTEs */ List *shardColNames = list_make5(makeString("logicalrelid"), makeString("shardid"), makeString("shardstorage"), makeString("shardminvalue"), makeString( "shardmaxvalue")); shardsRte->rtekind = RTE_RELATION; shardsRte->alias = shardsRte->eref = makeAlias("shards", shardColNames); shardsRte->lateral = false; shardsRte->inFromCl = true; shardsRte->relkind = RELKIND_RELATION; shardsRte->functions = NIL; shardsRte->inh = true; shardsRte->rellockmode = AccessShareLock; RangeVar *shardRangeVar = makeRangeVar("pg_catalog", "pg_dist_shard", -1); shardsRte->relid = RangeVarGetRelid(shardRangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *shardsPermInfo = addRTEPermissionInfo(&source->rteperminfos, shardsRte); shardsPermInfo->requiredPerms = ACL_SELECT; #else shardsRte->requiredPerms = ACL_SELECT; #endif source->rtable = lappend(source->rtable, shardsRte); /* Add citus_shard_sizes() to the RTEs */ RangeTblEntry *shardSizeRte = makeNode(RangeTblEntry); List *shardSizesColNames = list_make2(makeString("shard_id"), makeString("size")); shardSizeRte->rtekind = RTE_FUNCTION; shardSizeRte->alias = shardSizeRte->eref = makeAlias("shard_sizes", shardSizesColNames); shardSizeRte->lateral = false; shardSizeRte->inFromCl = true; shardSizeRte->functions = NIL; shardSizeRte->inh = false; shardSizeRte->rellockmode = AccessShareLock; Oid citusShardsSizesFuncId = GetCitusShardSizesFunctionOid(); FuncExpr *shardSizesFunc = makeFuncExpr(citusShardsSizesFuncId, RECORDOID, NIL, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); RangeTblFunction *shardSizesFunctions = makeNode(RangeTblFunction); shardSizesFunctions->funcexpr = (Node *) shardSizesFunc; shardSizesFunctions->funccolcount = 2; shardSizesFunctions->funccoltypes = list_make2_oid(INT4OID, INT8OID); shardSizesFunctions->funccolcollations = list_make2_oid(InvalidOid, InvalidOid); shardSizesFunctions->funccoltypmods = list_make2_int(-1, -1); shardSizeRte->functions = list_make1(shardSizesFunctions); #if PG_VERSION_NUM >= 160000 shardSizeRte->perminfoindex = 0; #else shardSizeRte->requiredPerms = ACL_SELECT; #endif source->rtable = lappend(source->rtable, shardSizeRte); /* Add pg_dist_placement */ RangeTblEntry *placementRte = makeNode(RangeTblEntry); List *placementColNames = list_make5(makeString("placementid"), makeString("shardid"), makeString("shardstate"), makeString("shardlength"), makeString( "groupid")); placementRte->rtekind = RTE_RELATION; placementRte->alias = placementRte->eref = makeAlias("placement", placementColNames); placementRte->lateral = false; placementRte->inFromCl = true; placementRte->relkind = RELKIND_RELATION; placementRte->functions = NIL; placementRte->inh = true; placementRte->rellockmode = AccessShareLock; RangeVar *placementRangeVar = makeRangeVar("pg_catalog", "pg_dist_placement", -1); placementRte->relid = RangeVarGetRelid(placementRangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *placementPermInfo = addRTEPermissionInfo(&source->rteperminfos, placementRte); placementPermInfo->requiredPerms = ACL_SELECT; #else placementRte->requiredPerms = ACL_SELECT; #endif source->rtable = lappend(source->rtable, placementRte); RangeTblRef *collectionsRef = makeNode(RangeTblRef); collectionsRef->rtindex = 1; RangeTblRef *shardsRef = makeNode(RangeTblRef); shardsRef->rtindex = 2; RangeTblRef *shardSizesRef = makeNode(RangeTblRef); shardSizesRef->rtindex = 3; RangeTblRef *placementRef = makeNode(RangeTblRef); placementRef->rtindex = 4; List *quals = NIL; /* WHERE view_definition IS NOT NULL */ NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NULL; nullTest->arg = (Expr *) makeVar(collectionsRef->rtindex, 6, BsonTypeId(), -1, InvalidOid, 0); quals = lappend(quals, nullTest); /* Join collection with shard */ Var *collectionIdVar = makeVar(collectionsRef->rtindex, 3, INT8OID, -1, InvalidOid, 0); char *tablePrefixString = psprintf("%s.%s", ApiDataSchemaName, DOCUMENT_DATA_TABLE_NAME_PREFIX); Const *tablePrefix = makeConst(TEXTOID, -1, InvalidOid, -1, CStringGetTextDatum( tablePrefixString), false, false); /* Construct the string */ FuncExpr *concatExpr = makeFuncExpr(F_TEXTANYCAT, TEXTOID, list_make2(tablePrefix, collectionIdVar), InvalidOid, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); FuncExpr *castConcatExpr = makeFuncExpr(F_REGCLASS, OIDOID, list_make1(concatExpr), DEFAULT_COLLATION_OID, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); /* Get the regclass of the join */ Var *regclassVar = makeVar(shardsRef->rtindex, 1, OIDOID, -1, InvalidOid, 0); FuncExpr *oidEqualFunc = makeFuncExpr(F_OIDEQ, BOOLOID, list_make2(regclassVar, castConcatExpr), DEFAULT_COLLATION_OID, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); quals = lappend(quals, oidEqualFunc); /* Join pg_dist_shard with shard_sizes */ Var *shardIdLeftVar = makeVar(shardsRef->rtindex, 2, INT8OID, -1, -1, 0); Var *shardIdRightVar = makeVar(shardSizesRef->rtindex, 1, INT8OID, -1, -1, 0); FuncExpr *shardIdEqual = makeFuncExpr(F_INT8EQ, BOOLOID, list_make2(shardIdLeftVar, shardIdRightVar), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); quals = lappend(quals, shardIdEqual); /* Join pg_dist_shard with pg_dist_placement */ Var *shardIdPlacementVar = makeVar(placementRef->rtindex, 2, INT8OID, -1, -1, 0); FuncExpr *shardIdPlacementEqual = makeFuncExpr(F_INT8EQ, BOOLOID, list_make2( shardIdLeftVar, shardIdPlacementVar), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); quals = lappend(quals, shardIdPlacementEqual); source->jointree = makeFromExpr(list_make4(collectionsRef, shardsRef, shardSizesRef, placementRef), (Node *) make_ands_explicit( quals)); Const *groupPrefix = MakeTextConst("shard_", 6); FuncExpr *groupIdStr = makeFuncExpr(F_TEXTANYCAT, TEXTOID, list_make2(groupPrefix, makeVar( placementRef->rtindex, 5, INT4OID, -1, -1, 0)), InvalidOid, DEFAULT_COLLATION_OID, COERCE_EXPLICIT_CALL); source->targetList = list_make5( makeTargetEntry((Expr *) makeVar(collectionsRef->rtindex, 1, TEXTOID, -1, -1, 0), 1, "database_name", false), makeTargetEntry((Expr *) makeVar(collectionsRef->rtindex, 2, TEXTOID, -1, -1, 0), 2, "collection_name", false), makeTargetEntry((Expr *) makeVar(shardsRef->rtindex, 2, INT8OID, -1, -1, 0), 3, "shard_id", false), makeTargetEntry((Expr *) makeVar(shardSizesRef->rtindex, 2, INT8OID, -1, -1, 0), 4, "size", false), makeTargetEntry((Expr *) groupIdStr, 5, "groupid", false)); source->targetList = lappend(source->targetList, makeTargetEntry((Expr *) makeVar( shardsRef-> rtindex, 5, TEXTOID, -1, -1, 0), 6, "shard_min", false)); source->targetList = lappend(source->targetList, makeTargetEntry((Expr *) makeVar( shardsRef-> rtindex, 6, TEXTOID, -1, -1, 0), 7, "shard_max", false)); RangeTblEntry *subQueryRte = MakeSubQueryRte(source, 1, 0, "config_shards_base", true); Var *rowExpr = makeVar(1, 0, RECORDOID, -1, InvalidOid, 0); FuncExpr *funcExpr = makeFuncExpr(RowGetBsonFunctionOid(), BsonTypeId(), list_make1(rowExpr), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); /* Build the projection spec for this query */ pgbson_writer specWriter; PgbsonWriterInit(&specWriter); PgbsonWriterAppendUtf8(&specWriter, "_id", 3, "$shard_id"); /* Write ns: */ pgbson_writer childWriter; PgbsonWriterStartDocument(&specWriter, "ns", 2, &childWriter); pgbson_array_writer childArray; PgbsonWriterStartArray(&childWriter, "$concat", 7, &childArray); PgbsonArrayWriterWriteUtf8(&childArray, "$database_name"); PgbsonArrayWriterWriteUtf8(&childArray, "."); PgbsonArrayWriterWriteUtf8(&childArray, "$collection_name"); PgbsonWriterEndArray(&childWriter, &childArray); PgbsonWriterEndDocument(&specWriter, &childWriter); PgbsonWriterAppendUtf8(&specWriter, "min", 3, "$shard_min"); PgbsonWriterAppendUtf8(&specWriter, "max", 3, "$shard_max"); PgbsonWriterAppendUtf8(&specWriter, "chunkSize", 9, "$size"); PgbsonWriterAppendUtf8(&specWriter, "shard", 5, "$groupid"); Const *specConst = MakeBsonConst(PgbsonWriterGetPgbson(&specWriter)); funcExpr = makeFuncExpr(BsonDollarProjectFunctionOid(), BsonTypeId(), list_make2(funcExpr, specConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *upperEntry = makeTargetEntry((Expr *) funcExpr, 1, "document", false); Query *newquery = makeNode(Query); newquery->commandType = CMD_SELECT; newquery->querySource = source->querySource; newquery->canSetTag = true; newquery->targetList = list_make1(upperEntry); newquery->rtable = list_make1(subQueryRte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; newquery->jointree = makeFromExpr(list_make1(rtr), NULL); return newquery; } static void UndistributeAndRedistributeTable(const char *postgresTable, const char *colocateWith, const char *shardKeyValue) { bool readOnly = false; bool resultNullIgnore = false; Oid tableDetailsArgTypes[3] = { TEXTOID, TEXTOID, TEXTOID }; Datum tableDetailsArgValues[3] = { CStringGetTextDatum(postgresTable), CStringGetTextDatum(colocateWith), (Datum) 0 }; char argNulls[3] = { ' ', ' ', 'n' }; /* This is a distributed table with distributionColumn == shard_key_value */ const char *undistributeTable = "SELECT undistribute_table($1)"; /* First undistribute the table.*/ ExtensionExecuteQueryWithArgsViaSPI(undistributeTable, 1, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); /* Then redistribute it as a single shard distributed table */ if (shardKeyValue != NULL) { tableDetailsArgValues[2] = CStringGetTextDatum(shardKeyValue); argNulls[2] = ' '; } const char *redistributeTable = "SELECT create_distributed_table($1::regclass, distribution_column => $3, colocate_with => $2)"; ExtensionExecuteQueryWithArgsViaSPI(redistributeTable, 3, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); } /* * For sharded citus tables, colocates the table with "none". */ static void ColocateShardedCitusTablesWithNone(const char *sourceTableName) { const char *colocateQuery = "SELECT alter_distributed_table(table_name => $1, colocate_with => $2, cascade_to_colocated => false)"; Oid argTypes[2] = { TEXTOID, TEXTOID }; Datum argValues[2] = { CStringGetTextDatum(sourceTableName), CStringGetTextDatum("none") }; char *argNulls = NULL; bool isNull = false; int colocateArgs = 2; ExtensionExecuteQueryWithArgsViaSPI(colocateQuery, colocateArgs, argTypes, argValues, argNulls, false, SPI_OK_SELECT, &isNull); } /* * Gets the distribution details of a given citus table. */ static void GetCitusTableDistributionDetails(const char *sourceTableName, const char **citusTableType, const char **distributionColumn, int64 *shardCount) { const char *tableDetailsQuery = "SELECT citus_table_type, distribution_column, shard_count FROM public.citus_tables WHERE table_name = $1::regclass"; Oid tableDetailsArgTypes[1] = { TEXTOID }; Datum tableDetailsArgValues[1] = { CStringGetTextDatum(sourceTableName) }; char *argNulls = NULL; bool readOnly = true; Datum results[3] = { 0 }; bool resultNulls[3] = { 0 }; ExtensionExecuteMultiValueQueryWithArgsViaSPI( tableDetailsQuery, 1, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, results, resultNulls, 3); if (resultNulls[0] || resultNulls[1] || resultNulls[2]) { ereport(ERROR, (errmsg( "Unexpected result found null value for shards query [0]=%d, [1]=%d, [2]=%d", resultNulls[0], resultNulls[1], resultNulls[2]))); } *citusTableType = TextDatumGetCString(results[0]); *distributionColumn = TextDatumGetCString(results[1]); *shardCount = DatumGetInt64(results[2]); } /* * breaks colocation for unsharded citus tables. */ static void ColocateUnshardedCitusTablesWithNone(const char *sourceTableName) { /* First get the current distribution mode/column. */ const char *citusTableType = NULL; const char *distributionColumn = NULL; int64 shardCount = 0; GetCitusTableDistributionDetails(sourceTableName, &citusTableType, &distributionColumn, &shardCount); ereport(NOTICE, (errmsg( "Current table type %s, distribution column %s, shardCount %ld", citusTableType, distributionColumn, shardCount))); /* Scenario 1: It's already a single shard distributed table */ bool readOnly = false; char *argNulls = NULL; bool resultNullIgnore = false; Oid tableDetailsArgTypes[1] = { TEXTOID }; Datum tableDetailsArgValues[1] = { CStringGetTextDatum(sourceTableName) }; if (strcmp(distributionColumn, "") == 0) { const char *updateColocationQuery = "SELECT update_distributed_table_colocation($1, colocate_with => 'none')"; ExtensionExecuteQueryWithArgsViaSPI(updateColocationQuery, 1, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); } else { const char *colocateWith = "none"; distributionColumn = NULL; UndistributeAndRedistributeTable(sourceTableName, colocateWith, distributionColumn); } } /* * Core logic for colocating 2 unsharded citus tables. */ static const char * ColocateUnshardedCitusTables(const char *tableToColocate, const char *colocateWithTableName) { const char *sourceCitusTableType = NULL; const char *sourceDistributionColumn = NULL; int64 sourceShardCount = 0; GetCitusTableDistributionDetails(tableToColocate, &sourceCitusTableType, &sourceDistributionColumn, &sourceShardCount); ereport(INFO, (errmsg("Source table type %s, distribution column %s, shardCount %ld", sourceCitusTableType, sourceDistributionColumn, sourceShardCount))); if (sourceShardCount != 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Cannot colocate collection to source in current state. Please colocate the source collection with colocation: none"))); } bool resultNullIgnore = false; char *argNulls = NULL; const char *targetCitusTableType = NULL; const char *targetDistributionColumn = NULL; int64 targetShardCount = 0; GetCitusTableDistributionDetails(colocateWithTableName, &targetCitusTableType, &targetDistributionColumn, &targetShardCount); ereport(INFO, (errmsg("Target table type %s, distribution column %s, shardCount %ld", targetCitusTableType, targetDistributionColumn, targetShardCount))); bool isTableSingleShardDistributed = strcmp(tableToColocate, "") == 0; if (strcmp(targetDistributionColumn, "") == 0) { /* target is a single shard distributed table */ if (isTableSingleShardDistributed) { Oid tableDetailsArgTypes[2] = { TEXTOID, TEXTOID }; Datum tableDetailsArgValues[2] = { CStringGetTextDatum(tableToColocate), (Datum) 0 }; /* First update colocation data to none */ const char *updateDistributionToNoneQuery = "SELECT update_distributed_table_colocation($1, colocate_with => 'none')"; bool readOnly = false; ExtensionExecuteQueryWithArgsViaSPI(updateDistributionToNoneQuery, 1, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); /* Then move the shard to match the source table */ MoveShardToDistributedTable(tableToColocate, colocateWithTableName); /* Match the colocation to the other table */ const char *updateDistributionToTargetTable = "SELECT update_distributed_table_colocation($1, colocate_with => $2)"; tableDetailsArgValues[1] = CStringGetTextDatum(colocateWithTableName); ExtensionExecuteQueryWithArgsViaSPI(updateDistributionToTargetTable, 2, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); } else { /* This is a distributed table with distributionColumn == shard_key_value */ const char *distributionColumn = NULL; UndistributeAndRedistributeTable(tableToColocate, colocateWithTableName, distributionColumn); } /* Distribution column is none */ return NULL; } else { /* The target is a distributed table with a single shard (legacy tables) */ if (isTableSingleShardDistributed) { /* We need to back-convert this to a single shard distributed table. */ /* This is a distributed table with distributionColumn == shard_key_value */ UndistributeAndRedistributeTable(tableToColocate, colocateWithTableName, "shard_key_value"); } else { /* Neither tables are single shard distributed. */ /* We need to back-convert this to a single shard distributed table. */ /* This is a distributed table with distributionColumn == shard_key_value */ Oid tableDetailsArgTypes[2] = { TEXTOID, TEXTOID }; Datum tableDetailsArgValues[2] = { CStringGetTextDatum(tableToColocate), CStringGetTextDatum( colocateWithTableName) }; /* Now create distributed table with colocation with the target */ const char *alterDistributedTableQuery = "SELECT alter_distributed_table(table_name => $1, colocate_with => $2)"; bool readOnly = false; ExtensionExecuteQueryWithArgsViaSPI(alterDistributedTableQuery, 2, tableDetailsArgTypes, tableDetailsArgValues, argNulls, readOnly, SPI_OK_SELECT, &resultNullIgnore); } /* legacy table value */ return "shard_key_value"; } } static int GetShardCountForDistributedTable(Oid relationId) { const char *shardIdCountQuery = "SELECT COUNT(*) FROM pg_dist_shard WHERE logicalrelid = $1"; Oid shardCountArgTypes[1] = { OIDOID }; Datum shardCountArgValues[1] = { ObjectIdGetDatum(relationId) }; char *argNullNone = NULL; bool readOnly = true; bool isNull = false; Datum shardIdDatum = ExtensionExecuteQueryWithArgsViaSPI(shardIdCountQuery, 1, shardCountArgTypes, shardCountArgValues, argNullNone, readOnly, SPI_OK_SELECT, &isNull); if (isNull) { return 0; } return DatumGetInt64(shardIdDatum); } /* * Gets the colocationId for a given pg table. */ static int GetColocationForTable(Oid tableOid, const char *collectionName, const char *tableName) { char *colocationId = "SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = $1"; int numArgs = 1; Oid argTypes[1] = { OIDOID }; Datum argValues[1] = { ObjectIdGetDatum(tableOid) }; char *argNulls = NULL; bool isNull = false; Datum result = ExtensionExecuteQueryWithArgsViaSPI(colocationId, numArgs, argTypes, argValues, argNulls, false, SPI_OK_SELECT, &isNull); if (isNull) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Could not find collection in internal colocation metadata: %s", collectionName), errdetail_log( "Could not find collection in internal colocation metadata %s: %s", collectionName, tableName))); } return DatumGetInt32(result); } /* * Gets the node level details for a single shard table. */ static void GetNodeNamePortForPostgresTable(const char *postgresTable, char **nodeName, int *nodePort, int64 *shardId) { char *allArgsProvidedNulls = NULL; int shardIdQuerynArgs = 1; Datum shardIdArgValues[1] = { CStringGetTextDatum(postgresTable) }; Oid shardIdArgTypes[1] = { TEXTOID }; bool readOnly = false; bool isNull = false; const char *shardIdQuery = "SELECT shardid FROM pg_dist_shard WHERE logicalrelid = $1::regclass"; /* While all these queries appear read-only inner Citus code seems to break this assumption * And these queries fail when readOnly is marked as TRUE. Until the underlying issue is fixed * in citus, these are left as read-only false. */ Datum shardIdValue = ExtensionExecuteQueryWithArgsViaSPI(shardIdQuery, shardIdQuerynArgs, shardIdArgTypes, shardIdArgValues, allArgsProvidedNulls, readOnly, SPI_OK_SELECT, &isNull); if (isNull) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Could not extract shard_id for newly created table"), errdetail_log("Could not get shardId value for postgres table %s", postgresTable))); } /* Now get the source node/port for this shard */ const char *shardPlacementTable = "SELECT nodename, nodeport FROM pg_dist_shard_placement WHERE shardid = $1"; int shardPlacementArgs = 1; Datum shardPlacementArgValues[1] = { shardIdValue }; Oid shardPlacementArgTypes[1] = { INT8OID }; Datum currentNodeDatums[2] = { 0 }; bool currentNodeIsNulls[2] = { 0 }; ExtensionExecuteMultiValueQueryWithArgsViaSPI(shardPlacementTable, shardPlacementArgs, shardPlacementArgTypes, shardPlacementArgValues, allArgsProvidedNulls, readOnly, SPI_OK_SELECT, currentNodeDatums, currentNodeIsNulls, 2); if (currentNodeIsNulls[0] || currentNodeIsNulls[1]) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Could not find shard placement for newly created table shard"), errdetail_log( "Could not find shardId %ld in the placement table for table %s: node is null %d, port is null %d", DatumGetInt64(shardIdValue), postgresTable, currentNodeIsNulls[0], currentNodeIsNulls[1]))); } *nodeName = TextDatumGetCString(currentNodeDatums[0]); *nodePort = DatumGetInt32(currentNodeDatums[1]); *shardId = DatumGetInt64(shardIdValue); } /* * Moves a single shard table to be colocated with another target single shard table. */ static void MoveShardToDistributedTable(const char *postgresTableToMove, const char *targetShardTable) { char *toMoveNodeName, *targetNodeName; int toMoveNodePort, targetNodePort; int64 toMoveShardId, targetShardId; GetNodeNamePortForPostgresTable(postgresTableToMove, &toMoveNodeName, &toMoveNodePort, &toMoveShardId); GetNodeNamePortForPostgresTable(targetShardTable, &targetNodeName, &targetNodePort, &targetShardId); elog(INFO, "Moving shard %ld from %s:%d to %s:%d", DatumGetInt64(toMoveShardId), toMoveNodeName, toMoveNodePort, targetNodeName, targetNodePort); const char *moveShardQuery = "SELECT citus_move_shard_placement(shard_id => $1, source_node_name => $2, source_node_port => $3," " target_node_name => $4, target_node_port => $5, shard_transfer_mode => 'block_writes'::citus.shard_transfer_mode)"; Datum moveShardDatums[5] = { toMoveShardId, CStringGetTextDatum(toMoveNodeName), Int32GetDatum(toMoveNodePort), CStringGetTextDatum(targetNodeName), Int32GetDatum(targetNodePort) }; Oid moveShardTypes[5] = { INT8OID, TEXTOID, INT4OID, TEXTOID, INT4OID }; bool resultIsNullIgnore = false; char *allArgsProvidedNulls = NULL; bool readOnly = false; ExtensionExecuteQueryWithArgsViaSPI(moveShardQuery, 5, moveShardTypes, moveShardDatums, allArgsProvidedNulls, readOnly, SPI_OK_SELECT, &resultIsNullIgnore); } static void WriteShardMap(pgbson_writer *writer, List *groupMap) { /* Now that we have the list ordered by group & role, write out the object */ /* First object is "map" */ pgbson_writer childWriter; StringInfo hostStringInfo = makeStringInfo(); int32_t groupId = -1; ListCell *listCell; const char *shardName = NULL; char *separator = ""; PgbsonWriterStartDocument(writer, "map", 3, &childWriter); foreach(listCell, groupMap) { NodeInfo *nodeInfo = lfirst(listCell); if (nodeInfo->groupId != groupId) { /* New groupId */ if (shardName != NULL) { PgbsonWriterAppendUtf8(&childWriter, shardName, -1, hostStringInfo->data); resetStringInfo(hostStringInfo); } shardName = nodeInfo->mongoShardName; groupId = nodeInfo->groupId; appendStringInfo(hostStringInfo, "%s/", nodeInfo->mongoShardName); separator = ""; } if (nodeInfo->isactive) { appendStringInfo(hostStringInfo, "%s%s", separator, nodeInfo->mongoNodeName); separator = ","; } } if (shardName != NULL && hostStringInfo->len > 0) { PgbsonWriterAppendUtf8(&childWriter, shardName, -1, hostStringInfo->data); } PgbsonWriterEndDocument(writer, &childWriter); /* Now write the hosts object */ PgbsonWriterStartDocument(writer, "hosts", 5, &childWriter); foreach(listCell, groupMap) { NodeInfo *nodeInfo = lfirst(listCell); if (nodeInfo->isactive) { PgbsonWriterAppendUtf8(&childWriter, nodeInfo->mongoNodeName, -1, nodeInfo->mongoShardName); } } PgbsonWriterEndDocument(writer, &childWriter); /* Now write the nodes object */ PgbsonWriterStartDocument(writer, "nodes", 5, &childWriter); foreach(listCell, groupMap) { NodeInfo *nodeInfo = lfirst(listCell); pgbson_writer nodeWriter; PgbsonWriterStartDocument(&childWriter, nodeInfo->mongoNodeName, -1, &nodeWriter); PgbsonWriterAppendUtf8(&nodeWriter, "role", 4, nodeInfo->nodeRole); PgbsonWriterAppendBool(&nodeWriter, "active", 6, nodeInfo->isactive); PgbsonWriterAppendUtf8(&nodeWriter, "cluster", 7, nodeInfo->nodeCluster); PgbsonWriterEndDocument(&childWriter, &nodeWriter); } PgbsonWriterEndDocument(writer, &childWriter); } static void WriteShardList(pgbson_writer *writer, List *groupMap) { pgbson_array_writer arrayWriter; PgbsonWriterStartArray(writer, "shards", 6, &arrayWriter); ListCell *listCell; StringInfo hostStringInfo = makeStringInfo(); int32_t groupId = -1; const char *shardName = NULL; char *separator = ""; pgbson_writer nestedObjectWriter; foreach(listCell, groupMap) { NodeInfo *nodeInfo = lfirst(listCell); if (nodeInfo->groupId != groupId) { /* New groupId */ if (shardName != NULL) { PgbsonArrayWriterStartDocument(&arrayWriter, &nestedObjectWriter); PgbsonWriterAppendUtf8(&nestedObjectWriter, "_id", 3, shardName); PgbsonWriterAppendUtf8(&nestedObjectWriter, "nodes", 5, hostStringInfo->data); PgbsonArrayWriterEndDocument(&arrayWriter, &nestedObjectWriter); resetStringInfo(hostStringInfo); } shardName = nodeInfo->mongoShardName; groupId = nodeInfo->groupId; appendStringInfo(hostStringInfo, "%s/", nodeInfo->mongoShardName); separator = ""; } if (nodeInfo->isactive) { appendStringInfo(hostStringInfo, "%s%s", separator, nodeInfo->mongoNodeName); separator = ","; } } if (shardName != NULL && hostStringInfo->len > 0) { PgbsonArrayWriterStartDocument(&arrayWriter, &nestedObjectWriter); PgbsonWriterAppendUtf8(&nestedObjectWriter, "_id", 3, shardName); PgbsonWriterAppendUtf8(&nestedObjectWriter, "nodes", 5, hostStringInfo->data); PgbsonArrayWriterEndDocument(&arrayWriter, &nestedObjectWriter); } PgbsonWriterEndArray(writer, &arrayWriter); } /* * Fetches the nodes in the cluster ordered by groupId and nodeRole. */ static List * GetShardMapNodes(void) { /* First query pg_dist_node to get the set of nodes in the cluster */ const char *baseQuery = psprintf( "WITH base AS (SELECT groupid, nodeid, noderole::text, nodecluster::text, isactive FROM pg_dist_node WHERE shouldhaveshards ORDER BY groupid, noderole)" " SELECT %s.BSON_ARRAY_AGG(%s.row_get_bson(base), 'nodes') FROM base", ApiCatalogSchemaName, ApiCatalogSchemaName); bool isNull = true; Datum nodeDatum = ExtensionExecuteQueryViaSPI(baseQuery, true, SPI_OK_SELECT, &isNull); if (isNull) { return NIL; } pgbson *queryResult = DatumGetPgBson(nodeDatum); pgbsonelement singleElement; bson_iter_t arrayIter; PgbsonToSinglePgbsonElement(queryResult, &singleElement); if (singleElement.bsonValue.value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Unexpected - getShardMap path %s should have an array not %s", singleElement.path, BsonTypeName(singleElement.bsonValue.value_type)), errdetail_log( "Unexpected - getShardMap path %s should have an array not %s", singleElement.path, BsonTypeName(singleElement.bsonValue.value_type)))); } BsonValueInitIterator(&singleElement.bsonValue, &arrayIter); List *groupMap = NIL; int32_t currentGroup = -1; while (bson_iter_next(&arrayIter)) { if (!BSON_ITER_HOLDS_DOCUMENT(&arrayIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Unexpected - getShardMap inner groupId %d should have a document not %s", currentGroup, BsonTypeName(bson_iter_type(&arrayIter))), errdetail_log( "Unexpected - getShardMap inner groupId %d should have a document not %s", currentGroup, BsonTypeName(bson_iter_type(&arrayIter))))); } bson_iter_t objectIter; NodeInfo *nodeInfo = palloc0(sizeof(NodeInfo)); if (bson_iter_recurse(&arrayIter, &objectIter)) { int numFields = 0; while (bson_iter_next(&objectIter)) { const char *key = bson_iter_key(&objectIter); if (strcmp(key, "groupid") == 0) { nodeInfo->groupId = bson_iter_int32(&objectIter); currentGroup = nodeInfo->groupId; numFields++; } else if (strcmp(key, "nodeid") == 0) { nodeInfo->nodeId = bson_iter_int32(&objectIter); numFields++; } else if (strcmp(key, "noderole") == 0) { nodeInfo->nodeRole = bson_iter_dup_utf8(&objectIter, NULL); numFields++; } else if (strcmp(key, "nodecluster") == 0) { nodeInfo->nodeCluster = bson_iter_dup_utf8(&objectIter, NULL); numFields++; } else if (strcmp(key, "isactive") == 0) { nodeInfo->isactive = bson_iter_bool(&objectIter); numFields++; } } if (numFields != 5) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Found missing fields in querying shard table: Found %d fields", numFields), errdetail_log( "Found missing fields in querying shard table: Found %d fields", numFields))); } nodeInfo->mongoNodeName = psprintf("node_%s_%d", nodeInfo->nodeCluster, nodeInfo->nodeId); nodeInfo->mongoShardName = psprintf("shard_%d", nodeInfo->groupId); groupMap = lappend(groupMap, nodeInfo); } } return groupMap; } documentdb-0.108-0/internal/pg_documentdb_distributed/src/distribution/000077500000000000000000000000001507310017400263375ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/distribution/cluster_operations.c000066400000000000000000001005471507310017400324360ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/distribution/cluster_operations.c * * Implementation of a set of cluster operations (e.g. upgrade, initialization, etc). * *------------------------------------------------------------------------- */ #include "postgres.h" #include "fmgr.h" #include "miscadmin.h" #include "utils/builtins.h" #include "utils/resowner.h" #include "lib/stringinfo.h" #include "access/xact.h" #include "utils/typcache.h" #include "parser/parse_type.h" #include "nodes/makefuncs.h" #include "utils/documentdb_errors.h" #include "metadata/collection.h" #include "metadata/index.h" #include "metadata/metadata_cache.h" #include "utils/guc_utils.h" #include "utils/query_utils.h" #include "utils/version_utils.h" #include "utils/error_utils.h" #include "utils/version_utils_private.h" #include "utils/data_table_utils.h" #include "api_hooks.h" extern char *ApiExtensionName; extern char *ApiGucPrefix; extern char *ClusterAdminRole; char *ApiDistributedSchemaName = "documentdb_api_distributed"; char *ApiDistributedSchemaNameV2 = "documentdb_api_distributed"; char *DistributedExtensionName = "documentdb_distributed"; bool CreateDistributedFunctions = false; bool CreateIndexBuildQueueTable = false; typedef struct ClusterOperationVersions { ExtensionVersion InstalledVersion; ExtensionVersion LastUpgradeVersion; } ClusterOperationVersions; extern char * GetIndexQueueName(void); static char * GetClusterInitializedVersion(void); static void DistributeCrudFunctions(void); static void CreateIndexBuildsTable(void); static void CreateValidateDbNameTrigger(void); static void AlterDefaultDatabaseObjects(void); static char * UpdateClusterMetadata(bool isInitialize); static void CreateReferenceTable(const char *tableName); static void CreateDistributedFunction(const char *functionName, const char *distributionArgName, const char *colocateWith, const char *forceDelegation); static void DropLegacyChangeStream(void); static void AddUserColumnsToIndexQueue(void); static void TriggerInvalidateClusterMetadata(void); static void AddCollectionsTableViewDefinition(void); static void AddCollectionsTableValidationColumns(void); static void CreateExtensionVersionsTrigger(void); static bool VersionEquals(ExtensionVersion versionA, ExtensionVersion versionB); static void GetInstalledVersion(ExtensionVersion *installedVersion); static void ParseVersionString(ExtensionVersion *extensionVersion, char *versionString); static bool SetupCluster(bool isInitialize); static void SetPermissionsForReadOnlyRole(void); static void CheckAndReplicateReferenceTable(const char *schema, const char *tableName); static void UpdateChangesTableOwnerToAdminRole(void); PG_FUNCTION_INFO_V1(command_initialize_cluster); PG_FUNCTION_INFO_V1(command_complete_upgrade); /* * command_initialize_cluster implements the core * logic to initialize the extension in the cluster */ Datum command_initialize_cluster(PG_FUNCTION_ARGS) { char *initializedVersion = GetClusterInitializedVersion(); if (initializedVersion != NULL) { ereport(NOTICE, errmsg( "Initialize: version is up-to-date. Skipping initialize_cluster")); PG_RETURN_VOID(); } bool isInitialize = true; SetupCluster(isInitialize); PG_RETURN_VOID(); } /* * command_complete_upgrade executes the necessary steps * to perform an extension upgrade. */ Datum command_complete_upgrade(PG_FUNCTION_ARGS) { /* Since complete_upgrade is internal operation, if the disk is full and we have readonly setting on, we should be able to upgrade so we turn off. */ int savedGUCLevel = NewGUCNestLevel(); SetGUCLocally(psprintf("%s.IsPgReadOnlyForDiskFull", ApiGucPrefix), "false"); bool isInitialize = false; bool upgraded = SetupCluster(isInitialize); RollbackGUCChange(savedGUCLevel); PG_RETURN_BOOL(upgraded); } /* * Helper function that checks if the setup scripts for a given extension version must be executed * in SetupCluster. It checks whether it's greater than the last upgraded version and less or equal * than the current installed version. */ static inline bool ShouldRunSetupForVersion(ClusterOperationVersions *versions, MajorVersion major, int minor, int patch) { return !IsExtensionVersionAtleast(versions->LastUpgradeVersion, major, minor, patch) && IsExtensionVersionAtleast(versions->InstalledVersion, major, minor, patch); } static bool ShouldRunSetupForVersionForHook(void *versionsVoid, int major, int minor, int patch) { return ShouldRunSetupForVersion((ClusterOperationVersions *) versionsVoid, (MajorVersion) major, minor, patch); } /* * Function that runs the necessary steps to initialize and upgrade a cluster. */ static bool SetupCluster(bool isInitialize) { ExtensionVersion lastUpgradeVersion = { 0 }; ExtensionVersion installedVersion = { 0 }; /* Ensure that the cluster_data table is replicated on all nodes * otherwise, writes to cluster_data will fail. */ EnsureMetadataTableReplicated("collections"); char *lastUpgradeVersionString = UpdateClusterMetadata(isInitialize); ParseVersionString(&lastUpgradeVersion, lastUpgradeVersionString); GetInstalledVersion(&installedVersion); /* For initialize, lastUpgradeVersion will always be 1.0-4, which is the default version for a new cluster until we finish SetupCluster. */ if (VersionEquals(installedVersion, lastUpgradeVersion)) { ereport(NOTICE, errmsg( "version is up-to-date. Skipping function")); return false; } if (!isInitialize) { ereport(NOTICE, errmsg( "Previous Version Major=%d, Minor=%d, Patch=%d; Current Version Major=%d, Minor=%d, Patch=%d", lastUpgradeVersion.Major, lastUpgradeVersion.Minor, lastUpgradeVersion.Patch, installedVersion.Major, installedVersion.Minor, installedVersion.Patch)); } ClusterOperationVersions versions = { .InstalledVersion = installedVersion, .LastUpgradeVersion = lastUpgradeVersion }; /* If the version is < 0.0-5 or if it's an initialize ensure metadata collections are created */ if (isInitialize || ShouldRunSetupForVersion(&versions, DocDB_V0, 0, 5)) { /* * We should only create and modify schema objects here for versions that are no longer covered by the upgrade path. */ StringInfo relationName = makeStringInfo(); appendStringInfo(relationName, "%s.collections", ApiCatalogSchemaName); CreateReferenceTable(relationName->data); resetStringInfo(relationName); appendStringInfo(relationName, "%s.collection_indexes", ApiCatalogSchemaName); CreateReferenceTable(relationName->data); DistributeCrudFunctions(); CreateValidateDbNameTrigger(); /* As of 1.23 the schema installs the type columns. */ if (!IsExtensionVersionAtleast(installedVersion, DocDB_V0, 23, 0)) { AlterDefaultDatabaseObjects(); } resetStringInfo(relationName); appendStringInfo(relationName, "%s.%s_cluster_data", ApiDistributedSchemaName, ExtensionObjectPrefix); CreateReferenceTable(relationName->data); } /* * For initialize, lastUpgradeVersion will always be 1.4-0, so all of the below conditions will apply if the installedVersion meets the requirement. */ if (ShouldRunSetupForVersion(&versions, DocDB_V0, 7, 0)) { AddCollectionsTableViewDefinition(); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 7, 0) && !ShouldRunSetupForVersion(&versions, DocDB_V0, 12, 0)) { /* Schedule happens again at 1.12 */ ScheduleIndexBuildTasks(ExtensionObjectPrefix); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 8, 0)) { CreateExtensionVersionsTrigger(); /* We invalidate the cache in order to enable the extension versions trigger we just created. */ TriggerInvalidateClusterMetadata(); AddCollectionsTableValidationColumns(); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 12, 0)) { CreateIndexBuildsTable(); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 12, 0) && !ShouldRunSetupForVersion(&versions, DocDB_V0, 15, 0)) { /* Unschedule index tasks from old queue. */ char *oldExtensionPrefix = ExtensionObjectPrefix; UnscheduleIndexBuildTasks(oldExtensionPrefix); char *extensionPrefix = ExtensionObjectPrefixV2; ScheduleIndexBuildTasks(extensionPrefix); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 14, 0)) { DropLegacyChangeStream(); AddUserColumnsToIndexQueue(); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 15, 0)) { /* reduce the Index background cron job schedule to 2 seconds by default. */ char *extensionPrefix = ExtensionObjectPrefixV2; UnscheduleIndexBuildTasks(extensionPrefix); ScheduleIndexBuildTasks(extensionPrefix); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 17, 1)) { SetPermissionsForReadOnlyRole(); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 21, 0)) { if (!isInitialize && ClusterAdminRole[0] != '\0') { StringInfo cmdStr = makeStringInfo(); bool isNull = false; appendStringInfo(cmdStr, "GRANT %s, %s TO %s WITH ADMIN OPTION;", ApiAdminRoleV2, ApiReadOnlyRole, quote_identifier(ClusterAdminRole)); ExtensionExecuteQueryViaSPI(cmdStr->data, false, SPI_OK_UTILITY, &isNull); } } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 23, 0)) { /* Re-add the primary key in the context of the cluster operations. */ StringInfo cmdStr = makeStringInfo(); bool isNull = false; appendStringInfo(cmdStr, "ALTER TABLE %s.%s_cluster_data DROP CONSTRAINT IF EXISTS %s_cluster_data_pkey", ApiDistributedSchemaName, ExtensionObjectPrefix, ExtensionObjectPrefix); ExtensionExecuteQueryViaSPI(cmdStr->data, false, SPI_OK_UTILITY, &isNull); resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TABLE %s.%s_cluster_data ADD PRIMARY KEY(metadata)", ApiDistributedSchemaName, ExtensionObjectPrefix); ExtensionExecuteQueryViaSPI(cmdStr->data, false, SPI_OK_UTILITY, &isNull); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 23, 2)) { CheckAndReplicateReferenceTable(ApiCatalogSchemaName, "collections"); CheckAndReplicateReferenceTable(ApiCatalogSchemaName, "collection_indexes"); StringInfo relationName = makeStringInfo(); appendStringInfo(relationName, "%s_cluster_data", ExtensionObjectPrefix); CheckAndReplicateReferenceTable(ApiDistributedSchemaName, relationName->data); } if (ShouldRunSetupForVersion(&versions, DocDB_V0, 102, 0)) { UpdateChangesTableOwnerToAdminRole(); } /* we call the post setup cluster hook to allow the extension to do any additional setup */ PostSetupClusterHook(isInitialize, &ShouldRunSetupForVersionForHook, &versions); TriggerInvalidateClusterMetadata(); return true; } /* * Returns the current installed version of the extension in the cluster. If it's not installed, * then NULL is returned. */ static char * GetClusterInitializedVersion() { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT %s.bson_get_value_text(metadata, 'initialized_version') FROM " "%s.%s_cluster_data;", CoreSchemaName, ApiDistributedSchemaName, ExtensionObjectPrefix); bool isNull = false; bool readOnly = true; Datum resultDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, &isNull); if (isNull) { return NULL; } return text_to_cstring(DatumGetTextP(resultDatum)); } /* * Creates all distributed objects required by the extension to run in the cluster. */ static void DistributeCrudFunctions() { /* TODO: when we move to OSS revisit change stream stuff. */ /* Table is distributed and co-located with the collections it is tracking */ const char *distributionArgName = "p_shard_key_value"; const char *forceDelegation = "true"; char changesRelation[50]; sprintf(changesRelation, "%s.changes", ApiDataSchemaName); const char *distributionColumn = "shard_key_value"; const char *colocateWith = "none"; int shardCount = 0; DistributePostgresTable(changesRelation, distributionColumn, colocateWith, shardCount); if (!CreateDistributedFunctions) { return; } StringInfo relationName = makeStringInfo(); /* Push down the delete/insert/update one function calls */ appendStringInfo(relationName, "%s.delete_one(bigint,bigint,%s,%s,bool,%s,text)", ApiInternalSchemaName, FullBsonTypeName, FullBsonTypeName, FullBsonTypeName); CreateDistributedFunction( relationName->data, distributionArgName, changesRelation, forceDelegation ); resetStringInfo(relationName); appendStringInfo(relationName, "%s.insert_one(bigint,bigint,%s,text)", ApiInternalSchemaName, FullBsonTypeName); CreateDistributedFunction( relationName->data, distributionArgName, changesRelation, forceDelegation ); resetStringInfo(relationName); appendStringInfo(relationName, "%s.update_one(bigint,bigint,%s,%s,%s,bool,%s,bool,%s,%s,text)", ApiInternalSchemaName, FullBsonTypeName, FullBsonTypeName, FullBsonTypeName, FullBsonTypeName, FullBsonTypeName, FullBsonTypeName); CreateDistributedFunction( relationName->data, distributionArgName, changesRelation, forceDelegation ); } static void CreateIndexBuildQueueCore() { bool readOnly = false; bool isNull = false; StringInfo dropStr = makeStringInfo(); appendStringInfo(dropStr, "DROP TABLE IF EXISTS %s;", GetIndexQueueName()); ExtensionExecuteQueryViaSPI(dropStr->data, readOnly, SPI_OK_UTILITY, &isNull); StringInfo createStr = makeStringInfo(); appendStringInfo(createStr, "CREATE TABLE IF NOT EXISTS %s (" "index_cmd text not null," /* 'C' for CREATE INDEX and 'R' for REINDEX */ "cmd_type char CHECK (cmd_type IN ('C', 'R'))," "index_id integer not null," /* index_cmd_status gets represented as enum IndexCmdStatus in index.h */ "index_cmd_status integer default 1," "global_pid bigint," "start_time timestamp WITH TIME ZONE," "collection_id bigint not null," /* Used to enter the error encounter during execution of index_cmd */ "comment %s.bson," /* current attempt counter for retrying the failed request */ "attempt smallint," /* update_time shows the time when request was updated in the table */ "update_time timestamp with time zone DEFAULT now()" ")", GetIndexQueueName(), CoreSchemaName); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(createStr); appendStringInfo(createStr, "CREATE INDEX IF NOT EXISTS %s_index_queue_indexid_cmdtype on %s (index_id, cmd_type)", ExtensionObjectPrefixV2, GetIndexQueueName()); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(createStr); appendStringInfo(createStr, "CREATE INDEX IF NOT EXISTS %s_index_queue_cmdtype_collectionid_cmdstatus on %s (cmd_type, collection_id, index_cmd_status)", ExtensionObjectPrefixV2, GetIndexQueueName()); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(createStr); appendStringInfo(createStr, "GRANT SELECT ON TABLE %s TO public", GetIndexQueueName()); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(createStr); appendStringInfo(createStr, "GRANT ALL ON TABLE %s TO %s, %s", GetIndexQueueName(), ApiAdminRoleV2, ApiAdminRole); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Create index queue table, its indexes and grant permissions. */ static void CreateIndexBuildsTable() { /* Create index builds table if legacy compat */ if (CreateIndexBuildQueueTable) { CreateIndexBuildQueueCore(); } bool readOnly = false; bool isNull = false; StringInfo createStr = makeStringInfo(); appendStringInfo(createStr, "SELECT citus_add_local_table_to_metadata('%s')", GetIndexQueueName()); ExtensionExecuteQueryViaSPI(createStr->data, readOnly, SPI_OK_SELECT, &isNull); } /* * Create validate_dbname trigger on the collections table. */ static void CreateValidateDbNameTrigger() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "CREATE OR REPLACE TRIGGER collections_trigger_validate_dbname " "BEFORE INSERT OR UPDATE ON %s.collections " "FOR EACH ROW EXECUTE FUNCTION " "%s.trigger_validate_dbname();", ApiCatalogSchemaName, ApiCatalogToApiInternalSchemaName); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Handle failures if the worker has the attribute. * This handles mixed schema versioning. */ static bool AddAttributeHandleIfExists(const char *addAttributeQuery) { volatile bool isSuccess = false; /* use a subtransaction to correctly handle failures */ MemoryContext oldContext = CurrentMemoryContext; ResourceOwner oldOwner = CurrentResourceOwner; BeginInternalSubTransaction(NULL); PG_TRY(); { bool readOnly = false; bool isNull = false; ExtensionExecuteQueryViaSPI(addAttributeQuery, readOnly, SPI_OK_UTILITY, &isNull); /* Commit the inner transaction, return to outer xact context */ ReleaseCurrentSubTransaction(); MemoryContextSwitchTo(oldContext); CurrentResourceOwner = oldOwner; isSuccess = true; } PG_CATCH(); { MemoryContextSwitchTo(oldContext); ErrorData *errorData = CopyErrorDataAndFlush(); /* Abort inner transaction */ RollbackAndReleaseCurrentSubTransaction(); /* Rollback changes MemoryContext */ MemoryContextSwitchTo(oldContext); CurrentResourceOwner = oldOwner; if (errorData->sqlerrcode != ERRCODE_DUPLICATE_COLUMN) { ReThrowError(errorData); } isSuccess = false; } PG_END_TRY(); return isSuccess; } /* * Change internal tables to include new fields and constraints required by the extension. * TODO: Remove this after Cluster Version 1.23-0 */ static void AlterDefaultDatabaseObjects() { StringInfo cmdStr = makeStringInfo(); /* -- We do the ALTER TYPE in the Initialize/Complete function so that we handle the */ /* -- upgrade scenarios where worker/coordinator are in mixed versions. Ser/Der/Casting would */ /* -- fail if any one upgrades first and we did the ALTER TYPE in the extension upgrade. */ /* -- by doing this in the initialize/complete, we guarantee it happens once from the DDL */ /* -- coordinator and it's transactional. */ resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TYPE %s.index_spec_type_internal ADD ATTRIBUTE cosmos_search_options %s.bson;", ApiCatalogSchemaName, CoreSchemaName); bool attributeAdded = AddAttributeHandleIfExists(cmdStr->data); if (!attributeAdded) { /* Scenario where worker has it but coordinator doesn't, disable DDL propagation and try again */ int gucLevel = NewGUCNestLevel(); SetGUCLocally("citus.enable_ddl_propagation", "off"); AddAttributeHandleIfExists(cmdStr->data); RollbackGUCChange(gucLevel); } /* -- all new options will go into this one bson field. */ /* -- Older options will be cleaned up in a separate release. */ resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TYPE %s.index_spec_type_internal ADD ATTRIBUTE index_options %s.bson;", ApiCatalogSchemaName, CoreSchemaName); attributeAdded = AddAttributeHandleIfExists(cmdStr->data); if (!attributeAdded) { /* Scenario where worker has it but coordinator doesn't, disable DDL propagation and try again */ int gucLevel = NewGUCNestLevel(); SetGUCLocally("citus.enable_ddl_propagation", "off"); AddAttributeHandleIfExists(cmdStr->data); RollbackGUCChange(gucLevel); } } /* * Adds bson column view_definition to the collections table. */ static void AddCollectionsTableViewDefinition() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "ALTER TABLE %s.collections ADD IF NOT EXISTS view_definition " "%s.bson default null;", ApiCatalogSchemaName, CoreSchemaName); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Add schema validation columns to the collections table. */ static void AddCollectionsTableValidationColumns() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "ALTER TABLE %s.collections " "ADD COLUMN IF NOT EXISTS validator %s.bson DEFAULT null, " "ADD COLUMN IF NOT EXISTS validation_level text DEFAULT null CONSTRAINT validation_level_check CHECK (validation_level IN ('off', 'strict', 'moderate')), " "ADD COLUMN IF NOT EXISTS validation_action text DEFAULT null CONSTRAINT validation_action_check CHECK (validation_action IN ('warn', 'error'));", ApiCatalogSchemaName, CoreSchemaName); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Creates trigger for updates or deletes in the cluster_data table from the catalog schema. */ static void CreateExtensionVersionsTrigger() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "CREATE TRIGGER %s_versions_trigger " "AFTER UPDATE OR DELETE ON " "%s.%s_cluster_data " "FOR STATEMENT EXECUTE FUNCTION " "%s.update_%s_version_data();", ExtensionObjectPrefix, ApiDistributedSchemaName, ExtensionObjectPrefix, ApiInternalSchemaName, ExtensionObjectPrefix); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Create a distributed reference table. */ static void CreateReferenceTable(const char *tableName) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT create_reference_table('%s');", tableName); bool isNull = false; bool readOnly = false; ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, &isNull); } /* * Create a distributed function. */ static void CreateDistributedFunction(const char *functionName, const char *distributionArgName, const char *colocateWith, const char *forceDelegation) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT create_distributed_function('%s', '%s', colocate_with := '%s', force_delegation := %s);", functionName, distributionArgName, colocateWith, forceDelegation); bool isNull = false; bool readOnly = false; ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, &isNull); } /* * Cleaning change_stream related constructs that were used for backward compatibility. */ static void DropLegacyChangeStream() { bool readOnly = false; bool isNull = false; ArrayType *arrayValue = GetCollectionIds(); if (arrayValue == NULL) { return; } StringInfo cmdStr = makeStringInfo(); Datum *elements = NULL; int numElements = 0; bool *val_is_null_marker; deconstruct_array(arrayValue, INT8OID, sizeof(int64), true, TYPALIGN_INT, &elements, &val_is_null_marker, &numElements); for (int i = 0; i < numElements; i++) { int64_t collection_id = DatumGetInt64(elements[i]); resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TABLE IF EXISTS %s.documents_%ld DROP COLUMN IF EXISTS change_description;", ApiDataSchemaName, collection_id); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(cmdStr); appendStringInfo(cmdStr, "DROP TRIGGER IF EXISTS record_changes_trigger ON %s.documents_%ld;", ApiDataSchemaName, collection_id); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } } /* * Add user_oid colum and its constraints to the index queue table. */ void AddUserColumnsToIndexQueue() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "ALTER TABLE %s ADD COLUMN IF NOT EXISTS user_oid Oid;", GetIndexQueueName()); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); /* We first drop the check constraint if it already exists. Some upgrade paths can create it before this function is executed. */ resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TABLE %s DROP CONSTRAINT IF EXISTS %s_index_queue_user_oid_check;", GetIndexQueueName(), ExtensionObjectPrefixV2); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); resetStringInfo(cmdStr); appendStringInfo(cmdStr, "ALTER TABLE %s ADD CONSTRAINT %s_index_queue_user_oid_check CHECK (user_oid IS NULL OR user_oid != '0'::oid);", GetIndexQueueName(), ExtensionObjectPrefixV2); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Invalidate the cluster version metadata cache for all active processes. */ static void TriggerInvalidateClusterMetadata() { bool isNull = false; bool readOnly = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "UPDATE %s.%s_cluster_data SET metadata = metadata;", ApiDistributedSchemaName, ExtensionObjectPrefix); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UPDATE, &isNull); } /* * Utility funtion that checks whether 2 ExtensionVersion objects are equal (i.e. both store the same version number) */ static bool VersionEquals(ExtensionVersion versionA, ExtensionVersion versionB) { return versionA.Major == versionB.Major && versionA.Minor == versionB.Minor && versionA.Patch == versionB.Patch; } /* * Receives an ExtensionVersion object and populates it with the contents of a version string in the form of "Major.Minor-Patch". */ static void ParseVersionString(ExtensionVersion *extensionVersion, char *versionString) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT regexp_split_to_array(TRIM(BOTH '\"' FROM '%s'), '[-\\.]')::int4[];", versionString); bool readOnly = true; bool isNull = false; Datum versionDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, &isNull); ArrayType *arrayValue = DatumGetArrayTypeP(versionDatum); Datum *elements = NULL; int numElements = 0; bool *val_is_null_marker; deconstruct_array(arrayValue, INT4OID, sizeof(int), true, TYPALIGN_INT, &elements, &val_is_null_marker, &numElements); Assert(numElements == 3); extensionVersion->Major = DatumGetInt32(elements[0]); extensionVersion->Minor = DatumGetInt32(elements[1]); extensionVersion->Patch = DatumGetInt32(elements[2]); } /* * Receives an ExtensionVersion object and populates it with the current installed version of the extension. */ static void GetInstalledVersion(ExtensionVersion *installedVersion) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT regexp_split_to_array((SELECT extversion FROM pg_extension WHERE extname = '%s'), '[-\\.]')::int4[];", ApiExtensionName); bool readOnly = true; bool isNull = false; Datum versionDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, &isNull); ArrayType *arrayValue = DatumGetArrayTypeP(versionDatum); Datum *elements = NULL; int numElements = 0; bool *val_is_null_marker; deconstruct_array(arrayValue, INT4OID, sizeof(int), true, TYPALIGN_INT, &elements, &val_is_null_marker, &numElements); Assert(numElements == 3); installedVersion->Major = DatumGetInt32(elements[0]); installedVersion->Minor = DatumGetInt32(elements[1]); installedVersion->Patch = DatumGetInt32(elements[2]); } /* * SetPermissionsForReadOnlyRole - Set the right permissions for ApiReadOnlyRole */ static void SetPermissionsForReadOnlyRole() { bool readOnly = false; bool isNull = false; StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "GRANT SELECT ON TABLE %s.%s_cluster_data TO %s;", ApiDistributedSchemaName, ExtensionObjectPrefix, ApiReadOnlyRole); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); ArrayType *arrayValue = GetCollectionIds(); if (arrayValue == NULL) { return; } Datum *elements = NULL; int numElements = 0; bool *val_is_null_marker; deconstruct_array(arrayValue, INT8OID, sizeof(int64), true, TYPALIGN_INT, &elements, &val_is_null_marker, &numElements); for (int i = 0; i < numElements; i++) { int64_t collection_id = DatumGetInt64(elements[i]); resetStringInfo(cmdStr); appendStringInfo(cmdStr, "GRANT SELECT ON %s.documents_%ld TO %s;", ApiDataSchemaName, collection_id, ApiReadOnlyRole); ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } } /* * Checks if the given reference table is replicated. */ static void CheckAndReplicateReferenceTable(const char *schema, const char *tableName) { StringInfo relationName = makeStringInfo(); appendStringInfo(relationName, "%s_%s", ExtensionObjectPrefix, "cluster_data"); if (!(strcmp(tableName, "collections") == 0 || strcmp(tableName, "collection_indexes") == 0 || strcmp(tableName, relationName->data) == 0)) { return; } StringInfo queryStringInfo = makeStringInfo(); appendStringInfo(queryStringInfo, "SELECT shardid FROM pg_catalog.pg_dist_shard WHERE logicalrelid = '%s.%s'::regclass", schema, tableName); bool isNull = false; ExtensionExecuteQueryViaSPI(queryStringInfo->data, false, SPI_OK_SELECT, &isNull); if (isNull) { /* Not replicated, replicate it.*/ resetStringInfo(relationName); appendStringInfo(relationName, "%s.%s", schema, tableName); CreateReferenceTable(relationName->data); } } static char * UpdateClusterMetadata(bool isInitialize) { bool isNull = false; Datum args[1] = { CStringGetTextDatum(DistributedExtensionName) }; Oid argTypes[1] = { TEXTOID }; Datum catalogExtVersion = ExtensionExecuteQueryWithArgsViaSPI( "SELECT extversion FROM pg_extension WHERE extname = $1", 1, argTypes, args, NULL, true, SPI_OK_SELECT, &isNull); Assert(!isNull); Datum clusterVersionDatum = ExtensionExecuteQueryViaSPI( FormatSqlQuery( "SELECT %s.bson_get_value_text(metadata, 'last_deploy_version') FROM %s.%s_cluster_data", CoreSchemaNameV2, ApiDistributedSchemaName, ExtensionObjectPrefix), true, SPI_OK_SELECT, &isNull); Assert(!isNull); char *catalogVersion = TextDatumGetCString(catalogExtVersion); char *clusterVersion = TextDatumGetCString(clusterVersionDatum); if (strcmp(clusterVersion, catalogVersion) == 0) { elog(NOTICE, "version is up-to-date. Skipping function"); return clusterVersion; } /* get Citus version. */ Datum citusVersion = ExtensionExecuteQueryViaSPI( "SELECT coalesce(metadata->>'last_upgrade_version', '11.0-1') FROM pg_dist_node_metadata", true, SPI_OK_SELECT, &isNull); Assert(!isNull); pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendUtf8(&writer, "last_deploy_version", -1, catalogVersion); PgbsonWriterAppendUtf8(&writer, "last_citus_version", -1, TextDatumGetCString( citusVersion)); /* Seed the first version */ if (isInitialize) { PgbsonWriterAppendUtf8(&writer, "initialized_version", -1, catalogVersion); } Datum updateArgs[1] = { PointerGetDatum(PgbsonWriterGetPgbson(&writer)) }; Oid updateTypes[1] = { BsonTypeId() }; /* Modify the existing row data */ const char *updateQuery = FormatSqlQuery( "UPDATE %s.%s_cluster_data SET metadata = %s.bson_dollar_set(metadata, $1)", ApiDistributedSchemaName, ExtensionObjectPrefix, ApiCatalogSchemaName); ExtensionExecuteQueryWithArgsViaSPI(updateQuery, 1, updateTypes, updateArgs, NULL, false, SPI_OK_UPDATE, &isNull); return clusterVersion; } /* If the changes table exists, then update the owner to the cluster admin role */ static void UpdateChangesTableOwnerToAdminRole(void) { /* First query if the changes table exists */ const char *query = FormatSqlQuery( "SELECT relowner::regrole::text FROM pg_class WHERE relname = 'changes' AND relnamespace = %d", ApiDataNamespaceOid()); bool isNull = false; Datum resultDatum = ExtensionExecuteQueryViaSPI(query, true, SPI_OK_SELECT, &isNull); if (isNull) { /* Changes table does not exist, can bail */ return; } /* Get the current owner of the changes table */ char *currentOwner = TextDatumGetCString(resultDatum); /* If the current owner is already the cluster admin role, no need to change */ if (strcmp(currentOwner, ApiAdminRole) == 0 || strcmp(currentOwner, ApiAdminRoleV2) == 0) { return; } /* Otherwise update the owner to the ApiAdminRole */ const char *alterQuery = FormatSqlQuery( "ALTER TABLE %s.changes OWNER TO %s;", ApiDataSchemaName, ApiAdminRole); /* Execute the query to change the owner */ ExtensionExecuteQueryViaSPI(alterQuery, false, SPI_OK_UTILITY, &isNull); } documentdb-0.108-0/internal/pg_documentdb_distributed/src/distribution/cluster_versioning.c000066400000000000000000000023551507310017400324340ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/distribution/cluster_versioning.c * * Utilities that Provide extension functions to handle version upgrade * scenarios for the current extension. * *------------------------------------------------------------------------- */ #include "utils/version_utils.h" #include "metadata/metadata_cache.h" #include #include "utils/query_utils.h" #include "executor/spi.h" #include "utils/inval.h" #include "utils/version_utils_private.h" PG_FUNCTION_INFO_V1(invalidate_cluster_version); PG_FUNCTION_INFO_V1(get_current_cached_cluster_version); /* * Invalidates the version cache and the metadata cache. */ Datum invalidate_cluster_version(PG_FUNCTION_ARGS) { InvalidateVersionCache(); /* Also invalidate the metadata_cache */ InvalidateCollectionsCache(); CacheInvalidateRelcacheAll(); PG_RETURN_VOID(); } /* * Returns the text version of the cluster version * Used for debugging and testing purposes. */ Datum get_current_cached_cluster_version(PG_FUNCTION_ARGS) { const char *versionString = GetCurrentVersionForLogging(); PG_RETURN_DATUM(CStringGetTextDatum(versionString)); } documentdb-0.108-0/internal/pg_documentdb_distributed/src/distribution/distributed_hooks.c000066400000000000000000000522261507310017400322370ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/distribution/distributed_hooks.c * * Implementation of API Hooks for a distributed execution. *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "utils/query_utils.h" #include "utils/guc_utils.h" #include "utils/version_utils.h" #include "metadata/metadata_cache.h" #include "utils/documentdb_errors.h" #include "metadata/collection.h" #include "api_hooks_def.h" #include "shard_colocation.h" #include "distributed_hooks.h" #include "node_distributed_operations.h" extern bool UseLocalExecutionShardQueries; extern char *ApiDistributedSchemaName; extern bool EnableMetadataReferenceTableSync; extern char *DistributedOperationsQuery; extern char *DistributedApplicationNamePrefix; /* Cached value for the current Global PID - can cache once * Since nodeId, Pid are stable. */ #define INVALID_CITUS_INTERNAL_BACKEND_GPID 0 static uint64 DocumentDBCitusGlobalPid = 0; /* * In Citus we query citus_is_coordinator() to get if * the current node is a metadata coordinator */ static bool IsMetadataCoordinatorCore(void) { bool readOnly = true; bool isNull = false; Datum resultBoolDatum = ExtensionExecuteQueryViaSPI( "SELECT citus_is_coordinator()", readOnly, SPI_OK_SELECT, &isNull); return !isNull && DatumGetBool(resultBoolDatum); } /* * Runs a command on the cluster's metadata holding coordinator node. */ static DistributedRunCommandResult RunCommandOnMetadataCoordinatorCore(const char *query) { const char *baseQuery = "SELECT nodeId, success, result FROM run_command_on_coordinator($1)"; int nargs = 1; Oid argTypes[1] = { TEXTOID }; Datum argValues[1] = { CStringGetTextDatum(query) }; char argNulls[1] = { ' ' }; bool readOnly = true; int numResultValues = 3; Datum resultDatums[3] = { 0 }; bool resultNulls[3] = { 0 }; ExtensionExecuteMultiValueQueryWithArgsViaSPI( baseQuery, nargs, argTypes, argValues, argNulls, readOnly, SPI_OK_SELECT, resultDatums, resultNulls, numResultValues); DistributedRunCommandResult result = { 0 }; /* TODO: handle error in coordinator correctly as it could be an exception we need to honor. */ if (resultNulls[0] || resultNulls[1]) { result.success = false; return result; } result.nodeId = DatumGetInt32(resultDatums[0]); result.success = DatumGetBool(resultDatums[1]); result.response = NULL; if (!resultNulls[2]) { result.response = DatumGetTextP(resultDatums[2]); } return result; } /* * Hook to run a query with commutative writes. * * This sets citus.all_modifications_commutative to true, before executing the query. * Enabling this setting allows Citus to optimize the execution of these modifications * across distributed shards in parallel, potentially improving performance for certain workloads. * * This setting should be used cautiously in various queries. Currently the use cases here are around * modifying reference tables based on the primary key only (where we know we only update the one * row). * See https://github.com/citusdata/citus/blob/a2315fdc677675b420913ca4f81116e165d52397/src/backend/distributed/executor/distributed_execution_locks.c#L149 * for more details. */ static Datum RunQueryWithCommutativeWritesCore(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, int expectedSPIOK, bool *isNull) { int savedGUCLevel = NewGUCNestLevel(); SetGUCLocally("citus.all_modifications_commutative", "true"); Datum result; bool readOnly = false; if (nargs > 0) { result = ExtensionExecuteQueryWithArgsViaSPI(query, nargs, argTypes, argValues, argNulls, readOnly, expectedSPIOK, isNull); } else { result = ExtensionExecuteQueryViaSPI(query, readOnly, expectedSPIOK, isNull); } RollbackGUCChange(savedGUCLevel); return result; } static Datum RunQueryWithSequentialModificationCore(const char *query, int expectedSPIOK, bool *isNull) { int savedGUCLevel = NewGUCNestLevel(); SetGUCLocally("citus.multi_shard_modify_mode", "sequential"); bool readOnly = false; Datum result = ExtensionExecuteQueryViaSPI(query, readOnly, expectedSPIOK, isNull); RollbackGUCChange(savedGUCLevel); return result; } static bool IsShardTableForDocumentDbTableCore(const char *relName, const char *numEndPointer) { /* It's definitely a documents query - it's a shard query if there's a documents__ * So treat it as such if there's 2 '_'. * This is a hack but need to find a better way to recognize * a worker query. * Note that this logic is a simpler form of the RelationIsAKnownShard * function in Citus. However, that function does extract the shard_id * and does a Scan on the pg_dist table as well to determine if it's really * a shard. However, this is too expensive for the hotpath of every query. * Consequently this simple check *should* be sufficient in the hot path. * * TODO: Could we do something like IsCitusTableType where we cache the results of * this? Ideally we could map this to something in the Mongo Collection Cache. However * the inverse lookup if it's not in the cache is not easily done in the query path. */ return numEndPointer != NULL && *numEndPointer == '_'; } /* * Distributes a Postgres table across all the available node based on the * specified distribution column. * * returns the actual distribution column used in the table. */ static const char * DistributePostgresTableCore(const char *postgresTable, const char *distributionColumn, const char *colocateWith, int shardCount) { const char *distributionColumnUsed = distributionColumn; /* * By default, Citus triggers are off as there are potential pitfalls if * not used properly, such as, doing operations on the remote node. We use * them here only for local operations. */ SetGUCLocally("citus.enable_unsafe_triggers", "on"); /* * Make sure that create_distributed_table does not parallelize shard creation, * since that would prevent us from pushing down an insert_one or update_one * call in the same transaction. When Citus pushes down a function call, it needs * to see both a distributed table and a shard, and if those are created over * separate connections that is not possible until commit. * * Setting multi_shard_modify_mode to sequential to enforce using a single * connection is a temporary workaround until this is solved in Citus. * https://github.com/citusdata/citus/issues/6169 */ SetGUCLocally("citus.multi_shard_modify_mode", "sequential"); /* Because ApiDataSchema.changes is created inside initialize/complete * We need to skip checking cluster version there so do other checks first. */ const char *createQuery = "SELECT create_distributed_table($1::regclass, $2, colocate_with => $3, shard_count => $4)"; int nargs = 4; Oid argTypes[4] = { TEXTOID, TEXTOID, TEXTOID, INT4OID }; Datum argValues[4] = { CStringGetTextDatum(postgresTable), (Datum) 0, (Datum) 0, (Datum) 0, }; if (distributionColumnUsed == NULL && shardCount != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Unexpected - distribution column is null but shardCount is %d", shardCount), errdetail_log( "Unexpected - distribution column is null but shardCount is %d", shardCount))); } char argNulls[4] = { ' ', 'n', 'n', 'n' }; if (distributionColumnUsed != NULL) { argValues[1] = CStringGetTextDatum(distributionColumnUsed); argNulls[1] = ' '; } if (colocateWith != NULL) { argValues[2] = CStringGetTextDatum(colocateWith); argNulls[2] = ' '; } else { bool innerReadOnly = true; bool isNull = true; ExtensionExecuteQueryViaSPI( FormatSqlQuery("SELECT 1 FROM pg_catalog.pg_dist_partition pdp " " JOIN pg_class pc on pdp.logicalrelid = pc.oid " " WHERE relname = 'changes' AND relnamespace = '%s'::regnamespace", ApiDataSchemaName), innerReadOnly, SPI_OK_SELECT, &isNull); if (!isNull) { char changesTableName[NAMEDATALEN] = { 0 }; sprintf(changesTableName, "%s.changes", ApiDataSchemaName); argValues[2] = CStringGetTextDatum(changesTableName); argNulls[2] = ' '; } else { /* If ApiDataSchema.changes doesn't exist - fall back into "none" */ argValues[2] = CStringGetTextDatum("none"); argNulls[2] = ' '; } } if (shardCount > 0) { argValues[3] = Int32GetDatum(shardCount); argNulls[3] = ' '; } bool readOnly = false; bool isNull = false; ExtensionExecuteQueryWithArgsViaSPI(createQuery, nargs, argTypes, argValues, argNulls, readOnly, SPI_OK_SELECT, &isNull); return distributionColumnUsed; } static void AllowNestedDistributionInCurrentTransactionCore(void) { SetGUCLocally("citus.allow_nested_distributed_execution", "true"); } /* * Allows nested distributed execution in the current query for citus. */ static void RunMultiValueQueryWithNestedDistributionCore(const char *query, int nArgs, Oid *argTypes, Datum *argDatums, char *argNulls, bool readOnly, int expectedSPIOK, Datum *datums, bool *isNull, int numValues) { int gucLevel = NewGUCNestLevel(); AllowNestedDistributionInCurrentTransactionCore(); ExtensionExecuteMultiValueQueryWithArgsViaSPI(query, nArgs, argTypes, argDatums, argNulls, readOnly, expectedSPIOK, datums, isNull, numValues); RollbackGUCChange(gucLevel); } /* * Given a relationId and a collectionId for the relation, tries to get * the shard tableName for the table if it is an unsharded table with a single shard. * e.g. for documents_1 returns documents_1_102011. * If shards are unavailable returns NULL - can be retried. * If the shard is remote and not loca - returns "" */ static const char * TryGetShardNameForUnshardedCollectionCore(Oid relationId, uint64 collectionId, const char *tableName) { if (!UseLocalExecutionShardQueries) { /* Defensive - only turn this on with feature flag */ return ""; } const char *shardIdDetailsQuery = "SELECT shardid, shardminvalue, shardmaxvalue FROM pg_dist_shard WHERE logicalrelid = $1 LIMIT 1"; Oid shardCountArgTypes[1] = { OIDOID }; Datum shardCountArgValues[1] = { ObjectIdGetDatum(relationId) }; char *argNullNone = NULL; bool readOnly = true; int numValues = 3; Datum resultDatums[3] = { 0 }; bool resultNulls[3] = { 0 }; ExtensionExecuteMultiValueQueryWithArgsViaSPI( shardIdDetailsQuery, 1, shardCountArgTypes, shardCountArgValues, argNullNone, readOnly, SPI_OK_SELECT, resultDatums, resultNulls, numValues); if (resultNulls[0]) { /* Not a distributed table */ return NULL; } int64_t shardIdValue = DatumGetInt64(resultDatums[0]); /* Only support this for single shard distributed * This is only true if shardminvalue and shardmaxvalue are NULL */ if (!resultNulls[1] || !resultNulls[2]) { /* has at least some shard values */ return ""; } /* Construct the shard table name */ char *shardTableName = psprintf("%s_%ld", tableName, shardIdValue); /* Now that we have a shard table name, try to find it in pg_class without locking it */ Oid shardTableOid = get_relname_relid(shardTableName, ApiDataNamespaceOid()); if (shardTableOid != InvalidOid) { return shardTableName; } else { return ""; } } /* * Gets distributed application for citus based applications. */ static const char * GetDistributedApplicationNameCore(void) { if (DocumentDBCitusGlobalPid == INVALID_CITUS_INTERNAL_BACKEND_GPID) { bool isNull; Datum result = ExtensionExecuteQueryViaSPI( "SELECT pg_catalog.citus_backend_gpid()", true, SPI_OK_SELECT, &isNull); if (isNull) { return NULL; } DocumentDBCitusGlobalPid = DatumGetUInt64(result); if (DocumentDBCitusGlobalPid == INVALID_CITUS_INTERNAL_BACKEND_GPID) { return NULL; } } /* * Match the application name pattern for the citus run_command* internal backend * so these don't count in the quota for max_client_backends for citus. */ return psprintf("citus_run_command gpid=%lu %s", DocumentDBCitusGlobalPid, GetExtensionApplicationName()); } static bool ExecuteMetadataChecksForReferenceTables(const char *tableName) { /* First get the shard_id for the table */ StringInfo queryStringInfo = makeStringInfo(); appendStringInfo(queryStringInfo, "SELECT shardid FROM pg_catalog.pg_dist_shard WHERE logicalrelid = '%s.%s'::regclass", ApiCatalogSchemaName, tableName); bool isNull = false; Datum result = ExtensionExecuteQueryViaSPI(queryStringInfo->data, false, SPI_OK_SELECT, &isNull); if (isNull) { return false; } int64 shardId = DatumGetInt64(result); /* Get the number of nodes for the primary group */ result = ExtensionExecuteQueryViaSPI( "SELECT COUNT(*)::int4 FROM pg_catalog.pg_dist_node WHERE isactive AND noderole = 'primary'", false, SPI_OK_SELECT, &isNull); if (isNull) { return false; } int numNodes = DatumGetInt32(result); resetStringInfo(queryStringInfo); appendStringInfo(queryStringInfo, "SELECT COUNT(*)::int4 FROM pg_catalog.pg_dist_placement WHERE shardid = %ld", shardId); result = ExtensionExecuteQueryViaSPI(queryStringInfo->data, false, SPI_OK_SELECT, &isNull); if (isNull) { return false; } int numPlacements = DatumGetInt32(result); if (numPlacements != numNodes) { /* There was an add node but the metadata table needed wasn't replicated: Call replicate_reference_tables first */ ExtensionExecuteQueryOnLocalhostViaLibPQ( "SELECT pg_catalog.replicate_reference_tables('block_writes')"); return true; } else { return false; } } static bool EnsureMetadataTableReplicatedCore(const char *tableName) { if (!EnableMetadataReferenceTableSync) { return false; } /* Set min messagees to reduce log spam in tests */ int savedGUCLevel = NewGUCNestLevel(); SetGUCLocally("client_min_messages", "WARNING"); bool result = ExecuteMetadataChecksForReferenceTables(tableName); RollbackGUCChange(savedGUCLevel); return result; } static char * TryGetExtendedVersionRefreshQueryCore(void) { /* Update the version check query to consider distributed versions */ MemoryContext currContext = MemoryContextSwitchTo(TopMemoryContext); StringInfo s = makeStringInfo(); appendStringInfo(s, "SELECT regexp_split_to_array(TRIM(%s.bson_get_value_text(metadata, 'last_deploy_version'), '\"'), '[-\\.]')::int4[] FROM %s.%s_cluster_data", CoreSchemaName, ApiDistributedSchemaName, ExtensionObjectPrefix); MemoryContextSwitchTo(currContext); ereport(DEBUG1, (errmsg("Version refresh query is %s", s->data))); return s->data; } static List * GetShardIdsForCollection(Oid relationOid) { const char *query = "SELECT array_agg(shardid) FROM pg_dist_shard WHERE logicalrelid = $1"; int nargs = 1; Oid argTypes[1] = { OIDOID }; Datum argValues[1] = { ObjectIdGetDatum(relationOid) }; bool isReadOnly = true; bool isNull = true; Datum shardIds = ExtensionExecuteQueryWithArgsViaSPI(query, nargs, argTypes, argValues, NULL, isReadOnly, SPI_OK_SELECT, &isNull); if (isNull) { return NIL; } ArrayType *arrayType = DatumGetArrayTypeP(shardIds); /* Need to build the result */ const int slice_ndim = 0; ArrayMetaState *mState = NULL; ArrayIterator shardIterator = array_create_iterator(arrayType, slice_ndim, mState); List *shardIdList = NIL; Datum shardIdDatum; while (array_iterate(shardIterator, &shardIdDatum, &isNull)) { if (isNull) { continue; } uint64_t *shardIdPointer = palloc(sizeof(uint64_t)); *shardIdPointer = DatumGetInt64(shardIdDatum); shardIdList = lappend(shardIdList, shardIdPointer); } array_free_iterator(shardIterator); return shardIdList; } static void GetShardIdsAndNamesForCollectionCore(Oid relationOid, const char *tableName, Datum **shardOidArray, Datum **shardNameArray, int32_t *shardCount) { *shardOidArray = NULL; *shardNameArray = NULL; *shardCount = 0; ListCell *shardCell; List *shardIdList = GetShardIdsForCollection(relationOid); /* Need to build the result */ int numItems = list_length(shardIdList); Datum *resultDatums = palloc0(sizeof(Datum) * numItems); Datum *resultNameDatums = palloc0(sizeof(Datum) * numItems); int resultCount = 0; foreach(shardCell, shardIdList) { uint64_t *shardIdPointer = (uint64_t *) lfirst(shardCell); char shardName[NAMEDATALEN] = { 0 }; pg_sprintf(shardName, "%s_%lu", tableName, *shardIdPointer); RangeVar *rangeVar = makeRangeVar(ApiDataSchemaName, shardName, -1); bool missingOk = true; Oid shardRelationId = RangeVarGetRelid(rangeVar, AccessShareLock, missingOk); if (shardRelationId != InvalidOid) { Assert(resultCount < numItems); resultDatums[resultCount] = shardRelationId; resultNameDatums[resultCount] = CStringGetTextDatum(shardName); resultCount++; } } /* Now that we have the shard list as a Datum*, create an array type */ if (resultCount > 0) { *shardOidArray = resultDatums; *shardNameArray = resultNameDatums; *shardCount = resultCount; } else { pfree(resultDatums); pfree(resultNameDatums); } list_free_deep(shardIdList); } /* * Get an index build request from the Index queue. */ static const char * GetPidForIndexBuildCore(void) { const char *queryStrDistributed = " citus_pid_for_gpid(iq.global_pid)"; return queryStrDistributed; } static const char * TryGetIndexBuildJobOpIdQueryCore(void) { const char *queryStrDistributed = "SELECT citus_backend_gpid(), query_start FROM pg_stat_activity where pid = pg_backend_pid();"; return queryStrDistributed; } static char * TryGetCancelIndexBuildQueryCore(int32_t indexId, char cmdType) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "SELECT citus_pid_for_gpid(iq.global_pid) AS pid, iq.start_time AS timestamp"); appendStringInfo(cmdStr, " FROM %s iq WHERE index_id = %d", GetIndexQueueName(), indexId); return cmdStr->data; } static bool ShouldScheduleIndexBuildsCore() { return false; } static List * GetDistributedShardIndexOidsCore(uint64_t collectionId, int indexId, bool ignoreMissing) { /* First for the given collection, get the shard ids associated with it */ char tableName[NAMEDATALEN] = { 0 }; pg_sprintf(tableName, DOCUMENT_DATA_TABLE_NAME_FORMAT, collectionId); Oid relationOid = get_relname_relid(tableName, ApiDataNamespaceOid()); List *shardIdList = GetShardIdsForCollection(relationOid); AllowNestedDistributionInCurrentTransactionCore(); List *indexShardList = NIL; ListCell *shardCell; foreach(shardCell, shardIdList) { uint64_t *shardIdPointer = (uint64_t *) lfirst(shardCell); char shardIndexName[NAMEDATALEN] = { 0 }; pg_sprintf(shardIndexName, DOCUMENT_DATA_TABLE_INDEX_NAME_FORMAT "_%lu", indexId, *shardIdPointer); Oid indexOid = get_relname_relid(shardIndexName, ApiDataNamespaceOid()); if (indexOid != InvalidOid) { indexShardList = lappend_oid(indexShardList, indexOid); } else if (!ignoreMissing) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("failed to find index to get index metadata." " This can happen if it's a multi-node cluster and is not yet supported"))); } } return indexShardList; } /* * Register hook overrides for DocumentDB. */ void InitializeDocumentDBDistributedHooks(void) { is_metadata_coordinator_hook = IsMetadataCoordinatorCore; run_command_on_metadata_coordinator_hook = RunCommandOnMetadataCoordinatorCore; run_query_with_commutative_writes_hook = RunQueryWithCommutativeWritesCore; run_query_with_sequential_modification_mode_hook = RunQueryWithSequentialModificationCore; distribute_postgres_table_hook = DistributePostgresTableCore; run_query_with_nested_distribution_hook = RunMultiValueQueryWithNestedDistributionCore; allow_nested_distribution_in_current_transaction_hook = AllowNestedDistributionInCurrentTransactionCore; is_shard_table_for_documentdb_table_hook = IsShardTableForDocumentDbTableCore; try_get_shard_name_for_unsharded_collection_hook = TryGetShardNameForUnshardedCollectionCore; get_distributed_application_name_hook = GetDistributedApplicationNameCore; ensure_metadata_table_replicated_hook = EnsureMetadataTableReplicatedCore; DefaultInlineWriteOperations = false; ShouldUpgradeDataTables = false; UpdateColocationHooks(); try_get_extended_version_refresh_query_hook = TryGetExtendedVersionRefreshQueryCore; get_shard_ids_and_names_for_collection_hook = GetShardIdsAndNamesForCollectionCore; get_pid_for_index_build_hook = GetPidForIndexBuildCore; try_get_index_build_job_op_id_query_hook = TryGetIndexBuildJobOpIdQueryCore; try_get_cancel_index_build_query_hook = TryGetCancelIndexBuildQueryCore; should_schedule_index_builds_hook = ShouldScheduleIndexBuildsCore; get_shard_index_oids_hook = GetDistributedShardIndexOidsCore; update_postgres_index_hook = UpdateDistributedPostgresIndex; DistributedOperationsQuery = "SELECT * FROM pg_stat_activity LEFT JOIN pg_catalog.get_all_active_transactions() ON process_id = pid JOIN pg_catalog.pg_dist_local_group ON TRUE"; DistributedApplicationNamePrefix = "citus_internal"; } node_distribution_operations.c000066400000000000000000000163351507310017400344230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/distribution/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/distribution/node_distribution_operations.c * * Implementation of scenarios that require distribution on a per node basis. *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include "utils/query_utils.h" #include "utils/documentdb_errors.h" #include "utils/error_utils.h" #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "node_distributed_operations.h" #include "metadata/collection.h" #include "commands/coll_mod.h" #include "parser/parse_func.h" extern char *ApiDistributedSchemaNameV2; static List * ExecutePerNodeCommand(Oid nodeFunction, pgbson *nodeFunctionArg, bool readOnly, const char *distributedTableName); static Oid UpdatePostgresIndexWorkerFunctionOid(void); PG_FUNCTION_INFO_V1(documentdb_update_postgres_index_worker); void UpdateDistributedPostgresIndex(uint64_t collectionId, int indexId, bool hidden) { pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendInt64(&writer, "collectionId", 12, collectionId); PgbsonWriterAppendInt32(&writer, "indexId", 7, indexId); PgbsonWriterAppendBool(&writer, "hidden", 6, hidden); MongoCollection *collection = GetMongoCollectionByColId(collectionId, NoLock); if (collection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Failed to find collection for index update"))); } char fullyQualifiedTableName[NAMEDATALEN * 2 + 2] = { 0 }; pg_sprintf(fullyQualifiedTableName, "%s.%s", ApiDataSchemaName, collection->tableName); ExecutePerNodeCommand(UpdatePostgresIndexWorkerFunctionOid(), PgbsonWriterGetPgbson( &writer), false, fullyQualifiedTableName); } Datum documentdb_update_postgres_index_worker(PG_FUNCTION_ARGS) { pgbson *argBson = PG_GETARG_PGBSON(0); uint64_t collectionId = 0; int indexId = 0; bool hidden = false; bool hasHidden = false; bson_iter_t argIter; PgbsonInitIterator(argBson, &argIter); while (bson_iter_next(&argIter)) { const char *key = bson_iter_key(&argIter); if (strcmp(key, "collectionId") == 0) { collectionId = bson_iter_as_int64(&argIter); } else if (strcmp(key, "indexId") == 0) { indexId = bson_iter_int32(&argIter); } else if (strcmp(key, "hidden") == 0) { hasHidden = true; hidden = bson_iter_as_bool(&argIter); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Unexpected argument to update_postgres_index_worker: %s", key))); } } if (collectionId == 0 || indexId == 0 || !hasHidden) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Missing argument to update_postgres_index_worker"))); } bool ignoreMissingShards = true; UpdatePostgresIndexCore(collectionId, indexId, hidden, ignoreMissingShards); PG_RETURN_POINTER(PgbsonInitEmpty()); } static ArrayType * ChooseShardNamesForTable(const char *distributedTableName) { const char *query = "WITH r1 AS (SELECT MIN($1 || '_' || sh.shardid) AS shardName FROM pg_dist_shard sh JOIN pg_dist_placement pl " " on pl.shardid = sh.shardid WHERE logicalrelid = $1::regclass GROUP by groupid) " " SELECT ARRAY_AGG(r1.shardName) FROM r1"; int nargs = 1; Oid argTypes[1] = { TEXTOID }; Datum argValues[1] = { CStringGetTextDatum(distributedTableName) }; bool isReadOnly = true; bool isNull = true; Datum result = ExtensionExecuteQueryWithArgsViaSPI(query, nargs, argTypes, argValues, NULL, isReadOnly, SPI_OK_SELECT, &isNull); if (isNull) { return NULL; } return DatumGetArrayTypeP(result); } static List * ExecutePerNodeCommand(Oid nodeFunction, pgbson *nodeFunctionArg, bool readOnly, const char *distributedTableName) { ArrayType *chosenShards = ChooseShardNamesForTable(distributedTableName); if (chosenShards == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Failed to get shards for table"), errdetail_log( "Failed to get shard names for distributed table %s", distributedTableName))); } MemoryContext targetContext = CurrentMemoryContext; if (SPI_connect() != SPI_OK_CONNECT) { ereport(ERROR, (errmsg("could not connect to SPI manager"))); } /* We build the query similar to update_worker and such where we have * SELECT node_distributed_function(nodeFunction, nodeFunctionArg, 0, chosenShards, fullyQualified) FROM distributedTableName; * Citus will apply distributed routing and send it to every shard. In the shard planner relpathlisthook, we'll rewrite * the query to be * SELECT node_distributed_function(nodeFunction, nodeFunctionArg, shardOid, chosenShards, fullyQualified); * * Then each shard will validate if it matches one of the chosenShards - if it does, then it runs nodeFunction, * otherwise it noops. * This ensures transactional processing of the command across all nodes that are hosting the shards, but each node runs * the logic exactly once. * * We don't create an aggregate here so that we avoid any distributed planning overhead of aggregates. * Allociate this string in the SPI context so it's freed on SPI_Finish(). */ StringInfoData s; initStringInfo(&s); appendStringInfo(&s, "SELECT %s.command_node_worker($1::oid, $2::%s.bson, 0, $3::text[], TRUE, NULL) FROM %s", ApiInternalSchemaNameV2, CoreSchemaNameV2, distributedTableName); int nargs = 3; Oid argTypes[3] = { OIDOID, BsonTypeId(), TEXTARRAYOID }; Datum argValues[3] = { ObjectIdGetDatum(nodeFunction), PointerGetDatum(nodeFunctionArg), PointerGetDatum(chosenShards) }; char argNulls[3] = { ' ', ' ', ' ' }; List *resultList = NIL; int tupleCountLimit = 0; if (SPI_execute_with_args(s.data, nargs, argTypes, argValues, argNulls, readOnly, tupleCountLimit) != SPI_OK_SELECT) { ereport(ERROR, (errmsg("could not run SPI query"))); } for (uint64 i = 0; i < SPI_processed && SPI_tuptable; i++) { AttrNumber attrNumber = 1; bool isNull = false; Datum resultDatum = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, attrNumber, &isNull); if (isNull) { /* this shard did not process any responses*/ continue; } pgbson *resultBson = DatumGetPgBson(resultDatum); MemoryContext oldContext = MemoryContextSwitchTo(targetContext); pgbson *copiedBson = CopyPgbsonIntoMemoryContext(resultBson, targetContext); resultList = lappend(resultList, copiedBson); MemoryContextSwitchTo(oldContext); } SPI_finish(); return resultList; } /* * Returns the OID of the update_postgres_index_worker function. * it isn't really worth caching this since it's only used in the diagnostic path. * If that changes, this can be put into an OID cache of sorts. */ static Oid UpdatePostgresIndexWorkerFunctionOid(void) { List *functionNameList = list_make2(makeString(ApiDistributedSchemaNameV2), makeString("update_postgres_index_worker")); Oid paramOids[1] = { DocumentDBCoreBsonTypeId() }; bool missingOK = false; return LookupFuncName(functionNameList, 1, paramOids, missingOK); } documentdb-0.108-0/internal/pg_documentdb_distributed/src/documentdb_distributed.c000066400000000000000000000026171507310017400305200ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/documentdb_distributed.c * * Initialization of the shared library. *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include "distributed_hooks.h" #include "documentdb_distributed_init.h" extern bool SkipDocumentDBLoad; PG_MODULE_MAGIC; void _PG_init(void); void _PG_fini(void); /* * _PG_init gets called when the extension is loaded. */ void _PG_init(void) { if (SkipDocumentDBLoad) { return; } if (!process_shared_preload_libraries_in_progress) { ereport(ERROR, (errmsg( "pg_documentdb_distributed can only be loaded via shared_preload_libraries. " "Add pg_documentdb_distributed to shared_preload_libraries configuration " "variable in postgresql.conf in coordinator and workers. " "Note that pg_documentdb_distributed should be placed right after citus and pg_documentdb."))); } InitializeDocumentDBDistributedHooks(); InitDocumentDBDistributedConfigurations("documentdb_distributed"); MarkGUCPrefixReserved("documentdb_distributed"); } /* * _PG_fini is called before the extension is reloaded. */ void _PG_fini(void) { } documentdb-0.108-0/internal/pg_documentdb_distributed/src/documentdb_distributed_init.c000066400000000000000000000037631507310017400315460ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/documentdb_distributed_init.c * * Initialization of the shared library initialization for distribution for Hleio API. *------------------------------------------------------------------------- */ #include #include #include #include "documentdb_distributed_init.h" /* --------------------------------------------------------- */ /* GUCs and default values */ /* --------------------------------------------------------- */ #define DEFAULT_ENABLE_METADATA_REFERENCE_SYNC true bool EnableMetadataReferenceTableSync = DEFAULT_ENABLE_METADATA_REFERENCE_SYNC; #define DEFAULT_ENABLE_SHARD_REBALANCER false bool EnableShardRebalancer = DEFAULT_ENABLE_SHARD_REBALANCER; #define DEFAULT_CLUSTER_ADMIN_ROLE "" char *ClusterAdminRole = DEFAULT_CLUSTER_ADMIN_ROLE; /* --------------------------------------------------------- */ /* Top level exports */ /* --------------------------------------------------------- */ /* * Initializes core configurations pertaining to documentdb distributed. */ void InitDocumentDBDistributedConfigurations(const char *prefix) { DefineCustomBoolVariable( psprintf("%s.enable_metadata_reference_table_sync", prefix), gettext_noop( "Determines whether or not to enable metadata reference table syncs."), NULL, &EnableMetadataReferenceTableSync, DEFAULT_ENABLE_METADATA_REFERENCE_SYNC, PGC_USERSET, 0, NULL, NULL, NULL); DefineCustomBoolVariable( psprintf("%s.enable_shard_rebalancer_apis", prefix), gettext_noop( "Determines whether or not to enable shard rebalancer APIs."), NULL, &EnableShardRebalancer, DEFAULT_ENABLE_SHARD_REBALANCER, PGC_USERSET, 0, NULL, NULL, NULL); DefineCustomStringVariable( psprintf("%s.clusterAdminRole", prefix), gettext_noop( "The cluster admin role."), NULL, &ClusterAdminRole, DEFAULT_CLUSTER_ADMIN_ROLE, PGC_USERSET, 0, NULL, NULL, NULL); } documentdb-0.108-0/internal/pg_documentdb_distributed/src/rebalancer/000077500000000000000000000000001507310017400257165ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/rebalancer/shard_rebalancer.c000066400000000000000000000210351507310017400313420ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/rebalancer/shard_rebalancer.c * * Implementation of a set of APIs for cluster rebalancing * *------------------------------------------------------------------------- */ #include "postgres.h" #include "fmgr.h" #include "miscadmin.h" #include "utils/builtins.h" #include "utils/resowner.h" #include "lib/stringinfo.h" #include "access/xact.h" #include "utils/typcache.h" #include "parser/parse_type.h" #include "nodes/makefuncs.h" #include "io/bson_core.h" #include "utils/documentdb_errors.h" #include "utils/query_utils.h" #include "commands/parse_error.h" #include "metadata/metadata_cache.h" #include "api_hooks.h" extern bool EnableShardRebalancer; PG_FUNCTION_INFO_V1(command_rebalancer_status); PG_FUNCTION_INFO_V1(command_rebalancer_start); PG_FUNCTION_INFO_V1(command_rebalancer_stop); static void PopulateRebalancerRowsFromResponse(pgbson_writer *responseWriter, pgbson *result); static bool HasActiveRebalancing(void); static char * GetRebalancerStrategy(pgbson *startArgs); Datum command_rebalancer_status(PG_FUNCTION_ARGS) { if (!EnableShardRebalancer) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("rebalancer_status is not supported yet"))); } bool readOnly = true; bool isNull = false; Datum result = ExtensionExecuteQueryViaSPI( FormatSqlQuery( "WITH r1 AS (SELECT jsonb_build_object(" " 'state', state::text," " 'startedAt', started_at::text," " 'finishedAt', finished_at::text," " 'task_state_counts', details->'task_state_counts'," " 'tasks', (SELECT jsonb_agg(task - 'LSN' - 'command' - 'hosts' - 'task_id') FROM jsonb_array_elements(details->'tasks') AS task)) AS obj" " FROM citus_rebalance_status())," " r2 AS (SELECT jsonb_build_object('rows', jsonb_agg(r1.obj)) AS obj FROM r1)" " SELECT %s.bson_json_to_bson(r2.obj::text) FROM r2", CoreSchemaName), readOnly, SPI_OK_SELECT, &isNull); pgbson_writer responseWriter; PgbsonWriterInit(&responseWriter); if (isNull) { /* No results from rebalancer */ PgbsonWriterAppendUtf8(&responseWriter, "mode", 4, "off"); } else { PopulateRebalancerRowsFromResponse(&responseWriter, DatumGetPgBson(result)); } result = ExtensionExecuteQueryViaSPI( FormatSqlQuery( "WITH r1 AS (SELECT jsonb_build_object('strategy_name', name, 'isDefault', default_strategy) AS obj FROM pg_dist_rebalance_strategy)," " r2 AS (SELECT jsonb_build_object('strategies', jsonb_agg(r1.obj)) AS obj FROM r1)" " SELECT %s.bson_json_to_bson(r2.obj::text) FROM r2", CoreSchemaName), readOnly, SPI_OK_SELECT, &isNull); if (!isNull) { PgbsonWriterConcat(&responseWriter, DatumGetPgBson(result)); } PgbsonWriterAppendDouble(&responseWriter, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&responseWriter)); } Datum command_rebalancer_start(PG_FUNCTION_ARGS) { if (!EnableShardRebalancer) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("starting the shard rebalancer is not supported yet"))); } if (IsChangeStreamFeatureAvailableAndCompatible()) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "starting the shard rebalancer is not supported when change streams is enabled"))); } pgbson *startArgs = PG_GETARG_PGBSON(0); if (HasActiveRebalancing()) { ereport(ERROR, (errcode( ERRCODE_DOCUMENTDB_BACKGROUNDOPERATIONINPROGRESSFORNAMESPACE), errmsg( "Cannot start rebalancing when another rebalancing is in progress"))); } char *rebalancerStrategyName = GetRebalancerStrategy(startArgs); bool readOnly = false; bool isNull = false; if (rebalancerStrategyName != NULL) { Oid argTypes[1] = { TEXTOID }; Datum argValues[1] = { CStringGetTextDatum(rebalancerStrategyName) }; ExtensionExecuteQueryWithArgsViaSPI( "SELECT citus_set_default_rebalance_strategy($1)", 1, argTypes, argValues, NULL, readOnly, SPI_OK_SELECT, &isNull); } ExtensionExecuteQueryViaSPI("SELECT citus_rebalance_start()", readOnly, SPI_OK_SELECT, &isNull); pgbson_writer responseWriter; PgbsonWriterInit(&responseWriter); PgbsonWriterAppendDouble(&responseWriter, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&responseWriter)); } Datum command_rebalancer_stop(PG_FUNCTION_ARGS) { if (!EnableShardRebalancer) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("stopping the rebalancer is not supported yet"))); } /* Check there's active jobs */ bool hasActiveJobs = HasActiveRebalancing(); if (hasActiveJobs) { bool readOnly = false; bool isNull = false; ExtensionExecuteQueryViaSPI("SELECT citus_rebalance_stop()", readOnly, SPI_OK_SELECT, &isNull); } pgbson_writer responseWriter; PgbsonWriterInit(&responseWriter); PgbsonWriterAppendBool(&responseWriter, "wasActive", 9, hasActiveJobs); PgbsonWriterAppendDouble(&responseWriter, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&responseWriter)); } /* * Appends a DocumentDB compatible response for the rebalancer status: * { * "mode": "off|full", * "runningJobs": [ { job output from citus }], * "otherJobs": [ { job output from citus }], * } */ static void PopulateRebalancerRowsFromResponse(pgbson_writer *responseWriter, pgbson *result) { pgbsonelement element; PgbsonToSinglePgbsonElement(result, &element); if (element.bsonValue.value_type == BSON_TYPE_NULL) { PgbsonWriterAppendUtf8(responseWriter, "mode", 4, "off"); return; } if (element.bsonValue.value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("shard rebalancer response should be an array, not %s", BsonTypeName(element.bsonValue.value_type)), errdetail_log( "shard rebalancer response should be an array, not %s", BsonTypeName( element.bsonValue.value_type)))); } bson_iter_t rowsIter; BsonValueInitIterator(&element.bsonValue, &rowsIter); List *runningJobs = NIL; List *otherJobs = NIL; while (bson_iter_next(&rowsIter)) { const bson_value_t *arrayValue = bson_iter_value(&rowsIter); if (arrayValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "shard rebalancer array element should be a document, not %s", BsonTypeName( arrayValue->value_type)), errdetail_log( "shard rebalancer array element should be a document, not %s", BsonTypeName( arrayValue->value_type)))); } bson_value_t *arrayValueCopy = palloc(sizeof(bson_value_t)); *arrayValueCopy = *arrayValue; bson_iter_t arrayValueIter; BsonValueInitIterator(arrayValue, &arrayValueIter); if (bson_iter_find(&arrayValueIter, "state")) { const char *stateValue = bson_iter_utf8(&arrayValueIter, NULL); if (strcmp(stateValue, "scheduled") == 0 || strcmp(stateValue, "running") == 0) { runningJobs = lappend(runningJobs, arrayValueCopy); } else { otherJobs = lappend(otherJobs, arrayValueCopy); } } else { /* Shove it in other jobs */ otherJobs = lappend(otherJobs, arrayValueCopy); } } char *status = list_length(runningJobs) > 0 ? "full" : "off"; PgbsonWriterAppendUtf8(responseWriter, "mode", 4, status); pgbson_array_writer jobsWriter; PgbsonWriterStartArray(responseWriter, "runningJobs", 11, &jobsWriter); ListCell *jobCell; foreach(jobCell, runningJobs) { bson_value_t *value = lfirst(jobCell); PgbsonArrayWriterWriteValue(&jobsWriter, value); } PgbsonWriterEndArray(responseWriter, &jobsWriter); PgbsonWriterStartArray(responseWriter, "otherJobs", 9, &jobsWriter); foreach(jobCell, otherJobs) { bson_value_t *value = lfirst(jobCell); PgbsonArrayWriterWriteValue(&jobsWriter, value); } PgbsonWriterEndArray(responseWriter, &jobsWriter); } static bool HasActiveRebalancing(void) { bool readOnly = true; bool isNull = false; Datum result = ExtensionExecuteQueryViaSPI( "SELECT COUNT(*)::int4 FROM citus_rebalance_status() WHERE state::text IN ('scheduled', 'running', 'cancelling', 'failing')", readOnly, SPI_OK_SELECT, &isNull); return !isNull && DatumGetInt32(result) > 0; } static char * GetRebalancerStrategy(pgbson *startArgs) { bson_iter_t argsIter; PgbsonInitIterator(startArgs, &argsIter); while (bson_iter_next(&argsIter)) { const char *key = bson_iter_key(&argsIter); if (strcmp(key, "strategy") == 0) { EnsureTopLevelFieldType("strategy", &argsIter, BSON_TYPE_UTF8); return bson_iter_dup_utf8(&argsIter, NULL); } } return NULL; } documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/000077500000000000000000000000001507310017400245775ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/Makefile000066400000000000000000000001721507310017400262370ustar00rootroot00000000000000subdir = src/test check-regress: $(MAKE) -C regress all check-dist-minimal: $(MAKE) -C regress $@ all: check-regress documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/000077500000000000000000000000001507310017400262515ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/.gitignore000077500000000000000000000000631507310017400302430ustar00rootroot00000000000000tmp/ log/ results/ regression.diffs !expected/*.outdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/Makefile000066400000000000000000000035021507310017400277110ustar00rootroot00000000000000 BASEPATH:=../../../ REGRESS := 1 PG_CONFIG ?= pg_config # export pg_config for child make commands (check etc) export PG_CONFIG PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) pg_major_version := $(shell $(PG_CONFIG) --version | awk -F' ' '{ print $$2 }' | awk -F'.' '{ print $$1 }') EXTENSIONLOAD := --load-extension=tsm_system_rows --load-extension=pg_cron --load-extension=vector --load-extension=postgis --load-extension citus --load-extension=documentdb_core --load-extension=documentdb --load-extension=documentdb_distributed --load-extension documentdb_extended_rum MAKEFILE_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) export PATH := $(MAKEFILE_DIR)bin:$(PATH) export PG_REGRESS_DIFF_OPTS = -dU10 export PGISOLATIONTIMEOUT = 60 .PHONY: check-basic check-dist-minimal define common_test $(top_builddir)/src/test/regress/pg_regress --encoding=UTF8 --dlpath=$(BASEPATH) $(EXTENSIONLOAD) --temp-instance ./tmp --temp-config ./postgresql.conf --host localhost --port 58070 $(1) $(2) || (cat regression.diffs && false) endef define isolation_test $(top_builddir)/src/test/isolation/pg_isolation_regress --encoding=UTF8 --dlpath=$(BASEPATH) $(EXTENSIONLOAD) --temp-instance ./tmp --temp-config ./isolation_postgresql.conf --host localhost --port 58071 $(1) $(2) || (cat regression.diffs && false) endef check-basic: generate_version_schedule $(call common_test,--schedule=./basic_schedule --schedule=./log/basic_schedule_$(pg_major_version)) check-dist-minimal: $(call common_test,--schedule=./minimal_schedule, $(EXTRA_TESTS)) check-test-output: ./validate_test_output.sh $(pg_major_version) generate_version_schedule: @mkdir -p log @cp basic_schedule_core log/basic_schedule_$(pg_major_version) @./mutate_schedule.sh log/basic_schedule_$(pg_major_version) $(pg_major_version) all: check-basic check-test-output documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/basic_schedule000066400000000000000000000001441507310017400311300ustar00rootroot00000000000000test: documentdb_distributed_setup test: public_api_schema test: documentdb_distributed_test_helpersdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/basic_schedule_core000066400000000000000000000233021507310017400321410ustar00rootroot00000000000000test: bson_base_operators bson_insert_basic_types bson_deduplicate bson_expr_eval_tests bson_sequence_tests test: bson_dollar_ops_basic_compare_tests_explain_runtime test: bson_dollar_ops_basic_compare_tests_runtime test: bson_dollar_ops_basic_compare_tests_explain_index test: bson_dollar_ops_basic_compare_tests_index test: bson_dollar_ops_basic_compare_tests_index_backcompat test: bson_dollar_ops_basic_compare_tests_errors bson_dollar_ops_basic_compare_tests_explain_index_no_bitmap test: bson_dollar_ops_basic_compare_tests_index_no_bitmap test: bson_dollar_ops_basic_text_ops_tests_explain_runtime test: bson_dollar_ops_basic_text_ops_tests_runtime test: bson_dollar_ops_basic_text_ops_tests_explain_index test: bson_dollar_ops_basic_text_ops_tests_index test: bson_dollar_ops_query_all_tests_runtime test: bson_dollar_ops_query_all_tests_index test: bson_dollar_ops_query_all_tests_index_backcompat test: bson_dollar_ops_query_array_size_tests_index bson_query_operator_array_tests_runtime test: bson_dollar_ops_query_array_size_tests_runtime bson_query_operator_array_tests_index_composite test: bson_query_operator_tests!PG17_OR_HIGHER!_explain_runtime bson_query_operator_elemmatch_tests_explain_runtime test: bson_query_operator_tests_runtime bson_query_operator_elemmatch_tests_runtime test: bson_query_operator_tests!PG17_OR_HIGHER!_explain_index bson_query_operator_elemmatch_tests_explain_index test: bson_query_operator_tests_index bson_query_operator_elemmatch_tests_index test: bson_query_operator_tests_index_backcompat bson_query_operator_elemmatch_explain_composite test: bson_query_operator_tests!PG17_OR_HIGHER!_explain_index_composite test: bson_query_operator_tests_index_composite test: bson_query_operator_tests!PG17_OR_HIGHER!_explain_index_comp_desc test: bson_query_operator_tests_index_comp_desc test: bson_query_operator_tests!PG17_OR_HIGHER!_explain_index_comp_unique test: bson_query_operator_tests_index_comp_unique test: bson_composite_index_prepare_for_unique_tests test: bson_aggregates_distinct_tests commands_collmod_tests_hidden test: bson_dollar_ops_query_bits_tests_runtime command_insert_procedure test: bson_dollar_ops_query_bits_tests_index test: bson_dollar_ops_query_bits_tests_explain test: bson_dollar_ops_query_mod_tests_runtime test: bson_dollar_ops_query_mod_tests_index test: bson_dollar_ops_query_mod_tests_explain test: bson_query_modifier_orderby_tests_explain_runtime test: bson_query_modifier_orderby_tests_explain_index test: bson_dollar_operators_negation_tests_runtime test: bson_dollar_operators_negation_tests_index test: bson_dollar_operators_negation_tests_explain_index test: bson_dollar_operators_negation_tests_explain_runtime test: bson_dollar_ops_collation_tests_runtime test: create_indexes_cosmos_vector bson_aggregation_pipeline_tests_index_pushdown test: bson_query_operator_geospatial_tests_index test: bson_query_operator_geospatial_tests_explain_index test: bson_query_operator_geospatial_tests_explain_runtime test: bson_query_operator_near_nearsphere test: bson_dollar_ops_text_search_tests bson_dollar_ops_expr_tests test: bson_dollar_ops_json_schema_build_tree_tests bson_dollar_ops_json_schema_query_tests test: bson_aggregation_stage_out_tests_2 bson_aggregation_pipeline_stage_densify bson_query_operator_error_tests test: bson_aggregation_pipeline_tests_top_bottom_group bson_aggregation_pipeline_tests_maxnminn_group bson_aggregation_pipeline_stage_fill test: bson_aggregation_pipeline_tests_bucket_auto test: bson_aggregation_array_operators_tests bson_aggregation_bitwise_operators_tests bson_aggregation_boolean_operators_tests bson_aggregation_comparison_operators_tests test: bson_aggregation_conditional_operators_tests bson_aggregation_data_size_operators_tests bson_aggregation_date_operators_tests bson_aggregation_miscellaneous_operators_tests test: bson_aggregation_object_operators_tests bson_aggregation_pipeline_tests_facet_group bson_aggregation_pipeline_tests_push_group bson_aggregation_pipeline_tests_stddevpopsamp_group test: bson_aggregation_set_operators_tests bson_aggregation_stage_addfield_tests bson_aggregation_stage_bucket_tests bson_projection_operator_positional_tests_core bson_aggregation_pipeline_tests_redact test: bson_projection_operator_elemmatch_tests_core bson_projection_operator_dollar_slice_test bson_aggregation_stage_unwind_tests test: bson_aggregation_type_operators_tests bson_aggregation_timestamp_operators_tests bson_aggregation_string_operators_tests test: bson_aggregation_stage_set_tests bson_aggregation_stage_replaceroot_tests bson_aggregation_stage_project_tests bson_wildcard_reduced_term_tests test: bson_query_projection_operator_expressions_map_tests bson_query_projection_operator_expressions_tests bson_type_comparison_tests bson_aggregation_arithmetic_operators_tests test: bson_aggregation_pipeline_operator_expMovingAvg bson_aggregation_pipeline_operator_linearFill bson_aggregation_pipeline_tests_graphlookup test: bson_aggregation_pipeline_tests_let bson_aggregation_pipeline_tests_merge_objects_group bson_aggregation_pipeline_tests bson_aggregation_stage_inversematch_tests bson_aggregation_stage_sample_tests bson_aggregation_pipeline_tests_percentile_median test: bson_aggregation_trigonometric_operators_tests bson_base_aggregates_tests_runtime bson_get_indexes_b bson_order_aggregates_tests test: bson_query_index_selection_sharded_tests bson_query_modifier_orderby_tests_index bson_aggregation!PG17_OR_HIGHER!_tests_lookup_inner_join test: bson_sort_index_pushdown test: bson_query_modifier_orderby_tests_runtime bson_selectivity_index_tests query_sharding_tests bson_composite_prefer_ordered_tests test: bson_query_operator_geospatial_multi_tests bson_composite_index_only_scan!PG16_OR_HIGHER!_tests test: bson_query_operator_object_id_tests bson_query_shard_key_optimization_tests bson_update_document_tests test: bson_update_positional_all bson_update_positional_arrayFilters bson_update_positional_queryFilters bson_query_operator_geospatial_runtime_validation test: commands_delete bson_decimal128 bson_index_term_generation bson_aggregation_stage_lookup!PG17_OR_HIGHER!_tests bson_aggregation_stage_facet_tests test: commands_create_drop_indexes_b commands_drop_indexes commands_create_indexes_wp regex5_tests_explain test: andor and and3 or9 bson_query_operator_tests_parameterized bson_query_disable_seqscan_tests test: bson_hash_indexes commands_find_and_modify bson_unique_index bson_index_hints_pushdown_tests test: regex5_tests_runtime regex_options_runtime bson_unique_index_composite test: regex5_tests_index regex_options_index regex bson_aggregation_pipeline_tests_point_read test: bson_index_selection_tests commands_shard_collection commands_update test: commands_create_indexes_background test: commands_create_indexes_pfe_b commands_create_indexes commands_create_drop_indexes_a test: bson_get_indexes_a commands_create_indexes_pfe_a commands_crud_ignore_common_spec_fields test: write_commands_batching conflicting_indexes test: bson_aggregation_pipeline_tests_vector_native bson_aggregation_expression_variable_tests bson_aggregation_pipeline_tests_vector_hnsw test: bson_aggregation_pipeline_tests_vector_ivf list_metadata_cursor_tests bson_aggregation_pipeline_tests_vector_hnsw_planner test: schema_validation_insert schema_validation test: bson_aggregation_pipeline_operator_locf commands_insert setwindowfields_and_group_compliance test: bson_index_rum_index_scan_to_bitmap_heap_scan commands_update_bulk test: bson_index_truncation_code_tests bson_index_truncation_symbol_tests bson_index_truncation_index_tests test: geospatial_extract_2d_geometries bson_query_operator_geospatial_tests_runtime commands_create_index_geospatial test: commands_create_ttl_indexes bson_query_operator_range bson_index_truncation_nested_objects_tests bson_index_truncation_binary_tests test: users_libpq_permissioning test: bson_aggregation_stage_merge_tests commands_create_indexes_text bson_aggregation_pipeline_tests_coll_agnostic commands_coll_mod test: bson_aggregation_pipeline_tests_geonear bson_aggregation_pipeline_stage_setWindowFields test: cursors_basic_support cursors_seqscan bson_aggregation_cursor_tests test: commands_create_unique_index_stats bson_aggregation_file_cursor_tests # Not to be run concurrently with other tests to prevent flakiness test: feature_counters test: bson_aggregation_stage_index_stats test: commands_validate test: command_compact test: commands_db_stats test: commands_create_view_tests # Needs to be separated out since it creates a new colo group that's fixed test: command_shard_commands # TODO join content with previous pfe tests test: bson_query_operator_pfe_index_pushdown # Adhoc Query optimization tests test: bson_query_operator_in_opt # Test is not great with concurrency with the way connections are managed and shard queries test: cursors_seqscan_sharded # collection_management test calls drop_database() and it causes acquiring # ExclusiveLock on related documents table. For this reasons, it should not # be run in parallel with a test that might call create_indexes() since # create_indexes() might deadlock with a command that acquires ExclusiveLock # due to the way that postgres behaves when building an index concurrently. # # See comments written for lock acquisition steps performed between Phase-1 # and Phase-2 index builds in DefineIndex(): test: collection_management # We want to test the merge stage with the GUC enableDataTableWithoutCreationTime enabled. # However, since the merge operation does not work within a transaction, # we cannot set this GUC inside one. This is why the test is not being run concurrently. test: three_column_data_table # This needs to be by itself since it updates the documentdb schema to add order by functions # Once this is added to the central schema, it can be run concurrently test: bson_composite_order_by_index_testsdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/bin/000077500000000000000000000000001507310017400270215ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/bin/diff000077500000000000000000000050231507310017400276570ustar00rootroot00000000000000#!/usr/bin/env bash # Our custom diff tool which normalizes result and expected files before # doing the actual diff. Rules for normalization are in normalize.sed. See # the comments there for more information. # # Note that src/test/regress/Makefile adds this directory to $PATH so # pg_regress uses this diff tool instead of the system diff tool. set -eu -o pipefail file1="${@:(-2):1}" file2="${@:(-1):1}" # pg_regress passes the expected file as the first argument ($file1 above), # and results file as the second argument ($file2 above). We take the base # filename of the expected file as the test name. We can have multiple # expected files for a single test with _0, _1, ... suffixes. # So for the test name, we also strip the additional suffix. test=$(basename "$file1" .out | sed -E "s/_[0-9]+$//") args=${@:1:$#-2} BASEDIR=$(dirname "$0") DIFF=/usr/bin/diff if [ ! -f "$DIFF" ] then # whereis searches for standard unix places before $PATH. So select the # first entry as the original diff tool. # With the default WSL2 configuration whereis is very slow though ~400ms, # so we only use it if /usr/bin/diff does not exist. DIFF=$(whereis diff | sed "s/diff://g" | awk '{print $1}') if [ -z "$DIFF" ] then echo "ERROR: could not find diff command" 1>&2 exit 1 fi fi if test -z "${VANILLATEST:-}" then touch "$file1" # when adding a new test the expected file does not exist normalize_file="$BASEDIR/normalize.sed" expect_normalize_file="$BASEDIR/expect_normalize.sed" # when running tests on an existing cluster some changes need to be done on # normalize.sed file. So a new file is used. if [[ -f "$BASEDIR/normalize_modified.sed" ]] then normalize_file="$BASEDIR/normalize_modified.sed" fi sed -Ef "$normalize_file" < "$file1" > "$file1.modified" sed -Ef "$normalize_file" < "$file2" > "$file2.modified" mkdir -p "$BASEDIR/normalized/expected" mkdir -p "$BASEDIR/normalized/results" cp "$file2.modified" "$BASEDIR/normalized/results/$(basename $file2)" cp "$file1.modified" "$BASEDIR/normalized/expected/$(basename $file1)" # Move original files of results as .orig and modify the dashes in expected and results to be consistent cp "$file2" "$file2.orig" sed -Ef "$expect_normalize_file" < "$file1" > "$file1.replace" sed -Ef "$expect_normalize_file" < "$file2" > "$file2.replace" mv "$file1.replace" "$file1" mv "$file2.replace" "$file2" "$DIFF" -Z $args "$file1.modified" "$file2.modified" | LC_CTYPE=C.UTF-8 diff-filter "$BASEDIR/normalize.sed" exit ${PIPESTATUS[0]} else exec "$DIFF" -w $args "$file1" "$file2" fi documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/bin/diff-filter000077500000000000000000000045561507310017400311540ustar00rootroot00000000000000#!/usr/bin/env python3 """ diff-filter denormalizes diff output by having lines beginning with ' ' or '+' come from file2's unmodified version. """ import re from sys import argv, stdin, stdout import io # For Test diff we write to stdout which uses ASCII codec, and may no handle non-ASCII characters. # Still don't understand why this is non deterministically fails on the gate. stdout = io.TextIOWrapper(stdout.buffer, encoding='utf8') class FileScanner: """ FileScanner is an iterator over the lines of a file. It can apply a rewrite rule which can be used to skip lines. """ def __init__(self, file, rewrite=lambda x: x): self.file = file self.line = 1 self.rewrite = rewrite def __next__(self): while True: nextline = self.rewrite(next(self.file)) if nextline is not None: self.line += 1 return nextline def main(): # we only test //d rules, as we need to ignore those lines regexregex = re.compile(r"^/(?P.*)/d$") regexpipeline = [] for line in open(argv[1]): line = line.strip() if not line or line.startswith("#") or not line.endswith("d"): continue rule = regexregex.match(line) if not rule: raise "Failed to parse regex rule: %s" % line regexpipeline.append(re.compile(rule.group("rule"))) def sed(line): if any(regex.search(line) for regex in regexpipeline): return None return line for line in stdin: if line.startswith("+++ "): tab = line.rindex("\t") fname = line[4:tab] file2 = FileScanner( open(fname.replace(".modified", ""), encoding="utf8"), sed ) stdout.write(line) elif line.startswith("@@ "): idx_start = line.index("+") + 1 idx_end = idx_start + 1 while line[idx_end].isdigit(): idx_end += 1 linenum = int(line[idx_start:idx_end]) while file2.line < linenum: next(file2) stdout.write(line) elif line.startswith(" "): stdout.write(" ") stdout.write(next(file2)) elif line.startswith("+"): stdout.write("+") stdout.write(next(file2)) else: stdout.write(line) main() documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/bin/expect_normalize.sed000077500000000000000000000016611507310017400330750ustar00rootroot00000000000000# Rules to normalize test outputs. Our custom diff tool passes test output # of tests through the substitution rules in this file before doing the # actual comparison. # # An example of when this is useful is when an error happens on a different # port number, or a different worker shard, or a different placement, etc. # because we are running the tests in a different configuration. # Differing names can have differing table column widths s/^-[+-]{2,}$/---------------------------------------------------------------------/g # Replace the values of the time system variables ($$NOW) with a constant s/\"sn\" : \{ \"\$date\" : \{ \"\$numberLong\" : \"[0-9]*\" \} \}/\"sn\" : NOW_SYS_VARIABLE/g s/\"now\" : \{ \"\$date\" : \{ \"\$numberLong\" : \"[0-9]*\" \} \}/\"now\" : NOW_SYS_VARIABLE/g s/TTL job elapsed time: [+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?ms,/TTL job elapsed time:/g s/expiry_cutoff=[0-9]*,/expiry_cutoff=/gdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/bin/normalize.sed000077500000000000000000000034031507310017400315210ustar00rootroot00000000000000# Rules to normalize test outputs. Our custom diff tool passes test output # of tests through the substitution rules in this file before doing the # actual comparison. # # An example of when this is useful is when an error happens on a different # port number, or a different worker shard, or a different placement, etc. # because we are running the tests in a different configuration. # Differing names can have differing table column widths s/^-[+-]{2,}$/---------------------------------------------------------------------/g s/^\s+/ /g s/\s+$//g s/Memory Usage: [0-9]+kB/Memory Usage: XXXkB/g s/Memory: [0-9]+kB/Memory: XXXkB/g s/process [0-9]+ still waiting for ShareLock on transaction [0-9]+ after [0-9\.]+ ms/process XYZ still waiting on ShareLock on transaction T1 after D1 ms/g s/process [0-9]+ acquired ShareLock on transaction [0-9]+ after [0-9\.]+ ms/process XYZ acquired ShareLock on transaction T1 after D1 ms/g s/Distributed Subplan \d+/Distributed Subplan DDD/g s/Distributed Subplan [0-9]+_[0-9]+/Distributed Subplan X_X/g s/read_intermediate_result\('[0-9]+_[0-9]+'::text/read_intermediate_result\('X_X'::text/g s/Type oid not supported \d+/Type oid not supported ddd/g # Replace the values of the $$NOW time system variable with a constant s/\"now\" : \{ \"\$date\" : \{ \"\$numberLong\" : \"[0-9]*\" \} \}/\"now\" : NOW_SYS_VARIABLE/g s/\"sn\" : \{ \"\$date\" : \{ \"\$numberLong\" : \"[0-9]*\" \} \}/\"sn\" : NOW_SYS_VARIABLE/g s/documentdb_api_catalog.shard_key_and_document/shard_key_and_document/g s/documentdb_api_internal.generate_unique_shard_document/generate_unique_shard_document/g s/documentdb_core.bson/bson/g s/TTL job elapsed time: [+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?ms,/TTL job elapsed time:/g s/expiry_cutoff=[0-9]*,/expiry_cutoff=/gdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/000077500000000000000000000000001507310017400300525ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/and.out000066400000000000000000000147501507310017400313540ustar00rootroot00000000000000-- Based on and.js CREATE SCHEMA and1; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,and1; SET citus.next_shard_id TO 549000; SET documentdb.next_collection_id TO 5490; SET documentdb.next_collection_index_id TO 5490; SELECT 1 FROM drop_collection('db','and1'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','and1', '{"a":[1,2]}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','and1', '{"a":"foo"}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'and1'); drop_primary_key --------------------------------------------------------------------- (1 row) CREATE OR REPLACE FUNCTION and1.assert_count(expected_row_count int, query bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','and1') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; CREATE OR REPLACE FUNCTION and1.check1() RETURNS void LANGUAGE plpgsql AS $$ BEGIN /* -- $and must be an array assert.throws(function() { '{"$and": 4}).toArray(); }); -- $and array must not be empty assert.throws(function() { '{"$and": []}).toArray(); }); -- $and elements must be objects assert.throws(function() { '{"$and": [4]}).toArray(); }); */ -- Check equality matching PERFORM assert_count(1, '{"$and": [{"a": 1}]}'); PERFORM assert_count(1, '{"$and": [{"a": 1}, {"a": 2}]}'); PERFORM assert_count(0, '{"$and": [{"a": 1}, {"a": 3}]}'); PERFORM assert_count(0, '{"$and": [{"a": 1}, {"a": 2}, {"a": 3}]}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}]}'); PERFORM assert_count(0, '{"$and": [{"a": "foo"}, {"a": "g"}]}'); -- Check $and with other fields PERFORM assert_count(1, '{"a": 2, "$and": [{"a": 1}]}'); PERFORM assert_count(0, '{"a": 0, "$and": [{"a": 1}]}'); PERFORM assert_count(0, '{"a": 2, "$and": [{"a": 0}]}'); PERFORM assert_count(1, '{"a": 1, "$and": [{"a": 1}]}'); -- Check recursive $and PERFORM assert_count(1, '{"a": 2, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"a": 0, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"a": 2, "$and": [{"$and": [{"a": 0}]}]}'); PERFORM assert_count(1, '{"a": 1, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(1, '{"$and": [{"a": 2}, {"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"$and": [{"a": 0}, {"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"$and": [{"a": 2}, {"$and": [{"a": 0}]}]}'); PERFORM assert_count(1, '{"$and": [{"a": 1}, {"$and": [{"a": 1}]}]}'); -- Some of these cases were more important with an alternative $and syntax -- that was rejected, but they're still valid check1s. -- Check simple regex PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}]}'); -- Check multiple regexes PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}, {"a": {"$regularExpression":{"pattern":"^f","options":""}}}, {"a": {"$regularExpression":{"pattern":"o","options":""}}}]}'); PERFORM assert_count(0, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}, {"a": {"$regularExpression":{"pattern":"^g","options":""}}}]}'); PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^f","options":""}}}, {"a": "foo"}]}'); -- Check regex flags PERFORM assert_count(0, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":""}}}, {"a": "foo"}]}'); --PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":"i"}}}, {"a": "foo"}]}'); -- Check operator PERFORM assert_count(1, '{"$and": [{"a": {"$gt": 0}}]}'); /* -- Check where PERFORM assert_count(1, '{"a": "foo", "$where": "this.a==\"foo\""}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}], "$where": "this.a==\"foo\""}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}], "$where": "this.a==\"foo\""}'); -- Nested where ok PERFORM assert_count(1, '{"$and": [{"$where": "this.a==\"foo\""}]}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}, {"$where": "this.a==\"foo\""}]}'); PERFORM assert_count(1, '{"$and": [{"$where": "this.a==\"foo\""}], "$where": "this.a==\"foo\""}'); */ END; $$; SELECT check1(); check1 --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('and1', 'index_1', '{"a.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; SELECT check1(); check1 --------------------------------------------------------------------- (1 row) ROLLBACK; SELECT assert_count(1, '{"a": 1, "$and": [{"a": 2}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$and": [{"a": 1}, {"a": 2}]}'); assert_count --------------------------------------------------------------------- (1 row) -- with regex options SELECT assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":"i"}}}, {"a": "foo"}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT drop_collection('db','and1'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA and1 CASCADE; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to function assert_count(integer,bson) drop cascades to function check1() documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/and3.out000066400000000000000000000252701507310017400314360ustar00rootroot00000000000000-- Based on and3.js CREATE SCHEMA and3; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,and3; SET citus.next_shard_id TO 547000; SET documentdb.next_collection_id TO 5470; SET documentdb.next_collection_index_id TO 5470; SELECT drop_collection('db','and3'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT 1 FROM insert_one('db','and3', '{"a":3}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','and3', '{"a":"foo"}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'and3'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('and3', 'index_1', '{"a.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- examined_row_count is currently ignored CREATE OR REPLACE FUNCTION and3.checkScanMatch(query bson, examined_row_count int, expected_row_count int) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','and3') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT checkScanMatch('{"a": {"$regularExpression":{"pattern":"o","options":""}}}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"a": {"$regularExpression":{"pattern":"a","options":""}}}', 0, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 0, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}, {"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 1, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}, {"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$or": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$or": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 0, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$nor": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$nor": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 0, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}]}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 1, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 0, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}]}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$nor": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 2, 1); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"$nor": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 2, 2); checkscanmatch --------------------------------------------------------------------- (1 row) -- $where is not yet supported SELECT checkScanMatch('{"$where": "this.a==1"}', 2, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"$and": [{"$where": "this.a==1"}]}', 2, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"a": 1, "$where": "this.a==1"}', 1, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"a": 1, "$and": [{"$where": "this.a==1"}]}', 1, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"$and": [{"a": 1}, {"$where": "this.a==1"}]}', 1, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"$and": [{"a": 1, "$where": "this.a==1"}]}', 1, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement SELECT checkScanMatch('{"a": 1, "$and": [{"a": 1}, {"a": 1, "$where": "this.a==1"}]}', 1, 1); ERROR: unknown top level operator: $where. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. CONTEXT: SQL statement "SELECT count(*) FROM collection('db','and3') WHERE document @@ query" PL/pgSQL function checkscanmatch(bson,integer,integer) line 5 at SQL statement -- these are supported SELECT checkScanMatch('{"a": 1, "$and": [{"a": 2}]}', NULL, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT checkScanMatch('{"$and": [{"a": 1}, {"a": 2}]}', NULL, 0); checkscanmatch --------------------------------------------------------------------- (1 row) SELECT drop_collection('db','and3'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA and3 CASCADE; NOTICE: drop cascades to function checkscanmatch(bson,integer,integer) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/andor.out000066400000000000000000000142621507310017400317130ustar00rootroot00000000000000-- Based on andor.js CREATE SCHEMA andor; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,andor; SET citus.next_shard_id TO 548000; SET documentdb.next_collection_id TO 5480; SET documentdb.next_collection_index_id TO 5480; CREATE OR REPLACE FUNCTION andor.ok(query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ BEGIN IF NOT EXISTS (SELECT 1 FROM collection('db','andor') WHERE document @@ query) THEN RAISE 'query return no rows: %', query::text; END IF; END; $$; SELECT 1 FROM drop_collection('db','andor'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','andor','{"a": 1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'andor'); drop_primary_key --------------------------------------------------------------------- (1 row) CREATE OR REPLACE FUNCTION andor.test1() RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM ok('{"a": 1}'); PERFORM ok('{"$and": [{"a": 1}]}'); PERFORM ok('{"$or": [{"a": 1}]}'); PERFORM ok('{"$and": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$or": [{"$or": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$or": [{"a": 1}]}]}'); PERFORM ok('{"$or": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$or": [{"a": 1}]}]}]}'); PERFORM ok('{"$and": [{"$or": [{"$and": [{"a": 1}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$and": [{"a": 1}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$or": [{"a": 1}]}]}]}'); -- now test $nor PERFORM ok('{"$and": [{"a": 1}]}'); PERFORM ok('{"$nor": [{"a": 2}]}'); PERFORM ok('{"$and": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$nor": [{"$nor": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"a": 2}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"a": 2}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$nor": [{"a": 2}]}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"$and": [{"a": 2}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$and": [{"a": 2}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$nor": [{"a": 1}]}]}]}'); END; $$; SELECT test1(); test1 --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('andor', 'index_1', '{"a.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; SELECT test1(); test1 --------------------------------------------------------------------- (1 row) ROLLBACK; -- Test an inequality base match. CREATE OR REPLACE FUNCTION andor.test2() RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM ok('{"a": {"$ne": 2}}'); PERFORM ok('{"$and": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$or": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$or": [{"$or": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$or": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$and": [{"$or": [{"$and": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}]}'); -- now test $nor PERFORM ok('{"$and": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$nor": [{"a": {"$ne": 1}}]}'); PERFORM ok('{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$nor": [{"$nor": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"a": {"$ne": 1}}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"a": {"$ne": 1}}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$nor": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"$and": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$and": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$nor": [{"a": {"$ne": 2}}]}]}]}'); END; $$; SELECT 1 FROM drop_collection('db','andor'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','andor','{"a": 1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT test2(); test2 --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('andor', 'index_2', '{"a.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; SELECT test2(); test2 --------------------------------------------------------------------- (1 row) ROLLBACK; SELECT drop_collection('db','andor'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA andor CASCADE; NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to function ok(bson) drop cascades to function test1() drop cascades to function test2() bson_aggregates_distinct_tests.out000066400000000000000000000756031507310017400370140ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6630000; SET documentdb.next_collection_id TO 6630; SET documentdb.next_collection_index_id TO 6630; SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 1, "b": { "c": "foo" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "bar" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "baz" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "foo" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 3, "b": { "c": "foo" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this is what the query will look like from the GW PREPARE distinctQuery(text, text, text) AS (WITH r1 AS (SELECT DISTINCT bson_distinct_unwind(document, $3) AS document FROM documentdb_api.collection($1, $2)) SELECT bson_build_distinct_response(COALESCE(array_agg(document), '{}'::bson[])) FROM r1); PREPARE distinctQueryWithFilter(text, text, text, bson) AS (WITH r1 AS (SELECT DISTINCT bson_distinct_unwind(document, $3) AS document FROM documentdb_api.collection($1, $2) WHERE document @@ $4 ) SELECT bson_build_distinct_response(COALESCE(array_agg(document), '{}'::bson[])) FROM r1); EXECUTE distinctQuery('db', 'distinct1', 'a'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct1', 'a', '{ "a": { "$lt": 3 }}'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct1', 'b.c'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ "foo", "bar", "baz" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct2', '{ "a": null }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct2', 'a.b'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct2', '{ "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct2', '{ }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct2', 'b'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 1, 2, 3 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 2, 3, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 3, 4, 5 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": 9 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'a'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "5" }, { "$numberInt" : "2" }, { "$numberInt" : "9" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'a.0'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'a.1'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "a" }, { "b": "d"} ], "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "b" }, { "b": "d"} ], "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "c" }, { "b": "e"} ], "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "c" }, { "b": "f"} ], "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ ], "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": { "b": "z" }, "c": 12 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'e.b'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ "b", "a", "c", "e", "f", "z", "d" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'e.0.b'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ "b", "a", "c" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'e.1.b'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ "e", "f", "d" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQuery('db', 'distinct3', 'e'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "b" : "c" }, { "b" : "b" }, { "b" : "d" }, { "b" : "a" }, { "b" : "e" }, { "b" : "z" }, { "b" : "f" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct3', 'e.b', '{ "e.b": { "$gt": "d" } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ "f", "c", "z", "e" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 1 } } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 2 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 3 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "notRelevant": 3 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "notRelevant": 3 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct4', 'a.b.c', '{ "a.b.c": { "$gt": 0 } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct4', 'a.b.c', '{ "a.b.c": { "$gt": 1 } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test for DBRef SELECT documentdb_api.insert_one('db', 'distinct5', '{ "a": 1, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'distinct5', '{ "a": 2, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19cea" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'distinct5', '{ "a": 3, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19cea" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'distinct6', '{ "_id": { "$oid" : "147f000000c1de008ec19cea" }, "c": 1}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'distinct6', '{ "_id": { "$oid" : "147f000000c1de008ec19ceb" }, "c": 2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct5', 'a', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" } } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db', 'distinct5', 'a', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19cea" } } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- optional parameter - $db SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 20, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }, "$db": "db" }}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 30, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to get 20 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" }, "$db": "db" } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "20" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to get 30 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" } } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "30" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 1, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce1" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 2, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce2" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 3, "b": { "$id" : { "$oid" : "147f000000c1de008ec19ce3" }, "$ref" : "distinct6" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 4, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 5, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce5" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 6, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 7, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db": "db", "tt":1}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to get 3 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": {"$id": { "$oid" : "147f000000c1de008ec19ce3" }, "$ref" : "distinct6"} }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to get 7 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "7" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to get null EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db" } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- expect to work in $in/$nin EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$in": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$nin": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); bson_build_distinct_response --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" }, { "$numberInt" : "6" }, { "$numberInt" : "2" }, { "$numberInt" : "20" }, { "$numberInt" : "5" }, { "$numberInt" : "30" }, { "$numberInt" : "1" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- index SELECT documentdb_api_internal.create_indexes_non_concurrently('db2', '{ "createIndexes": "distinct7", "indexes": [ { "key": { "b": 1 }, "name": "ref_idx" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; begin; SET LOCAL enable_seqscan to off; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Aggregate (actual rows=1 loops=1) -> HashAggregate (actual rows=1 loops=1) Group Key: documentdb_api_catalog.bson_distinct_unwind(collection.document, $3) Batches: 1 Memory Usage: 37kB -> ProjectSet (actual rows=1 loops=1) -> Result (actual rows=1 loops=1) One-Time Filter: documentdb_api_catalog.bson_true_match($4) -> Bitmap Heap Scan on documents_6637_6630098 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on ref_idx (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Aggregate (actual rows=1 loops=1) -> HashAggregate (actual rows=1 loops=1) Group Key: documentdb_api_catalog.bson_distinct_unwind(collection.document, $3) Batches: 1 Memory Usage: 37kB -> ProjectSet (actual rows=1 loops=1) -> Result (actual rows=1 loops=1) One-Time Filter: documentdb_api_catalog.bson_true_match($4) -> Bitmap Heap Scan on documents_6637_6630098 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db" : "db", "tt" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on ref_idx (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db" : "db", "tt" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": {"$id": { "$oid" : "147f000000c1de008ec19ce6" }, "$ref" : "distinct6"}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 30 bytes Tasks Shown: All -> Task Tuple data received from node: 30 bytes Node: host=localhost port=58070 dbname=regression -> Aggregate (actual rows=1 loops=1) -> HashAggregate (actual rows=0 loops=1) Group Key: documentdb_api_catalog.bson_distinct_unwind(collection.document, $3) Batches: 1 Memory Usage: 37kB -> ProjectSet (actual rows=0 loops=1) -> Result (actual rows=0 loops=1) One-Time Filter: documentdb_api_catalog.bson_true_match($4) -> Bitmap Heap Scan on documents_6637_6630098 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$ref" : "distinct6" } }'::documentdb_core.bson) -> Bitmap Index Scan on ref_idx (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$ref" : "distinct6" } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$in": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 44 bytes Tasks Shown: All -> Task Tuple data received from node: 44 bytes Node: host=localhost port=58070 dbname=regression -> Aggregate (actual rows=1 loops=1) -> HashAggregate (actual rows=2 loops=1) Group Key: documentdb_api_catalog.bson_distinct_unwind(collection.document, $3) Batches: 1 Memory Usage: 37kB -> ProjectSet (actual rows=2 loops=1) -> Result (actual rows=2 loops=1) One-Time Filter: documentdb_api_catalog.bson_true_match($4) -> Bitmap Heap Scan on documents_6637_6630098 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db" : "db", "tt" : { "$numberInt" : "1" } }, { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" } } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on ref_idx (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db" : "db", "tt" : { "$numberInt" : "1" } }, { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" } } ] }'::documentdb_core.bson) (19 rows) commit; bson_aggregation_arithmetic_operators_tests.out000066400000000000000000004041371507310017400415760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6800000; SET documentdb.next_collection_id TO 6800; SET documentdb.next_collection_index_id TO 6800; -- $add operator -- Returns expected result SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$add": [ "$a", "$b", 0 ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$add": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "20" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$add": [ "$a", 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.199999999999999289" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": [ "$a", 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "11" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", 86400000]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "86400000" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "100" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", {"$numberDouble": "43200000.56"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "43200001" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", {"$numberDecimal": "1e10"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "10000000000" } } } (1 row) -- A single expression is also valid SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "10" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": "$b"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": NaN}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":2147483646}', '{"result": { "$add": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1073741823, "b": 1073741825}', '{"result": { "$add": [ "$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$add": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "9223372036854775808.0" } } (1 row) -- Any null should project to null (even if it is a date overflow), non-existent paths return null if there is no date overflow SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$add": [ "$a", "$b", 0 ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$add": [ "$a", "$b", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": null}', '{"result": { "$add": [ "$a", "$b", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$add": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$add": [ "$a", "$a.b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "9223372036854775807" }} }', '{"result": { "$add": [ "$a", 100, 100, null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "9223372036854775807" }}, "b": null }', '{"result": { "$add": [ "$a", 100, 100, "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Should return invalid date (INT64_MAX) if there is a decimal128 overflow SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "1e5000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "NaN"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "Infinity"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDouble": "NaN"}, {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) -- Should round to nearest even for date operations SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDouble": "819.4"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1548833410955" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDouble": "819.56"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1548833410956" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDecimal": "819.4899999"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1548833410955" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDecimal": "819.5359123621083"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1548833410956" } } } (1 row) -- Should error with non-numeric or date expressions SELECT * FROM bson_dollar_project('{"a":{ }, "b": null}', '{"result": { "$add": [ "$a", 922, 1 ]}}'); ERROR: $add can only process numeric or date types, not object SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); ERROR: $add can only process numeric or date types, not bool SELECT * FROM bson_dollar_project('{"a": 1, "b": "false"}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); ERROR: $add can only process numeric or date types, not string SELECT * FROM bson_dollar_project('{"a": 1, "b": [2, 3]}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); ERROR: $add can only process numeric or date types, not array SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$add": [ "$a.0", "$a.1", 0 ]}}'); ERROR: $add can only process numeric or date types, not array SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", "string" ]}}'); ERROR: $add can only process numeric or date types, not string SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", true ]}}'); ERROR: $add can only process numeric or date types, not bool SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", {} ]}}'); ERROR: $add can only process numeric or date types, not object -- Should error if multiple dates are passed in SELECT * FROM bson_dollar_project('{"a":{ "$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); ERROR: Only a single date value is permitted within an $add operators expression. SELECT * FROM bson_dollar_project('{"a":{ "$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ 1, 2, "$a", "$b" ]}}'); ERROR: Only a single date value is permitted within an $add operators expression. SELECT * FROM bson_dollar_project('{"a": 100, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ 1, 2, "$a", "$b", {"$date": {"$numberLong": "1000"}} ]}}'); ERROR: Only a single date value is permitted within an $add operators expression. -- Should error if date overflows SELECT * FROM bson_dollar_project('{"a": 100, "b": {"$date": { "$numberLong" : "9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); ERROR: Date value overflow detected in operator $add SELECT * FROM bson_dollar_project('{"a": -100, "b": {"$date": { "$numberLong" : "-9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); ERROR: Date value overflow detected in operator $add SELECT * FROM bson_dollar_project('{"a": -100, "b": {"$date": { "$numberLong" : "-9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b", "$c" ]}}'); ERROR: Date value overflow detected in operator $add SELECT * FROM bson_dollar_project('{"a": {"$numberDouble": "100.58"}, "b": {"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", "$b", {"$numberDouble": "9223372036854775800.22"} ]}}'); ERROR: Date value overflow detected in operator $add SELECT * FROM bson_dollar_project('{"a": {"$numberDouble": "100.58"}, "b": {"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", "$b", NaN ]}}'); ERROR: Date value overflow detected in operator $add -- $subtract operator -- Returns expected result SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$subtract": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$subtract": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$subtract": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$subtract": [ "$a", 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "9.1999999999999992895" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1221.8000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1231" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDecimal": "102123"}}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "-1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "103355" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$subtract": [ "$a", -1000]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1010" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", 86400000]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-86400000" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", -86400000]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "86400000" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", {"$numberDouble": "43200000.56"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-43200000" } } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "86000" }}}', '{"result": { "$subtract": [ "$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-86000" } } (1 row) -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":2147483646}', '{"result": { "$subtract": [ "$a", -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) SELECT * FROM bson_dollar_project('{"a":-1073741825, "b": 1073741825}', '{"result": { "$subtract": [ "$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-2147483650" } } (1 row) -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$subtract": [ "$a", -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "9223372036854775808.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":-9223372036854775807}', '{"result": { "$subtract": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-9223372036854775808.0" } } (1 row) -- Null or undefined path should result to null SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$subtract": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$subtract": [ "$a", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": null}', '{"result": { "$subtract": [ "$b", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$subtract": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$subtract": [ "$a", "$a.b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ "string", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ {"$date":{"$numberLong": "0"}}, null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Should error if no numbers or dates are passed in SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [ "$a", 922 ]}}'); ERROR: can't $subtract int from object SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$subtract": [ "$a", "$b"]}}'); ERROR: can't $subtract bool from int SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ "string", 1]}}'); ERROR: can't $subtract int from string SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ 1, "string"]}}'); ERROR: can't $subtract string from int SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$subtract": [ "$a.0", 0 ]}}'); ERROR: can't $subtract int from array SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", true ]}}'); ERROR: can't $subtract bool from int SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {} ]}}'); ERROR: can't $subtract object from int SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {} ]}}'); ERROR: can't $subtract object from int SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {"$date": {"$numberLong": "2"}}]}}'); ERROR: can't $subtract date from int SELECT * FROM bson_dollar_project('{"a":{"$date": {"$numberLong": "0"}}}', '{"result": { "$subtract": [ "$a", true]}}'); ERROR: can't $subtract bool from date -- Should error if wrong number of args is provided SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": "$a" }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [] }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [{"$subtract": [1, 2, 3]}, 2, 4, 5] }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": ["$a", 1, 3] }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": "string"}', '{"result": { "$subtract": ["$a", "$b", "$c"] }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": "string"}', '{"result": { "$subtract": ["$a", "$b", "$c", 2, 3, 3, 3, 3] }}'); ERROR: The expression $subtract requires exactly 2 arguments, but 8 arguments were actually provided. -- $multiply operator -- Returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": []}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$multiply": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": { "$numberDouble" : "NaN" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$multiply": ["$a", { "$numberDouble" : "NaN" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$multiply": [ "$a", "$b", 3 ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "6" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$multiply": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$multiply": [ "$a.b", "$a.c", -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-10000" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$multiply": [ "$a", 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "10.199999999999999289" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "12566.4000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1232" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDecimal": "102123"}}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "-1232"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-125815536" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$multiply": [ "$a", -1000]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-10000" } } (1 row) -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":1073741824}', '{"result": { "$multiply": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) SELECT * FROM bson_dollar_project('{"a":-1073741824}', '{"result": { "$multiply": [ "$a", 2, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-4294967296" } } (1 row) -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$multiply": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "18446744073709551616.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":-9223372036854775807}', '{"result": { "$multiply": [ "$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-18446744073709551616.0" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$multiply": "$a.b"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$multiply": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$multiply": [ "$a", "$b", 3, 100, null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$multiply": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$multiply": [ "$a", "$a.b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Should error if no number is provided SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$multiply": [ "$a", 922 ]}}'); ERROR: $multiply works exclusively with numeric data types, not with object SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$multiply": [ "$a", "$b"]}}'); ERROR: $multiply works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": [ "string", 1]}}'); ERROR: $multiply works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": [ 1, "string"]}}'); ERROR: $multiply works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$multiply": [ "$a.0", 2 ]}}'); ERROR: $multiply works exclusively with numeric data types, not with array SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$multiply": [ "$a", true ]}}'); ERROR: $multiply works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$multiply": [ "$a", {} ]}}'); ERROR: $multiply works exclusively with numeric data types, not with object SELECT * FROM bson_dollar_project('{"a":{}}', '{"result": { "$multiply": [ "$a", 32 ]}}'); ERROR: $multiply works exclusively with numeric data types, not with object -- $divide operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [3, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$divide": ["$a", 4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [{ "$numberDouble" : "NaN" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$divide": ["$a", { "$numberDouble" : "NaN" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$divide": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$divide": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "10.2000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.999999999999990" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999999"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.00000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$divide": [ "$a", 5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [null, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [null, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": ["str", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$divide": ["$a", "$a.b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$divide": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$divide": [ "$a", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$divide": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$divide": [ "$a", "$a.b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, 0]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, {"$numberLong": "0"}]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, {"$numberDecimal": "0"}]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, 0.0]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{"a": 0.0}', '{"result": { "$divide": [2, "$a"]}}'); ERROR: $divide by zero is not allowed -- Number or args should be 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": {}}}'); ERROR: The expression $divide requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": 1}}'); ERROR: The expression $divide requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 2, 3, 4, 5, 6]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 6 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 2, 3]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [{"$divide": [1, 0]}]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 1 arguments were actually provided. -- Only numbers should be allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, "str"]}}'); ERROR: $divide only supports numeric types, not int and string SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": ["str", 1]}}'); ERROR: $divide only supports numeric types, not string and int SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [true, 1]}}'); ERROR: $divide only supports numeric types, not bool and int SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, false]}}'); ERROR: $divide only supports numeric types, not int and bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$divide": [2, "$a"]}}'); ERROR: $divide only supports numeric types SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$divide": ["$a", 5]}}'); ERROR: $divide only supports numeric types -- $mod operator : basic SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [1, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [3, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", 4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$mod": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$mod": [ "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.2000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.999999999999990" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999999"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0E-14" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$mod": [ "$a", 5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "500000000000"}}', '{"result": { "$mod": [ "$a", {"$numberDouble": "450000000000.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "50000000000.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "500000000000"}}', '{"result": { "$mod": [ "$a", {"$numberLong": "450000000000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "50000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "5"}}', '{"result": { "$mod": [ "$a", {"$numberDouble": "3"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{"a":5}', '{"result": { "$mod": [ "$a", {"$numberDouble": "3"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) -- $mod operator : Nan and Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [{ "$numberDouble" : "NaN" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "NaN" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "Infinity" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "NaN" }, { "$numberDouble" : "NaN" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "Infinity" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Nan" }, { "$numberDouble" : "Infinity" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "NaN" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "Infinity" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "Infinity" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "Nan" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [null, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [null, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": ["str", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": ["$a", "$a.b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$mod": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$mod": [ "$a", null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$mod": [ "$a", "$b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$mod": [ "$a", "$a.b" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $mod operator : can't mod by zero SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "0" }] }}'); ERROR: Cannot perform $mod with zero SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "0" }] }}'); ERROR: Cannot perform $mod with zero SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, 0] }}'); ERROR: Cannot perform $mod with zero -- $mod operator : Only numerics allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [1, "str"]}}'); ERROR: $mod operator supports only numeric types, not int and string SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": ["str", 1]}}'); ERROR: $mod operator supports only numeric types, not string and int SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [true, 1]}}'); ERROR: $mod operator supports only numeric types, not bool and int SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [2, false]}}'); ERROR: $mod operator supports only numeric types, not int and bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$mod": [2, "$a"]}}'); ERROR: $mod only supports numeric types SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$mod": ["$a", 5]}}'); ERROR: $mod only supports numeric types -- $mod operator : Return types based on operands types -- Any operand Decimal => Result is Decimal -- Any operand Long and the result has no fraction => Result is Long -- Everything else => Result is Double SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberLong": "-1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberDouble": "1.032"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.7119999999999997442" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, 21]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "10" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberDecimal": "1.032"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.712" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, {"$numberDecimal": "1.032"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.712" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, {"$numberDouble": "1.032"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.71200000000000" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, 21]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "10" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberDouble": "1.032"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.7119999999999997442" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberDouble": "7"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, 7]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberLong": "-1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10.78"}, {"$numberLong": "-1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.77999999999999936051" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ 89, 7]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) -- $abs: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDouble": "-232232.23"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "232232.23000000001048" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-2323232"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2323232" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-9223372036854775807"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "9223372036854775807" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": -2147483648}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDecimal": "-9223372036854775808"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "9223372036854775808" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -2}', '{"result": { "$abs": {"$add": [-2, "$a"]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) -- $abs: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$abs": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $abs: can't calculate abs of MIN_INT64 SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-9223372036854775808"}}}'); ERROR: Cannot compute $abs for minimum long long value -- $abs: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": "str"}}'); ERROR: $abs operator only accepts numeric data types, not string SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": true}}'); ERROR: $abs operator only accepts numeric data types, not bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [false]}}'); ERROR: $abs operator only accepts numeric data types, not bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [{}]}}'); ERROR: $abs operator only accepts numeric data types, not object -- $abs: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": []}}'); ERROR: The expression $abs requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [1, 2]}}'); ERROR: The expression $abs requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [1, 2, 3, 4]}}'); ERROR: The expression $abs requires exactly 1 arguments, but 4 arguments were actually provided. -- $ceil: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberLong": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberLong": "-1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "23065.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "-23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-23064.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "23065" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "-23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-23064" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "0.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$log": [10, 2]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "4.0" } } (1 row) -- $ceil: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$ceil": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $ceil: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": "str"}}'); ERROR: $ceil can only handle numeric data types, not string SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": true}}'); ERROR: $ceil can only handle numeric data types, not bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [false]}}'); ERROR: $ceil can only handle numeric data types, not bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [{}]}}'); ERROR: $ceil can only handle numeric data types, not object -- $ceil: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": []}}'); ERROR: The expression $ceil requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [1, 2]}}'); ERROR: The expression $ceil requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [1, 2, 3, 4]}}'); ERROR: The expression $ceil requires exactly 1 arguments, but 4 arguments were actually provided. -- $exp: returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.36787944117144233402" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": 10}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "22026.465794806717895" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberLong": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.7182818284590450908" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "-1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.3678794411714423215955237701614609" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2.718281828459045235360287471352662" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) -- $exp: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$exp": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $exp: input should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": "str"}}'); ERROR: The $exp operator can only be used with numeric data types, not string SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$exp": "$a"}}'); ERROR: The $exp operator can only be used with numeric data types, not bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": [[]]}}'); ERROR: The $exp operator can only be used with numeric data types, not array -- $exp: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": ["str", 1]}}'); ERROR: The expression $exp requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$exp": ["$a", 2 ,2, 3]}}'); ERROR: The expression $exp requires exactly 1 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": []}}'); ERROR: The expression $exp requires exactly 1 arguments, but 0 arguments were actually provided. -- $floor: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberLong": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberLong": "-1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "23064.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "-23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-23065.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "23064" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "-23064.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-23065" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "0.000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$log": [10, 2]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.0" } } (1 row) -- $floor: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$floor": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $floor: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": "str"}}'); ERROR: Expected numberic type for $floor but found 'string' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": true}}'); ERROR: Expected numberic type for $floor but found 'bool' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [false]}}'); ERROR: Expected numberic type for $floor but found 'bool' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [{}]}}'); ERROR: Expected numberic type for $floor but found 'object' type -- $floor: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": []}}'); ERROR: The expression $floor requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [1, 2]}}'); ERROR: The expression $floor requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [1, 2, 3, 4]}}'); ERROR: The expression $floor requires exactly 1 arguments, but 4 arguments were actually provided. -- $ln: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "2.718281828459045"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "2.718281828459045235360287471352662"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999999999999999998" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "0.0001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-9.210340371976181828" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "0.1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-2.302585092994045684017991454684364" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberLong": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"$a": 1}', '{"result": { "$ln": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $ln: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"$a": null}', '{"result": { "$ln": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $ln: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": "str"}}'); ERROR: $ln works exclusively with numeric data types, but received string instead SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": true}}'); ERROR: $ln works exclusively with numeric data types, but received bool instead SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [false]}}'); ERROR: $ln works exclusively with numeric data types, but received bool instead SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [{}]}}'); ERROR: $ln works exclusively with numeric data types, but received object instead -- $ln: should be positive number greater than 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "-2"}}}'); ERROR: The argument provided to the $ln operator must be a positive numeric value, but received -2 instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "0"}}}'); ERROR: The argument provided to the $ln operator must be a positive numeric value, but received 0 instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberLong": "-1"}}}'); ERROR: The argument provided to the $ln operator must be a positive numeric value, but received -1 instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": -100}}'); ERROR: The argument provided to the $ln operator must be a positive numeric value, but received -100 instead. -- $ln: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": []}}'); ERROR: The expression $ln requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [1, 2]}}'); ERROR: The expression $ln requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [1, 2, 3, 4]}}'); ERROR: The expression $ln requires exactly 1 arguments, but 4 arguments were actually provided. -- $log: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [10, 10]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "0.1"}, 10]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.99999999999999977796" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "10"}, {"$numberDouble": "10"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "10"}, {"$numberDouble": "5"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.430676558073393050670106568763966" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, {"$numberDouble": "5"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.4306765580733933341" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberLong": "10"}, 10]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberLong": "9223372036854775807"}, 10]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "18.964889726830811867" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.3219280948873626258" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "NaN"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, {"$numberDecimal": "NaN"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- $log: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [10, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": ["$a", 10]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"$a": null}', '{"result": { "$log": ["$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $log: number must be positive number greater than 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [-1, 10]}}'); ERROR: $log requires its argument to be a positive number, but the provided value is -1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [0, 10]}}'); ERROR: $log requires its argument to be a positive number, but the provided value is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "0"}, 10]}}'); ERROR: $log requires its argument to be a positive number, but the provided value is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "-3"}, 10]}}'); ERROR: $log requires its argument to be a positive number, but the provided value is -3 -- $log: base must be positive number greater than 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1, 1]}}'); ERROR: The base value for the $log must be positive and cannot be 1, but it is 1. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, 0]}}'); ERROR: The base value for the $log must be positive and cannot be 1, but it is 0. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDecimal": "1"}]}}'); ERROR: The base value for the $log must be positive and cannot be 1, but it is 1. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDecimal": "0"}]}}'); ERROR: The base value for the $log must be positive and cannot be 1, but it is 0. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDouble": "0"}]}}'); ERROR: The base value for the $log must be positive and cannot be 1, but it is 0. -- $log: arguments must be numbers SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [[], 1]}}'); ERROR: $log requires a numeric argument, but received array instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, "str"]}}'); ERROR: The base value for the $log operator must be numeric, not string -- $log: takes exactly 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": []}}'); ERROR: The expression $log requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": {}}}'); ERROR: The expression $log requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1, 2, 3]}}'); ERROR: The expression $log requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1]}}'); ERROR: The expression $log requires exactly 2 arguments, but 1 arguments were actually provided. -- $log10: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": 10}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "10"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "10"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "10"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "10000"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "10000"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "4.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "0.0000000001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-10.00000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "0.001"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-3.0" } } (1 row) -- $log10: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$log10": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $log10: argument must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": "str"}}'); ERROR: Expected numeric type for $log10 but found 'string' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": true}}'); ERROR: Expected numeric type for $log10 but found 'bool' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [[]]}}'); ERROR: Expected numeric type for $log10 but found 'array' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [{}]}}'); ERROR: Expected numeric type for $log10 but found 'object' type -- $log10: argument must be positive number SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": 0}}'); ERROR: The argument provided to $log10 must be a positive number, but the given value is 0. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "-1"}}}'); ERROR: The argument provided to $log10 must be a positive number, but the given value is -1. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "-1"}}}'); ERROR: The argument provided to $log10 must be a positive number, but the given value is -1. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "0.000000000000"}}}'); ERROR: The argument provided to $log10 must be a positive number, but the given value is 0E-12. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "0.0000000"}}}'); ERROR: The argument provided to $log10 must be a positive number, but the given value is 0. -- $log10: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [1, 2]}}'); ERROR: The expression $log10 requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [1, 2, 3]}}'); ERROR: The expression $log10 requires exactly 1 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": []}}'); ERROR: The expression $log10 requires exactly 1 arguments, but 0 arguments were actually provided. -- $pow: returns expected SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDouble": "2"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "4.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberDouble": "31"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2147483648.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "10"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1024" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "62"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4611686018427387904" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "10"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "100" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDecimal": "10"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "100.0000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [5, { "$numberDecimal": "-112"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "5.192296858534827628530496329220096E-79" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1, { "$numberDecimal": "NaN"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1, { "$numberDouble": "NaN"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDecimal": "NaN"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDouble": "NaN"}, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- should lose precision only when a double is returned SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, 35]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "50031545098999707" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, {"$numberDecimal": "35"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "50031545098999707.00000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, {"$numberDouble": "35"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "50031545098999704.0" } } (1 row) -- $pow: should coerce when there is overflow -- int32 -> int64 SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 31]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483648" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 62]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4611686018427387904" } } (1 row) -- int32 -> double SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 63]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "9223372036854775808.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 66]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "73786976294838206464.0" } } (1 row) -- int64 -> double SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "2" }, 63]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "9223372036854775808.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "2" }, 64]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "18446744073709551616.0" } } (1 row) -- $pow: should return double for negative exponent with bases not [-1, 0, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "-2" }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.25" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, { "$numberLong": "-2" }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.25" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-4, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0625" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "-1" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "1" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) -- $pow: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [null, 31]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $pow: arguments must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [[], 31]}}'); ERROR: $pow requires its base to be numeric, but received array instead SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, "a"]}}'); ERROR: The operator $pow requires a numeric exponent rather than string SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, true]}}'); ERROR: The operator $pow requires a numeric exponent rather than bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [false, true]}}'); ERROR: $pow requires its base to be numeric, but received bool instead -- $pow: exponent can't be negative if base is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -31]}}'); ERROR: A base of 0 and a negative exponent can't be taken by $pow SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -1]}}'); ERROR: A base of 0 and a negative exponent can't be taken by $pow SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -0.00000001]}}'); ERROR: A base of 0 and a negative exponent can't be taken by $pow SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, {"$numberDecimal": "-0.00000001"}]}}'); ERROR: A base of 0 and a negative exponent can't be taken by $pow -- $pow: takes exactly 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -31, 3]}}'); ERROR: The expression $pow requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0]}}'); ERROR: The expression $pow requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": []}}'); ERROR: The expression $pow requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1,2,3,4,5,6]}}'); ERROR: The expression $pow requires exactly 2 arguments, but 6 arguments were actually provided. -- $sqrt: returns expected SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": 4}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberLong": "4"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberLong": "9223372036854775807"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3037000499.9760499001" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDouble": "4"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDecimal": "4"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDecimal": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) -- $sqrt: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$sqrt": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $sqrt: arg must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": "str"}}'); ERROR: $sqrt can only be applied to numeric types, not to string. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [[]]}}'); ERROR: $sqrt can only be applied to numeric types, not to array. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {}}}'); ERROR: $sqrt can only be applied to numeric types, not to object. -- $sqrt: arg must be greater than or equal to 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": -1}}'); ERROR: The operator sqrt requires its argument to be zero or a positive value SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDouble": "-1000000"}}}'); ERROR: The operator sqrt requires its argument to be zero or a positive value SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDouble": "-0.00001"}}}'); ERROR: The operator sqrt requires its argument to be zero or a positive value SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDecimal": "-0.000000000000001"}}}'); ERROR: The operator sqrt requires its argument to be zero or a positive value -- $sqrt: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": []}}'); ERROR: The expression $sqrt requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [1, 2, 3, 4]}}'); ERROR: The expression $sqrt requires exactly 1 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [1, 2]}}'); ERROR: The expression $sqrt requires exactly 1 arguments, but 2 arguments were actually provided. -- $round: defaults to 0 if 1 arg is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDouble": "1.3" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.3" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDouble": "1.51" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.51" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.49" }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.49" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDecimal": "1.68" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.68" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": 10023 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "10023" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberLong": "10023" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "10023" } } (1 row) -- $round: double, long or int SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 50]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "132" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "132" }, 20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [132, 20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "132" } } (1 row) -- $round: positive precision, limit to 35 digits for number decimal SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "123.40000000000000568" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "123.39" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, 3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "123.391" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.397" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "123.40000000000000568" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.397" }, 50]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.397000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.397" }, 35]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.397000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 35]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.3970000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.3970000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 15]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.397000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "-123.397" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-123.40000000000000568" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.298912343250054252245154325" }, {"$numberDecimal": "20.000000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.29891234325005425225" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "0.0" }, {"$numberDecimal": "100.00000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0E-100" } } (1 row) -- $round: negative precision SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "100.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1E+2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0E+4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "1234532345" }, -5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1234500000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "1234532345" }, -20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [123402345, -8]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [123402345, -19]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) -- $round: NaN, Infinity/-Infinity, Null/Undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "NaN" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "NaN" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "-Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [null, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [1232, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": ["$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [343, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $round: overflow SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2147483650" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{"$numberLong": "9223372036854775806"}, -1]}}'); ERROR: Invalid conversion from Decimal128 leading to $round, caused by provided arguments: [9223372036854775806, -1] -- $round: num args should be either 1 or 2. SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1, 4]}}'); ERROR: The expression $round requires no fewer than 1 arguments and no more than 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1, 4, 5]}}'); ERROR: The expression $round requires no fewer than 1 arguments and no more than 2 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": []}}'); ERROR: The expression $round requires no fewer than 1 arguments and no more than 2 arguments, but 0 arguments were actually provided. -- $round: args should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{}]}}'); ERROR: $round works exclusively with numeric data types, not with object SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [1, "str"]}}'); ERROR: Unable to convert from BSON type string into a long value SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [true, 1]}}'); ERROR: $round works exclusively with numeric data types, not with bool -- $round: precision must be >= -20 and <= 100 SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, -21]}}'); ERROR: Unable to apply $round when using precision value -21, as the acceptable range is between -20 and 100. SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, 101]}}'); ERROR: Unable to apply $round when using precision value 101, as the acceptable range is between -20 and 100. -- $round: precision must be integral value in int64 range SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDecimal": "-21.1"} ]}}'); ERROR: precision argument to $round must be a integral value SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDouble": "-21.1"} ]}}'); ERROR: precision argument to $round must be a integral value SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDecimal": "9223372036854775808"} ]}}'); ERROR: Unable to convert out-of-range value 9223372036854775808 into a long type -- $trunc: defaults to 0 if 1 arg is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDouble": "1.3" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.3" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDouble": "1.51" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.51" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.49" }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.49" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDecimal": "1.68" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.68" }, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": 10023 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "10023" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberLong": "10023" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "10023" } } (1 row) -- $trunc: double, long or int SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 50]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3200000000000000622" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "132" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "132" }, 20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [132, 20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "132" } } (1 row) -- $trunc: positive precision, limit to 35 digits for number decimal SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "123.29999999999999716" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "123.39" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, 3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "123.391" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.397" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "123.39000000000000057" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.397" }, 50]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.397000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.397" }, 35]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.397000000000000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 35]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.3970000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 100]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.3970000000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 15]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "132423423.397000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "-123.397" }, 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-123.39000000000000057" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.298912343250054252245154325" }, {"$numberDecimal": "20.000000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.29891234325005425224" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "0.0" }, {"$numberDecimal": "100.00000"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0E-100" } } (1 row) -- $trunc: negative precision SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "100.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1E+2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0E+4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "1234532345" }, -5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1234500000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "1234532345" }, -20]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [123402345, -8]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [123402345, -19]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) -- $trunc: NaN, Infinity/-Infinity, Null/Undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "NaN" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "NaN" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "-Infinity" }, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [null, -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [1232, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": ["$a", 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [343, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $trunc: num args should be either 1 or 2. SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [2147483647, -1, 4]}}'); ERROR: The expression $trunc requires no fewer than 1 arguments and no more than 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [2147483647, -1, 4, 5]}}'); ERROR: The expression $trunc requires no fewer than 1 arguments and no more than 2 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": []}}'); ERROR: The expression $trunc requires no fewer than 1 arguments and no more than 2 arguments, but 0 arguments were actually provided. -- $trunc: args should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{}]}}'); ERROR: $trunc works exclusively with numeric data types, not with object SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [1, "str"]}}'); ERROR: Unable to convert from BSON type string into a long value SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [true, 1]}}'); ERROR: $trunc works exclusively with numeric data types, not with bool -- $trunc: precision must be >= -20 and <= 100 SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, -21]}}'); ERROR: Unable to apply $trunc when using precision value -21, as the acceptable range is between -20 and 100. SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, 101]}}'); ERROR: Unable to apply $trunc when using precision value 101, as the acceptable range is between -20 and 100. -- $trunc: precision must be integral value in int64 range SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDecimal": "-21.1"} ]}}'); ERROR: precision argument to $trunc must be a integral value SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDouble": "-21.1"} ]}}'); ERROR: precision argument to $trunc must be a integral value SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDecimal": "9223372036854775808"} ]}}'); ERROR: Unable to convert out-of-range value 9223372036854775808 into a long type -- Test which verifies the infinity and NaN behavior SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "inf"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "-inf"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "nan"}}}'); ERROR: Attempt to convert NaN value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "1e310"}}}'); -- This would have failed while converting to double earlier ERROR: Conversion would overflow target type in $convert with no onError value: 1E+310 bson_aggregation_array_operators_tests.out000066400000000000000000006444701507310017400405710ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6900000; SET documentdb.next_collection_id TO 6900; SET documentdb.next_collection_index_id TO 6900; -- $in operator -- returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, [1, 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": ["$a", [1, { }]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": ["$a", [1, { "a": true}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a", [1, { "b": true}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", [1, true]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", [null, false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": { "$in": ["$a.b", [1, [1, 2], 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": { "$in": ["$a.b", [1, [1, 3], 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", []]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "NaN"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "0.0"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "Infinity"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- null should match mising paths and null SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [null, ["$a", 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [null, [1, 2, 3, null]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": [null, [1, 2, 3, "$a.b"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- undefined expression as first shouldn't match null/undefined in array SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": ["$z", [1, 2, 3, "$a.b"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": ["$z", [null]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- nested expressions in array should be evaluated SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, [1, 2, {"$add": [1, 1, 1]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, [1, 2, {"$add": [1, 1, 3]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": true, "b": [1, 2]}', '{"result": { "$in": ["$a", [1, 2, {"$isArray": "$b"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": [{"$literal": "$a"}, [1, 2, {"$literal": "$a"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- second argument must be an array SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, "$b"]}}'); ERROR: Expected 'array' type for $in operator but found 'missing' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, {"$undefined": true}]}}'); ERROR: Expected 'array' type for $in operator but found 'undefined' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, { }]}}'); ERROR: Expected 'array' type for $in operator but found 'object' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, "str"]}}'); ERROR: Expected 'array' type for $in operator but found 'string' type SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$in": [3, "$a"]}}'); ERROR: Expected 'array' type for $in operator but found 'bool' type SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$in": [3, "$a"]}}'); ERROR: Expected 'array' type for $in operator but found 'int' type -- number of arguments should be 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3]}}'); ERROR: The expression $in requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": 2}}'); ERROR: The expression $in requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, 2, 3, 4]}}'); ERROR: The expression $in requires exactly 2 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, 2, 3, 4, 6, 7, 8]}}'); ERROR: The expression $in requires exactly 2 arguments, but 7 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": null}}'); ERROR: The expression $in requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$not": []}, 2, 3]}}'); ERROR: The expression $in requires exactly 2 arguments, but 3 arguments were actually provided. -- $size operator -- returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[1, 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[1, [1,2]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": {"$literal": [1]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$size": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$size": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) -- should error if no array is passed in SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [null]}}'); ERROR: $size requires an array argument, but received a value of type: null SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": null}}'); ERROR: $size requires an array argument, but received a value of type: null SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": "$b"}}'); ERROR: $size requires an array argument, but received a value of type: missing SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{ }]}}'); ERROR: $size requires an array argument, but received a value of type: object SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [true]}}'); ERROR: $size requires an array argument, but received a value of type: bool -- should error if wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [null, 2]}}'); ERROR: The expression $size requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": []}}'); ERROR: The expression $size requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{"$divide": [1, 0]}, 2]}}'); ERROR: The expression $size requires exactly 1 arguments, but 2 arguments were actually provided. -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{"$divide": [1, 0]}]}}'); ERROR: $divide by zero is not allowed -- nested mongo evaluates expressions in array eventhough they are not needed for $size calculation -- for error validation. SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[{"$divide": [1, 0]}, 2]]}}'); ERROR: $divide by zero is not allowed -- $arrayElemAt -- returns expected element positive idx SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberLong": "1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "1.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "1.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "5" } } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", 0]}, {"$arrayElemAt": ["$a", 1]}]}], 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "101" } } (1 row) -- returns expected element negative idx SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "5" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -2]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", -4]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", -4]}, {"$arrayElemAt": ["$a", -3]}]}], -1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "101" } } (1 row) -- returns no result idx out of bounds SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], -2]}, "otherResult": {"$add": [1,2]}}'); bson_dollar_project --------------------------------------------------------------------- { "otherResult" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -5]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -20]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -30]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -40]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", -60]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", -4]}, {"$arrayElemAt": ["$a", -3]}]}], -70]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], 1]}, "otherResult": {"$add": [1,2]}}'); bson_dollar_project --------------------------------------------------------------------- { "otherResult" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 4]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 5]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 6]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 7]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", 8]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", 0]}, {"$arrayElemAt": ["$a", 1]}]}], 9]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "2147483647.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "-2147483648.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "2147483647.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "-2147483648.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- should return null if array is null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [null, -5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": ["$a", -5]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- should error if first arg is not array SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [{}, -5]}}'); ERROR: $arrayElemAt's first argument must be an array, but is object SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": ["string", -5]}}'); ERROR: $arrayElemAt's first argument must be an array, but is string SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [true, -5]}}'); ERROR: $arrayElemAt's first argument must be an array, but is bool -- should error if second arg is not a number SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {}]}}'); ERROR: The second argument of $arrayElemAt must be a numeric type value, but it is object instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], true]}}'); ERROR: The second argument of $arrayElemAt must be a numeric type value, but it is bool instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], [1, 2]]}}'); ERROR: The second argument of $arrayElemAt must be a numeric type value, but it is array instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], "string"]}}'); ERROR: The second argument of $arrayElemAt must be a numeric type value, but it is string instead. -- should return null if second arg is null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- should error if second arg is not representable as a 32-bit integer SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberLong": "2147483648"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 2147483648 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberLong": "-2147483649"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: -2147483649 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDouble": "1.1"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 1.1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDouble": "1.0003"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 1.0003 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "2147483648.0"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 2.14748E+09 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "-2147483649.0"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: -2.14748E+09 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "2147483648.0"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 2147483648.0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "-2147483649.0"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: -2147483649.0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "1.0003"}]}}'); ERROR: The second argument of $arrayElemAt must be a valid 32-bit integer value: 1.0003 -- should honor nested expression errors even second arg is not a 32-bit integer or if the value is found (even if the index points to an expression that doesn't produce an error). SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[{"$divide": [1, 0]}], {"$numberDecimal": "1.0003"}]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, {"$divide": [1, 0]}], 0]}}'); ERROR: $divide by zero is not allowed -- should error if wrong number of args is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [7]}}'); ERROR: The expression $arrayElemAt requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7]]}}'); ERROR: The expression $arrayElemAt requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7, {"$divide": [1, 0]}], {"$numberLong": "2147483648"}, 2]}}'); ERROR: The expression $arrayElemAt requires exactly 2 arguments, but 3 arguments were actually provided. -- $first operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1, 2, 3, 4]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[{"$add": [2, 4, 6]}, 2, 3, 4]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [100, 2, 3, 4]}', '{"result": { "$first": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100" } } (1 row) -- null or undefined array should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- should error if no array is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [{}]}}'); ERROR: The argument provided for $first must be of array type, yet it is actually object. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [true]}}'); ERROR: The argument provided for $first must be of array type, yet it is actually bool. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [false]}}'); ERROR: The argument provided for $first must be of array type, yet it is actually bool. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": ["string"]}}'); ERROR: The argument provided for $first must be of array type, yet it is actually string. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [1]}}'); ERROR: The argument provided for $first must be of array type, yet it is actually int. -- should error with wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [1, 2, 3]}}'); ERROR: The expression $first requires exactly 1 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[], 2]}}'); ERROR: The expression $first requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": []}}'); ERROR: The expression $first requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [{"$divide": [1, 0]}, 2]}}'); ERROR: The expression $first requires exactly 1 arguments, but 2 arguments were actually provided. -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1, 2, 3, 4, {"$divide": [1, 0]}]]}}'); ERROR: $divide by zero is not allowed -- $last operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[1]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[1, 2, 3, 4]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[2, 3, 4, {"$add": [2, 4, 6]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [100, 2, 3, 4]}', '{"result": { "$last": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) -- null or undefined array should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- should error if no array is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [{}]}}'); ERROR: The argument provided for $last must be of array type, yet it is actually object. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [true]}}'); ERROR: The argument provided for $last must be of array type, yet it is actually bool. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [false]}}'); ERROR: The argument provided for $last must be of array type, yet it is actually bool. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": ["string"]}}'); ERROR: The argument provided for $last must be of array type, yet it is actually string. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [1]}}'); ERROR: The argument provided for $last must be of array type, yet it is actually int. -- should error with wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [1, 2, 3]}}'); ERROR: The expression $last requires exactly 1 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[], 2]}}'); ERROR: The expression $last requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": []}}'); ERROR: The expression $last requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [{"$divide": [1, 0]}, 2]}}'); ERROR: The expression $last requires exactly 1 arguments, but 2 arguments were actually provided. -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[{"$divide": [1, 0]}, 1, 2, 3, 4]]}}'); ERROR: $divide by zero is not allowed -- $objectToArray: returns expected array SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": "$b" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "$numberInt" : "1" } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [{ "a": 1 }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "$numberInt" : "1" } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": 2 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "$numberInt" : "1" } }, { "k" : "b", "v" : { "$numberInt" : "2" } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": [1, {"b": 2}] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": {"b": { "c": {"d": "hello"}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "b" : { "c" : { "d" : "hello" } } } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": {"$add": [1, 1]}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "$numberInt" : "1" } }, { "k" : "b", "v" : { "$numberInt" : "2" } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": {"c": { "d": { "$add": [1, 1]}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "$numberInt" : "1" } }, { "k" : "b", "v" : { "c" : { "d" : { "$numberInt" : "2" } } } } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": {"c": 2}}}', '{"result": { "$objectToArray": { "a": "$a", "b": "$a.b", "c": "$a.b.c" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "a", "v" : { "b" : { "c" : { "$numberInt" : "2" } } } }, { "k" : "b", "v" : { "c" : { "$numberInt" : "2" } } }, { "k" : "c", "v" : { "$numberInt" : "2" } } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": {"c": 2}}}', '{"result": { "$objectToArray": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "k" : "b", "v" : { "c" : { "$numberInt" : "2" } } } ] } (1 row) -- $objectToArray: null or undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$objectToArray": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$objectToArray": {"$arrayElemAt": [[1], 5]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $objectToArray: expects document as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [1]}}'); ERROR: $objectToArray expression requires a document input, but received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": 1}}'); ERROR: $objectToArray expression requires a document input, but received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": "string"}}'); ERROR: $objectToArray expression requires a document input, but received: string SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [true]}}'); ERROR: $objectToArray expression requires a document input, but received: bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": false}}'); ERROR: $objectToArray expression requires a document input, but received: bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": {"$add": [1, 2]}}}'); ERROR: $objectToArray expression requires a document input, but received: int -- $objectToArray: accepts exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": []}}'); ERROR: The expression $objectToArray requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [1, 2]}}'); ERROR: The expression $objectToArray requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [{}, {}]}}'); ERROR: The expression $objectToArray requires exactly 1 arguments, but 2 arguments were actually provided. -- $arrayToObject: returns expected object SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "value" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", 1], ["b", {"$add": [1, 1]}]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a.b.c", true]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a.b.c" : true } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a.b.c", [1, 2, 3]]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a.b.c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": { "$literal": [[ "key", "value"], [ "qty", 25 ]]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "key" : "value", "qty" : { "$numberInt" : "25" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "value" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": 1}, {"k": "b", "v": {"$add": [1, 1]}}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a.b.c", "v": true}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a.b.c" : true } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a.b.c", "v": [1, 2, 3]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a.b.c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": { "$literal": [{ "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 }]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "item" : "abc123", "qty" : { "$numberInt" : "25" } } } (1 row) -- $arrayToObject: deduplicates if multiple keys are the same SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["a", "value2"], ["a", "final value"]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "final value" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "value2"], ["a", "final value"], ["b", true], ["c", 1], ["c", 2]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "final value", "b" : true, "c" : { "$numberInt" : "2" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}, {"k": "b", "v": "value2"}, {"k": "c", "v": "value3"}, {"k": "c", "v": "final"}, {"k": "b", "v": "final"}, {"k": "a", "v": "final"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "final", "b" : "final", "c" : "final" } } (1 row) -- $arrayToObject: null or undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$objectToArray": [null]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$objectToArray": {"$arrayElemAt": [[1], -2]}}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $objectToArray -> $arrayToObject roundtrips SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayToObject": { "$objectToArray": { "a": 1 }}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayToObject": { "$objectToArray": { "a": 1, "b": {"$add": [1, 1]}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } } (1 row) -- $arrayToObject: accepts exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": []}}'); ERROR: The expression $arrayToObject requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1, 2, 3]}}'); ERROR: The expression $arrayToObject requires exactly 1 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1, 2]}}'); ERROR: The expression $arrayToObject requires exactly 1 arguments, but 2 arguments were actually provided. -- $arrayToObject: input must be array SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1]}}'); ERROR: $arrayToObject needs an array as input, but a different type was provided: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{}]}}'); ERROR: $arrayToObject needs an array as input, but a different type was provided: object SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$add": [1, 1]}]}}'); ERROR: $arrayToObject needs an array as input, but a different type was provided: int -- $arrayToObject: requires consistent input all objects or all arrays SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], {"k": "b", "v": 1}]]}}'); ERROR: $arrayToObject needs a consistent format of input. All elements must either be arrays or objects exclusively. An array was identified initially, but the following element was found: object SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "b", "v": 1}, ["a", "value"]]]}}'); ERROR: $arrayToObject needs a consistent format of input; every element should be either entirely arrays or entirely objects. An object was initially detected, but the following element was found: array -- $arrayToObject: key must be string SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[[1, "value"]]]}}'); ERROR: Expected 'string' type for $arrayToObject entries but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "foo"], [2, 2]]]}}'); ERROR: Expected 'string' type for $arrayToObject entries but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": 1, "v": "value"}]]}}'); ERROR: $arrayToObject needs an input object containing keys 'k' and 'v', with 'k' specifically required to be a string type. Detected type: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}, {"k": "b", "v": "value"}, {"k": 1, "v": "value"}]]}}'); ERROR: $arrayToObject needs an input object containing keys 'k' and 'v', with 'k' specifically required to be a string type. Detected type: int -- $arrayToObject: array input format must be of length 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["value"]]]}}'); ERROR: $arrayToObject needs an array containing exactly two elements, but received one with size: 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "v"], [1, 2, 3]]]}}'); ERROR: $arrayToObject needs an array containing exactly two elements, but received one with size: 3 -- $arrayToObject: document input format must have 2 fields SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a"}]]}}'); ERROR: $arrayToObject needs object keys named 'k' and 'v', but an incorrect number of keys was detected: 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"k": "a"}]]}}'); ERROR: $arrayToObject needs object keys named 'k' and 'v', but an incorrect number of keys was detected: 1 -- $arrayToObject: document input must have a 'k' and a 'v' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "foo": "value"}]]}}'); ERROR: $arrayToObject needs an object containing both 'k' and 'v' keys, but one or both of these required keys are missing from: { "k" : "a", "foo" : "value" } SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"v": "a", "blah": "k"}]]}}'); ERROR: $arrayToObject needs an object containing both 'k' and 'v' keys, but one or both of these required keys are missing from: { "v" : "a", "blah" : "k" } SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"v": "a", "k": "k"}, {"blah": 1, "foo": 2}]]}}'); ERROR: $arrayToObject needs an object containing both 'k' and 'v' keys, but one or both of these required keys are missing from: { "blah" : 1, "foo" : 2 } -- $arrayToObject: key must not contain embedded null byte SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "fo\u0000os", "v": "value"}]]}}'); ERROR: Key field must not include an embedded null byte SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "fo\u0000", "v": "value"}]]}}'); ERROR: Key field must not include an embedded null byte SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["\u0000", "value"]]]}}'); ERROR: Key field must not include an embedded null byte SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["\u0000hello", "value"]]]}}'); ERROR: Key field must not include an embedded null byte --$slice Operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$slice": [[1,2,3],1,1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3]}', '{"result": { "$slice": ["$a",1,1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$slice": [[1,2,{"$add":[1,2,3]}],{"$add":[0,1]},1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3]}', '{"result": { "$slice": ["$b",1,1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) --$slice with positive array field input select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "slicedArray" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10,10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",2,10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$b",10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) --$slice with Negative array field input or Zero select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],-1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "slicedArray" : [ { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],-2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "slicedArray" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : ["$a",-1,2]} }'); ERROR: The first parameter provided to $slice must be an array, but a value of type int was received instead. select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],1,0]} }'); ERROR: The third argument provided to the $slice operator must have a positive value: 0 select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],2,-1]} }'); ERROR: The third argument provided to the $slice operator must have a positive value: -1 select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$b",-1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) --$slice with other expression select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[{"$add": [1,2,3]},2,3,4,5],1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[{"$add": [1,2,3]},2,3,4,5],{"$multiply":[1,2]},3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",-2,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) --$slice with inclusion or exclusion spec select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":1, "d":1}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":0}'); ERROR: exclusion cannot be applied to field b within the inclusion projection. select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":0, "d":1}'); ERROR: exclusion cannot be applied to field b within the inclusion projection. --$slice has NULL input select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [null,1,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[1,2,3],null,2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[1,2,3],1,null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) --Invalid Input Negative cases $slice projection select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : "str"}}'); ERROR: The expression $slice requires no fewer than 2 arguments and no more than 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["hello",1,2]}}'); ERROR: The first parameter provided to $slice must be an array, but a value of type string was received instead. select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a","str",2]}}'); ERROR: The Second argument for the $slice needs to be a numeric value; however, it is currently of type: string select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,"str"]}}'); ERROR: The Third argument for the $slice needs to be a numeric value; however, it is currently of type: string select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,1.02]}}'); ERROR: The Third value provided to the $slice operator cannot be expressed within the limits of a 32-bit integer: 1.02 select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,-1]}}'); ERROR: The third argument provided to the $slice operator must have a positive value: -1 select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,0]}}'); ERROR: The third argument provided to the $slice operator must have a positive value: 0 select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a"]}}'); ERROR: The expression $slice requires no fewer than 2 arguments and no more than 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,2,4]}}'); ERROR: The expression $slice requires no fewer than 2 arguments and no more than 3 arguments, but 4 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "NaN"},{ "$numberDecimal" : "NaN"}]}}'); ERROR: The Second value provided to the $slice operator cannot be expressed within the limits of a 32-bit integer: NaN select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "NaN"},{ "$numberDecimal" : "Infinity"}]}}'); ERROR: The Second value provided to the $slice operator cannot be expressed within the limits of a 32-bit integer: NaN select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "Infinity"},{ "$numberDecimal" : "NaN"}]}}'); ERROR: The Second value provided to the $slice operator cannot be expressed within the limits of a 32-bit integer: Infinity select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "Infinity"},{ "$numberDecimal" : "Infinity"}]}}'); ERROR: The Second value provided to the $slice operator cannot be expressed within the limits of a 32-bit integer: Infinity -- $concatArrays operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": []}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"array": []}', '{"result": { "$concatArrays": [[], "$array"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4", "2" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2", ["nested", "array"]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4", "2", [ "nested", "array" ] ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2", ["nested", "array", ["more", "nested", "array"]]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4", "2", [ "nested", "array", [ "more", "nested", "array" ] ] ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [[{"$add": [1, 1]}, [{"$add": [1,2]}]]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, [ { "$numberInt" : "3" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2"], "c": ["3", "4"]}}', '{"result": { "$concatArrays": ["$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4" ] } (1 row) -- $concatArrays the indexes are preserved and we can query the result via array index keys. WITH r1 AS (SELECT bson_dollar_project('{"doc": {"foo": "value"}, "array": ["first", "second"]}', '{"result": {"$concatArrays": [["$doc"], "$array"]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.2": "second"}'; result --------------------------------------------------------------------- { "result" : [ { "foo" : "value" }, "first", "second" ] } (1 row) WITH r1 AS (SELECT bson_dollar_project('{"doc": {"foo": "value"}, "array": ["first", "second"]}', '{"result": {"$concatArrays": [["$doc"], "$array"]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.0": {"foo": "value"}}'; result --------------------------------------------------------------------- { "result" : [ { "foo" : "value" }, "first", "second" ] } (1 row) WITH r1 AS (SELECT bson_dollar_project('{}', '{"result": {"$concatArrays": [["0", "1"], ["2", "3", "4", "5"]]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.0": "0"}'; result --------------------------------------------------------------------- { "result" : [ "0", "1", "2", "3", "4", "5" ] } (1 row) WITH r1 AS (SELECT bson_dollar_project('{}', '{"result": {"$concatArrays": [["0", "1"], ["2", "3", "4", "5"]]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.4": "4"}'; result --------------------------------------------------------------------- { "result" : [ "0", "1", "2", "3", "4", "5" ] } (1 row) -- $concatArrays null/undefined argument should result in null. Nested nulls, should just be nulls in the final array SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": ["$undef"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": "$undef"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], null, ["3", "4"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4"], null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", null]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4", null ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "$undef"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "1", "2", "3", "4", null ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], "$undef", ["3", "4", "$undef"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"doc": {"foo": "string"}, "array": ["first", "second", null]}', '{"result": { "$concatArrays": [["$doc"], "$array"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "foo" : "string" }, "first", "second", null ] } (1 row) -- $concatArrays error when arguments are not an array SELECT * FROM bson_dollar_project('{"a": {"b": "1"}}', '{"result": { "$concatArrays": "$a"}}'); ERROR: $concatArrays requires array inputs, but a value of type object was provided SELECT * FROM bson_dollar_project('{"a": {"b": "1"}}', '{"result": { "$concatArrays": ["$a"]}}'); ERROR: $concatArrays requires array inputs, but a value of type object was provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [[1], {"a": "1"}]}}'); ERROR: $concatArrays requires array inputs, but a value of type object was provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [true]}}'); ERROR: $concatArrays requires array inputs, but a value of type bool was provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": ["string"]}}'); ERROR: $concatArrays requires array inputs, but a value of type string was provided -- $filter simple cond SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": false}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": null}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": 1}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": 0}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $filter use cond with expression and reference variable for each element SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", 3]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"a": {"$undefined": true}}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$filter": {"input": "$undefinedPath", "cond": {"$lt": ["$$this", 4]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this", null]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "foo", "baz", "var", "blah" ] } (1 row) SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$dummy", null]}, "as": "dummy"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "foo", "baz", "var", "blah" ] } (1 row) -- $filter reference variable with dotted expression SELECT * FROM bson_dollar_project('{"a": [{"first": "foo", "second": "bar"}, {"first": "baz", "second": null}]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this.second", null]}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "first" : "foo", "second" : "bar" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [{"first": "foo", "second": "bar"}, {"first": "baz", "second": null}]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$dummy.second", null]}, "as": "dummy"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "first" : "foo", "second" : "bar" } ] } (1 row) -- $filter with limit SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": 1}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberLong": "1"}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDecimal": "5.00000"}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "1.0"}}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": null}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": "$undefinedPath"}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": 5}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this", null]}, "limit": 4}} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "foo", "baz", "var", "blah" ] } (1 row) -- $filter with nested filter and clashing variable names SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "cond": {"$filter": {"input": "$$this", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$this"]}, 3]}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "-100" }, { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "30" }, { "$numberInt" : "40" }, { "$numberInt" : "8000" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "cond": {"$filter": {"input": "$$this", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$number"]}, 3]}, "as": "number"}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "-100" }, { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "30" }, { "$numberInt" : "40" }, { "$numberInt" : "8000" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "as": "number", "cond": {"$filter": {"input": "$$number", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$number"]}, 3]}, "as": "number"}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "-100" }, { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "30" }, { "$numberInt" : "40" }, { "$numberInt" : "8000" } ] ] } (1 row) -- $filter with $and/$or shouldn't fail when if condition is met before error in nested expression SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": {"$or": [{"$lt": ["$$this", 0]}, {"$ln": "$$this"}]}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "-1" }, { "$numberInt" : "-2" }, { "$numberInt" : "-3" }, { "$numberInt" : "-4" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": {"$and": [{"$gt": ["$$this", 0]}, {"$ln": "$$this"}]}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $filter, arg must be an object SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": "$a"}}'); ERROR: $filter can accept only an object type as its valid argument SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": true}}'); ERROR: $filter can accept only an object type as its valid argument SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": []}}'); ERROR: $filter can accept only an object type as its valid argument -- $filter, object should have cond and input, as/limit are optional, any other path is invalid SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a"}}}'); ERROR: The 'cond' parameter required by the $filter operator is missing SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"cond": true}}}'); ERROR: 'Input' parameter is missing for $filter SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": true, "sort": false}}}'); ERROR: Parameter not recognized in $filter: sort -- $filter, input should be an array SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": "$a", "cond": true}}}'); ERROR: Expected 'array' type as input to $filter but found 'object' type SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": "a", "cond": true}}}'); ERROR: Expected 'array' type as input to $filter but found 'string' type SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": true, "cond": true}}}'); ERROR: Expected 'array' type as input to $filter but found 'bool' type -- $filter, as variable name should be valid -- invalid SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "_element"}}}'); ERROR: The variable name '_element' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "1element"}}}'); ERROR: The variable name '1element' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "Element"}}}'); ERROR: The variable name 'Element' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el@ement"}}}'); ERROR: The variable name 'el@ement' contains an invalid character '@'. SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el-ement"}}}'); ERROR: The variable name 'el-ement' contains an invalid character '-'. SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": ""}}}'); ERROR: Variable names cannot be left empty SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": null}}}'); ERROR: Variable names cannot be left empty SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": true}}}'); ERROR: Variable names cannot be left empty -- valid SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "element1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el_ement1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "eLEMEnt"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $filter, limit must be representable as a 32bit integer and > 0 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "1.1"}}} }'); ERROR: Operator $filter requires the limit to be specified as a 32-bit integer value: 1.1 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDecimal": "1.1"}}} }'); ERROR: Operator $filter requires the limit to be specified as a 32-bit integer value: 1.1 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberLong": "2147483648"}}} }'); ERROR: Operator $filter requires the limit to be specified as a 32-bit integer value: 2147483648 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "2147483648.0"}}} }'); ERROR: Operator $filter requires the limit to be specified as a 32-bit integer value: 2.14748E+09 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "0.0"}}} }'); ERROR: $filter: limit value must be strictly greater than zero: 0 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "-1.0"}}} }'); ERROR: $filter: limit value must be strictly greater than zero: -1 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": -100}} }'); ERROR: $filter: limit value must be strictly greater than zero: -100 -- $filter, undefined variable SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "as":"element", "cond": {"$gt": ["$$this", 3]}}} }'); ERROR: Attempting to use an undefined variable: this SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$element", 3]}}} }'); ERROR: Attempting to use an undefined variable: element SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", "$$filterValue"]}}} }'); ERROR: Attempting to use an undefined variable: filterValue SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", "$$filterValue.name.last"]}}} }'); ERROR: Attempting to use an undefined variable: filterValue -- $firstN, operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":3} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":1} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":11} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "45" }, { "$numberInt" : "12" }, null, "asdhkas", { "$numberDouble" : "12890.891200000000026" }, { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "45" }, { "$numberInt" : "12" }, null, "asdhkas", { "$numberDouble" : "12890.891200000000026" }, { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [], "n":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":3.000000} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":{"$numberDecimal": "2.000000"}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775807"} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) -- $firstN, operator with docs in db select documentdb_api.insert_one('db','dollarfirstN','{"a":[1,2,3] , "_id":1}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarfirstN','{"a":[42,67] , "_id":2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarfirstN','{"a":[] , "_id":3}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarfirstN','{"a":[1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"] , "_id":4}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarfirstN'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "2" }, "result" : [ { "$numberInt" : "42" }, { "$numberInt" : "67" } ] } { "_id" : { "$numberInt" : "3" }, "result" : [ ] } { "_id" : { "$numberInt" : "4" }, "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (4 rows) -- $firstN , operator with docs in db and invalid path select documentdb_api.insert_one('db','dollarFirstN','{"b":[] , "_id":5}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarFirstN'); ERROR: Expected 'array' type as input select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":"abc"} }}') from documentdb_api.collection('db','dollarFirstN'); ERROR: Expected 'integer' type for 'n' field but found '"abc"' type --$firstN, operator invalid input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": true, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": 5, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": "abcvde", "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": 4.56, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": true }}'); ERROR: specification must be defined as an object, but the provided input was $firstN :true SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": "ayush_test_name" }}'); ERROR: specification must be defined as an object, but the provided input was $firstN :"ayush_test_name" --$firstN, operator invalid n SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":"3"} }}'); ERROR: Expected 'integer' type for 'n' field but found '"3"' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":0} }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":-1} }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":3.124} }}'); ERROR: Expected 'integer' type for 'n' field but found 'double' type for value '3.124' SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775808"} } }}'); ERROR: Expected 'integer' type for 'n' field but found 'decimal' type for value '9223372036854775808' SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "0"} } }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 -- $lastN, operator with docs in db select documentdb_api.insert_one('db','dollarLastN','{"a":[1,2,3] , "_id":1}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarLastN','{"a":[42,67] , "_id":2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarLastN','{"a":[] , "_id":3}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db','dollarLastN','{"a":[1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"] , "_id":4}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarLastN'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "2" }, "result" : [ { "$numberInt" : "42" }, { "$numberInt" : "67" } ] } { "_id" : { "$numberInt" : "3" }, "result" : [ ] } { "_id" : { "$numberInt" : "4" }, "result" : [ { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (4 rows) -- $lastN , operator with docs in db and invalid path select documentdb_api.insert_one('db','dollarLastN','{"b":[] , "_id":5}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarLastN'); ERROR: Expected 'array' type as input select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":"abc"} }}') from documentdb_api.collection('db','dollarLastN'); ERROR: Expected 'integer' type for 'n' field but found '"abc"' type --$firstN, operator missing or extra args SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4]} }}'); ERROR: $firstN requires an 'n' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"n": 5} }}'); ERROR: $firstN needs to have an 'input' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"n": 5, "input": [1,2,3], "abc":1} }}'); ERROR: $firstN encountered an unrecognized argument value: abc -- $lastN, operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":3} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":1} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":11} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "45" }, { "$numberInt" : "12" }, null, "asdhkas", { "$numberDouble" : "12890.891200000000026" }, { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "45" }, { "$numberInt" : "12" }, null, "asdhkas", { "$numberDouble" : "12890.891200000000026" }, { "$numberDecimal" : "223.234823904823904823041212233" }, { "$date" : { "$numberLong" : "0" } }, "퀀8" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [], "n":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":3.000000} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":{"$numberDecimal": "2.000000"}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775807"} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) --$lastN, operator invalid input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": true, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": 5, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": "abcvde", "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": 4.56, "n":3} }}'); ERROR: Expected 'array' type as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": true }}'); ERROR: specification must be defined as an object, but the provided input was $lastN :true SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": "ayush_test_name" }}'); ERROR: specification must be defined as an object, but the provided input was $lastN :"ayush_test_name" --$lastN, operator invalid n SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":"3"} }}'); ERROR: Expected 'integer' type for 'n' field but found '"3"' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":0} }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":-1} }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":3.124} }}'); ERROR: Expected 'integer' type for 'n' field but found 'double' type for value '3.124' SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775808"} } }}'); ERROR: Expected 'integer' type for 'n' field but found 'decimal' type for value '9223372036854775808' SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "0"} } }}'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 --$lastN, operator missing or extra args SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4]} }}'); ERROR: $lastN requires an 'n' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"n": 5} }}'); ERROR: $lastN needs to have an 'input' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"n": 5, "input": [1,2,3], "abc":1} }}'); ERROR: $lastN encountered an unrecognized argument value: abc -- $range, simple condition asc SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" }, { "$numberInt" : "7" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,100,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" }, { "$numberInt" : "7" }, { "$numberInt" : "10" }, { "$numberInt" : "13" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "31" }, { "$numberInt" : "34" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "46" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "55" }, { "$numberInt" : "58" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "67" }, { "$numberInt" : "70" }, { "$numberInt" : "73" }, { "$numberInt" : "76" }, { "$numberInt" : "79" }, { "$numberInt" : "82" }, { "$numberInt" : "85" }, { "$numberInt" : "88" }, { "$numberInt" : "91" }, { "$numberInt" : "94" }, { "$numberInt" : "97" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberLong": "50"},100,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "50" }, { "$numberInt" : "53" }, { "$numberInt" : "56" }, { "$numberInt" : "59" }, { "$numberInt" : "62" }, { "$numberInt" : "65" }, { "$numberInt" : "68" }, { "$numberInt" : "71" }, { "$numberInt" : "74" }, { "$numberInt" : "77" }, { "$numberInt" : "80" }, { "$numberInt" : "83" }, { "$numberInt" : "86" }, { "$numberInt" : "89" }, { "$numberInt" : "92" }, { "$numberInt" : "95" }, { "$numberInt" : "98" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberLong": "150"},{"$numberDecimal":"20.0000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "50" }, { "$numberInt" : "70" }, { "$numberInt" : "90" }, { "$numberInt" : "110" }, { "$numberInt" : "130" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberDecimal": "150"},{"$numberDouble":"20.00000000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "50" }, { "$numberInt" : "70" }, { "$numberInt" : "90" }, { "$numberInt" : "110" }, { "$numberInt" : "130" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberDecimal": "50"},{"$numberDouble":"20.00000000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $range, simple condition desc SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,-10,-1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" }, { "$numberInt" : "8" }, { "$numberInt" : "7" }, { "$numberInt" : "6" }, { "$numberInt" : "5" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" }, { "$numberInt" : "0" }, { "$numberInt" : "-1" }, { "$numberInt" : "-2" }, { "$numberInt" : "-3" }, { "$numberInt" : "-4" }, { "$numberInt" : "-5" }, { "$numberInt" : "-6" }, { "$numberInt" : "-7" }, { "$numberInt" : "-8" }, { "$numberInt" : "-9" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,-3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "10" }, { "$numberInt" : "7" }, { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [100,1,-3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "100" }, { "$numberInt" : "97" }, { "$numberInt" : "94" }, { "$numberInt" : "91" }, { "$numberInt" : "88" }, { "$numberInt" : "85" }, { "$numberInt" : "82" }, { "$numberInt" : "79" }, { "$numberInt" : "76" }, { "$numberInt" : "73" }, { "$numberInt" : "70" }, { "$numberInt" : "67" }, { "$numberInt" : "64" }, { "$numberInt" : "61" }, { "$numberInt" : "58" }, { "$numberInt" : "55" }, { "$numberInt" : "52" }, { "$numberInt" : "49" }, { "$numberInt" : "46" }, { "$numberInt" : "43" }, { "$numberInt" : "40" }, { "$numberInt" : "37" }, { "$numberInt" : "34" }, { "$numberInt" : "31" }, { "$numberInt" : "28" }, { "$numberInt" : "25" }, { "$numberInt" : "22" }, { "$numberInt" : "19" }, { "$numberInt" : "16" }, { "$numberInt" : "13" }, { "$numberInt" : "10" }, { "$numberInt" : "7" }, { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberLong": "100"},-50,-3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "100" }, { "$numberInt" : "97" }, { "$numberInt" : "94" }, { "$numberInt" : "91" }, { "$numberInt" : "88" }, { "$numberInt" : "85" }, { "$numberInt" : "82" }, { "$numberInt" : "79" }, { "$numberInt" : "76" }, { "$numberInt" : "73" }, { "$numberInt" : "70" }, { "$numberInt" : "67" }, { "$numberInt" : "64" }, { "$numberInt" : "61" }, { "$numberInt" : "58" }, { "$numberInt" : "55" }, { "$numberInt" : "52" }, { "$numberInt" : "49" }, { "$numberInt" : "46" }, { "$numberInt" : "43" }, { "$numberInt" : "40" }, { "$numberInt" : "37" }, { "$numberInt" : "34" }, { "$numberInt" : "31" }, { "$numberInt" : "28" }, { "$numberInt" : "25" }, { "$numberInt" : "22" }, { "$numberInt" : "19" }, { "$numberInt" : "16" }, { "$numberInt" : "13" }, { "$numberInt" : "10" }, { "$numberInt" : "7" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "-2" }, { "$numberInt" : "-5" }, { "$numberInt" : "-8" }, { "$numberInt" : "-11" }, { "$numberInt" : "-14" }, { "$numberInt" : "-17" }, { "$numberInt" : "-20" }, { "$numberInt" : "-23" }, { "$numberInt" : "-26" }, { "$numberInt" : "-29" }, { "$numberInt" : "-32" }, { "$numberInt" : "-35" }, { "$numberInt" : "-38" }, { "$numberInt" : "-41" }, { "$numberInt" : "-44" }, { "$numberInt" : "-47" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberLong": "50"},{"$numberDecimal":"-20.0000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "150" }, { "$numberInt" : "130" }, { "$numberInt" : "110" }, { "$numberInt" : "90" }, { "$numberInt" : "70" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberDecimal": "50"},{"$numberDouble":"-20.00000000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "150" }, { "$numberInt" : "130" }, { "$numberInt" : "110" }, { "$numberInt" : "90" }, { "$numberInt" : "70" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberDecimal": "150"},{"$numberDouble":"-20.00000000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $range, asc series but skip val negative SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,-1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,{"$numberDecimal":"-1.0000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $range, desc series but skip val positive SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,{"$numberDecimal":"1.0000"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) -- $range, expects only ranges in int_32 hence, if numbers overflow during range we should stop SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,2147483647,1073741824] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "1073741825" } ] } (1 row) -- $range, testing with values from document SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 42}', '{"result": {"$range": ["$distance",200,40] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "42" }, { "$numberInt" : "82" }, { "$numberInt" : "122" }, { "$numberInt" : "162" } ] } (1 row) SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 88}', '{"result": {"$range": ["$distance",200,40] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "88" }, { "$numberInt" : "128" }, { "$numberInt" : "168" } ] } (1 row) SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 288}', '{"result": {"$range": ["$distance",200,40] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 288}', '{"result": {"$range": [10,"$distance",5] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberInt" : "25" }, { "$numberInt" : "30" }, { "$numberInt" : "35" }, { "$numberInt" : "40" }, { "$numberInt" : "45" }, { "$numberInt" : "50" }, { "$numberInt" : "55" }, { "$numberInt" : "60" }, { "$numberInt" : "65" }, { "$numberInt" : "70" }, { "$numberInt" : "75" }, { "$numberInt" : "80" }, { "$numberInt" : "85" }, { "$numberInt" : "90" }, { "$numberInt" : "95" }, { "$numberInt" : "100" }, { "$numberInt" : "105" }, { "$numberInt" : "110" }, { "$numberInt" : "115" }, { "$numberInt" : "120" }, { "$numberInt" : "125" }, { "$numberInt" : "130" }, { "$numberInt" : "135" }, { "$numberInt" : "140" }, { "$numberInt" : "145" }, { "$numberInt" : "150" }, { "$numberInt" : "155" }, { "$numberInt" : "160" }, { "$numberInt" : "165" }, { "$numberInt" : "170" }, { "$numberInt" : "175" }, { "$numberInt" : "180" }, { "$numberInt" : "185" }, { "$numberInt" : "190" }, { "$numberInt" : "195" }, { "$numberInt" : "200" }, { "$numberInt" : "205" }, { "$numberInt" : "210" }, { "$numberInt" : "215" }, { "$numberInt" : "220" }, { "$numberInt" : "225" }, { "$numberInt" : "230" }, { "$numberInt" : "235" }, { "$numberInt" : "240" }, { "$numberInt" : "245" }, { "$numberInt" : "250" }, { "$numberInt" : "255" }, { "$numberInt" : "260" }, { "$numberInt" : "265" }, { "$numberInt" : "270" }, { "$numberInt" : "275" }, { "$numberInt" : "280" }, { "$numberInt" : "285" } ] } (1 row) -- $range, negative conditions starting number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [2147483648,214748364121,40] } }'); ERROR: The $range operator needs a starting value that fits within a 32-bit integer, but the provided value was: 2147483648 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberDecimal":"0.35"},400,40] } }'); ERROR: The $range operator needs a starting value that fits within a 32-bit integer, but the provided value was: 0.35 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": ["abvcf",400,40] } }'); ERROR: $range expression requires a numeric start value but encountered a value of type: string SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [true,400,40] } }'); ERROR: $range expression requires a numeric start value but encountered a value of type: bool SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [null,400,40] } }'); ERROR: $range expression requires a numeric start value but encountered a value of type: null SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [null,400,40,400] } }'); ERROR: The expression $range requires no fewer than 2 arguments and no more than 3 arguments, but 4 arguments were actually provided. -- $range, negative conditions ending number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [2147648,214748364121,40] } }'); ERROR: $range needs an ending value representable as a 32-bit integer, but encountered value: 214748364121 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [-10, {"$numberDecimal":"0.35"},4] } }'); ERROR: $range needs an ending value representable as a 32-bit integer, but encountered value: 0.35 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [400,"abvcf",400] } }'); ERROR: $range expression needs a numeric ending value, but a value of type string was provided SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [5,true,40] } }'); ERROR: $range expression needs a numeric ending value, but a value of type bool was provided SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,null] } }'); ERROR: $range expression needs a numeric ending value, but a value of type null was provided -- $range, negative conditions step number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [21,21471,2147483648] } }'); ERROR: $range operator needs a step value that fits within a 32-bit integer, but the provided value was: 2147483648 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [-10,15, {"$numberDecimal":"0.35"}] } }'); ERROR: $range operator needs a step value that fits within a 32-bit integer, but the provided value was: 0.35 SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,400,"abvcf"] } }'); ERROR: Expression $range needs a numeric step value, but received a value of type: string SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [5,40,true] } }'); ERROR: Expression $range needs a numeric step value, but received a value of type: bool SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,5,null] } }'); ERROR: Expression $range needs a numeric step value, but received a value of type: null SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,5,0] } }'); ERROR: $range requires a step value that cannot be zero -- $range, tests large numbers SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [200,20000] }} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "19800" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [200,20000] },0]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "200" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [200,20000] },19799]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "19999" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [50000,65535960,100000] }} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "655" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [50000,65535960,100000] },0]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "50000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [50000,65535960,100000] },654]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "65450000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [2000000,1073741924,1000000] }} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1072" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [2000000,1073741924,1000000] },0]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [2000000,1073741924,1000000] },1071]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1073000000" } } (1 row) -- $range, tests memory limit exceed SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [200,65535960] } }'); ERROR: $range requires excessive memory (906389542 bytes) and cannot be offloaded to disk, exceeding the memory limit of 104857600 bytes. SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50000,65535960] } }'); ERROR: $range requires excessive memory (905692342 bytes) and cannot be offloaded to disk, exceeding the memory limit of 104857600 bytes. SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [0,1073741924] } }'); ERROR: $range requires excessive memory (16068759686 bytes) and cannot be offloaded to disk, exceeding the memory limit of 104857600 bytes. SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [0,6505360] } }'); ERROR: $range: The buffer size required to store the output has gone beyond the allowed 64MB maximum limit. -- $reverseArray, simple case SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4,5,6] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4,5,6,{"$numberLong":"1"}, {"$numberDecimal":"12389.2134234"}] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "12389.2134234" }, { "$numberLong" : "1" }, { "$numberInt" : "6" }, { "$numberInt" : "5" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}, "$field"] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "$field", { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}, "$field", [1.45,9,9]] } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberDouble" : "1.4499999999999999556" }, { "$numberInt" : "9" }, { "$numberInt" : "9" } ], "$field", { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": "$nums" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "145" }, { "$numberInt" : "9" }, { "$numberInt" : "9" } ], "$field", { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"key":[{"a":[8,9,10]},{"a":[3,2,1,-1]},{"a":[4,5,6]}]}', '{"result": {"$reverseArray": "$key.a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" }, { "$numberInt" : "-1" } ], [ { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } (1 row) -- $reverseArray, operator cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$range":[1,4]} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) -- $reverseArray, null cases SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": "$noField" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": null } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$undefined":true} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": {"$literal":null} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": {"$literal":{"$undefined":true}} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $reverseArray, negative cases SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": [1,2,345,5] } }'); ERROR: The expression $reverseArray requires exactly 1 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": true } }'); ERROR: The argument to $reverseArray must be an array, but was of type: bool SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": 1 } }'); ERROR: The argument to $reverseArray must be an array, but was of type: int -- $indexOfArray, simple cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[], 1,1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [null, 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 4] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "7" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "7" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 0, 111] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "7" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 111, 111] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 2, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 2, 7] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 7, 7] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) -- $indexOfArray, document based array SELECT * FROM bson_dollar_project('{"a": [1,2,345,5]}', '{"result": {"$indexOfArray": ["$a", 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [[1,2,345,5]]}', '{"result": {"$indexOfArray": ["$a", [1]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [[1,2,345,5]]}', '{"result": {"$indexOfArray": ["$a", [1,2]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) -- $indexOfArray, negative cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [true, 50.0, 1,50] } }'); ERROR: $indexOfArray expects the first argument to be an array, but received: bool SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 11, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, -1, 5] } }'); ERROR: Operator $indexOfArray needs a nonnegative starting index value, but received: -1 SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1, -5] } }'); ERROR: Operator $indexOfArray needs a nonnegative ending index value, but received: -5 SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1.1] } }'); ERROR: The $indexOfArray operator needs an integer starting index, but encountered a value of type double with the value 1.1. SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5.11] } }'); ERROR: The $indexOfArray operator needs an integer ending index, but encountered a value of type double with the value 5.11. SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5.11] } }'); ERROR: The $indexOfArray operator needs an integer ending index, but encountered a value of type double with the value 5.11. SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5,4] } }'); ERROR: The expression $indexOfArray requires no fewer than 2 arguments and no more than 4 arguments, but 5 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, "1",5] } }'); ERROR: The $indexOfArray operator needs an integer starting index, but encountered a value of type string with the value "1". SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,"50"] } }'); ERROR: The $indexOfArray operator needs an integer ending index, but encountered a value of type string with the value "50". SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,90000000000000] } }'); ERROR: The $indexOfArray operator needs an integer ending index, but encountered a value of type long with the value 90000000000000. -- $indexOfArray, search for elements of different type SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], "2"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], true] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], {"a":1}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"$numberLong":"44374"}], {"$numberLong":"44374"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"$numberDecimal":"44374.124"}], {"$numberDecimal":"44374.124"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,null], null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true, {"$date": { "$numberLong" : "0" }}, null], {"$date": { "$numberLong" : "0" }}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true, "This is â¤ï¸", null], "This is â¤ï¸"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 44374, "2", true, {"$numberLong":"44374"}], {"$numberLong":"44374"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 44374, "2", true, {"$numberLong":"44374"}], {"$numberInt":"44374"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", true, {"$numberLong":"44374"}], {"$numberDecimal":"44374"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", [true, {"$numberLong":"44374"}]], [true,{"$numberDecimal":"44374"}]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", [true, {"$numberLong":"44374"}, 1]], [1,true,{"$numberDecimal":"44374"}]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2}}], {"a":{"b":24, "d":2, "c":1 }}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2, "e": null}}], {"a":{"b":24,"c":1, "d":2, "e":null }}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2, "e": null}}], {"a":{"b":24,"c":1, "d":2, "e": {"$undefined":true} }}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) -- $max, single input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": null } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$undefined":true} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"a":1} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": 5 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$numberDouble":"5.454"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5.4539999999999997371" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$numberDecimal":"5.454"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "5.454" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$date": { "$numberLong" : "0" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "0" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [-2147483648, 2147483647, -9223372036854775808, 9223372036854775807, 0, 100, -100] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "9223372036854775807" } } (1 row) -- $max, array input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,2,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [[1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,2,3,5,3,2,1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,3,5,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,33, [1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,200.0] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "200.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$regularExpression" : { "pattern" : "/ab/cdsd/abc", "options" : "" } } } (1 row) -- $max, null cases within array SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [null, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{}, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{"$undefined": true}, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [null, NaN, 1, 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{}, NaN, 1, 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,{"$undefined":true},8,3,4,[1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) -- $max, input document cases SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 130.5}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "130.5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": NaN}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$max": ["$a", 223324342] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$max": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$regularExpression" : { "pattern" : "/ab/cdsd/abc", "options" : "" } } } (1 row) SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$max": [1,2,45, "$a"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "100" }, { "$numberInt" : "2" }, { "$numberInt" : "33" }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$date" : { "$numberLong" : "0" } }, { "$numberDecimal" : "5.12124545487878787" }, { }, { "$numberDouble" : "NaN" }, { "$regularExpression" : { "pattern" : "/ab/cdsd/abc", "options" : "" } } ] } (1 row) -- $min, single input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": null } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$undefined":true} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"a":1} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "1" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": 5 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$numberDouble":"5.454"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5.4539999999999997371" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$numberDecimal":"5.454"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "5.454" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$date": { "$numberLong" : "0" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "0" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [-2147483648, 2147483647, -9223372036854775808, 9223372036854775807, 0, 100, -100] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-9223372036854775808" } } (1 row) -- $min, array input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,2,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [[1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,2,3,5,3,2,1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,3,5,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,33, [1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,200.0] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "100" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- $min, null cases within array SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [null, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{}, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{"$undefined": true}, NaN] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [null, NaN, 1, 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{}, NaN, 1, 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,{"$undefined":true},8,3,4,[1,2,3]] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) -- $min, input document cases SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 130.5}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "130.5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": NaN}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$min": ["$a", 223324342] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "223324342" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$min": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$min": [1,2,45, "$a"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) -- $sum , single input SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": "foo" }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": null }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"b": null }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) -- $sum , array input SELECT * FROM bson_dollar_project('{"a": [ 7, 1, 2 ] }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "10" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [ "foo", 1, 2 ] }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [ 1, null, 2 ] }', '{"result": {"$sum": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) -- $sum , array expression SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$sum": [ "$a", "$b", "$c" ] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "6" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$sum": [ "$a", { "$subtract": [ "$c", "$b" ] } ] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) -- $avg , single input SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": "foo" }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": null }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"b": null }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $avg , array input SELECT * FROM bson_dollar_project('{"a": [ 7, 1, 2 ] }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.3333333333333334814" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [ "foo", 1, 2 ] }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [ 1, null, 2 ] }', '{"result": {"$avg": "$a" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5" } } (1 row) -- $avg , array expression SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$avg": [ "$a", "$b", "$c" ] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$avg": [ "$a", { "$subtract": [ "$c", "$b" ] } ] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) -- $map select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$map": {"input": "$a", "as": "x", "in": { "$add": ["$$x", 1] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) select *from bson_dollar_project('{"str": ["a", "b", "c"]}', '{"result": {"$map": {"input": "$str", "as": "y", "in": { "$concat": ["$$y", "ddd"] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "addd", "bddd", "cddd" ] } (1 row) select *from bson_dollar_project('{"bools": [true, true, false, true] }', '{"allTrue": { "$map": { "input": "$bools", "as": "x", "in": { "$and": ["$$x", false] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "allTrue" : [ false, false, false, false ] } (1 row) select *from bson_dollar_project('{ "a": ["Hello", "", "big", "World", "!"] }', '{"a": { "$map": { "input": "$a", "as": "x", "in": { "$concat": [{ "$trim": { "input" : "$$x" }}, {"$cond": {"if": { "$eq": [ "$$x", "" ] }, "then": "1", "else": "2" } }, { "$trim": { "input" : "$$x" } } ] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "a" : [ "Hello2Hello", "1", "big2big", "World2World", "!2!" ] } (1 row) select *from bson_dollar_project('{"a": [["a", "b"], ["b", "c"], ["c", "d"], ["e", "a"], ["y", "z"]] }', '{"result": {"$map": {"input": "$a","as": "x","in": { "$setUnion": ["$$x", ["a","b"]] }}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ "b", "a" ], [ "b", "a", "c" ], [ "b", "a", "c", "d" ], [ "b", "e", "a" ], [ "b", "y", "a", "z" ] ] } (1 row) select *from bson_dollar_project('{"a": [{"b": [1, 2, 3]},{"b": [4, 5, 6]}]}', '{"result": {"$map": {"input": "$a","as": "outer","in": {"$map": {"input": "$$outer.b","as": "inner","in": { "$multiply": ["$$inner", 2] }}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "8" }, { "$numberInt" : "10" }, { "$numberInt" : "12" } ] ] } (1 row) -- $map in $addfield stage SELECT documentdb_api.insert_one('db','addFieldMap','{"_id":"1", "a": [{ "fieldA": "Hello World", "fieldB": "FOO" },{ "fieldA": "Goodbye everyone", "fieldB": "BAza" }]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "addFieldMap", "pipeline": [ { "$addFields": {"newField": { "$map": { "input": "$a", "as": "dummy", "in": {"fieldA_fieldB": { "$concat": ["$$dummy.fieldA", " -- ", "$$dummy.fieldB"] }} } } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "fieldA" : "Hello World", "fieldB" : "FOO" }, { "fieldA" : "Goodbye everyone", "fieldB" : "BAza" } ], "newField" : [ { "fieldA_fieldB" : "Hello World -- FOO" }, { "fieldA_fieldB" : "Goodbye everyone -- BAza" } ] } (1 row) -- $map, nested case select *from bson_dollar_project('{"a":[{"fieldA":"abc","fieldB":2,"fieldC":[{"number":45, "foo":"ab"}, {"foo":"ac","number":1}]},{"fieldA":"def","fieldB":6,"fieldC":[{"foo":"kb", "number":10}]}]}', '{"result":{"$map":{"input":"$a","as":"dummy","in":{"fieldA":"$$dummy.fieldA","fieldB":"$$dummy.fieldB","fieldC":{"$map":{"input":"$$dummy.fieldC","as":"fieldC","in":{"foo":"$$fieldC.foo","number":{"$add":["$$fieldC.number",100]}}}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "fieldA" : "abc", "fieldB" : { "$numberInt" : "2" }, "fieldC" : [ { "foo" : "ab", "number" : { "$numberInt" : "145" } }, { "foo" : "ac", "number" : { "$numberInt" : "101" } } ] }, { "fieldA" : "def", "fieldB" : { "$numberInt" : "6" }, "fieldC" : [ { "foo" : "kb", "number" : { "$numberInt" : "110" } } ] } ] } (1 row) -- $map, negative cases select *from bson_dollar_project('{"a": 1}', '{"result": {"$map": {"input": "$a", "as": "x", "in": { "$add": ["$$x", 1] } } } }'); ERROR: The $map operator requires an array input, but received int instead select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$map": {"input": "$a" }} }'); ERROR: 'in' parameter must be specified for $map -- $reduce select *from bson_dollar_project('{"a": ["a", "b", "c"]}', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "abc" } (1 row) select *from bson_dollar_project('{"a": [ 1, 2, 3, 4 ]}', '{"result": { "$reduce": { "input": "$a", "initialValue": { "sum": 5, "product": 2 }, "in": { "sum": { "$add" : ["$$value.sum", "$$this"] }, "product": { "$multiply": [ "$$value.product", "$$this" ] } } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "sum" : { "$numberInt" : "15" }, "product" : { "$numberInt" : "48" } } } (1 row) select *from bson_dollar_project('{"a": [ [ 3, 4 ], [ 5, 6 ] ] }', '{"result": { "$reduce": { "input": "$a", "initialValue": [ 1, 2 ], "in": { "$concatArrays" : ["$$value", "$$this"] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } (1 row) select *from bson_dollar_project('{"a": [[1, 2], [3, 4], [5, 6]] }', '{"result": { "$reduce": { "input": "$a", "initialValue": 0, "in": { "$add" : ["$$value", {"$reduce": {"input": "$$this","initialValue": 0, "in": { "$add": ["$$value", "$$this"] }}}] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "21" } } (1 row) select *from bson_dollar_project('{ "a": ["Hello", "", "big", "World", "!"] }', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": [{ "$trim": { "input" : "$$value" }}, {"$cond": {"if": { "$eq": [ "$$value", "" ] }, "then": "1", "else": "2" } }, { "$trim": { "input" : "$$this" } } ] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "1Hello22big2World2!" } (1 row) select *from bson_dollar_project('{"a": [2, 3, 5, 8, 13, 21,7,1]}','{"result": {"$reduce": { "input": "$a", "initialValue": 0, "in": { "$cond": [{ "$gt": ["$$this", 5] }, { "$add": ["$$value", 1] }, "$$value"] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) select *from bson_dollar_project('{"a": [true, true, false, true] }', '{"result": { "$reduce": { "input": "$bools", "initialValue": true, "in": { "$and": ["$$value", "$$this"] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"a": [1, null, 3, null, 5] }', '{"result": { "$reduce": { "input": "$a", "initialValue": 0, "in": { "$add": ["$$value", { "$ifNull": ["$$this", 0] }] } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "9" } } (1 row) select *from bson_dollar_project('{"a": [[1, 2], [2, 3], [3, 4]] }', '{"result": {"$reduce": {"input": "$a","initialValue": [],"in": { "$setUnion": ["$$value", "$$this"] }}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select *from bson_dollar_project('{"a": [{ "a": 1 }, { "b": 2 }, { "a": 2 }, { "b": 3 },{ "c": 3 }, { "c": 4 }] }','{"result":{"$reduce": {"input": "$a","initialValue": {},"in":{ "$mergeObjects": ["$$value", "$$this"] }}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "4" } } } (1 row) select *from bson_dollar_project('{"a": [[1, 2], [3, 4], [5, 6]] }','{"result":{"$reduce": {"input": "$a","initialValue": 0,"in":{ "$sum": ["$$value",{ "$avg": "$$this" }] }}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "10.5" } } (1 row) -- $reduce in $addfield stage SELECT documentdb_api.insert_one('db','addFieldReduce','{"_id":"1", "a": ["a", "b", "c"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "addFieldReduce", "pipeline": [ { "$addFields": {"newField": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : [ "a", "b", "c" ], "newField" : "abc" } (1 row) -- $reduce, negative cases select *from bson_dollar_project('{"a": 1}', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }'); ERROR: The input provided to $reduce must be an array, not int select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$reduce": {"input": "$a", "initialValue": 0 }} }'); ERROR: Missing 'in' argument for operator $reduce select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$reduce": {"input": "$a", "in": { "$concat": ["$$value", "$$this"] } }} }'); ERROR: The 'initialValue' parameter required by $reduce is missing. -- $maxN/minN, n too large SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 23 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "3", { "$numberDouble" : "2.2000000000000001776" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 23 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" }, "3" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [1, 2, 3, 5, 7, 9], "n": {"$numberDecimal": "12345678901234567890" } } }}'); ERROR: Conversion would exceed target type limit SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [1, 2, 3, 5, 7, 9], "n": {"$numberDecimal": "12345678901234567890" } } }}'); ERROR: Conversion would exceed target type limit -- $maxN/minN, n short SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "3", { "$numberDouble" : "2.2000000000000001776" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } (1 row) -- $maxN/minN, n == 1 SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 1 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "3" ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 1 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) -- $maxN/minN, n missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"] } }}'); ERROR: Required value for 'n' is not provided SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"] } }}'); ERROR: Required value for 'n' is not provided -- $maxN/minN, input missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": { "n": 1 } }}'); ERROR: No value provided for 'input' SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": { "n": 1 } }}'); ERROR: No value provided for 'input' -- $maxN/minN, n and input missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": { "x": 1 } }}'); ERROR: Unrecognized parameter supplied for 'n' operator: x SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": { "x": 1 } }}'); ERROR: Unrecognized parameter supplied for 'n' operator: x -- $maxN/minN, use input from $d1 SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": "$d1", "n": 23 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1,4,5,6,7,8, 99,99,99,99,99]}', '{"result": { "$maxN": {"input": "$d1", "n": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "99" }, { "$numberInt" : "99" } ] } (1 row) -- $maxN/minN, tests from official jstests SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [null, 2, null, 1], "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [null, 2, null, 1], "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [1, 2, 3, 5, 7, 9], "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [1, 2, 3, 5, 7, 9], "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) --$maxN/minN, nested array SELECT * FROM bson_dollar_project('{"d1": [[1,2,3],[4,5,6],[7,8,9]]}', '{"result": { "$maxN": {"input": "$d1", "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [[1,2,3],[4,5,6],[7,8,9]]}', '{"result": { "$minN": {"input": "$d1", "n": 3 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [[4,5,6],[7,8,9],1,2,3]}', '{"result": { "$maxN": {"input": "$d1", "n": 5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [[7,8,9],[4,5,6],1,2,3]}', '{"result": { "$minN": {"input": "$d1", "n": 5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] ] } (1 row) --$maxN/minN, numberDecimal type array SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "2.23456789" }, { "$numberDecimal" : "1.34256789" }, { "$numberDecimal" : "1.32456789" }, { "$numberDecimal" : "1.23456789" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "1.23456789" }, { "$numberDecimal" : "1.32456789" }, { "$numberDecimal" : "1.34256789" }, { "$numberDecimal" : "2.23456789" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "-1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "2.23456789" }, { "$numberDecimal" : "1.34256789" }, { "$numberDecimal" : "1.23456789" }, { "$numberDecimal" : "-1.32456789" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "-1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "-1.32456789" }, { "$numberDecimal" : "1.23456789" }, { "$numberDecimal" : "1.34256789" }, { "$numberDecimal" : "2.23456789" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "1.34256789" }, { "$numberDecimal" : "1.32456789" }, { "$numberDecimal" : "1.23456789" }, { "$numberDecimal" : "NaN" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "NaN" }, { "$numberDecimal" : "1.23456789" }, { "$numberDecimal" : "1.32456789" }, { "$numberDecimal" : "1.34256789" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" }, 1, 3, -2, null, [3, {"numberDouble": "NaN"}], {"$numberDecimal": "Infinity" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 7 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "3" }, { "numberDouble" : "NaN" } ], { "$numberDecimal" : "Infinity" }, { "$numberInt" : "3" }, { "$numberInt" : "1" }, { "$numberInt" : "-2" }, { "$numberDecimal" : "NaN" } ] } (1 row) SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" }, 1, 3, -2, null, [3, {"numberDouble": "NaN"}], {"$numberDecimal": "Infinity" }]}', '{"result": { "$minN": {"input": "$d1", "n": 7 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberDecimal" : "NaN" }, { "$numberInt" : "-2" }, { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberDecimal" : "Infinity" }, [ { "$numberInt" : "3" }, { "numberDouble" : "NaN" } ] ] } (1 row) -- $sortArray SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[9,7,4,6,8],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[9,7,4,6,8],"sortBy":-1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "9" }, { "$numberInt" : "8" }, { "$numberInt" : "7" }, { "$numberInt" : "6" }, { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":["alpha","delta","charlie","bravo"],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "alpha", "bravo", "charlie", "delta" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":["alpha","delta","charlie","bravo"],"sortBy":-1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "delta", "charlie", "bravo", "alpha" ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[17],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "17" } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[13,2,{"a":"itemA"},4,25,3,"itemB",{"a":null},{"a":{"type":"x","flag":true}},{"$numberDecimal":"6.78"},{"a":"itemC"}],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberDecimal" : "6.78" }, { "$numberInt" : "13" }, { "$numberInt" : "25" }, "itemB", { "a" : null }, { "a" : "itemA" }, { "a" : "itemC" }, { "a" : { "type" : "x", "flag" : true } } ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[[1,9,2],[8,3,5],9,2,7,10,6],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "2" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, [ { "$numberInt" : "1" }, { "$numberInt" : "9" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "8" }, { "$numberInt" : "3" }, { "$numberInt" : "5" } ] ] } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[{"$numberDecimal":"NaN"},3,8,2,10,7,null," "],"sortBy":1}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ null, { "$numberDecimal" : "NaN" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "10" }, " " ] } (1 row) SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"a":1}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "a" : "item1", "b" : { "$numberInt" : "23" }, "c" : { "d" : "value1", "e" : "typeA" } }, { "a" : "item2", "b" : { "$numberInt" : "45" }, "c" : { "d" : "value2", "e" : "typeB" } }, { "a" : "item3", "b" : { "$numberInt" : "31" }, "c" : { "d" : "value3", "e" : "typeC" } } ] } (1 row) SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"a":-1}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "a" : "item3", "b" : { "$numberInt" : "31" }, "c" : { "d" : "value3", "e" : "typeC" } }, { "a" : "item2", "b" : { "$numberInt" : "45" }, "c" : { "d" : "value2", "e" : "typeB" } }, { "a" : "item1", "b" : { "$numberInt" : "23" }, "c" : { "d" : "value1", "e" : "typeA" } } ] } (1 row) SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"c.e":1}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "a" : "item1", "b" : { "$numberInt" : "23" }, "c" : { "d" : "value1", "e" : "typeA" } }, { "a" : "item2", "b" : { "$numberInt" : "45" }, "c" : { "d" : "value2", "e" : "typeB" } }, { "a" : "item3", "b" : { "$numberInt" : "31" }, "c" : { "d" : "value3", "e" : "typeC" } } ] } (1 row) SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"c.e":-1}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "a" : "item3", "b" : { "$numberInt" : "31" }, "c" : { "d" : "value3", "e" : "typeC" } }, { "a" : "item2", "b" : { "$numberInt" : "45" }, "c" : { "d" : "value2", "e" : "typeB" } }, { "a" : "item1", "b" : { "$numberInt" : "23" }, "c" : { "d" : "value1", "e" : "typeA" } } ] } (1 row) SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"b":-1,"a":1}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "a" : "item2", "b" : { "$numberInt" : "45" }, "c" : { "d" : "value2", "e" : "typeB" } }, { "a" : "item3", "b" : { "$numberInt" : "31" }, "c" : { "d" : "value3", "e" : "typeC" } }, { "a" : "item1", "b" : { "$numberInt" : "23" }, "c" : { "d" : "value1", "e" : "typeA" } } ] } (1 row) -- $sortArray, negative cases select *from bson_dollar_project('{}', '{"result": {"$sortArray": null } }'); ERROR: Expected 'document' type for $sortArray but found 'null' type select *from bson_dollar_project('{}', '{"result": {"$sortArray": " " } }'); ERROR: Expected 'document' type for $sortArray but found 'string' type select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": "", "sortBy": 1 } } }'); ERROR: The provided input for the $sortArray operator must be an array, but a value of type string was received instead. select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"sortBy": 1 } } }'); ERROR: $sortArray needs the 'input' parameter to be explicitly provided select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4] } } }'); ERROR: The $sortArray needs the 'sortBy' parameter to be explicitly specified select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": "", "sortBy": 1} } }'); ERROR: The provided input for the $sortArray operator must be an array, but a value of type string was received instead. select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": {}, "sortBy": 1} } }'); ERROR: The provided input for the $sortArray operator must be an array, but a value of type object was received instead. select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortByy": 1} } }'); ERROR: $sortArray encountered an unrecognized argument: sortByy select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": 2} } }'); ERROR: The $sort element value must be either 1 or -1 select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": ""} } }'); ERROR: The $sort is invalid: use 1/-1 to sort the whole element, or {field:1/-1} to sort embedded fields select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": {}} } }'); ERROR: The $sort pattern is empty when it should be a set of fields. -- $zip select *from bson_dollar_project('{"a": [[1, 2, 3], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$a"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "6" } ] ] } (1 row) select *from bson_dollar_project('{"multitypes": [[1, true, {"value": 2}], ["a", [3, 2], "Great"]]}', '{"result": {"$zip": {"inputs": "$multitypes"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "1" }, "a" ], [ true, [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ { "value" : { "$numberInt" : "2" } }, "Great" ] ] } (1 row) select *from bson_dollar_project('{"diffLen": [[ "a", "b" ], [ "b", "c", "d" ]]}', '{"result": {"$zip": {"inputs": "$diffLen"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ "a", "b" ], [ "b", "c" ] ] } (1 row) select *from bson_dollar_project('{"useLongest": [[ 0, 1 ], [ 2, 3, 4, 5 ]]}', '{"result": {"$zip": {"inputs": "$useLongest", "useLongestLength": true} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ null, { "$numberInt" : "4" } ], [ null, { "$numberInt" : "5" } ] ] } (1 row) select *from bson_dollar_project('{"falseUseLongest": [[ 0 ], [ 2, 3 ]]}', '{"result": {"$zip": {"inputs": "$falseUseLongest", "useLongestLength": false} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "2" } ] ] } (1 row) select *from bson_dollar_project('{"withDefaults": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$withDefaults", "useLongestLength": true, "defaults": [ "a", "b", "c" ]} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ "a", { "$numberInt" : "2" }, "c" ] ] } (1 row) select *from bson_dollar_project('{"emptyArray": [[], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$emptyArray"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ ] } (1 row) select *from bson_dollar_project('{"emptyArrayUseLongest": [[], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$emptyArrayUseLongest", "useLongestLength": true} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ null, { "$numberInt" : "4" } ], [ null, { "$numberInt" : "5" } ], [ null, { "$numberInt" : "6" } ] ] } (1 row) select *from bson_dollar_project('{"nullELemArray": [[null, null], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$nullELemArray"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ null, { "$numberInt" : "4" } ], [ null, { "$numberInt" : "5" } ] ] } (1 row) select *from bson_dollar_project('{"withDefaults": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$withDefaults", "useLongestLength": true, "defaults": "$withDefaults"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ [ { "$numberInt" : "0" } ], { "$numberInt" : "2" }, [ { "$numberInt" : "3" } ] ] ] } (1 row) select *from bson_dollar_project('{"array1": [1, 2, 3], "array2": ["a", "b", "c"], "array3": ["x", "y", "z"] }', '{"result": {"$zip": {"inputs": [{ "$zip": { "inputs": ["$array1", "$array2"]}}, "$array3" ]} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ [ [ { "$numberInt" : "1" }, "a" ], "x" ], [ [ { "$numberInt" : "2" }, "b" ], "y" ], [ [ { "$numberInt" : "3" }, "c" ], "z" ] ] } (1 row) -- $zip, negative cases select *from bson_dollar_project('{"a": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$a", "defaults": [ "a", "b", "c" ]} } }'); ERROR: defaults can only be specified when useLongestLength is set to true select *from bson_dollar_project('{"a": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": true, "defaults": [ "a", "b" ]} } }'); ERROR: defaults and inputs are required to be of identical length select *from bson_dollar_project('{"a": []}', '{"result": {"$zip": {"inputs": "$a"} } }'); ERROR: $zip needs at least one provided input array select *from bson_dollar_project('{"a": null}', '{"result": {"$zip": {"inputs": "$a"} } }'); ERROR: Inputs must be provided as an array of expressions, but null was encountered instead. select *from bson_dollar_project('{"a": [1]}', '{"result": {"$zip": {"inputs": "$a"} } }'); ERROR: The $zip encountered an input that is not an array: 1 select *from bson_dollar_project('{"a": [[1,2,3], "anString"]}', '{"result": {"$zip": {"inputs": "$a"} } }'); ERROR: The $zip encountered an input that is not an array: "anString" select *from bson_dollar_project('{"a": [[0], [1, 2]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": 0} } }'); ERROR: useLongestLength must be a boolean value, but a int type was given select *from bson_dollar_project('{"a": [[0], [1, 2]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": true, "defaults": 0} } }'); ERROR: defaults are expected to be provided as an array of expressions, but received int bson_aggregation_bitwise_operators_tests.out000066400000000000000000000305751507310017400411140ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8900000; SET documentdb.next_collection_id TO 8900; SET documentdb.next_collection_index_id TO 8900; -- $bitAnd $bitOr $bitXor $bitNot select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-2" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2.1,3] } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1.8,2,3] } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3.7] } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [1.4] } }'); ERROR: $bitNot supports only int and long types, not: double. select *from bson_dollar_project('{}', '{"result": { "$bitAnd": [{"$numberDecimal": "1.18"},3] } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitOr": [{"$numberDecimal": "1.18"},3] } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitXor": [{"$numberDecimal": "1.18"},3] } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitNot": {"$numberDecimal": "1.18"} } }'); ERROR: $bitNot supports only int and long types, not: decimal. select *from bson_dollar_project('{}', '{"result": { "$bitAnd": [123456789012345678,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "2" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$bitOr": [123456789012345678,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "123456789012345679" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$bitXor": [123456789012345678,3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "123456789012345677" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$bitNot": 123456789012345678 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-123456789012345679" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$bitAnd": 1.3 } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitOr": 1.3 } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitXor": 1.3 } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{}', '{"result": { "$bitNot": 1.3 } }'); ERROR: $bitNot supports only int and long types, not: double. -- $bitAnd $bitOr $bitXor $bitNot, use $array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": "$array" } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": "$array" } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": "$array" } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{"array": [3]}', '{"result": { "$bitNot": "$array" } }'); ERROR: $bitNot works exclusively with numeric data types, not with array select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": ["$array", 4] } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": ["$array",5] } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": ["$array",4] } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{"array": [3]}', '{"result": { "$bitNot": ["$array"] } }'); ERROR: $bitNot works exclusively with numeric data types, not with array select *from bson_dollar_project('{"array": [1,2.1,3]}', '{"result": { "$bitAnd": "$array" } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1.5,2,3]}', '{"result": { "$bitOr": "$array" } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3.4]}', '{"result": { "$bitXor": "$array" } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{"array": [3.1]}', '{"result": { "$bitNot": "$array" } }'); ERROR: $bitNot works exclusively with numeric data types, not with array -- $bitAnd $bitOr $bitXor $bitNot, null in array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [2,3,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [2,3,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [2,3,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [2,3,null] } }'); ERROR: The expression $bitNot requires exactly 1 arguments, but 3 arguments were actually provided. -- $bitAnd $bitOr $bitXor $bitNot, null array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [] } }'); ERROR: The expression $bitNot requires exactly 1 arguments, but 0 arguments were actually provided. -- $bitAnd $bitOr $bitXor $bitNot, nested array select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,3,[1,2]] } }'); ERROR: $bitAnd can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,3,[3,4]] } }'); ERROR: $bitOr can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3,[5,6]] } }'); ERROR: $bitXor can only be used with int and long type operands. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [[1]] } }'); ERROR: $bitNot works exclusively with numeric data types, not with array -- $bitAnd $bitOr $bitXor $bitNot, dotted path tests SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitAnd": ["$array.b",3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitOr": ["$array.b",3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitXor": ["$array.b",3]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitNot": "$array.b"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-2" } } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [null] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,"$undefined"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,"$undefined"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,"$undefined"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": ["$undefined"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,"$undefinedPath"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,"$undefinedPath"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,"$undefinedPath"] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": ["$undefinedPath"]} }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) bson_aggregation_boolean_operators_tests.out000066400000000000000000000527331507310017400410650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5500000; SET documentdb.next_collection_id TO 5500; SET documentdb.next_collection_index_id TO 5500; -- $and operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": true}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": { }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": "str"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": []}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, 1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, 0.1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, {"$numberDecimal": "0.1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, { }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, [ ]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, [ 1, 2]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": true, "b": true, "c": true}', '{"result": { "$and": ["$a", "$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": true}}', '{"result": { "$and": ["$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [{"$add": [0, 1]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": false}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [0.1, false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, {"$numberDecimal": "0.1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": true, "b": true, "c": false}', '{"result": { "$and": ["$a", "$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": false}}', '{"result": { "$and": ["$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [{"$add": [0, 0]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- If nested expression parses to a constant that evaluates to an error, the error from the nested expression will be thrown. SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [false, {"$divide": [1, 0]}, "$a.c"]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [false, "$a.c", {"$subtract": [1, {"$date": {"$numberLong": "11232"}}]}]}}'); ERROR: can't $subtract date from int SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$and": [{"$add": [0, 1]}, "$a.c", {"$not": [1,2]}]}}'); ERROR: The expression $not requires exactly 1 arguments, but 2 arguments were actually provided. -- If nested expression parses to a non-constant (eg: path) that eventually evaluates to an error, shortcircuit evaluation will occur. SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$and": [false, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$and": [true, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); ERROR: $divide by zero is not allowed -- $or operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": true}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": -23.453}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": { "$numberDecimal": "-0.4" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": { }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": "str"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false, true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, 0.1]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, {"$numberDecimal": "0.1"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, { }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, [ ]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [[ 1, 2], true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [null, true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": true, "b": false, "c": true}', '{"result": { "$or": ["$a", "$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": true}}', '{"result": { "$or": ["$z", "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 1]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": false}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": "$z"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": []}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false, 0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, 0.0]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, {"$numberDecimal": "0.0"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, "$d"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [null, false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": false, "b": false, "c": false}', '{"result": { "$or": ["$a", "$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": { "b": false, "c": false}}', '{"result": { "$or": ["$z", "$a.b", "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 0]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- If nested expression parses to a constant that evaluates to an error should get that error. SELECT * FROM bson_dollar_project('{"a": false, "b": false, "c": false}', '{"result": { "$or": ["$a", "$b", "$c", {"$divide": []}]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$or": [false, {"$divide": [1, 0]}, "$a.c"]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$or": [false, "$a.c", {"$subtract": [1, {"$date": {"$numberLong": "11232"}}]}]}}'); ERROR: can't $subtract date from int SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 1]}, "$a.c", {"$not": [1,2]}]}}'); ERROR: The expression $not requires exactly 1 arguments, but 2 arguments were actually provided. -- If nested expression parses to a non-constant should error. SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$or": [true, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$or": [false, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); ERROR: $divide by zero is not allowed -- $not operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": false}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$numberDecimal": "0"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": ["$z"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$and": [false, true]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$or": [false, false]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": false}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.0}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": true}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": -1.23}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$numberDecimal": "-0.3"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": ["str"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$and": [true, true]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$or": [false, true]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.1}', '{"result": { "$not": ["$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- should return error for wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": []}}'); ERROR: The expression $not requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true, false]}}'); ERROR: The expression $not requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true, false, 2, 3]}}'); ERROR: The expression $not requires exactly 1 arguments, but 4 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [{"$divide": [1, 0]}, false, 2, 3]}}'); ERROR: The expression $not requires exactly 1 arguments, but 4 arguments were actually provided. bson_aggregation_comparison_operators_tests.out000066400000000000000000002067331507310017400416210ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5700000; SET documentdb.next_collection_id TO 5700; SET documentdb.next_collection_index_id TO 5700; SET client_min_messages TO DEBUG3; -- $cmp -- should return 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [1, 1]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [-1, -1]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, null]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$cmp": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", "str"]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [true, true]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cmp": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$cmp": [{"$literal": "$a"}, "$a.b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) -- should return 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, 1]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0, -1]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", null]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", "s"]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [true, false]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00001, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$cmp": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$cmp": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$cmp": [{"b": "$a"}, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) -- should return -1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [1, 2]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [-1, 0]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, "str"]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["string", "stringa"]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["String", "string"]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [false, true]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [{"$numberDouble": "NaN"}, 0.00001]}}'); DEBUG: Precomputed bson $cmp operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$cmp": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [3, 2, 3, 4]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$cmp": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "-1" } } (1 row) -- $eq operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [1, 1]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [-1, -1]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [null, null]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$eq": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", "str"]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [true, true]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$eq": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$eq": [{"$literal": "$a"}, "$a.b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [2, 1]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0, -1]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", null]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", "s"]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [true, false]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["string", "stringa"]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["String", "string"]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [false, true]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$numberDouble": "NaN"}, 0.00001]}}'); DEBUG: Precomputed bson $eq operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$eq": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$eq": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$eq": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$eq": [{"b": "$a"}, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $ne operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [2, 1]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0, -1]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", null]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", "s"]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [true, false]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["string", "stringa"]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["String", "string"]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [false, true]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$numberDouble": "NaN"}, 0.00001]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$ne": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$ne": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$ne": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$ne": [{"b": "$a"}, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [1, 1]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [-1, -1]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [null, null]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$ne": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", "str"]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [true, true]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $ne operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$ne": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$ne": [{"$literal": "$a"}, "$a.b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $gt operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [2, 1]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0, -1]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", null]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", "s"]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [true, false]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.1, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$gt": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$gt": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [-1, -1]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, null]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$gt": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", "str"]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [true, true]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [{"$numberDouble": "NaN"}, 0.1]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, "str"]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["string", "stringa"]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["String", "string"]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [false, true]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $gt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$gt": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$gt": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $gte operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [2, 1]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0, -1]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", null]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", "s"]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [true, false]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [-1, -1]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, null]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$gte": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", "str"]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.1, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [true, true]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$gte": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$gte": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$gte": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, "str"]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["string", "stringa"]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["String", "string"]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [false, true]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$numberDouble": "NaN"}, 0.1]}}'); DEBUG: Precomputed bson $gte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$gte": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $lt operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [1, 2]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [-1, 0]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, "str"]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["string", "stringa"]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["String", "string"]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [false, true]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [{"$numberDouble": "NaN"}, 0.1]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$lt": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [3, 2, 3, 4]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lt": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [2, 1]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0, -1]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", null]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", "s"]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [true, false]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [-1, -1]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, null]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$lt": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", "str"]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [true, true]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.1, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $lt operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$lt": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lt": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$lt": ["$a", {}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $lte operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [1, 2]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [-1, 0]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, "str"]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["string", "stringa"]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["String", "string"]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [false, true]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.00001, 0.0001]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [-1, -1]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, null]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$lte": ["$a", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", "str"]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.00002, 0.00002]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [true, true]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$lte": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 4, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [3, 2, 3, 4]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lte": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [2, 1]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0, -1]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, "$a"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", null]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", "s"]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [true, false]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.0001, 0.00001]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.1, {"$numberDouble": "NaN"}]}}'); DEBUG: Precomputed bson $lte operator for constant comparison. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$lte": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 3, 5]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3]]}}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lte": ["$a", {"b": 1, "c": 1}]}}'); DEBUG: Converting document expression into a fixed constant. bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- should error for wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, 3, 2]}}'); ERROR: The expression $cmp requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [2]}}'); ERROR: The expression $eq requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": []}}'); ERROR: The expression $ne requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": 2}}'); ERROR: The expression $gt requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [1, 2, 3, 4, 5]}}'); ERROR: The expression $gte requires exactly 2 arguments, but 5 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [2, 1, 0]}}'); ERROR: The expression $lt requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [1]}}'); ERROR: The expression $lte requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$divide": [1, 0]}]}}'); ERROR: The expression $lte requires exactly 2 arguments, but 1 arguments were actually provided. -- should error if there is an error in nested expressions SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, {"$subtract": [1, {"$date": { "$numberLong": "1" }}]}]}}'); ERROR: can't $subtract date from int SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$divide": [1, 0]}, 2]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$not": []}, 3]}}'); ERROR: The expression $not requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [{"$in": [1, 2]}, 2]}}'); ERROR: Expected 'array' type for $in operator but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$divide": [1, 0, 3]}, 2]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [{"$divide": [1, 0, {"$not": []}]}, 2]}}'); ERROR: The expression $divide requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$add": [{"$date": { "$numberLong": "1" }}, {"$date": { "$numberLong": "1" }}]}, 3]}}'); ERROR: Only a single date value is permitted within an $add operators expression. bson_aggregation_conditional_operators_tests.out000066400000000000000000000566411507310017400417530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5800000; SET documentdb.next_collection_id TO 5800; SET documentdb.next_collection_index_id TO 5800; -- $ifNull: should return first not null SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": ["not null", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "not null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "not null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, null, "not null"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "not null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [{"$arrayElemAt": [[1], 2]}, "not null", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "not null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", "not null", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "not null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", {"$add":[1,2]}, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", [1, 2, {"$add":[1,2]}], null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project('{"b": 2}', '{"result": {"$ifNull": [null, "$a", "$b", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } (1 row) -- $ifNull: should not return result if last expression is undefined field or an expression with no result SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, null, {"$arrayElemAt": [[1], 2]}]}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- $ifNull: should have at least 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": {}}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": "string"}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": false}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": []}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 0. SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null]}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [{"$divide": [1, 0]}]}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. -- $ifNull: should honor nested expression errors, even if a not null expression is found SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", {"$divide": [1, 0]}]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", {"$ifNull": [1]}]}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 1. -- $cond: returns then when condition is true SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$gt": [3, 2]}, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$lt": [2, 3]}, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{"b": true}', '{"result": {"$cond": ["$b", "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "else": "else", "then": "then" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "if": true, "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "if": true, "then": "then"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 2]}, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$lt": [2, 3]}, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) SELECT * FROM bson_dollar_project('{"b": true}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "then" } (1 row) -- $cond: returns else when condition is false SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$gt": [3, 3]}, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$lt": [3, 3]}, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": ["$b", "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": ["$b", "then", {"$add": [1, 2]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 3]}, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$lt": [3, 3]}, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": [1, 2, {"$add": [1, 2]}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) -- $cond: null/undefined conditions should evaluate to false and return else SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [null, "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": ["$a", "then", "else"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": null, "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "$a", "then": "then", "else": "else"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "else" } (1 row) -- $cond: returns no result when the returned expression is an undefined field or an expression with no result SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "$a"}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 3]}, "then": "then", "else": {"$ifNull": [null, null, {"$arrayElemAt": [[1], 2]}]}}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- $cond: if is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "else": "$a"}}}'); ERROR: 'if' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "then": "$a"}}}'); ERROR: 'if' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else"}}}'); ERROR: 'if' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {}}}'); ERROR: 'if' parameter is missing in the $cond operator -- $cond: then is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "if", "else": "$a"}}}'); ERROR: 'then' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "if": "$a"}}}'); ERROR: 'then' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "$a"}}}'); ERROR: 'then' parameter is missing in the $cond operator -- $cond: else is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "if", "then": "$a"}}}'); ERROR: 'else' parameter is missing in the $cond operator SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "if": "$a"}}}'); ERROR: 'else' parameter is missing in the $cond operator -- $cond: unknown argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "$a", "foo": "blah"}}}'); ERROR: Unrecognized argument provided to operators $cond: foo SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"foo": "blah"}}}'); ERROR: Unrecognized argument provided to operators $cond: foo -- $cond: requires 3 arguments error SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, "else"]}}'); ERROR: The expression $cond requires exactly 3 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": []}}'); ERROR: The expression $cond requires exactly 3 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, true, true, true, true]}}'); ERROR: The expression $cond requires exactly 3 arguments, but 5 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": "str"}}'); ERROR: The expression $cond requires exactly 3 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": true}}'); ERROR: The expression $cond requires exactly 3 arguments, but 1 arguments were actually provided. -- $cond: nested expression errors honored even if result is not affected by it SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, {"$divide": [1, 0]}, "else"]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, "then", {"$divide": [1, 0]}]}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": {"$divide": [1, 0]}, "else": "else"}}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "then": "then", "else": {"$divide": [1, 0]}}}}'); ERROR: $divide by zero is not allowed -- $switch: returns expected branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "first branch is true" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": true, "then": "second branch is true"}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "second branch is true" } (1 row) SELECT * FROM bson_dollar_project('{"a": 1, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$lt": ["$a", "$b"]}, "then": "a < b"}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "a < b" } (1 row) SELECT * FROM bson_dollar_project('{"a": 3, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$lt": ["$a", "$b"]}, "then": "a < b"}], "default": "a = b"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "a > b" } (1 row) SELECT * FROM bson_dollar_project('{"a": 2, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$not": {"$eq": ["$a", "$b"]}}, "then": "a != b"}], "default": "a = b"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "a = b" } (1 row) SELECT * FROM bson_dollar_project('{"a": 0, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$not": {"$eq": ["$a", "$b"]}}, "then": "a != b"}], "default": "a = b"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "a != b" } (1 row) -- $switch: null/undefined should evaluate to false SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": null, "then": "first branch is true"}], "default": "it was false"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "it was false" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": "$a", "then": "first branch is true"}], "default": "it was false"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "it was false" } (1 row) -- $switch: shouldn't return result if resulting expression is undefined field or expression with undef result SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "$b"}]}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": {"$arrayElemAt": [[1], 2]}}]}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": ""}], "default": {"$arrayElemAt": [[1], 2]}}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- $switch: requires object argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": []}}'); ERROR: The $switch expression requires an object as its argument, but instead received: array SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": true}}'); ERROR: The $switch expression requires an object as its argument, but instead received: bool SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": "Str"}}'); ERROR: The $switch expression requires an object as its argument, but instead received: string -- $switch: branches must be an array SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": {}}}}'); ERROR: $switch requires an array for 'branches', but received: object SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": "true"}}}'); ERROR: $switch requires an array for 'branches', but received: string SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": false}}}'); ERROR: $switch requires an array for 'branches', but received: bool -- $switch: found an unknown argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [], "foo": "blah"}}}'); ERROR: Unknown argument: foo SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"foo": "blah", "branches": {}}}}'); ERROR: Unknown argument: foo -- $switch: requires at least one branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": []}}}'); ERROR: $switch must contain at least one branch. -- $switch: default is required only when there is no matching branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}]}}}'); ERROR: The $switch operator failed to locate a matching branch for the provided input, and no default branch was defined. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"case": null, "then": "it is null"}]}}}'); ERROR: The $switch operator failed to locate a matching branch for the provided input, and no default branch was defined. -- $switch: found unknown argument to a branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"foo": "blah"}]}}}'); ERROR: $switch encountered an unrecognized argument for a branch: foo -- $switch: branch requires a case expression SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"then": "blah"}]}}}'); ERROR: The $switch requires that every branch must contain a valid 'case' expression. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {}]}}}'); ERROR: The $switch requires that every branch must contain a valid 'case' expression. -- $switch: branch requires a then expression SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"case": "blah"}]}}}'); ERROR: The $switch requires that every branch must contain a valid 'then' expression. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false}]}}}'); ERROR: The $switch requires that every branch must contain a valid 'then' expression. -- Fails for constant error expressions SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": {"$ifNull": []}}]}}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 0. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": "false"}], "default": {"$ifNull": []}}}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 0. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": false, "then": "false"}], "default": {"$ifNull": []}}}}'); ERROR: Expression $ifNull requires at least two provided arguments, but received only 0. SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": {"$divide": [1, 0]}, "then": "false"}], "default": {"$ifNull": []}}}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": {"$divide": [1, 0]}, "then": "false"}], "default": {"$ifNull": []}}}}'); ERROR: $divide by zero is not allowed -- Fail for non-constant error branch expressions (eg: paths) if that branch is matched SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": true, "then": {"$divide": [1, "$a"]}}]}}}'); ERROR: $divide by zero is not allowed -- Does not fail for non-constant error expressions (eg: paths) if a valid branch is found SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": {"$divide": [1, "$a"]}}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "first branch is true" } (1 row) -- Does not fail for non-constant branch error expressions (eg: paths) if the default expression is matched. SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": false, "then": {"$divide": [1, "$a"]}}], "default": "I am the default"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "I am the default" } (1 row) bson_aggregation_cursor_tests.out000066400000000000000000012055121507310017400366610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, public; SET citus.next_shard_id TO 3120000; SET documentdb.next_collection_id TO 3120; SET documentdb.next_collection_index_id TO 3120; SET citus.multi_shard_modify_mode TO 'sequential'; CREATE SCHEMA aggregation_cursor_test; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }', i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection CREATE TYPE aggregation_cursor_test.drain_result AS (filteredDoc bson, docSize int, continuationFiltered bson, persistConnection bool); CREATE FUNCTION aggregation_cursor_test.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL, sort bson DEFAULT NULL, filter bson default null, obfuscate_id bool DEFAULT false) RETURNS SETOF aggregation_cursor_test.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; BEGIN WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "find", filter AS "filter", sort AS "sort", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; CREATE FUNCTION aggregation_cursor_test.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, obfuscate_id bool DEFAULT false, singleBatch bool DEFAULT NULL) RETURNS SETOF aggregation_cursor_test.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'get_aggregation_cursor_test' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- STREAMING BASED: -- test getting the first page (with max page size) - should limit to 2 docs at a time. SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (7 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (7 rows) -- test smaller docs (500KB) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "10" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 6000348 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "10" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 6000348 | | f | | | f | | | f (3 rows) -- test smaller batch size(s) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 0, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 600123 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "1" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f | | | f | | | f (13 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 2, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "2" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "2" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "2" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "2" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 3, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800173 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "3" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "3" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "projection" : { "a" : { "$numberInt" : "1" } }, "batchSize" : { "$numberInt" : "3" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 0, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 600123 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | 600122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f | | | f | | | f (13 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "2" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "2" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "2" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "2" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800173 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$skip": 0 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800173 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } }, { "$skip" : { "$numberInt" : "0" } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } }, { "$skip" : { "$numberInt" : "0" } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } }, { "$skip" : { "$numberInt" : "0" } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f (5 rows) -- test singleBatch SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}', singleBatch => TRUE); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800173 | | f | | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}', singleBatch => FALSE); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800173 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" }, "singleBatch" : false } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" }, "singleBatch" : false } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800172 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$project" : { "a" : { "$numberInt" : "1" } } } ], "cursor" : { "batchSize" : { "$numberInt" : "3" }, "singleBatch" : false } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600122 | | f | | | f (5 rows) -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', skipVal => 0, limitVal => 0); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "skip" : { "$numberInt" : "0" }, "limit" : { "$numberInt" : "0" }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "skip" : { "$numberInt" : "0" }, "limit" : { "$numberInt" : "0" }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "skip" : { "$numberInt" : "0" }, "limit" : { "$numberInt" : "0" }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654033 | | f | | | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 1200131 | | t | | | f (2 rows) BEGIN; SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) ROLLBACK; -- inside a transaction block BEGIN; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) ROLLBACK; -- With local execution off. BEGIN; set local citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120007" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) ROLLBACK; -- with sharded SELECT documentdb_api.shard_collection('db', 'get_aggregation_cursor_test', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" }, { "table_name" : "documents_3120_3120022" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (7 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" }, { "table_name" : "documents_3120_3120022" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (7 rows) -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "8" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "3" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) -- inside a transaction block BEGIN; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "8" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "3" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 1200147 | | f | | | f (6 rows) ROLLBACK; -- With local execution off. BEGIN; set local citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3120_3120018" }, { "table_name" : "documents_3120_3120021" }, { "table_name" : "documents_3120_3120019" }, { "table_name" : "documents_3120_3120017" }, { "table_name" : "documents_3120_3120016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654032 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654033 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 98 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 97 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307968 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307967 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200148 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200147 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200147 | | f | | | f (6 rows) ROLLBACK; -- test for errors when returnKey is set to true SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "returnKey" : true, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); ERROR: The key returnKey is currently not supported -- test for no errors when returnKey is set to false SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "returnKey" : false, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.movies", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test for errors when returnKey and showRecordId are set to true SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "showRecordId": true, "returnKey" : true, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); ERROR: The key showRecordId is currently not supported -- test for ntoreturn in find command with unset documentdb.version SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "limit" : 1, "batchSize" : 1, "ntoreturn":1 ,"$db" : "test" }'); ERROR: 'limit' or 'batchSize' fields can not be set with 'ntoreturn' field SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 ,"$db" : "test" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.movies", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 , "batchSize":1, "$db" : "test" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.movies", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 , "limit":1, "$db" : "test" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.movies", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test $limit for large docs, even when batch size is enough to fit all limited docs, the response size should enforce persisted cursors for $limit SELECT 1 FROM drop_collection('db','get_aggregation_cursor_test'); ?column? --------------------------------------------------------------------- 1 (1 row) DO $$ DECLARE i int; BEGIN -- each doc is ~16MB FOR i IN 1..5 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test', FORMAT('{ "_id": %s, "a": "%s" }', i, repeat('a', 16777000))::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 10, limitVal => 5); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 16777123 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 16777122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 16777122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 16777122 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | 16777122 | | f | | | f (6 rows) bson_aggregation_data_size_operators_tests.out000066400000000000000000000223641507310017400414060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8500000; SET documentdb.next_collection_id TO 8500; SET documentdb.next_collection_index_id TO 8500; -- $bsonSize operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"x":1} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [{"a":1}] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"$undefined":true} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"x":1 , "b": 5, "c": {"$numberLong": "10"} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "30" } } (1 row) -- $bsonSize operator , large size documents SELECT * FROM bson_dollar_project(('{"input" : "' || LPAD('', 16000000, 'a') || '"}')::bson, '{"result": { "$bsonSize": "$$ROOT" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "16000017" } } (1 row) -- $bsonSize operator , document based tests SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$$ROOT" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$ROOT" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "27" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$ROOT.b" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$$CURRENT" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$CURRENT" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "27" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$CURRENT.b" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) -- $bsonSize operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [1,2] }}'); ERROR: The expression $bsonSize requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [1] }}'); ERROR: Expected 'document' type for $bsonSize but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": 11 }}'); ERROR: Expected 'document' type for $bsonSize but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": true }}'); ERROR: Expected 'document' type for $bsonSize but found 'bool' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": "12absd" }}'); ERROR: Expected 'document' type for $bsonSize but found 'string' type SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$a" }}'); ERROR: Expected 'document' type for $bsonSize but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"$regex": "a*b", "$options":""} }}'); ERROR: Expected 'document' type for $bsonSize but found 'regex' type -- $binarySize operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": null }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$undefined":true} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "abvd" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "hello!" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "6" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "abc\\0c" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "6" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "I â¤ï¸ documentdb" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "19" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "🙈" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "アユシュ・サルージャã§ã™"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "36" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "7" } } (1 row) -- $binarySize operator , large size documents SELECT * FROM bson_dollar_project(('{"input" : "' || LPAD('', 16000000, 'a') || '"}')::bson, '{"result": { "$binarySize": "$input" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "16000000" } } (1 row) -- $binarySize operator , document based tests SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$binarySize": "$a" }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: int SELECT * FROM bson_dollar_project('{"a":"temp", "b":{"a":12} }', '{"result": { "$binarySize": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":"world!"} }', '{"result": { "$binarySize": "$b.a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "6" } } (1 row) -- $binarySize operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": [1,2] }}'); ERROR: The expression $binarySize requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": [1] }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": 11 }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": true }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: bool SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$binarySize": "$a" }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$regex": "a*b", "$options":""} }}'); ERROR: The $binarySize operator expects either a string or BinData argument, but received: regex bson_aggregation_date_operators_tests.out000066400000000000000000007667321507310017400403760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5900000; SET documentdb.next_collection_id TO 5900; SET documentdb.next_collection_index_id TO 5900; -- $hour, $minute, $second, $millisecond: simple SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T07:30:10.5Z"}}', '{"hour": {"$hour": "$date"}, "minute": {"$minute": "$date"}, "second": {"$second": "$date"}, "ms": {"$millisecond": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "7" }, "minute" : { "$numberInt" : "30" }, "second" : { "$numberInt" : "10" }, "ms" : { "$numberInt" : "500" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T10:30:10.5Z"}}', '{"hour": {"$hour": [ "$date" ]}, "minute": {"$minute": [ "$date" ]}, "second": {"$second": [ "$date" ]}, "ms": {"$millisecond": [ "$date" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "10" }, "minute" : { "$numberInt" : "30" }, "second" : { "$numberInt" : "10" }, "ms" : { "$numberInt" : "500" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T23:59:59.28Z"}}', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "23" }, "minute" : { "$numberInt" : "59" }, "second" : { "$numberInt" : "59" }, "ms" : { "$numberInt" : "280" } } (1 row) -- 2022-12-14T01:28:46.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "639926cee6bda3127f153bf1" } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "1" }, "minute" : { "$numberInt" : "28" }, "second" : { "$numberInt" : "46" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$timestamp" : { "t": 1670981326, "i": 1 } } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "1" }, "minute" : { "$numberInt" : "28" }, "second" : { "$numberInt" : "46" }, "ms" : { "$numberInt" : "0" } } (1 row) -- 2022-12-14T01:31:47.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "63992783f5e4d92817ef6ccc" } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "1" }, "minute" : { "$numberInt" : "31" }, "second" : { "$numberInt" : "47" }, "ms" : { "$numberInt" : "0" } } (1 row) -- $hour, $minute, $second, $millisecond: with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+08:05"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "8" }, "minute" : { "$numberInt" : "5" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:00.001Z"}, "tz": "-08:05"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "55" }, "second" : { "$numberInt" : "0" }, "ms" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-08"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "16" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-0801"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "59" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.020Z"}, "tz": "+1210"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "12" }, "minute" : { "$numberInt" : "10" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "20" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "UTC"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "0" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+00"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "0" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+0000"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "0" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-00:00"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "0" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "0" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "16" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "201" } } (1 row) -- should observe daylight savings or not SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-06-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "17" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "201" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-12-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : { "$numberInt" : "16" }, "minute" : { "$numberInt" : "0" }, "second" : { "$numberInt" : "1" }, "ms" : { "$numberInt" : "201" } } (1 row) -- $year, $month, $dayOfMonth: simple SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "month": {"$month": "$date"}, "dayOfMonth": {"$dayOfMonth": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2005" }, "month" : { "$numberInt" : "1" }, "dayOfMonth" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2999-02-28T10:30:10.5Z"}}', '{"year": {"$year": [ "$date" ]}, "month": {"$month": [ "$date" ]}, "dayOfMonth": {"$dayOfMonth": [ "$date" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2999" }, "month" : { "$numberInt" : "2" }, "dayOfMonth" : { "$numberInt" : "28" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T23:59:59.28Z"}}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1930" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "31" } } (1 row) -- 2022-12-14T01:28:46.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "639926cee6bda3127f153bf1" }}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2022" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "14" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$timestamp" : { "t": 1670981326, "i": 1 } }}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2022" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "14" } } (1 row) -- $year, $month, $dayOfMonth: with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T23:59:59.28Z"}, "tz": "+01"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1931" }, "month" : { "$numberInt" : "1" }, "dayOfMonth" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "+12"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1930" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "31" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "+12:01"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1931" }, "month" : { "$numberInt" : "1" }, "dayOfMonth" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "-1159"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1930" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "31" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "-12"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "1930" }, "month" : { "$numberInt" : "12" }, "dayOfMonth" : { "$numberInt" : "30" } } (1 row) -- $week and $isoWeek -- $week range is 0-53, weeks are from Sunday-Saturday. -- $isoWeek ranges is 1-53, weeks are Monday-Sunday. -- 2023-01-01 is first Sunday of the year. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"week": {"$week": "$date"}, "isoWeek": {"$isoWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "week" : { "$numberInt" : "1" }, "isoWeek" : { "$numberInt" : "52" } } (1 row) -- 2023-01-08 is second Sunday of the year. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-08T07:30:10.5Z"}}', '{"week": {"$week": "$date"}, "isoWeek": {"$isoWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "week" : { "$numberInt" : "2" }, "isoWeek" : { "$numberInt" : "1" } } (1 row) -- 2022-01-01 is Saturday SELECT * FROM bson_dollar_project('{"date": {"$date": "2022-01-01T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date"}}, "isoWeek": {"$isoWeek": { "date": "$date"}}}'); bson_dollar_project --------------------------------------------------------------------- { "week" : { "$numberInt" : "0" }, "isoWeek" : { "$numberInt" : "52" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2022-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); bson_dollar_project --------------------------------------------------------------------- { "week" : [ { "$numberInt" : "52" } ], "isoWeek" : [ { "$numberInt" : "52" } ] } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); bson_dollar_project --------------------------------------------------------------------- { "week" : [ { "$numberInt" : "53" } ], "isoWeek" : [ { "$numberInt" : "1" } ] } (1 row) -- $week and $isoWeek: leap year SELECT * FROM bson_dollar_project('{"date": {"$date": "2020-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); bson_dollar_project --------------------------------------------------------------------- { "week" : [ { "$numberInt" : "52" } ], "isoWeek" : [ { "$numberInt" : "53" } ] } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2000-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); bson_dollar_project --------------------------------------------------------------------- { "week" : [ { "$numberInt" : "53" } ], "isoWeek" : [ { "$numberInt" : "52" } ] } (1 row) -- $dayOfYear SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfYear" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-31T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": [ "$date" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfYear" : { "$numberInt" : "31" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-02-28T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfYear" : { "$numberInt" : "59" } } (1 row) -- $dayOfYear: leap year should add 1 day SELECT * FROM bson_dollar_project('{"leapDate": {"$date": "2024-03-01T07:30:10.5Z"}, "nonLeapDate": {"$date": "2023-03-01T07:30:10.5Z"}}', '{"leapDayOfYear": {"$dayOfYear": { "date": "$leapDate" }}, "nonLeapDayOfYear": {"$dayOfYear": { "date": "$nonLeapDate" }}}'); bson_dollar_project --------------------------------------------------------------------- { "leapDayOfYear" : { "$numberInt" : "61" }, "nonLeapDayOfYear" : { "$numberInt" : "60" } } (1 row) SELECT * FROM bson_dollar_project('{"leapDate": {"$date": "2024-12-31T07:30:10.5Z"}, "nonLeapDate": {"$date": "2023-12-31T07:30:10.5Z"}}', '{"leapDayOfYear": {"$dayOfYear": { "date": "$leapDate" }}, "nonLeapDayOfYear": {"$dayOfYear": { "date": "$nonLeapDate" }}}'); bson_dollar_project --------------------------------------------------------------------- { "leapDayOfYear" : { "$numberInt" : "366" }, "nonLeapDayOfYear" : { "$numberInt" : "365" } } (1 row) -- $dayOfWeek and $isoDayOfWeek both are 1-7 following $week or $isoWeek. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"name": "Sunday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Sunday", "dayOfWeek" : { "$numberInt" : "1" }, "isoDayOfWeek" : { "$numberInt" : "7" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-02T07:30:10.5Z"}}', '{"name": "Monday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Monday", "dayOfWeek" : { "$numberInt" : "2" }, "isoDayOfWeek" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1999-02-02T07:30:10.5Z"}}', '{"name": "Tuesday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Tuesday", "dayOfWeek" : { "$numberInt" : "3" }, "isoDayOfWeek" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-03-15T07:30:10.5Z"}}', '{"name": "Wednesday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Wednesday", "dayOfWeek" : { "$numberInt" : "4" }, "isoDayOfWeek" : { "$numberInt" : "3" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-11-29T07:30:10.5Z"}}', '{"name": "Thursday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Thursday", "dayOfWeek" : { "$numberInt" : "5" }, "isoDayOfWeek" : { "$numberInt" : "4" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2028-05-19T07:30:10.5Z"}}', '{"name": "Friday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Friday", "dayOfWeek" : { "$numberInt" : "6" }, "isoDayOfWeek" : { "$numberInt" : "5" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"name": "Saturday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "name" : "Saturday", "dayOfWeek" : { "$numberInt" : "7" }, "isoDayOfWeek" : { "$numberInt" : "6" } } (1 row) -- $year and $isoWeekYear SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2023" }, "isoWeekYear" : { "$numberLong" : "2022" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2006-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2006" }, "isoWeekYear" : { "$numberLong" : "2005" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2006-01-02T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2006" }, "isoWeekYear" : { "$numberLong" : "2006" } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2012" }, "isoWeekYear" : { "$numberLong" : "2013" } } (1 row) -- date part operators with nested operators -- add 1 year to the date. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"year": {"$year": { "$add": ["$date", {"$numberLong": "31540000000"}]}}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : { "$numberInt" : "2024" } } (1 row) -- date part operators, null/undefined date or timezone, should return null. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": null}}'); bson_dollar_project --------------------------------------------------------------------- { "year" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": [ null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "month" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"date": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfMonth" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"date": "$a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfYear" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": null }}}'); bson_dollar_project --------------------------------------------------------------------- { "dayOfWeek" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": [ "$a" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "hour" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "minute" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": [ null ]}}'); bson_dollar_project --------------------------------------------------------------------- { "second" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "millisecond" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "week" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": null }}}'); bson_dollar_project --------------------------------------------------------------------- { "isoWeekYear" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "isoDayOfWeek" : null } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": "$a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "isoWeek" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": "$timezone"}}}'); bson_dollar_project --------------------------------------------------------------------- { "isoWeek" : null } (1 row) -- negative tests for date part operators -- -- date part operators: date expression should be convertible to date: timestamp, object id or date time. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": "str"}}'); ERROR: can't convert from BSON type string to Date SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": true}}'); ERROR: can't convert from BSON type bool to Date SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": false}}'); ERROR: can't convert from BSON type bool to Date SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": false}}'); ERROR: can't convert from BSON type bool to Date SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": "str"}}'); ERROR: can't convert from BSON type string to Date SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": 1}}'); ERROR: can't convert from BSON type int to Date SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": 1}}'); ERROR: can't convert from BSON type int to Date SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": 1}}'); ERROR: can't convert from BSON type int to Date SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": 1}}'); ERROR: can't convert from BSON type int to Date SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": [[]]}}'); ERROR: can't convert from BSON type array to Date SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": [[]]}}'); ERROR: can't convert from BSON type array to Date SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": {}}}}'); ERROR: can't convert from BSON type object to Date SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": []}}}'); ERROR: can't convert from BSON type array to Date SELECT * FROM bson_dollar_project('{"date": {"date": {"$date": "2012-12-31T07:30:10.5Z"} }}', '{"isoWeek": {"$isoWeek": "$date"}}'); ERROR: can't convert from BSON type object to Date -- date part operators: timezone argument should be string SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": true}}}'); ERROR: $year requires a string for the timezone argument, but was given a bool (true) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"month": {"$month": {"date": "$date", "timezone": false}}}'); ERROR: $month requires a string for the timezone argument, but was given a bool (false) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfMonth": {"$dayOfMonth": {"date": "$date", "timezone": []}}}'); ERROR: $dayOfMonth requires a string for the timezone argument, but was given a array ([ ]) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": {"date": "$date", "timezone": 1}}}'); ERROR: $dayOfYear requires a string for the timezone argument, but was given a int (1) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfWeek": {"$dayOfWeek": {"date": "$date", "timezone": {}}}}'); ERROR: $dayOfWeek requires a string for the timezone argument, but was given a object ({ }) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"hour": {"$hour": {"date": "$date", "timezone": false}}}'); ERROR: $hour requires a string for the timezone argument, but was given a bool (false) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"minute": {"$minute": {"date": "$date", "timezone": [[[]]]}}}'); ERROR: $minute requires a string for the timezone argument, but was given a array ([ [ [ ] ] ]) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"second": {"$second": {"date": "$date", "timezone": {}}}}'); ERROR: $second requires a string for the timezone argument, but was given a object ({ }) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"millisecond": {"$millisecond": {"date": "$date", "timezone": 1}}}'); ERROR: $millisecond requires a string for the timezone argument, but was given a int (1) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date", "timezone": {"$date": {"$numberLong": "0"}}}}}'); ERROR: $week requires a string for the timezone argument, but was given a date ({ "$date" : "1970-01-01T00:00:00Z" }) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeekYear": {"$isoWeekYear": {"date": "$date", "timezone": {"$oid": "639926cee6bda3127f153bf1"}}}}'); ERROR: $isoWeekYear requires a string for the timezone argument, but was given a objectId ({ "$oid" : "639926cee6bda3127f153bf1" }) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": "$date", "timezone": true}}}'); ERROR: $isoDayOfWeek requires a string for the timezone argument, but was given a bool (true) SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": true}}}'); ERROR: $isoWeek requires a string for the timezone argument, but was given a bool (true) -- date part operators: object argument. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": {"timezone": true}}}'); ERROR: missing 'date' argument to $year, provided: $year: { "timezone" : true } SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": {}}}'); ERROR: missing 'date' argument to $month, provided: $month: { } SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"timezone": []}}}'); ERROR: missing 'date' argument to $dayOfMonth, provided: $dayOfMonth: { "timezone" : [ ] } SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"timezone": 1}}}'); ERROR: missing 'date' argument to $dayOfYear, provided: $dayOfYear: { "timezone" : 1 } SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"timezone": {}}}}'); ERROR: missing 'date' argument to $dayOfWeek, provided: $dayOfWeek: { "timezone" : { } } SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": {}}}'); ERROR: missing 'date' argument to $hour, provided: $hour: { } SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"timezone": [[[]]]}}}'); ERROR: missing 'date' argument to $minute, provided: $minute: { "timezone" : [ [ [ ] ] ] } SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": {"timezone": {}}}}'); ERROR: missing 'date' argument to $second, provided: $second: { "timezone" : { } } SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": {}}}'); ERROR: missing 'date' argument to $millisecond, provided: $millisecond: { } SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"timezone": {"$date": {"$numberLong": "0"}}}}}'); ERROR: missing 'date' argument to $week, provided: $week: { "timezone" : { "$date" : "1970-01-01T00:00:00Z" } } SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"timezone": {"$oid": "639926cee6bda3127f153bf1"}}}}'); ERROR: missing 'date' argument to $isoWeekYear, provided: $isoWeekYear: { "timezone" : { "$oid" : "639926cee6bda3127f153bf1" } } SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"timezone": true}}}'); ERROR: missing 'date' argument to $isoDayOfWeek, provided: $isoDayOfWeek: { "timezone" : true } SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"timezone": true}}}'); ERROR: missing 'date' argument to $isoWeek, provided: $isoWeek: { "timezone" : true } -- date part operators: object with date and timezone arguments. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": {"random": true}}}'); ERROR: Unrecognized $year option provided: "random" SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": {"foo": 1}}}'); ERROR: Unrecognized $month option provided: "foo" SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"timezone": [], "date": 1, "time": 1}}}'); ERROR: Unrecognized $dayOfMonth option provided: "time" SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"timezone": 1, "dat": 2}}}'); ERROR: Unrecognized $dayOfYear option provided: "dat" SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"timezon": {}}}}'); ERROR: Unrecognized $dayOfWeek option provided: "timezon" SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": {"datetime": 1}}}'); ERROR: Unrecognized $hour option provided: "datetime" SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"timeZone": [[[]]]}}}'); ERROR: Unrecognized $minute option provided: "timeZone" SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": {"Timezone": {}}}}'); ERROR: Unrecognized $second option provided: "Timezone" SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": {"unknown": "1"}}}'); ERROR: Unrecognized $millisecond option provided: "unknown" SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"location": {"$date": {"$numberLong": "0"}}}}}'); ERROR: Unrecognized $week option provided: "location" SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"timezonE": {"$oid": "639926cee6bda3127f153bf1"}}}}'); ERROR: Unrecognized $isoWeekYear option provided: "timezonE" SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"timezone": true, "foo": 1}}}'); ERROR: Unrecognized $isoDayOfWeek option provided: "foo" SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": 1, "info": ""}}}'); ERROR: Unrecognized $isoWeek option provided: "info" -- date part operators: array argument, should be single element array. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": [1, 2, 3]}}'); ERROR: $year requires exactly one argument when an array is provided, but received 3 SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": []}}'); ERROR: $month requires exactly one argument when an array is provided, but received 0 SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": [1, 2]}}'); ERROR: $dayOfMonth requires exactly one argument when an array is provided, but received 2 SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": [[], []]}}'); ERROR: $dayOfYear requires exactly one argument when an array is provided, but received 2 SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": []}}'); ERROR: $dayOfWeek requires exactly one argument when an array is provided, but received 0 SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": [1, 2, 3, 4]}}'); ERROR: $hour requires exactly one argument when an array is provided, but received 4 SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": []}}'); ERROR: $minute requires exactly one argument when an array is provided, but received 0 SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": ["srr", "foo"]}}'); ERROR: $second requires exactly one argument when an array is provided, but received 2 SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": [1, 2]}}'); ERROR: $millisecond requires exactly one argument when an array is provided, but received 2 SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": []}}'); ERROR: $week requires exactly one argument when an array is provided, but received 0 SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": [1, 2, 3, 4, 5]}}'); ERROR: $isoWeekYear requires exactly one argument when an array is provided, but received 5 SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": []}}'); ERROR: $isoDayOfWeek requires exactly one argument when an array is provided, but received 0 SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": [1, []]}}'); ERROR: $isoWeek requires exactly one argument when an array is provided, but received 2 -- date part operators: unrecognized timezones SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": ""}}}'); ERROR: unrecognized time zone identifier: "" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": "\u0000\u0000"}}}'); ERROR: unrecognized time zone identifier: "" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": "+8"}}}'); ERROR: unrecognized time zone identifier: "+8" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"month": {"$month": {"date": "$date", "timezone": "+080"}}}'); ERROR: unrecognized time zone identifier: "+080" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfMonth": {"$dayOfMonth": {"date": "$date", "timezone": "+08:800"}}}'); ERROR: unrecognized time zone identifier: "+08:800" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": {"date": "$date", "timezone": "-888888"}}}'); ERROR: unrecognized time zone identifier: "-888888" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfWeek": {"$dayOfWeek": {"date": "$date", "timezone": "US/Unknown"}}}'); ERROR: unrecognized time zone identifier: "US/Unknown" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"hour": {"$hour": {"date": "$date", "timezone": "+"}}}'); ERROR: unrecognized time zone identifier: "+" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"minute": {"$minute": {"date": "$date", "timezone": "08:09"}}}'); ERROR: unrecognized time zone identifier: "08:09" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"second": {"$second": {"date": "$date", "timezone": "Etc/Invalid"}}}'); ERROR: unrecognized time zone identifier: "Etc/Invalid" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"millisecond": {"$millisecond": {"date": "$date", "timezone": "US/Pacifi"}}}'); ERROR: unrecognized time zone identifier: "US/Pacifi" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date", "timezone": "America/LosAngeles"}}}'); ERROR: unrecognized time zone identifier: "America/LosAngeles" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeekYear": {"$isoWeekYear": {"date": "$date", "timezone": "UST"}}}'); ERROR: unrecognized time zone identifier: "UST" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": "$date", "timezone": "+080\u00001"}}}'); ERROR: unrecognized time zone identifier: "+080" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": "+080\u0000"}}}'); ERROR: unrecognized time zone identifier: "+080" -- $dateToParts no timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1990-01-01T23:13:00.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": true }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "isoWeekYear" : { "$numberInt" : "1990" }, "isoWeek" : { "$numberInt" : "1" }, "isoDayOfWeek" : { "$numberInt" : "1" }, "hour" : { "$numberInt" : "23" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "0" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-12-31T15:13:25.003Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "6" }, "month" : { "$numberInt" : "12" }, "day" : { "$numberInt" : "31" }, "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "3" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-12-31T15:13:25.003Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": false }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "6" }, "month" : { "$numberInt" : "12" }, "day" : { "$numberInt" : "31" }, "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "3" } } } (1 row) -- $dateToParts with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "Europe/London" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "16" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "America/New_York" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "11" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "+01" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "16" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "-01" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "14" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "-0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "6" }, "day" : { "$numberInt" : "19" }, "hour" : { "$numberInt" : "15" }, "minute" : { "$numberInt" : "12" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}, "tz": "America/New_York"}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "$tz", "iso8601": {"$eq": ["$tz", "America/New_York"]} }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : { "isoWeekYear" : { "$numberInt" : "2017" }, "isoWeek" : { "$numberInt" : "25" }, "isoDayOfWeek" : { "$numberInt" : "1" }, "hour" : { "$numberInt" : "11" }, "minute" : { "$numberInt" : "13" }, "second" : { "$numberInt" : "25" }, "millisecond" : { "$numberInt" : "713" } } } (1 row) -- oid == 2017-06-19T15:13:25.713Z UTC. SELECT * FROM bson_dollar_project('{"_id": {"$oid": "58c7cba47bbadf523cf2c313"}}', '{"dateParts": {"$dateToParts": { "date": "$_id", "timezone": "Europe/London" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$oid" : "58c7cba47bbadf523cf2c313" }, "dateParts" : { "year" : { "$numberInt" : "2017" }, "month" : { "$numberInt" : "3" }, "day" : { "$numberInt" : "14" }, "hour" : { "$numberInt" : "10" }, "minute" : { "$numberInt" : "53" }, "second" : { "$numberInt" : "24" }, "millisecond" : { "$numberInt" : "0" } } } (1 row) -- $dateToParts should return null SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "$tz" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": null }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": "$iso" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": null }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateParts" : null } (1 row) SELECT * FROM bson_dollar_project('{"_id": 1 }', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": true }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "dateParts" : null } (1 row) SELECT * FROM bson_dollar_project('{"_id": 1 }', '{"dateParts": {"$dateToParts": { "date": null, "timezone": "UTC", "iso8601": true }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "dateParts" : null } (1 row) -- $dateToParts 'date' argument is required SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "$tz" }}}'); ERROR: 'date' parameter is required for $dateToParts SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "$tz", "iso8601": true }}}'); ERROR: 'date' parameter is required for $dateToParts SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "Unknown", "iso8601": true }}}'); ERROR: 'date' parameter is required for $dateToParts -- $dateToParts 'iso8601' should be a bool SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": {"$add": [1, 1]} }}}'); ERROR: iso8601 should return a boolean value, but received int instead SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": "str" }}}'); ERROR: iso8601 should return a boolean value, but received string instead SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str" }}}'); ERROR: iso8601 should return a boolean value, but received string instead -- $dateToParts 'date' must be a date, timestamp or oid SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": true }}}'); ERROR: can't convert from BSON type int to Date SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "str" }}}'); ERROR: can't convert from BSON type string to Date -- $dateToParts 'timezone' must be a string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str", "timezone": 1 }}}'); ERROR: timezone must evaluate to a string, found int SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str", "timezone": {"$add": [1]} }}}'); ERROR: timezone must evaluate to a string, found int -- $dateToParts 'timezone' is unknown SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": ""}}}'); ERROR: unrecognized time zone identifier: "" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "\u0000\u0000"}}}'); ERROR: unrecognized time zone identifier: "" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+8"}}}'); ERROR: unrecognized time zone identifier: "+8" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+080"}}}'); ERROR: unrecognized time zone identifier: "+080" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+08:800"}}}'); ERROR: unrecognized time zone identifier: "+08:800" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "-888888"}}}'); ERROR: unrecognized time zone identifier: "-888888" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "Ut"}}}'); ERROR: unrecognized time zone identifier: "Ut" SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "Unknown"}}}'); ERROR: unrecognized time zone identifier: "Unknown" -- $dateToString no timezone default format SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-06-19T15:13:25.713Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-06-01T00:01:02.003Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "0006-06-01T00:01:02.003Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0906-06-01T08:01:02.023Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "0906-06-01T08:01:02.023Z" } (1 row) -- $dateToString with timezone default format SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "UTC" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-06-19T15:13:25.713Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/Los_Angeles" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-06-19T08:13:25.713Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/Los_Angeles" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-01-19T07:13:25.713Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Europe/London" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-06-19T16:13:25.713Z" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Europe/London" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-01-19T15:13:25.713Z" } (1 row) -- $dateToString random formats SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%d%d***%d***%d**%d*%d" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "1919***19***19**19*19" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-06-01T00:01:02.003Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%%%%%%%%%%%%%%%%%%---%Y---%%%%%%%%%%%%" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "%%%%%%%%%---0006---%%%%%%" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "0906-06-01T08:01:02.023Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "This is a custom format:\u0000....%Y-%d-%m....\u0000"}}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "This is a custom format:\u0000....0906-01-06....\u0000" } (1 row) -- $dateToString timezone specifiers SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)", "timezone": "America/Los_Angeles" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: -0700 (-420 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "America/Los_Angeles" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: -0800 (-480 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "Africa/Asmera" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: +0300 (180 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+08" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: +0800 (480 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+0059" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: +0059 (59 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+5959" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: +5959 (3599 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "-00:01" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "UTC offset: -0001 (-1 minutes)" } (1 row) -- $dateToString multiple timezones SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 14:56:42 +0000 (0 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Europe/London" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 15:56:42 +0100 (60 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 10:56:42 -0400 (-240 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Australia/Eucla" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 23:41:42 +0845 (525 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Asia/Katmandu" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 20:41:42 +0545 (345 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Europe/Amsterdam" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 16:56:42 +0200 (120 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "1900-07-10T11:41:22.418Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/Caracas" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "1900-07-10 07:13:42 -0427 (-267 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-04T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-01-04 10:08:51 -0500 (-300 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T15:09:12.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-07-04 11:09:12 -0400 (-240 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-12-04 10:09:14 -0500 (-300 minutes)" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "2017-12-04 15:09:14 +0000 (0 minutes)" } (1 row) -- $dateToString natural vs iso dates SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "Natural: 2017-W1-01-d001, ISO: 2016-W7-52-d001" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T15:09:12.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "Natural: 2017-W3-27-d185, ISO: 2017-W2-27-d185" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "Natural: 2017-W2-49-d338, ISO: 2017-W1-49-d338" } (1 row) -- $dateToString long format strings > 256 bytes SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZNMIX was placed on: %Y-%m-%d %H:%M:%S" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZNMIX was placed on: 2017-01-01 15:08:51" } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2038-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZ was placed on: %Y-%m-%d %H:%M:%S" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZ was placed on: 2038-01-01 15:08:51" } (1 row) -- $dateToString returns null if no onNull is specified and any arg expression is null or undefined SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "$tz", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": null, "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/New_York", "format": "$format" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/New_York", "format": null }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": null, "timezone": "America/New_York"}}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$literal": null}, "timezone": "America/New_York"}}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) -- $dateToString onNull expression is only returned and honored when 'date' argument is null SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "date was null or undefined" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "date was null or undefined" } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$date" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": {"$date": "2017-12-04T15:09:14.911Z"} }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : { "$date" : { "$numberLong" : "1512400154911" } } } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$newYorkDate", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "date was null or undefined" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : "date was null or undefined" } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "timezone": "$tz", "onNull": "date was null or undefined" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "$format", "onNull": "date was null or undefined" }}}'); bson_dollar_project --------------------------------------------------------------------- { "dateString" : null } (1 row) -- $dateToString when date is null and onNull expression points to a non existent path in the document, no result is returned SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$b" }}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$c" }}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- $dateToString 'date' is required SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a" }}}'); ERROR: Missing 'date' parameter to $dateToString -- $dateToString unknown field SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a", "customField": "a" }}}'); ERROR: Unrecognized parameter provided for $dateToString: customField -- $dateToString an object is required as an argument SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": "$arg"}}'); ERROR: $dateToString requires an object parameter only SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": null}}'); ERROR: $dateToString requires an object parameter only SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": []}}'); ERROR: $dateToString requires an object parameter only -- $dateToString invalid format modifier SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %i %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); ERROR: Invalid format character '%i' in format string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%i %Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); ERROR: Invalid format character '%i' in format string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes) %i", "timezone": "UTC" }}}'); ERROR: Invalid format character '%i' in format string -- $dateToString unmatched % at end of format string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)%%%", "timezone": "UTC" }}}'); ERROR: Unmatched '%' at end of format string -- $dateToString 'format' argument must be a string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": true, "timezone": "UTC" }}}'); ERROR: $dateToString requires that 'format' be a string, but instead encountered: bool with value true SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": 1, "timezone": "UTC" }}}'); ERROR: $dateToString requires that 'format' be a string, but instead encountered: int with value 1 -- $dateToString 'date' must be an oid, timestamp or date SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "", "timezone": "UTC" }}}'); ERROR: can't convert from BSON type string to Date -- $dateToString 'timezone' must be string and a valid timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": true }}}'); ERROR: timezone must evaluate to a string, found bool SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Unknown" }}}'); ERROR: unrecognized time zone identifier: "Unknown" SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "+8" }}}'); ERROR: unrecognized time zone identifier: "+8" SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "+80000000" }}}'); ERROR: unrecognized time zone identifier: "+80000000" -- $dateToString date component outside of supported range SELECT * FROM bson_dollar_project('{"date": {"$date": "9999-12-31T11:59:59.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$add": ["$date", {"$numberLong": "86400000"}]} }}}'); ERROR: Failed to convert date into text because the date value was beyond the supported range of 0 to 9999: 10000 SELECT * FROM bson_dollar_project('{"date": {"$date": "9999-12-31T11:59:59.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$add": ["$date", {"$numberLong": "86400000"}]}, "format": "%Y" }}}'); ERROR: Failed to convert date into text because the date value was beyond the supported range of 0 to 9999: 10000 -- $dateFromParts null cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": null }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"$undefined":true} }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":200, "timezone":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": 5, "isoDayOfWeek":null} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateFromParts undefined cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": {"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": {"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":200, "timezone":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : {"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": {"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": 5, "isoDayOfWeek":{"$undefined":true}} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateFromParts non-iso format cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2029} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1861920000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2000, "month": 5, "day":5} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "957484800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589077205450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1970, "month": 2, "day": 10, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "3542390450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2000, "month": 2, "day": 29, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951868790450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62130499209550" } } } (1 row) -- $dateFromParts non-iso format cases with timezone select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "UTC"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589077205450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "America/Denver"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589098805450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "Asia/Kolkata"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589057405450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "+04:30"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589061005450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "+0430"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1589061005450" } } } (1 row) -- $dateFromParts iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1861920000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1873497600000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1873572312000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2023, "isoWeek":12, "isoDayOfWeek": 2} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1679356800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733856312000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62128790088000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone": "+04:30"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62128806288000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone": "+0430"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62128806288000" } } } (1 row) -- $dateFromParts iso cases with timezone select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12, "timezone": "America/Denver"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1873593912000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2023, "isoWeek":12, "isoDayOfWeek": 2, "timezone": "America/Los_Angeles"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1679382000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12 , "timezone": "Asia/Kolkata"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733843712000" } } } (1 row) -- $dateFromParts cases with carrying when range is not valid for iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2017, "isoWeek":0, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1482864312000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2000, "isoWeek":0, "isoDayOfWeek": 5 ,"hour":18, "minute":45, "second":12} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946665912000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2000, "isoWeek":0, "isoDayOfWeek": 15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "947590324876" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":0, "isoDayOfWeek": 15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62134864075124" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2011, "isoWeek":-24, "isoDayOfWeek": -15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1277638324876" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2011, "isoWeek":-24, "isoDayOfWeek": -15 ,"hour":-28, "minute":-450, "second":-124 , "millisecond":876} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1277382476876" } } } (1 row) -- $dateFromParts cases with carrying when range is not valid for non-iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 15, "day": 100, "hour":23 , "minute":210, "second":1115, "millisecond":450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1623206915450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1640245884550" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62073274115450" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 9999, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "253433173884550" } } } (1 row) -- $dateFromParts cases negative cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": 1 }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": "abc" }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {} }}'); ERROR: $dateFromParts needs to include either 'year' or 'isoWeekYear' in order to function properly select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017, "isoWeekYear": 2012} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": {"$numberDecimal": "2014.5"} } }}'); ERROR: 'year' must evaluate to an integer, but found decimal with the actual value :2014.5 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": 1 }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": "abc" }}'); ERROR: $dateFromParts only accepts an object type as its provided argument select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {} }}'); ERROR: $dateFromParts needs to include either 'year' or 'isoWeekYear' in order to function properly select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017, "isoWeekYear": 2012} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017.5} }}'); ERROR: 'year' must evaluate to an integer, but found double with the actual value :2017.5 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":"2017"} }}'); ERROR: 'year' must evaluate to an integer, but found string with the actual value :"2017" select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2017, "abcd":1} }}'); ERROR: Invalid argument supplied to operator $dateFromParts: abcd select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012.12} }}'); ERROR: 'isoWeekYear' must evaluate to an integer, but found double with the actual value :2012.12 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": "2012"} }}'); ERROR: 'isoWeekYear' must evaluate to an integer, but found string with the actual value :"2012" select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "timezone": "hello"} }}'); ERROR: unrecognized time zone identifier: "hello" select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2012, "timezone": 1} }}'); ERROR: timezone must evaluate to a string, found int select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 0} }}'); ERROR: The value for 'year' must evaluate to an integer in the range 1 to 9999, but the provided value was 0 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 11110} }}'); ERROR: The value for 'year' must evaluate to an integer in the range 1 to 9999, but the provided value was 11110 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 0} }}'); ERROR: The value for 'isoWeekYear' must evaluate to an integer in the range 1 to 9999, but the provided value was 0 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 11110} }}'); ERROR: The value for 'isoWeekYear' must evaluate to an integer in the range 1 to 9999, but the provided value was 11110 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 32769, "day": 100, "second": 50, "minute":100} }}'); ERROR: 'month' must evaluate to a value in the range [-32768, 32767]; value 32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 32769, "second": 50, "minute":100} }}'); ERROR: 'day' must evaluate to a value in the range [-32768, 32767]; value 32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "second": 32769, "minute":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1291200369000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": 32769, "minute":100} }}'); ERROR: 'hour' must evaluate to a value in the range [-32768, 32767]; value 32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -24, "minute":32769} }}'); ERROR: 'minute' must evaluate to a value in the range [-32768, 32767]; value 32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": -32769, "day": 100, "second": 50, "minute":100} }}'); ERROR: 'month' must evaluate to a value in the range [-32768, 32767]; value -32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": -32769, "second": 50, "minute":100} }}'); ERROR: 'day' must evaluate to a value in the range [-32768, 32767]; value -32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "second": -32769, "minute":100} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1291134831000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -32769, "minute":100} }}'); ERROR: 'hour' must evaluate to a value in the range [-32768, 32767]; value -32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -24, "minute":-32769} }}'); ERROR: 'minute' must evaluate to a value in the range [-32768, 32767]; value -32769 is not in range select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "millisecond": {"$numberDecimal": "-18999999999999999888888888"}} }}'); ERROR: 'millisecond' must evaluate to an integer, but found decimal with the actual value :-18999999999999999888888888 select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "month":12} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "day":12} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 1209, "isoWeek": 12} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 1209, "isoDayOfWeek": 12} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"month": 1209, "isoDayOfWeek": 12} }}'); ERROR: $dateFromParts cannot be used when combining natural date formats with ISO date formats select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"month": 1209} }}'); ERROR: $dateFromParts needs to include either 'year' or 'isoWeekYear' in order to function properly select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeek": 1209} }}'); ERROR: $dateFromParts needs to include either 'year' or 'isoWeekYear' in order to function properly -- $dateFromParts document based cases select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month", "day": "$day", "hour":"$hour" , "minute":"$minute", "second":"$second", "millisecond":"$millisecond"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1298937590450" } } } (1 row) select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1296518400000" } } } (1 row) select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450, "timezone": "America/Los_Angeles"}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month" , "timezone": "$timezone"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1296547200000" } } } (1 row) select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek" ,"hour":"$hour", "minute":"$minute", "second":"$second"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733856312000" } } } (1 row) select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733788800000" } } } (1 row) select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone" : "America/New_York"}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek", "timezone": "$timezone"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733806800000" } } } (1 row) --$dateTrunc null cases select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": null }}'); ERROR: $dateTrunc requires an object type as its input argument select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"$undefined": true} }}'); ERROR: $dateTrunc requires an object type as its input argument select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": null } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": {"$undefined": true} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "timezone": null , "binSize": 5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "timezone": {"$undefined": true} , "binSize":5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "timezone": "+04:45", "unit": null , "binSize": 5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "timezone": "-0430", "unit": {"$undefined": true} , "binSize":5 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateTrunc case when startOfWeek is null select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "startOfWeek": null , "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "startOfWeek": {"$undefined": true}, "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateTrunc case when startOfWeek null but unit is not week select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "startOfWeek": null , "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123354000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "startOfWeek": {"$undefined": true} , "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123354000" } } } (1 row) -- $dateTrunc cases with unit millisecond select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "millisecond", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123355380" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "millisecond" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "millisecond", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951850555380" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "millisecond" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951850400000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "millisecond" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "7498552500" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "millisecond" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "7084800000" } } } (1 row) -- $dateTrunc cases with unit second select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123354000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707084800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "second", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951850554000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "second" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951665000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "second" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "7494300000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "second" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-403315200000" } } } (1 row) -- $dateTrunc cases with unit minute select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "minute", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707123240000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "minute" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1702684800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "minute", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951850440000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "minute" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946665000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "minute" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "7354800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "minute" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-26053315200000" } } } (1 row) -- $dateTrunc cases with unit hour select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "hour", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707120000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "hour" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1666684800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour", "binSize": 2, "timezone": "America/Los_Angeles" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951847200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour" , "binSize": 200000, "timezone": "America/New_York" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946702800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour" , "binSize": 200000, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946710000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "hour" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "7084800000" } } } (1 row) /* This test case has overflow, postgres added this check in newer minor versions. * Todo: add this test back and check overflow after we bump up the postgres minor version (>=15.7 and >=16.3). */ -- select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "hour" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit day select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "day", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1707004800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "day" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946684800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "day", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951721200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "day" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946665000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "day" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-219715200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "day" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) -- $dateTrunc cases with unit week select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1706400000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946771200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "week", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "951634800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "week" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946751400000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "week" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-1774828800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "week" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) -- $dateTrunc cases with unit month select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "month", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1704067200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "month" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946684800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "month", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946710000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "month" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946665000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "month" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-10887091200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "month" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) -- $dateTrunc cases with unit year select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "year", "binSize": 2 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1704067200000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "year" , "binSize": 200000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946684800000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "year", "binSize": 2, "timezone": "America/Denver" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946710000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "year" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "946665000000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "year" , "binSize": 4500 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-141059577600000" } } } (1 row) select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "year" , "binSize": 450000000 } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "9223372036854775807" } } } (1 row) -- $dateTrunc invalid cases select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": "A" }}'); ERROR: $dateTrunc requires an object type as its input argument select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {} }}'); ERROR: The 'date' parameter required by the $dateTrunc is missing. select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"abc": 1} }}'); ERROR: Invalid argument provided to operator $dateTrunc: abc. Expected parameters include date, unit, and optionally binSize, timezone, and startOfWeek. select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} } }}'); ERROR: The 'unit' parameter required by the $dateTrunc is missing. select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": 1 } }}'); ERROR: $dateTrunc needs 'unit' as a string, but received int instead select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "456" } }}'); ERROR: The provided 'unit' parameter for $dateTrunc is not recognized as a valid time unit: 456 select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "456" } }}'); ERROR: The provided 'unit' parameter for $dateTrunc is not recognized as a valid time unit: 456 select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": "1" } }}'); ERROR: $dateTrunc needs 'binSize' as a 64-bit integer, but received value '"1"' of type string select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": 1.5 } }}'); ERROR: $dateTrunc needs 'binSize' as a 64-bit integer, but received value '1.5' of type double select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": 1 , "timezone": 123} }}'); ERROR: timezone must evaluate to a string, found int select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "week", "binSize": 1 , "startOfWeek": "Menday"} }}'); ERROR: The 'startOfWeek' parameter in $dateTrunc has a value that is not recognized as a valid day of the week: Menday select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": "A" , "unit": "456" } }}'); ERROR: $dateTrunc expects the 'date' parameter to be a valid date type, but received string instead. -- $dateAdd null based cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": null } }'); ERROR: $dateAdd requires an object type argument, but received input type: null select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"$undefined":true} } }'); ERROR: $dateAdd requires an object type argument, but received input type: { "$undefined" : true } select * from bson_dollar_project('{}','{"result": {"$dateAdd": {} } }'); ERROR: $dateAdd needs startDate, unit, and amount to be presented -- $dateAdd cases when input parts are null or undefined select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": null , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":null , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":null, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$undefined":true} , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":{"$undefined":true} , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":{"$undefined":true}, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateAdd normal cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615647900000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":-30 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1536850800000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":3 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1710342000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"quarter" , "amount":45 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1970751600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":145 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1628175600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"week" , "amount":-14 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1607180400000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"hour" , "amount":4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615662000000" } } } (1 row) -- $dateAdd cases with timezone handling select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount":2, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1617156000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount":12, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1612105200000" } } } (1 row) -- dst offset not applied for hours select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount":24, "timezone": "Europe/Paris" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603649400000" } } } (1 row) -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "Europe/Paris" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603653000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603649400000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"second" , "amount":1, "timezone": "-05:30" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603563001000" } } } (1 row) -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":5, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1616076000000" } } } (1 row) -- $dateAdd cases with input validation of ranges which are calculated manually. With these inputs we should error that it's out of range. This is a pre-addition validation select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 584942419} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 584942419 year is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"quarter" , "amount": 1754827252} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 1754827252 quarter is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount": 7019309005} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 7019309005 month is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 30500568906 week is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 30500568906 week is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"day" , "amount": 213503982336} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 213503982336 day is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount": 5124095576041} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 5124095576041 hour is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"minute" , "amount": 307445734562401} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 307445734562401 minute is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 18446744073744001} } }'); ERROR: Invalid $dateAdd for 'amount' parameter: provided value 18446744073744001 second is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 1, "hex": "a"} } }'); ERROR: Unrecognized argument to $dateAdd: hex. Expected arguments are startDate, unit, amount, and optionally timezone -- $dateAdd cases with error cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56.55} } }'); ERROR: Expected 'integer' type for $dateAdd select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"years" , "amount": 56} } }'); ERROR: Unrecognized or invalid time unit value: years select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); ERROR: Unrecognized argument to $dateAdd: field. Expected arguments are startDate, unit, amount, and optionally timezone select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); ERROR: Unrecognized argument to $dateAdd: field. Expected arguments are startDate, unit, amount, and optionally timezone select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56} } }'); ERROR: $dateAdd needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"unit":"day" , "amount": 56} } }'); ERROR: $dateAdd needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"unit":"day" , "amount": 56} } }'); ERROR: $dateAdd needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": "abcd" , "amount": 56, "unit": 5} } }'); ERROR: $dateAdd needs startDate to be converted into a valid date select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56, "unit": 5, "timezone": "abcd"} } }'); ERROR: $dateAdd expects string defining the time unit -- $dateAdd cases with overflow select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"year" , "amount": 584942416} } }'); ERROR: $dateAdd overflowed select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"month" , "amount": 584942416} } }'); ERROR: $dateAdd overflowed select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount": 58411942416} } }'); ERROR: $dateAdd overflowed -- $dateAdd cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615647900000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":3 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1623596400000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":10 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1931180400000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":60 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1620831600000" } } } (1 row) -- $dateSubtract null based cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": null } }'); ERROR: $dateSubtract requires an object type argument, but received input type: null select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"$undefined":true} } }'); ERROR: $dateSubtract requires an object type argument, but received input type: { "$undefined" : true } select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {} } }'); ERROR: $dateSubtract needs startDate, unit, and amount to be presented -- $dateSubtract cases when input parts are null or undefined select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": null , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":null , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":null, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$undefined":true} , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":{"$undefined":true} , "amount":30000000000, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":{"$undefined":true}, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateSubtract normal cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615647300000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":-30 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1694617200000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":3 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1520953200000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1709205288000"} } , "unit":"year" , "amount":1 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1677582888000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"quarter" , "amount":45 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1260716400000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":145 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603119600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"week" , "amount":-14 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1624114800000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"hour" , "amount":4 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615633200000" } } } (1 row) -- $dateSubtract cases with timezone handling select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount":2, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1606791600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount":12, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1612018800000" } } } (1 row) -- dst offset not applied for hours select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount":24, "timezone": "Europe/Paris" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603476600000" } } } (1 row) -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "Europe/Paris" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603476600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "+04:00" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603476600000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"second" , "amount":1, "timezone": "-05:30" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1603562999000" } } } (1 row) -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":5, "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615215600000" } } } (1 row) -- $dateSubtract cases with input validation of ranges which are calculated manually. With these inputs we should error that it's out of range. This is a pre-subtraction validation select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 584942419} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 584942419 year is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"quarter" , "amount": 1754827252} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 1754827252 quarter is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount": 7019309005} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 7019309005 month is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 30500568906 week is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 30500568906 week is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"day" , "amount": 213503982336} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 213503982336 day is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount": 5124095576041} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 5124095576041 hour is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"minute" , "amount": 307445734562401} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 307445734562401 minute is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 18446744073744001} } }'); ERROR: Invalid $dateSubtract for 'amount' parameter: provided value 18446744073744001 second is not acceptable select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 1, "hex": "a"} } }'); ERROR: Unrecognized argument to $dateSubtract: hex. Expected arguments are startDate, unit, amount, and optionally timezone -- $dateSubtract cases with error cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56.55} } }'); ERROR: Expected 'integer' type for $dateSubtract select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"years" , "amount": 56} } }'); ERROR: Unrecognized or invalid time unit value: years select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); ERROR: Unrecognized argument to $dateSubtract: field. Expected arguments are startDate, unit, amount, and optionally timezone select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); ERROR: Unrecognized argument to $dateSubtract: field. Expected arguments are startDate, unit, amount, and optionally timezone select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56} } }'); ERROR: $dateSubtract needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"unit":"day" , "amount": 56} } }'); ERROR: $dateSubtract needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"unit":"day" , "amount": 56} } }'); ERROR: $dateSubtract needs startDate, unit, and amount to be presented select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": "abcd" , "amount": 56, "unit": 5} } }'); ERROR: $dateSubtract needs startDate to be converted into a valid date select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56, "unit": 5, "timezone": "abcd"} } }'); ERROR: $dateSubtract expects string defining the time unit -- $dateSubtract cases with overflow select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"year" , "amount": 584942416} } }'); ERROR: $dateSubtract overflowed select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"month" , "amount": 584942416} } }'); ERROR: $dateSubtract overflowed select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount": 58411942416} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "6184962583800001" } } } (1 row) -- $dateSubtract cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1615647300000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":3 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1607871600000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":10 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1300028400000" } } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":60 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610463600000" } } } (1 row) -- $dateDiff null cases select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": null , "unit":"minute" , "endDate": {"$date": {"$numberLong": "1678924740000"} } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "unit":"minute" , "endDate": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": "-05:00", "startOfWeek" : null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$undefined":true} , "unit":"minute" , "endDate": {"$date": {"$numberLong": "1678924740000"} } } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "unit":"minute" , "endDate": {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": "-05:00", "startOfWeek" : {"$undefined":true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $dateDiff null cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezones" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unist", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDsate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$sstartDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- startOfWeek is ignored when unit is not week select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" , "timezone": "-05:00", "startOfWeek" : null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" , "timezone": "-05:00", "startOfWeek" : 1 } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) -- $dateDiff unit milliseconds select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-500" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "3999500" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "millisecond" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-1678920000500" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "3999500" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "3999500" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "3999500" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "3999500" } } (1 row) -- $dateDiff unit seconds select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4000" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "second" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-1678920000" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4000" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4000" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4000" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4000" } } (1 row) -- $dateDiff unit minute select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "67" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "minute" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-27982000" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "67" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "67" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "67" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "67" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "8639" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "8639" } } (1 row) -- $dateDiff unit hour select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "hour" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-466366" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "143" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "143" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "hour"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "6" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "hour", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "6" } } (1 row) -- $dateDiff unit day select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "day" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-19432" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "5" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "5" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "day", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) -- days in 2024 year select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "365" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "day", "timezone": "America/Denver"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "365" } } (1 row) -- $dateDiff unit week select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "week" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-2776" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "UTC" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678488740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "week", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) -- weeks in 2024 year select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "52" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "week", "timezone": "America/Denver"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "52" } } (1 row) -- week startOfWeek cases select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "MONDAY"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "monday"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "tuesday"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1610859600000"} } , "endDate": {"$date": {"$numberLong": "1610859540000"} }, "unit": "week", "startOfWeek": "sunday", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek", "timezone": "$timezone"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) -- $dateDiff unit month select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "12" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "17" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "103" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "month" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-103" } } (1 row) -- $dateDiff unit quarter select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "5" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "35" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "quarter" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-35" } } (1 row) -- $dateDiff unit year select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "0" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "9" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "year" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-9" } } (1 row) -- $dateDiff invalid cases select * from bson_dollar_project('{}','{"result": {"$dateDiff": 1 } }'); ERROR: $dateDiff can only accept an object type as its input argument select * from bson_dollar_project('{}','{"result": {"$dateDiff": "abc" } }'); ERROR: $dateDiff can only accept an object type as its input argument select * from bson_dollar_project('{}','{"result": {"$dateDiff": ["abc"] } }'); ERROR: $dateDiff can only accept an object type as its input argument select * from bson_dollar_project('{}','{"result": {"$dateDiff": {} } }'); ERROR: 'startDate' parameter required for $dateDiff select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "month" } } }'); ERROR: $dateDiff requires 'endDate' to be specified select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "month" } } }'); ERROR: 'startDate' parameter required for $dateDiff select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": 1 , "unit": "month", "endDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); ERROR: $dateDiff needs 'startDate' to be provided as a valid date, but instead received int select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": 1 , "unit": "month", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); ERROR: $dateDiff needs 'endDate' to be provided as a valid date, but instead received int select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"hex":1, "endDate": 1 , "unit": "month", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); ERROR: Unrecognized parameter provided to $dateDiff: hex select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "ashd", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); ERROR: The 'unit' parameter in $dateDiff has an unrecognized time unit value: ashd select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": 1, "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); ERROR: $dateDiff needs 'unit' as a string, but received int instead select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : 1 } } }'); ERROR: timezone must evaluate to a string, found int select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : "abcd" } } }'); ERROR: unrecognized time zone identifier: "abcd" select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : "UTC", "startOfWeek": "hello" } } }'); ERROR: 'startOfWeek' parameter in $dateDiff must be a valid weekday, but got: hello -- $dateFromString null cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- checking with undefined as well select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": {"$undefined": true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": {"$undefined": true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": {"$undefined": true} } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- onError null does not effect null response select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": "UTC", "onError": null} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610352000000" } } } (1 row) -- $dateFromString null cases with document select * from bson_dollar_project('{"dateString": null}','{"result": {"$dateFromString": {"dateString": "$dateString" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11", "format": null }','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": null }','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"dateString": {"$undefined": true} }','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11", "format": {"$undefined": true}}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": {"$undefined": true}}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- onError null does not effect null response select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": "UTC", "onError": null}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone", "onError": "$onError"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610352000000" } } } (1 row) -- $dateFromString normal cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.506Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ABCD 2021-01-11T12.53.12.506Z", "format": "ABCD %Y-%m-%dT%H.%M.%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2025-12-31", "format": "%Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1767168000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "20-1-1", "format": "%Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-61536038822000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Year 2025, Month 12, Day 31", "format": "Year %Y, Month %m, Day %d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1767168000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) -- millisecond can be of min 1 and max 3 digits select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.5Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392500" } } } (1 row) -- millisecond of 2 digits select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.50Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392500" } } } (1 row) -- iso date format select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "53.7.2017", "format": "%V.%u.%G"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1515312000000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "1.1.1", "format": "%V.%u.%G"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62135568422000" } } } (1 row) -- iso part only requires year select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017", "format": "%G"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1483344000000" } } } (1 row) -- % format specifier parsing test select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "%% %Y-%m-%dT%H:%M:%S.%LZ"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) -- $dateFromString normal cases with document select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.506Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{"dateString": "ABCD 2021-01-11T12.53.12.506Z", "format": "ABCD %Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{"dateString": "2025-12-31", "format": "%Y-%m-%d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1767168000000" } } } (1 row) select * from bson_dollar_project('{"dateString": "20-1-1", "format": "%Y-%m-%d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-61536038822000" } } } (1 row) select * from bson_dollar_project('{"dateString": "Year 2025, Month 12, Day 31", "format": "Year %Y, Month %m, Day %d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1767168000000" } } } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12.506Z"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) -- millisecond can be of min 1 and max 3 digits select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.5Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392500" } } } (1 row) -- millisecond of 2 digits select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.50Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392500" } } } (1 row) -- iso date format select * from bson_dollar_project('{"dateString": "53.7.2017", "format": "%V.%u.%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1515312000000" } } } (1 row) select * from bson_dollar_project('{"dateString": "1.1.1", "format": "%V.%u.%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-62135568422000" } } } (1 row) -- iso part only requires year select * from bson_dollar_project('{"dateString": "2017", "format": "%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1483344000000" } } } (1 row) -- $dateFromString cases with onNull select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": "5"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "5" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": 1} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": {"$date": {"$numberLong": "1678924740500"} }} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1678924740500" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "$missing", "onNull": "$missing"} } }'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- only when dateString is nullish value, onNull is considered select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2018-02-06T11:56:02Z", "format": null, "onNull": 1} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- onNull with document cases select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": "5"}','{"result": {"$dateFromString": {"dateString": "$dateFromString", "format": "$format", "onNull": "$onNull"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "5" } (1 row) select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": 1}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "onNull": "$onNull"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } (1 row) select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": {"$date": {"$numberLong": "1678924740500"} }}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "onNull": "$onNull"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1678924740500" } } } (1 row) -- $dateFromString cases with timezone select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "UTC"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "+01:00"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610394792506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "America/Denver"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610423592506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506+130", "format": "%Y-%m-%dT%H:%M:%S.%L%Z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610390592506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506-130", "format": "%Y-%m-%dT%H:%M:%S.%L%Z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610406192506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Year is 2021 , Month is 12 and Day is @ 12 with minute offset +560", "format": "Year is %Y , Month is %m and Day is @ %d with minute offset %Z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1639262400000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506+0130", "format": "%Y-%m-%dT%H:%M:%S.%L%z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610392992506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506-01:30", "format": "%Y-%m-%dT%H:%M:%S.%L%z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610403792506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 UTC", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 MST", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610423592506" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 GMT-03:00", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610409192506" } } } (1 row) -- $dateFromString invalid cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": "a" } }'); ERROR: $dateFromString only supports an object as an argument, found: string", select * from bson_dollar_project('{}','{"result": {"$dateFromString": 1 } }'); ERROR: $dateFromString only supports an object as an argument, found: int", select * from bson_dollar_project('{}','{"result": {"$dateFromString": {} } }'); ERROR: Required 'dateString' parameter is not provided for $dateFromString select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": 5} } }'); ERROR: $dateFromString requires that 'dateString' be a string, found: int with value 5 select * FROM bson_dollar_project('{"dates": { "startDate": "2024-04-15", "endDate": "2024-05-14" }}','{ "result": { "$dateFromString": {"dateString": "$dates", "format": "%Y-%m-%d"}}}'); ERROR: $dateFromString requires that 'dateString' be a string, found: object with value { "startDate" : "2024-04-15", "endDate" : "2024-05-14" } select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": 1} } }'); ERROR: $dateFromString requires that 'format' be a string, but instead it received int with the value 1 select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); ERROR: Error parsing date string '2022-10-12'. Format literal not found '2' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); ERROR: Error parsing date string '2022-10-12'. Format literal not found '2' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 1002", "format": "%Y %j" } } }'); ERROR: Error parsing date string '2024 1002'. Trailing data '2' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Jenuery 1 2024", "format": "%B %d %Y" } } }'); ERROR: an incomplete date/time string has been found, with certain required elements missing: 'Jenuery 1 2024' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "act 1 2024", "format": "%b %d %Y" } } }'); ERROR: an incomplete date/time string has been found, with certain required elements missing: 'act 1 2024' -- unkown argument in input select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d", "unknown":1} } }'); ERROR: Unrecognized argument passed to $dateFromString operator: unknown -- passing timezone as input with existing timezone in string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 GMT+02:00", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); ERROR: you cannot pass in a date/time string with GMT offset together with a timezone argument select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 GMT", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); ERROR: It is not allowed to provide a date/time string containing time zone details ('GMT') at the same time as specifying a separate timezone argument. select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 +02:20", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); ERROR: you cannot pass in a date/time string with GMT offset together with a timezone argument -- not enough data select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07T22:23:55 GMT+02:00", "format": "%Y-%mT%H:%M:%S %z"} } }'); ERROR: an incomplete date/time string has been found, with certain required elements missing: '2017-07T22:23:55 GMT+02:00' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017", "format": "%C"} } }'); ERROR: Invalid format character '%C' in format string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ISO Week 1, 2018", "format": "ISO Week %V, %Y"} } }'); ERROR: Error parsing date string 'ISO Week 1, 2018'; Mixing of ISO dates with natural dates is not allowed select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "12/31/2018", "format": "%m/%d\\0/%Y"} } }'); ERROR: Error parsing date string '12/31/2018'. Format literal not found '/' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-12", "format": "%Y"} } }'); ERROR: Error parsing date string '2017-12'. Trailing data '-' select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ISO Day 6", "format": "ISO Day %V"} }}'); ERROR: Error parsing date string 'ISO Day 6';The parsed date was invalid select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "12/31/2018", "format": "%m/%d/%G"} } }'); ERROR: Error parsing date string '12/31/2018'; Mixing of ISO dates with natural dates is not allowed -- % format specifier test select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "% %Y-%m-%dT%H:%M:%S.%LZ"} } }'); ERROR: Invalid format character '% ' in format string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "%%Y-%m-%dT%H:%M:%S.%LZ"} } }'); ERROR: Error parsing date string '% 2021-01-11T12:53:12.506Z'. Format literal not found ' ' -- $dateFromString cases with onError select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": 5} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- if dateString is not a string, onError should be considered select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": 5, "format": null } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) -- passing timezone as input with existing timezone in string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07-12T22:23:55 GMT+02:00", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07-12T22:23:55 GMT", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled", "dateString": "2017-07-12T22:23:55 +02:20", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) -- not enough data select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07T22:23:55 GMT+02:00", "format": "%Y-%mT%H:%M:%S %z"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "ISO Week 1, 2018", "format": "ISO Week %V, %Y"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "12/31/2018", "format": "%m/%d\\0/%Y"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-12", "format": "%Y"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "ISO Day 6", "format": "ISO Day %V"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "12/31/2018", "format": "%m/%d/%G"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : "error handled" } (1 row) -- checking with changing onError return type select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": 5} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1678924740500" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1678924740500" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1678924740500" } } } (1 row) -- adding extra format specifiers select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 234 04:34:11", "format": "%Y %j %H:%M:%S" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1724301240000" } } } (1 row) -- exception test for value of dayOfyear is 999 select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 999", "format": "%Y %j" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1790380800000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "year is 2024 and the days are 234 and time is 04:34:11", "format": "year is %Y and the days are %j and time is %H:%M:%S" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1724301240000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "dec 1 2024 04:34:11", "format": "%b %d %Y %H:%M:%S" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1733056451000" } } } (1 row) select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "janUary 1 2024 04:34:11", "format": "%B %d %Y %H:%M:%S" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1704112451000" } } } (1 row) -- Defensive check to prevent error from ms conversion to timestamptz SELECT * FROM bson_dollar_project('{}', '{"result": {"$dateToString": {"date":{"$toDate": {"$numberDouble": "-244058800000000"}}}}}'); ERROR: value -244058800000000 (milliseconds) is out of range for timestamps. SELECT * FROM bson_dollar_project('{}', '{"result": {"$dateToString": {"date":{"$toDate": {"$numberDouble": "9664590969990000"}}}}}'); ERROR: value 9664590969990000 (milliseconds) is out of range for timestamps. -- parse with preset formats select * from bson_dollar_project('{"dateString": "2021-01-11 11:00:03"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610391603000" } } } (1 row) select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1610398392000" } } } (1 row) select * from bson_dollar_project('{"dateString": "July 4th, 2017"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1499151600000" } } } (1 row) select * from bson_dollar_project('{"dateString": "July 4th, 2017 12:39:30 BST"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1499193570000" } } } (1 row) select * from bson_dollar_project('{"dateString": "July 4th, 2017 11am"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1499191200000" } } } (1 row) select * from bson_dollar_project('{"dateString": "2017-Jul-04 noon"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1499194800000" } } } (1 row) bson_aggregation_expression_variable_tests.out000066400000000000000000002203431507310017400414060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4910000; SET documentdb.next_collection_id TO 4910; SET documentdb.next_collection_index_id TO 4910; -- $$ROOT as a variable. SELECT documentdb_api_catalog.bson_expression_get('{ "a": 1 }', '{ "c": "$$ROOT" }'); bson_expression_get --------------------------------------------------------------------- { "c" : { "a" : { "$numberInt" : "1" } } } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.a" }'); bson_expression_get --------------------------------------------------------------------- { "c" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.a.b" }'); bson_expression_get --------------------------------------------------------------------- { "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.c" }'); bson_expression_get --------------------------------------------------------------------- { } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$isArray": "$$ROOT.a.b" } }'); bson_expression_get --------------------------------------------------------------------- { "c" : true } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$isArray": "$$ROOT.a" } }'); bson_expression_get --------------------------------------------------------------------- { "c" : false } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$size": "$$ROOT.a.b" } }'); bson_expression_get --------------------------------------------------------------------- { "c" : { "$numberInt" : "3" } } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": 2 } }', '{ "c": { "$eq": [ "$$ROOT.a.b", 2 ] } }'); bson_expression_get --------------------------------------------------------------------- { "c" : true } (1 row) SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": 2 } }', '{ "c": { "$eq": [ "$$ROOT.a.b", 3 ] } }'); bson_expression_get --------------------------------------------------------------------- { "c" : false } (1 row) -- override $$CURRENT should change the meaning of path expressions since $a -> $$CURRENT.a SELECT * FROM bson_dollar_project('{"a": 1}', '{"b": {"$filter": {"input": [{"a": 10, "b": 8}, {"a": 7, "b": 8}], "as": "CURRENT", "cond": {"$and": [{"$gt": ["$a", 8]}, {"$gt": ["$b", 7]}]}}}}'); bson_dollar_project --------------------------------------------------------------------- { "b" : [ { "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "8" } } ] } (1 row) -- $reduce with multiple documents in a collection to ensure variable context is reset between every row evaluation SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 1, "a": ["a", "b", "c"]}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 2, "a": ["d", "e", "f"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 3, "a": ["g", "h", "i"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select bson_dollar_project(document, '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }') from documentdb_api.collection('db', 'remove_variable_tests'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : "abc" } { "_id" : { "$numberInt" : "2" }, "result" : "def" } { "_id" : { "$numberInt" : "3" }, "result" : "ghi" } (3 rows) -- $$REMOVE should not be written select bson_dollar_project('{}', '{"result": "$$REMOVE" }'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) select bson_dollar_project(document, '{"result": [ "$a", "$$REMOVE", "final" ] }') from documentdb_api.collection('db', 'remove_variable_tests'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : [ [ "a", "b", "c" ], null, "final" ] } { "_id" : { "$numberInt" : "2" }, "result" : [ [ "d", "e", "f" ], null, "final" ] } { "_id" : { "$numberInt" : "3" }, "result" : [ [ "g", "h", "i" ], null, "final" ] } (3 rows) select bson_dollar_project(document, '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$REMOVE", "$$this"] } } } }') from documentdb_api.collection('db', 'remove_variable_tests'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : null } { "_id" : { "$numberInt" : "2" }, "result" : null } { "_id" : { "$numberInt" : "3" }, "result" : null } (3 rows) -- $let aggregation operator -- verify that defined variables work SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": "$$foo"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "this is my foo variable" } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"sum": {"$add": ["$a", 10]}}, "in": "$$sum"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "20" } } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"sumValue": {"$add": ["$a", 10]}}, "in": "$$sumValue"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "20" } } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$a"}, "in": "$$value"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "10" } } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$CURRENT"}, "in": "$$value"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "10" } } } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$ROOT"}, "in": "$$value"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : { "$numberInt" : "10" } } } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$REMOVE"}, "in": "$$value"}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"日本語": 10}, "in": "$$日本語"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "10" } } (1 row) -- verify nested let work and can also override variables SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo2": "$$foo"}, "in": {"a": "$$foo", "b": "$$foo2"}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "this is my foo variable", "b" : "this is my foo variable" } } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "$$foo"}, "in": {"a": "$$foo"}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "this is my foo variable" } } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "this is a foo override"}, "in": {"a": "$$foo"}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "this is a foo override" } } (1 row) SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo2": "$$foo"}, "in": {"$let": {"vars": {"foo3": "this is my foo3 variable"}, "in": {"foo": "$$foo", "foo2": "$$foo2", "foo3": "$$foo3"}}}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "foo" : "this is my foo variable", "foo2" : "this is my foo variable", "foo3" : "this is my foo3 variable" } } (1 row) -- nested works with expressions that define variables SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$let": {"vars": {"value": "100"}, "in": {"$filter": {"input": "$input", "as": "value", "cond": {"$gte": ["$$value", 4]}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$let": {"vars": {"value": "100"}, "in": {"$filter": {"input": "$input", "as": "this", "cond": {"$gte": ["$$value", 4]}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$filter": {"input": "$input", "as": "value", "cond": {"$let": {"vars": {"value": 100}, "in": {"$gte": ["$$value", 4]}}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) -- override current SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"CURRENT": {"a": "this is a in new current"}}, "in": "$a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "this is a in new current" } (1 row) -- use dotted paths on variable expressions SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": {"a": "value a field"}}, "in": "$$value.a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "value a field" } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": [{"a": "nested field in array"}]}, "in": "$$value.a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : [ "nested field in array" ] } (1 row) SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": {"a": "value a field"}}, "in": "$$value.nonExistent"}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- test with multiple rows on a collection and a non constant spec such that caching is not in the picture to test we don't have memory corruption on the variable data itself SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 1, "name": "santi", "hobby": "running"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 2, "name": "joe", "hobby": "soccer"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 3, "name": "daniel", "hobby": "painting"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 4, "name": "lucas", "hobby": "music"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 5, "name": "richard", "hobby": "running"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 6, "name": "daniela", "hobby": "reading"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 7, "name": "isabella", "hobby": "video games"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 8, "name": "daniel II", "hobby": "board games"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 9, "name": "jose", "hobby": "music"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 10, "name": "camille", "hobby": "painting"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_project(document, FORMAT('{"result": {"$let": {"vars": {"intro": "%s", "hobby_text": " , and my hobby is: "}, "in": {"$concat": ["$$intro", "$name", "$$hobby_text", "$hobby"]}}}}', 'Hello my name is: ')::bson) FROM documentdb_api.collection('db', 'dollar_let_test'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : "Hello my name is: santi , and my hobby is: running" } { "_id" : { "$numberInt" : "2" }, "result" : "Hello my name is: joe , and my hobby is: soccer" } { "_id" : { "$numberInt" : "3" }, "result" : "Hello my name is: daniel , and my hobby is: painting" } { "_id" : { "$numberInt" : "4" }, "result" : "Hello my name is: lucas , and my hobby is: music" } { "_id" : { "$numberInt" : "5" }, "result" : "Hello my name is: richard , and my hobby is: running" } { "_id" : { "$numberInt" : "6" }, "result" : "Hello my name is: daniela , and my hobby is: reading" } { "_id" : { "$numberInt" : "7" }, "result" : "Hello my name is: isabella , and my hobby is: video games" } { "_id" : { "$numberInt" : "8" }, "result" : "Hello my name is: daniel II , and my hobby is: board games" } { "_id" : { "$numberInt" : "9" }, "result" : "Hello my name is: jose , and my hobby is: music" } { "_id" : { "$numberInt" : "10" }, "result" : "Hello my name is: camille , and my hobby is: painting" } (10 rows) -- negative cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": [1, 2, 3]}}'); ERROR: $let can accept only an object type as its argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": true, "in": "a"}}}'); ERROR: Parameter is invalid: an object type was expected (vars) SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {}}}}'); ERROR: 'in' parameter is missing for $let SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": {"$let": {"in": "$a"}}}'); ERROR: 'vars' parameter for $let is missing SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": [], "in": "$$123"}}}'); ERROR: Parameter is invalid: an object type was expected (vars) SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"123": "123 variable"}, "in": "$$123"}}}'); ERROR: The variable name '123' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"ROOT": "new root"}, "in": "$$ROOT"}}}'); ERROR: The variable name 'ROOT' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"REMOVE": "new remove"}, "in": "$$REMOVE"}}}'); ERROR: The variable name 'REMOVE' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"MyVariable": "MyVariable"}, "in": "$$MyVariable"}}}'); ERROR: The variable name 'MyVariable' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"_variable": "_variable"}, "in": "$$_variable"}}}'); ERROR: The variable name '_variable' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"with space": "with space"}, "in": "$$with space"}}}'); ERROR: The variable name 'with space' contains an invalid character ' '. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"hello!": "with space"}, "in": "$$FOO"}}}'); ERROR: The variable name 'hello!' contains an invalid character '!'. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$_variable"}}}'); ERROR: The variable name '_variable' begins with a character that is not valid for user-defined variables SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$with spaces"}}}'); ERROR: The variable name 'with spaces' contains an invalid character ' '. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$hello!"}}}'); ERROR: The variable name 'hello!' contains an invalid character '!'. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$FOO"}}}'); ERROR: Attempting to use an undefined variable: FOO SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$.a"}}}'); ERROR: Variable names cannot be left empty SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$variable."}}}'); ERROR: The FieldPath cannot terminate with a '.' character. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"a.b": "a.b"}, "in": "$$a.b"}}}'); ERROR: The variable name 'a.b' contains an invalid character '.'. SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "$$foo2"}, "in": {"a": "$$foo"}}}}}}'); ERROR: Attempting to use an undefined variable: foo2 -- $$NOW SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"1", "a": "umbor" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"2", "a": "gabby" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"3", "a": "jo" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- $$NOW with dotted expression should evaluate to EOD SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$NOW.foo" }, "filter": {} }'); document --------------------------------------------------------------------- { "_id" : "1" } { "_id" : "2" } { "_id" : "3" } (3 rows) CREATE SCHEMA time_system_variables_test; -- Function to replace the value of $$NOW with NOW_SYS_VARIABLE CREATE OR REPLACE FUNCTION time_system_variables_test.mask_time_value(query text, out result text) RETURNS SETOF TEXT AS $$ BEGIN FOR result IN EXECUTE query LOOP RETURN QUERY SELECT REGEXP_REPLACE( result, '\{\s*"\$date"\s*:\s*\{\s*"\$numberLong"\s*:\s*"[0-9]+"\s*\}\s*\}', 'NOW_SYS_VARIABLE', 'g' ); END LOOP; RETURN; END; $$ LANGUAGE plpgsql; SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$NOW" }, "filter": {} }') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : "1", "nowField" : NOW_SYS_VARIABLE } { "_id" : "2", "nowField" : NOW_SYS_VARIABLE } { "_id" : "3", "nowField" : NOW_SYS_VARIABLE } (3 rows) SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$NOW" } }') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : "1", "nowField" : NOW_SYS_VARIABLE } { "_id" : "2", "nowField" : NOW_SYS_VARIABLE } { "_id" : "3", "nowField" : NOW_SYS_VARIABLE } (3 rows) SELECT time_system_variables_test.mask_time_value($Q$ EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$NOW" } }') $Q$); mask_time_value --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "nowField" : "$$varRef" }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : NOW_SYS_VARIABLE } } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4912_4910033 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4912'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4912_4910033 collection Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "nowField" : "$$varRef" }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : NOW_SYS_VARIABLE } } }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4912'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4912'::bigint) (12 rows) SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": "$$NOW" } }') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : "1", "a" : "umbor", "nowField" : NOW_SYS_VARIABLE, "c" : true } { "_id" : "2", "a" : "gabby", "nowField" : NOW_SYS_VARIABLE, "c" : true } { "_id" : "3", "a" : "jo", "nowField" : NOW_SYS_VARIABLE, "c" : true } (3 rows) SELECT time_system_variables_test.mask_time_value($Q$ EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": "$$NOW" } }') $Q$); mask_time_value --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "nowField" : "$$varRef", "c" : { "$lt" : [ "$_id", "$$varRef" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : NOW_SYS_VARIABLE } } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4912_4910033 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4912'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4912_4910033 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "nowField" : "$$varRef", "c" : { "$lt" : [ "$_id", "$$varRef" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : NOW_SYS_VARIABLE } } }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4912'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4912'::bigint) (12 rows) SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ] }') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : "1", "a" : "umbor", "nowField" : NOW_SYS_VARIABLE } { "_id" : "2", "a" : "gabby", "nowField" : NOW_SYS_VARIABLE } { "_id" : "3", "a" : "jo", "nowField" : NOW_SYS_VARIABLE } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "nowField" : "$$NOW" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4912_4910033 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4912'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4912_4910033 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "nowField" : "$$NOW" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4912'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4912'::bigint) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "other": "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$NOW" ]} }, "let": { "varRef": "3" } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "other" : "$$varRef" }'::documentdb_core.bson, '{ "$expr" : { "$lt" : [ "$_id", "$$NOW" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : "3" } } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4912_4910033 collection WHERE (documentdb_api_internal.bson_dollar_expr(document, '{ "" : { "$lt" : [ "$_id", "$$NOW" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : "3" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4912'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4912_4910033 collection Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "other" : "$$varRef" }'::documentdb_core.bson, '{ "$expr" : { "$lt" : [ "$_id", "$$NOW" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : "3" } } }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4912'::bigint) Filter: documentdb_api_internal.bson_dollar_expr(collection.document, '{ "" : { "$lt" : [ "$_id", "$$NOW" ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : "3" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4912'::bigint) (13 rows) -- $$NOW in $lookup SELECT documentdb_api.insert_one('db','now_test_from','{"_id":1,"a":"alpha","b":["x","y"],"c":10,"d":["m","n"]}',NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_from','{"_id":2,"a":"beta","b":["p","q"],"c":20,"d":["z"]}',NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_to','{"_id":1,"x":"x","a":"alpha","c":10}',NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_to','{"_id":2,"x":"p","a":"beta","y":"t","c":20}',NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_to','{"_id":3,"x":"p","a":"beta","y":"z","c":30}',NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_from_2','{"_id":1,"z":"val1","c":10}',NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','now_test_from_2','{"_id":2,"z":"val2","c":20}',NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT time_system_variables_test.mask_time_value($q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$match":{"$expr":{"$eq":["$c","$$c"]}}},{"$addFields":{"newC":"$$c","now":"$$NOW"}}],"as":"joined","localField":"a","foreignField":"a","let":{"c":"$c"}}}],"cursor":{}}') $q$); mask_time_value --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : "x", "a" : "alpha", "c" : { "$numberInt" : "10" }, "joined" : [ { "_id" : { "$numberInt" : "1" }, "a" : "alpha", "b" : [ "x", "y" ], "c" : { "$numberInt" : "10" }, "d" : [ "m", "n" ], "newC" : { "$numberInt" : "10" }, "now" : NOW_SYS_VARIABLE } ] } { "_id" : { "$numberInt" : "2" }, "x" : "p", "a" : "beta", "y" : "t", "c" : { "$numberInt" : "20" }, "joined" : [ { "_id" : { "$numberInt" : "2" }, "a" : "beta", "b" : [ "p", "q" ], "c" : { "$numberInt" : "20" }, "d" : [ "z" ], "newC" : { "$numberInt" : "20" }, "now" : NOW_SYS_VARIABLE } ] } { "_id" : { "$numberInt" : "3" }, "x" : "p", "a" : "beta", "y" : "z", "c" : { "$numberInt" : "30" }, "joined" : [ ] } (3 rows) SELECT time_system_variables_test.mask_time_value($q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$sort":{"_id":1}},{"$match":{"$expr":{"$eq":["$c","$$NOW"]}}}],"as":"joined","localField":"a","foreignField":"a","let":{"c":"$c"}}}],"cursor":{}}') $q$); mask_time_value --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : "x", "a" : "alpha", "c" : { "$numberInt" : "10" }, "joined" : [ ] } { "_id" : { "$numberInt" : "2" }, "x" : "p", "a" : "beta", "y" : "t", "c" : { "$numberInt" : "20" }, "joined" : [ ] } { "_id" : { "$numberInt" : "3" }, "x" : "p", "a" : "beta", "y" : "z", "c" : { "$numberInt" : "30" }, "joined" : [ ] } (3 rows) SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$addFields":{"extra":"$$NOW"}},{"$lookup":{"from":"now_test_from_2","localField":"z","foreignField":"c","as":"inner","let":{"v":"$c"},"pipeline":[{"$match":{"$expr":{"$eq":["$z","$$v"]}}}]}}],"as":"joined","localField":"a","foreignField":"a"}}],"cursor":{}}') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : "x", "a" : "alpha", "c" : { "$numberInt" : "10" }, "joined" : [ { "_id" : { "$numberInt" : "1" }, "a" : "alpha", "b" : [ "x", "y" ], "c" : { "$numberInt" : "10" }, "d" : [ "m", "n" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } { "_id" : { "$numberInt" : "2" }, "x" : "p", "a" : "beta", "y" : "t", "c" : { "$numberInt" : "20" }, "joined" : [ { "_id" : { "$numberInt" : "2" }, "a" : "beta", "b" : [ "p", "q" ], "c" : { "$numberInt" : "20" }, "d" : [ "z" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } { "_id" : { "$numberInt" : "3" }, "x" : "p", "a" : "beta", "y" : "z", "c" : { "$numberInt" : "30" }, "joined" : [ { "_id" : { "$numberInt" : "2" }, "a" : "beta", "b" : [ "p", "q" ], "c" : { "$numberInt" : "20" }, "d" : [ "z" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } (3 rows) SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$addFields":{"extra":"$$NOW"}},{"$lookup":{"from":"now_test_from_2","localField":"z","foreignField":"c","as":"inner","let":{"v":"$$NOW"},"pipeline":[{"$match":{"$expr":{"$eq":["$z","$$v"]}}}]}}],"as":"joined","localField":"a","foreignField":"a"}}],"cursor":{}}') $Q$); mask_time_value --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : "x", "a" : "alpha", "c" : { "$numberInt" : "10" }, "joined" : [ { "_id" : { "$numberInt" : "1" }, "a" : "alpha", "b" : [ "x", "y" ], "c" : { "$numberInt" : "10" }, "d" : [ "m", "n" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } { "_id" : { "$numberInt" : "2" }, "x" : "p", "a" : "beta", "y" : "t", "c" : { "$numberInt" : "20" }, "joined" : [ { "_id" : { "$numberInt" : "2" }, "a" : "beta", "b" : [ "p", "q" ], "c" : { "$numberInt" : "20" }, "d" : [ "z" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } { "_id" : { "$numberInt" : "3" }, "x" : "p", "a" : "beta", "y" : "z", "c" : { "$numberInt" : "30" }, "joined" : [ { "_id" : { "$numberInt" : "2" }, "a" : "beta", "b" : [ "p", "q" ], "c" : { "$numberInt" : "20" }, "d" : [ "z" ], "extra" : NOW_SYS_VARIABLE, "inner" : [ ] } ] } (3 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate":"now_test_to", "pipeline":[{ "$match":{ "_id":3 }},{ "$addFields":{ "nowField1":"$$NOW" }},{ "$lookup":{ "from":"now_test_from", "pipeline":[{ "$addFields":{ "nowField2":"$$NOW" }},{ "$lookup":{ "from":"now_test_from_2", "localField":"z", "foreignField":"c", "as":"inner", "let":{ "v":"$c" }, "pipeline":[{ "$match":{ "$expr":{ "$eq":["$z","$$v"] }}}] }}], "as":"joined", "localField":"a", "foreignField":"a" }}], "cursor":{} }') \gset \set result0 :document SELECT :'result0'::json->>'nowField1' = :'result0'::json->'joined'->0->>'nowField2'; ?column? --------------------------------------------------------------------- t (1 row) -- $$NOW in transactions. We expect same values. SELECT documentdb_api.insert_one('db','now_test_2','{"_id": 0}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result1 :document SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result2 :document SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result3 :document SELECT :'result1'::bson->>'nowField' = :'result2'::bson->>'nowField' AND :'result2'::bson->>'nowField' = :'result3'::bson->>'nowField'; ?column? --------------------------------------------------------------------- t (1 row) END; -- $$NOW outside transaction block. We expect different values. SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result4 :document SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result5 :document SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result6 :document SELECT :'result4'::bson->>'nowField' <> :'result5'::bson->>'nowField' AND :'result5'::bson->>'nowField' <> :'result6'::bson->>'nowField'; ?column? --------------------------------------------------------------------- t (1 row) -- Earlier queries should have higher $$NOW values SELECT :'result4'::bson->>'nowField' < :'result5'::bson->>'nowField' AND :'result5'::bson->>'nowField' < :'result6'::bson->>'nowField'; ?column? --------------------------------------------------------------------- t (1 row) -- $$NOW with cursors CREATE TYPE time_system_variables_test.drain_result AS (filteredDoc bson, nowCompareResult bool, persistConnection bool); DO $$ DECLARE i int; BEGIN FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'now_cursor_tests', FORMAT('{ "_id": %s }', i)::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection -- Drains a find query and compares the value of 'nowField' across all batches returned by the cursor. CREATE FUNCTION time_system_variables_test.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL) RETURNS SETOF time_system_variables_test.drain_result AS $$ DECLARE i int; doc bson; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; currentBatch jsonb[]; currentDoc jsonb; currentNowValue text; finalResult bool; BEGIN WITH r1 AS (SELECT 'now_cursor_tests' AS "find", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'now_cursor_tests' AS "collection", 4294967295::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967295); finalResult := TRUE; currentNowValue := ((doc->>'cursor')::bson->>'firstBatch')::jsonb->0->>'nowField'; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, persistConn)::time_system_variables_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); currentBatch := ( SELECT ARRAY( SELECT jsonb_array_elements( ((doc->>'cursor')::bson->>'nextBatch')::jsonb) ) ); IF currentBatch IS NOT NULL AND array_length(currentBatch, 1) > 0 THEN FOR i IN 1..array_length(currentBatch, 1) LOOP currentDoc := currentBatch[i]; finalResult := finalResult AND (currentNowValue = currentDoc->>'nowField'); currentNowValue := currentDoc->>'nowField'; END LOOP; END IF; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- Drains an aggregate query and compares the value of 'nowField' across all batches returned by the cursor. CREATE FUNCTION time_system_variables_test.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, singleBatch bool DEFAULT NULL) RETURNS SETOF time_system_variables_test.drain_result AS $$ DECLARE i int; doc bson; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; currentBatch jsonb[]; currentDoc jsonb; currentNowValue text; finalResult bool; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'now_cursor_tests' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'now_cursor_tests' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); finalResult := TRUE; currentNowValue := ((doc->>'cursor')::bson->>'firstBatch')::jsonb->0->>'nowField'; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); currentBatch := ( SELECT ARRAY( SELECT jsonb_array_elements( ((doc->>'cursor')::bson->>'nextBatch')::jsonb) ) ); IF currentBatch IS NOT NULL AND array_length(currentBatch, 1) > 0 THEN FOR i IN 1..array_length(currentBatch, 1) LOOP currentDoc := currentBatch[i]; finalResult := finalResult AND (currentNowValue = currentDoc->>'nowField'); currentNowValue := currentDoc->>'nowField'; END LOOP; END IF; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; SELECT time_system_variables_test.mask_time_value($Q$ SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "now_cursor_tests", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ], "cursor": { "batchSize": 2 } }', 4294967294); $Q$); mask_time_value --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests", "firstBatch" : [ { "_id" : { "$numberInt" : "1" }, "nowField" : NOW_SYS_VARIABLE }, { "_id" : { "$numberInt" : "2" }, "nowField" : NOW_SYS_VARIABLE } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "nowField": "$$NOW" }'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | t | f | t | f | t | f | t | f (13 rows) SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1, "nowField": "$$NOW" }'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | t | f | t | f | t | f | t | f (13 rows) SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 2, project => '{ "a": 1, "nowField": "$$NOW" }'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | t | f | t | f | t | f | t | f | t | f | t | f | t | f | t | f | t | f (13 rows) SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 12, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | t | f | t | f | t | f | t | f | t | f | t | f | t | f | t | f | t | f (13 rows) SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | t | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | t | f | t | f | t | f | t | f (13 rows) SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}', singleBatch => TRUE); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | t | f | t | f | t | f | t | f | t | f (5 rows) SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$project": { "nowField": "$$NOW" } }, { "$limit": 3 }]}'); filtereddoc | nowcompareresult | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.now_cursor_tests" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | t | f | t | f | t | f | t | f | t | f (5 rows) bson_aggregation_file_cursor_tests.out000066400000000000000000010354101507310017400376560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, public; SET citus.next_shard_id TO 3160000; SET documentdb.next_collection_id TO 3160; SET documentdb.next_collection_index_id TO 3160; SET citus.multi_shard_modify_mode TO 'sequential'; set documentdb.useFileBasedPersistedCursors to on; CREATE SCHEMA aggregation_cursor_test_file; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test_file', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }', i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection CREATE TYPE aggregation_cursor_test_file.drain_result AS (filteredDoc bson, docSize int, continuationFiltered bson, persistConnection bool); CREATE FUNCTION aggregation_cursor_test_file.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL, sort bson DEFAULT NULL, filter bson default null, obfuscate_id bool DEFAULT false) RETURNS SETOF aggregation_cursor_test_file.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; BEGIN WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "find", filter AS "filter", sort AS "sort", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test_file.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test_file.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; CREATE FUNCTION aggregation_cursor_test_file.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, obfuscate_id bool DEFAULT false, singleBatch bool DEFAULT NULL) RETURNS SETOF aggregation_cursor_test_file.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test_file.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test_file.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- PERSISTED BASED: -- test getting the first page (with max page size) - should limit to 2 docs at a time. SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 6, limitVal => 300000, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (7 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 6, pageSize => 100000, pipeline => '{ "": [{ "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (7 rows) -- test smaller docs (500KB) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, limitVal => 300000, pageSize => 100000, project => '{ "a": 1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "10" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 6000353 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "10" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 6000353 | | f | | | f | | | f (3 rows) -- test smaller batch size(s) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 0, project => '{ "a": 1 }', limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (3 rows) -- this will fail (with cursor in use) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1 }', limitVal => 300000); ERROR: could not open temporary file "pg_documentdb_cursor_files/cursor_4294967294": File exists CONTEXT: SQL statement "SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967294)" PL/pgSQL function aggregation_cursor_test_file.drain_find_query(integer,integer,bson,integer,integer,bson,bson,boolean) line 19 at SQL statement SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967294::int8]); delete_cursors --------------------------------------------------------------------- { } (1 row) -- now this works SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 2, project => '{ "a": 1 }', limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200152 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 3, project => '{ "a": 1 }', limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800178 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800177 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAACadxsAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800177 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600127 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 0, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArI5bAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (3 rows) SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967294::int8]); delete_cursors --------------------------------------------------------------------- { } (1 row) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 600128 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADeJwkAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAACadxsAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "5" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "6" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABWxy0AzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "7" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "8" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAASF0AAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "9" } ] } | 600127 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADwPkkAzmZSAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600127 | | f | | | f | | | f | | | f (13 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200152 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 1800178 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1800177 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAACadxsAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 1800177 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYAEhdAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "10" } ] } | 600127 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$skip": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1800178 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANO82AA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] } | 1800177 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAACadxsANO82AA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "3" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1800177 | | f | | | f | | | f (5 rows) -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', skipVal => 0, limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 300000 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200152 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654038 | | f | | | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 1200136 | | f | | | f (2 rows) BEGIN; SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) ROLLBACK; -- With local execution off. set citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', limitVal => 300000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160002" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160002" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160002" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "3" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } | 1200152 | | f | | | f (6 rows) RESET citus.enable_local_execution; -- with sharded SELECT documentdb_api.shard_collection('db', 'get_aggregation_cursor_test_file', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160022" }, { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (7 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 6, pageSize => 100000); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160022" }, { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (7 rows) -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "7" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "8" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "6" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "2" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "$numberInt" : "4" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "8" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "9" }, { "$numberInt" : "3" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ] } | 1200152 | | f | | | f (6 rows) -- With local execution off. set citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "filter" : { "_id" : { "$gt" : { "$numberInt" : "2" } } }, "batchSize" : { "$numberInt" : "100000" } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1, obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "1" }, "qc" : { "find" : "get_aggregation_cursor_test_file", "limit" : { "$numberInt" : "1" }, "batchSize" : { "$numberInt" : "0" } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "10" }, { "$numberInt" : "9" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBOKIFAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | | f | | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$match" : { "_id" : { "$gt" : { "$numberInt" : "2" } } } } ], "cursor" : { "batchSize" : { "$numberInt" : "100000" } } }, "continuation" : [ { "table_name" : "documents_3160_3160016" }, { "table_name" : "documents_3160_3160021" }, { "table_name" : "documents_3160_3160017" }, { "table_name" : "documents_3160_3160019" }, { "table_name" : "documents_3160_3160018" } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtEVWAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654037 | | f | | | f | | | f | | | f (5 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "1" }, "ids" : [ { "a" : "1" } ] } | 5654038 | | f | | | f | | | f (3 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 103 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "0" }, "ids" : [ ] } | 102 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "get_aggregation_cursor_test_file", "pipeline" : [ { "$limit" : { "$numberInt" : "1" } } ], "cursor" : { "batchSize" : { "$numberInt" : "0" } } }, "continuation" : [ ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f (2 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307973 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAABoi6wAoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAADQFlkBoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA4ogUCoC2yAg==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 11307972 | | f | | | f (6 rows) SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }', obfuscate_id => true); filtereddoc | docsize | continuationfiltered | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200153 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAC8TxIA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAB4nyQA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200152 | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAA07zYA8D5JAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.get_aggregation_cursor_test_file" }, "ok" : { "$numberDouble" : "1.0" }, "batchCount" : { "$numberInt" : "2" }, "ids" : [ { "a" : "1" }, { "a" : "1" } ] } | 1200152 | | f | | | f (6 rows) RESET citus.enable_local_execution; -- start draining first page first (should not persist connection and have a query file) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967291" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967291" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967291", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3MjkxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%4294967291%' ORDER BY 1; f --------------------------------------------------------------------- cursor_4294967291 (1 row) -- can't reuse the same cursorId SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); ERROR: could not open temporary file "pg_documentdb_cursor_files/cursor_4294967291": File exists SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967291::int8]); delete_cursors --------------------------------------------------------------------- { } (1 row) SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%4294967291%' ORDER BY 1; f --------------------------------------------------------------------- (0 rows) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967291" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967291" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967291", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3MjkxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) -- set max cursors to 5 set documentdb.maxCursorFileCount to 5; SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967292); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967292" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967292" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967292", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3MjkyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967293); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967293" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967293" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967293", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3MjkzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967294); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967294", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967295); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967295" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967295", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967296); ERROR: Could not reserve a cursor - all cursors are in use and not expired -- delete a cursor and see that it succeeds one time. SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%429496729%' ORDER BY 1; f --------------------------------------------------------------------- cursor_4294967291 cursor_4294967292 cursor_4294967293 cursor_4294967294 cursor_4294967295 (5 rows) SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967295::int8]); delete_cursors --------------------------------------------------------------------- { } (1 row) SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%429496729%' ORDER BY 1; f --------------------------------------------------------------------- cursor_4294967291 cursor_4294967292 cursor_4294967293 cursor_4294967294 (4 rows) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967295); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967295" }, "ns" : "db.get_aggregation_cursor_test_file", "firstBatch" : [ { "_id" : { "$numberInt" : "6" } }, { "_id" : { "$numberInt" : "2" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967295" }, "qp" : true, "qk" : { "$numberInt" : "1" }, "qn" : "cursor_4294967295", "qf" : { "$binary" : { "base64" : "MAEAAHBnX2RvY3VtZW50ZGJfY3Vyc29yX2ZpbGVzL2N1cnNvcl80Mjk0OTY3Mjk1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzRgAAA==", "subType" : "00" } }, "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | f (1 row) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967298); ERROR: Could not reserve a cursor - all cursors are in use and not expired bson_aggregation_miscellaneous_operators_tests.out000066400000000000000000000045501507310017400423030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4900000; SET documentdb.next_collection_id TO 4900; SET documentdb.next_collection_index_id TO 4900; CREATE OR REPLACE FUNCTION generate_random_values(p_doc bson, p_rand_spec bson) RETURNS bool AS $$ DECLARE random_number numeric; BEGIN FOR cnt in 1..3000 LOOP SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8 INTO random_number; IF random_number < 0 AND random_number >= 1 THEN RAISE NOTICE '$rand generated out of range double value'; RETURN false; END IF; END LOOP; RETURN true; END $$ LANGUAGE plpgsql; -- $rand error cases where the value of $rand non - object / non empty SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": 5 } }'); ERROR: Expected 'array' or 'document' type for $rand but found 'int' type CONTEXT: SQL statement "SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8" PL/pgSQL function generate_random_values(bson,bson) line 7 at SQL statement SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": false } }'); ERROR: Expected 'array' or 'document' type for $rand but found 'bool' type CONTEXT: SQL statement "SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8" PL/pgSQL function generate_random_values(bson,bson) line 7 at SQL statement SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": [5] } }'); ERROR: Expected 0 arguments to be present for $rand CONTEXT: SQL statement "SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8" PL/pgSQL function generate_random_values(bson,bson) line 7 at SQL statement SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": {"value": 5} } }'); ERROR: Expected 0 arguments to be present for $rand CONTEXT: SQL statement "SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8" PL/pgSQL function generate_random_values(bson,bson) line 7 at SQL statement -- $rand valid empty params SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": {} } }'); generate_random_values --------------------------------------------------------------------- t (1 row) SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": [] } }'); generate_random_values --------------------------------------------------------------------- t (1 row) bson_aggregation_object_operators_tests.out000066400000000000000000000755011507310017400407120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 367000; SET documentdb.next_collection_id TO 3670; SET documentdb.next_collection_index_id TO 3670; -- -- $mergeObjects operator -- -- simple merge SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": {"a": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "1" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "1"}, {"b": true}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "1", "b" : true } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "1"}, {"b": true, "c": 2}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "1", "b" : true, "c" : { "$numberInt" : "2" } } } (1 row) -- null and undefined return empty doc SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": "$undefinedField"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [null, null, null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [null, "$undefinedField", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "onlyDoc"}, "$undefinedField", null]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "a" : "onlyDoc" } } (1 row) -- with field expressions referencing parent doc SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }}', '{"result": { "$mergeObjects": "$b"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : [ true, "1" ] } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : [ true, "1" ], "foo" : true } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c", "$b"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "foo" : true, "d" : [ true, "1" ] } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c", "$d"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "foo" : true } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": { "f": [true, "1"] }}, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c.d", "$b.d"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "f" : [ true, "1" ] } } (1 row) -- last path found wins when there is a clash SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": false}}', '{"result": { "$mergeObjects": ["$b", "$c"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : false } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": false}}', '{"result": { "$mergeObjects": ["$b", "$c", {"d": "this is my final string"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : "this is my final string" } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": { "z": false}}}', '{"result": { "$mergeObjects": ["$b", {"d": "this is my final string"}, "$c.d"]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : "this is my final string", "z" : false } } (1 row) SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": { "z": false}}}', '{"result": { "$mergeObjects": [{"d": "this is my final string"}, "$b", "$c.d", {"hello": "world"}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "d" : [ true, "1" ], "z" : false, "hello" : "world" } } (1 row) -- nested expressions are evaluated on result document SELECT * FROM bson_dollar_project('{"_id": 4, "a": 1}', '{"result": { "$mergeObjects": [{"id": { "$add": ["$_id", "$a"]}}]}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "result" : { "id" : { "$numberInt" : "5" } } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"isArray": {"$isArray": "$a.b"}}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "b" : [ "1", "2", "3" ], "isArray" : true } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"b": [{"$literal": "$b"}]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "b" : [ "$b" ] } } (1 row) SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"b": [{"$literal": "$b"}, "$a"]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "b" : [ "$b", { "b" : [ "1", "2", "3" ] } ] } } (1 row) -- -- expressions that evaluate to non objects are not valid SELECT * FROM bson_dollar_project('{"_id": 4, "a": 1}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); ERROR: Expected 'document' type for $mergeObjects but value 1 has 'int' type SELECT * FROM bson_dollar_project('{"_id": 4, "a": "string"}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); ERROR: Expected 'document' type for $mergeObjects but value "string" has 'string' type SELECT * FROM bson_dollar_project('{"_id": 4, "a": true}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); ERROR: Expected 'document' type for $mergeObjects but value true has 'bool' type SELECT * FROM bson_dollar_project('{"_id": 4, "a": 2.0}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); ERROR: Expected 'document' type for $mergeObjects but value 2 has 'double' type SELECT * FROM bson_dollar_project('{"_id": 4, "a": 2.0}', '{"result": { "$mergeObjects": [{"$add": [1, 2, 3]}]}}'); ERROR: Expected 'document' type for $mergeObjects but value 6 has 'int' type -- $setField operator -- $setField should be given an Object no array SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": {"$setField": [ "field", "input", "value" ]}}}'); ERROR: Expected 'document' type for $setField -- Extra param called thing gives an error SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "thing": "a", "field": "a", "input": "$$ROOT", "value": "newValue" } }]}}'); ERROR: $setField encountered an unrecognized argument value: thing -- All required args -and- input param of field is a number SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": 123, "input": "$$ROOT", "value": "newValue" } }]}}'); ERROR: Expected 'string' type for $setField but found 'int' type -- All required args -and- input: $$ROOT SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "input": "$$ROOT", "value": "newValue" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "newValue" } ] } } (1 row) -- Missing param input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "value": "newValue" } }]}}'); ERROR: $setField needs the 'input' parameter to be explicitly specified -- Missing param field SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "input": "$$ROOT", "value": "newValue" } }]}}'); ERROR: $setField cannot proceed unless the 'field' parameter is explicitly defined -- Missing param value SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "input": "$$ROOT" } }]}}'); ERROR: The $setField requires that a 'value' parameter be explicitly provided -- Wrong type for field, must be a string not null or bool SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [ { "$literal": "b"}, {"$setField": { "field": true, "value": "REMOVE" } }]}}'); ERROR: $setField needs the 'input' parameter to be explicitly specified SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [ { "$literal": "b"}, {"$setField": { "field": null, "value": "REMOVE" } }]}}'); ERROR: $setField needs the 'input' parameter to be explicitly specified -- The next item should add "$x.y.z" : "newValue" to the input doc {"a":"b"} SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "newValue" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b", "$x.y.z" : "newValue" } ] } } (1 row) -- Not yet implemented fully for $$REMOVE -- SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": {"field": "a", "input": "$$ROOT", "value": "$$REMOVE" } }]}}'); -- here we test the "value" as magic value $$REMOVE as value, that should remove "baz" from the input, using $literal as means to give field name. Field not present SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b" } ] } } (1 row) -- here we test the "value" as magic $$REMOVE as part of the value, that should not remove "baz" from the input, using $literal as means to give field name. Field not present SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "no$$REMOVE" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b", "$x.y.z" : "no$$REMOVE" } ] } } (1 row) -- here we test the "value" as magic $$REMOVE that should remove "baz" from the input, using $literal as means to give field name. Field *is* present. SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "baz"}, "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b" } ] } } (1 row) -- here we test the "value" as magic $$REMOVE that should remove "baz" from the input. Same as prev test w/o using $literal operator. SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b" } ] } } (1 row) -- here we test the "value" as a empty document SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": {} } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b", "baz" : { } } ] } } (1 row) -- here we test the "value" as a document with 1 item SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": { "x" : "y"} } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b", "baz" : { "x" : "y" } } ] } } (1 row) -- Not yet implemented, fully for $$ROOT -- here we use $$ROOT in probably wrong "value" field, should pick up the record { "d1": {"val": "a"}} as the value of the new field SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": "$$ROOT" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "a" : "b", "baz" : { "d1" : { "val" : "a" } } } ] } } (1 row) -- here we use $$ROOT that pickups the { "d1": {"val": "a"}} and should add "baz" : "foooooo" SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": "$$ROOT", "value": "foooooo" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "d1" : { "val" : "a" }, "baz" : "foooooo" } ] } } (1 row) -- Check that we can use dot path like $$ROOT.d1: SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": "$$ROOT.d1", "value": "foooooo" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ { "val" : "a", "baz" : "foooooo" } ] } } (1 row) -- Check that we can use dot path like $$REMOVE in a non $setField context SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$concat": "$$REMOVE" } ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ null ] } } (1 row) -- Inject a null as "input", via "input" SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": null, "value": "foooooo" } }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldA" : [ null ] } } (1 row) -- insert where we overwrite the tail. SELECT * FROM bson_dollar_project('{"a1": { "b": 1, "c": 1, "d": 1 }, "b1": { "d": 2, "e": 3 } }', '{"result": { "$mergeObjects": [ "$a1", "$b1" ]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : { "$numberInt" : "3" } } } (1 row) -- testing multiple scenarios with $$REMOVE to check all work properly SELECT * FROM bson_dollar_project('{"a": 1}', '{ "result": { "$bsonSize": "$$REMOVE" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{"a": 1}', '{ "result": { "$bsonSize": { "a": 1, "test": "$$REMOVE" } } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberInt" : "12" } } (1 row) SELECT * FROM bson_dollar_project('{ "_id": 16, "group": 2, "obj": { "a": 1, "b": 1 } }', '{ "mergedDocument": { "$mergeObjects": ["$obj", { "b": "$$REMOVE" } ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "mergedDocument" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } } (1 row) -- $getField operator SELECT insert_one('db','test_get_field',' { "_id": 0, "a": 1, "b": "test" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- positive cases -- entire expression -- field parsed from $literal SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "a" }, "input": {"a": { "b": 3 }}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "3" } } } } (1 row) -- field parsed from expression SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "a" }, "input": {"a": { "b": 3 }}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "3" } } } } (1 row) -- field is a path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "test_get_field", "pipeline": [{"$project": {"result": {"fieldValue": {"$getField": {"field": "$b", "input": {"test": { "b": 3 }}}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "result" : { "fieldValue" : { "b" : { "$numberInt" : "3" } } } } (1 row) -- input be a system variable SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "a", "input": "$$ROOT"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "3" } } } } (1 row) -- input be null SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "a", "input": null}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : null } } (1 row) -- input be a path SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "$numberInt" : "3" } } } (1 row) -- input be a missing path SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$adf"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) -- input be constant SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "dx"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) -- get array field value SELECT * FROM bson_dollar_project('{"a": { "b": ["1"] }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : [ "1" ] } } (1 row) -- get document field value SELECT * FROM bson_dollar_project('{"a": { "b": {"c": "1"} }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "c" : "1" } } } (1 row) -- field name contains $ and . SELECT * FROM bson_dollar_project('{"a": { "b": {"c": "nested text"}, "b.c": "plain text" }}', '{"result": { "fieldValue": {"$getField": {"field": "b.c", "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : "plain text" } } (1 row) SELECT * FROM bson_dollar_project('{"a": { "$b.01": {"c": "1"} }}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "$b.01" }, "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "c" : "1" } } } (1 row) -- nested expression SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": { "$getField": "a" }}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "$numberInt" : "3" } } } (1 row) -- test pipeline SELECT documentdb_api.insert_one('db','getfield','{"_id":"1", "a": null }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','getfield','{"_id":"2", "a": { "b": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','getfield','{"_id":"3"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "getfield", "pipeline": [ { "$project": { "fieldValue": { "$getField": { "field": "b", "input": "$a" }}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "fieldValue" : null } { "_id" : "2", "fieldValue" : { "$numberInt" : "1" } } { "_id" : "3" } (3 rows) -- shorthand expression -- input will be $$CURRENT SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": "a"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "3" } } } } (1 row) SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": "b"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { } } (1 row) -- negative cases -- full expression -- field is required SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {}}}}'); ERROR: $getField requires that the 'field' parameter must be explicitly specified SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"input": {}}}}}'); ERROR: $getField requires that the 'field' parameter must be explicitly specified -- input is required SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": "a"}}}}'); ERROR: $getField needs the 'input' parameter to be defined -- field must be a string SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": null, "input": {}}}}}'); ERROR: $getField needs 'field' to evaluate to a String type, but received null SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": 1, "input": {}}}}}'); ERROR: $getField needs 'field' to evaluate to a String type, but received int SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": [], "input": {}}}}}'); ERROR: $getField needs 'field' to evaluate to a String type, but received array -- shorthand expression -- field must be a string SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": []}}}'); ERROR: $getField needs 'field' to evaluate to a String type, but received array -- $unsetField -- postive cases -- null input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": null}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : null } } (1 row) -- empty input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { } } } (1 row) -- remove from input argument not current document SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {"a": 1, "b": 2}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "2" } } } } (1 row) -- won't traverse objects automatically with dotted field SELECT * FROM bson_dollar_project('{"a": {"b": 1}, "a.b": 2}', '{"result": { "fieldValue": {"$unsetField": {"field": "a.b", "input": "$$ROOT"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "a" : { "b" : { "$numberInt" : "1" } } } } } (1 row) -- field name starts with $ SELECT * FROM bson_dollar_project('{"$a": 1, "b": 2}', '{"result": { "fieldValue": {"$unsetField": {"field": { "$const": "$a" }, "input": "$$ROOT"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "b" : { "$numberInt" : "2" } } } } (1 row) -- take specific path from current document SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}}', '{"result": { "fieldValue": {"$unsetField": {"field": "b", "input": "$a"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "c" : { "$numberInt" : "2" } } } } (1 row) -- cooperate with getField SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}}', '{"result": { "fieldValue": {"$unsetField": {"field": "b", "input": {"$getField": "a"}}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "c" : { "$numberInt" : "2" } } } } (1 row) -- unset an array SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}, "d": [2, 3]}', '{"result": { "fieldValue": {"$unsetField": {"field": "d", "input": "$$ROOT"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "fieldValue" : { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } } } (1 row) -- negative cases SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": 1}}}'); ERROR: Expected 'document' type for $unsetField SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a"}}}}'); ERROR: $unsetField needs the 'input' parameter to be explicitly specified SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"input": null}}}}'); ERROR: $unsetField cannot proceed unless the 'field' parameter is explicitly defined SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": null, "value": 1}}}}'); ERROR: $unsetField encountered an unrecognized argument value: value SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": {"$add": [2, 3]}, "input": null}}}}'); ERROR: The $unsetField needs the 'field' value to be constant, but a non-constant value was provided instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "$a", "input": null}}}}'); ERROR: A field path reference is being used here, but it is not permitted in this specific context. Perhaps you intended to use the operators {$literal: '$a'} instead? SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": 5, "input": null}}}}'); ERROR: Expected 'string' type for $unsetField but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": ["a"], "input": null}}}}'); ERROR: The $unsetField needs the 'field' value to be constant, but a non-constant value was provided instead. SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": null, "input": null}}}}'); ERROR: Expected 'string' type for $unsetField but found 'null' type SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": 3}}}}'); ERROR: $unsetField needs 'input' to evaluate as an Object type SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {"$add": [2, 3]}}}}}'); ERROR: $unsetField needs 'input' to evaluate as an Object type bson_aggregation_pg17_tests_lookup_inner_join.out000066400000000000000000001045211507310017400417220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 9437000; SET documentdb.next_collection_id TO 94370; SET documentdb.next_collection_index_id TO 94370; \i sql/bson_aggregation_tests_lookup_inner_join_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 1, "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:4: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes','{ "_id" : 2, "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 3, "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 4, "model" : "737", "price" : 50, "quantity" : 30 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 1, "plane_model" : "A330", "gates" : 30 }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:9: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 11, "plane_model" : "A340", "gates" : 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 2, "plane_model" : "A380", "gates" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 3, "plane_model" : "A350", "gates" : 20 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 4, "plane_model" : "737", "gates" : 110 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- set up indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "planes", "indexes": [ { "key": { "model": 1 }, "name": "planes_model_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "gate_availability", "indexes": [ { "key": { "plane_model": 1 }, "name": "plane_model_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Remove primary key ALTER TABLE documentdb_data.documents_7311 DROP CONSTRAINT collection_pk_7311; psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:21: ERROR: relation "documentdb_data.documents_7311" does not exist ALTER TABLE documentdb_data.documents_7312 DROP CONSTRAINT collection_pk_7312; psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:22: ERROR: relation "documentdb_data.documents_7312" does not exist ANALYZE documentdb_data.documents_7311; psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:24: ERROR: relation "documentdb_data.documents_7311" does not exist ANALYZE documentdb_data.documents_7312; psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:25: ERROR: relation "documentdb_data.documents_7312" does not exist BEGIN; set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) ROLLBACK; -- Insert a lot more data DO $$ DECLARE i int; BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes','{ "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "737", "price" : 50, "quantity" : 30 }', NULL); END LOOP; END; $$; DO $$ DECLARE i int; BEGIN FOR i IN 1..250 LOOP PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A330", "gates" : 30 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A340", "gates" : 10 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A380", "gates" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A350", "gates" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "737", "gates" : 110 }', NULL); END LOOP; END; $$; -- Now test index usage BEGIN; set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_94371_9437002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Heap Scan on documents_94372_9437004 collection_0_1 Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) -> Bitmap Index Scan on plane_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) (14 rows) set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_94371_9437002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Heap Scan on documents_94372_9437004 collection_0_1 Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) -> Bitmap Index Scan on plane_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) (14 rows) set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_94371_9437002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using plane_model_1 on documents_94372_9437004 collection_0_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) (13 rows) set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_94371_9437002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using plane_model_1 on documents_94372_9437004 collection_0_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) (13 rows) ROLLBACK; -- Cleanup SELECT documentdb_api.drop_collection('lookupdb', 'planes'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('lookupdb', 'gate_availability'); drop_collection --------------------------------------------------------------------- t (1 row) -- lookup with point read where inner plan depends on external param crash fix scenario SELECT documentdb_api.insert_one('lookupdb','Dishes',' { "_id" : 1, "dishId" : 1, "ingredients": [1, 2, 3, 4] }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:104: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 1, "shopId" : 101, "name": "Salt" }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:105: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 2, "shopId" : 101, "name": "Clove" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 3, "shopId" : 101, "name": "Olive" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 4, "shopId" : 101, "name": "Pepper" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Shops',' { "_id" : 101, "name": "ABC Mart" }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:109: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Get collection IDs for each collection and store them in variables SELECT collection_id AS dishes_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Dishes' \gset SELECT collection_id AS ingredients_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Ingredients' \gset SELECT collection_id AS shops_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Shops' \gset -- Dynamically run ANALYZE commands using the collection IDs SELECT 'ANALYZE documentdb_data.documents_' || :'dishes_id' \gexec ANALYZE documentdb_data.documents_94373 SELECT 'ANALYZE documentdb_data.documents_' || :'ingredients_id' \gexec ANALYZE documentdb_data.documents_94374 SELECT 'ANALYZE documentdb_data.documents_' || :'shops_id' \gexec ANALYZE documentdb_data.documents_94375 BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "1" }, "ingredient_info" : { "_id" : { "$numberInt" : "1" }, "shopId" : { "$numberInt" : "101" }, "name" : "Salt" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "2" }, "ingredient_info" : { "_id" : { "$numberInt" : "2" }, "shopId" : { "$numberInt" : "101" }, "name" : "Clove" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "3" }, "ingredient_info" : { "_id" : { "$numberInt" : "3" }, "shopId" : { "$numberInt" : "101" }, "name" : "Olive" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "4" }, "ingredient_info" : { "_id" : { "$numberInt" : "4" }, "shopId" : { "$numberInt" : "101" }, "name" : "Pepper" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } (4 rows) ROLLBACK; BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; EXPLAIN (COSTS OFF, SUMMARY OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'shop_info'::text) AS document FROM ((SELECT agg_stage_3.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_3.document, '{ "_id" : "ingredient_info.shopId" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_1.document, "lookupRight_stage_1_1".document, 'ingredient_info'::text) AS document FROM ((SELECT agg_stage_2.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_2.document, '{ "_id" : "ingredients" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text) AS document FROM documentdb_data.documents_94373_9437006 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "dishId" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '94373'::bigint))) agg_stage_2) lookup_stage_1_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_94374_9437008 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '94374'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_1.lookup_filter))) "lookupRight_stage_1_1" ON (true)) WHERE ("lookupRight_stage_1_1".document IS NOT NULL)) agg_stage_3) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_94375_9437010 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '94375'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) WHERE ("lookupRight_stage_1".document IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), collection_0_1.document, 'ingredient_info'::text), collection_0_1_1.document, 'shop_info'::text) -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text) -> Seq Scan on documentdb_data.documents_94373_9437006 collection Output: collection.shard_key_value, collection.object_id, collection.document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "dishId" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Nested Loop Output: collection_0_1.document, collection_0_1.object_id, collection_0_1_1.document, collection_0_1_1.object_id -> Index Scan using _id_ on documentdb_data.documents_94374_9437008 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: ((collection_0_1.shard_key_value = '94374'::bigint) AND (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), '{ "_id" : "ingredients" }'::documentdb_core.bson)))) -> Index Scan using _id_ on documentdb_data.documents_94375_9437010 collection_0_1_1 Output: collection_0_1_1.shard_key_value, collection_0_1_1.object_id, collection_0_1_1.document Index Cond: ((collection_0_1_1.shard_key_value = '94375'::bigint) AND (collection_0_1_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), collection_0_1.document, 'ingredient_info'::text), '{ "_id" : "ingredient_info.shopId" }'::documentdb_core.bson)))) (22 rows) ROLLBACK; bson_aggregation_pipeline_operator_expMovingAvg.out000066400000000000000000000701341507310017400423330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4156000; SET documentdb.next_collection_id TO 41560; SET documentdb.next_collection_index_id TO 41560; -- insert data -- positive case SELECT documentdb_api.insert_one('db','test1','{ "_id": 1, "name": "p1", "cost": 20, "date": { "$date": { "$numberLong": "1718841600001"}}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 2, "name": "p1", "cost": 22.4, "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 4, "name": "p1", "cost": 18.7, "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 5, "name": "p2", "cost": 89, "date": { "$date": { "$numberLong": "1718841600001"}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 6, "name": "p2", "cost": 101, "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test1','{ "_id": 8, "name": "p2", "cost": 104.3, "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : { "$numberInt" : "20" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : { "$numberDouble" : "22.399999999999998579" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "21.600000000000001421" } } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.86666666666666714" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : { "$numberDouble" : "18.699999999999999289" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.088888888888899231" } } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : { "$numberInt" : "89" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "89" } } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : { "$numberInt" : "101" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberInt" : "97" } } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "111.6666666666666714" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : { "$numberDouble" : "104.29999999999999716" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "106.75555555555567366" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : { "$numberInt" : "20" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : { "$numberDouble" : "22.399999999999998579" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "21.598400000000001597" } } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.867865599999998238" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : { "$numberDouble" : "18.699999999999999289" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.090067110399999706" } } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : { "$numberInt" : "89" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "89" } } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : { "$numberInt" : "101" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "96.992000000000004434" } } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "111.64932799999999702" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : { "$numberDouble" : "104.29999999999999716" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "106.75467555199999481" } } (8 rows) -- N is long SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 12345678901234} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : { "$numberInt" : "20" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : { "$numberDouble" : "22.399999999999998579" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "20.000000000000387246" } } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "20.000000000000238032" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : { "$numberDouble" : "18.699999999999999289" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.999999999999989342" } } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : { "$numberInt" : "89" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "89" } } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : { "$numberInt" : "101" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "89.000000000001946887" } } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "89.000000000006764367" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : { "$numberDouble" : "104.29999999999999716" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "89.000000000009279688" } } (8 rows) -- negative case -- no sortBy SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); ERROR: 'sortBy' parameters must be specified for $shift -- alpha and N all exist SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666, "N": 2} } } } } ] }'); ERROR: The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'. -- miss input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"alpha": 0.666, "N": 2} } } } } ] }'); ERROR: The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'. -- miss alpha and N SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost"} } } } } ] }'); ERROR: The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'. -- incorrect parameter SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpah": 0.666} } } } } ] }'); ERROR: Got unrecognized field in $expMovingAvg, The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "M": 2} } } } } ] }'); ERROR: Got unrecognized field in $expMovingAvg, The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'. -- N is float SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2.3} } } } } ] }'); ERROR: The 'N' field is required to be an integer value, but instead a floating-point number was provided as N: 2.300000; to specify a non-integer, please use the 'alpha' argument. -- alpha >= 1 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 2} } } } } ] }'); ERROR: The value of 'alpha' must lie strictly between 0 and 1 (not inclusive), but the provided alpha is: 2.000000 -- alpha <= 0 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": -2.8} } } } } ] }'); ERROR: The value of 'alpha' must lie strictly between 0 and 1 (not inclusive), but the provided alpha is: -2.800000 -- data contains null SELECT documentdb_api.insert_one('db','test2','{ "_id": 1, "name": "p1", "cost": 20, "date": { "$date": { "$numberLong": "1718841600001"}}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 2, "name": "p1", "cost": null, "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 4, "name": "p1", "cost": 18.7, "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 5, "name": "p2", "cost": null, "date": { "$date": { "$numberLong": "1718841600001"}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 6, "name": "p2", "cost": 101, "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test2','{ "_id": 8, "name": "p2", "cost": 104.3, "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test2", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : { "$numberInt" : "20" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : null, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.333333333333332149" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : { "$numberDouble" : "18.699999999999999289" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "18.911111111111100769" } } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : null, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : { "$numberInt" : "101" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberInt" : "101" } } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberInt" : "113" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : { "$numberDouble" : "104.29999999999999716" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "107.20000000000000284" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test2", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : { "$numberInt" : "20" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : null, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "19.333999999999999631" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : { "$numberDouble" : "18.699999999999999289" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "18.911756000000000455" } } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : null, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : { "$numberInt" : "101" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberInt" : "101" } } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "112.98799999999999955" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : { "$numberDouble" : "104.29999999999999716" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : { "$numberDouble" : "107.20179199999999753" } } (8 rows) -- input contains string SELECT documentdb_api.insert_one('db','test3','{ "_id": 1, "name": "p1", "cost": "asd", "date": { "$date": { "$numberLong": "1718841600001"}}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 2, "name": "p1", "cost": 22.4, "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 4, "name": "p1", "cost": "zxc", "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 5, "name": "p2", "cost": 89, "date": { "$date": { "$numberLong": "1718841600001"}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 6, "name": "p2", "cost": "qwe", "date": { "$date": { "$numberLong": "1718841600002" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test3','{ "_id": 8, "name": "p2", "cost": "vbn", "date": { "$date": { "$numberLong": "1718841600004"}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test3", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : "asd", "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : { "$numberDouble" : "22.399999999999998579" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "22.399999999999998579" } } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "20.13333333333333286" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : "zxc", "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : { "$numberInt" : "89" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "89" } } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : "qwe", "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberInt" : "109" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : "vbn", "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : null } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test3", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "p1", "cost" : "asd", "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "2" }, "name" : "p1", "cost" : { "$numberDouble" : "22.399999999999998579" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : { "$numberDouble" : "22.399999999999998579" } } { "_id" : { "$numberInt" : "3" }, "name" : "p1", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "20.135600000000000165" } } { "_id" : { "$numberInt" : "4" }, "name" : "p1", "cost" : "zxc", "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "5" }, "name" : "p2", "cost" : { "$numberInt" : "89" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "expMovingAvgForCost" : { "$numberInt" : "89" } } { "_id" : { "$numberInt" : "6" }, "name" : "p2", "cost" : "qwe", "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "expMovingAvgForCost" : null } { "_id" : { "$numberInt" : "7" }, "name" : "p2", "cost" : { "$numberInt" : "119" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "expMovingAvgForCost" : { "$numberDouble" : "108.98000000000000398" } } { "_id" : { "$numberInt" : "8" }, "name" : "p2", "cost" : "vbn", "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "expMovingAvgForCost" : null } (8 rows) bson_aggregation_pipeline_operator_linearFill.out000066400000000000000000003333311507310017400420030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 466000; SET documentdb.next_collection_id TO 4660; SET documentdb.next_collection_index_id TO 4660; --------------------------------------------------------------------- -- Prepare data --------------------------------------------------------------------- SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "p3", "cost": 2, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --------------------------------------------------------------------- -- positive case --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } (11 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } (11 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "252.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberDouble" : "36.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberDouble" : "68.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$linearFill": "$quantity"}, "quantity2": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" }, "quantity2" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" }, "quantity2" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" }, "quantity2" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" }, "quantity2" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" }, "quantity2" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" }, "quantity2" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" }, "quantity2" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" }, "quantity2" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" }, "quantity2" : { "$numberInt" : "100" } } (11 rows) --------------------------------------------------------------------- -- positive case with different sort key value --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 501 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "1" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "9" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "509.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "510" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 501 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": -10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "-10" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "1" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "9" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "501" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "1" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "502" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "9" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "509" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "510" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "501" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 11, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 12, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 0, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 520 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "0" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "520" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "1" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "502" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "9" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "509" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "11" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : null } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "12" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "19" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } (8 rows) --------------------------------------------------------------------- -- positive corner case --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : null } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : null } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : null } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600006" } }, "quantity" : null } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600007" } }, "quantity" : null } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600008" } }, "quantity" : null } (8 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) --------------------------------------------------------------------- -- positive case with Infinity and -Infinity --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "Infinity" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberInt" : "500" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "Infinity" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDecimal" : "Infinity" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "Infinity" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": { "$numberDecimal": "500" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDecimal" : "500" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": -Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "-Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberInt" : "500" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "-Infinity" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "-Infinity" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "-Infinity" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": -Infinity }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1" } }, "quantity" : { "$numberDouble" : "-Infinity" } } { "_id" : { "$numberInt" : "2" }, "a" : "a1", "b" : "b2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "2" } }, "quantity" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "a" : "a1", "b" : "b1", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "3" } }, "quantity" : { "$numberDouble" : "-Infinity" } } (3 rows) --------------------------------------------------------------------- -- positive case to test manual window trim --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006"}}, "quantity": 600 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600009"}}, "quantity": 700 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "533.33333333333337123" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : { "$numberDouble" : "566.66666666666662877" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600006" } }, "quantity" : { "$numberInt" : "600" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600007" } }, "quantity" : { "$numberDouble" : "633.33333333333337123" } } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600008" } }, "quantity" : { "$numberDouble" : "666.66666666666662877" } } { "_id" : { "$numberInt" : "9" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600009" } }, "quantity" : { "$numberInt" : "700" } } (9 rows) --------------------------------------------------------------------- -- positive case with different numeric types --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDecimal" : "501.000000000000" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDecimal" : "502.000000000000" } } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberDouble" : "503.0" } } (8 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) --------------------------------------------------------------------- -- positive corner case with sortBy --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "def", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } (4 rows) --------------------------------------------------------------------- -- negative case --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- without sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: $linearFill requires specifying a top-level sortBy expression that contains exactly one element -- sortBy is not numeric or date SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: The sortBy parameter must contain either a numeric value or a date, but instead received string SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: The sortBy parameter must contain either a numeric value or a date, but instead received string -- mixed numeric and date type in sortBy SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "1", "cost": 5, "date": 1, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "2", "cost": 8, "date": 2, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: The sortBy field should contain either numeric values or dates, but cannot include both types simultaneously -- sortBy with repeated value in one partition SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": 0}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 9, "val": 9}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "test": 10, "val": 10}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "test": 10, "val": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "test": 11, "val": 11}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); ERROR: The sort field must not contain any duplicate values -- fill non-numeric field SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: The value provided must be either a numeric type or explicitly null SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ERROR: The value provided must be either a numeric type or explicitly null -- window fields existed in the input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity", "window":{ "documents": ["unbounded", "unbounded"]}}}}}]}'); ERROR: 'window' field is not allowed in $linearFill --------------------------------------------------------------------- -- Infinity result test --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": { "$numberDecimal": "-9.999999999999999999999999999999999E+6144" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 2, "val": { "$numberDecimal": "9.999999999999999999999999999999999E+6144" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "test" : { "$numberInt" : "0" }, "val" : { "$numberDecimal" : "-9.999999999999999999999999999999999E+6144" } } { "_id" : { "$numberInt" : "2" }, "test" : { "$numberInt" : "1" }, "val" : { "$numberDecimal" : "Infinity" } } { "_id" : { "$numberInt" : "3" }, "test" : { "$numberInt" : "2" }, "val" : { "$numberDecimal" : "9.999999999999999999999999999999999E+6144" } } (3 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": { "$numberDecimal": "9.999999999999999999999999999999999E+6144" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 2, "val": { "$numberDecimal": "-9.999999999999999999999999999999999E+6144" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "test" : { "$numberInt" : "0" }, "val" : { "$numberDecimal" : "9.999999999999999999999999999999999E+6144" } } { "_id" : { "$numberInt" : "2" }, "test" : { "$numberInt" : "1" }, "val" : { "$numberDecimal" : "-Infinity" } } { "_id" : { "$numberInt" : "3" }, "test" : { "$numberInt" : "2" }, "val" : { "$numberDecimal" : "-9.999999999999999999999999999999999E+6144" } } (3 rows) bson_aggregation_pipeline_operator_locf.out000066400000000000000000002120351507310017400406420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 475000; SET documentdb.next_collection_id TO 4750; SET documentdb.next_collection_index_id TO 4750; --------------------------------------------------------------------- -- Prepare data --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "p3", "cost": 2, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 12, "a": "p4", "cost": 2, "date": { "$date": { "$numberLong": "1718841600031"} }, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 13, "a": "p4", "cost": 8, "date": { "$date": { "$numberLong": "1718841605032" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 14, "a": "p4", "cost": 8, "date": { "$date": { "$numberLong": "1718841606033" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --------------------------------------------------------------------- -- positive case --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : null } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : null } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : null } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a","output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : null } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : null } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : null } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : { "$numberInt" : "100" } } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : { "$numberInt" : "100" } } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : null } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : null } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : null } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$locf": "$quantity"}, "quantity2": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" }, "quantity2" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" }, "quantity2" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "503" }, "quantity2" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" }, "quantity2" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" }, "quantity2" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "4" }, "quantity2" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "4" }, "quantity2" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" }, "quantity2" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" }, "quantity2" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : null, "quantity2" : null } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : null, "quantity2" : null } (14 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "12" }, "a" : "p4", "cost" : { "$numberInt" : "2" }, "date" : { "$date" : { "$numberLong" : "1718841600031" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "13" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605032" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "14" }, "a" : "p4", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606033" } }, "quantity" : { "$numberInt" : "100" } } (14 rows) --------------------------------------------------------------------- -- positive corner case --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : null } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : null } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) --------------------------------------------------------------------- -- positive case with different types --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberDouble" : "503.0" } } (8 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600000"}}, "quantity": "string501" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": "string501" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": "string501" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": 600}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "600" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : { "$numberInt" : "600" } } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "600" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "600" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : "string501" } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "quantity" : "string501" } (6 rows) -- fill non-numeric field SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : "503" } (4 rows) SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : "503" } (5 rows) --------------------------------------------------------------------- -- positive corner case with sortBy --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "def", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) -- sortBy is not numeric or date SELECT documentdb_api.drop_collection('db','setWindowFields'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) -- without sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) -- sortBy with repeated value in one partition SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } (4 rows) --------------------------------------------------------------------- -- negative case --------------------------------------------------------------------- -- window fields existed in the input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity", "window":{ "documents": ["unbounded", "unbounded"]}}}}}]}'); ERROR: 'window' field is not allowed in $locf bson_aggregation_pipeline_stage_densify.out000066400000000000000000003547271507310017400406470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 477000; SET documentdb.next_collection_id TO 4770; SET documentdb.next_collection_index_id TO 4770; SELECT insert_one('db','densify','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 2, "a": "abc", "cost": 5, "quantity": 507, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 3, "a": "abc", "cost": 3, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 4, "a": "abc", "cost": 7, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 11, "a": "def", "cost": 16, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 12, "a": "def", "cost": 11, "quantity": 507, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 13, "a": "def", "cost": -5, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify','{ "_id": 14, "a": "def", "cost": 9, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations of $densify stage and negative test cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": "Not an object" }]}'); ERROR: The $densify stage specification must be provided as an object, but encountered string instead SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { } }]}'); ERROR: The BSON field '$densify.field' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": [ ] }]}'); ERROR: The $densify stage specification must be provided as an object, but encountered array instead SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": 1 } }]}'); ERROR: The BSON field '$densify.field' has an incorrect type 'int'; it should be of type 'string'. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a" } }]}'); ERROR: The BSON field '$densify.range' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": "A" } }]}'); ERROR: The BSON field '$densify.range' has an incorrect type 'string'; it should be of type 'object'. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { } } }]}'); ERROR: The BSON field '$densify.range.bounds' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : 1 } } }]}'); ERROR: Range bounds must be 'full', 'partition', or an ascending array of two numbers or two dates. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "na" } } }]}'); ERROR: The bounds string value should be either 'full' or 'partition' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "full" } } }]}'); ERROR: The BSON field '$densify.range.step' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "partition" } } }]}'); ERROR: The BSON field '$densify.range.step' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1] } } }]}'); ERROR: A boundary array used within a range statement is required to contain exactly two elements. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2, 3] } } }]}'); ERROR: A boundary array used within a range statement is required to contain exactly two elements. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, { "$date": { "$numberLong": "1718841600000" } }] } } }]}'); ERROR: The BSON field '$densify.range.step' is required but was not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "full", "step": "Hello" } } }]}'); ERROR: The BSON field '$densify.range.step' has an incorrect type 'string'; it should be one of the following valid types: [int, decimal, double, long] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "partition", "step": "Hello" } } }]}'); ERROR: The BSON field '$densify.range.step' has an incorrect type 'string'; it should be one of the following valid types: [int, decimal, double, long] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, {"$numberDouble": 2}], "step": 1 } } }]}'); ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Unexpected integer 2 in type "double"' LINE 1: ...ECT document FROM bson_aggregation_pipeline('db', '{ "aggreg... ^ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": {"$numberDecimal": "1"} } } }]}'); ERROR: Upper bound, lower bound, and step values must each be of identical type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 1, "unit": "sec" } } }]}'); ERROR: Unrecognized value for time unit: sec SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 1, "unit": "Hour" } } }]}'); ERROR: Unrecognized value for time unit: Hour SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": -1 } } }]}'); ERROR: The step argument within a range expression should always be a strictly positive numerical value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 0 } } }]}'); ERROR: The step argument within a range expression should always be a strictly positive numerical value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": {"$numberDecimal": "-1e1000"} } } }]}'); ERROR: The step argument within a range expression should always be a strictly positive numerical value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [2, 1], "step": 1 } } }]}'); ERROR: Range bounds must be 'full', 'partition', or an ascending array of two numbers or two dates. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "partitionByFields": "a", "range": { "bounds" : "full", "step": 1 } } }]}'); ERROR: The BSON field '$densify.partitionByFields' has an incorrect type 'string'; it should be of type 'array'. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "partitionByFields": ["$a"], "range": { "bounds" : "full", "step": 1 } } }]}'); ERROR: FieldPath field names are not allowed to begin with the operators symbol '$'; consider using $getField or $setField instead. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "$a", "partitionByFields": ["a"], "range": { "bounds" : "full", "step": 1 } } }]}'); ERROR: FieldPath field names are not allowed to begin with the operators symbol '$'; consider using $getField or $setField instead. -- Valid cases that works -- Check an empty table returns value when used with range based partition SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "empty_table", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [1, 10], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "cost" : { "$numberInt" : "1" } } { "cost" : { "$numberInt" : "2" } } { "cost" : { "$numberInt" : "3" } } { "cost" : { "$numberInt" : "4" } } { "cost" : { "$numberInt" : "5" } } { "cost" : { "$numberInt" : "6" } } { "cost" : { "$numberInt" : "7" } } { "cost" : { "$numberInt" : "8" } } { "cost" : { "$numberInt" : "9" } } (9 rows) -- Range with lower and upper bounds SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (13 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1.2 } } }]}'); ERROR: Upper bound, lower bound, and step values must each be of identical type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [-10, -5], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "a" : "abc", "cost" : { "$numberInt" : "-10" } } { "a" : "abc", "cost" : { "$numberInt" : "-9" } } { "a" : "abc", "cost" : { "$numberInt" : "-8" } } { "a" : "abc", "cost" : { "$numberInt" : "-7" } } { "a" : "abc", "cost" : { "$numberInt" : "-6" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberInt" : "-10" } } { "a" : "def", "cost" : { "$numberInt" : "-9" } } { "a" : "def", "cost" : { "$numberInt" : "-8" } } { "a" : "def", "cost" : { "$numberInt" : "-7" } } { "a" : "def", "cost" : { "$numberInt" : "-6" } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (18 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [11, 15], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "a" : "abc", "cost" : { "$numberInt" : "12" } } { "a" : "abc", "cost" : { "$numberInt" : "13" } } { "a" : "abc", "cost" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberInt" : "12" } } { "a" : "def", "cost" : { "$numberInt" : "13" } } { "a" : "def", "cost" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (15 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [3, 10], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "cost" : { "$numberInt" : "3" } } { "a" : "def", "cost" : { "$numberInt" : "4" } } { "a" : "def", "cost" : { "$numberInt" : "5" } } { "a" : "def", "cost" : { "$numberInt" : "6" } } { "a" : "def", "cost" : { "$numberInt" : "7" } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (18 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": [{ "$date" : { "$numberLong" : "1718841610000" } }, { "$date" : { "$numberLong" : "1718841615000" } }], "step": 1, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}') -- Partition mode SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); ERROR: syntax error at or near "SELECT" LINE 4: SELECT document FROM bson_aggregation_pipeline('db', ^ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "formatted" : "2024-06-20T00:00:00.000Z" } { "formatted" : "2024-06-20T00:00:01.000Z" } { "formatted" : "2024-06-20T00:00:02.000Z" } { "formatted" : "2024-06-20T00:00:03.000Z" } { "formatted" : "2024-06-20T00:00:04.000Z" } { "_id" : { "$numberInt" : "2" }, "formatted" : "2024-06-20T00:00:05.000Z" } { "formatted" : "2024-06-20T00:00:06.000Z" } { "formatted" : "2024-06-20T00:00:07.000Z" } { "formatted" : "2024-06-20T00:00:08.000Z" } { "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "3" }, "formatted" : "2024-06-20T00:00:10.000Z" } { "formatted" : "2024-06-20T00:00:11.000Z" } { "formatted" : "2024-06-20T00:00:12.000Z" } { "formatted" : "2024-06-20T00:00:13.000Z" } { "formatted" : "2024-06-20T00:00:14.000Z" } { "_id" : { "$numberInt" : "4" }, "formatted" : "2024-06-20T00:00:15.000Z" } { "_id" : { "$numberInt" : "11" }, "formatted" : "2024-06-20T00:00:00.000Z" } { "formatted" : "2024-06-20T00:00:01.000Z" } { "formatted" : "2024-06-20T00:00:02.000Z" } { "formatted" : "2024-06-20T00:00:03.000Z" } { "formatted" : "2024-06-20T00:00:04.000Z" } { "_id" : { "$numberInt" : "12" }, "formatted" : "2024-06-20T00:00:05.000Z" } { "formatted" : "2024-06-20T00:00:06.000Z" } { "formatted" : "2024-06-20T00:00:07.000Z" } { "formatted" : "2024-06-20T00:00:08.000Z" } { "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "13" }, "formatted" : "2024-06-20T00:00:10.000Z" } { "formatted" : "2024-06-20T00:00:11.000Z" } { "formatted" : "2024-06-20T00:00:12.000Z" } { "formatted" : "2024-06-20T00:00:13.000Z" } { "formatted" : "2024-06-20T00:00:14.000Z" } { "_id" : { "$numberInt" : "14" }, "formatted" : "2024-06-20T00:00:15.000Z" } (32 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 3, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "formatted" : "2024-06-20T00:00:00.000Z" } { "formatted" : "2024-06-20T00:00:03.000Z" } { "_id" : { "$numberInt" : "2" }, "formatted" : "2024-06-20T00:00:05.000Z" } { "formatted" : "2024-06-20T00:00:06.000Z" } { "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "3" }, "formatted" : "2024-06-20T00:00:10.000Z" } { "formatted" : "2024-06-20T00:00:12.000Z" } { "_id" : { "$numberInt" : "4" }, "formatted" : "2024-06-20T00:00:15.000Z" } { "_id" : { "$numberInt" : "11" }, "formatted" : "2024-06-20T00:00:00.000Z" } { "formatted" : "2024-06-20T00:00:03.000Z" } { "_id" : { "$numberInt" : "12" }, "formatted" : "2024-06-20T00:00:05.000Z" } { "formatted" : "2024-06-20T00:00:06.000Z" } { "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "13" }, "formatted" : "2024-06-20T00:00:10.000Z" } { "formatted" : "2024-06-20T00:00:12.000Z" } { "_id" : { "$numberInt" : "14" }, "formatted" : "2024-06-20T00:00:15.000Z" } (16 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": { "$numberDecimal": "1.5"} } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "4.5" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "6.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "7.5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "9.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "-3.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "-2.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "-0.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "1.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "2.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "4.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "5.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "7.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "8.5" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "10.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "11.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "13.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "14.5" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (25 rows) -- Full mode SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "cost" : { "$numberInt" : "0" } } { "a" : "abc", "cost" : { "$numberInt" : "1" } } { "a" : "abc", "cost" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberInt" : "-4" } } { "a" : "def", "cost" : { "$numberInt" : "-3" } } { "a" : "def", "cost" : { "$numberInt" : "-2" } } { "a" : "def", "cost" : { "$numberInt" : "-1" } } { "a" : "def", "cost" : { "$numberInt" : "0" } } { "a" : "def", "cost" : { "$numberInt" : "1" } } { "a" : "def", "cost" : { "$numberInt" : "2" } } { "a" : "def", "cost" : { "$numberInt" : "3" } } { "a" : "def", "cost" : { "$numberInt" : "4" } } { "a" : "def", "cost" : { "$numberInt" : "5" } } { "a" : "def", "cost" : { "$numberInt" : "6" } } { "a" : "def", "cost" : { "$numberInt" : "7" } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberInt" : "12" } } { "a" : "def", "cost" : { "$numberInt" : "13" } } { "a" : "def", "cost" : { "$numberInt" : "14" } } { "a" : "def", "cost" : { "$numberInt" : "15" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "a" : "abc", "cost" : { "$numberInt" : "12" } } { "a" : "abc", "cost" : { "$numberInt" : "13" } } { "a" : "abc", "cost" : { "$numberInt" : "14" } } { "a" : "abc", "cost" : { "$numberInt" : "15" } } { "a" : "abc", "cost" : { "$numberInt" : "16" } } (44 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1, "unit": "second" } } }, {"$project": { "a": 1, "formatted": { "$dateToString": { "date": "$date" } }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "formatted" : "2024-06-20T00:00:00.000Z" } { "_id" : { "$numberInt" : "11" }, "a" : "def", "formatted" : "2024-06-20T00:00:00.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:01.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:02.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:03.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:04.000Z" } { "_id" : { "$numberInt" : "12" }, "a" : "def", "formatted" : "2024-06-20T00:00:05.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:01.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:02.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:03.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:04.000Z" } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "formatted" : "2024-06-20T00:00:05.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:06.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:07.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:08.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "formatted" : "2024-06-20T00:00:10.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:06.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:07.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:08.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "13" }, "a" : "def", "formatted" : "2024-06-20T00:00:10.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:11.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:12.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:13.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:14.000Z" } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "formatted" : "2024-06-20T00:00:15.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:11.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:12.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:13.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:14.000Z" } { "_id" : { "$numberInt" : "14" }, "a" : "def", "formatted" : "2024-06-20T00:00:15.000Z" } (32 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 3, "unit": "second" } } }, {"$project": { "a": 1, "formatted": { "$dateToString": { "date": "$date" } }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "formatted" : "2024-06-20T00:00:00.000Z" } { "_id" : { "$numberInt" : "11" }, "a" : "def", "formatted" : "2024-06-20T00:00:00.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:03.000Z" } { "_id" : { "$numberInt" : "12" }, "a" : "def", "formatted" : "2024-06-20T00:00:05.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:03.000Z" } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "formatted" : "2024-06-20T00:00:05.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:06.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "formatted" : "2024-06-20T00:00:10.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:06.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:09.000Z" } { "_id" : { "$numberInt" : "13" }, "a" : "def", "formatted" : "2024-06-20T00:00:10.000Z" } { "a" : "abc", "formatted" : "2024-06-20T00:00:12.000Z" } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "formatted" : "2024-06-20T00:00:15.000Z" } { "a" : "def", "formatted" : "2024-06-20T00:00:12.000Z" } { "_id" : { "$numberInt" : "14" }, "a" : "def", "formatted" : "2024-06-20T00:00:15.000Z" } (16 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": { "$numberDecimal": "1.5"} } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "-3.5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "-2.0" } } { "a" : "abc", "cost" : { "$numberDecimal" : "-0.5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "1.0" } } { "a" : "abc", "cost" : { "$numberDecimal" : "2.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "4.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "5.5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "-3.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "-2.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "-0.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "1.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "2.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "4.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "5.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "7.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "8.5" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "8.5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "10.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberDecimal" : "11.5" } } { "a" : "def", "cost" : { "$numberDecimal" : "13.0" } } { "a" : "def", "cost" : { "$numberDecimal" : "14.5" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberDecimal" : "11.5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "13.0" } } { "a" : "abc", "cost" : { "$numberDecimal" : "14.5" } } { "a" : "abc", "cost" : { "$numberDecimal" : "16.0" } } (34 rows) -- Explains EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "empty_table", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [1, 10], "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- ProjectSet Output: bson_lookup_unwind((bson_densify_range(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ], "step" : { "$numberInt" : "1" } } }'::bson) OVER (?)), '_'::text) -> WindowAgg Output: bson_densify_range(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "1" }, { "$numberInt" : "10" } ], "step" : { "$numberInt" : "1" } } }'::bson) OVER (?), (bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::bson)), (bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::bson)) -> Sort Output: (bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::bson)), (bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::bson)), collection.document Sort Key: (bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::bson)), (bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::bson)) NULLS FIRST -> Result Output: bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::bson), bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::bson), collection.document -> Append -> Function Scan on documentdb_api_internal.empty_data_table collection Output: collection.document Function Call: empty_data_table() -> Result Output: NULL::bson (15 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT documentdb_api_internal.bson_densify_range(agg_stage_0_1.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY (documentdb_api_internal.bson_expression_partition_by_fields_get(agg_stage_0_1.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(agg_stage_0_1.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM (SELECT collection.document FROM documentdb_data.documents_4770_477002 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4770'::bigint) UNION ALL SELECT NULL::documentdb_core.bson AS document) agg_stage_0_1) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_range(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_range(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Result Output: documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson), collection.document -> Append -> Bitmap Heap Scan on documentdb_data.documents_4770_477002 collection Output: collection.document Recheck Cond: (collection.shard_key_value = '4770'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4770'::bigint) -> Result Output: NULL::documentdb_core.bson (24 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM documentdb_data.documents_4770_477002 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4770'::bigint)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_4770_477002 collection Output: documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), documentdb_api_internal.bson_expression_partition_by_fields_get(collection.document, '{ "" : [ "a" ] }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '4770'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4770'::bigint) (19 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT documentdb_api_internal.bson_densify_full(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "full", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (ORDER BY (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM documentdb_data.documents_4770_477002 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4770'::bigint)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_full(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "full", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_full(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "full", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_4770_477002 collection Output: documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '4770'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4770'::bigint) (19 rows) -- Shard collection SELECT documentdb_api.shard_collection('db', 'densify', '{"a": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (13 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }, {"$sort": { "a": 1, "cost": 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "cost" : { "$numberInt" : "-4" } } { "a" : "def", "cost" : { "$numberInt" : "-3" } } { "a" : "def", "cost" : { "$numberInt" : "-2" } } { "a" : "def", "cost" : { "$numberInt" : "-1" } } { "a" : "def", "cost" : { "$numberInt" : "0" } } { "a" : "def", "cost" : { "$numberInt" : "1" } } { "a" : "def", "cost" : { "$numberInt" : "2" } } { "a" : "def", "cost" : { "$numberInt" : "3" } } { "a" : "def", "cost" : { "$numberInt" : "4" } } { "a" : "def", "cost" : { "$numberInt" : "5" } } { "a" : "def", "cost" : { "$numberInt" : "6" } } { "a" : "def", "cost" : { "$numberInt" : "7" } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberInt" : "12" } } { "a" : "def", "cost" : { "$numberInt" : "13" } } { "a" : "def", "cost" : { "$numberInt" : "14" } } { "a" : "def", "cost" : { "$numberInt" : "15" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (30 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "cost" : { "$numberInt" : "0" } } { "a" : "abc", "cost" : { "$numberInt" : "1" } } { "a" : "abc", "cost" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "cost" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "cost" : { "$numberInt" : "-4" } } { "a" : "def", "cost" : { "$numberInt" : "-3" } } { "a" : "def", "cost" : { "$numberInt" : "-2" } } { "a" : "def", "cost" : { "$numberInt" : "-1" } } { "a" : "def", "cost" : { "$numberInt" : "0" } } { "a" : "def", "cost" : { "$numberInt" : "1" } } { "a" : "def", "cost" : { "$numberInt" : "2" } } { "a" : "def", "cost" : { "$numberInt" : "3" } } { "a" : "def", "cost" : { "$numberInt" : "4" } } { "a" : "def", "cost" : { "$numberInt" : "5" } } { "a" : "def", "cost" : { "$numberInt" : "6" } } { "a" : "def", "cost" : { "$numberInt" : "7" } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "cost" : { "$numberInt" : "12" } } { "a" : "def", "cost" : { "$numberInt" : "13" } } { "a" : "def", "cost" : { "$numberInt" : "14" } } { "a" : "def", "cost" : { "$numberInt" : "15" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "a" : "abc", "cost" : { "$numberInt" : "12" } } { "a" : "abc", "cost" : { "$numberInt" : "13" } } { "a" : "abc", "cost" : { "$numberInt" : "14" } } { "a" : "abc", "cost" : { "$numberInt" : "15" } } { "a" : "abc", "cost" : { "$numberInt" : "16" } } (44 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 53_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_4770_477016 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4770_477016 collection Output: document -> Distributed Subplan 53_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT intermediate_result.document FROM read_intermediate_result('53_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson) UNION ALL SELECT NULL::documentdb_core.bson AS document Node: host=localhost port=58070 dbname=regression -> Append -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document Function Call: read_intermediate_result('53_1'::text, 'binary'::citus_copy_format) -> Result Output: NULL::documentdb_core.bson Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT documentdb_api_internal.bson_densify_range(agg_stage_0_1.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY (documentdb_api_internal.bson_expression_partition_by_fields_get(agg_stage_0_1.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(agg_stage_0_1.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('53_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0_1) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_range(intermediate_result.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_range(intermediate_result.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a" ] }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), intermediate_result.document Sort Key: (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a" ] }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a" ] }'::documentdb_core.bson), intermediate_result.document Function Call: read_intermediate_result('53_2'::text, 'binary'::citus_copy_format) (41 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(worker_column_1, '_'::text) AS document FROM (SELECT agg_stage_0.document AS worker_column_1 FROM (SELECT documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY collection.shard_key_value ORDER BY (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM documentdb_data.documents_4770_477016 collection) agg_stage_0) worker_subquery Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), collection.shard_key_value -> Sort Output: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), collection.shard_key_value, collection.document Sort Key: collection.shard_key_value, (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Seq Scan on documentdb_data.documents_4770_477016 collection Output: documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), collection.shard_key_value, collection.document (16 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 57_1 -> WindowAgg Output: bson_densify_full(remote_scan.document, '{ "field" : "cost", "partitionByFields" : [ "a" ], "range" : { "bounds" : "full", "step" : { "$numberInt" : "1" } } }'::bson) OVER (?), remote_scan.worker_column_2 -> Sort Output: remote_scan.worker_column_2, remote_scan.document Sort Key: remote_scan.worker_column_2 NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.worker_column_2, remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_catalog.bson_orderby(document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson) AS worker_column_2 FROM documentdb_data.documents_4770_477016 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4770_477016 collection Output: document, documentdb_api_catalog.bson_orderby(document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('57_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind(intermediate_result.document, '_'::text) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document Function Call: read_intermediate_result('57_1'::text, 'binary'::citus_copy_format) (27 rows) -- Reshard multikey SELECT documentdb_api.shard_collection('db', 'densify', '{"a": "hashed", "quantity": "hashed"}', true); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); document --------------------------------------------------------------------- { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } (37 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "partition", "step": 1 } } }, {"$sort": { "a": 1, "quantity": 1, "cost": 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } (8 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "full", "step": 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "def", "cost" : { "$numberInt" : "-5" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "0" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "1" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "3" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "0" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "1" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "2" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "3" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "0" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "1" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "2" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "3" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "4" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "5" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "7" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-5" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-4" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-3" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-2" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "-1" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "0" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "1" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "2" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "3" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "4" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "5" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "6" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "7" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "14" }, "a" : "def", "cost" : { "$numberInt" : "9" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-5" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-4" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-3" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-2" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-1" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "0" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "1" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "2" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "3" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "4" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "5" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "6" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "7" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-5" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-4" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-3" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-2" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "-1" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "0" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "1" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "2" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "3" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "4" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "5" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "6" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "7" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "12" }, "a" : "def", "cost" : { "$numberInt" : "11" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-5" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-4" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-3" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-2" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "-1" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "0" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "1" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "2" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "3" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "4" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "5" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "6" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "7" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "12" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "13" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "14" } } { "a" : "def", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "15" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "16" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "6" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "7" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "11" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "12" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "13" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "14" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "15" } } { "a" : "abc", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "16" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "5" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "6" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "7" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "11" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "12" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "13" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "14" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "15" } } { "a" : "abc", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "16" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "8" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "9" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "11" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "12" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "13" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "14" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "15" } } { "a" : "abc", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "16" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-4" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-3" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-2" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "-1" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "0" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "1" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "2" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "3" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "5" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "6" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "7" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "8" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "9" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "12" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "13" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "14" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "15" } } { "a" : "def", "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "16" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "11" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "12" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "13" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "14" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "15" } } { "a" : "def", "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "16" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "12" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "13" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "14" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "15" } } { "a" : "def", "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "16" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "11" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "12" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "13" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "14" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "15" } } { "a" : "abc", "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "16" } } (176 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 78_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_4770_477024 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4770_477024 collection Output: document -> Distributed Subplan 78_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT intermediate_result.document FROM read_intermediate_result('78_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson) UNION ALL SELECT NULL::documentdb_core.bson AS document Node: host=localhost port=58070 dbname=regression -> Append -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document Function Call: read_intermediate_result('78_1'::text, 'binary'::citus_copy_format) -> Result Output: NULL::documentdb_core.bson Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT documentdb_api_internal.bson_densify_range(agg_stage_0_1.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY (documentdb_api_internal.bson_expression_partition_by_fields_get(agg_stage_0_1.document, '{ "" : [ "a", "quantity" ] }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(agg_stage_0_1.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('78_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0_1) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_range(intermediate_result.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_range(intermediate_result.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : [ { "$numberInt" : "8" }, { "$numberInt" : "12" } ], "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a", "quantity" ] }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a", "quantity" ] }'::documentdb_core.bson)), intermediate_result.document Sort Key: (documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a", "quantity" ] }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_catalog.bson_orderby(intermediate_result.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), documentdb_api_internal.bson_expression_partition_by_fields_get(intermediate_result.document, '{ "" : [ "a", "quantity" ] }'::documentdb_core.bson), intermediate_result.document Function Call: read_intermediate_result('78_2'::text, 'binary'::citus_copy_format) (41 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "partition", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(worker_column_1, '_'::text) AS document FROM (SELECT agg_stage_0.document AS worker_column_1 FROM (SELECT documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (PARTITION BY collection.shard_key_value ORDER BY (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST) AS document FROM documentdb_data.documents_4770_477024 collection) agg_stage_0) worker_subquery Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind((documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?)), '_'::text) -> WindowAgg Output: documentdb_api_internal.bson_densify_partition(collection.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : "partition", "step" : { "$numberInt" : "1" } } }'::documentdb_core.bson) OVER (?), (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), collection.shard_key_value -> Sort Output: (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)), collection.shard_key_value, collection.document Sort Key: collection.shard_key_value, (documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Seq Scan on documentdb_data.documents_4770_477024 collection Output: documentdb_api_catalog.bson_orderby(collection.document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson), collection.shard_key_value, collection.document (16 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "full", "step": 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 82_1 -> WindowAgg Output: bson_densify_full(remote_scan.document, '{ "field" : "cost", "partitionByFields" : [ "a", "quantity" ], "range" : { "bounds" : "full", "step" : { "$numberInt" : "1" } } }'::bson) OVER (?), remote_scan.worker_column_2 -> Sort Output: remote_scan.worker_column_2, remote_scan.document Sort Key: remote_scan.worker_column_2 NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.worker_column_2, remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_catalog.bson_orderby(document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson) AS worker_column_2 FROM documentdb_data.documents_4770_477024 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4770_477024 collection Output: document, documentdb_api_catalog.bson_orderby(document, '{ "cost" : { "$numberLong" : "1" } }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_lookup_unwind(document, '_'::text) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('82_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_lookup_unwind(intermediate_result.document, '_'::text) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document Function Call: read_intermediate_result('82_1'::text, 'binary'::citus_copy_format) (27 rows) -- Test that internal number of documents generated limits are working -- Tests inspired from aggregation/sources/densify/generated_limit.js, currently we don't support setParameter so only a unit test should be suffice to test internal limits SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 10; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 11], "step": 1 } } }]}'); ERROR: $densify stage produced 11 documents which is greater that the allowed limit of 10 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 45], "step": 4 } } }]}'); ERROR: $densify stage produced 11 documents which is greater that the allowed limit of 10 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 10], "step": 4 } } }]}'); -- should pass document --------------------------------------------------------------------- { "cost" : { "$numberInt" : "0" } } { "cost" : { "$numberInt" : "4" } } { "cost" : { "$numberInt" : "8" } } (3 rows) SELECT insert_one('db','densify_limit','{ "_id": 1, "a": "abc", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify_limit','{ "_id": 2, "a": "abc", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); ERROR: $densify stage produced 11 documents which is greater that the allowed limit of 10 SELECT insert_one('db','densify_limit','{ "_id": 3, "a": "def", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify_limit','{ "_id": 4, "a": "def", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test limit works across partitions SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 20; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); ERROR: $densify stage produced 21 documents which is greater that the allowed limit of 20 -- Verify existing documents don't count towards the limit SELECT insert_one('db','densify_limit','{ "_id": 5, "a": "abc", "cost": 5, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify_limit','{ "_id": 6, "a": "def", "cost": 5, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Should pass now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "0" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "_id" : { "$numberInt" : "3" }, "a" : "def", "cost" : { "$numberInt" : "0" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "1" } } { "a" : "abc", "cost" : { "$numberInt" : "2" } } { "a" : "abc", "cost" : { "$numberInt" : "3" } } { "a" : "abc", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberInt" : "1" } } { "a" : "def", "cost" : { "$numberInt" : "2" } } { "a" : "def", "cost" : { "$numberInt" : "3" } } { "a" : "def", "cost" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "def", "cost" : { "$numberInt" : "5" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "abc", "cost" : { "$numberInt" : "6" } } { "a" : "abc", "cost" : { "$numberInt" : "7" } } { "a" : "abc", "cost" : { "$numberInt" : "8" } } { "a" : "abc", "cost" : { "$numberInt" : "9" } } { "a" : "abc", "cost" : { "$numberInt" : "10" } } { "a" : "abc", "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "12" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } { "a" : "def", "cost" : { "$numberInt" : "6" } } { "a" : "def", "cost" : { "$numberInt" : "7" } } { "a" : "def", "cost" : { "$numberInt" : "8" } } { "a" : "def", "cost" : { "$numberInt" : "9" } } { "a" : "def", "cost" : { "$numberInt" : "10" } } { "a" : "def", "cost" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "4" }, "a" : "def", "cost" : { "$numberInt" : "12" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } } } (26 rows) -- Check time also works SELECT drop_collection('db', 'densify_limit') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT insert_one('db','densify_limit','{ "_id": 1, "a": "abc", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','densify_limit','{ "_id": 2, "a": "abc", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 5; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 , "unit": "second"} } }]}'); ERROR: $densify stage produced 6 documents which is greater that the allowed limit of 5 RESET documentdb.test.internalQueryMaxAllowedDensifyDocs; -- Test memory limit too SET documentdb.test.internaldocumentsourcedensifymaxmemorybytes TO 100; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 40], "step": 1 } } }]}'); ERROR: PlanExecutor error during aggregation :: caused by :: $densify ran out of memory limit: 100 RESET documentdb.test.internalDocumentSourceDensifyMaxmemoryBytes; SHOW documentdb.test.internalQueryMaxAllowedDensifyDocs; documentdb.test.internalQueryMaxAllowedDensifyDocs --------------------------------------------------------------------- 500000 (1 row) SHOW documentdb.test.internalDocumentSourceDensifyMaxmemoryBytes; documentdb.test.internalDocumentSourceDensifyMaxMemoryBytes --------------------------------------------------------------------- 104857600 (1 row) bson_aggregation_pipeline_stage_fill.out000066400000000000000000002577051507310017400401320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 468000; SET documentdb.next_collection_id TO 4680; SET documentdb.next_collection_index_id TO 4680; --------------------------------------------------------------------- -- Prepare data --------------------------------------------------------------------- SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 11, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --------------------------------------------------------------------- -- positive case --------------------------------------------------------------------- SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "252.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberDouble" : "36.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberDouble" : "68.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "value": 123}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "123" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "value": 567}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "567" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "567" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "567" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "567" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "567" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "567" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "value": "test"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : "test" } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "value": {"$numberDecimal": "123"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "123" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "value": 123}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "123" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "123" } } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : null } (11 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a", "cost"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "5" }, "a" : "p2", "cost" : { "$numberInt" : "3" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "p2", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : null } { "_id" : { "$numberInt" : "7" }, "a" : "p2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600021" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "10" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841605022" } }, "quantity" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "9" }, "a" : "p3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841606023" } }, "quantity" : { "$numberInt" : "100" } } (11 rows) --------------------------------------------------------------------- -- positive corner case --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : null } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : null } (4 rows) SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc1", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc2", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc3", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc4", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) --------------------------------------------------------------------- -- positive case to test manual window trim --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": 500 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006"}}, "quantity": 600 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}}, "quantity": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 9, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600009"}}, "quantity": 700 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "533.33333333333337123" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600005" } }, "quantity" : { "$numberDouble" : "566.66666666666662877" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600006" } }, "quantity" : { "$numberInt" : "600" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600007" } }, "quantity" : { "$numberDouble" : "633.33333333333337123" } } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600008" } }, "quantity" : { "$numberDouble" : "666.66666666666662877" } } { "_id" : { "$numberInt" : "9" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600009" } }, "quantity" : { "$numberInt" : "700" } } (9 rows) --------------------------------------------------------------------- -- positive case with different numeric types --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDecimal" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDecimal" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } (4 rows) SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberLong" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberDouble" : "503.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600011" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600012" } }, "quantity" : { "$numberDecimal" : "501.000000000000" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600013" } }, "quantity" : { "$numberDecimal" : "502.000000000000" } } { "_id" : { "$numberInt" : "8" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600014" } }, "quantity" : { "$numberDouble" : "503.0" } } (8 rows) SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberDecimal" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } (4 rows) --------------------------------------------------------------------- -- positive corner case with sortBy --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "5" }, "date" : { "$date" : { "$numberLong" : "1718841600001" } }, "quantity" : { "$numberInt" : "500" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600002" } }, "quantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "def", "cost" : { "$numberInt" : "4" }, "date" : { "$date" : { "$numberLong" : "1718841600004" } }, "quantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "4" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "date" : { "$date" : { "$numberLong" : "1718841600003" } }, "quantity" : null } (4 rows) --------------------------------------------------------------------- -- negative case --------------------------------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- without sortBy field SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: $linearFill requires specifying a top-level sortBy expression that contains exactly one element -- sortBy is not numeric or date SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: The sortBy parameter must contain either a numeric value or a date, but instead received string -- sortBy with repeated value in one partition SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: The sort field must not contain any duplicate values -- partionBy and partitionByFields both are present SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "partitionByFields": ["a"], "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: Only one of 'partitionBy' or 'partitionByFields' is allowed when using the '$fill'. -- partitionByFields element starts with $ SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["$a"], "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: FieldPath field names are not allowed to begin with the operators symbol '$'; consider using $getField or $setField instead. -- output field is not present in the document SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }}}]}'); ERROR: Required field '$fill.output' is missing -- fill non-numeric field SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: The value provided must be either a numeric type or explicitly null SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ERROR: The value provided must be either a numeric type or explicitly null -- fill with missing value SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": 1, "c": 5 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": 2, "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"output": {"c": { "value": "$a"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" } } (4 rows) -- fill with mixed types SELECT documentdb_api.drop_collection('db','filltest'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": 1, "b": 1, "c": 5 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": 2, "b": null, "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": 3, "b": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": 4, "b": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": 5, "b": 5, "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "linear" } ,"c": { "value": "$a" }}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberDouble" : "2.0" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "4" }, "b" : { "$numberDouble" : "4.0" }, "c" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "5" }, "c" : { "$numberInt" : "5" } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "locf" } ,"c": { "value": "$a" }}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "5" }, "c" : { "$numberInt" : "5" } } (5 rows) -- fill with multi methods SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "locf", "method": "linear" }}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberDouble" : "2.0" }, "c" : null } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "4" }, "b" : { "$numberDouble" : "4.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "5" }, "c" : null } (5 rows) -- explain plan validation EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "linear" }}}}]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> WindowAgg -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(collection.document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_4693_468212 collection Recheck Cond: (shard_key_value = '4693'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4693'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "value": 1 }}}}]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_4693_468212 collection Recheck Cond: (shard_key_value = '4693'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4693'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "c": { "method": "linear" }, "b": { "value": 1 }}}}]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> WindowAgg -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(collection.document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_4693_468212 collection Recheck Cond: (shard_key_value = '4693'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4693'::bigint) (13 rows) bson_aggregation_pipeline_stage_setWindowFields.out000066400000000000000000046624441507310017400423220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 455000; SET documentdb.next_collection_id TO 4550; SET documentdb.next_collection_index_id TO 4550; SELECT 1 from documentdb_api.drop_collection('db','setWindowFields'); ?column? --------------------------------------------------------------------- 1 (1 row) -- Add error and validation tests for setWindowFields stage SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 10, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "def", "cost": 8, "quantity": 505, "date": { "$date": { "$numberLong": "1718841620000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "ghi", "cost": 4, "quantity": 506, "date": { "$date": { "$numberLong": "1718841630000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 10, "quantity": 507, "date": { "$date": { "$numberLong": "1718841640000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "def", "cost": 8, "quantity": 508, "date": { "$date": { "$numberLong": "1718841680000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "ghi", "cost": 4, "quantity": 509, "date": { "$date": { "$numberLong": "1718841700000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "abc", "cost": 10, "quantity": 510, "date": { "$date": { "$numberLong": "1718841800000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "def", "cost": 8, "quantity": 511, "date": { "$date": { "$numberLong": "1718841900000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 12, "a": "ghi", "cost": 4, "quantity": 512, "date": { "$date": { "$numberLong": "1718842600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 13, "a": "abc", "cost": 80, "quantity": 515, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 1, "a": "abc", "cost": 80, "quantity": 515, "date": 1 }', NULL); -- date type mismatch NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 2, "a": "abc", "cost": 80, "quantity": 515 }', NULL); -- date is missing insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 3, "a": "abc", "cost": "80", "quantity": 515 }', NULL); -- cost type mismatch insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 4, "a": "abc", "quantity": 515 }', NULL); -- cost is missing insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations of $setWindowFields stage and negative test cases SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": "Not an object" }]}'); ERROR: the $setWindowFields stage specification must be an object, found string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "partitionBy": 1, "sortBy": {"a": 1} } }]}'); ERROR: The BSON field '$setWindowFields.output' is required but was not provided SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "unknownField": {} } }]}'); ERROR: The BSON field '$setWindowFields.unknownField' is not recognized as a valid field. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": [1] } }]}'); ERROR: A partition expression cannot be evaluated to yield an array type value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": { "$concatArrays": [[1], [2]] }}}]}'); ERROR: PlanExecutor error during aggregation :: caused by :: An expression used to partition cannot evaluate to value of type array SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": 1, "sortBy": { "a" : "asc" }}}]}'); ERROR: Sort direction value "asc" is not valid SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": 1, "sortBy": "Not an Object"}}]}'); ERROR: The BSON field '$setWindowFields.sortBy' has an incorrect type 'string'; it should be of type 'object'. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": "Not an object" }}}]}'); ERROR: Expected 'document' type for 'total' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$unknownOperator": 1}}}}]}'); ERROR: Unrecognized window function, $unknownOperator SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "$total": {"$sum": 1}}}}]}'); ERROR: FieldPath field names are not allowed to begin with the operators symbol '$'; consider using $getField or $setField instead. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "": {"$unknownOperator": 1}}}}]}'); ERROR: FieldPath cannot be created from an empty string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1}, "total2": "Not an object" }}}]}'); ERROR: Expected 'document' type for 'total2' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": "Not an object"}}}}]}'); ERROR: The 'window' field is required to be a valid object SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "unknownBound": [1, 2] }}}}}]}'); ERROR: 'window' field can only contain 'documents' as the only argument or 'range' with an optional 'unit' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "": [1, 2] }}}}}]}'); ERROR: 'window' field can only contain 'documents' as the only argument or 'range' with an optional 'unit' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": "not an array" }}}}}]}'); ERROR: Window bounds should consist of exactly two elements in the array: documents: "not an array" SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": { "a": 1, "b": 2 } }}}}}]}'); ERROR: Window bounds should consist of exactly two elements in the array: range: { "a" : 1, "b" : 2 } SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current", "current"], "unknownBound": [1, 2] }}}}}]}'); ERROR: The 'window' field specifying documents is not allowed to be used together with other fields . SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["current", "current"], "unknownBound": [1, 2] }}}}}]}'); ERROR: The 'window' field specifying range is not allowed to be used together with other fields besides 'unit'. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current", "current"], "unit": "second" }}}}}]}'); ERROR: The 'unit' parameter is valid only when bounds are defined using a range-based specification. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [-1 , 1] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , 1] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , "current"] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , "unbounded"] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["unbounded" , 1] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [-1 , "unbounded"] }}}}}]}'); ERROR: Missing sortBy field for document-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["" , ""] }}}}}]}'); ERROR: The window boundaries value must be either 'unbounded', 'current', or a specific numeric value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); ERROR: Expected a single sort by field for range-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1, "b": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); ERROR: Expected a single sort by field for range-based window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": -1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); ERROR: Expected ascending sortBy field definition SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1] }}}}}]}'); ERROR: Window bounds should consist of exactly two elements in the array: documents: [ 1 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, 2, 3] }}}}}]}'); ERROR: Window bounds should consist of exactly two elements in the array: documents: [ 1, 2, 3 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, "text"] }}}}}]}'); ERROR: The window boundaries value must be either 'unbounded', 'current', or a specific numeric value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, {"a": 1}] }}}}}]}'); ERROR: The numeric boundaries specified for the document must be provided as an integer value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, -1] }}}}}]}'); ERROR: The lower boundary should never be greater than the specified upper boundary: [ 1, -1 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": [1, "current"] }}}}}]}'); ERROR: The lower boundary should never be greater than the specified upper boundary: [ 1, "current" ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["current", -2] }}}}}]}'); ERROR: The lower boundary should never be greater than the specified upper boundary: [ "current", -2 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2] }}}}}]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (date) was provided. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "day" }}}}}]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (string) was provided. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "days" }}}}}]}'); ERROR: Unrecognized value for time unit: days SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "Day" }}}}}]}'); ERROR: Unrecognized value for time unit: Day SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": {"_id": 1 }}, {"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "second"}}}}}]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (int) was provided. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 2 }}, {"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "second"}}}}}]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (undefined) was provided. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 3 }}, {"$setWindowFields": { "sortBy": {"cost": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2]}}}}}]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (string) was provided. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 4 }}, {"$setWindowFields": { "sortBy": {"cost": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2]}}}}}]}'); ERROR: SortBy range is invalid: expected a Number type field, but received undefined instead -- Common Positive tests for $setWindowFields stage and explains SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "total" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "total" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "total" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "total" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "total" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"output": {"total": { "$sum": 1}}}}]}'); -- No partitionBy or sortBy document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "13" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": {"a": 1, "quantity": -1}, "output": {"total": { "$sum": 1}}}}]}'); -- No partitionBy document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "total" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "13" } } (13 rows) -- [Optimization] Partition by on same shard key pushes the $setWindowFields stage to the shard SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db', 'setWindowFields_sharded', '{"a": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$cost", "output": {"total": { "$sum": 1}}}}, {"$sort": { "a": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "1" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$cost", "output": {"total": { "$sum": 1}}}}]}'); -- different partitionby, not pushed to shards QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 74_1 -> WindowAgg Output: remote_scan.document, bsonsum(documentdb_api_internal.bson_expression_get(remote_scan.total, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (?), remote_scan."?partitionBy?" -> Sort Output: remote_scan."?partitionBy?", remote_scan.document, remote_scan.total Sort Key: remote_scan."?partitionBy?" -> Custom Scan (Citus Adaptive) Output: remote_scan."?partitionBy?", remote_scan.document, remote_scan.total Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, document AS total, documentdb_api_internal.bson_expression_partition_get(document, '{ "" : "$cost" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "?partitionBy?" FROM documentdb_data.documents_4552_455048 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4552_455048 collection Output: document, document, documentdb_api_internal.bson_expression_partition_get(document, '{ "" : "$cost" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_core.bson_repath_and_build('total'::text, total), false) AS document FROM (SELECT intermediate_result.document, intermediate_result.total FROM read_intermediate_result('74_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, total documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result.document, documentdb_core.bson_repath_and_build('total'::text, intermediate_result.total), false) Function Call: read_intermediate_result('74_1'::text, 'binary'::citus_copy_format) (25 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}, { "$sort" : {"a" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "1" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); -- same partitioBy as shardkey, pushed to shards QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(worker_column_1, documentdb_core.bson_repath_and_build('total'::text, worker_column_2), false) AS document FROM (SELECT agg_stage_0.document AS worker_column_1, agg_stage_0.total AS worker_column_2 FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (PARTITION BY collection.shard_key_value ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS total FROM documentdb_data.documents_4552_455048 collection) agg_stage_0) worker_subquery Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_merge_documents(agg_stage_0.document, documentdb_core.bson_repath_and_build('total'::text, agg_stage_0.total), false) -> WindowAgg Output: collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (?), collection.shard_key_value -> Index Scan using _id_ on documentdb_data.documents_4552_455048 collection Output: collection.shard_key_value, collection.document (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$match": {"a": "def"}}, {"$setWindowFields": { "output": {"total": { "$sum": 1}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "1" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$match": {"a": "def"}}, {"$setWindowFields": { "output": {"total": { "$sum": 1}}}}]}'); -- target a single shard with $match, pushed to shard QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_core.bson_repath_and_build('total'::text, total), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS total FROM documentdb_data.documents_4552_455051 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "def" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8022442720571987527'::bigint))) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_1 Output: documentdb_api_internal.bson_dollar_merge_documents(agg_stage_1.document, documentdb_core.bson_repath_and_build('total'::text, agg_stage_1.total), false) -> WindowAgg Output: collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (?) -> Seq Scan on documentdb_data.documents_4552_455051 collection Output: collection.document Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "def" }'::documentdb_core.bson) AND (collection.shard_key_value = '8022442720571987527'::bigint)) (14 rows) -- Push to shard doesn't work when there is multi key shard key SELECT documentdb_api.shard_collection('db', 'setWindowFields_sharded', '{"a": "hashed", "b": "hashed"}', true); shard_collection --------------------------------------------------------------------- (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); -- same partitioBy as first key in shardkey, not pushed to shards QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 93_1 -> WindowAgg Output: remote_scan.document, bsonsum(documentdb_api_internal.bson_expression_get(remote_scan.total, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (?), remote_scan."?partitionBy?" -> Sort Output: remote_scan."?partitionBy?", remote_scan.document, remote_scan.total Sort Key: remote_scan."?partitionBy?" -> Custom Scan (Citus Adaptive) Output: remote_scan."?partitionBy?", remote_scan.document, remote_scan.total Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, document AS total, documentdb_api_internal.bson_expression_partition_get(document, '{ "" : "$a" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "?partitionBy?" FROM documentdb_data.documents_4552_455056 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4552_455056 collection Output: document, document, documentdb_api_internal.bson_expression_partition_get(document, '{ "" : "$a" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_core.bson_repath_and_build('total'::text, total), false) AS document FROM (SELECT intermediate_result.document, intermediate_result.total FROM read_intermediate_result('93_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, total documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result.document, documentdb_core.bson_repath_and_build('total'::text, intermediate_result.total), false) Function Call: read_intermediate_result('93_1'::text, 'binary'::citus_copy_format) (25 rows) --------------------------------------------------------------------- -- $sum accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$sum": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1526" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2036" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "2022" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1518" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "1011" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1010" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1021" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1526" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "1518" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1011" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "1010" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "1021" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1011" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1017" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "1011" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1010" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1015" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1021" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1526" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "2036" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "1526" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2036" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "1521" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$sum": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "2030" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1005" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1512" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "2022" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "2537" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "1007" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1515" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "2026" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "1009" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "1518" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "2030" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "1017" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "1521" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "1526" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1520" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "1016" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "1019" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "1524" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "1515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "1007" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "1021" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "1527" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "1518" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "1009" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "2" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "4" } } (13 rows) -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "1" } } (13 rows) --------------------------------------------------------------------- -- $count accumulator tests --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); document --------------------------------------------------------------------- (0 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [0, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "2" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [-10, 10]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalCount" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalCount" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalCount" : { "$numberInt" : "3" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "2" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "1" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "4" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "countInGroup" : { "$numberInt" : "1" } } (13 rows) -- Should error since $count take no argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": 1}}}}]}'); ERROR: $count can only receive an empty object as its valid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": "str"}}}}]}'); ERROR: $count can only receive an empty object as its valid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": true }}}}]}'); ERROR: $count can only receive an empty object as its valid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": {"fst": 1} }}}}]}'); ERROR: $count can only receive an empty object as its valid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": [1, "$a"] }}}}]}'); ERROR: $count can only receive an empty object as its valid input -- test on shard collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "countInGroup" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "countInGroup" : { "$numberInt" : "1" } } (3 rows) -- test on shard collection with range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-0.5, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-1, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "2" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalCount" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalCount" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalCount" : { "$numberInt" : "2" } } (3 rows) --------------------------------------------------------------------- -- $avg accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "509.5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "508.66666666666668561" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "505.5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "505.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "504.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "510.5" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "515.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "504.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "510.0" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "505.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "511.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "503.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "512.0" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "509.0" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$avg": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "501.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "502.5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "504.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "505.5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "502.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "503.5" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "505.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "503.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "504.5" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "507.5" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberDouble" : "508.5" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberDouble" : "508.66666666666668561" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "506.66666666666668561" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberDouble" : "509.5" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberDouble" : "505.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberDouble" : "503.5" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberDouble" : "510.5" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberDouble" : "509.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberDouble" : "504.5" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$avg": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberDouble" : "502.5" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberDouble" : "504.0" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberDouble" : "507.0" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberDouble" : "508.5" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberDouble" : "515.0" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberDouble" : "503.5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberDouble" : "505.0" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberDouble" : "508.0" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberDouble" : "509.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberDouble" : "504.5" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberDouble" : "509.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberDouble" : "510.5" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$avg": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberDouble" : "507.39999999999997726" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberDouble" : "506.5" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberDouble" : "506.0" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberDouble" : "512.0" } } (13 rows) --------------------------------------------------------------------- -- $push accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$$varRef", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "let": {"varRef": "Hello"}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ "Hello", "Hello", "Hello", "Hello" ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$push": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$match": {"quantity": {"$type": "number"}}}, {"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$push": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$push": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : [ { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- Missing Field Test --------------------------------------------------------------------- SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 1, "a": "abc", "quantity": 30, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 2, "a": "abc", "quantity": [], "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 3, "a": "abc", "quantity": {}, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 4, "a": "abc", "quantity": null, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 5, "a": "abc", "quantity": { "$undefined": true }, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 6, "a": "abc", "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Should push every quantity except a NULL from _id: 6 document where quantity is missing SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "$numberInt" : "30" }, [ ], { }, null, { "$undefined" : true } ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": { "qty": "$quantity" }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ { "qty" : { "$numberInt" : "30" } }, { "qty" : [ ] }, { "qty" : { } }, { "qty" : null }, { "qty" : { "$undefined" : true } }, { } ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": [ "$quantity" ], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ [ { "$numberInt" : "30" } ], [ [ ] ], [ { } ], [ null ], [ null ], [ null ] ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": "$non_existing" } } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : [ ] } (6 rows) --------------------------------------------------------------------- -- $addToSet accumulator tests --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": 1}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "1" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": [1]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ [ { "$numberInt" : "1" } ] ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": []}}}}]}'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": {}}}}}]}'); document --------------------------------------------------------------------- (0 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": ["$$varRef1", "$$varRef2"], "window": {"documents": ["unbounded", "unbounded"]}}}}}], "let": {"varRef1": "Hello", "varRef2": "World"}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ [ "Hello", "World" ] ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ [ "Hello", "World" ] ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"addedSet": { "$addToSet": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "addedSet" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "addedSet" : [ { "$numberInt" : "504" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "addedSet" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "addedSet" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "addedSet" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "addedSet" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "addedSet" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$match": {"quantity": {"$type": "number"}}}, {"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$addToSet": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$addToSet": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : [ { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- Missing Field Test --------------------------------------------------------------------- SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 1, "a": "abc", "quantity": 30, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 2, "a": "abc", "quantity": [], "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 3, "a": "abc", "quantity": {}, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 4, "a": "abc", "quantity": null, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 5, "a": "abc", "quantity": { "$undefined": true }, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 6, "a": "abc", "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Should addToSet every quantity except a NULL from _id: 6 document where quantity is missing SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null, [ ], { }, { "$numberInt" : "30" } ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": { "qty": "$quantity" }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ { "qty" : null }, { "qty" : { } }, { "qty" : [ ] }, { "qty" : { "$undefined" : true } }, { "qty" : { "$numberInt" : "30" } } ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": [ "$quantity" ], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ [ { "$numberInt" : "30" } ], [ { } ], [ [ ] ], [ null ] ] } (6 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": "$non_existing" } } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "quantity" : { "$numberInt" : "30" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "quantity" : [ ], "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "quantity" : { }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : null, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } { "_id" : { "$numberInt" : "5" }, "a" : "abc", "quantity" : { "$undefined" : true }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } { "_id" : { "$numberInt" : "6" }, "a" : "abc", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "addedSet" : [ null ] } (6 rows) --------------------------------------------------------------------- -- $covariancePop & $covarianceSamp accumulator tests --------------------------------------------------------------------- -- empty collection SELECT documentdb_api.insert_one('db','empty_covar_col',' { "_id": 0, "x": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_covar_col", "pipeline": [{"$setWindowFields": {"output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "covariancePop" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_covar_col", "pipeline": [{"$setWindowFields": {"output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "covarianceSamp" : null } (1 row) -- collection with single document SELECT documentdb_api.insert_one('db','single_col',' { "_id": 0, "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_col", "pipeline": [{"$setWindowFields": {"output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covariancePop" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_col", "pipeline": [{"$setWindowFields": {"output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covarianceSamp" : null } (1 row) -- document with non-numeric values SELECT documentdb_api.insert_one('db','non_numeric_col',' { "_id": 0, "x": "a", "y": "b" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','non_numeric_col',' { "_id": 1, "x": "c", "y": "d" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : "a", "y" : "b", "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : "c", "y" : "d", "covariancePop" : null } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : "a", "y" : "b", "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : "c", "y" : "d", "covarianceSamp" : null } (2 rows) -- document with mixed values SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 0, "x": 1, "y": "a" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 1, "x": 2, "y": 0 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 2, "x": 3, "y": "b" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 3, "x": 4, "y": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : "a", "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "0" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : "b", "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "1" }, "covariancePop" : { "$numberDouble" : "0.5" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : "a", "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "0" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : "b", "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "1" }, "covarianceSamp" : { "$numberDouble" : "1.0" } } (4 rows) -- document with NAN values SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 0, "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 1, "x": 2, "y": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "NaN" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 3, "x": 4, "y": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "NaN" }, "covariancePop" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "covariancePop" : { "$numberDecimal" : "NaN" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "NaN" }, "covarianceSamp" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "covarianceSamp" : { "$numberDecimal" : "NaN" } } (4 rows) -- document with Infinity values SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 0, "type": "a", "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 1, "type": "a", "x": 2, "y": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 2, "type": "a", "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 3, "type": "a", "x": 4, "y": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 5, "type": "b", "x": 1, "y": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 6, "type": "b", "x": 2, "y": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 7, "type": "b", "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 8, "type": "b", "x": 4, "y": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "type" : "a", "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "type" : "a", "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "Infinity" }, "covariancePop" : { "$numberDecimal" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "type" : "a", "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "covariancePop" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "type" : "a", "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "covariancePop" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "5" }, "type" : "b", "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "6" }, "type" : "b", "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "7" }, "type" : "b", "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "covariancePop" : { "$numberDecimal" : "-Infinity" } } { "_id" : { "$numberInt" : "8" }, "type" : "b", "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "Infinity" }, "covariancePop" : { "$numberDecimal" : "NaN" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "type" : "a", "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "type" : "a", "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "Infinity" }, "covarianceSamp" : { "$numberDecimal" : "Infinity" } } { "_id" : { "$numberInt" : "2" }, "type" : "a", "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "covarianceSamp" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "type" : "a", "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "covarianceSamp" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "5" }, "type" : "b", "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "6" }, "type" : "b", "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "type" : "b", "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "covarianceSamp" : { "$numberDecimal" : "-Infinity" } } { "_id" : { "$numberInt" : "8" }, "type" : "b", "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "Infinity" }, "covarianceSamp" : { "$numberDecimal" : "NaN" } } (8 rows) -- document with Decimal128 values SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 0, "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 1, "x": 2, "y": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "4.0" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 3, "x": 4, "y": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "4.0" }, "covariancePop" : { "$numberDecimal" : "0.6666666666666666666666666666666667" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "covariancePop" : { "$numberDecimal" : "1.2500000000000000000000000000" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "4.0" }, "covarianceSamp" : { "$numberDecimal" : "1.0000000000000000000000000000" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "covarianceSamp" : { "$numberDecimal" : "1.666666666666666666666666666666667" } } (4 rows) -- number overflow SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 0, "x": 1, "y": {"$numberDecimal": "100000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 1, "x": 2, "y": {"$numberDecimal": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "1000000000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 3, "x": 4, "y": {"$numberDecimal": "1000000000000000000"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberDecimal" : "100000004" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "10000000007" }, "covariancePop" : { "$numberDecimal" : "2475000000.750000000000000000000000" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "1000000000000013" }, "covariancePop" : { "$numberDecimal" : "333333300000003.0000000000000000000" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "1000000000000000000" }, "covariancePop" : { "$numberDecimal" : "375124998712499999.250000000000000" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberDecimal" : "100000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "10000000007" }, "covarianceSamp" : { "$numberDecimal" : "4950000001.500000000000000000000000" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "1000000000000013" }, "covarianceSamp" : { "$numberDecimal" : "499999950000004.5000000000000000000" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "1000000000000000000" }, "covarianceSamp" : { "$numberDecimal" : "500166664949999999.000000000000000" } } (4 rows) -- long values return double SELECT documentdb_api.insert_one('db','long_col',' { "_id": 0, "x": 1, "y": {"$numberLong": "10000000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_col',' { "_id": 1, "x": 2, "y": {"$numberLong": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_col',' { "_id": 2, "x": 3, "y": {"$numberLong": "10000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_col',' { "_id": 3, "x": 4, "y": {"$numberLong": "10000000016"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : { "$numberDouble" : "0.75" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : { "$numberDouble" : "5.25" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : { "$numberDouble" : "1.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : { "$numberDouble" : "4.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : { "$numberDouble" : "7.0" } } (4 rows) -- evaluate data in expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", {"$multiply": ["$x", "$y"]}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : { "$numberDouble" : "2500000002.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : { "$numberDouble" : "6666666678.3333330154" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : { "$numberDouble" : "12500000025.625" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", {"$multiply": ["$x", "$y"]}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : { "$numberDouble" : "5000000005.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : { "$numberDouble" : "10000000017.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : { "$numberDouble" : "16666666700.833333969" } } (4 rows) -- negative cases -- incorrect arguments won't throw error SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y", "$z"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": [5], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["a", {}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covariancePop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covariancePop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covariancePop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y", "$z"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": [5], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["a", {}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberLong" : "10000000004" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberLong" : "10000000007" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberLong" : "10000000013" }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberLong" : "10000000016" }, "covarianceSamp" : null } (4 rows) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 0, "x": 1, "y": 2, "type": "a", "date": { "$date": { "$numberLong": "1718841600000" } } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 1, "x": 2, "y": 3, "type": "a", "date": { "$date": { "$numberLong": "1718841605000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 2, "x": 3, "y": 4, "type": "a", "date": { "$date": { "$numberLong": "1718841610000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 3, "x": 4, "y": 5, "type": "a", "date": { "$date": { "$numberLong": "1718841615000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 4, "x": 5, "y": 6, "type": "a", "date": { "$date": { "$numberLong": "1718841620000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 5, "x": 6, "y": 7, "type": "a", "date": { "$date": { "$numberLong": "1718841630000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 6, "x": 7, "y": 8, "type": "b", "date": { "$date": { "$numberLong": "1718841640000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 7, "x": 8, "y": 9, "type": "b", "date": { "$date": { "$numberLong": "1718841680000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 8, "x": 9, "y": 10, "type": "b", "date": { "$date": { "$numberLong": "1718841700000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 9, "x": 10, "y": 11, "type": "b", "date": { "$date": { "$numberLong": "1718841800000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 10, "x": 11, "y": 12, "type": "b", "date": { "$date": { "$numberLong": "1718841900000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_col',' { "_id": 11, "x": 12, "y": 13, "type": "b", "date": { "$date": { "$numberLong": "1718842600000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- without window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } (12 rows) -- document window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : null } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } (12 rows) -- range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"range": [-2, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"range": [-2, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : null } (12 rows) -- unsharded collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "5.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "8.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "11.666666666666666075" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "5.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "8.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "11.666666666666666075" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "4.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "6.6666666666666669627" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "10.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "14.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "4.0" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "6.6666666666666669627" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "10.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "14.0" } } (12 rows) -- shard collection SELECT documentdb_api.shard_collection('db', 'window_col', '{ "type": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "0.25" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "0.66666666666666662966" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "1.25" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "2.9166666666666665186" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "1.6666666666666667407" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "2.5" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "3.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covariancePop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covariancePop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covariancePop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covariancePop" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covariancePop" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covariancePop" : { "$numberDouble" : "5.0" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covariancePop" : { "$numberDouble" : "5.0" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covariancePop" : { "$numberDouble" : "8.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covariancePop" : { "$numberDouble" : "8.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covariancePop" : { "$numberDouble" : "11.666666666666666075" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covariancePop" : { "$numberDouble" : "11.666666666666666075" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "covarianceSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "covarianceSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "covarianceSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "4" }, "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "covarianceSamp" : { "$numberDouble" : "4.0" } } { "_id" : { "$numberInt" : "5" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "covarianceSamp" : { "$numberDouble" : "4.0" } } { "_id" : { "$numberInt" : "6" }, "x" : { "$numberInt" : "7" }, "y" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "covarianceSamp" : { "$numberDouble" : "6.6666666666666669627" } } { "_id" : { "$numberInt" : "7" }, "x" : { "$numberInt" : "8" }, "y" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "covarianceSamp" : { "$numberDouble" : "6.6666666666666669627" } } { "_id" : { "$numberInt" : "8" }, "x" : { "$numberInt" : "9" }, "y" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "covarianceSamp" : { "$numberDouble" : "10.0" } } { "_id" : { "$numberInt" : "9" }, "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "covarianceSamp" : { "$numberDouble" : "10.0" } } { "_id" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "11" }, "y" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "covarianceSamp" : { "$numberDouble" : "14.0" } } { "_id" : { "$numberInt" : "11" }, "x" : { "$numberInt" : "12" }, "y" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "covarianceSamp" : { "$numberDouble" : "14.0" } } (12 rows) --------------------------------------------------------------------- -- $rank accumulator tests --------------------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "rank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "rank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "rank" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rank" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "rank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "rank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "rank" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "rank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "rank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "rank" : { "$numberInt" : "4" } } (13 rows) -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rank" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "rank" : { "$numberInt" : "1" } } (13 rows) -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : { "$numberInt" : "515" }, "rank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$numberInt" : "1" }, "rank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "rank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : "80", "quantity" : { "$numberInt" : "515" }, "rank" : { "$numberInt" : "4" } } (4 rows) -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}, "window": []}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}, "window": {"documents": [-1, 1]}}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when input is not empty document to $rank SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {"a":1}}}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": "$a" }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"rank": { "$rank": {} }}}}]}'); ERROR: $rank must be provided along with a top-level sortBy expression that contains exactly one element SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {} }}}}]}'); ERROR: $rank must be provided along with a top-level sortBy expression that contains exactly one element -- error when window is present > rank input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {"a":1}, "window":[] }}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when rank is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {"a":1} }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {} }}}}]}'); ERROR: $rank must be provided along with a top-level sortBy expression that contains exactly one element --------------------------------------------------------------------- -- $denseRank accumulator tests --------------------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "denseRank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "denseRank" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "denseRank" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "denseRank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "denseRank" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "denseRank" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "denseRank" : { "$numberInt" : "4" } } (13 rows) -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "denseRank" : { "$numberInt" : "1" } } (13 rows) -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : { "$numberInt" : "515" }, "denseRank" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$numberInt" : "1" }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "denseRank" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : "80", "quantity" : { "$numberInt" : "515" }, "denseRank" : { "$numberInt" : "3" } } (4 rows) -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}, "window": []}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}, "window": {"documents": [-1, 1]}}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when input is not empty document to $denseRank SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {"a":1}}}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": "$a" }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); ERROR: $denseRank must be provided along with a top-level sortBy expression that contains exactly one element SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); ERROR: $denseRank must be provided along with a top-level sortBy expression that contains exactly one element -- error when window is present > denseRank input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {"a":1}, "window":[] }}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when denseRank is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {"a":1} }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); ERROR: $denseRank must be provided along with a top-level sortBy expression that contains exactly one element --------------------------------------------------------------------- -- $documentNumber accumulator tests --------------------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "rowNumber" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rowNumber" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "rowNumber" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "rowNumber" : { "$numberInt" : "4" } } (13 rows) -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "rowNumber" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "rowNumber" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "rowNumber" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "rowNumber" : { "$numberInt" : "4" } } (13 rows) -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : "abc", "quantity" : { "$numberInt" : "515" }, "rowNumber" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$numberInt" : "1" }, "rowNumber" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "rowNumber" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "a" : "abc", "cost" : "80", "quantity" : { "$numberInt" : "515" }, "rowNumber" : { "$numberInt" : "4" } } (4 rows) -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}, "window": []}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}, "window": {"documents": [-1, 1]}}}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when input is not empty document to $documentNumber SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {"a":1}}}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": "$a" }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); ERROR: $documentNumber must be provided along with a top-level sortBy expression that contains exactly one element SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); ERROR: $documentNumber must be provided along with a top-level sortBy expression that contains exactly one element -- error when window is present > rowNumber input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {"a":1}, "window":[] }}}}]}'); ERROR: Rank-style window functions do not accept any additional arguments -- error when rowNumber is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {"a":1} }}}}]}'); ERROR: A value of '{}' must be explicitly assigned to (None) -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); ERROR: $documentNumber must be provided along with a top-level sortBy expression that contains exactly one element --------------------------------------------------------------------- -- $integral and $derivative accumulator tests --------------------------------------------------------------------- SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" }}, "a": "abc", "kilowatts": 2.95}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" }}, "a": "abc", "kilowatts": 2.7}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" }}, "a": "abc", "kilowatts": 2.6}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" }}, "a": "abc", "kilowatts": 2.98}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" }}, "a": "abc", "kilowatts": 2.5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" }}, "a": "abc", "kilowatts": 2.25}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" }}, "a": "abc", "kilowatts": 2.75}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" }}, "a": "abc", "kilowatts": 2.82}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.023541666666666665603" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.04562499999999999889" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.019791666666666665741" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.040624999999999994449" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "minute" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.04533333333333333659" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.044041666666666666463" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -10, 20 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "millisecond" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "84750.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "164250.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "247950.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "71250.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "146250.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "229800.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "second" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "84.75" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "164.25" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "247.94999999999998863" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "71.25" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "146.25" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "229.80000000000001137" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "minute" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "1.4125000000000000888" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "2.7375000000000002665" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "4.1325000000000002842" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "1.1875" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "2.4375" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "3.8300000000000000711" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "day" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00098090277777777780573" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.001901041666666666765" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.002869791666666666758" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00082465277777777777537" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0016927083333333333912" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0026597222222222221752" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "week" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00014012896825396826571" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00027157738095238102838" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00040997023809523813927" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00011780753968253968413" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00024181547619047619874" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.00037996031746031746134" } } (8 rows) -- Negative tests -- unknown argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour", "unknown": 1 }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: $integral received an unexpected argument: unknown -- $integral (with no 'unit') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: $integral (with no 'unit') expects the sortBy field to be numeric -- $integral (with no 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: $integral requires a sortBy -- $integral sort by unknown field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "unknown": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: $integral (with no 'unit') expects the sortBy field to be numeric -- $integral with invalid 'unit' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "year" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: The specified unit must be 'week' or a smaller time interval -- $integral with no input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: $integral needs a valid 'input' expression -- $integral with invalid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$unknown", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: The input value of $integral window function must be a vector of 2 value, the first value must be numeric or date type and the second must be numeric. -- $integral with invalid window range SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, "current" ] } } } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (date) was provided. -- $integral input is str SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$str", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ERROR: The input value of $integral window function must be a vector of 2 value, the first value must be numeric or date type and the second must be numeric. -- test integral without timestamp SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 0, "y": 1}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 1, "y": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 2, "y": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 3, "y": 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 0, "y": 100}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 2, "y": 105}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 4, "y": 107}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 6, "y": -100}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "4.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "212.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "7.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "4.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "212.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "7.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "1.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "417.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "424.0" } } (8 rows) -- Negative tests, common negative tests for $integral -- $integral (with unit and without timestamp) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y", "unit": "hour" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); ERROR: $integral with 'unit' requires that the sortBy field needs to be a Date value -- test derivative with timestamp SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 1295.1, "a": "abc"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 1295.63, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 1296.25, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 1296.76, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 10234.1, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 10234.33, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 10234.73, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 10235.13, "a": "abc"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "63.60000000002401066" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "74.399999999986903276" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "61.199999999998908606" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "63.60000000002401066" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "69.000000000005456968" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "66.400000000003274181" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "millisecond" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "1295.0999999999999091" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.7666666666673335899e-05" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.9166666666668181741e-05" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.8444444444445352806e-05" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "10234.100000000000364" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "10234.329999999999927" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "7.6666666666521152113e-06" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "10234.729999999999563" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.0499999999986660344e-05" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "10235.1299999999992" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.1444444444431509851e-05" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "second" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "1295.0999999999999091" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.017666666666673335601" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.019166666666668181335" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.01844444444444535286" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "10234.100000000000364" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "10234.329999999999927" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.0076666666666521145201" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "10234.729999999999563" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.010499999999986660629" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "10235.1299999999992" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.011444444444431508753" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "minute" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "1295.0999999999999091" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.0600000000004001777" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.1500000000000909495" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1.1066666666667213104" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "10234.100000000000364" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "10234.329999999999927" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.45999999999912688509" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "10234.729999999999563" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.62999999999919964466" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "10235.1299999999992" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "0.68666666666589060153" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "day" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "1295.0999999999999091" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1526.4000000005762558" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1656.0000000001309672" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "1593.6000000000785803" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "10234.100000000000364" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "10234.329999999999927" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "662.39999999874271452" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "10234.729999999999563" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "907.19999999884748831" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "10235.1299999999992" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "988.79999999888241291" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "week" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "1295.0999999999999091" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "10684.800000004033791" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "11592.000000000916771" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "11155.200000000548243" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "miles" : { "$numberDouble" : "10234.100000000000364" }, "a" : "abc", "truckAverageSpeed" : null } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "10234.329999999999927" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "4636.7999999911990017" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "10234.729999999999563" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "6350.3999999919324182" } } { "truckID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "10235.1299999999992" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "6921.5999999921759809" } } (8 rows) -- Negative tests -- $derivative (with no 'unit') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: $derivative with sortBy set to Date needs a specified 'unit' -- $derivative with invalid 'unit' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "month" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: The specified unit must be 'week' or a smaller time interval -- $derivative (with no 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: The 'unit' parameter is valid only when bounds are defined using a range-based specification. -- $derivative (with invalid str 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "str": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (undefined) was provided. -- $derivative sort by unknown field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "unknown": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (undefined) was provided. -- $derivative with no window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: $derivative requires explicit window bounds -- $derivative with invalid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$str", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: The input value of $derivative window function must be a vector of 2 value, the first value must be numeric or date type and the second must be numeric. -- $derivative with no input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: $derivative needs a valid 'input' expression -- unknown argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour", "unknown": 1 }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); ERROR: $derivative received an unexpected argument: unknown -- test derivative without timestamp -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "derivative" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "derivative" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "derivative" : null } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y"}, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "derivative" : null } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "derivative" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "derivative" : { "$numberDouble" : "1.75" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "derivative" : { "$numberDouble" : "-33.333333333333335702" } } (8 rows) -- Negative tests -- $derivative (with 'unit' and without timestamp) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y", "unit": "hour" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); ERROR: $derivative with 'unit' requires that the sortBy field needs to be a Date value -- $derivative (window is with date range) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ], "unit": "second"} } } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (int) was provided. -- test integral and derivative with shard SELECT documentdb_api.shard_collection('db', 'collNumeric', '{ "type": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db', 'deliveryFleet', '{ "type": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db', 'powerConsumption', '{ "type": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- derivative SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "derivative" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "derivative" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "derivative" : null } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y"}, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "derivative" : null } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "derivative" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "derivative" : { "$numberDouble" : "1.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "derivative" : null } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "derivative" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "derivative" : { "$numberDouble" : "1.75" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "derivative" : { "$numberDouble" : "-33.333333333333335702" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "63.60000000002401066" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "74.399999999986903276" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "61.199999999998908606" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "miles" : { "$numberDouble" : "1295.6300000000001091" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "63.60000000002401066" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "miles" : { "$numberDouble" : "1296.25" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "69.000000000005456968" } } { "truckID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "miles" : { "$numberDouble" : "1296.7599999999999909" }, "a" : "abc", "truckAverageSpeed" : { "$numberDouble" : "66.400000000003274181" } } (3 rows) -- integral SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "4.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "212.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "7.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "4.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "2.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "212.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "7.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "1.5" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "1" }, "integral" : { "$numberDouble" : "3.0" } } { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "5.5" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberInt" : "100" }, "integral" : { "$numberDouble" : "0.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "105" }, "integral" : { "$numberDouble" : "205.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "107" }, "integral" : { "$numberDouble" : "417.0" } } { "partitionID" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "6" }, "y" : { "$numberInt" : "-100" }, "integral" : { "$numberDouble" : "424.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.023541666666666665603" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.04562499999999999889" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.019791666666666665741" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.040624999999999994449" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "minute" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.068874999999999991784" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.04533333333333333659" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.063833333333333325266" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.044041666666666666463" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -10, 20 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9500000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.7000000000000001776" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.6000000000000000888" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.9799999999999999822" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.5" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814660000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.25" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.75" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "2", "timeStamp" : { "$date" : { "$numberLong" : "1589814720000" } }, "a" : "abc", "kilowatts" : { "$numberDouble" : "2.8199999999999998401" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } (8 rows) -- test integral and derivative with invalid mixed types -- insert non-date data SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 1295.1}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 1295.63}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 1296.25}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 1296.76}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 10234.1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 10234.33}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 10234.73}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 10235.13}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": 0, "miles": 10234.73}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "3", "timeStamp": 1, "miles": 10234.73}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- derivative failed SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "IntegralInvalid", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (int) was provided. -- integral failed SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "IntegralInvalid", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$integral": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); ERROR: Aggregation PlanExecutor encountered an - Invalid range - error: The specified sortBy field should be of type Date, but a different type (int) was provided. -- test integral and derivative with infinity/null/NaN mixed types SELECT documentdb_api.insert_one('db', 'collNaN', '{"partitionID": 1, "x": 0, "y": {"$numberDecimal": "NaN" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test NaN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNaN", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberDecimal" : "NaN" }, "integral" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNaN", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "partitionID" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "0" }, "y" : { "$numberDecimal" : "NaN" }, "integral" : null } (1 row) -- test infinity SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 0, "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 1, "x": 2, "y": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 3, "x": 4, "y": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 5, "x": 1, "y": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 6, "x": 2, "y": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 7, "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 8, "x": 4, "y": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col_integral", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "Infinity" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "integral" : { "$numberDouble" : "0.0" } } { "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "Infinity" }, "integral" : { "$numberDouble" : "0.0" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col_integral", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : null } { "x" : { "$numberInt" : "2" }, "y" : { "$numberDecimal" : "Infinity" }, "integral" : null } { "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "integral" : null } { "x" : { "$numberInt" : "4" }, "y" : { "$numberInt" : "4" }, "integral" : null } { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "integral" : null } { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "3" }, "integral" : null } { "x" : { "$numberInt" : "3" }, "y" : { "$numberDecimal" : "-Infinity" }, "integral" : null } { "x" : { "$numberInt" : "4" }, "y" : { "$numberDecimal" : "Infinity" }, "integral" : null } (8 rows) -- test null SELECT documentdb_api.insert_one('db','null_col',' { "_id": 0, "x": 1, "y": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','null_col',' { "_id": 1, "x": 2, "y": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','null_col',' { "_id": 2, "x": 3, "y": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','null_col',' { "_id": 3, "x": 4, "y": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "null_col", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); ERROR: The input value of $integral window function must be a vector of 2 value, the first value must be numeric or date type and the second must be numeric. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "null_col", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); ERROR: The input value of $derivative window function must be a vector of 2 value, the first value must be numeric or date type and the second must be numeric. -- test decimal overflow SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "kilowatts": { "$numberDecimal": "1E+320" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "kilowatts": { "$numberDecimal": "2E+340" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814700000" } }, "kilowatts": { "$numberDecimal": "2E+330" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814800000" } }, "kilowatts": { "$numberDecimal": "3E+332" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814900000" } }, "kilowatts": { "$numberDecimal": "3.123E+331" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerMeterDataDecimal", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "kilowatts" : { "$numberDecimal" : "1E+320" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814690000" } }, "kilowatts" : { "$numberDecimal" : "2E+340" }, "powerMeterKilowattHours" : { "$numberDecimal" : "1.666666666666666666675000000000000E+338" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814700000" } }, "kilowatts" : { "$numberDecimal" : "2E+330" }, "powerMeterKilowattHours" : { "$numberDecimal" : "1.944444444472222222230555555555556E+338" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814800000" } }, "kilowatts" : { "$numberDecimal" : "3E+332" }, "powerMeterKilowattHours" : { "$numberDecimal" : "1.944444486416666666675000000000000E+338" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814900000" } }, "kilowatts" : { "$numberDecimal" : "3.123E+331" }, "powerMeterKilowattHours" : { "$numberDecimal" : "1.944444532420833333341666666666667E+338" } } (5 rows) -- test double overflow SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "kilowatts": 1e308 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814900000" } }, "kilowatts": 1e308 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814910000" } }, "kilowatts": 1e308 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814920000" } }, "kilowatts": 1e308 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814930000" } }, "kilowatts": 1e308 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerMeterDataDouble", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); document --------------------------------------------------------------------- { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814630000" } }, "kilowatts" : { "$numberDouble" : "1.000000000000000011e+308" }, "powerMeterKilowattHours" : { "$numberDouble" : "0.0" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814900000" } }, "kilowatts" : { "$numberDouble" : "1.000000000000000011e+308" }, "powerMeterKilowattHours" : { "$numberDouble" : "Infinity" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814910000" } }, "kilowatts" : { "$numberDouble" : "1.000000000000000011e+308" }, "powerMeterKilowattHours" : { "$numberDouble" : "Infinity" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814920000" } }, "kilowatts" : { "$numberDouble" : "1.000000000000000011e+308" }, "powerMeterKilowattHours" : { "$numberDouble" : "Infinity" } } { "powerMeterID" : "1", "timeStamp" : { "$date" : { "$numberLong" : "1589814930000" } }, "kilowatts" : { "$numberDouble" : "1.000000000000000011e+308" }, "powerMeterKilowattHours" : { "$numberDouble" : "Infinity" } } (5 rows) --------------------------------------------------------------------- -- $shift accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Negative Tests --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); -- window not allowed with $shift ERROR: The $shift operator cannot be used with the 'window' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }, "window": {"range": [-1, 1]}}}}}]}'); -- range not allowed with $shift ERROR: The $shift operator cannot be used with the 'window' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }}}}}]}'); -- missing sortBy in $setWindowFields ERROR: 'sortBy' parameters must be specified for $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "by": 1 }}}}}]}'); -- missing ouput field in $shift ERROR: Operator $shift needs an 'output' expression. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity" }}}}}]}'); -- missing by field in $shift ERROR: The shift operator requires the 'by' parameter to be provided as an integer value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1.1 }}}}}]}'); -- non-integer by field in $shift ERROR: The parameter $shift:by requires an integer value, but received: 1.1 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": {"t": 1} }}}}}]}'); -- non-integer by field in $shift ERROR: The parameter $shift:by requires an integer value, but received: { "t" : 1 } SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": {"undefined": true} }}}}}]}'); -- non-integer by field in $shift ERROR: The parameter $shift:by requires an integer value, but received: { "undefined" : true } SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1, "default": "$quantity" }}}}}]}'); -- non-constant default expression in $shift ERROR: Expression '$shift:default' is required to produce a constant value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1, "default": ["$sasdf"] }}}}}]}'); -- non-constant default expression in $shift ERROR: Expression '$shift:default' is required to produce a constant value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 2147483649}}}}}]}'); -- by value greater than int32 max value ERROR: The parameter $shift:by requires an integer value, but received: 2147483649 --------------------------------------------------------------------- -- Valid tests --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "shiftQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "shiftQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "shiftQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "shiftQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "shiftQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "shiftQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "shiftQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "shiftQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "shiftQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "shiftQuantity" : null } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": -2 }}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "shiftQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "shiftQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "shiftQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "shiftQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "shiftQuantity" : null } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "shiftQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "shiftQuantity" : { "$numberInt" : "506" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": 0 }}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "shiftQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "shiftQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "shiftQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "80" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "shiftQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "shiftQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "shiftQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "shiftQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "shiftQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "shiftQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "shiftQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "shiftQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "4" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": 1, "default": "Not available" }}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "shiftQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "shiftQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "shiftQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "80" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : "Not available" } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "shiftQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "shiftQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "shiftQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "shiftQuantity" : "Not available" } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "shiftQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "shiftQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "shiftQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "shiftQuantity" : "Not available" } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": -2, "default": [0, 0] }}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "shiftQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "shiftQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "shiftQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "shiftQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "shiftQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "8" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "shiftQuantity" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "shiftQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "shiftQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "4" } ] } (13 rows) --------------------------------------------------------------------- -- $top accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) --------------------------------------------------------------------- -- $bottom accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "$numberInt" : "512" } } (13 rows) --------------------------------------------------------------------- -- $topN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- $bottomN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) /* Negative tests FOR $top(N)/$bottom(N) */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": [1]}}}}] }'); -- spec should be document ERROR: specification must be defined as an object, but the provided input was $topN :[ 1 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": "hello"}}}}] }'); -- spec should be document ERROR: specification must be defined as an object, but the provided input was $bottomN :"hello" SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$top": {"output": "hello"}}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottom": {"sortBy": {"quantity": 1}}}}}} ] }'); -- missing output field ERROR: The 'output' parameter is missing a required value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "hello", "sortBy": {"quantity": 1}}}}}} ] }'); -- missing n ERROR: Required value for 'n' is not provided SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"n": 2, "sortBy": {"quantity": 1}}}}}} ] }'); -- missing output ERROR: The 'output' parameter is missing a required value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "hello", "n": 2}}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "$quantity", "n": 2, "sortBy": {"quantity": 1}, "fourth": true}}}}} ] }'); -- extra field ERROR: Unrecognized argument passed to $bottomN: 'fourth' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": -2, "sortBy": {"quantity": 1}}}}}} ] }'); -- negative n ERROR: The value of 'n' must be strictly greater than 0, but the current value is -2 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": 2.2, "sortBy": {"quantity": 1}}}}}} ] }'); -- non-integer n ERROR: Expected 'integer' type for 'n' but found 'double' for value '2.2' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": "a", "sortBy": {"quantity": 1}}}}}} ] }'); -- non-integer n ERROR: Expected 'integer' type for 'n' but found 'string' for value '"a"' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": {"$undefined": true}, "sortBy": {"quantity": 1}}}}}} ] }'); -- undefined n ERROR: Expected 'integer' type for 'n' but found 'undefined' for value '{ "$undefined" : true }' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": {"$numberDecimal": "Infinity"}, "sortBy": {"quantity": 1}}}}}} ] }'); -- undefined n ERROR: Unable to convert out-of-range value Infinity into a long type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "$quantity", "n": 2, "sortBy": 1}}}}} ] }'); -- sortBy is not an object ERROR: Expected 'sortBy' parameter to already contain an object within the provided arguments to $bottomN --------------------------------------------------------------------- -- $stdDevPop & $stdDevSamp accumulator tests --------------------------------------------------------------------- -- empty collection SELECT documentdb_api.insert_one('db','empty_stddev_col',' { "_id": 0, "num": {} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { }, "stdDevPop" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { }, "stdDevSamp" : null } (1 row) -- collection with single document SELECT documentdb_api.insert_one('db','single_stddev_col',' { "_id": 0, "num": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "1" }, "stdDevPop" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "1" }, "stdDevSamp" : null } (1 row) -- document with non-numeric values SELECT documentdb_api.insert_one('db','non_numeric_stddev_col',' { "_id": 0, "num": "a"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','non_numeric_stddev_col',' { "_id": 1, "num": "c"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : "a", "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "num" : "c", "stdDevPop" : null } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : "a", "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : "c", "stdDevSamp" : null } (2 rows) -- document with mixed values SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 0, "num": "a" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 1, "num": 0 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 2, "num": "b" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 3, "num": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : "a", "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "0" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : "b", "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "1" }, "stdDevPop" : { "$numberDouble" : "0.5" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : "a", "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "0" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "num" : "b", "stdDevSamp" : null } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "1" }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } (4 rows) -- document with NAN values SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 0, "num": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 1, "num": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "NaN" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 3, "num": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "NaN" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "4" }, "stdDevPop" : { "$numberDouble" : "NaN" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "NaN" }, "stdDevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "4" }, "stdDevSamp" : { "$numberDouble" : "NaN" } } (4 rows) -- document with Infinity values SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 0, "type": "a", "num": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 1, "type": "a", "num": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 2, "type": "a", "num": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 3, "type": "a", "num": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 5, "type": "b", "num": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 6, "type": "b", "num": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 7, "type": "b", "num": {"$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 8, "type": "b", "num": {"$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "type" : "a", "num" : { "$numberInt" : "2" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "type" : "a", "num" : { "$numberDecimal" : "Infinity" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "2" }, "type" : "a", "num" : { "$numberDecimal" : "-Infinity" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "type" : "a", "num" : { "$numberInt" : "4" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "5" }, "type" : "b", "num" : { "$numberInt" : "2" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "6" }, "type" : "b", "num" : { "$numberInt" : "3" }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "type" : "b", "num" : { "$numberDecimal" : "-Infinity" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "8" }, "type" : "b", "num" : { "$numberDecimal" : "Infinity" }, "stdDevPop" : { "$numberDouble" : "NaN" } } (8 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stddevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "type" : "a", "num" : { "$numberInt" : "2" }, "stddevSamp" : null } { "_id" : { "$numberInt" : "1" }, "type" : "a", "num" : { "$numberDecimal" : "Infinity" }, "stddevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "2" }, "type" : "a", "num" : { "$numberDecimal" : "-Infinity" }, "stddevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "3" }, "type" : "a", "num" : { "$numberInt" : "4" }, "stddevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "5" }, "type" : "b", "num" : { "$numberInt" : "2" }, "stddevSamp" : null } { "_id" : { "$numberInt" : "6" }, "type" : "b", "num" : { "$numberInt" : "3" }, "stddevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "7" }, "type" : "b", "num" : { "$numberDecimal" : "-Infinity" }, "stddevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "8" }, "type" : "b", "num" : { "$numberDecimal" : "Infinity" }, "stddevSamp" : { "$numberDouble" : "NaN" } } (8 rows) -- document with Decimal128 values SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 0, "num": 2 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 1, "num": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "4.0" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 3, "num": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "4.0" }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "4.0" }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } (4 rows) -- number overflow SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 0, "num": {"$numberDecimal": "100000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 1, "num": {"$numberDecimal": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "1000000000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 3, "num": {"$numberDecimal": "1000000000000000000"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberDecimal" : "100000004" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberDecimal" : "10000000007" }, "stdDevPop" : { "$numberDouble" : "4950000001.5" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "1000000000000013" }, "stdDevPop" : { "$numberDouble" : "471402140215531.1875" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberDecimal" : "1000000000000000000" }, "stdDevPop" : { "$numberDouble" : "432868555379387136.0" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberDecimal" : "100000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberDecimal" : "10000000007" }, "stdDevSamp" : { "$numberDouble" : "7000357135.8681402206" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberDecimal" : "1000000000000013" }, "stdDevSamp" : { "$numberDouble" : "577347353591990.5" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberDecimal" : "1000000000000000000" }, "stdDevSamp" : { "$numberDouble" : "499833553944027136.0" } } (4 rows) -- long values return double SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 0, "x": 1, "num": {"$numberLong": "10000000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 1, "x": 2, "num": {"$numberLong": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 2, "x": 3, "num": {"$numberLong": "10000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 3, "x": 4, "num": {"$numberLong": "10000000016"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevPop" : { "$numberDouble" : "1.5" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevPop" : { "$numberDouble" : "3.7416573867739413295" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevPop" : { "$numberDouble" : "4.7434164902525690621" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevSamp" : { "$numberDouble" : "2.1213203435596423851" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevSamp" : { "$numberDouble" : "4.582575694955839829" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevSamp" : { "$numberDouble" : "5.4772255750516611883" } } (4 rows) -- large values return nan SELECT documentdb_api.insert_one('db','large_stddev_col',' { "_id": 0, "num": {"$numberDecimal": "1E+310" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','large_stddev_col',' { "_id": 1, "num": {"$numberDecimal": "2E+310" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": 1, "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberDecimal" : "1E+310" }, "stdDevPop" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberDecimal" : "2E+310" }, "stdDevPop" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": 1, "sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberDecimal" : "1E+310" }, "stdDevSamp" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberDecimal" : "2E+310" }, "stdDevSamp" : { "$numberDouble" : "NaN" } } (2 rows) -- evaluate data in expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": {"$multiply": ["$x", "$num"]}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevPop" : { "$numberDouble" : "5000000005.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevPop" : { "$numberDouble" : "8164965823.5659503937" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevPop" : { "$numberDouble" : "11180339910.418645859" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": {"$multiply": ["$x", "$num"]}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevSamp" : { "$numberDouble" : "7071067818.936542511" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevSamp" : { "$numberDouble" : "10000000017.5" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevSamp" : { "$numberDouble" : "12909944513.823442459" } } (4 rows) -- array value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": ["$num"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevPop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": ["$num"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevSamp" : null } (4 rows) -- negative cases -- incorrect arguments won't throw error SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevPop" : { "$numberDouble" : "0.0" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": {"a": "$num"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevPop" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevPop" : null } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevSamp" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevSamp" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevSamp" : { "$numberDouble" : "0.0" } } (4 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "x" : { "$numberInt" : "1" }, "num" : { "$numberLong" : "10000000004" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" }, "num" : { "$numberLong" : "10000000007" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "x" : { "$numberInt" : "3" }, "num" : { "$numberLong" : "10000000013" }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "3" }, "x" : { "$numberInt" : "4" }, "num" : { "$numberLong" : "10000000016" }, "stdDevSamp" : null } (4 rows) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 0, "num": 2, "type": "a", "date": { "$date": { "$numberLong": "1718841600000" } } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 1, "num": 3, "type": "a", "date": { "$date": { "$numberLong": "1718841605000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 2, "num": 4, "type": "a", "date": { "$date": { "$numberLong": "1718841610000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 3, "num": 5, "type": "a", "date": { "$date": { "$numberLong": "1718841615000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 4, "num": 6, "type": "a", "date": { "$date": { "$numberLong": "1718841620000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 5, "num": 7, "type": "a", "date": { "$date": { "$numberLong": "1718841630000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 6, "num": 8, "type": "b", "date": { "$date": { "$numberLong": "1718841640000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 7, "num": 9, "type": "b", "date": { "$date": { "$numberLong": "1718841680000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 8, "num": 10, "type": "b", "date": { "$date": { "$numberLong": "1718841700000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 9, "num": 11, "type": "b", "date": { "$date": { "$numberLong": "1718841800000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 10, "num": 12, "type": "b", "date": { "$date": { "$numberLong": "1718841900000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 11, "num": 13, "type": "b", "date": { "$date": { "$numberLong": "1718842600000" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- without window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } (12 rows) -- document window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : null } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } (12 rows) -- range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"range": [-2, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"range": [-2, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.5811388300841897614" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : null } (12 rows) -- unsharded collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : null } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.5811388300841897614" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.5811388300841897614" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.6329931618554520689" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "2.2360679774997898051" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "2.8284271247461902909" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "3.4156502553198659911" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.6329931618554520689" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "2.2360679774997898051" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "2.8284271247461902909" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "3.4156502553198659911" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "2.5819888974716111996" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "3.1622776601683795228" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "3.7416573867739413295" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "2.5819888974716111996" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "3.1622776601683795228" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "3.7416573867739413295" } } (12 rows) -- shard collection SELECT documentdb_api.shard_collection('db', 'window_stddev_col', '{ "type": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", -1]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : null } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "0.5" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "0.81649658092772603446" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "1.1180339887498949025" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "1.7078251276599329955" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "1.5811388300841897614" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "0.70710678118654757274" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "1.2909944487358055998" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "1.5811388300841897614" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "1.8708286933869706647" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevPop" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevPop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevPop" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevPop" : { "$numberDouble" : "1.6329931618554520689" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevPop" : { "$numberDouble" : "1.6329931618554520689" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevPop" : { "$numberDouble" : "2.2360679774997898051" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevPop" : { "$numberDouble" : "2.2360679774997898051" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevPop" : { "$numberDouble" : "2.8284271247461902909" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevPop" : { "$numberDouble" : "2.8284271247461902909" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevPop" : { "$numberDouble" : "3.4156502553198659911" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevPop" : { "$numberDouble" : "3.4156502553198659911" } } (12 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "num" : { "$numberInt" : "2" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "1" }, "num" : { "$numberInt" : "3" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "stdDevSamp" : null } { "_id" : { "$numberInt" : "2" }, "num" : { "$numberInt" : "4" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "stdDevSamp" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "3" }, "num" : { "$numberInt" : "5" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "stdDevSamp" : { "$numberDouble" : "1.4142135623730951455" } } { "_id" : { "$numberInt" : "4" }, "num" : { "$numberInt" : "6" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "stdDevSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "num" : { "$numberInt" : "7" }, "type" : "a", "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "stdDevSamp" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "6" }, "num" : { "$numberInt" : "8" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "stdDevSamp" : { "$numberDouble" : "2.5819888974716111996" } } { "_id" : { "$numberInt" : "7" }, "num" : { "$numberInt" : "9" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "stdDevSamp" : { "$numberDouble" : "2.5819888974716111996" } } { "_id" : { "$numberInt" : "8" }, "num" : { "$numberInt" : "10" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "stdDevSamp" : { "$numberDouble" : "3.1622776601683795228" } } { "_id" : { "$numberInt" : "9" }, "num" : { "$numberInt" : "11" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "stdDevSamp" : { "$numberDouble" : "3.1622776601683795228" } } { "_id" : { "$numberInt" : "10" }, "num" : { "$numberInt" : "12" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "stdDevSamp" : { "$numberDouble" : "3.7416573867739413295" } } { "_id" : { "$numberInt" : "11" }, "num" : { "$numberInt" : "13" }, "type" : "b", "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "stdDevSamp" : { "$numberDouble" : "3.7416573867739413295" } } (12 rows) --------------------------------------------------------------------- -- $first accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- No window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$first": {"output": "$date"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841620000" } } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841620000" } } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841620000" } } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841620000" } } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841630000" } } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841630000" } } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841630000" } } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841630000" } } } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$first": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); -- the sortBy inside $first is just treated as output expression document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "515" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "515" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "515" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "515" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "515" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "511" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "511" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "511" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "511" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "512" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "512" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "512" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "512" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } (13 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "503" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$first": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$first": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } } (13 rows) --------------------------------------------------------------------- -- $last accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- No window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$last": {"output": "$date"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841600000" } } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841605000" } } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841605000" } } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841605000" } } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841605000" } } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841700000" } } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841700000" } } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841700000" } } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "firstDate" : { "output" : { "$date" : { "$numberLong" : "1718841700000" } } } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$last": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); -- the sortBy inside $last is just treated as output expression document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "501" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "501" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "501" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "501" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "501" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "502" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "502" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "502" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "502" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "503" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "503" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "503" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "output" : { "$numberInt" : "503" }, "sortBy" : { "cost" : { "$numberInt" : "-1" } } } } (13 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : null } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : { "$numberInt" : "512" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$last": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$last": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } } (13 rows) --------------------------------------------------------------------- -- $firstN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- No window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$firstN": {"input": "$date", "n": 2}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841600000" } }, { "$date" : { "$numberLong" : "1718841615000" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841600000" } }, { "$date" : { "$numberLong" : "1718841615000" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841600000" } }, { "$date" : { "$numberLong" : "1718841615000" } } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841600000" } }, { "$date" : { "$numberLong" : "1718841615000" } } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841600000" } }, { "$date" : { "$numberLong" : "1718841615000" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841620000" } }, { "$date" : { "$numberLong" : "1718841900000" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841620000" } }, { "$date" : { "$numberLong" : "1718841900000" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841620000" } }, { "$date" : { "$numberLong" : "1718841900000" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841620000" } }, { "$date" : { "$numberLong" : "1718841900000" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841630000" } }, { "$date" : { "$numberLong" : "1718841610000" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841630000" } }, { "$date" : { "$numberLong" : "1718841610000" } } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841630000" } }, { "$date" : { "$numberLong" : "1718841610000" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "firstDate" : [ { "$date" : { "$numberLong" : "1718841630000" } }, { "$date" : { "$numberLong" : "1718841610000" } } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$firstN": {"input": "$quantity", "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 4}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 5}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$firstN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$firstN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 2}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } (13 rows) --------------------------------------------------------------------- -- $lastN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- No window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": { "$lastN": {"input": "$quantity", "n": 2}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "lastDate" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "lastDate" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "lastDate" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "lastDate" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "lastDate" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "lastDate" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "lastDate" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "lastDate" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "lastDate" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "lastDate" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "lastDate" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "lastDate" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "lastDate" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$lastN": {"input": "$quantity", "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 4}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 5}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "cheapQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "cheapQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "cheapQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$lastN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "515" }, "cost" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$lastN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 2}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "501" }, "cost" : { "$numberInt" : "10" } }, { "quantity" : { "$numberInt" : "504" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "507" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "510" }, "cost" : { "$numberInt" : "10" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "502" }, "cost" : { "$numberInt" : "8" } }, { "quantity" : { "$numberInt" : "505" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "508" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "511" }, "cost" : { "$numberInt" : "8" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "503" }, "cost" : { "$numberInt" : "4" } }, { "quantity" : { "$numberInt" : "506" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "509" }, "cost" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "quantity" : { "$numberInt" : "512" }, "cost" : { "$numberInt" : "4" } } ] } (13 rows) /* Negative tests for $firstN/$lastN */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": [1]}}}}] }'); -- spec should be document ERROR: specification must be defined as an object, but the provided input was $firstN :[ 1 ] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": "hello"}}}}] }'); -- spec should be document ERROR: specification must be defined as an object, but the provided input was $lastN :"hello" SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "hello"}}}}} ] }'); -- missing n ERROR: $firstN requires an 'n' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": {"n": 2}}}}} ] }'); -- missing input ERROR: $lastN needs to have an 'input' field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": {"input": "$quantity", "n": 2, "third": true}}}}} ] }'); -- extra field ERROR: $lastN encountered an unrecognized argument value: third SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": -2}}}}} ] }'); -- negative n ERROR: The value of 'n' must be strictly greater than 0, but the current value is -2 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": 2.2}}}}} ] }'); -- non-integer n ERROR: Expected 'integer' type for 'n' but found 'double' for value '2.2' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": "a"}}}}} ] }'); -- non-integer n ERROR: Expected 'integer' type for 'n' but found 'string' for value '"a"' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": {"$undefined": true}}}}}} ] }'); -- undefined n ERROR: Expected 'integer' type for 'n' but found 'undefined' for value '{ "$undefined" : true }' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": {"$numberDecimal": "Infinity"}}}}}} ] }'); -- undefined n ERROR: Unable to convert out-of-range value Infinity into a long type /* Test $first, $last, $firstN, $lastN with $group stage as code path is common with $setWindowFields */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$firstN": {"input": "$quantity", "n": 3 }}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : "def", "res" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : "ghi", "res" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" }, { "$numberInt" : "512" } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$lastN": {"input": "$quantity", "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : "def", "res" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : "ghi", "res" : [ { "$numberInt" : "503" }, { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$lastN": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : [ [ { "$numberInt" : "507" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "510" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "501" }, { "$numberInt" : "10" } ] ] } { "_id" : "def", "res" : [ [ { "$numberInt" : "511" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "508" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "502" }, { "$numberInt" : "8" } ] ] } { "_id" : "ghi", "res" : [ [ { "$numberInt" : "503" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "512" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "509" }, { "$numberInt" : "4" } ] ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$first": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : { "input" : [ { "$numberInt" : "515" }, { "$numberInt" : "80" } ], "n" : { "$numberInt" : "3" } } } { "_id" : "def", "res" : { "input" : [ { "$numberInt" : "505" }, { "$numberInt" : "8" } ], "n" : { "$numberInt" : "3" } } } { "_id" : "ghi", "res" : { "input" : [ { "$numberInt" : "506" }, { "$numberInt" : "4" } ], "n" : { "$numberInt" : "3" } } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$first": "$quantity"}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : { "$numberInt" : "515" } } { "_id" : "def", "res" : { "$numberInt" : "505" } } { "_id" : "ghi", "res" : { "$numberInt" : "506" } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$last": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : { "input" : [ { "$numberInt" : "501" }, { "$numberInt" : "10" } ], "n" : { "$numberInt" : "3" } } } { "_id" : "def", "res" : { "input" : [ { "$numberInt" : "502" }, { "$numberInt" : "8" } ], "n" : { "$numberInt" : "3" } } } { "_id" : "ghi", "res" : { "input" : [ { "$numberInt" : "509" }, { "$numberInt" : "4" } ], "n" : { "$numberInt" : "3" } } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$last": "$quantity"}}}] }'); document --------------------------------------------------------------------- { "_id" : "abc", "res" : { "$numberInt" : "501" } } { "_id" : "def", "res" : { "$numberInt" : "502" } } { "_id" : "ghi", "res" : { "$numberInt" : "509" } } (3 rows) --------------------------------------------------------------------- -- $maxN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" }, { "$numberInt" : "504" }, { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- $minN accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "504" }, { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" }, { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" }, { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "505" }, { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" }, { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" }, { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "506" }, { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" }, { "$numberInt" : "512" } ] } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "expensiveQuantity" : [ { "$numberInt" : "501" }, { "$numberInt" : "504" }, { "$numberInt" : "515" } ] } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "expensiveQuantity" : [ { "$numberInt" : "507" } ] } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "expensiveQuantity" : [ { "$numberInt" : "510" } ] } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "expensiveQuantity" : [ { "$numberInt" : "502" }, { "$numberInt" : "505" } ] } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "expensiveQuantity" : [ { "$numberInt" : "508" } ] } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "expensiveQuantity" : [ { "$numberInt" : "511" } ] } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "expensiveQuantity" : [ { "$numberInt" : "503" }, { "$numberInt" : "506" } ] } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "expensiveQuantity" : [ { "$numberInt" : "509" } ] } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "expensiveQuantity" : [ { "$numberInt" : "512" } ] } (13 rows) --------------------------------------------------------------------- -- $min accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$min": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$min": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "503" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "503" } } (13 rows) -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) --------------------------------------------------------------------- -- $max accumulator tests --------------------------------------------------------------------- --------------------------------------------------------------------- -- Document window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$max": "$quantity"}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : null } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) --------------------------------------------------------------------- -- Document window with sort --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$max": "$quantity"}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalQuantity" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalQuantity" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalQuantity" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalQuantity" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalQuantity" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalQuantity" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalQuantity" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalQuantity" : { "$numberInt" : "506" } } (13 rows) --------------------------------------------------------------------- -- Range window --------------------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["unbounded", "current"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "501" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "unbounded"]}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "512" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "13" }, "a" : "abc", "cost" : { "$numberInt" : "80" }, "quantity" : { "$numberInt" : "515" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "totalInGroup" : { "$numberInt" : "515" } } { "_id" : { "$numberInt" : "4" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "504" }, "date" : { "$date" : { "$numberLong" : "1718841615000" } }, "totalInGroup" : { "$numberInt" : "504" } } { "_id" : { "$numberInt" : "7" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "507" }, "date" : { "$date" : { "$numberLong" : "1718841640000" } }, "totalInGroup" : { "$numberInt" : "507" } } { "_id" : { "$numberInt" : "10" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "510" }, "date" : { "$date" : { "$numberLong" : "1718841800000" } }, "totalInGroup" : { "$numberInt" : "510" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "totalInGroup" : { "$numberInt" : "502" } } { "_id" : { "$numberInt" : "5" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "505" }, "date" : { "$date" : { "$numberLong" : "1718841620000" } }, "totalInGroup" : { "$numberInt" : "505" } } { "_id" : { "$numberInt" : "8" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "508" }, "date" : { "$date" : { "$numberLong" : "1718841680000" } }, "totalInGroup" : { "$numberInt" : "508" } } { "_id" : { "$numberInt" : "11" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "511" }, "date" : { "$date" : { "$numberLong" : "1718841900000" } }, "totalInGroup" : { "$numberInt" : "511" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "totalInGroup" : { "$numberInt" : "503" } } { "_id" : { "$numberInt" : "6" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "506" }, "date" : { "$date" : { "$numberLong" : "1718841630000" } }, "totalInGroup" : { "$numberInt" : "506" } } { "_id" : { "$numberInt" : "9" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "509" }, "date" : { "$date" : { "$numberLong" : "1718841700000" } }, "totalInGroup" : { "$numberInt" : "509" } } { "_id" : { "$numberInt" : "12" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "512" }, "date" : { "$date" : { "$numberLong" : "1718842600000" } }, "totalInGroup" : { "$numberInt" : "512" } } (13 rows) -- Tests for $last SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 1, "storeId": 1, "area": "Delhi", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1756720800000" } }, "status": "open" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 2, "storeId": 2, "area": "Mumbai", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1756902000000" } }, "status": "closed" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 3, "storeId": 3, "area": "Kolkata", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1757086200000" } }, "status": "open" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 4, "storeId": 4, "area": "Chennai", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1757235600000" } }, "status": "open" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "lastSetWindowFields", "pipeline":[{"$match":{"company":{"$in":["ABC Cares"]}}}, {"$setWindowFields": {"partitionBy":"$company","sortBy": {"lastUpdated": {"$numberInt" : "1" } }, "output" : { "lastUpdatedDateForStore" : { "$last" : "$lastUpdated", "window" : { "documents" : [ "current", "unbounded" ] } } } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "storeId" : { "$numberInt" : "1" }, "area" : "Delhi", "company" : "ABC Cares", "lastUpdated" : { "$date" : { "$numberLong" : "1756720800000" } }, "status" : "open", "lastUpdatedDateForStore" : { "$date" : { "$numberLong" : "1757235600000" } } } { "_id" : { "$numberInt" : "2" }, "storeId" : { "$numberInt" : "2" }, "area" : "Mumbai", "company" : "ABC Cares", "lastUpdated" : { "$date" : { "$numberLong" : "1756902000000" } }, "status" : "closed", "lastUpdatedDateForStore" : { "$date" : { "$numberLong" : "1757235600000" } } } { "_id" : { "$numberInt" : "3" }, "storeId" : { "$numberInt" : "3" }, "area" : "Kolkata", "company" : "ABC Cares", "lastUpdated" : { "$date" : { "$numberLong" : "1757086200000" } }, "status" : "open", "lastUpdatedDateForStore" : { "$date" : { "$numberLong" : "1757235600000" } } } { "_id" : { "$numberInt" : "4" }, "storeId" : { "$numberInt" : "4" }, "area" : "Chennai", "company" : "ABC Cares", "lastUpdated" : { "$date" : { "$numberLong" : "1757235600000" } }, "status" : "open", "lastUpdatedDateForStore" : { "$date" : { "$numberLong" : "1757235600000" } } } (4 rows) bson_aggregation_pipeline_tests.out000066400000000000000000007101161507310017400371510ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 411000; SET documentdb.next_collection_id TO 4110; SET documentdb.next_collection_index_id TO 4110; SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'aggregation_pipeline') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 4110 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } 4110 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 4110 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- add newField SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } (3 rows) -- do 2 addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] }, "newField2" : "someOtherField" } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$set": { "newField2": "someOtherField" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] }, "newField2" : "someOtherField" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$set": { "newField2": "someOtherField" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (12 rows) -- add $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (12 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField2" : "someOtherField" } { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField2" : "someOtherField" } { "_id" : "3", "newField2" : "someOtherField" } (3 rows) -- add $unset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unset": "_id" }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); document --------------------------------------------------------------------- { "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField2" : "someOtherField" } { "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField2" : "someOtherField" } { "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "newField2" : "someOtherField" } (3 rows) -- add skip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3" } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) OFFSET '1'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (14 rows) -- add limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 2 }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 2 }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (14 rows) -- add skip + limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) LIMIT '1'::bigint) agg_stage_2 OFFSET '1'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Limit Output: (documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Seq Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) (13 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }, { "$limit": 1 }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }, { "$limit": 1 }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) OFFSET '1'::bigint) agg_stage_2 LIMIT '1'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Limit Output: (documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : { "$numberInt" : "1" }, "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (16 rows) -- try match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_4110_411001 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "_id" : "1" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_4110_411001 collection Output: document Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson)) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "1" }'::documentdb_core.bson) (11 rows) -- match + project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3" } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1 } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "_id" : "1" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson)) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "1" }'::documentdb_core.bson) (11 rows) -- match + project + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); document --------------------------------------------------------------------- { "c" : "3" } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" }, "c" : "$_id", "_id" : { "$numberInt" : "0" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE ((documentdb_api_internal.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" }, "c" : "$_id", "_id" : { "$numberInt" : "0" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) OPERATOR(documentdb_api_catalog.#>) '{ "c" : "2" }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#>) '{ "_id" : "1" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint))) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" }, "c" : "$_id", "_id" : { "$numberInt" : "0" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson)) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "1" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_dollar_project(collection.document, '{ "a.b" : { "$numberInt" : "1" }, "c" : "$_id", "_id" : { "$numberInt" : "0" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) OPERATOR(documentdb_api_catalog.@>) '{ "c" : "2" }'::documentdb_core.bson)) (11 rows) -- unwind SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : "x" } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : true } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (5 rows) -- match and then unwind SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$unwind": "$a.b" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (1 row) -- unwind and then match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$match": { "$expr": { "$not": { "$isArray": "$a.b" } } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : "x" } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : true } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (5 rows) -- unwind and addfields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : "x" }, "xyz" : "1" } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } }, "xyz" : "1" } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberDouble" : "2.0" } }, "xyz" : "1" } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : true }, "xyz" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "xyz" : "2" } (5 rows) -- $addFields then addFields is inlined. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "x": 1, "y": 2, "xyz": 3 } }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "xyz" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "xyz" : "2" } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "xyz" : "3" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "x": 1, "y": 2, "xyz": 3 } }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "xyz" : { "$numberInt" : "3" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "xyz" : "$_id" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_add_fields(document, '{ "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" }, "xyz" : { "$numberInt" : "3" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "xyz" : "$_id" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (12 rows) -- $project then addFields can be inlined only on exclusion today SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "1" }, "xyz" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "$numberInt" : "1" }, "xyz" : "2" } { "_id" : "3", "a" : { "$numberInt" : "1" }, "b" : "yes", "c" : true, "xyz" : "3" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "a" : { "$numberInt" : "1" }, "xyz" : "$_id", "boolean" : "$$REMOVE" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "a" : { "$numberInt" : "1" }, "xyz" : "$_id", "boolean" : "$$REMOVE" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (12 rows) -- error scenarios for $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 1 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); ERROR: exclusion cannot be applied to field boolean within the inclusion projection. -- replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceRoot": { "newRoot": "$e" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "f" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } { "f" : { "c" : { "$numberInt" : "3" } } } { } (3 rows) -- count SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$count": "d" }], "cursor": {} }'); document --------------------------------------------------------------------- { "d" : { "$numberInt" : "3" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$count": "d" }, { "$addFields": { "e": "$d" } }], "cursor": {} }'); document --------------------------------------------------------------------- { "d" : { "$numberInt" : "5" }, "e" : { "$numberInt" : "5" } } (1 row) -- replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceWith": "$e" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "f" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } { "f" : { "c" : { "$numberInt" : "3" } } } { } (3 rows) -- sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sort": { "_id": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- sort + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (2 rows) -- match + sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$sort": { "_id": 1 } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (2 rows) -- sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sortByCount": { "$eq": [ { "$mod": [ { "$toInt": "$_id" }, 2 ] }, 0 ] } }, { "$sort": { "_id": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : false, "count" : { "$numberInt" : "2" } } { "_id" : true, "count" : { "$numberInt" : "1" } } (2 rows) -- $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "d" : "2", "e" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "d" : "3", "e" : { "$numberInt" : "2" } } (2 rows) -- $group with keys having dotted path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d.e": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); ERROR: The specified field name d.e is not allowed to include the '.' character. -- $group with first/last SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "d" : "2", "e" : "2" } { "_id" : { "$numberInt" : "1" }, "d" : "1", "e" : "3" } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'd'::text AS c3, documentdb_api_catalog.bsonfirstonsorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'e'::text AS c5, documentdb_api_catalog.bsonlastonsorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6 FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4, agg_stage_0.c5, agg_stage_0.c6) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'd'::text, documentdb_api_catalog.bsonfirstonsorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'e'::text, documentdb_api_catalog.bsonlastonsorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$mod" : [ { "$toInt" : "$_id" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (20 rows) -- $group with first/last sorted (TODO) -- add $sample SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 2 } }, { "$project": { "_id": "1" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1" } { "_id" : "1" } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 2 } }, { "$project": { "_id": "1" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection TABLESAMPLE public.system_rows ('2'::bigint) WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) ORDER BY (random()) LIMIT '2'::bigint) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_1 Output: documentdb_api_internal.bson_dollar_project(agg_stage_1.document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (random()) -> Sort Output: collection.document, (random()) Sort Key: (random()) -> Sample Scan on documentdb_data.documents_4110_411001 collection Output: collection.document, random() Sampling: system_rows ('2'::bigint) (17 rows) -- Sample after pass-through stages EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id": "1" } }, { "$sample": { "size": 2 } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection TABLESAMPLE public.system_rows ('2'::bigint) WHERE (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) ORDER BY (random()) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project(document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), (random()) -> Sort Output: (documentdb_api_internal.bson_dollar_project(document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), (random()) Sort Key: (random()) -> Sample Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "_id" : "1" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), random() Sampling: system_rows ('2'::bigint) (15 rows) -- Sample after sample EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 3 } }, { "$sample": { "size": 2 } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection TABLESAMPLE public.system_rows ('3'::bigint) WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) ORDER BY (random()) LIMIT '3'::bigint) agg_stage_1 ORDER BY (random()) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: agg_stage_1.document, (random()) -> Sort Output: agg_stage_1.document, (random()) Sort Key: (random()) -> Subquery Scan on agg_stage_1 Output: agg_stage_1.document, random() -> Limit Output: collection.document, (random()) -> Sort Output: collection.document, (random()) Sort Key: (random()) -> Sample Scan on documentdb_data.documents_4110_411001 collection Output: collection.document, random() Sampling: system_rows ('3'::bigint) (22 rows) -- Sample after other stage EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$sample": { "size": 2 } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_catalog.bson_dollar_unwind(collection.document, '$a.b'::text) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) agg_stage_1 ORDER BY (random()) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: agg_stage_1.document, (random()) -> Sort Output: agg_stage_1.document, (random()) Sort Key: (random()) -> Subquery Scan on agg_stage_1 Output: agg_stage_1.document, random() -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(collection.document, '$a.b'::text) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (21 rows) -- internalInhibitOptimization SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1", "newField2" : "someOtherField" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] }, "newField2" : "someOtherField" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: WITH internalinhibitoptimization AS MATERIALIZED (SELECT documentdb_api_internal.bson_dollar_add_fields(collection.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM internalinhibitoptimization inhibit_stage_1 Node: host=localhost port=58070 dbname=regression -> CTE Scan on internalinhibitoptimization inhibit_stage_1 Output: documentdb_api_internal.bson_dollar_add_fields(inhibit_stage_1.document, '{ "newField2" : "someOtherField" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) CTE internalinhibitoptimization -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_add_fields(collection.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (15 rows) -- facet SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "a" : [ { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "c" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "a" : [ { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } ], "b" : [ { "c" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "a" : [ { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" }, { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } ], "b" : [ { "d" : { "$numberInt" : "3" } } ], "c" : [ { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : "x" } }, { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } }, { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberDouble" : "2.0" } } }, { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : true } }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }]}'); document --------------------------------------------------------------------- { "results" : [ ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } }]}'); document --------------------------------------------------------------------- { "a" : [ { "results" : [ ], "newField" : "1", "a" : { "y" : [ "p", "q" ] } } ], "b" : [ { "d" : { "$numberInt" : "1" } } ], "c" : [ ] } (1 row) EXPlAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: WITH facet_base_0_0 AS (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) SELECT documentdb_api_catalog.bson_object_agg(document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM facet_base_0_0 facetsub_stage_1) agg_stage_sub_1_1 UNION ALL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'b'::text), '{ "b" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) AS document FROM (SELECT facetsub_stage_2.document FROM facet_base_0_0 facetsub_stage_2) agg_stage_sub_1_0) agg_stage_sub_1_1 UNION ALL SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text) AS document FROM facet_base_0_0 facetsub_stage_3) agg_stage_sub_1_1)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson))) CTE facet_base_0_0 -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: collection.document Recheck Cond: (collection.shard_key_value = '4110'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) -> Append -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson) -> CTE Scan on facet_base_0_0 facetsub_stage_1 Output: facetsub_stage_1.document -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'b'::text), '{ "b" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> CTE Scan on facet_base_0_0 facetsub_stage_2 Output: facetsub_stage_2.document -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text)), 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text) -> CTE Scan on facet_base_0_0 facetsub_stage_3 Output: facetsub_stage_3.document (32 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_object_agg(document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT facetsub_stage_1.document FROM (SELECT agg_stage_1_1.document FROM (SELECT documentdb_api_catalog.bson_object_agg(agg_stage_0.document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1_1.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT facetsub_stage_0.document FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) facetsub_stage_0 WHERE (facetsub_stage_0.document OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery)) agg_stage_sub_1_1_1) agg_stage_0) agg_stage_1_1) facetsub_stage_1 WHERE (facetsub_stage_1.document OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery)) agg_stage_sub_1_1) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson)))), 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson)))), 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) Filter: (documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4110'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "result" : true }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) (22 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: WITH facet_base_2_0 AS (SELECT agg_stage_2_1.document FROM (SELECT documentdb_api_catalog.bson_object_agg(agg_stage_1.document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT facetsub_stage_1.document FROM (SELECT agg_stage_1_1.document FROM (SELECT documentdb_api_catalog.bson_object_agg(agg_stage_0.document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1_1.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT facetsub_stage_0.document FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) facetsub_stage_0 WHERE (facetsub_stage_0.document OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery)) agg_stage_sub_1_1_1) agg_stage_0) agg_stage_1_1) facetsub_stage_1 WHERE (facetsub_stage_1.document OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery)) agg_stage_sub_1_1) agg_stage_1) agg_stage_2_1) SELECT documentdb_api_catalog.bson_object_agg(document) AS document FROM (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM facet_base_2_0 facetsub_stage_1) agg_stage_sub_1_1 UNION ALL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'b'::text), '{ "b" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) AS document FROM (SELECT facetsub_stage_2.document FROM facet_base_2_0 facetsub_stage_2) agg_stage_sub_1_0) agg_stage_sub_1_1 UNION ALL SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text) AS document FROM facet_base_2_0 facetsub_stage_3) agg_stage_sub_1_1)) agg_stage_2 Node: host=localhost port=58070 dbname=regression -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson))) CTE facet_base_2_0 -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson)))), 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson)))), 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) Filter: (documentdb_api_catalog.bson_object_agg((COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson))) OPERATOR(documentdb_api_catalog.#=) '{ "result" : true }'::documentdb_core.bsonquery) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection.document, 'results'::text), '{ "results" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4110'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "result" : true }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4110'::bigint) -> Append -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_add_fields(facetsub_stage_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'a'::text), '{ "a" : [ ] }'::documentdb_core.bson) -> CTE Scan on facet_base_2_0 facetsub_stage_1 Output: facetsub_stage_1.document -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'b'::text), '{ "b" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_core.bson_repath_and_build('d'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> CTE Scan on facet_base_2_0 facetsub_stage_2 Output: facetsub_stage_2.document -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text)), 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(facetsub_stage_3.document, '$a.b'::text) -> CTE Scan on facet_base_2_0 facetsub_stage_3 Output: facetsub_stage_3.document (42 rows) -- facet with parent transform: SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$facet": { "a" : [ { "$unset": "_id" } ], "b" : [ { "$count": "d" } ], "c": [ { "$replaceWith": { "f": "$_id" } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "a" : [ { "int" : { "$numberInt" : "10" }, "a" : { "b" : "x" } }, { "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } }, { "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberDouble" : "2.0" } } }, { "int" : { "$numberInt" : "10" }, "a" : { "b" : true } }, { "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } ], "b" : [ { "d" : { "$numberInt" : "5" } } ], "c" : [ { "f" : "1" }, { "f" : "1" }, { "f" : "1" }, { "f" : "1" }, { "f" : "2" } ] } (1 row) -- facet negative tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ "hello" ] } } ], "cursor": {} }'); ERROR: Pipeline stage for facet a must be a document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { } ] } } ], "cursor": {} }'); ERROR: Pipeline stage must have a single field. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$count": "d", "$unset": "b" } ] } } ], "cursor": {} }'); ERROR: A pipeline stage specification object is required to have one and only one field. -- FIND SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": 2 }'); document --------------------------------------------------------------------- { "_id" : "3" } (1 row) BEGIN; set local documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": 2 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "_id" : { "$gt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "_id" : "1" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) AND documentdb_api_internal.bson_dollar_fullscan(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST OFFSET '1'::bigint LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project_find(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "_id" : { "$gt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Index Scan using _id_ on documentdb_data.documents_4110_411001 collection Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "_id" : { "$gt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson)) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "1" }'::documentdb_core.bson) (13 rows) ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": -2 }'); document --------------------------------------------------------------------- { "_id" : "3" } (1 row) -- count SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline" }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "3" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- count with skip SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": 0 }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "3" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": 1 }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": null }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "3" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -3.14159 }'); ERROR: The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '-3'. SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -9223372036854775808 }'); ERROR: The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '-9223372036854775808'. SELECT document FROM bson_aggregation_count('db', '{ "count": "non_existent_coll" }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline" }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "3" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": null }'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "3" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -3.14159 }'); ERROR: The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '-3'. SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -9223372036854775808 }'); ERROR: The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '-9223372036854775808'. -- handling of skip as an aggregation stage; this is different from skip in a count query SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": 0 }], "cursor": {}}'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": 1 }], "cursor": {}}'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": null }], "cursor": {}}'); ERROR: $skip requires a numeric argument SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": -3.14159 }], "cursor": {}}'); ERROR: Invalid parameter provided to $skip stage: value cannot be expressed as a 64-bit integer $skip: -3.141590 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": -9223372036854775808 }], "cursor": {}}'); ERROR: Invalid argument provided to $skip stage: A non-negative numerical value was expected in $skip, but received -9223372036854775808. EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline" }'); QUERY PLAN --------------------------------------------------------------------- Function Scan on coll_stats_aggregation collection (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Index Scan using _id_ on documents_4110_411001 collection Index Cond: ((shard_key_value = '4110'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "1" }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "1" }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "non_existent_coll" }'); QUERY PLAN --------------------------------------------------------------------- Aggregate -> Function Scan on empty_data_table collection (2 rows) -- distinct SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "aggregation_pipeline", "key": "_id" }'); document --------------------------------------------------------------------- { "values" : [ "1", "2", "3" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "non_existent_coll", "key": "foo" }'); document --------------------------------------------------------------------- { "values" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.distinct_query('db', '{ "distinct": "aggregation_pipeline", "key": "_id" }'); document --------------------------------------------------------------------- { "values" : [ "1", "2", "3" ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.distinct_query('db', '{ "distinct": "non_existent_coll", "key": "foo" }'); document --------------------------------------------------------------------- { "values" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Explain for LIMIT 1 + Point query BEGIN; set local documentdb.enableCursorsOnAggregationQueryRewrite to on; -- with singleBatch we should not see customScan EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": "1" }, "singleBatch": true }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_4110_411001 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "1" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_4110_411001 collection Output: document Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "1" }'::documentdb_core.bson)) (10 rows) -- with _id query and limit 1 we should see custom scan with primary key lookup. EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": "2" }, "limit": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.continuation Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_internal.current_cursor_state(document) AS continuation FROM documentdb_data.documents_4110_411001 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "2" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "2" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) AND documentdb_api_internal.cursor_state(document, '{ }'::documentdb_core.bson)) LIMIT '1'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.current_cursor_state(document)) -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_internal.current_cursor_state(document) -> Bitmap Heap Scan on documentdb_data.documents_4110_411001 collection Output: shard_key_value, object_id, document Recheck Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "2" }'::documentdb_core.bson)) Filter: documentdb_api_internal.cursor_state(collection.document, '{ }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: ((collection.shard_key_value = '4110'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "2" }'::documentdb_core.bson)) (17 rows) ROLLBACK; -- $lookup SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 1, "movie_title" : "Interstellar", "ticket_price" : 15, "tickets_sold" : 120 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings','{ "_id" : 2, "movie_title" : "Inception", "ticket_price" : 13, "tickets_sold" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 3, "movie_title" : "Dune", "ticket_price" : 18, "tickets_sold" : 95 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 4, "movie_title" : ["Interstellar", "Dune", "Inception"], "ticket_price" : 14, "tickets_sold" : 250 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 6, "movie_title" : {"a": "v", "b" : 2, "c" : [5, 6, 7]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 7, "movie_title" : [{"a": { "b" : 2}}, [5, 6, 7], 9, "z"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog',' { "_id" : 11, "title" : "Interstellar", "genre": "Sci-Fi", "available_seats" : 50 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog',' { "_id" : 12, "title" : "Interstellar", "genre": "Sci-Fi", "available_seats" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 13, "title" : "Dune", "genre": "Sci-Fi", "available_seats" : 30 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 14, "title" : "Blade Runner", "genre": "Cyberpunk", "available_seats" : 40 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 15, "title" : "Inception", "genre": "Thriller", "available_seats" : 60 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 16, "title" : null, "genre": "Unknown", "available_seats" : 0 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 17, "title" : {"a": "x", "b" : 1, "c" : [1, 2, 3]}, "genre": "Experimental" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 18, "title" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "genre": "Experimental Array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 19, "title" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "genre": "Experimental Array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } (7 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } }, { "$sample": { "size": 3 } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document FROM documentdb_data.documents_4111_411020 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4111'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_4112_411038 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4112'::bigint)) agg_stage_sub_1_0) agg_stage_sub_1_1) "lookupRight_stage_1" ON (true))) agg_stage_1 ORDER BY (random()) LIMIT '3'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true)), (random()) -> Sort Output: (documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true)), (random()) Sort Key: (random()) -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true), random() -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_4112_411038 collection_0_1 Recheck Cond: (collection_0_1.shard_key_value = '4112'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4112'::bigint) -> Bitmap Heap Scan on documentdb_data.documents_4111_411020 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4111'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4111'::bigint) (27 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_1."funcName", 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM (SELECT documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) AS "funcName" FROM (SELECT lookup_subpipeline_substage_0.lookup_unwind AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind)) agg_stage_sub_1_0) agg_stage_sub_1_1), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "title" : "title" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_4111_411020 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4111'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_4112_411038 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4112'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'title'::text)) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true) -> Bitmap Heap Scan on documentdb_data.documents_4111_411020 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4111'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4111'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_4112_411038 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '4112'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "title" : "title" }'::documentdb_core.bson), 'title'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4112'::bigint) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson))), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Aggregate Output: documentdb_core.bson_repath_and_build('efe'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) (30 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "coll_dne", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [], "as": "c" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "c" : [ ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "c" : [ ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "c" : [ ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "c" : [ ] } { "_id" : { "$numberInt" : "5" }, "c" : [ ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "c" : [ ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "c" : [ ] } (7 rows) BEGIN; set local citus.enable_local_execution to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } (7 rows) ROLLBACK; SELECT documentdb_api.shard_collection('db', 'agg_pipeline_movie_screenings', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } (7 rows) BEGIN; set local citus.enable_local_execution to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } (7 rows) ROLLBACK; SELECT documentdb_api.shard_collection('db', 'agg_pipeline_movie_catalog', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "9" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "coll_dne", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [], "as": "c" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "c" : [ ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "c" : [ ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "c" : [ ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "c" : [ ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "c" : [ ] } { "_id" : { "$numberInt" : "5" }, "c" : [ ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "c" : [ ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "as": "matched_docs", "pipeline": [ { "$documents": [ { "a": 1}, { "a": 2 } ] } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ { "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "as": "matched_docs", "foreignField": "foo", "localField": "_id", "pipeline": [ { "$documents": [ { "a": 1}, { "a": 2 } ] } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "movie_title" : [ "Interstellar", "Dune", "Inception" ], "ticket_price" : { "$numberInt" : "14" }, "tickets_sold" : { "$numberInt" : "250" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "6" }, "movie_title" : { "a" : "v", "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "movie_title" : "Inception", "ticket_price" : { "$numberInt" : "13" }, "tickets_sold" : { "$numberInt" : "100" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "3" }, "movie_title" : "Dune", "ticket_price" : { "$numberInt" : "18" }, "tickets_sold" : { "$numberInt" : "95" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "7" }, "movie_title" : [ { "a" : { "b" : { "$numberInt" : "2" } } }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], { "$numberInt" : "9" }, "z" ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "movie_title" : "Interstellar", "ticket_price" : { "$numberInt" : "15" }, "tickets_sold" : { "$numberInt" : "120" }, "matched_docs" : [ ] } (7 rows) -- $lookup.pipeline Negative tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": { "$count": "efe" }, "as": "c" } } ], "cursor": {} }'); ERROR: The BSON field '$lookup.pipeline' has an incorrect type 'object'; it should be of type 'array'. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ "$count" ], "as": "c" } } ], "cursor": {} }'); ERROR: Pipeline stage for lookup pipeline must be a document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ { } ], "as": "c" } } ], "cursor": {} }'); ERROR: Pipeline stage must have a single field. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ { "$count": "efe", "$match": { "year": 2018 } } ], "as": "c" } } ], "cursor": {} }'); ERROR: A pipeline stage specification object is required to have one and only one field. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); ERROR: The value '{aggregate: 1}' is invalid for the '$addFields'; a collection input is necessary. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$match": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); ERROR: The value '{aggregate: 1}' is invalid for the '$match'; a collection input is necessary. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$project": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); ERROR: The value '{aggregate: 1}' is invalid for the '$project'; a collection input is necessary. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$skip": 1 } ], "cursor": {} }'); ERROR: The value '{aggregate: 1}' is invalid for the '$skip'; a collection input is necessary. -- test sort behavior on sharded/unsharded SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate" : "agg_pipeline_movie_catalog", "pipeline" : [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } }, { "this_predicate_matches_nothing" : true } ] } }, { "$sort" : { "_id" : -1.0 } }, { "$limit" : 1.0 }, { "$project" : { "_id" : 1.0, "b" : { "$round" : "$a" } } } ], "cursor" : { }, "lsid" : { "id" : { "$binary" : { "base64": "VJmzOaS5R46C4aFkQzrFaQ==", "subType" : "04" } } }, "$db" : "test" }'); $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) -> Distributed Subplan X_X -> Limit -> Sort Sort Key: remote_scan."?sort?" DESC NULLS LAST -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberDouble" : "-1.0" } }'::documentdb_core.bson)) DESC NULLS LAST -> Seq Scan on documents_4112_411056 collection Filter: (((document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberDouble" : "9999.0" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@!=) '{ "some_other_field" : { "$numberDouble" : "3.0" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "this_predicate_matches_nothing" : true }'::documentdb_core.bson)) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Function Scan on read_intermediate_result intermediate_result (20 rows) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate" : "aggregation_pipeline", "pipeline" : [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } }, { "this_predicate_matches_nothing" : true } ] } }, { "$sort" : { "_id" : -1.0 } }, { "$limit" : 1.0 }, { "$project" : { "_id" : 1.0, "b" : { "$round" : "$a" } } } ], "cursor" : { }, "lsid" : { "id" : { "$binary" : { "base64": "VJmzOaS5R46C4aFkQzrFaQ==", "subType" : "04" } } }, "$db" : "test" }') $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_3 -> Limit -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(collection.document, '{ "_id" : { "$numberDouble" : "-1.0" } }'::documentdb_core.bson)) DESC NULLS LAST -> Seq Scan on documents_4110_411001 collection Filter: (((document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberDouble" : "9999.0" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@!=) '{ "some_other_field" : { "$numberDouble" : "3.0" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "this_predicate_matches_nothing" : true }'::documentdb_core.bson)) (11 rows) -- unionWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": "aggregation_pipeline" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (12 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$match": { "a": "no" } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } (6 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT collection.document FROM documentdb_data.documents_4110_411001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint) UNION ALL SELECT documentdb_api_internal.bson_dollar_add_fields(collection_0_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4110_411001 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4110'::bigint)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Append -> Seq Scan on documentdb_data.documents_4110_411001 collection Output: collection.document -> Seq Scan on documentdb_data.documents_4110_411001 collection_0_1 Output: documentdb_api_internal.bson_dollar_add_fields(collection_0_1.document, '{ "newField" : "1", "a.y" : [ "p", "q" ] }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) (12 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "agg_pipeline_movie_catalog", "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "_id" : { "$numberInt" : "12" }, "title" : "Interstellar", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "70" } } { "_id" : { "$numberInt" : "14" }, "title" : "Blade Runner", "genre" : "Cyberpunk", "available_seats" : { "$numberInt" : "40" } } { "_id" : { "$numberInt" : "19" }, "title" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "genre" : "Experimental Array" } { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "17" }, "title" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "genre" : "Experimental" } { "_id" : { "$numberInt" : "11" }, "title" : "Interstellar", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "13" }, "title" : "Dune", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "30" } } { "_id" : { "$numberInt" : "15" }, "title" : "Inception", "genre" : "Thriller", "available_seats" : { "$numberInt" : "60" } } { "_id" : { "$numberInt" : "18" }, "title" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "genre" : "Experimental Array" } (12 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": { "nonexist": { "$exists": true } } }, { "$unionWith": { "coll": "agg_pipeline_movie_catalog", "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "title" : "Interstellar", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "70" } } { "_id" : { "$numberInt" : "14" }, "title" : "Blade Runner", "genre" : "Cyberpunk", "available_seats" : { "$numberInt" : "40" } } { "_id" : { "$numberInt" : "19" }, "title" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "genre" : "Experimental Array" } { "_id" : { "$numberInt" : "16" }, "title" : null, "genre" : "Unknown", "available_seats" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "17" }, "title" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "genre" : "Experimental" } { "_id" : { "$numberInt" : "11" }, "title" : "Interstellar", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "13" }, "title" : "Dune", "genre" : "Sci-Fi", "available_seats" : { "$numberInt" : "30" } } { "_id" : { "$numberInt" : "15" }, "title" : "Inception", "genre" : "Thriller", "available_seats" : { "$numberInt" : "60" } } { "_id" : { "$numberInt" : "18" }, "title" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "genre" : "Experimental Array" } (9 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { } } ], "cursor": {} }'); ERROR: A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ ] } } ], "cursor": {} }'); ERROR: A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); ERROR: A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ { "$documents": [ { "a": 1 }, { "a": 2 } ]}] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } { "a" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "2" } } (5 rows) -- $addFields nested usage SELECT documentdb_api.insert_one('db','aggregation_pipeline','{ "_id": 100, "movie": "Nebula Drift", "critics": [7, 8, 9], "audience": [8, 7], "bonusPoints": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline','{ "_id": 200, "movie": "Quantum Heist", "critics": [6, 6, 7], "audience": [7, 6], "bonusPoints": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "bonusPoints": { "$gte": 0 } } }, { "$addFields": { "totalCritics": { "$sum": "$critics" }, "totalAudience": { "$sum": "$audience" } } }, { "$addFields": { "totalScore": { "$add": [ "$totalCritics", "$totalAudience", "$bonusPoints" ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "movie" : "Nebula Drift", "critics" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ], "audience" : [ { "$numberInt" : "8" }, { "$numberInt" : "7" } ], "bonusPoints" : { "$numberInt" : "2" }, "totalCritics" : { "$numberInt" : "24" }, "totalAudience" : { "$numberInt" : "15" }, "totalScore" : { "$numberInt" : "41" } } { "_id" : { "$numberInt" : "200" }, "movie" : "Quantum Heist", "critics" : [ { "$numberInt" : "6" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ], "audience" : [ { "$numberInt" : "7" }, { "$numberInt" : "6" } ], "bonusPoints" : { "$numberInt" : "3" }, "totalCritics" : { "$numberInt" : "19" }, "totalAudience" : { "$numberInt" : "13" }, "totalScore" : { "$numberInt" : "35" } } (2 rows) -- NumberDouble Range+1 and Range-1 Negative test $skip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "-9223372036854776833"} } ], "cursor": {} }'); ERROR: Invalid parameter provided to $skip stage: value cannot be expressed as a 64-bit integer $skip: -9223372036854777856.000000 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "9223372036854775296"} } ], "cursor": {} }'); ERROR: Invalid parameter provided to $skip stage: value cannot be expressed as a 64-bit integer $skip: 9223372036854775808.000000 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "-9223372036854776832"} } ], "cursor": {} }'); ERROR: Invalid argument provided to $skip stage: A non-negative numerical value was expected in $skip, but received -9223372036854775808. -- samplerate /* insert 100 documents */ /* test unshard case */ DO $$ DECLARE i int; BEGIN FOR i IN 1..100 LOOP PERFORM documentdb_api.insert_one('db', 'agg_pipeline_samplerate', FORMAT('{ "_id": %s }',i)::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "100" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_4113_411069 collection Recheck Cond: (shard_key_value = '4113'::bigint) Filter: (random() < '1'::double precision) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4113'::bigint) (11 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_4113_411069 collection Recheck Cond: (shard_key_value = '4113'::bigint) Filter: (random() < '0'::double precision) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4113'::bigint) (11 rows) /* sampleRate will random select document, use greater than 0 to make sure slice of documents is selected */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- { "gtZero" : true } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_2 -> Aggregate -> Bitmap Heap Scan on documents_4113_411069 collection Recheck Cond: (shard_key_value = '4113'::bigint) Filter: (random() < '0.5'::double precision) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4113'::bigint) (12 rows) /* test shard case */ SELECT documentdb_api.shard_collection('db', 'agg_pipeline_samplerate', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "100" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Aggregate -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_4113_411080 collection Filter: (random() < '1'::double precision) (9 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Aggregate -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_4113_411080 collection Filter: (random() < '0'::double precision) (9 rows) /* sampleRate will random select document, use greater than 0 to make sure slice of documents is selected */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- { "gtZero" : true } (1 row) -- negative samplerate SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": -1.23 } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: numeric argument to $sampleRate must be in [0, 1] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": null } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: The operator $sampleRate requires an argument of numeric data type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": NaN } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: numeric argument to $sampleRate must be in [0, 1] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": Infinity } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: numeric argument to $sampleRate must be in [0, 1] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": -Infinity } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: numeric argument to $sampleRate must be in [0, 1] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": "0.65" } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: The operator $sampleRate requires an argument of numeric data type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 10 } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: numeric argument to $sampleRate must be in [0, 1] SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": false } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); ERROR: The operator $sampleRate requires an argument of numeric data type. -- Pipeline directly push to shards if all stages refer to same collection and that is not sharded and is present on the same node as coordinator. SELECT documentdb_api.insert_one('pipelineDB','agg_pipeline_optimizations','{ "_id": 1, "a": "RANDOM_A", "b": {"c": ["SAMPLE1", "SAMPLE2"], "d": [[1,2], [3, 4]]} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('pipelineDB','agg_pipeline_optimizations','{ "_id": 2, "a": "RANDOM_B", "b": {"c": ["SAMPLE3", "SAMPLE4"], "d": [[5,6], [7, 8]]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "RANDOM_A", "b" : { "c" : [ "SAMPLE1", "SAMPLE2" ], "d" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ] } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documentdb_data.documents_4115_411090 collection Output: document Recheck Cond: (collection.shard_key_value = '4115'::bigint) Filter: (collection.document @= '{ "a" : "RANDOM_A" }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4115'::bigint) (6 rows) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "RANDOM_A" } { "_id" : { "$numberInt" : "2" }, "a" : "RANDOM_B" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documentdb_data.documents_4115_411090 collection Output: bson_dollar_project(document, '{ "a" : { "$numberInt" : "1" } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) Recheck Cond: (collection.shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4115'::bigint) (5 rows) EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations" } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Merge on documents_4115_411090 documents_4115 -> Nested Loop Left Join Join Filter: (documents_4115.object_id OPERATOR(documentdb_core.=) documentdb_core.bson_get_value(collection.document, '_id'::text)) -> Bitmap Heap Scan on documents_4115_411090 collection Recheck Cond: (shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4115'::bigint) -> Materialize -> Bitmap Heap Scan on documents_4115_411090 documents_4115 Recheck Cond: (shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4115'::bigint) (17 rows) SELECT documentdb_api.create_collection('pipelineDB', 'agg_pipeline_optimizations_new'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations_new" } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Merge on documents_4116_411092 documents_4116 -> Nested Loop Left Join Join Filter: (documents_4116.object_id OPERATOR(documentdb_core.=) documentdb_core.bson_get_value(collection.document, '_id'::text)) -> Bitmap Heap Scan on documents_4115_411090 collection Recheck Cond: (shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4115'::bigint) -> Materialize -> Bitmap Heap Scan on documents_4116_411092 documents_4116 Recheck Cond: (shard_key_value = '4116'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4116'::bigint) (17 rows) EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations" } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Merge on documents_4115_411090 documents_4115 -> Nested Loop Left Join Join Filter: (documents_4115.object_id OPERATOR(documentdb_core.=) documentdb_core.bson_get_value(collection.document, '_id'::text)) -> Bitmap Heap Scan on documents_4115_411090 collection Recheck Cond: (shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4115'::bigint) -> Materialize -> Bitmap Heap Scan on documents_4115_411090 documents_4115 Recheck Cond: (shard_key_value = '4115'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4115'::bigint) (17 rows) -- Shard the collection now SELECT documentdb_api.shard_collection('pipelineDB', 'agg_pipeline_optimizations', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "RANDOM_A", "b" : { "c" : [ "SAMPLE1", "SAMPLE2" ], "d" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ] } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_4115_411094 collection WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "RANDOM_A" }'::documentdb_core.bsonquery) Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4115_411094 collection Output: document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "RANDOM_A" }'::documentdb_core.bson) (10 rows) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "RANDOM_B" } { "_id" : { "$numberInt" : "1" }, "a" : "RANDOM_A" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4115_411094 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4115_411094 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) (9 rows) -- Test limit on aggregation stages CREATE OR REPLACE FUNCTION check_aggregation_stages_limit(num_stages int) RETURNS boolean AS $fn$ DECLARE pipeline jsonb := '[]'::jsonb; aggregate_spec jsonb; BEGIN -- Create a json array of form [{$match: {}}] with num_stages elements FOR i IN 1..num_stages LOOP pipeline := pipeline || '{"$match": {}}'::jsonb; END LOOP; aggregate_spec := jsonb_build_object('aggregate', 'dummy', 'pipeline', pipeline); PERFORM document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson); RETURN true; END; $fn$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION check_lookup_stages_limit(num_inline_stages int, num_non_inline_stages int) RETURNS boolean AS $fn$ DECLARE pipeline jsonb := '[]'::jsonb; aggregate_spec jsonb; lookup_spec jsonb; BEGIN -- Create a json array of form [{$match: {}}] with num_stages elements FOR i IN 1..num_inline_stages LOOP pipeline := pipeline || '{"$match": { }}'::jsonb; END LOOP; FOR i IN 1..num_non_inline_stages LOOP pipeline := pipeline || '{"$count": "dummy" }'::jsonb; END LOOP; lookup_spec := jsonb_build_object('$lookup', jsonb_build_object('from', 'dummy', 'as', 'dummy', 'localField', 'dummy', 'foreignField', 'dummy', 'pipeline', pipeline)); aggregate_spec := jsonb_build_object('aggregate', 'dummy', 'pipeline', '[]'::jsonb || lookup_spec); PERFORM document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson); RETURN true; END; $fn$ LANGUAGE plpgsql; SELECT check_aggregation_stages_limit(100); check_aggregation_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_aggregation_stages_limit(1000); check_aggregation_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_aggregation_stages_limit(1001); ERROR: The pipeline length cannot exceed a maximum of 1000 stages. CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson)" PL/pgSQL function check_aggregation_stages_limit(integer) line 12 at PERFORM SELECT check_lookup_stages_limit(1, 1); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(1000, 0); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(0, 1000); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(500, 500); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(1000, 1); ERROR: The pipeline length cannot exceed a maximum of 1000 stages. CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson)" PL/pgSQL function check_lookup_stages_limit(integer,integer) line 18 at PERFORM SELECT check_lookup_stages_limit(1, 1000); ERROR: The pipeline length cannot exceed a maximum of 1000 stages. CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson)" PL/pgSQL function check_lookup_stages_limit(integer,integer) line 18 at PERFORM SET documentdb.aggregation_stages_limit = 1005; SELECT check_aggregation_stages_limit(1001); check_aggregation_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(1000, 1); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) SELECT check_lookup_stages_limit(1, 1000); check_lookup_stages_limit --------------------------------------------------------------------- t (1 row) RESET documentdb.aggregation_stages_limit; -- $lookup and $unwind stage combined when null results need to be preserved SELECT documentdb_api.insert_one('db','lookup_directors','{ "_id": 1, "name": "Alex Veridian" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lookup_directors','{ "_id": 2, "name": "Morgan Slate" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 1, "title": "Shadow Horizon", "director": "Alex Veridian" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 2, "title": "Neon Abyss", "director": "Morgan Slate" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 3, "title": "Celestial Rift", "director": "Alex Veridian" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "lookup_movies", "pipeline": [ { "$lookup": { "from": "lookup_directors", "localField": "director", "foreignField": "name", "as": "director_info" } }, { "$unwind": { "path": "$director_info", "preserveNullAndEmptyArrays": true } }, { "$match": { "title": "Celestial Rift" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "title" : "Celestial Rift", "director" : "Alex Veridian", "director_info" : { "_id" : { "$numberInt" : "1" }, "name" : "Alex Veridian" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "lookup_movies", "pipeline": [ { "$lookup": { "from": "lookup_directors", "localField": "director", "foreignField": "name", "as": "director_info" } }, { "$unwind": { "path": "$director_info", "preserveNullAndEmptyArrays": true } }, { "$match": { "title": "Celestial Rift" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'director_info'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "name" : "director" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_4118_411123 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4118'::bigint)) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_4117_411107 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4117'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'name'::text)) "lookupRight_stage_1" ON (true))) agg_stage_1 WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "title" : "Celestial Rift" }'::documentdb_core.bsonquery) Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'director_info'::text) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "name" : "director" }'::documentdb_core.bson), 'name'::text) Filter: (documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'director_info'::text) OPERATOR(documentdb_api_catalog.#=) '{ "title" : "Celestial Rift" }'::documentdb_core.bsonquery) -> Bitmap Heap Scan on documentdb_data.documents_4118_411123 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4118'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4118'::bigint) -> Materialize Output: collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_4117_411107 collection_0_1 Output: collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '4117'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4117'::bigint) (23 rows) bson_aggregation_pipeline_tests_bucket_auto.out000066400000000000000000001673351507310017400415470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 5110000; SET documentdb.next_collection_id TO 51100; SET documentdb.next_collection_index_id TO 51100; /* Insert data */ SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 1, "product" : "apple", "price" : 1, "year": 2021 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 2, "product" : "peach", "price" : 2, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 3, "product" : "melon", "price" : 5, "year": 2021}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 4, "product" : "melon", "price" : 7, "year": 2021}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 5, "product" : "melon", "price" : 20, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 6, "product" : "apple", "price" : 30, "year": 2022 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 7, "product" : "melon", "price" : 60, "year": 2022 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 8, "product" : "peach", "price" : 62, "year": 2022 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 9, "product" : "banana", "price" : 170, "year": 2023 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 10, "product" : "banana", "price" : 300, "year": 2023 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 11, "product" : "peach", "price" : 320, "year": 2023 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 12, "product" : "peach", "price" : 350, "year": 2024 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* positive cases: */ -- $bucketAuto with only required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- $bucketAuto with diferent num of buckets SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 4 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "7" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "7" }, "max" : { "$numberInt" : "60" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "60" }, "max" : { "$numberInt" : "300" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "300" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "3" } } (4 rows) -- $bucketAuto with output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "count": { "$sum": 1 }, "averageAmount": { "$avg": "$price" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "3.75" } } { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "43.0" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "285.0" } } (3 rows) -- $bucketAuto without count in output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "averageAmount": { "$avg": "$price" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "averageAmount" : { "$numberDouble" : "3.75" } } { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "averageAmount" : { "$numberDouble" : "43.0" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "averageAmount" : { "$numberDouble" : "285.0" } } (3 rows) -- $bucketAuto with expression in groupBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 1] }, "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "0" }, "max" : { "$numberInt" : "19" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "19" }, "max" : { "$numberInt" : "169" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "169" }, "max" : { "$numberInt" : "349" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- $bucketAuto with another stage before it SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$match": { "product": "melon" } }, { "$bucketAuto": { "groupBy": "$price", "buckets": 2 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "5" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "60" } }, "count" : { "$numberInt" : "2" } } (2 rows) -- groupBy non-integar field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : "apple", "max" : "melon" }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : "melon", "max" : "peach" }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : "peach", "max" : "peach" }, "count" : { "$numberInt" : "4" } } (3 rows) -- unevenly distributed data SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "7" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "7" }, "max" : { "$numberInt" : "60" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "60" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "320" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "320" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "2" } } (5 rows) -- try granularity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": "R5" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.63000000000000000444" }, "max" : { "$numberDouble" : "10.0" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberDouble" : "10.0" }, "max" : { "$numberDouble" : "63.0" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberDouble" : "63.0" }, "max" : { "$numberDouble" : "400.0" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- $bucketAuto with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$let": { "vars": { "adjustedAmount": { "$multiply": ["$price", 10] } }, "in": "$$adjustedAmount" }}, "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "10" }, "max" : { "$numberInt" : "200" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "200" }, "max" : { "$numberInt" : "1700" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "1700" }, "max" : { "$numberInt" : "3500" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- With let at aggregation level SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "let": { "multiplier": 10 }, "pipeline": [ { "$bucketAuto": { "groupBy": { "$multiply": ["$price", "$$multiplier"] }, "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "10" }, "max" : { "$numberInt" : "200" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "200" }, "max" : { "$numberInt" : "1700" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "1700" }, "max" : { "$numberInt" : "3500" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- less buckets will be returned if the unique values are less than the buckets specified SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 8 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : "apple", "max" : "banana" }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : "banana", "max" : "melon" }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : "melon", "max" : "peach" }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : "peach", "max" : "peach" }, "count" : { "$numberInt" : "4" } } (4 rows) -- Expand bucket: same value should go to the same bucket, even if this makes the buckets uneven SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$year", "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "2021" }, "max" : { "$numberInt" : "2022" } }, "count" : { "$numberInt" : "5" } } { "_id" : { "min" : { "$numberInt" : "2022" }, "max" : { "$numberInt" : "2024" } }, "count" : { "$numberInt" : "6" } } { "_id" : { "min" : { "$numberInt" : "2024" }, "max" : { "$numberInt" : "2024" } }, "count" : { "$numberInt" : "1" } } (3 rows) /* all granularity types */ DO $$ DECLARE i int; BEGIN FOR i IN 0..99 LOOP PERFORM documentdb_api.insert_one('db', 'bucketAutoGranularity', FORMAT('{ "_id": %s, "amount": %s }', i + 1, i)::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection -- POWERSOF2 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "POWERSOF2" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "32.0" } }, "count" : { "$numberInt" : "32" } } { "_id" : { "min" : { "$numberDouble" : "32.0" }, "max" : { "$numberDouble" : "64.0" } }, "count" : { "$numberInt" : "32" } } { "_id" : { "min" : { "$numberDouble" : "64.0" }, "max" : { "$numberDouble" : "128.0" } }, "count" : { "$numberInt" : "36" } } (3 rows) -- 1-2-5 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "1-2-5" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "20.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "20.0" }, "max" : { "$numberDouble" : "50.0" } }, "count" : { "$numberInt" : "30" } } { "_id" : { "min" : { "$numberDouble" : "50.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "50" } } (3 rows) -- R5 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R5" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "25.0" } }, "count" : { "$numberInt" : "25" } } { "_id" : { "min" : { "$numberDouble" : "25.0" }, "max" : { "$numberDouble" : "63.0" } }, "count" : { "$numberInt" : "38" } } { "_id" : { "min" : { "$numberDouble" : "63.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "37" } } (3 rows) -- R10 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R10" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "20.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "20.0" }, "max" : { "$numberDouble" : "40.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "40.0" }, "max" : { "$numberDouble" : "63.0" } }, "count" : { "$numberInt" : "23" } } { "_id" : { "min" : { "$numberDouble" : "63.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "37" } } (4 rows) -- R20 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R20" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "20.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "20.0" }, "max" : { "$numberDouble" : "40.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "40.0" }, "max" : { "$numberDouble" : "63.0" } }, "count" : { "$numberInt" : "23" } } { "_id" : { "min" : { "$numberDouble" : "63.0" }, "max" : { "$numberDouble" : "90.0" } }, "count" : { "$numberInt" : "27" } } { "_id" : { "min" : { "$numberDouble" : "90.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "10" } } (5 rows) -- R40 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R40" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "20.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "20.0" }, "max" : { "$numberDouble" : "40.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "40.0" }, "max" : { "$numberDouble" : "60.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "60.0" }, "max" : { "$numberDouble" : "80.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "80.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "20" } } (5 rows) -- R80 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R80" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "19.300000000000000711" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "19.300000000000000711" }, "max" : { "$numberDouble" : "40.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "40.0" }, "max" : { "$numberDouble" : "59.100000000000001421" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "59.100000000000001421" }, "max" : { "$numberDouble" : "79.400000000000005684" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "79.400000000000005684" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "20" } } (5 rows) -- E6 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E6" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "22.0" } }, "count" : { "$numberInt" : "22" } } { "_id" : { "min" : { "$numberDouble" : "22.0" }, "max" : { "$numberDouble" : "47.0" } }, "count" : { "$numberInt" : "25" } } { "_id" : { "min" : { "$numberDouble" : "47.0" }, "max" : { "$numberDouble" : "68.0" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "68.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "32" } } (4 rows) -- E12 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E12" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "22.0" } }, "count" : { "$numberInt" : "22" } } { "_id" : { "min" : { "$numberDouble" : "22.0" }, "max" : { "$numberDouble" : "47.0" } }, "count" : { "$numberInt" : "25" } } { "_id" : { "min" : { "$numberDouble" : "47.0" }, "max" : { "$numberDouble" : "68.0" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "68.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "32" } } (4 rows) -- E24 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E24" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "20.0" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "20.0" }, "max" : { "$numberDouble" : "43.0" } }, "count" : { "$numberInt" : "23" } } { "_id" : { "min" : { "$numberDouble" : "43.0" }, "max" : { "$numberDouble" : "68.0" } }, "count" : { "$numberInt" : "25" } } { "_id" : { "min" : { "$numberDouble" : "68.0" }, "max" : { "$numberDouble" : "91.0" } }, "count" : { "$numberInt" : "23" } } { "_id" : { "min" : { "$numberDouble" : "91.0" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "9" } } (5 rows) -- E48 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E48" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "19.600000000000001421" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "19.600000000000001421" }, "max" : { "$numberDouble" : "40.199999999999995737" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "40.199999999999995737" }, "max" : { "$numberDouble" : "61.900000000000005684" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "61.900000000000005684" }, "max" : { "$numberDouble" : "82.5" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "82.5" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "17" } } (5 rows) -- E96 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E96" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "19.099999999999997868" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "19.099999999999997868" }, "max" : { "$numberDouble" : "39.200000000000002842" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "39.200000000000002842" }, "max" : { "$numberDouble" : "60.399999999999998579" } }, "count" : { "$numberInt" : "21" } } { "_id" : { "min" : { "$numberDouble" : "60.399999999999998579" }, "max" : { "$numberDouble" : "80.600000000000008527" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "80.600000000000008527" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "19" } } (5 rows) -- E192 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E192" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberDouble" : "0.0" }, "max" : { "$numberDouble" : "19.099999999999997868" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "19.099999999999997868" }, "max" : { "$numberDouble" : "39.200000000000002842" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "39.200000000000002842" }, "max" : { "$numberDouble" : "59.699999999999995737" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "59.699999999999995737" }, "max" : { "$numberDouble" : "79.599999999999994316" } }, "count" : { "$numberInt" : "20" } } { "_id" : { "min" : { "$numberDouble" : "79.599999999999994316" }, "max" : { "$numberDouble" : "100.0" } }, "count" : { "$numberInt" : "20" } } (5 rows) /* groupBy array or document field */ SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 1, "valueArray" : [1, 2, 3], "valueDocument" : { "a": 1, "b": 2 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 2, "valueArray" : [4, 5, 6], "valueDocument" : { "a": 3, "b": 4 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 3, "valueArray" : [9, 8], "valueDocument" : { "a": 5, "b": 6 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 4, "valueArray" : [10, 11, 12], "valueDocument" : { "a": 4, "b": 8 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 5, "valueArray" : [3, 14, 15], "valueDocument" : { "a": 2, "b": 10 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 6, "valueArray" : [6, 17, 18], "valueDocument" : { "a": 11, "b": 12 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAutoGroupBy", "pipeline": [ { "$bucketAuto": { "groupBy": "$valueArray", "buckets": 3, "output": { "Ids" : { "$push": "$_id" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "max" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "Ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" } ] } { "_id" : { "min" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "max" : [ { "$numberInt" : "9" }, { "$numberInt" : "8" } ] }, "Ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "6" } ] } { "_id" : { "min" : [ { "$numberInt" : "9" }, { "$numberInt" : "8" } ], "max" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" } ] }, "Ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAutoGroupBy", "pipeline": [ { "$bucketAuto": { "groupBy": "$valueDocument", "buckets": 3, "output": { "Ids" : { "$push": "$_id" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } }, "max" : { "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "4" } } }, "Ids" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" } ] } { "_id" : { "min" : { "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "4" } }, "max" : { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "6" } } }, "Ids" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } { "_id" : { "min" : { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "6" } }, "max" : { "a" : { "$numberInt" : "11" }, "b" : { "$numberInt" : "12" } } }, "Ids" : [ { "$numberInt" : "3" }, { "$numberInt" : "6" } ] } (3 rows) /* negative cases, validations: */ -- required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "buckets": 3 } } ] }'); ERROR: The $bucketAuto stage must include both 'groupBy' and 'buckets' parameters. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price" } } ] }'); ERROR: The $bucketAuto stage must include both 'groupBy' and 'buckets' parameters. -- groupBy must be a path with prefix $ or expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "price", "buckets": 3 } } ] }'); ERROR: The $bucketAuto 'groupBy' field must be specified using either a $-prefixed path or a valid expression object, but instead received: "price" -- buckets must be a positive integer SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": "abc" } } ] }'); ERROR: The 'buckets' field in $bucketAuto must contain a numeric value, but a different type was detected: string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3.1 } } ] }'); ERROR: The 'buckets' setting in $bucketAuto must fit within a 32-bit integer range, but was given: 3.1, type: double SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": -3 } } ] }'); ERROR: The 'buckets' field in the $bucketAuto operator must have a value greater than zero, but the provided value was: -3 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 0 } } ] }'); ERROR: The 'buckets' field in the $bucketAuto operator must have a value greater than zero, but the provided value was: 0 -- output must be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": 1 } } ] }'); ERROR: The 'output' field in $bucketAuto must be an object, but a different type was provided: int -- unknown argument of $bucketAuto SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "unknown": 1 } } ] }'); ERROR: Unrecognized option to $bucketAuto: unknown -- granularity must be a string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": 1 } } ] }'); ERROR: Expected 'string' for 'granularity' field for $bucketAuto but found 'int' type -- unsupported granularity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": "abc" } } ] }'); ERROR: Rounding granularity not recognized: abc -- when has granularity, groupby value must be a non-negative number SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3, "granularity": "POWERSOF2" } } ] }'); ERROR: $bucketAuto only allows specifying a 'granularity' with numeric boundaries, but encountered a value of type: string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 100] }, "buckets": 3, "granularity": "POWERSOF2" } } ] }'); ERROR: $bucketAuto only allows specifying a 'granularity' with numeric boundaries, but a negative value was provided: -99.000000 /* Explain */ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'count'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id) AS document FROM (SELECT agg_stage_0_3.document, documentdb_api_internal.bson_dollar_bucket_auto(documentdb_api_internal.bson_expression_get(agg_stage_0_3.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "groupBy" : "$price", "buckets" : { "$numberInt" : "3" } }'::documentdb_core.bson) OVER (ORDER BY (documentdb_api_internal.bson_expression_get(agg_stage_0_3.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS bucket_id FROM (SELECT collection.document FROM documentdb_data.documents_51100_5110001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '51100'::bigint)) agg_stage_0_3) agg_stage_0_2) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'count'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) Group Key: (documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Sort Key: (documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Subquery Scan on agg_stage_0_2 Output: documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> WindowAgg Output: collection.document, documentdb_api_internal.bson_dollar_bucket_auto((documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), '{ "groupBy" : "$price", "buckets" : { "$numberInt" : "3" } }'::documentdb_core.bson) OVER (?), (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_51100_5110001 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '51100'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '51100'::bigint) (27 rows) /* running $bucketAuto with intermediate size of more than 100mb */ DO $$ DECLARE i int; BEGIN -- each doc is "%s": 5 MB - ~5.5 MB & there's 60 of them FOR i IN 1..60 LOOP PERFORM documentdb_api.insert_one('db', 'bucketAuto_sizes_test', FORMAT('{ "_id": %s, "groupName": "ABC", "tag": { "%s": [ %s "d" ] } }', i, i, repeat('"' || i || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection /* should fail with intermediate size error */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAuto_sizes_test", "pipeline": [ { "$bucketAuto": { "groupBy": "$_id", "buckets": 2, "output": { "allTags" : { "$push" : "$tag" } } } } ] }'); ERROR: Size 106297374 is larger than maximum size allowed for an intermediate document 104857600 /* sharded collection */ SELECT documentdb_api.shard_collection('db', 'dollarBucketAuto', '{ "price": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) /* positive cases: */ -- $bucketAuto with only required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- $bucketAuto with diferent num of buckets SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 4 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "60" }, "max" : { "$numberInt" : "300" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "7" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "7" }, "max" : { "$numberInt" : "60" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "300" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "3" } } (4 rows) -- $bucketAuto with output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "count": { "$sum": 1 }, "averageAmount": { "$avg": "$price" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "43.0" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "285.0" } } { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "4" }, "averageAmount" : { "$numberDouble" : "3.75" } } (3 rows) -- $bucketAuto without count in output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "averageAmount": { "$avg": "$price" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "170" } }, "averageAmount" : { "$numberDouble" : "43.0" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "350" } }, "averageAmount" : { "$numberDouble" : "285.0" } } { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "20" } }, "averageAmount" : { "$numberDouble" : "3.75" } } (3 rows) -- $bucketAuto with expression in groupBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 1] }, "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "19" }, "max" : { "$numberInt" : "169" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "169" }, "max" : { "$numberInt" : "349" } }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : { "$numberInt" : "0" }, "max" : { "$numberInt" : "19" } }, "count" : { "$numberInt" : "4" } } (3 rows) -- $bucketAuto with another stage before it SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucketAuto": { "groupBy": "$price", "buckets": 2 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "300" }, "max" : { "$numberInt" : "300" } }, "count" : { "$numberInt" : "1" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "300" } }, "count" : { "$numberInt" : "1" } } (2 rows) -- groupBy non-integar field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : "melon", "max" : "peach" }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : "apple", "max" : "melon" }, "count" : { "$numberInt" : "4" } } { "_id" : { "min" : "peach", "max" : "peach" }, "count" : { "$numberInt" : "4" } } (3 rows) -- unevenly distributed data SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "7" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "7" }, "max" : { "$numberInt" : "60" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "320" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "170" }, "max" : { "$numberInt" : "320" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "60" }, "max" : { "$numberInt" : "170" } }, "count" : { "$numberInt" : "2" } } (5 rows) -- test with null values SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 13, "product" : "peach", "price" : null, "year": 2024 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 14, "product" : "peach", "price" : null, "year": 2024 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "min" : { "$numberInt" : "2" }, "max" : { "$numberInt" : "20" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "320" }, "max" : { "$numberInt" : "350" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "min" : { "$numberInt" : "62" }, "max" : { "$numberInt" : "320" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : { "$numberInt" : "20" }, "max" : { "$numberInt" : "62" } }, "count" : { "$numberInt" : "3" } } { "_id" : { "min" : null, "max" : { "$numberInt" : "2" } }, "count" : { "$numberInt" : "3" } } (5 rows) /* Explain */ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 280_1 -> WindowAgg Output: remote_scan.document, documentdb_api_internal.bson_dollar_bucket_auto(documentdb_api_internal.bson_expression_get(remote_scan.bucket_id, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "groupBy" : "$price", "buckets" : { "$numberInt" : "3" } }'::documentdb_core.bson) OVER (?), remote_scan.worker_column_3 -> Sort Output: remote_scan.worker_column_3, remote_scan.document, remote_scan.bucket_id Sort Key: remote_scan.worker_column_3 -> Custom Scan (Citus Adaptive) Output: remote_scan.worker_column_3, remote_scan.document, remote_scan.bucket_id Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, document AS bucket_id, documentdb_api_internal.bson_expression_get(document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS worker_column_3 FROM documentdb_data.documents_51100_5110064 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_51100_5110064 collection Output: document, document, documentdb_api_internal.bson_expression_get(document, '{ "" : "$price" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'count'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT documentdb_api_catalog.bson_dollar_add_fields(agg_stage_0_2.document, agg_stage_0_2.bucket_id) AS document FROM (SELECT intermediate_result.document, intermediate_result.bucket_id FROM read_intermediate_result('280_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, bucket_id documentdb_core.bson)) agg_stage_0_2) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> HashAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(intermediate_result.document, intermediate_result.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'count'::text, documentdb_api_catalog.bsonsum('{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) Group Key: documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(intermediate_result.document, intermediate_result.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_expression_get(documentdb_api_catalog.bson_dollar_add_fields(intermediate_result.document, intermediate_result.bucket_id), '{ "" : "$bucket_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Function Call: read_intermediate_result('280_1'::text, 'binary'::citus_copy_format) (30 rows) bson_aggregation_pipeline_tests_coll_agnostic.out000066400000000000000000000103111507310017400420370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 314000; SET documentdb.next_collection_id TO 3140; SET documentdb.next_collection_index_id TO 3140; -- collection agnostic with no pipeline should work and return 0 rows. SELECT document from bson_aggregation_pipeline('agnosticTests', '{ "aggregate" : 1.0, "pipeline" : [ ], "cursor" : { }, "txnNumber" : 100, "lsid" : { "id" : { "$binary" : { "base64": "AAAAAA==", "subType" : "04" } } }, "$db" : "agnosticTests" }'); document --------------------------------------------------------------------- (0 rows) -- $document tests SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [] } ], "cursor": {}}'); documents_aggregate --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }], "cursor": {} }'); documents_aggregate --------------------------------------------------------------------- { "field1" : { "$numberInt" : "10" } } { "field2" : { "$numberInt" : "20" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": { "$isArray": "field1" } }, { "field2": 20 } ] }], "cursor": {}}'); documents_aggregate --------------------------------------------------------------------- { "field1" : false } { "field2" : { "$numberInt" : "20" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Function Scan on documentdb_api_catalog.bson_lookup_unwind documents Output: documents Function Call: bson_lookup_unwind('{ "$documents" : [ { "field1" : { "$numberInt" : "10" } }, { "field2" : { "$numberInt" : "20" } } ] }'::bson, '$documents'::text) (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }, { "$addFields": { "field2": 30 } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Function Scan on documentdb_api_catalog.bson_lookup_unwind documents Output: bson_dollar_add_fields(documents.documents, '{ "field2" : { "$numberInt" : "30" } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) Function Call: bson_lookup_unwind('{ "$documents" : [ { "field1" : { "$numberInt" : "10" } }, { "field2" : { "$numberInt" : "20" } } ] }'::bson, '$documents'::text) (3 rows) -- error cases SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": null }], "cursor": {} }'); ERROR: An array was expected. SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": "String Value" }], "cursor": {} }'); ERROR: An array was expected. SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": {} }], "cursor": {}}'); ERROR: An array was expected. -- bugfix scenario: SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [{ "$documents": [ { "userId": "User1", "sessionId": "S1", "points": 100 } ] }, { "$group": { "_id": "$sessionId", "firstFivePoints": { "$firstN": { "input": "$points", "n": 5 } } } } ] }'); documents_aggregate --------------------------------------------------------------------- { "_id" : "S1", "firstFivePoints" : [ { "$numberInt" : "100" } ] } (1 row) bson_aggregation_pipeline_tests_facet_group.out000066400000000000000000000332601507310017400415250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 313000; SET documentdb.next_collection_id TO 3130; SET documentdb.next_collection_index_id TO 3130; SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 1, "a": { "b": 1, "c": 1} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 2, "a": { "b": 1, "c": 2} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 3, "a": { "b": 1, "c": 3} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 4, "a": { "b": 2, "c": 1} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 5, "a": { "b": 2, "c": 2} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 6, "a": { "b": 2, "c": 3} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 7, "a": { "b": 3, "c": 1} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 8, "a": { "b": 3, "c": 2} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 9, "a": { "b": 3, "c": 3} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet2" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); document --------------------------------------------------------------------- { "facet1" : [ { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" } } ], "facet2" : [ { "_id" : { "$numberInt" : "2" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet1" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); document --------------------------------------------------------------------- { "facet1" : [ { "_id" : { "$numberInt" : "2" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } (3 rows) SELECT documentdb_api.shard_collection('db', 'agg_facet_group', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet2" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); document --------------------------------------------------------------------- { "facet1" : [ { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" } } ], "facet2" : [ { "_id" : { "$numberInt" : "2" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet1" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); document --------------------------------------------------------------------- { "facet1" : [ { "_id" : { "$numberInt" : "2" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "1" }, "last" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "1" }, "first" : { "$numberInt" : "3" }, "last" : { "$numberInt" : "1" } } (3 rows) bson_aggregation_pipeline_tests_geonear.out000066400000000000000000007164451507310017400406640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 498000; SET documentdb.next_collection_id TO 49800; SET documentdb.next_collection_index_id TO 49800; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 1, "a": { "b": [ 0, 0]} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 2, "a": { "b": [ 1.1, 1.1]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 3, "a": { "b": [ 2.29, 2.29]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 4, "a": { "b": [ 3.31, 3.31]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 5, "a": { "b": [ 4.42, 4.42]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 6, "a": { "b": [ 5.5, 5.5]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 7, "a": { "b": [ 6.66, 6.66]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 8, "a": { "b": [ 7.74, 7.74]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 9, "a": { "b": [ 8.81, 8.81]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 10, "a": { "geo": {"type": "Point", "coordinates": [35.3, 35.4]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 11, "a": { "geo": {"type": "LineString", "coordinates": [[35.36, 35.42], [32.3, 30]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 12, "a": { "geo": {"type": "Polygon", "coordinates": [[[35.73, 35.74], [38.6, 35.3], [38.7, 39.2], [35.73, 35.74]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 13, "a": { "geo": {"type": "MultiPoint", "coordinates": [[35.43, 35.44], [32.3, 30]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 14, "a": { "geo": {"type": "MultiLineString", "coordinates": [[[35.83, 35.84], [32.3, 30]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 15, "a": { "geo": {"type": "MultiPolygon", "coordinates": [[[[35.312, 35.441], [38.644, 35.3231], [38.71, 39.32], [35.312, 35.441]]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Validations (more validations to follow) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$match": { "query": { } } }, { "$geoNear": { "near": [5, 6], "key": "a.b", "distanceField": "dist.calculated" } } ]}'); ERROR: $geoNear stage must be present before any other stage in the pipeline SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated" } } ]}'); ERROR: The $geoNear operator needs either a 2d or 2dsphere index, but no such index exists SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { } } ]}'); ERROR: $geoNear needs a 'distanceField' option specified as a String value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": "value" } ]}'); ERROR: Invalid parameter: an object was expected for $geoNear. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": true, "distanceField": "dist.calculated", "key": "a" } } ]}'); ERROR: Expected 'document' or 'array' type for $geoNear 'near' field but found 'bool' type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "$text": { "$search": "cat" } } } } ]}'); ERROR: Using text and geoNear together in a single query is not permitted SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "$or": [{"$text": { "$search": "cat" }}, {"b": 2}] } } } ]}'); ERROR: Using text and geoNear together in a single query is not permitted SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "a": {"$near": [1, 1]}} } } ]}'); ERROR: Excessive number of geoNear query expressions SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "a": {"$nearSphere": {"coordinates": [1, 1]}}} } } ]}'); ERROR: Excessive number of geoNear query expressions SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": -1} } ]}'); ERROR: minDistance value must be zero or greater SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "-Infinity"}} } ]}'); ERROR: minDistance value must be zero or greater SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "NaN"}} } ]}'); ERROR: minDistance must be positive or zero SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "-NaN"}} } ]}'); ERROR: minDistance must be positive or zero SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "-Infinity"}} } ]}'); ERROR: maxDistance value must be zero or greater SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "NaN"}} } ]}'); ERROR: maxDistance must be positive or zero SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "-NaN"}} } ]}'); ERROR: maxDistance must be positive or zero SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a"} }, { "$match": { "a": { "$near": {"coordinates": [1,1]}}}} ]}'); ERROR: Too many geoNear expressions -- Tests for verifying strict index usage SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } }] }'); ERROR: unable to find index for $geoNear query SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b" } }] }'); ERROR: unable to find index for $geoNear query -- Test whether we can push $geonear to runtime based on the GUC SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear", "indexes": [{"key": {"a.b": 1}, "name": "ab_idx" }, {"key": {"a.geo": 1}, "name": "a_geo_idx" }, {"key": {"a.geo.type": 1}, "name": "a_geo_type_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "calculated" : { "$numberDouble" : "473415.0" } } } (5 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "390888381795.0" } } } (1 row) ROLLBACK; BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint))) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson)) Sort Key: ((documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_49800_498003 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson) Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bson) Filter: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) IS NOT NULL) -> Bitmap Index Scan on ab_idx Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (16 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint))) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson)) Sort Key: ((documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_49800_498003 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson) Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bson) Filter: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) IS NOT NULL) -> Bitmap Index Scan on a_geo_type_idx Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bson) (16 rows) ROLLBACK; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }, {"key": {"a.geo": "2dsphere"}, "name": "my_2ds_ageo_idx" }, {"key": {"a.c": "2d"}, "name": "my_2d_ac_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Also test multiple indexes when geospatial indexes are available BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "calculated" : { "$numberDouble" : "473415.0" } } } (5 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "390888381795.0" } } } (1 row) ROLLBACK; BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint))) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson)) Sort Key: ((documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_49800_498003 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "query" : { "a.b" : { "$gte" : { "$numberInt" : "4" } } } }'::documentdb_core.bson) Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bson) Filter: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) IS NOT NULL) -> Bitmap Index Scan on ab_idx Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (16 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint))) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson)) Sort Key: ((documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_49800_498003 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo", "query" : { "a.geo.type" : "MultiPoint" } }'::documentdb_core.bson) Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bson) Filter: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) IS NOT NULL) -> Bitmap Index Scan on a_geo_type_idx Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.geo.type" : "MultiPoint" }'::documentdb_core.bson) (16 rows) ROLLBACK; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','agg_geonear'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'agg_geonear') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 49800 | 49801 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "ab_idx" } | t 49800 | 49802 | { "v" : { "$numberInt" : "2" }, "key" : { "a.geo" : { "$numberInt" : "1" } }, "name" : "a_geo_idx" } | t 49800 | 49803 | { "v" : { "$numberInt" : "2" }, "key" : { "a.geo.type" : { "$numberInt" : "1" } }, "name" : "a_geo_type_idx" } | t 49800 | 49804 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : "2d" }, "name" : "my_2d_ab_idx" } | t 49800 | 49805 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : "2dsphere" }, "name" : "my_2ds_ab_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t 49800 | 49806 | { "v" : { "$numberInt" : "2" }, "key" : { "a.geo" : "2dsphere" }, "name" : "my_2ds_ageo_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t 49800 | 49807 | { "v" : { "$numberInt" : "2" }, "key" : { "a.c" : "2d" }, "name" : "my_2d_ac_idx" } | t (7 rows) \d documentdb_data.documents_4980 -- If geo indexes are available on different paths then also geonear should fail SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "not_available" } }] }'); ERROR: unable to find index for $geoNear query BEGIN; -- Find using $geoNear set local citus.enable_local_execution TO OFF; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 6378.1 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7851641.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18726743.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19781171.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35330111.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35946104.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51094295.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52412129.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69654220.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86877567.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488256.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856384.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778059.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780975615.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 0.001 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780976.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488256.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856384.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778059.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780975615.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "877873731.0" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "2329546050.0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } }, "dist" : { "calculated" : { "$numberDouble" : "5216633547.0" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "5663819707.0" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "6260588933.0" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "10560172762.0" } } } (6 rows) --min/max distance test SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 500 kms document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } (5 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "155563.0" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } (7 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0, 2], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "155563.0" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } (7 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "maxDistance": 0.2, "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "maxDistance": 0.2, "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ageo_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) (10 rows) -- min / maxDistance Explains EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); -- Upto 500 kms QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) (11 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } ]}'); -- Upto 2 cartesian distance QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) (11 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } ]}'); -- Upto 0.1 radians QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49800_498003 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '49800'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498003 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) (11 rows) ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'agg_geonear', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; -- Find using $geoNear set local citus.enable_local_execution TO OFF; SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 6378.1 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7851641.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18726743.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19781171.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35330111.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35946104.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51094295.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52412129.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69654220.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86877567.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "70711.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "168309.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "178639.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "317682.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "324580.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "459437.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "473415.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "626259.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "781025.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488256.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856384.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778059.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780975615.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 0.001 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780976.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "51037488256.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "52353856384.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "69576778059.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "86780975615.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "877873731.0" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "2329546050.0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } }, "dist" : { "calculated" : { "$numberDouble" : "5216633547.0" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "5663819707.0" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "6260588933.0" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } }, "dist" : { "calculated" : { "$numberDouble" : "10560172762.0" } } } (6 rows) --min/max distance test SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 500 kms document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "7842911090.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "18705922360.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "19759178280.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "35290831015.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "35906139203.0" } } } (5 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "155563.0" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } (7 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0, 2], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "155563.0" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } (7 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "maxDistance": 0.2, "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "maxDistance": 0.2, "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] }, "dist" : { "location" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ], "calculated" : { "$numberDouble" : "1231.0" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] }, "dist" : { "location" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ], "calculated" : { "$numberDouble" : "2936.0" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] }, "dist" : { "location" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ], "calculated" : { "$numberDouble" : "3101.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] }, "dist" : { "location" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ], "calculated" : { "$numberDouble" : "5539.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] }, "dist" : { "location" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ], "calculated" : { "$numberDouble" : "5636.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] }, "dist" : { "location" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ], "calculated" : { "$numberDouble" : "8011.0" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] }, "dist" : { "location" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ], "calculated" : { "$numberDouble" : "8218.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] }, "dist" : { "location" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ], "calculated" : { "$numberDouble" : "10921.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "13621.0" } } } (9 rows) -- As of version 1.16 ORDER BY clauses are not pushed to shards it can pick either 2d or 2dsphere index for use in shards and sorts the data in coordinator. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "spherical" : true, "key" : "a.b", "includeLocs" : "dist.location" }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } ]}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ageo_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] }, "distanceField" : "dist.calculated", "key" : "a.geo" }'::documentdb_core.bson) (12 rows) -- min / maxDistance Explains EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); -- Upto 500 kms QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "500000" } } }'::documentdb_core.bson) (13 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } ]}'); -- Upto 2 cartesian distance QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a.b", "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberInt" : "2" } } }'::documentdb_core.bson) (13 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } ]}'); -- Upto 0.1 radians QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_49800_498016 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "near" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "distanceField" : "dist.calculated", "key" : "a.b", "spherical" : true, "includeLocs" : "dist.location", "minDistance" : { "$numberInt" : "0" }, "maxDistance" : { "$numberDouble" : "0.10000000000000000555" } } }'::documentdb_core.bson) (13 rows) ROLLBACK; -- Legacy geonear spherical queries are pushed to 2dsphere index if that is the only index available SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear_legacy", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'agg_geonear_legacy') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 49801 | 49815 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 49801 | 49816 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t (2 rows) SELECT documentdb_api.insert_one('db','agg_geonear_legacy','{ "_id": 1, "a": [1, 1] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": true } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ], "dist" : { "calculated" : { "$numberDouble" : "2468.0" } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": true } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49801_498024 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '49801'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((documentdb_api_catalog.bson_validate_geography(document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson)) Sort Key: ((documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_49801_498024 collection Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist.calculated", "key" : "a", "spherical" : true }'::documentdb_core.bson) Recheck Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) IS NOT NULL) -> Bitmap Index Scan on my_2ds_a_idx (14 rows) -- Same non spherical query doesn't work though SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": false } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); ERROR: unable to find index for $geoNear query -- Tests with other stages. $lookup SELECT documentdb_api.insert_one('db','geonear_lookup_1','{ "_id": 1, "a": [10, 10], "x": 5 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geonear_lookup_1", "indexes": [{"key": {"a": "2dsphere"}, "name": "lookup1_2ds_a_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db','geonear_lookup_2','{ "_id": 5, "foo": "bar", "a": [5, 5], "x": 5 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "geonear_lookup_1", "pipeline": [ { "$geoNear": {"near": {"type": "Point", "coordinates": [0, 1]}, "distanceField": "dist.calculated", "spherical": true, "key": "a"}}, {"$lookup": {"from": "geonear_lookup_2", "localField": "x", "foreignField": "x", "as": "new"}}, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ] } '); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "x" : { "$numberInt" : "5" }, "dist" : { "calculated" : { "$numberDouble" : "149129740323.0" } }, "new" : [ { "_id" : { "$numberInt" : "5" }, "foo" : "bar", "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], "x" : { "$numberInt" : "5" } } ] } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "geonear_lookup_1", "pipeline": [ { "$geoNear": {"near": {"type": "Point", "coordinates": [0, 1]}, "distanceField": "dist.calculated", "spherical": true, "key": "a"}}, {"$lookup": {"from": "geonear_lookup_2", "localField": "x", "foreignField": "x", "as": "new"}}, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ] } '); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT agg_stage_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(agg_stage_1.document, '{ "x" : "x" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_catalog.bson_dollar_project_geonear(collection.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49802_498044 collection WHERE ((documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) IS NOT NULL) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '49802'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson)) agg_stage_1) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'new'::text), '{ "new" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_49803_498056 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '49803'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'x'::text)) "lookupRight_stage_1" ON (true))) agg_stage_2 Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_internal.bson_dollar_merge_documents((documentdb_api_catalog.bson_dollar_project_geonear(collection.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson)), (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'new'::text), '{ "new" : [ ] }'::documentdb_core.bson)), true), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Index Scan using lookup1_2ds_a_idx on documentdb_data.documents_49802_498044 collection Output: documentdb_api_catalog.bson_dollar_project_geonear(collection.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'new'::text), '{ "new" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_49803_498056 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '49803'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression((documentdb_api_catalog.bson_dollar_project_geonear(collection.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }, "distanceField" : "dist.calculated", "spherical" : true, "key" : "a" }'::documentdb_core.bson)), '{ "x" : "x" }'::documentdb_core.bson), 'x'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '49803'::bigint) (20 rows) -- This fails because no valid index on geonear_lookup_2 for $geoNear SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} } ], "as": "c" } }]}'); ERROR: unable to find index for $geoNear query SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geonear_lookup_2", "indexes": [{"key": {"a": "2dsphere"}, "name": "lookup2_2ds_a_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Now it should pass SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ], "as": "c" } }]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "x" : { "$numberInt" : "5" }, "c" : [ { "_id" : { "$numberInt" : "5" }, "foo" : "bar", "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], "x" : { "$numberInt" : "5" }, "dist" : { "calculated" : { "$numberDouble" : "11119507973.0" } } } ] } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ], "as": "c" } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document FROM documentdb_data.documents_49802_498044 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '49802'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_2.document, 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(collection_0_1.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_49803_498056 collection_0_1 WHERE ((documentdb_api_catalog.bson_validate_geography(collection_0_1.document, 'a'::text) IS NOT NULL) AND (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '49803'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(collection_0_1.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson)) agg_stage_sub_1_2) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(collection_0_1.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson)), true) -> Seq Scan on documentdb_data.documents_49802_498044 collection Output: collection.shard_key_value, collection.object_id, collection.document -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(collection_0_1.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'c'::text), '{ "c" : [ ] }'::documentdb_core.bson) -> Index Scan using lookup2_2ds_a_idx on documentdb_data.documents_49803_498056 collection_0_1 Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(collection_0_1.document, '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geography(collection_0_1.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection_0_1.document, 'a'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "distanceField" : "dist.calculated", "key" : "a" }'::documentdb_core.bson) (16 rows) -- Additional checks with legacy pair array BEGIN; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 16, "a": { "c": [[10, 10], [20, 20], [30, 30], [40, 40]]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 17, "a": { "c": [{"x": 10, "y": 10}, {"x": 20, "y": 20}, {"x": 30, "y": 30}, {"x": 40, "y": 40}]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 18, "a": { "c": [[]]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 19, "a": { "c": [{}]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "a" : { "c" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ] ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "17" }, "a" : { "c" : [ { "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "10" } }, { "x" : { "$numberInt" : "20" }, "y" : { "$numberInt" : "20" } }, { "x" : { "$numberInt" : "30" }, "y" : { "$numberInt" : "30" } }, { "x" : { "$numberInt" : "40" }, "y" : { "$numberInt" : "40" } } ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } (2 rows) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [30, 30], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "a" : { "c" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ] ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "17" }, "a" : { "c" : [ { "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "10" } }, { "x" : { "$numberInt" : "20" }, "y" : { "$numberInt" : "20" } }, { "x" : { "$numberInt" : "30" }, "y" : { "$numberInt" : "30" } }, { "x" : { "$numberInt" : "40" }, "y" : { "$numberInt" : "40" } } ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } (2 rows) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c", "spherical": true } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "a" : { "c" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ] ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "17" }, "a" : { "c" : [ { "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "10" } }, { "x" : { "$numberInt" : "20" }, "y" : { "$numberInt" : "20" } }, { "x" : { "$numberInt" : "30" }, "y" : { "$numberInt" : "30" } }, { "x" : { "$numberInt" : "40" }, "y" : { "$numberInt" : "40" } } ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } (2 rows) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [30, 30], "distanceField": "dist.calculated", "key": "a.c", "spherical": true } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "a" : { "c" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ] ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "17" }, "a" : { "c" : [ { "x" : { "$numberInt" : "10" }, "y" : { "$numberInt" : "10" } }, { "x" : { "$numberInt" : "20" }, "y" : { "$numberInt" : "20" } }, { "x" : { "$numberInt" : "30" }, "y" : { "$numberInt" : "30" } }, { "x" : { "$numberInt" : "40" }, "y" : { "$numberInt" : "40" } } ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } (2 rows) ROLLBACK; BEGIN; set citus.enable_local_execution TO OFF; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 16, "a": { "c": [[10, 10], [20, 20], [30, 30], [40, 40]]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 17, "a": { "c": [{"x": 10, "y": 10}, {"x": 20, "y": 20}, {"x": 30, "y": 30}, {"x": 40, "y": 40}]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 18, "a": { "c": [[]]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 19, "a": { "c": [{}]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN VERBOSE SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); QUERY PLAN --------------------------------------------------------------------- Sort (cost=11041.82..11291.82 rows=100000 width=40) Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=40) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "distanceField" : "dist.calculated", "key" : "a.c" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.c'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "distanceField" : "dist.calculated", "key" : "a.c" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_49800_498016 collection WHERE (documentdb_api_catalog.bson_validate_geometry(document, 'a.c'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ac_idx on documentdb_data.documents_49800_498016 collection (cost=0.12..8.17 rows=2 width=40) Output: documentdb_api_internal.bson_dollar_add_fields(documentdb_api_catalog.bson_dollar_project_geonear(document, '{ "near" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "distanceField" : "dist.calculated", "key" : "a.c" }'::documentdb_core.bson), '{ "dist.calculated" : { "$round" : [ { "$multiply" : [ "$dist.calculated", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (documentdb_api_catalog.bson_validate_geometry(document, 'a.c'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "near" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], "distanceField" : "dist.calculated", "key" : "a.c" }'::documentdb_core.bson) (12 rows) ROLLBACK; SELECT documentdb_api.insert_one('db','boundstest','{ "_id": 1, "geo": [ 0, 0]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "boundstest", "indexes": [{"key": {"geo": "2d"}, "name": "2d_bounds_idx", "max": 1, "min": -1 }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Errors out with point not in interval based on index bounds. -- TODO: add index bound tests for sharded collection once ORDER BY pushdown to shards is supported SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); ERROR: Point lies outside the specified interval range [-1, 1] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [0, 6], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); ERROR: Point lies outside the specified interval range [-1, 1] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [5, 0], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); ERROR: Point lies outside the specified interval range [-1, 1] SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [1, -1], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "dist" : { "location" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "calculated" : { "$numberDouble" : "1.4142135623730951455" } } } (1 row) RESET enable_seqscan; RESET documentdb.forceUseIndexIfAvailable; SELECT documentdb_api.drop_collection('db', 'boundstest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','valid_extract','{ "_id" : 1, "a" : { "b" : { "type" : "Point", "coordinates" : [ 10, 10 ] } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','invalid_extract1','{ "_id" : 2, "a" : { "b" : { "type" : "MultiPoint", "coordinates" : [ [ 10, 10 ], [ 15, 15 ] ] } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- This now fails to because no valid index, and without index this invalid extract will not happen SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "valid_extract", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b"} } ]}'); ERROR: unable to find index for $geoNear query SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "invalid_extract1", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b"} } ]}'); ERROR: unable to find index for $geoNear query SELECT documentdb_api.drop_collection('db', 'valid_extract') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'invalid_extract1') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) bson_aggregation_pipeline_tests_graphlookup.out000066400000000000000000002302761507310017400415700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 912000; SET documentdb.next_collection_id TO 9120; SET documentdb.next_collection_index_id TO 9120; SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 1, "userName" : "Sam" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 2, "userName" : "Alex", "friend" : "Sam" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 3, "userName" : "Jamie", "friend" : "Alex" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 4, "userName" : "Taylor", "friend" : "Alex" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 5, "userName" : "Morgan", "friend" : "Jamie" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 6, "userName" : "Jordan", "friend" : "Taylor" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "friendChain" : [ ] } { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" } ] } { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] } { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] } { "_id" : { "$numberInt" : "5" }, "userName" : "Morgan", "friend" : "Jamie", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex" } ] } { "_id" : { "$numberInt" : "6" }, "userName" : "Jordan", "friend" : "Taylor", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex" } ] } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'friendChain'::text), '{ "friendChain" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_9120_912000 collection_0_2 WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9120'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", 'userName'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_9120_912000 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9120'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "userName" : { "$makeArray" : "$friend" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") "graphLookup_stage_2".document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "friendChain" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "userName" : { "$makeArray" : "$friend" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "inputExpr" FROM documentdb_data.documents_9120_912000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '9120'::bigint)) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9120_912000 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "friendChain" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.shard_key_value = '9120'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '9120'::bigint) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg("graphLookup_stage_2".document, 'friendChain'::text), '{ "friendChain" : [ ] }'::documentdb_core.bson) -> Unique Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_9120_912000 collection_0_2 Output: collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.shard_key_value = '9120'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "userName" : { "$makeArray" : "$friend" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2.shard_key_value = '9120'::bigint) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "userName" : { "$makeArray" : "$friend" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: (NOT "lookupRecursive_stage_1".is_cycle) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_9120_912000 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.shard_key_value = '9120'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2_1.shard_key_value = '9120'::bigint) -> Sort Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 0, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 1, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 2, "placeCode" : "P3", "nearby" : [ "P1" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 3, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 4, "placeCode" : "P5", "nearby" : [ "P4" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 1, "userName" : "Sam", "homePlace" : "P1" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 2, "userName" : "Alex", "homePlace" : "P1" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 3, "userName" : "Jamie", "homePlace" : "P2" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] } ] } { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] } ] } { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "homePlace" : "P2", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] }, { "_id" : { "$numberInt" : "4" }, "placeCode" : "P5", "nearby" : [ "P4" ] } ] } (3 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'reachablePlaces'::text), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_9121_912019 collection_0_2 WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9121'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", 'placeCode'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_9121_912019 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9121'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "placeCode" : { "$makeArray" : "$nearby" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text) AND ("lookupRecursive_stage_1".depth OPERATOR(documentdb_api_catalog.#<) '{ "depth" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") "graphLookup_stage_2".document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "placeCode" : { "$makeArray" : "$homePlace" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "inputExpr" FROM documentdb_data.documents_9122_912038 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '9122'::bigint)) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9122_912038 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.shard_key_value = '9122'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '9122'::bigint) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg("graphLookup_stage_2".document, 'reachablePlaces'::text), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) -> Unique Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_9121_912019 collection_0_2 Output: collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.shard_key_value = '9121'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "placeCode" : { "$makeArray" : "$homePlace" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2.shard_key_value = '9121'::bigint) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "placeCode" : { "$makeArray" : "$nearby" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: ((NOT "lookupRecursive_stage_1".is_cycle) AND ("lookupRecursive_stage_1".depth OPERATOR(documentdb_api_catalog.#<) '{ "depth" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery)) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_9121_912019 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.shard_key_value = '9121'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2_1.shard_key_value = '9121'::bigint) -> Sort Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "depthField": "stepsCount" } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ], "stepsCount" : { "$numberInt" : "0" } }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ], "stepsCount" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "4" }, "placeCode" : "P5", "nearby" : [ "P4" ], "stepsCount" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ], "stepsCount" : { "$numberInt" : "0" } }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ], "stepsCount" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "4" }, "placeCode" : "P5", "nearby" : [ "P4" ], "stepsCount" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "homePlace" : "P2", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ], "stepsCount" : { "$numberInt" : "0" } }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ], "stepsCount" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ], "stepsCount" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "4" }, "placeCode" : "P5", "nearby" : [ "P4" ], "stepsCount" : { "$numberInt" : "2" } } ] } (3 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "depthField": "stepsCount" } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'reachablePlaces'::text), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "stepsCount" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_9121_912019 collection_0_2 WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9121'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", 'placeCode'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "stepsCount" : { "$add" : [ "$stepsCount", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_9121_912019 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9121'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "placeCode" : { "$makeArray" : "$nearby" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true) AS document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "placeCode" : { "$makeArray" : "$homePlace" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "inputExpr" FROM documentdb_data.documents_9122_912038 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '9122'::bigint)) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9122_912038 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.shard_key_value = '9122'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '9122'::bigint) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), 'reachablePlaces'::text), '{ "reachablePlaces" : [ ] }'::documentdb_core.bson) -> Unique Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_9121_912019 collection_0_2 Output: collection_0_2.document, '{ "stepsCount" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.shard_key_value = '9121'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "placeCode" : { "$makeArray" : "$homePlace" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2.shard_key_value = '9121'::bigint) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "stepsCount" : { "$add" : [ "$stepsCount", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "placeCode" : { "$makeArray" : "$nearby" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'placeCode'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: (NOT "lookupRecursive_stage_1".is_cycle) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_9121_912019 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.shard_key_value = '9121'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2_1.shard_key_value = '9121'::bigint) -> Sort Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) -- $graphLookup inside $facet SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$facet": { "inner": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ] } } ]}'); document --------------------------------------------------------------------- { "inner" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "friendChain" : [ ] }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" } ] }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "5" }, "userName" : "Morgan", "friend" : "Jamie", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex" } ] }, { "_id" : { "$numberInt" : "6" }, "userName" : "Jordan", "friend" : "Taylor", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex" } ] } ] } (1 row) -- $graphLookup inside $lookup SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$lookup": { "from": "graphlookup_socialgroup", "as": "inner", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ] } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "homePlace" : "P1", "inner" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "friendChain" : [ ] }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" } ] }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "5" }, "userName" : "Morgan", "friend" : "Jamie", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex" } ] }, { "_id" : { "$numberInt" : "6" }, "userName" : "Jordan", "friend" : "Taylor", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex" } ] } ] } { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "homePlace" : "P1", "inner" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "friendChain" : [ ] }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" } ] }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "5" }, "userName" : "Morgan", "friend" : "Jamie", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex" } ] }, { "_id" : { "$numberInt" : "6" }, "userName" : "Jordan", "friend" : "Taylor", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex" } ] } ] } { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "homePlace" : "P2", "inner" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "friendChain" : [ ] }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" } ] }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" } ] }, { "_id" : { "$numberInt" : "5" }, "userName" : "Morgan", "friend" : "Jamie", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "friend" : "Alex" } ] }, { "_id" : { "$numberInt" : "6" }, "userName" : "Jordan", "friend" : "Taylor", "friendChain" : [ { "_id" : { "$numberInt" : "1" }, "userName" : "Sam" }, { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "friend" : "Sam" }, { "_id" : { "$numberInt" : "4" }, "userName" : "Taylor", "friend" : "Alex" } ] } ] } (3 rows) -- source can be sharded SELECT documentdb_api.shard_collection('db', 'graphlookup_visitors', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "userName" : "Alex", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] } ] } { "_id" : { "$numberInt" : "3" }, "userName" : "Jamie", "homePlace" : "P2", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] }, { "_id" : { "$numberInt" : "4" }, "placeCode" : "P5", "nearby" : [ "P4" ] } ] } { "_id" : { "$numberInt" : "1" }, "userName" : "Sam", "homePlace" : "P1", "reachablePlaces" : [ { "_id" : { "$numberInt" : "0" }, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }, { "_id" : { "$numberInt" : "1" }, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }, { "_id" : { "$numberInt" : "2" }, "placeCode" : "P3", "nearby" : [ "P1" ] }, { "_id" : { "$numberInt" : "3" }, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] } ] } (3 rows) -- target cannot be sharded SELECT documentdb_api.shard_collection('db', 'graphlookup_places', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db', 'graphlookup_socialgroup', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); ERROR: $graphLookup using 'from' on a sharded collection is currently unsupported SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); ERROR: $graphLookup using 'from' on a sharded collection is currently unsupported -- Construct random numeric relationship between 1000 users and 5 interests DO $$ DECLARE i int; BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('db', 'graphlookup_members', FORMAT('{ "_id": %s, "userName": %s, "links": [ %s, %s, %s ], "interests": [ %s, %s, %s ] }', i, i, FLOOR(RANDOM() * 10) + 1 , FLOOR(RANDOM() * 10) + 1, FLOOR(RANDOM() * 10) + 1, FLOOR(RANDOM() * 5) + 1, FLOOR(RANDOM() * 5) + 1, FLOOR(RANDOM() * 5) + 1 )::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection -- $graphlookup with restrictSearchWithMatch SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "graphlookup_members", "indexes": [{"key": {"userName": 1, "interests": 1}, "name": "userName_1_interests_1" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d+ documentdb_data.documents_9123; Table "documentdb_data.documents_9123" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------------------------------------------------------------------- shard_key_value | bigint | | not null | | plain | | object_id | bson | | not null | | extended | | document | bson | | not null | | extended | | Indexes: "collection_pk_9123" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9127" documentdb_rum (document bson_rum_single_path_ops (path='userName', tl='2691'), document bson_rum_single_path_ops (path=interests, tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '9123'::bigint) ANALYZE documentdb_data.documents_9123; BEGIN; SET enable_seqscan TO off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_members", "pipeline": [ { "$match": { "userName": { "$lte": 50 } } }, { "$graphLookup": { "from": "graphlookup_members", "startWith": "$links", "connectFromField": "links", "connectToField": "userName", "as": "interestFriends", "restrictSearchWithMatch": { "interests" : { "$lte": 3 } } } }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'interestFriends'::text), '{ "interestFriends" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_9123_912079 collection_0_2 WHERE ((collection_0_2.document OPERATOR(documentdb_api_catalog.#<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9123'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", 'userName'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_9123_912079 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.document OPERATOR(documentdb_api_catalog.#<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '9123'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "userName" : { "$makeArray" : "$links" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") "graphLookup_stage_2".document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "interestFriends" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "userName" : { "$makeArray" : "$links" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "inputExpr" FROM documentdb_data.documents_9123_912079 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#<=) '{ "userName" : { "$numberInt" : "50" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '9123'::bigint))) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9123_912079 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "interestFriends" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "userName" : { "$numberInt" : "50" } }'::documentdb_core.bson) -> Bitmap Index Scan on "userName_1_interests_1" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "userName" : { "$numberInt" : "50" } }'::documentdb_core.bson) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg("graphLookup_stage_2".document, 'interestFriends'::text), '{ "interestFriends" : [ ] }'::documentdb_core.bson) -> Unique Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_9123_912079 collection_0_2 Output: collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.document OPERATOR(documentdb_api_catalog.@<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "userName" : { "$makeArray" : "$links" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text) -> Bitmap Index Scan on "userName_1_interests_1" Index Cond: ((collection_0_2.document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_expression_get(collection.document, '{ "userName" : { "$makeArray" : "$links" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AND (collection_0_2.document OPERATOR(documentdb_api_catalog.@<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "userName" : { "$makeArray" : "$links" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), 'userName'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: (NOT "lookupRecursive_stage_1".is_cycle) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_9123_912079 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.document OPERATOR(documentdb_api_catalog.@<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on "userName_1_interests_1" Index Cond: (collection_0_2_1.document OPERATOR(documentdb_api_catalog.@<=) '{ "interests" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Sort Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: "graphLookup_stage_2".document, "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) ROLLBACK; bson_aggregation_pipeline_tests_index_pushdown.out000066400000000000000000000153231507310017400422650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 416000; SET documentdb.next_collection_id TO 4160; SET documentdb.next_collection_index_id TO 4160; -- create entries with accid == 1, 2, val == 3, 4 with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 1), ((s % 2) + 3), repeat(md5(random()::text), 50))::json as textVal from generate_series(1, 25000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""25000"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 1, "val": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) DO $$ DECLARE v_output record; BEGIN FOR i IN 1..5 LOOP with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 1), ((s % 2) + 3), repeat(md5(random()::text), 50))::json from generate_series(1, 15000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) INTO v_output FROM r2; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 1, "val": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create entries with accid == 3, 4, val == 5, 6 SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 2, "val": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) DO $$ DECLARE v_output record; BEGIN FOR i IN 1..5 LOOP with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 3), ((s % 2) + 5), repeat(md5(random()::text), 50))::json from generate_series(1, 15000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) INTO v_output FROM r2; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 2, "val": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "agg_pipeline_index_pushdown", "indexes": [ { "key": { "accid": 1, "val": 1 }, "name": "myIdx1" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_4160; -- First scenario with enable_indexscan to off: This technically loads 25000 rows on the bitmap scan BEGIN; set local documentdb.enableRumIndexScan to off; set local seq_page_cost to 5; set local rum.enable_semifast_gettuple to on; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "agg_pipeline_index_pushdown", "filter": { "accid": 1 }, "skip": 100, "limit": 100 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=100 loops=1) Task Count: 1 Tuple data received from nodes: 161 kB Tasks Shown: All -> Task Tuple data received from node: 161 kB Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=100 loops=1) -> Bitmap Heap Scan on documents_4160_416000 collection (actual rows=200 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=100 -> Bitmap Index Scan on "myIdx1" (actual rows=12502 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) (13 rows) ROLLBACK; -- now turn on the flag - we should only load as many rows as the skip/limit BEGIN; set local documentdb.enableRumIndexScan to on; set local seq_page_cost to 5; set local rum.enable_semifast_gettuple to on; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "agg_pipeline_index_pushdown", "filter": { "accid": 1 }, "skip": 100, "limit": 100 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=100 loops=1) Task Count: 1 Tuple data received from nodes: 161 kB Tasks Shown: All -> Task Tuple data received from node: 161 kB Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=100 loops=1) -> Index Scan using "myIdx1" on documents_4160_416000 collection (actual rows=200 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) ROLLBACK; bson_aggregation_pipeline_tests_let.out000066400000000000000000004444741507310017400400300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 413000; SET documentdb.next_collection_id TO 4130; SET documentdb.next_collection_index_id TO 4130; SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'aggregation_pipeline_let') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 4130 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } 4130 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 4130 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- add newField -- with let enabled EXPLAIN (VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": 20 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "newField" : "$$varRef" }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : { "$numberInt" : "20" } } } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4130_413001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4130'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4130_413001 collection (cost=4.18..12.65 rows=4 width=32) Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "newField" : "$$varRef" }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : { "$numberInt" : "20" } } } }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4130'::bigint) -> Bitmap Index Scan on _id_ (cost=0.00..4.18 rows=4 width=0) Index Cond: (collection.shard_key_value = '4130'::bigint) (12 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": 20 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "20" } } { "_id" : "2", "newField" : { "$numberInt" : "20" } } { "_id" : "3", "newField" : { "$numberInt" : "20" } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": { "$avg": [ 20, 40 ] } } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberDouble" : "30.0" } } { "_id" : "2", "newField" : { "$numberDouble" : "30.0" } } { "_id" : "3", "newField" : { "$numberDouble" : "30.0" } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varNotRef" }, "filter": {}, "let": { "varRef": { "$avg": [ 20, 40 ] } } }'); ERROR: Attempting to use an undefined variable: varNotRef -- let support in $expr SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varRef" ]} }, "let": { "varRef": "3" } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : "3" } { "_id" : "2", "newField" : "3" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ]} }, "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } { "_id" : "2", "newField" : { "$numberInt" : "3" } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varNotRef" ]} }, "let": { "varRef": "3" } }'); ERROR: Attempting to use an undefined variable: varNotRef -- let support in $expr with nested $let SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } { "_id" : "2", "newField" : { "$numberInt" : "3" } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } (1 row) -- same scenario but with aggregation pipeline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ "$_id", "$$varRef" ]} } } ], "let": { "varRef": "3" } }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varNotRef" ] } } } ], "let": { "varRef": 3 } }'); ERROR: Attempting to use an undefined variable: varNotRef -- let support in $expr with nested $let SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } { "_id" : "2", "newField" : { "$numberInt" : "3" } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } (1 row) -- same scenario but with aggregation pipeline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } (1 row) -- find/aggregate with variables referencing other variables on the same let spec should work SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]} } }'); document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }}], "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]} } }'); document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } (3 rows) -- nested $let should also work SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" }, "filter": {}, "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]}, "nestedLet": {"$let": {"vars": {"add": {"$add": ["$$multiply", 1]}}, "in": "$$add"}} } }'); document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" }}], "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]}, "nestedLet": {"$let": {"vars": {"add": {"$add": ["$$multiply", 1]}}, "in": "$$add"}} } }'); document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } (3 rows) -- if we change the order and the variable that we're referencing is defined afterwards we should fail SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "add": {"$add": ["$$varRef", 2]}, "varRef": 20, "multiply": {"$multiply": ["$$add", 2]} } }'); ERROR: Attempting to use an undefined variable: varRef SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }}], "let": { "add": {"$add": ["$$varRef", 2]}, "varRef": 20, "multiply": {"$multiply": ["$$add", 2]} } }'); ERROR: Attempting to use an undefined variable: varRef -- $addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : false, "newField" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$set": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : false, "newField" : { "$numberInt" : "3" } } (3 rows) -- pipeline with inlined $project then addFields, on exclusion SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": "$$varRef", "xyz": "$_id" } } ], "let": {"varRef": 1}}'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "1" }, "xyz" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "$numberInt" : "1" }, "xyz" : "2" } { "_id" : "3", "a" : { "$numberInt" : "1" }, "b" : "yes", "c" : true, "xyz" : "3" } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "let": {"varRef": 1}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "a" : { "$numberInt" : "1" }, "xyz" : "$_id", "boolean" : "$$REMOVE" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : { "$numberInt" : "1" } } } }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4130_413001 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '4130'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4130_413001 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "a" : { "$numberInt" : "1" }, "xyz" : "$_id", "boolean" : "$$REMOVE" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE, "let" : { "varRef" : { "$literal" : { "$numberInt" : "1" } } } }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '4130'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4130'::bigint) (12 rows) -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceRoot": { "newRoot": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } (3 rows) -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceWith": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } (3 rows) -- $group (with simple aggregators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" } } (1 row) -- $group (with sorted accumulators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "first": { "$first" : "$a.b" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" }, "first" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "last": { "$last" : "$a.b" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "top": {"$top": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "top" : [ "1" ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "bottom": {"$bottom": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "bottom" : [ "3" ] } (1 row) -- $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "_id": 1, "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "2", "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "3", "c" : false, "newField" : { "$numberInt" : "3" } } (3 rows) -- $unionWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": { "c": "foo" }}, { "$unionWith": { "coll": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "bar": "$$varRef" } } ] } } ], "let": { "varRef": 30 }}'); document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "c" : "foo" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "c" : "foo" } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : "foo" } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "bar" : { "$numberInt" : "30" } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "bar" : { "$numberInt" : "30" } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "bar" : { "$numberInt" : "30" } } (6 rows) -- $sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$sortByCount": { "$lt": [ "$_id", "$$varRef" ] } } ], "let": { "varRef": "2" } }'); document --------------------------------------------------------------------- { "_id" : false, "count" : { "$numberInt" : "2" } } { "_id" : true, "count" : { "$numberInt" : "1" } } (2 rows) -- $facet SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField": "myvalue" }}, { "$facet": { "sb1": [ { "$addFields": { "myVar": "$$varRef" }} ], "sb2": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ] }} ], "let": { "varRef": "2" } }'); document --------------------------------------------------------------------- { "sb1" : [ { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField" : "myvalue", "myVar" : "2" }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField" : "myvalue", "myVar" : "2" }, { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "newField" : "myvalue", "myVar" : "2" } ], "sb2" : [ { "_id" : "2", "c" : { "$numberInt" : "0" } } ] } (1 row) -- $graphLookup SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 1, "name" : "Dev" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 2, "name" : "Eliot", "reportsTo" : "Dev" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 3, "name" : "Ron", "reportsTo" : "Eliot" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 4, "name" : "Andrew", "reportsTo" : "Eliot" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 5, "name" : "Asya", "reportsTo" : "Ron" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 6, "name" : "Dan", "reportsTo" : "Andrew" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_gl", "pipeline": [ { "$graphLookup": { "from": "aggregation_pipeline_let_gl", "startWith": { "$max": [ "$reportsTo", "$$reportsTo" ] }, "connectFromField": "reportsTo", "connectToField": "name", "as": "reportingHierarchy" } } ], "let": { "reportsTo": "Dev" } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Dev", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" } ] } { "_id" : { "$numberInt" : "2" }, "name" : "Eliot", "reportsTo" : "Dev", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" } ] } { "_id" : { "$numberInt" : "3" }, "name" : "Ron", "reportsTo" : "Eliot", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" }, { "_id" : { "$numberInt" : "2" }, "name" : "Eliot", "reportsTo" : "Dev" } ] } { "_id" : { "$numberInt" : "4" }, "name" : "Andrew", "reportsTo" : "Eliot", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" }, { "_id" : { "$numberInt" : "2" }, "name" : "Eliot", "reportsTo" : "Dev" } ] } { "_id" : { "$numberInt" : "5" }, "name" : "Asya", "reportsTo" : "Ron", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" }, { "_id" : { "$numberInt" : "2" }, "name" : "Eliot", "reportsTo" : "Dev" }, { "_id" : { "$numberInt" : "3" }, "name" : "Ron", "reportsTo" : "Eliot" } ] } { "_id" : { "$numberInt" : "6" }, "name" : "Dan", "reportsTo" : "Andrew", "reportingHierarchy" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Dev" } ] } (6 rows) -- $inverseMatch SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_inv', '{ "_id" : 1, "policy" : { "name": "Dev" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_inv', '{ "_id" : 1, "policy" : { "name": "Elliot" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_inv", "pipeline": [ { "$inverseMatch": { "path": "policy", "from": "aggregation_pipeline_let_gl", "pipeline": [{"$match": {"$expr": { "$eq": [ "$name", "$$varRef"] }} }] } }], "let": { "varRef": "Dev" } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "policy" : { "name" : "Dev" } } (1 row) -- $window operators SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": { "$concat": ["$a", "$$varRef" ] }, "output": {"total": { "$sum": "$$varRefNum"}}}}], "let": { "varRef": "prefix", "varRefNum": 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "2" } } (3 rows) -- $lookup SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom',' {"_id": 1, "name": "American Steak House", "food": ["filet", "sirloin"], "quantity": 100 , "beverages": ["beer", "wine"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom','{ "_id": 2, "name": "Honest John Pizza", "food": ["cheese pizza", "pepperoni pizza"], "quantity": 120, "beverages": ["soda"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 1, "item": "filet", "restaurant_name": "American Steak House", "qval": 100 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 2, "item": "cheese pizza", "restaurant_name": "Honest John Pizza", "drink": "lemonade", "qval": 120 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 3, "item": "cheese pizza", "restaurant_name": "Honest John Pizza", "drink": "soda", "qval": 140 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom_second',' {"_id": 1, "country": "America", "qq": 100 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom_second','{ "_id": 2, "country": "Canada", "qq": 120 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Add a $lookup with let SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQval": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedQval" : { "$numberInt" : "100" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedQval" : { "$numberInt" : "120" } } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } (3 rows) -- Add a $lookup with let but add a subquery stage SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } (3 rows) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$addFields": { "addedQvalBefore": "$$qval" }}, { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQvalAfter": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedQvalBefore" : { "$numberInt" : "100" }, "addedQvalAfter" : { "$numberInt" : "100" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedQvalBefore" : { "$numberInt" : "120" }, "addedQvalAfter" : { "$numberInt" : "120" } } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } (3 rows) -- nested $lookup SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "myExtra" : [ { "_id" : { "$numberInt" : "1" }, "country" : "America", "qq" : { "$numberInt" : "100" } } ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" } } ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" } } ] } ] } (3 rows) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedVal" : { "$numberInt" : "100" }, "myExtra" : [ { "_id" : { "$numberInt" : "1" }, "country" : "America", "qq" : { "$numberInt" : "100" } } ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "120" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" } } ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "140" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" } } ] } ] } (3 rows) -- multiple variable in lookup let SELECT documentdb_api.insert('db', '{"insert":"orderscoll", "documents":[ { "_id": 1, "orderId": "A001", "productId": "P001", "quantity": 10 }, { "_id": 2, "orderId": "A002", "productId": "P002", "quantity": 5 }, { "_id": 3, "orderId": "A003", "productId": "P001", "quantity": 2 } ] }'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"products", "documents":[ { "_id": "P001", "name": "Product 1", "price": 100 }, { "_id": "P002", "name": "Product 2", "price": 200 } ] }'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$_id", "$$productId" ] } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "orderId" : "A001", "productId" : "P001", "quantity" : { "$numberInt" : "10" }, "productDetails" : { "name" : "Product 1", "price" : { "$numberInt" : "100" }, "field" : "parag" } } { "_id" : { "$numberInt" : "2" }, "orderId" : "A002", "productId" : "P002", "quantity" : { "$numberInt" : "5" }, "productDetails" : { "name" : "Product 2", "price" : { "$numberInt" : "200" }, "field" : "parag" } } { "_id" : { "$numberInt" : "3" }, "orderId" : "A003", "productId" : "P001", "quantity" : { "$numberInt" : "2" }, "productDetails" : { "name" : "Product 1", "price" : { "$numberInt" : "100" }, "field" : "parag" } } (3 rows) EXPLAIN (COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$_id", "$$productId" ] } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop -> Bitmap Heap Scan on documents_4137_413118 collection Recheck Cond: (shard_key_value = '4137'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4137'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_4138_413128 collection_0_1 Recheck Cond: (shard_key_value = '4138'::bigint) Filter: documentdb_api_internal.bson_dollar_expr(document, '{ "" : { "$eq" : [ "$_id", "$$productId" ] } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "productId" : "$productId", "hello" : "parag" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4138'::bigint) SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_0 (20 rows) -- only part of the pipeline uses let SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "_id": { "$gt": "P001" } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "orderId" : "A001", "productId" : "P001", "quantity" : { "$numberInt" : "10" }, "productDetails" : { "name" : "Product 2", "price" : { "$numberInt" : "200" }, "field" : "parag" } } { "_id" : { "$numberInt" : "2" }, "orderId" : "A002", "productId" : "P002", "quantity" : { "$numberInt" : "5" }, "productDetails" : { "name" : "Product 2", "price" : { "$numberInt" : "200" }, "field" : "parag" } } { "_id" : { "$numberInt" : "3" }, "orderId" : "A003", "productId" : "P001", "quantity" : { "$numberInt" : "2" }, "productDetails" : { "name" : "Product 2", "price" : { "$numberInt" : "200" }, "field" : "parag" } } (3 rows) EXPLAIN (COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "_id": { "$gt": "P001" } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop -> Aggregate -> Index Scan using _id_ on documents_4138_413128 collection_0_1 Index Cond: ((shard_key_value = '4138'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "P001" }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "P001" }'::documentdb_core.bson) -> Bitmap Heap Scan on documents_4137_413118 collection Recheck Cond: (shard_key_value = '4137'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4137'::bigint) SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_0 (18 rows) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }}, { "$addFields": { "addedVal": "$$qval" }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedVal" : { "$numberInt" : "100" }, "myExtra" : [ { "_id" : { "$numberInt" : "1" }, "country" : "America", "qq" : { "$numberInt" : "100" }, "addedVal" : { "$numberInt" : "100" } } ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "120" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" }, "addedVal" : { "$numberInt" : "120" } } ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "140" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" }, "addedVal" : { "$numberInt" : "140" } } ] } ] } (3 rows) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$sort": { "_id": 1 }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }}, { "$addFields": { "addedVal": "$$secondVar" }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedVal" : { "$numberInt" : "100" }, "myExtra" : [ { "_id" : { "$numberInt" : "1" }, "country" : "America", "qq" : { "$numberInt" : "100" }, "addedVal" : { "$numberInt" : "100" } } ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "120" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" }, "addedVal" : { "$numberInt" : "120" } } ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedVal" : { "$numberInt" : "140" }, "myExtra" : [ { "_id" : { "$numberInt" : "2" }, "country" : "Canada", "qq" : { "$numberInt" : "120" }, "addedVal" : { "$numberInt" : "120" } } ] } ] } (3 rows) -- with an expression that returns empty, the variable should be defined as empty SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "c": "$$c" }, "filter": {}, "let": { "c": {"$getField": {"field": "c", "input": {"a": 1}}}} }'); document --------------------------------------------------------------------- { "_id" : "1" } { "_id" : "2" } { "_id" : "3" } (3 rows) -- $literal should be treated as literal SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "c": "$$c" }, "filter": {}, "let": { "c": {"$literal": "$$NOW"}} }'); document --------------------------------------------------------------------- { "_id" : "1", "c" : "$$NOW" } { "_id" : "2", "c" : "$$NOW" } { "_id" : "3", "c" : "$$NOW" } (3 rows) -- these should fail - parse and validate no path, CURRENT or ROOT in let spec. SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$a" } }'); ERROR: A command let expression attempted to access a field, which is disallowed because such expressions execute prior to the query processing any documents. SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$ROOT" } }'); ERROR: A command let expression attempted to access a field, which is disallowed because such expressions execute prior to the query processing any documents. SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$CURRENT" } }'); ERROR: A command let expression attempted to access a field, which is disallowed because such expressions execute prior to the query processing any documents. SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": { "$sum": [ "$a", "$a" ] } } }'); ERROR: A command let expression attempted to access a field, which is disallowed because such expressions execute prior to the query processing any documents. -- internal, lookup expression eval merge should wrap variables into $literal and if the variable evaluates to empty, should transform into $$REMOVE SELECT documentdb_api_internal.bson_dollar_lookup_expression_eval_merge('{"_id": 1, "b": "$someField"}', '{ "local_b" : "$b", "local_a": "$a" }'::documentdb_core.bson, '{}'::documentdb_core.bson); bson_dollar_lookup_expression_eval_merge --------------------------------------------------------------------- { "let" : { "local_b" : { "$literal" : "$someField" }, "local_a" : "$$REMOVE" } } (1 row) SELECT documentdb_api_internal.bson_dollar_lookup_expression_eval_merge('{"_id": 1, "b": "$someField"}', '{ "local_b" : "$b", "local_a": "$a", "local_var1": "$$var1" }'::documentdb_core.bson, '{"var1": {"$literal": "ABC"}}'::documentdb_core.bson); bson_dollar_lookup_expression_eval_merge --------------------------------------------------------------------- { "var1" : { "$literal" : "ABC" }, "let" : { "local_b" : { "$literal" : "$someField" }, "local_a" : "$$REMOVE", "local_var1" : { "$literal" : "ABC" } } } (1 row) -- lookup with let when a field is missing the path a variable references and when that field is a string in the form of a field expression SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"1", "a": { } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"2", "b": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"3", "a": "$notAFieldPath" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_lookup_missing", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_lookup_missing", "as": "res", "let": {"local_a": "$a"}, "pipeline": [ { "$match": {"$expr": {"$eq": ["$$local_a", "$a"]}}}, {"$project":{"_id": 1}} ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { }, "res" : [ { "_id" : "1" } ] } { "_id" : "2", "b" : { "$numberInt" : "1" }, "res" : [ { "_id" : "2" } ] } { "_id" : "3", "a" : "$notAFieldPath", "res" : [ { "_id" : "3" } ] } (3 rows) /* Shard the collections */ SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- let support in $expr WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varNotRef" ] } }, "let": { "varRef": "3" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; ERROR: Attempting to use an undefined variable: varNotRef -- let support in $expr with nested $let WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } { "_id" : "2", "newField" : { "$numberInt" : "3" } } (2 rows) WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } (1 row) -- same scenario but with aggregation pipeline WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": "3" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (2 rows) WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (2 rows) -- let support in $expr with nested $let WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" } } { "_id" : "2", "newField" : { "$numberInt" : "3" } } (2 rows) -- same scenario but with aggregation pipeline WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } (1 row) -- find/aggregate with variables referencing other variables on the same let spec should work WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef": "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "varRef": 20, "add": { "$add": ["$$varRef", 2] }, "multiply": { "$multiply": ["$$add", 2] } } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" } } (3 rows) -- nested $let should also work WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$project": { "varRef": "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" } }], "let": { "varRef": 20, "add": { "$add": ["$$varRef", 2] }, "multiply": { "$multiply": ["$$add", 2] }, "nestedLet": { "$let": { "vars": { "add": { "$add": ["$$multiply", 1] } }, "in": "$$add" } } } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "2", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } { "_id" : "3", "varRef" : { "$numberInt" : "20" }, "add" : { "$numberInt" : "22" }, "multiply" : { "$numberInt" : "44" }, "nestedLet" : { "$numberInt" : "45" } } (3 rows) -- $addFields WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField1": "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField1" : { "$numberInt" : "3" }, "c" : false } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField1" : { "$numberInt" : "3" }, "c" : false } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : false, "newField1" : { "$numberInt" : "3" } } (3 rows) -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceRoot": { "newRoot": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } (3 rows) -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceWith": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } { "newField" : { "$numberInt" : "3" }, "c" : false } (3 rows) -- $group (with simple aggregators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" } } (1 row) -- $group (with sorted accumulators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "first": { "$first" : "$a.b" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" }, "first" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "last": { "$last" : "$a.b" } } } ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "9" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "top": {"$top": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "top" : [ "1" ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "bottom": {"$bottom": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "bottom" : [ "3" ] } (1 row) -- $project WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "_id": 1, "newField": "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "2", "newField" : { "$numberInt" : "3" }, "c" : false } { "_id" : "3", "c" : false, "newField" : { "$numberInt" : "3" } } (3 rows) -- $unionWith WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "c": "foo" } }, { "$unionWith": { "coll": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "bar": "$$varRef" } } ] } } ], "let": { "varRef": 30 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "c" : "foo" } { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "bar" : { "$numberInt" : "30" } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "c" : "foo" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "bar" : { "$numberInt" : "30" } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : "foo" } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "bar" : { "$numberInt" : "30" } } (6 rows) -- $sortByCount WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$sortByCount": { "$lt": [ "$_id", "$$varRef" ] } } ], "let": { "varRef": "2" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : false, "count" : { "$numberInt" : "2" } } { "_id" : true, "count" : { "$numberInt" : "1" } } (2 rows) -- $facet WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField": "myvalue" } }, { "$facet": { "sb1": [ { "$addFields": { "myVar": "$$varRef" } } ], "sb2": [ { "$group": { "_id": "$$varRef", "c": { "$sum": "$$varRef" } } } ] } } ], "let": { "varRef": "2" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "sb1" : [ { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "newField" : "myvalue", "myVar" : "2" }, { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newField" : "myvalue", "myVar" : "2" }, { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newField" : "myvalue", "myVar" : "2" } ], "sb2" : [ { "_id" : "2", "c" : { "$numberInt" : "0" } } ] } (1 row) -- $graphLookup SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_gl', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_gl", "pipeline": [ { "$graphLookup": { "from": "aggregation_pipeline_let_gl", "startWith": { "$max": [ "$reportsTo", "$$reportsTo" ] }, "connectFromField": "reportsTo", "connectToField": "name", "as": "reportingHierarchy" } } ], "let": { "reportsTo": "Dev" } }'); ERROR: $graphLookup using 'from' on a sharded collection is currently unsupported -- $inverseMatch SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_inv', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_inv", "pipeline": [ { "$inverseMatch": { "path": "policy", "from": "aggregation_pipeline_let_gl", "pipeline": [{"$match": {"$expr": { "$eq": [ "$name", "$$varRef"] }} }] } }], "let": { "varRef": "Dev" } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "policy" : { "name" : "Dev" } } (1 row) -- $window operators SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_setWindowFields', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- $setWindowFields WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_setWindowFields", "pipeline": [ { "$setWindowFields": { "partitionBy": { "$concat": ["$a", "$$varRef"] }, "output": { "total": { "$sum": "$$varRefNum" } } } } ], "let": { "varRef": "prefix", "varRefNum": 2 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "abc", "cost" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "501" }, "date" : { "$date" : { "$numberLong" : "1718841600000" } }, "total" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "def", "cost" : { "$numberInt" : "8" }, "quantity" : { "$numberInt" : "502" }, "date" : { "$date" : { "$numberLong" : "1718841605000" } }, "total" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "ghi", "cost" : { "$numberInt" : "4" }, "quantity" : { "$numberInt" : "503" }, "date" : { "$date" : { "$numberLong" : "1718841610000" } }, "total" : { "$numberInt" : "2" } } (3 rows) -- $lookup SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_pipelineto', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- $lookup with nested pipeline and let WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } } }, { "$addFields": { "addedQval": "$$qval" } } ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } } } ], "cursor": {} }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedQval" : { "$numberInt" : "100" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedQval" : { "$numberInt" : "120" } } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } (3 rows) -- Add a $lookup with let but add a subquery stage -- $lookup with nested pipeline using $sort and $match with let WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } } } ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } } } ], "cursor": {} }') ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ] } ] } { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } (3 rows) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$addFields": { "addedQvalBefore": "$$qval" }}, { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQvalAfter": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "lemonade", "qval" : { "$numberInt" : "120" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "name" : "Honest John Pizza", "food" : [ "cheese pizza", "pepperoni pizza" ], "quantity" : { "$numberInt" : "120" }, "beverages" : [ "soda" ], "addedQvalBefore" : { "$numberInt" : "120" }, "addedQvalAfter" : { "$numberInt" : "120" } } ] } { "_id" : { "$numberInt" : "3" }, "item" : "cheese pizza", "restaurant_name" : "Honest John Pizza", "drink" : "soda", "qval" : { "$numberInt" : "140" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "item" : "filet", "restaurant_name" : "American Steak House", "qval" : { "$numberInt" : "100" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "name" : "American Steak House", "food" : [ "filet", "sirloin" ], "quantity" : { "$numberInt" : "100" }, "beverages" : [ "beer", "wine" ], "addedQvalBefore" : { "$numberInt" : "100" }, "addedQvalAfter" : { "$numberInt" : "100" } } ] } (3 rows) -- nested $lookup SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); ERROR: Nested lookup with let on sharded collections not supported yet SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); ERROR: Nested lookup with let on sharded collections not supported yet -- Test for lookup with let and $match with $expr SELECT documentdb_api.insert_one('db','lookup_left',' { "_id" : 1, "item" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','lookup_left',' { "_id" : 2, "item" : 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Fill right collection with more than 100 MB of data DO $$ DECLARE i int; BEGIN FOR i IN 1..50 LOOP PERFORM documentdb_api.insert_one('db', 'lookup_right', FORMAT('{ "_id": %s, "name": %s, "c": { "%s": [ %s "d" ] } }', i, i, i, REPEAT('"' || i || REPEAT('a', 1000) || '", ', 5000))::documentdb_core.bson, NULL); END LOOP; END; $$; NOTICE: creating collection -- This will throw size error because $match in not inlined with right query as it is not the first stage SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$project": { "c": 0 } }, { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); ERROR: Size 106297794 is larger than maximum size allowed for an intermediate document 104857600 EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$project": { "c": 0 } }, { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'myMatch'::text) lookup_subpipeline_substage_0(lookup_unwind) WHERE documentdb_api_internal.bson_dollar_expr(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let), '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let)), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right", documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413201 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4140'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS document FROM documentdb_data.documents_4141_413218 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4141'::bigint)) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_4141_413218 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '4141'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4141'::bigint) -> Bitmap Heap Scan on documentdb_data.documents_4140_413201 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4140'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4140'::bigint) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson)), 'myMatch'::text) Filter: documentdb_api_internal.bson_dollar_expr(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) (28 rows) -- This should not throw error as $match is inlined with right query SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : { "$numberInt" : "1" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : { "$numberInt" : "2" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : { "$numberInt" : "2" } } ] } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'myMatch'::text) lookup_subpipeline_substage_0(lookup_unwind)), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right", documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413201 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '4140'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_4141_413218 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '4141'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_expr(lookup_right_query_stage_0.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, lookup_stage_1.let)) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true) -> Bitmap Heap Scan on documentdb_data.documents_4140_413201 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '4140'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '4140'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_4141_413218 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '4141'::bigint) Filter: documentdb_api_internal.bson_dollar_expr(collection_0_1.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4141'::bigint) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(collection.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson)), 'myMatch'::text) (28 rows) -- Shard left collection and right collections SET citus.explain_all_tasks to on; SET citus.max_adaptive_executor_pool_size to 1; SELECT documentdb_api.shard_collection('{ "shardCollection": "db.lookup_left", "key": { "_id": "hashed" }, "numInitialChunks": 2 }'); shard_collection --------------------------------------------------------------------- (1 row) WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline( 'db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] } } }, { "$project": { "c": 0 } } ], "as": "myMatch", "let": { "item_name": "$item" } } } ], "cursor": {} }' ) ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : { "$numberInt" : "1" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : { "$numberInt" : "2" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : { "$numberInt" : "2" } } ] } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 444_1 -> Custom Scan (Citus Adaptive) Output: remote_scan."left", remote_scan."right", remote_scan.let -> Distributed Subplan 447_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.let Task Count: 2 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413232 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4140_413232 collection Output: document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413233 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4140_413233 collection Output: document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Distributed Subplan 447_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_4141_413218 collection_0_1 WHERE (shard_key_value OPERATOR(pg_catalog.=) '4141'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_4141_413218 collection_0_1 Output: document Recheck Cond: (collection_0_1.shard_key_value = '4141'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '4141'::bigint) Task Count: 1 Tasks Shown: All -> Task Query: SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right", documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM ((SELECT intermediate_result.document, intermediate_result.let FROM read_intermediate_result('447_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, let documentdb_core.bson)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('447_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_expr(lookup_right_query_stage_0.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, lookup_stage_1.let)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: intermediate_result.document, (COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson)), documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(intermediate_result.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document, intermediate_result.let Function Call: read_intermediate_result('447_1'::text, 'binary'::citus_copy_format) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result_1 Output: intermediate_result_1.document Function Call: read_intermediate_result('447_2'::text, 'binary'::citus_copy_format) Filter: documentdb_api_internal.bson_dollar_expr(intermediate_result_1.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, intermediate_result.let) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'myMatch'::text) lookup_subpipeline_substage_0(lookup_unwind)), true) AS document FROM (SELECT intermediate_result."left", intermediate_result."right", intermediate_result.let FROM read_intermediate_result('444_1'::text, 'binary'::citus_copy_format) intermediate_result("left" documentdb_core.bson, "right" documentdb_core.bson, let documentdb_core.bson)) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result."left", (SubPlan 1), true) Function Call: read_intermediate_result('444_1'::text, 'binary'::citus_copy_format) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, intermediate_result.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind(intermediate_result."right", 'myMatch'::text) (63 rows) SELECT documentdb_api.shard_collection('{ "shardCollection": "db.lookup_right", "key": { "_id": "hashed" }, "numInitialChunks": 2 }'); shard_collection --------------------------------------------------------------------- (1 row) WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline( 'db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] } } }, { "$project": { "c": 0 } } ], "as": "myMatch", "let": { "item_name": "$item" } } } ], "cursor": {} }' ) ) SELECT * FROM c1 ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : { "$numberInt" : "1" }, "myMatch" : [ { "_id" : { "$numberInt" : "1" }, "name" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "item" : { "$numberInt" : "2" }, "myMatch" : [ { "_id" : { "$numberInt" : "2" }, "name" : { "$numberInt" : "2" } } ] } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 477_1 -> Custom Scan (Citus Adaptive) Output: remote_scan."left", remote_scan."right", remote_scan.let -> Distributed Subplan 480_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.let Task Count: 2 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413232 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4140_413232 collection Output: document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM documentdb_data.documents_4140_413233 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4140_413233 collection Output: document, documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Distributed Subplan 480_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 2 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_4141_413234 collection_0_1 WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4141_413234 collection_0_1 Output: document -> Task Query: SELECT document FROM documentdb_data.documents_4141_413235 collection_0_1 WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_4141_413235 collection_0_1 Output: document Task Count: 1 Tasks Shown: All -> Task Query: SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right", documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS let FROM ((SELECT intermediate_result.document, intermediate_result.let FROM read_intermediate_result('480_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, let documentdb_core.bson)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('480_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_expr(lookup_right_query_stage_0.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, lookup_stage_1.let)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: intermediate_result.document, (COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson)), documentdb_api_internal.bson_dollar_lookup_expression_eval_merge(intermediate_result.document, '{ "item_name" : "$item" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document, intermediate_result.let Function Call: read_intermediate_result('480_1'::text, 'binary'::citus_copy_format) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result_1 Output: intermediate_result_1.document Function Call: read_intermediate_result('480_2'::text, 'binary'::citus_copy_format) Filter: documentdb_api_internal.bson_dollar_expr(intermediate_result_1.document, '{ "" : { "$eq" : [ "$name", "$$item_name" ] } }'::documentdb_core.bson, intermediate_result.let) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, lookup_non_inlined_stage_1.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'myMatch'::text) lookup_subpipeline_substage_0(lookup_unwind)), true) AS document FROM (SELECT intermediate_result."left", intermediate_result."right", intermediate_result.let FROM read_intermediate_result('477_1'::text, 'binary'::citus_copy_format) intermediate_result("left" documentdb_core.bson, "right" documentdb_core.bson, let documentdb_core.bson)) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result."left", (SubPlan 1), true) Function Call: read_intermediate_result('477_1'::text, 'binary'::citus_copy_format) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(documentdb_api_internal.bson_dollar_project(lookup_subpipeline_substage_0.lookup_unwind, '{ "c" : { "$numberInt" : "0" } }'::documentdb_core.bson, intermediate_result.let), 'myMatch'::text), '{ "myMatch" : [ ] }'::documentdb_core.bson) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind(intermediate_result."right", 'myMatch'::text) (65 rows) RESET citus.explain_all_tasks; RESET citus.max_adaptive_executor_pool_size; -- query match -- ignore variableSpec (turn off all GUCs that enable bson_query_match) SET documentdb_core.enableCollation TO off; SET documentdb.enableLetAndCollationForQueryMatch TO off; SET documentdb.enableVariablesSupportForWriteCommands TO off; SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"a": "$$varRef"} }', '{ "let": {"varRef": "cat"} }', NULL); NOTICE: using bson_query_match implementation ERROR: Attempting to use an undefined variable: varRef -- use variableSpec (turn GUC on) SET documentdb.enableLetAndCollationForQueryMatch TO on; -- query match: wrong access of variable in query (outside $expr) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "$$varRef"}', '{ "let": {"varRef": "cat"} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 5}', '{"a": {"$lt": "$$varRef"} }', '{ "let": {"varRef": 10} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) -- query match: using $expr SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$eq": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "cat"} }', NULL); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"$expr": {"$and": [{"$eq": ["$a", "$$varRef1"] }, {"$eq": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$ne": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "dog"} }', NULL); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$gt": ["$a", "$$varRef"] } }', '{ "let": {"varRef": 5} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$gte": ["$a", "$$varRef"] } }', '{ "let": {"varRef": -2} }', NULL); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$or": [{"$lt": ["$a", "$$varRef1"] }, {"$gt": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 2} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$and": [{"$lt": ["$a", "$$varRef1"] }, {"$gt": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 2} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$not": {"$lt": ["$a", "$$varRef"] } } }', '{ "let": {"varRef": 5} }', NULL); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$in": ["$a", ["$$varRef1", "$$varRef2"]] } }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: sharded collection SELECT documentdb_api.shard_collection('db', 'coll_query_op_let', '{ "_id": "hashed" }', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.insert_one('db', 'coll_query_op_let', '{"_id": 1, "a": "cat" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_query_op_let', '{"_id": 2, "a": "dog" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$eq": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "cat"} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$ne": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "dog"} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$in": ["$a", ["$$varRef1", "$$varRef2"]] } }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (2 rows) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$lt": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 2} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$lte": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 2} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (2 rows) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$gt": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (1 row) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$gte": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (2 rows) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$and": [{"$lt": ["$_id", "$$varRef1"] }, {"$gt": ["$_id", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 1} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- (0 rows) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$or": [{"$lt": ["$_id", "$$varRef1"] }, {"$gt": ["$_id", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 1} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (2 rows) SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$not": {"$lt": ["$_id", "$$varRef"] } } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } (2 rows) RESET documentdb.enableLetAndCollationForQueryMatch; RESET documentdb.enableVariablesSupportForWriteCommands; -- let with geonear SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear_let", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }]}'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 1, "a": { "b": [ 5, 5]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 2, "a": { "b": [ 5, 6]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 3, "a": { "b": [ 5, 7]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": "$location", "distanceField": "dist.calculated", "key": "a.b" } } ] } $$); ERROR: The $geoNear operator must be provided with a fixed and constant near argument SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : "Not a valid point" }, "distanceField": "dist.calculated", "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); ERROR: Expected 'document' or 'array' type for $geoNear 'near' field but found 'string' type SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : [5, 6] }, "distanceField": "dist.calculated", "minDistance": "$p", "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); ERROR: The $geoNear needs the $minDistance to resolve to a fixed numerical value SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : [5, 6] }, "distanceField": "dist.calculated", "maxDistance": { "$literal": [1, 2] }, "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); ERROR: The value for maxDistance must be a valid numeric type -- a valid query SELECT document FROM bson_aggregation_pipeline('db', $spec$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": "$$pointRef", "distanceField": "dist.calculated", "minDistance": "$$dist1", "maxDistance": "$$dist2", "key": "a.b" } } ], "let": { "pointRef": [5, 5], "dist1": 0, "dist2": 2} } $spec$); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] }, "dist" : { "calculated" : { "$numberDouble" : "0.0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }, "dist" : { "calculated" : { "$numberDouble" : "1.0" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }, "dist" : { "calculated" : { "$numberDouble" : "2.0" } } } (3 rows) bson_aggregation_pipeline_tests_maxnminn_group.out000066400000000000000000001353651507310017400423010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1116000; SET documentdb.next_collection_id TO 11160; SET documentdb.next_collection_index_id TO 11160; SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userA", "points": 10 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userB", "points": 55 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userC", "points": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userD", "points": 20 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userA", "points": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userB", "points": 18 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userC", "points": 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userD", "points": 60 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userA", "points": null }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userB", "points": 55 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userC", "points": {"$undefined":true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userD", "points": 20 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userA", "points": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userB", "points": 99 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userA", "points": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userB", "points": 18 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userC", "points": 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userD", "points": {"$undefined":true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userA", "points": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userB", "points": {"$undefined":true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userA", "points": 10 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userB", "points": 55 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userC", "points": [[2,4],8,1,5] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userD", "points": 20 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userA", "points": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userB", "points": [[3,6],2,7] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userC", "points": 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userD", "points": 60 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 1, "teamId": "T1", "person" : "userA", "points": 10 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 2, "teamId": "T1", "person" : "userB", "points": 55 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 3, "teamId": "T1", "person" : "userC", "points": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 4, "teamId": "T1", "person" : "userD", "points": 20 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 5, "teamId": "T2", "person" : "userA", "points": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 6, "teamId": "T2", "person" : "userB", "points": 18 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 7, "teamId": "T2", "person" : "userC", "points": 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 8, "teamId": "T2", "person" : "userD", "points": 60 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userA", "points": 10 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userB", "points": [[1,2],[3,4]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userC", "points": "apple" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userD", "points": 20 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userA", "points": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userC", "points": [[3,4],8,1] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userB", "points": "port" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userD", "points": 60 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" }, { "$numberInt" : "10" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" } ] } (2 rows) /*n == 1*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 1 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 1 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" } ] } (2 rows) /*n == 0*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 0 } } } } ] }'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 0 } } } } ] }'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is 0 /*n == -1*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": -1 } } } } ] }'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": -1 } } } } ] }'); ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 /*n == 0.5*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 0.5 } } } } ] }'); ERROR: Expected 'integer' type for 'n' but found 'double' for value '0.5' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 0.5 } } } } ] }'); ERROR: Expected 'integer' type for 'n' but found 'double' for value '0.5' /*n is a variable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": "$$nValue" } } } } ], "let": { "nValue": 3 } }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": "$$nValue" } } } } ], "let": { "nValue": 3 } }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" }, { "$numberInt" : "10" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" } ] } (2 rows) /*input is a document*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": {"$bitAnd": ["$points", 7]}, "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "4" }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": {"$bitAnd": ["$points", 7]}, "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "0" }, { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } (2 rows) /*n is a object*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": {"key" :{"value": {"points": "$points" }}}, "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "key" : { "value" : { "points" : { "$numberInt" : "55" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "20" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "10" } } } } ] } { "_id" : "T2", "NScore" : [ { "key" : { "value" : { "points" : { "$numberInt" : "60" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "40" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "18" } } } } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": {"key" :{"value": {"points": "$points" }}}, "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "key" : { "value" : { "points" : { "$numberInt" : "3" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "10" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "20" } } } } ] } { "_id" : "T2", "NScore" : [ { "key" : { "value" : { "points" : { "$numberInt" : "7" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "18" } } } }, { "key" : { "value" : { "points" : { "$numberInt" : "40" } } } } ] } (2 rows) /*input is a nested array*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": [[2,3], "$points"], "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "55" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "20" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "10" } ] ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "60" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "40" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "18" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": [[2,3], "$points"], "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "3" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "10" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "20" } ] ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "7" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "18" } ], [ [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "40" } ] ] } (2 rows) /*n too large */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" }, { "$numberInt" : "3" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "18" }, { "$numberInt" : "7" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" }, { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "55" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" }, { "$numberInt" : "60" } ] } (2 rows) /*n missing */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points"} } } } ] }'); ERROR: $maxN requires an 'n' field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points"} } } } ] }'); ERROR: $minN requires an 'n' field /*input missing */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"n": 3 } } } } ] }'); ERROR: $maxN needs to have an 'input' field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"n": 3 } } } } ] }'); ERROR: $minN needs to have an 'input' field /*test null/$undefined */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "99" }, { "$numberInt" : "55" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "40" }, { "$numberInt" : "18" }, { "$numberInt" : "7" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "20" }, { "$numberInt" : "55" }, { "$numberInt" : "99" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "99" }, { "$numberInt" : "55" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "40" }, { "$numberInt" : "18" }, { "$numberInt" : "7" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "20" }, { "$numberInt" : "55" }, { "$numberInt" : "99" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" } ] } (2 rows) /* nested array */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" }, { "$numberInt" : "5" } ], { "$numberInt" : "55" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "3" }, { "$numberInt" : "6" } ], { "$numberInt" : "2" }, { "$numberInt" : "7" } ], { "$numberInt" : "60" }, { "$numberInt" : "40" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "55" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "40" }, { "$numberInt" : "60" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" }, { "$numberInt" : "5" } ], { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" } ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "3" }, { "$numberInt" : "6" } ], { "$numberInt" : "2" }, { "$numberInt" : "7" } ], { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "7" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "55" }, [ [ { "$numberInt" : "2" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" }, { "$numberInt" : "5" } ] ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "40" }, { "$numberInt" : "60" }, [ [ { "$numberInt" : "3" }, { "$numberInt" : "6" } ], { "$numberInt" : "2" }, { "$numberInt" : "7" } ] ] } (2 rows) /* sharded tests */ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> GroupAggregate Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_11163_1116049 collection Recheck Cond: (shard_key_value = '11163'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '11163'::bigint) (14 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> GroupAggregate Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_11163_1116049 collection Recheck Cond: (shard_key_value = '11163'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '11163'::bigint) (14 rows) SELECT documentdb_api.shard_collection('db', 'bson_maxminn_group_test4', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) -> Distributed Subplan 133_1 -> HashAggregate Group Key: remote_scan.c2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> HashAggregate Group Key: documentdb_api_internal.bson_expression_get(document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Seq Scan on documents_11163_1116080 collection Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Function Scan on read_intermediate_result intermediate_result (17 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) -> Distributed Subplan 135_1 -> HashAggregate Group Key: remote_scan.c2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> HashAggregate Group Key: documentdb_api_internal.bson_expression_get(document, '{ "" : "$teamId" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Seq Scan on documents_11163_1116080 collection Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Function Scan on read_intermediate_result intermediate_result (17 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" }, { "$numberInt" : "10" }, { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "55" }, { "$numberInt" : "20" }, { "$numberInt" : "10" }, { "$numberInt" : "3" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "60" }, { "$numberInt" : "40" }, { "$numberInt" : "18" }, { "$numberInt" : "7" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "3" }, { "$numberInt" : "10" }, { "$numberInt" : "20" }, { "$numberInt" : "55" } ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "40" }, { "$numberInt" : "60" } ] } (2 rows) /* test string and nested array */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ], "apple", { "$numberInt" : "20" } ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" } ], "port", { "$numberInt" : "60" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "10" }, { "$numberInt" : "20" }, "apple" ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "40" }, { "$numberInt" : "60" }, "port" ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ], "apple", { "$numberInt" : "20" }, { "$numberInt" : "10" } ] } { "_id" : "T2", "NScore" : [ [ [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" } ], "port", { "$numberInt" : "60" }, { "$numberInt" : "40" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "NScore" : [ { "$numberInt" : "10" }, { "$numberInt" : "20" }, "apple", [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ] ] } { "_id" : "T2", "NScore" : [ { "$numberInt" : "40" }, { "$numberInt" : "60" }, "port", [ [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ], { "$numberInt" : "8" }, { "$numberInt" : "1" } ] ] } (2 rows) /* $maxN are subject to the 100 MB limit */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 12345678 } } } } ] }'); ERROR: Size is larger than maximum size allowed for an intermediate document 104857600 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 9223372036854775807 } } } } ] }'); ERROR: Size is larger than maximum size allowed for an intermediate document 104857600 /* $minN are subject to the 100 MB limit */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 12345678 } } } } ] }'); ERROR: Size is larger than maximum size allowed for an intermediate document 104857600 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 9223372036854775807 } } } } ] }'); ERROR: Size is larger than maximum size allowed for an intermediate document 104857600 bson_aggregation_pipeline_tests_merge_objects_group.out000066400000000000000000001246401507310017400432560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1220000; SET documentdb.next_collection_id TO 12200; SET documentdb.next_collection_index_id TO 12200; SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 1, "year": 2020, "category": "X", "metrics": { "2020A": 10, "2020B": 200 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 2, "year": 2019, "category": "X", "metrics": { "2019A": 150, "2019B": 250, "2019C": 0, "2019D": 0 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 3, "year": 2020, "category": "Y", "metrics": { "2020A": 250 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 4, "year": 2019, "category": "Y", "metrics": { "2019C": 80, "2019D": 180 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 5, "year": 2020, "category": "Z", "metrics": { "2019C": 900, "2019D": 210 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* running multiple $mergeObjects accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2019" }, "mergedMetrics" : { "2019A" : { "$numberInt" : "150" }, "2019B" : { "$numberInt" : "250" }, "2019C" : { "$numberInt" : "80" }, "2019D" : { "$numberInt" : "180" } } } { "_id" : { "$numberInt" : "2020" }, "mergedMetrics" : { "2020A" : { "$numberInt" : "250" }, "2020B" : { "$numberInt" : "200" }, "2019C" : { "$numberInt" : "900" }, "2019D" : { "$numberInt" : "210" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); document --------------------------------------------------------------------- { "_id" : "X", "mergedMetrics" : { "2020A" : { "$numberInt" : "10" }, "2020B" : { "$numberInt" : "200" }, "2019A" : { "$numberInt" : "150" }, "2019B" : { "$numberInt" : "250" }, "2019C" : { "$numberInt" : "0" }, "2019D" : { "$numberInt" : "0" } } } { "_id" : "Y", "mergedMetrics" : { "2020A" : { "$numberInt" : "250" }, "2019C" : { "$numberInt" : "80" }, "2019D" : { "$numberInt" : "180" } } } { "_id" : "Z", "mergedMetrics" : { "2019C" : { "$numberInt" : "900" }, "2019D" : { "$numberInt" : "210" } } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2019" }, "lastCategory" : { "category" : "Y" } } { "_id" : { "$numberInt" : "2020" }, "lastCategory" : { "category" : "Z" } } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedMetrics'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$metrics" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12200_1220001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12200'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedMetrics'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$metrics" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12200_1220001 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12200'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12200'::bigint) (20 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedMetrics'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$metrics" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12200_1220001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12200'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedMetrics'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$metrics" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12200_1220001 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$category" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12200'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12200'::bigint) (20 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'lastCategory'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : { "category" : "$category" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12200_1220001 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12200'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'lastCategory'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "category" : "$category" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12200_1220001 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$year" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12200'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12200'::bigint) (20 rows) SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 13, "group": 1, "obj": {}, "val": null }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 14, "group": 1, "obj": { "x": 2, "y": 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 15, "group": 1, "obj": { "x": 1, "z": 3, "y": null } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 16, "group": 2, "obj": { "x": 1, "y": 1 }, "val": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* running multiple $mergeObjects accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "mergedObj" : { "x" : { "$numberInt" : "1" }, "y" : null, "z" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "2" }, "mergedObj" : { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj.x" } } } ] }'); ERROR: $mergeObjects needs both inputs to be objects, but the provided input 2 has the type int SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": { "result": "$obj.y" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "mergedObj" : { "result" : null } } { "_id" : { "$numberInt" : "2" }, "mergedObj" : { "result" : { "$numberInt" : "1" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$val" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "mergedObj" : null } { "_id" : { "$numberInt" : "2" }, "mergedObj" : null } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj" } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedObj'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$obj" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12201_1220018 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12201'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedObj'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$obj" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12201_1220018 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12201'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12201'::bigint) (20 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj.x" } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedObj'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$obj.x" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12201_1220018 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12201'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedObj'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$obj.x" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12201_1220018 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12201'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12201'::bigint) (20 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": { "result": "$obj.y" } } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedObj'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : { "result" : "$obj.y" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12201_1220018 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12201'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedObj'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "result" : "$obj.y" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12201_1220018 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12201'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12201'::bigint) (20 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$val" } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'mergedObj'::text AS c3, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$val" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4 FROM (SELECT collection.document FROM documentdb_data.documents_12201_1220018 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '12201'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_core.bson_repath_and_build(agg_stage_0.c1, agg_stage_0.c2, agg_stage_0.c3, agg_stage_0.c4) -> GroupAggregate Output: '_id'::text, (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'mergedObj'::text, documentdb_api_internal.bson_merge_objects_on_sorted(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$val" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) Group Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Sort Output: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), collection.document Sort Key: (documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_12201_1220018 collection Output: documentdb_api_internal.bson_expression_get(collection.document, '{ "" : "$group" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), collection.document Recheck Cond: (collection.shard_key_value = '12201'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '12201'::bigint) (20 rows) /* running mergeObjects with intermediate size of more than 100mb */ DO $$ DECLARE i int; BEGIN -- each doc is "%s": 5 MB - ~5.5 MB & there's 25 of them FOR i IN 1..25 LOOP PERFORM documentdb_api.insert_one('db', 'mergeObjSizeTest', FORMAT('{ "_id": %s, "groupName": "A", "largeObj": { "%s": [ %s "d" ] } }', i, i, repeat('"' || i || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection /* should fail with intermediate size error */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjSizeTest", "pipeline": [ { "$group": { "_id": "$groupName", "mergedObj": { "$mergeObjects": "$largeObj" } } } ] }'); ERROR: Size 106297374 is larger than maximum size allowed for an intermediate document 104857600 /* shard collections and test for order and validations */ SELECT documentdb_api.shard_collection('db', 'mergeObjTestColl1', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2019" }, "mergedMetrics" : { "2019A" : { "$numberInt" : "150" }, "2019B" : { "$numberInt" : "250" }, "2019C" : { "$numberInt" : "80" }, "2019D" : { "$numberInt" : "180" } } } { "_id" : { "$numberInt" : "2020" }, "mergedMetrics" : { "2020A" : { "$numberInt" : "250" }, "2020B" : { "$numberInt" : "200" }, "2019C" : { "$numberInt" : "900" }, "2019D" : { "$numberInt" : "210" } } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); document --------------------------------------------------------------------- { "_id" : "X", "mergedMetrics" : { "2019A" : { "$numberInt" : "150" }, "2019B" : { "$numberInt" : "250" }, "2019C" : { "$numberInt" : "0" }, "2019D" : { "$numberInt" : "0" }, "2020A" : { "$numberInt" : "10" }, "2020B" : { "$numberInt" : "200" } } } { "_id" : "Z", "mergedMetrics" : { "2019C" : { "$numberInt" : "900" }, "2019D" : { "$numberInt" : "210" } } } { "_id" : "Y", "mergedMetrics" : { "2019C" : { "$numberInt" : "80" }, "2019D" : { "$numberInt" : "180" }, "2020A" : { "$numberInt" : "250" } } } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2019" }, "lastCategory" : { "category" : "Y" } } { "_id" : { "$numberInt" : "2020" }, "lastCategory" : { "category" : "Z" } } (2 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "shouldFail": { "$mergeObjects": "$category" } } } ] }'); ERROR: $mergeObjects needs both inputs to be objects, but the provided input "X" has the type string select documentdb_api.drop_collection('db','mergeObjTestColl1'); drop_collection --------------------------------------------------------------------- t (1 row) select documentdb_api.drop_collection('db','mergeObjTestColl2'); drop_collection --------------------------------------------------------------------- t (1 row) select documentdb_api.drop_collection('db','mergeObjSizeTest'); drop_collection --------------------------------------------------------------------- t (1 row) bson_aggregation_pipeline_tests_percentile_median.out000066400000000000000000000445651507310017400427100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- will move to bson_aggregation_pipeline_stage_setWindowFields.sql and remove this file after window operator is done, just like $stddevopo did SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1033000; SET documentdb.next_collection_id TO 10330; SET documentdb.next_collection_index_id TO 10330; SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 1, "group": 1, "dataVal": 111, "dataVal2": 111, "dataVal3": {"$numberDecimal": "111"}, "dataVal4": 111, "dataVal5": NaN }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 2, "group": 1, "dataVal": 11, "dataVal2": 11, "dataVal3": {"$numberDecimal": "11"}, "dataVal4": 11, "dataVal5": Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 3, "group": 1, "dataVal": 11111, "dataVal2": "string", "dataVal3": {"$numberDecimal": "11111"}, "dataVal4": {"$numberDecimal": "2E+310"}, "dataVal5": Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 4, "group": 1, "dataVal": 1, "dataVal2": 1, "dataVal3": {"$numberDecimal": "1"}, "dataVal4": 1, "dataVal5": -Infinity }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 5, "group": 1, "dataVal": 1111, "dataVal2": 1111, "dataVal3": {"$numberDecimal": "1111"}, "dataVal4": 1111, "dataVal5": NaN }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- positive test case for percentile SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "11111.0" } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "11111.0" }, { "$numberDouble" : "111.0" } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": null, "p": [ 0.95 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ null ] } (1 row) -- contain non-numeric value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal2", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "1111.0" } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal2", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "1111.0" }, { "$numberDouble" : "11.0" } ] } (1 row) -- contain decimal value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal3", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "11111.0" } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal3", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "11111.0" }, { "$numberDouble" : "111.0" } ] } (1 row) -- data value exceeds double range taken as infinity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal4", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "Infinity" } ] } (1 row) -- handle NaN and Infinity values SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal5", "p": [ 1, 0, 0.1, 0.9, 0.4 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "Infinity" }, { "$numberDouble" : "-Infinity" }, { "$numberDouble" : "-Infinity" }, { "$numberDouble" : "Infinity" }, { "$numberDouble" : "Infinity" } ] } (1 row) -- with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [{"$group": {"_id": null,"percentileVal": {"$percentile": {"p": "$$ps", "input": "$dataVal","method": "approximate"}}}}], "let": {"ps": [0.95, 0.5]}}'); document --------------------------------------------------------------------- { "_id" : null, "percentileVal" : [ { "$numberDouble" : "11111.0" }, { "$numberDouble" : "111.0" } ] } (1 row) -- positive test case for median SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "111.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": null, "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : null } (1 row) -- contain non-numeric value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal2", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "11.0" } } (1 row) -- contain decimal value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal3", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "111.0" } } (1 row) -- data value exceeds double range taken as infinity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal4", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "111.0" } } (1 row) -- handle NaN and Infinity values SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal5", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "Infinity" } } (1 row) -- with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [{"$group": {"_id": null,"medianVal": {"$median": {"input": "$$val","method": "approximate"}}}}], "let": {"val": 5}}'); document --------------------------------------------------------------------- { "_id" : null, "medianVal" : { "$numberDouble" : "5.0" } } (1 row) -- negative test case for percentile -- invalid input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": 1 } } } ] }'); ERROR: Specification must be an object type, but instead received $percentile with type: int -- unkonwn field in input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "approximate", "unknownField": "unknownValue" } } } } ] }'); ERROR: The BSON field named with operators '$$percentile.unknownField' is not recognized. -- p value not an array SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": 1.5, "method": "approximate" } } } } ] }'); ERROR: Expected an array containing numbers from 0.0 to 1.0, but instead received: 1.5 -- p value is an empty array SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [], "method": "approximate" } } } } ] }'); ERROR: Expected an array containing numbers from 0.0 to 1.0, but instead received: [ ] -- p value is an array with invalid value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 1.5 ], "method": "approximate" } } } } ] }'); ERROR: Expected an array containing numbers from 0.0 to 1.0, but instead received: 1.500000 -- invalid method SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "invalid" } } } } ] }'); ERROR: Currently only 'approximate' can be used as percentile 'method' -- missing input field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "p": [ 0.95 ], "method": "approximate" } } } } ] }'); ERROR: The BSON field '$$percentile.input' is required but is currently missing from the data structure -- missing p field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "method": "approximate" } } } } ] }'); ERROR: The BSON field '$$percentile.p' is required but is currently missing from the data structure -- missing method field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ] } } } } ] }'); ERROR: The BSON field '$$percentile.method' is required but is currently missing from the data structure -- negative test case for median -- invalid input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": 1 } } } ] }'); ERROR: Specification must be an object type, but instead received $median with type: int -- unkonwn field in input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate", "unknownField": "unknownValue" } } } } ] }'); ERROR: The BSON field named with operators '$$median.unknownField' is not recognized. -- invalid method SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "invalid" } } } } ] }'); ERROR: Currently only 'approximate' can be used as percentile 'method' -- missing input field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "method": "approximate" } } } } ] }'); ERROR: The BSON field '$$median.input' is required but is currently missing from the data structure -- missing method field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal" } } } } ] }'); ERROR: The BSON field '$$median.method' is required but is currently missing from the data structure /* shard collection */ SELECT documentdb_api.shard_collection('db', 'testPercentileAndMedian', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- percentile SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "percentileVal" : [ { "$numberDouble" : "11111.0" }, { "$numberDouble" : "111.0" } ] } (1 row) -- median SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "medianVal" : { "$numberDouble" : "111.0" } } (1 row) bson_aggregation_pipeline_tests_point_read.out000066400000000000000000000766651507310017400413730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 423000; SET documentdb.next_collection_id TO 4230; SET documentdb.next_collection_index_id TO 4230; SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('agg_db', '{ "createIndexes": "aggregation_find_point_read", "indexes": [ { "key": { "$**": "text" }, "name": "my_txt" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('agg_db', 'aggregation_find_point_read') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 4232 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } 4232 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 4232 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- basic point read (colocated table) - uses fast path SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }}'); document --------------------------------------------------------------------- { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } (1 row) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }}'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) -- same point read on non-colocated table - uses slow path EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_find_point_read_noncoll", "filter": { "_id": "2" }}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) (actual rows=1 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 55 bytes Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_4230_423000 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "2" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "2" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '4230'::bigint)) Tuple data received from node: 55 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_4230_423000 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4230'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "2" }'::documentdb_core.bson)) (12 rows) -- now test point reads with various find features for fast path -- limit EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 0 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 1 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 2 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 3 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) -- skip EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 1 }'); QUERY PLAN --------------------------------------------------------------------- Limit (cost=0.00..0.00 rows=1 width=32) (actual rows=0 loops=1) Output: document -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (5 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 2 }'); QUERY PLAN --------------------------------------------------------------------- Limit (cost=0.00..0.00 rows=1 width=32) (actual rows=0 loops=1) Output: document -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (5 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 3 }'); QUERY PLAN --------------------------------------------------------------------- Limit (cost=0.00..0.00 rows=1 width=32) (actual rows=0 loops=1) Output: document -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (5 rows) -- skip + limit EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0, "limit": 0 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0, "limit": 1 }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 1, "limit": 1 }'); QUERY PLAN --------------------------------------------------------------------- Limit (cost=0.00..0.00 rows=1 width=32) (actual rows=0 loops=1) Output: document -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (5 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 2, "limit": 2 }'); QUERY PLAN --------------------------------------------------------------------- Limit (cost=0.00..0.00 rows=1 width=32) (actual rows=0 loops=1) Output: document -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (5 rows) -- sort EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "_id": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "_id": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) -- projection EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "projection": { "a.b": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: bson_dollar_project_find(document, '{ "a.b" : { "$numberInt" : "1" } }'::bson, '{ "_id" : "2" }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) -- filter EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "a": { "$exists": true } }, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: (collection.document #>= '{ "a" : { "$minKey" : 1 } }'::bsonquery) (4 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "a": { "$exists": false } }, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=0 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: bson_dollar_exists(collection.document, '{ "a" : false }'::bson) Rows Removed by Filter: 1 (5 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 1 } }, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (cost=0.01..0.02 rows=1 width=64) (actual rows=0 loops=1) Output: document, (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) Sort Key: (bson_orderby(collection.document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=64) (actual rows=0 loops=1) Output: document, bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson) Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: (collection.document @> '{ "_id" : { "$numberInt" : "1" } }'::bson) Rows Removed by Filter: 1 (9 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 2 } }, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (cost=0.01..0.02 rows=1 width=64) (actual rows=0 loops=1) Output: document, (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) Sort Key: (bson_orderby(collection.document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=64) (actual rows=0 loops=1) Output: document, bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson) Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: (collection.document @> '{ "_id" : { "$numberInt" : "2" } }'::bson) Rows Removed by Filter: 1 (9 rows) -- filter with special operators EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "$text": { "$search": "abc" } }, "sort": { "$meta": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (cost=25000004.03..25000004.04 rows=1 width=64) (actual rows=0 loops=1) Output: document, (bson_orderby(document, '{ "$meta" : { "$numberInt" : "1" } }'::bson)) Sort Key: (bson_orderby(collection.document, '{ "$meta" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiQueryScan) (cost=0.00..25000004.02 rows=1 width=64) (actual rows=0 loops=1) Output: document, bson_orderby(document, '{ "$meta" : { "$numberInt" : "1" } }'::bson) -> Bitmap Heap Scan on documentdb_data.documents_4232_423018 collection (cost=0.00..25000004.02 rows=1 width=32) (actual rows=0 loops=1) Output: document Filter: ((collection.document @= '{ "_id" : "2" }'::bson) AND (collection.object_id = '{ "" : "2" }'::bson) AND bson_text_meta_qual(collection.document, '''abc'''::tsquery, '\x0400000000000000ffffffff000000000000000001000000000000002800000000000000000000000000803f000000000000803f000000000000803f000000000000803f00000000'::bytea, true)) -> Bitmap Index Scan on my_txt (cost=0.00..0.00 rows=1 width=0) (actual rows=0 loops=1) Index Cond: (collection.document @#% '''abc'''::tsquery) (11 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "g": { "$nearSphere": { "$geometry": { "type" : "Point", "coordinates": [0, 0] } }} }, "sort": { "a": 1 } }'); ERROR: unable to find index for $geoNear query -- filters with and/nested and. EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "$and": [ { "_id": { "$gt": "1" } }, { "$and": [ {"_id": "2" }, {"_id": { "$gt": "0" } } ] } ] } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: ((collection.document @> '{ "_id" : "1" }'::bson) AND (collection.document @> '{ "_id" : "0" }'::bson)) (4 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": { "$gt": "1" }, "_id": "2", "_id": { "$gt": "0" } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=32) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: ((collection.document @> '{ "_id" : "1" }'::bson) AND (collection.document @> '{ "_id" : "0" }'::bson)) (4 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "$and": [ { "a": { "$gt": "1" } }, { "$and": [ {"_id": "2" }, {"a": { "$gt": "0" } } ] } ] } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=0 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: ((collection.document #> '{ "a" : "1" }'::bsonquery) AND ((collection.document #= '{ "_id" : "2" }'::bsonquery) AND (collection.document #> '{ "a" : "0" }'::bsonquery))) Rows Removed by Filter: 1 (5 rows) EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "a": { "$gt": "1" }, "_id": "2", "a": { "$gt": "0" } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=0 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: ((collection.document #> '{ "a" : "1" }'::bsonquery) AND (collection.document #> '{ "a" : "0" }'::bsonquery)) Rows Removed by Filter: 1 (5 rows) -- singleBatch EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": 1 }, "singleBatch": true }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=123123.00..1231230.00 rows=1 width=0) (actual rows=1 loops=1) Output: document Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) (3 rows) -- batchSize EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 2 } }, "sort": { "a": 1 }, "batchSize": 0 }'); QUERY PLAN --------------------------------------------------------------------- Sort (cost=0.01..0.02 rows=1 width=64) (actual rows=0 loops=1) Output: document, (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) Sort Key: (bson_orderby(collection.document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documentdb_data.documents_4232_423018 collection (cost=0.00..0.00 rows=1 width=64) (actual rows=0 loops=1) Output: document, bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson) Index Cond: ((collection.shard_key_value = '4232'::bigint) AND (collection.object_id = '{ "" : "2" }'::bson)) Filter: (collection.document @> '{ "_id" : { "$numberInt" : "2" } }'::bson) Rows Removed by Filter: 1 (9 rows) bson_aggregation_pipeline_tests_push_group.out000066400000000000000000000276611507310017400414320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1012000; SET documentdb.next_collection_id TO 10120; SET documentdb.next_collection_index_id TO 10120; SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 1, "product" : "beer", "pricingInfo" : { "msrp": 10, "retailPrice": 15 }, "stock" : 2, "year": 2020 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 2, "product" : "red wine", "pricingInfo" : { "msrp": 4, "retailPrice": 9 }, "stock" : 1, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 3, "product" : "bread", "pricingInfo" : { "msrp": 3, "retailPrice": 11 }, "stock" : 5 , "year": 2020}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 4, "product" : "whiskey", "pricingInfo" : { "msrp": 4, "retailPrice": 10 }, "stock" : 3 , "year": 2022}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 5, "product" : "bread", "pricingInfo" : { "msrp": 75, "retailPrice": 100 }, "stock" : 1, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* running multiple $push accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "wholesalePricing": { "$sum": ["$pricingInfo.msrp", 1] }, "qty": "$stock"} } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "11" }, "qty" : { "$numberInt" : "2" } }, { "wholesalePricing" : { "$numberInt" : "4" }, "qty" : { "$numberInt" : "5" } } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "5" }, "qty" : { "$numberInt" : "1" } }, { "wholesalePricing" : { "$numberInt" : "76" }, "qty" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2022" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "5" }, "qty" : { "$numberInt" : "3" } } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "retailPricing": { "$subtract": ["$pricingInfo.retailPrice", 1] }, "isBread": { "$in": ["$product", ["bread"]] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "items" : [ { "retailPricing" : { "$numberInt" : "14" }, "isBread" : false }, { "retailPricing" : { "$numberInt" : "10" }, "isBread" : true } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "retailPricing" : { "$numberInt" : "8" }, "isBread" : false }, { "retailPricing" : { "$numberInt" : "99" }, "isBread" : true } ] } { "_id" : { "$numberInt" : "2022" }, "items" : [ { "retailPricing" : { "$numberInt" : "9" }, "isBread" : false } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "shouldBeNull": { "$subtract": ["$invalidName", 12] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "items" : [ { "shouldBeNull" : null }, { "shouldBeNull" : null } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "shouldBeNull" : null }, { "shouldBeNull" : null } ] } { "_id" : { "$numberInt" : "2022" }, "items" : [ { "shouldBeNull" : null } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "combinedPrice": { "$add": ["$pricingInfo.msrp", "$pricingInfo.retailPrice"] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "items" : [ { "combinedPrice" : { "$numberInt" : "25" } }, { "combinedPrice" : { "$numberInt" : "14" } } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "combinedPrice" : { "$numberInt" : "13" } }, { "combinedPrice" : { "$numberInt" : "175" } } ] } { "_id" : { "$numberInt" : "2022" }, "items" : [ { "combinedPrice" : { "$numberInt" : "14" } } ] } (3 rows) /* shard collection */ SELECT documentdb_api.shard_collection('db', 'testGroupWithPush', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) /* run same $push queries to ensure consistency */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "wholesalePricing": { "$sum": ["$pricingInfo.msrp", 1] }, "qty": "$stock"} } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "5" }, "qty" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "5" }, "qty" : { "$numberInt" : "1" } }, { "wholesalePricing" : { "$numberInt" : "76" }, "qty" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2020" }, "items" : [ { "wholesalePricing" : { "$numberInt" : "4" }, "qty" : { "$numberInt" : "5" } }, { "wholesalePricing" : { "$numberInt" : "11" }, "qty" : { "$numberInt" : "2" } } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "retailPricing": { "$subtract": ["$pricingInfo.retailPrice", 1] }, "isBread": { "$in": ["$product", ["bread"]] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "items" : [ { "retailPricing" : { "$numberInt" : "9" }, "isBread" : false } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "retailPricing" : { "$numberInt" : "8" }, "isBread" : false }, { "retailPricing" : { "$numberInt" : "99" }, "isBread" : true } ] } { "_id" : { "$numberInt" : "2020" }, "items" : [ { "retailPricing" : { "$numberInt" : "10" }, "isBread" : true }, { "retailPricing" : { "$numberInt" : "14" }, "isBread" : false } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "shouldBeNull": { "$subtract": ["$invalidName", 12] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "items" : [ { "shouldBeNull" : null } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "shouldBeNull" : null }, { "shouldBeNull" : null } ] } { "_id" : { "$numberInt" : "2020" }, "items" : [ { "shouldBeNull" : null }, { "shouldBeNull" : null } ] } (3 rows) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "combinedPrice": { "$add": ["$pricingInfo.msrp", "$pricingInfo.retailPrice"] } } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "items" : [ { "combinedPrice" : { "$numberInt" : "14" } } ] } { "_id" : { "$numberInt" : "2021" }, "items" : [ { "combinedPrice" : { "$numberInt" : "13" } }, { "combinedPrice" : { "$numberInt" : "175" } } ] } { "_id" : { "$numberInt" : "2020" }, "items" : [ { "combinedPrice" : { "$numberInt" : "14" } }, { "combinedPrice" : { "$numberInt" : "25" } } ] } (3 rows) -- Test for missing values SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 7, "product" : "bread", "pricingInfo" : { "msrp": 75, "retailPrice": 100 }, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": { "qty": "$stock"} } } } ] }'); document --------------------------------------------------------------------- { "_id" : "bread", "items" : [ { "qty" : { "$numberInt" : "5" } }, { }, { "qty" : { "$numberInt" : "1" } } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": "$stock" } } } ] }'); document --------------------------------------------------------------------- { "_id" : "bread", "items" : [ { "$numberInt" : "5" }, { "$numberInt" : "1" } ] } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": ["$stock"] } } } ] }'); document --------------------------------------------------------------------- { "_id" : "bread", "items" : [ [ { "$numberInt" : "5" } ], [ null ], [ { "$numberInt" : "1" } ] ] } (1 row) bson_aggregation_pipeline_tests_redact.out000066400000000000000000001622141507310017400404730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5150000; SET documentdb.next_collection_id TO 51500; SET documentdb.next_collection_index_id TO 51500; /* Insert data, normal case*/ SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 2, "level": "restricted", "content": "content 2", "details": { "level": "public", "value": "content 2.1", "moreDetails": { "level": "restricted", "info": "content 2.1.1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 3, "level": "public", "content": "content 3", "details": { "level": "restricted", "value": "content 3.1", "moreDetails": { "level": "public", "info": "content 3.1.1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 4, "content": "content 4", "details": { "level": "public", "value": "content 4.1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 5, "level": "public", "content": "content 5", "details": { "level": "public", "value": "content 5.1", "moreDetails": [{ "level": "restricted", "info": "content 5.1.1" }, { "level": "public", "info": "content 5.1.2" }] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest1", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "public"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : "public", "content" : "content 1", "details" : { "level" : "public", "value" : "content 1.1", "moreDetails" : { "level" : "restricted", "info" : "content 1.1.1" } } } { "_id" : { "$numberInt" : "3" }, "level" : "public", "content" : "content 3", "details" : { "level" : "restricted", "value" : "content 3.1", "moreDetails" : { "level" : "public", "info" : "content 3.1.1" } } } { "_id" : { "$numberInt" : "5" }, "level" : "public", "content" : "content 5", "details" : { "level" : "public", "value" : "content 5.1", "moreDetails" : [ { "level" : "restricted", "info" : "content 5.1.1" }, { "level" : "public", "info" : "content 5.1.2" } ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest1", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "public"] }, "then": "$$DESCEND", "else": "$$PRUNE" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : "public", "content" : "content 1", "details" : { "level" : "public", "value" : "content 1.1" } } { "_id" : { "$numberInt" : "3" }, "level" : "public", "content" : "content 3" } { "_id" : { "$numberInt" : "5" }, "level" : "public", "content" : "content 5", "details" : { "level" : "public", "value" : "content 5.1", "moreDetails" : [ { "level" : "public", "info" : "content 5.1.2" } ] } } (5 rows) /* Insert data, add validation for array-nested subdocument, array of documents, array of arrays, empty document being returned, test DESCEND and PRUNE*/ SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 1, "level": 1, "a": { "level": 2, "b": { "level": 4, "c": { "level": 1, "d": 8 } } }, "e": 20 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 2, "level": 4, "a": { "level": 3, "b": [{ "level": 1, "e": 4 }] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 3, "level": 2, "a": { "b": { "level": 3, "n": 12 } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 4, "level": 3, "a": [{ "level": 5, "b": 20 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 5, "level": 3, "b": { "level": 3, "d": [ { "level": 1, "e": 4 }, { "level": 5, "g": 9 }, [{ "level": 1, "r": 11 }, 52, 42, 75, { "level": 5, "s": 3 }]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "20" } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "2" } }, "e" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "2" }, "a" : { } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "2" } }, "e" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "2" }, "a" : { "b" : { "level" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "12" } } } } { "_id" : { "$numberInt" : "4" }, "level" : { "$numberInt" : "3" }, "a" : [ ] } { "_id" : { "$numberInt" : "5" }, "level" : { "$numberInt" : "3" }, "b" : { "level" : { "$numberInt" : "3" }, "d" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } }, [ { "level" : { "$numberInt" : "1" }, "r" : { "$numberInt" : "11" } }, { "$numberInt" : "52" }, { "$numberInt" : "42" }, { "$numberInt" : "75" } ] ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 4]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "level" : { "$numberInt" : "4" }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "8" } } } }, "e" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "4" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } } ] } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "2" }, "a" : { "b" : { "level" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "12" } } } } { "_id" : { "$numberInt" : "4" }, "level" : { "$numberInt" : "3" }, "a" : [ ] } { "_id" : { "$numberInt" : "5" }, "level" : { "$numberInt" : "3" }, "b" : { "level" : { "$numberInt" : "3" }, "d" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } }, [ { "level" : { "$numberInt" : "1" }, "r" : { "$numberInt" : "11" } }, { "$numberInt" : "52" }, { "$numberInt" : "42" }, { "$numberInt" : "75" } ] ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 5]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "level" : { "$numberInt" : "4" }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "8" } } } }, "e" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "4" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } } ] } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "2" }, "a" : { "b" : { "level" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "12" } } } } { "_id" : { "$numberInt" : "4" }, "level" : { "$numberInt" : "3" }, "a" : [ { "level" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "20" } } ] } { "_id" : { "$numberInt" : "5" }, "level" : { "$numberInt" : "3" }, "b" : { "level" : { "$numberInt" : "3" }, "d" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } }, { "level" : { "$numberInt" : "5" }, "g" : { "$numberInt" : "9" } }, [ { "level" : { "$numberInt" : "1" }, "r" : { "$numberInt" : "11" } }, { "$numberInt" : "52" }, { "$numberInt" : "42" }, { "$numberInt" : "75" }, { "level" : { "$numberInt" : "5" }, "s" : { "$numberInt" : "3" } } ] ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 5]}, { "$literal" :"$$DESCEND"}, "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "level" : { "$numberInt" : "4" }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "8" } } } }, "e" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "4" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } } ] } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "2" }, "a" : { "b" : { "level" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "12" } } } } { "_id" : { "$numberInt" : "4" }, "level" : { "$numberInt" : "3" }, "a" : [ { "level" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "20" } } ] } { "_id" : { "$numberInt" : "5" }, "level" : { "$numberInt" : "3" }, "b" : { "level" : { "$numberInt" : "3" }, "d" : [ { "level" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "4" } }, { "level" : { "$numberInt" : "5" }, "g" : { "$numberInt" : "9" } }, [ { "level" : { "$numberInt" : "1" }, "r" : { "$numberInt" : "11" } }, { "$numberInt" : "52" }, { "$numberInt" : "42" }, { "$numberInt" : "75" }, { "level" : { "$numberInt" : "5" }, "s" : { "$numberInt" : "3" } } ] ] } } (5 rows) /* Insert data, test KEEP*/ SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 1, "level": 1, "a": { "level": 1, "b": 1 }, "c": { "level": 1, "d": 1 }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 2, "level": 2, "a": { "level": 2, "b": 2 }, "c": { "level": 2, "d": 2 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 3, "level": 3, "a": { "level": 3, "b": 3 }, "c": { "level": 3, "d": 3 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) /*test directly systemvariable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$PRUNE"}], "cursor": {} }'); document --------------------------------------------------------------------- (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$DESCEND"}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) /*switch case*/ SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 1, "title": "Document 1", "classification": "confidential", "content": "This is confidential content.", "metadata": { "author": "Alice", "revision": 3 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 2, "title": "Document 2", "classification": "public", "content": "This is public content.", "metadata": { "author": "Bob", "revision": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 3, "title": "Document 3", "classification": "restricted", "content": "This content is restricted.", "metadata": { "author": "Charlie", "revision": 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTestSwitch", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$classification", "confidential"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "restricted"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "title" : "Document 2", "classification" : "public", "content" : "This is public content.", "metadata" : { "author" : "Bob", "revision" : { "$numberInt" : "1" } } } (3 rows) /*$lookup $let and $redact example*/ SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 1, "name": "Alice"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 2, "name": "Bob"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 3, "name": "Charlie"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 1, "user_id": 1, "order_amount":150, "status": "completed"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 2, "user_id": 1, "order_amount":200, "status": "pending"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 3, "user_id": 2, "order_amount":500, "status": "completed"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 4, "user_id": 2, "order_amount":50, "status": "completed"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 5, "user_id": 3, "order_amount":300, "status": "pending"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* $redact with $let*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$$ROOT.order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "user_orders" : [ { "_id" : { "$numberInt" : "1" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "150" }, "status" : "completed" }, { "_id" : { "$numberInt" : "2" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "200" }, "status" : "pending" } ] } { "_id" : { "$numberInt" : "2" }, "name" : "Bob", "user_orders" : [ { "_id" : { "$numberInt" : "3" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "500" }, "status" : "completed" }, { "_id" : { "$numberInt" : "4" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "50" }, "status" : "completed" } ] } { "_id" : { "$numberInt" : "3" }, "name" : "Charlie", "user_orders" : [ { "_id" : { "$numberInt" : "5" }, "user_id" : { "$numberInt" : "3" }, "order_amount" : { "$numberInt" : "300" }, "status" : "pending" } ] } (3 rows) /* add $let with the same level with $lookup, different variable with $let in $redact*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id" }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "user_orders" : [ { "_id" : { "$numberInt" : "1" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "150" }, "status" : "completed" }, { "_id" : { "$numberInt" : "2" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "200" }, "status" : "pending" } ] } { "_id" : { "$numberInt" : "2" }, "name" : "Bob", "user_orders" : [ { "_id" : { "$numberInt" : "3" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "500" }, "status" : "completed" }, { "_id" : { "$numberInt" : "4" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "50" }, "status" : "completed" } ] } { "_id" : { "$numberInt" : "3" }, "name" : "Charlie", "user_orders" : [ { "_id" : { "$numberInt" : "5" }, "user_id" : { "$numberInt" : "3" }, "order_amount" : { "$numberInt" : "300" }, "status" : "pending" } ] } (3 rows) /* two level $let has the same variable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id", "totalAmount": { "$sum": "$user_orders.order_amount" } }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "user_orders" : [ { "_id" : { "$numberInt" : "1" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "150" }, "status" : "completed" }, { "_id" : { "$numberInt" : "2" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "200" }, "status" : "pending" } ] } { "_id" : { "$numberInt" : "2" }, "name" : "Bob", "user_orders" : [ { "_id" : { "$numberInt" : "3" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "500" }, "status" : "completed" }, { "_id" : { "$numberInt" : "4" }, "user_id" : { "$numberInt" : "2" }, "order_amount" : { "$numberInt" : "50" }, "status" : "completed" } ] } { "_id" : { "$numberInt" : "3" }, "name" : "Charlie", "user_orders" : [ { "_id" : { "$numberInt" : "5" }, "user_id" : { "$numberInt" : "3" }, "order_amount" : { "$numberInt" : "300" }, "status" : "pending" } ] } (3 rows) /* redact use top level $let*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id" }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$and": [ { "$gt": [ "$$totalAmount", 40 ] }, { "$lt": [ "$$user_id", 2 ] } ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "user_orders" : [ { "_id" : { "$numberInt" : "1" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "150" }, "status" : "completed" }, { "_id" : { "$numberInt" : "2" }, "user_id" : { "$numberInt" : "1" }, "order_amount" : { "$numberInt" : "200" }, "status" : "pending" } ] } { "_id" : { "$numberInt" : "2" }, "name" : "Bob", "user_orders" : [ ] } { "_id" : { "$numberInt" : "3" }, "name" : "Charlie", "user_orders" : [ ] } (3 rows) /*facet with redact test case user data*/ SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 1, "name": "Alice", "email": "alice@example.com", "age": 25 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 2, "name": "Bob", "email": "bob@example.com", "age": 25 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 3, "name": "Charlie", "email": "charlie@example.com", "age": 30 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /*facet with redact case, one is empty array and the other is not*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "facetUsers", "pipeline": [ { "$facet": { "ageGroup": [ { "$group": { "_id": "$age", "users": { "$push": "$name" } } } ], "redactEmail": [ { "$redact": { "$cond": { "if": { "$eq": ["$email", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "ageGroup" : [ { "_id" : { "$numberInt" : "30" }, "users" : [ "Charlie" ] }, { "_id" : { "$numberInt" : "25" }, "users" : [ "Alice", "Bob" ] } ], "redactEmail" : [ ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "facetUsers", "pipeline": [ { "$facet": { "ageGroup": [ { "$group": { "_id": "$age", "users": { "$push": "$name" } } } ], "redactEmail": [ { "$redact": { "$cond": { "if": { "$eq": ["$email", "alice@example.com"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "ageGroup" : [ { "_id" : { "$numberInt" : "30" }, "users" : [ "Charlie" ] }, { "_id" : { "$numberInt" : "25" }, "users" : [ "Alice", "Bob" ] } ], "redactEmail" : [ { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "email" : "alice@example.com", "age" : { "$numberInt" : "25" } } ] } (1 row) /*graphLookup with redact test case employee data*/ SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 1, "employee_id": 1, "name": "Alice", "manager_id": null, "email": "alice@example.com" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 2, "employee_id": 2, "name": "Bob", "manager_id": 1, "email": "bob@example.com" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 3, "employee_id": 3, "name": "Charlie", "manager_id": 1, "email": "charlie@example.com" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 4, "employee_id": 4, "name": "David", "manager_id": 2, "email": "david@example.com" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 5, "employee_id": 5, "name": "Eve", "manager_id": 2, "email": "eve@example.com" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /*graphLookup with redact test case, prune employee do not have subordinates*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "graphLookupEmployee", "pipeline": [ { "$graphLookup": { "from": "graphLookupEmployee", "startWith": "$employee_id", "connectFromField": "employee_id", "connectToField": "manager_id", "as": "subordinates" } }, { "$redact": { "$cond": { "if": { "$eq": [{ "$size": "$subordinates" }, 0] }, "then": "$$PRUNE", "else": "$$KEEP" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "employee_id" : { "$numberInt" : "1" }, "name" : "Alice", "manager_id" : null, "email" : "alice@example.com", "subordinates" : [ { "_id" : { "$numberInt" : "2" }, "employee_id" : { "$numberInt" : "2" }, "name" : "Bob", "manager_id" : { "$numberInt" : "1" }, "email" : "bob@example.com" }, { "_id" : { "$numberInt" : "3" }, "employee_id" : { "$numberInt" : "3" }, "name" : "Charlie", "manager_id" : { "$numberInt" : "1" }, "email" : "charlie@example.com" }, { "_id" : { "$numberInt" : "4" }, "employee_id" : { "$numberInt" : "4" }, "name" : "David", "manager_id" : { "$numberInt" : "2" }, "email" : "david@example.com" }, { "_id" : { "$numberInt" : "5" }, "employee_id" : { "$numberInt" : "5" }, "name" : "Eve", "manager_id" : { "$numberInt" : "2" }, "email" : "eve@example.com" } ] } { "_id" : { "$numberInt" : "2" }, "employee_id" : { "$numberInt" : "2" }, "name" : "Bob", "manager_id" : { "$numberInt" : "1" }, "email" : "bob@example.com", "subordinates" : [ { "_id" : { "$numberInt" : "4" }, "employee_id" : { "$numberInt" : "4" }, "name" : "David", "manager_id" : { "$numberInt" : "2" }, "email" : "david@example.com" }, { "_id" : { "$numberInt" : "5" }, "employee_id" : { "$numberInt" : "5" }, "name" : "Eve", "manager_id" : { "$numberInt" : "2" }, "email" : "eve@example.com" } ] } (5 rows) /*unionWith with redact test case user and employee data*/ SELECT documentdb_api.insert_one('db', 'unionWithUsers', '{ "_id": 1, "name": "Alice", "role": "admin", "address": { "city": "New York", "zip": "10001" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'unionWithUsers', '{ "_id": 2, "name": "Bob", "role": "user", "address": { "city": "Los Angeles", "zip": "90001" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'unionWithEmployees', '{ "_id": 101, "name": "Charlie", "role": "admin", "department": "HR", "address": { "city": "San Francisco", "zip": "94101" } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'unionWithEmployees', '{ "_id": 102, "name": "David", "role": "user", "department": "IT", "address": { "city": "Chicago", "zip": "60601" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "unionWithUsers", "pipeline": [ { "$unionWith": { "coll": "unionWithEmployees", "pipeline": [ { "$redact": { "$cond": { "if": { "$gt": ["$_id", 101] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Alice", "role" : "admin", "address" : { "city" : "New York", "zip" : "10001" } } { "_id" : { "$numberInt" : "2" }, "name" : "Bob", "role" : "user", "address" : { "city" : "Los Angeles", "zip" : "90001" } } { "_id" : { "$numberInt" : "102" }, "name" : "David", "role" : "user", "department" : "IT", "address" : { "city" : "Chicago", "zip" : "60601" } } (4 rows) /*negative case*/ /*redact input as number*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": 1 }], "cursor": {} }'); ERROR: $redact's parameter must be an expression or string valued as $$KEEP, $$DESCEND, and $$PRUNE, but input as '1'. /*redact input as string*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "string" }], "cursor": {} }'); ERROR: The $redact stage must evaluate to one of the variables $$KEEP, $$DESCEND, or $$PRUNE, but instead it produced '"string"'. /*redact input as boolean*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": true }], "cursor": {} }'); ERROR: $redact's parameter must be an expression or string valued as $$KEEP, $$DESCEND, and $$PRUNE, but input as 'true'. /*redact input system variable not KEEP or PRUNE or DESCEND*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$NOTVALID"}], "cursor": {} }'); ERROR: Attempting to use an undefined variable: NOTVALID /*redact input as array*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": ["$$KEEP", "$$PRUNE"]} ], "cursor": {} }'); ERROR: $redact's parameter must be an expression or string valued as $$KEEP, $$DESCEND, and $$PRUNE, but input as '[ "$$KEEP", "$$PRUNE" ]'. /*redact input cond return not KEEP or PRUNE or DESCEND*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$NOTVALID"} } } ], "cursor": {} }'); ERROR: Attempting to use an undefined variable: NOTVALID /*throw exception when $$KEEP $$PRUEN $$DESCEND are used in other stages*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"filteredField" : "$$PRUNE"} } ], "cursor": {} }'); ERROR: Reference to variable PRUNE is not defined SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"newField" : "$$DESCEND"} } ], "cursor": {} }'); ERROR: Usage of an undefined variable detected: DESCEND SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"newField" :{ "$add":["$$KEEP",1]} } } ], "cursor": {} }'); ERROR: Reference to variable KEEP is not defined SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$addFields": {"newField" : "$$DESCEND"} } ], "cursor": {} }'); ERROR: Usage of an undefined variable detected: DESCEND /*EXPLAIN*/ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_redact(document, '{ }'::documentdb_core.bson, '$$KEEP'::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_51502_5150036 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '51502'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_51502_5150036 collection Output: documentdb_api_internal.bson_dollar_redact(document, '{ }'::documentdb_core.bson, '$$KEEP'::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '51502'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '51502'::bigint) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$PRUNE"} } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_redact(document, '{ "$cond" : { "if" : { "$eq" : [ "$level", { "$numberInt" : "1" } ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } }'::documentdb_core.bson, ''::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_51502_5150036 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '51502'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_51502_5150036 collection Output: documentdb_api_internal.bson_dollar_redact(document, '{ "$cond" : { "if" : { "$eq" : [ "$level", { "$numberInt" : "1" } ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } }'::documentdb_core.bson, ''::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Recheck Cond: (collection.shard_key_value = '51502'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '51502'::bigint) (12 rows) /*sharded collection*/ SELECT shard_collection('db', 'redactTest3', '{ "amount": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) /*positive cases:*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) /*test directly systemvariable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$PRUNE"}], "cursor": {} }'); document --------------------------------------------------------------------- (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$DESCEND"}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : { "$numberInt" : "1" }, "a" : { "level" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "c" : { "level" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "level" : { "$numberInt" : "2" }, "a" : { "level" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, "c" : { "level" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "level" : { "$numberInt" : "3" }, "a" : { "level" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } }, "c" : { "level" : { "$numberInt" : "3" }, "d" : { "$numberInt" : "3" } } } (3 rows) /*EXPLAIN*/ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_internal.bson_dollar_redact(document, '{ }'::documentdb_core.bson, '$$KEEP'::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_51502_5150160 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_51502_5150160 collection Output: documentdb_api_internal.bson_dollar_redact(document, '{ }'::documentdb_core.bson, '$$KEEP'::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) (9 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$PRUNE"} } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT documentdb_api_internal.bson_dollar_redact(document, '{ "$cond" : { "if" : { "$eq" : [ "$level", { "$numberInt" : "1" } ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } }'::documentdb_core.bson, ''::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM documentdb_data.documents_51502_5150160 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_51502_5150160 collection Output: documentdb_api_internal.bson_dollar_redact(document, '{ "$cond" : { "if" : { "$eq" : [ "$level", { "$numberInt" : "1" } ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } }'::documentdb_core.bson, ''::text, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) (9 rows) bson_aggregation_pipeline_tests_stddevpopsamp_group.out000066400000000000000000001022341507310017400433320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1015000; SET documentdb.next_collection_id TO 10150; SET documentdb.next_collection_index_id TO 10150; SELECT documentdb_api.insert_one('db','tests',' { "_id" : 1, "group": 1, "num" : 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','tests',' { "_id" : 2, "group": 1, "num" : 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','tests',' { "_id" : 3, "group": 1, "num" : 13 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','tests',' { "_id" : 4, "group": 1, "num" : 16 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "4.7434164902525690621" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "5.4772255750516611883" } } (1 row) /* empty collection */ SELECT documentdb_api.insert_one('db','empty_col',' {"num": {} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_col", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_col", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /*single number value in collection*/ SELECT documentdb_api.insert_one('db','single_num',' {"num": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /*two number values in collection*/ SELECT documentdb_api.insert_one('db','two_nums',' {"num": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','two_nums',' {"num": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "two_nums", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "two_nums", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) /*single char value in collection*/ SELECT documentdb_api.insert_one('db','single_char',' {"num": "a" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /*single number and single char in collection*/ SELECT documentdb_api.insert_one('db','single_num_char',' {"num": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','single_num_char',' {"num": "a" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /*number and char mixed in collection*/ SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": "a" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_char_mixed", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_char_mixed", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "0.0" } } (1 row) /*string in collection*/ SELECT documentdb_api.insert_one('db','num_string',' {"num": "string1" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_string',' {"num": "string2" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_string',' {"num": "strign3" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_string", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_string", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /*large number values in collection*/ SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000016"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "4.7434164902525690621" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "5.4772255750516611883" } } (1 row) /*double in collection*/ SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "4.0"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "7.0"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "13.0"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "16.0"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "double", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "4.7434164902525690621" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "double", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "5.4772255750516611883" } } (1 row) /*numberDecimal in collection*/ SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "4"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "7"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "13"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "16"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_decimal", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "4.7434164902525690621" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_decimal", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "5.4772255750516611883" } } (1 row) /*NaN and Infinity*/ SELECT documentdb_api.insert_one('db', 'single_nan',' {"num": {"$numberDecimal": "NaN" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT documentdb_api.insert_one('db', 'nans',' {"num": {"$numberDecimal": "NaN" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nans',' {"num": {"$numberDecimal": "-NaN"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nans", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nans", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 13 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : {"$numberDecimal": "NaN" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 16 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT documentdb_api.insert_one('db', 'single_infinity',' {"num": {"$numberDecimal": "Infinity"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_infinity", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_infinity", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT documentdb_api.insert_one('db', 'infinities',' {"num": { "$numberDecimal": "Infinity" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'infinities',' {"num": { "$numberDecimal": "-Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "infinities", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "infinities", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 7 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 13 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : { "$numberDecimal": "Infinity" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 16 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_inf", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_inf", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "NaN" } } (1 row) /*number overflow*/ SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "100000004"} }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "10000000007"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "1000000000000013"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "1000000000000000000"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_overflow", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "432868555379387136.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_overflow", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "499833553944027136.0" } } (1 row) /*array test*/ SELECT documentdb_api.insert_one('db','num_array',' { "num" : [4, 7, 13, 16] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_array", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_array", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : null } (1 row) /* shard collection */ SELECT documentdb_api.shard_collection('db', 'tests', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "4.7434164902525690621" } } (1 row) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": "$num" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "stdDev" : { "$numberDouble" : "5.4772255750516611883" } } (1 row) /* nagetive tests */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": ["$num"] } } } ] }'); ERROR: The $stdDevPop accumulator functions as a single-operand operator SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": ["$num"] } } } ] }'); ERROR: The $stdDevSamp accumulator functions as a single-operand operator bson_aggregation_pipeline_tests_top_bottom_group.out000066400000000000000000000644151507310017400426370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 10120000; SET documentdb.next_collection_id TO 101200; SET documentdb.next_collection_index_id TO 101200; SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Alpha", "team": "T1", "points": 10 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Beta", "team": "T1", "points": 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Gamma", "team": "T1", "points": 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Delta", "team": "T1", "points": 20 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Epsilon", "team": "T1"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Zeta", "team": "T1", "points": [3, 2] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Alpha", "team": "T2", "points": {"$undefined":true} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Beta", "team": "T2", "points": 15 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Gamma", "team": "T2", "points": 18 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Delta", "team": "T2", "points": 8 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Negative tests */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ]}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"sortBy": { "points": 1 }}}}} ] }'); -- missing output ERROR: The 'output' parameter is missing a required value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"sortBy": { "points": 1 }, "n": 1}}}} ] }'); -- n isn't supported with $top ERROR: Unrecognized argument provided to $top 'n' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ]}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"sortBy": { "points": 1 }}}}} ] }'); -- missing output ERROR: The 'output' parameter is missing a required value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"sortBy": { "points": 1 }, "n": 1}}}} ] }'); -- n isn't supported with $top ERROR: Unrecognized argument provided to $bottom 'n' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "n": 1}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"sortBy": {"points": 1}, "n": 1}}}} ] }'); -- missing output ERROR: The 'output' parameter is missing a required value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); -- missing n ERROR: Required value for 'n' is not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": "a"}}}} ] }'); -- n is not a number ERROR: Expected 'integer' type for 'n' but found 'string' for value '"a"' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$undefined": true}}}}} ] }'); -- n is not a number ERROR: Expected 'integer' type for 'n' but found 'undefined' for value '{ "$undefined" : true }' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$numberDecimal": "Infinity"}}}}} ] }'); -- n is not a number ERROR: Unable to convert out-of-range value Infinity into a long type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": -1}}}} ] }'); -- n is negative ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 0.5}}}} ] }'); -- n is not an integer ERROR: Expected 'integer' type for 'n' but found 'double' for value '0.5' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "n": 1}}}} ] }'); -- missing sortBy ERROR: No value provided for 'sortBy' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"sortBy": {"points": 1}, "n": 1}}}} ] }'); -- missing output ERROR: The 'output' parameter is missing a required value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); -- missing n ERROR: Required value for 'n' is not provided SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": "a"}}}} ] }'); -- n is not a number ERROR: Expected 'integer' type for 'n' but found 'string' for value '"a"' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$undefined": true}}}}} ] }'); -- n is not a number ERROR: Expected 'integer' type for 'n' but found 'undefined' for value '{ "$undefined" : true }' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$numberDecimal": "Infinity"}}}}} ] }'); -- n is not a number ERROR: Unable to convert out-of-range value Infinity into a long type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": -1}}}} ] }'); -- n is negative ERROR: The value of 'n' must be strictly greater than 0, but the current value is -1 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 0.5}}}} ] }'); -- n is not an integer ERROR: Expected 'integer' type for 'n' but found 'double' for value '0.5' SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": 1, "n": 1}}}} ] }'); -- sortBy is not an object ERROR: Expected 'sortBy' parameter to already contain an object within the provided arguments to $bottomN /* $top operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } { "_id" : "T2", "user" : [ "Alpha", null ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } { "_id" : "T2", "user" : [ "Gamma", { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$sort": {"user": 1}}, {"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); -- different sort in sortBy stage but documents in output field are sorted by $top spec document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } { "_id" : "T2", "user" : [ "Gamma", { "$numberInt" : "18" } ] } (2 rows) /* $topN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Epsilon", null ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Beta", { "$numberInt" : "5" } ] ] } { "_id" : "T2", "user" : [ [ "Alpha", null ], [ "Delta", { "$numberInt" : "8" } ], [ "Beta", { "$numberInt" : "15" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Delta", { "$numberInt" : "20" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Gamma", { "$numberInt" : "7" } ] ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Delta", { "$numberInt" : "20" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Gamma", { "$numberInt" : "7" } ] ] } { "_id" : "T2", "user" : [ [ "Gamma", { "$numberInt" : "18" } ], [ "Beta", { "$numberInt" : "15" } ], [ "Delta", { "$numberInt" : "8" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$sort": {"user": 1}}, {"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); -- different sort in sortBy stage but documents in output field are sorted by $top spec document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Delta", { "$numberInt" : "20" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Gamma", { "$numberInt" : "7" } ] ] } { "_id" : "T2", "user" : [ [ "Gamma", { "$numberInt" : "18" } ], [ "Beta", { "$numberInt" : "15" } ], [ "Delta", { "$numberInt" : "8" } ] ] } (2 rows) /* $bottom operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } { "_id" : "T2", "user" : [ "Gamma", { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } { "_id" : "T2", "user" : [ "Alpha", null ] } (2 rows) /* $bottomN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Gamma", { "$numberInt" : "7" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Delta", { "$numberInt" : "20" } ] ] } { "_id" : "T2", "user" : [ [ "Delta", { "$numberInt" : "8" } ], [ "Beta", { "$numberInt" : "15" } ], [ "Gamma", { "$numberInt" : "18" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Beta", { "$numberInt" : "5" } ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Epsilon", null ] ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Beta", { "$numberInt" : "5" } ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Epsilon", null ] ] } { "_id" : "T2", "user" : [ [ "Beta", { "$numberInt" : "15" } ], [ "Delta", { "$numberInt" : "8" } ], [ "Alpha", null ] ] } (2 rows) /* shard collection */ SELECT documentdb_api.shard_collection('db', 'pipeline_group_tests', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) /* run same queries to ensure consistency */ /* $top operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } { "_id" : "T2", "user" : [ "Alpha", null ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } { "_id" : "T2", "user" : [ "Gamma", { "$numberInt" : "18" } ] } (2 rows) /* $topN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Epsilon", null ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Beta", { "$numberInt" : "5" } ] ] } { "_id" : "T2", "user" : [ [ "Alpha", null ], [ "Delta", { "$numberInt" : "8" } ], [ "Beta", { "$numberInt" : "15" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Delta", { "$numberInt" : "20" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Gamma", { "$numberInt" : "7" } ] ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Delta", { "$numberInt" : "20" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Gamma", { "$numberInt" : "7" } ] ] } { "_id" : "T2", "user" : [ [ "Gamma", { "$numberInt" : "18" } ], [ "Beta", { "$numberInt" : "15" } ], [ "Delta", { "$numberInt" : "8" } ] ] } (2 rows) /* $bottom operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Delta", { "$numberInt" : "20" } ] } { "_id" : "T2", "user" : [ "Gamma", { "$numberInt" : "18" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ "Epsilon", null ] } { "_id" : "T2", "user" : [ "Alpha", null ] } (2 rows) /* $bottomN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Gamma", { "$numberInt" : "7" } ], [ "Alpha", { "$numberInt" : "10" } ], [ "Delta", { "$numberInt" : "20" } ] ] } { "_id" : "T2", "user" : [ [ "Delta", { "$numberInt" : "8" } ], [ "Beta", { "$numberInt" : "15" } ], [ "Gamma", { "$numberInt" : "18" } ] ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Beta", { "$numberInt" : "5" } ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Epsilon", null ] ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); document --------------------------------------------------------------------- { "_id" : "T1", "user" : [ [ "Beta", { "$numberInt" : "5" } ], [ "Zeta", [ { "$numberInt" : "3" }, { "$numberInt" : "2" } ] ], [ "Epsilon", null ] ] } { "_id" : "T2", "user" : [ [ "Beta", { "$numberInt" : "15" } ], [ "Delta", { "$numberInt" : "8" } ], [ "Alpha", null ] ] } (2 rows) bson_aggregation_pipeline_tests_vector_hnsw.out000066400000000000000000022673541507310017400416070ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- init a test user and set vector pre-filtering on SELECT current_user as original_test_user \gset CREATE ROLE test_filter_user_hnsw WITH LOGIN INHERIT SUPERUSER CREATEDB CREATEROLE IN ROLE :original_test_user; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8200000; SET documentdb.next_collection_id TO 8200; SET documentdb.next_collection_index_id TO 8200; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents(collectionName text, beginId integer, numDocuments integer, docPerBatch integer, numDimensions integer DEFAULT 3) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN if numDimensions < 3 then RAISE EXCEPTION 'Number of dimensions must be greater than or equal to 3'; end if; RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS ( SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), rv AS (SELECT counter, CASE WHEN numDimensions > 3 THEN array_to_string(array_agg(random()), ',') ELSE '' END AS vect FROM r1 LEFT JOIN generate_series(1, GREATEST(numDimensions-3, 0)) ON true GROUP BY counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || CASE WHEN numDimensions > 3 THEN ', ' || vect ELSE '' END || ' ] }') AS documentValue FROM rv order by counter), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------- -- HNSW -- HNSW create index, error cases SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector'); drop_primary_key --------------------------------------------------------------------- (1 row) ANALYZE; -- by default, HNSW index is enabled SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "unknown", "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "unknown", "similarity" : "IP", "dimensions" : 3 } }:Invalid search index kind unknown SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": -4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : -4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } }:m must be greater than or equal to 2, but was -4 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 101, "efConstruction": 160, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 101, "efConstruction" : 160, "similarity" : "IP", "dimensions" : 3 } }:m should not exceed 100, but received 101 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": -16, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : -16, "similarity" : "COS", "dimensions" : 3 } }:efConstruction must be greater than or equal to 4, but was -16 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 40, "efConstruction": 1001, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 40, "efConstruction" : 1001, "similarity" : "COS", "dimensions" : 3 } }:efConstruction should not exceed 1000, but received 1001 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": "40", "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : "40", "efConstruction" : 16, "similarity" : "L2", "dimensions" : 3 } }:m must be a number not string SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 40, "efConstruction": "16", "similarity": "L2", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 40, "efConstruction" : "16", "similarity" : "L2", "dimensions" : 3 } }:efConstruction must be a number not string SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "unknown", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "unknown", "dimensions" : 3 } }:Invalid search index distance kind unknown -- efConstruction is less than 2*m SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 4, "similarity" : "IP", "dimensions" : 3 } }:efConstruction must be greater than or equal to 2 * m for vector-hnsw indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 64, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 64, "similarity" : "COS", "dimensions" : 3 } }:efConstruction must be greater than or equal to 2 * m for vector-hnsw indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "efConstruction": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "efConstruction" : 4, "similarity" : "COS", "dimensions" : 3 } }:efConstruction must be greater than or equal to 2 * m for vector-hnsw indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "unknown", "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "unknown", "similarity" : "IP", "dimensions" : 3 } }:Invalid search index kind unknown -- check dimensions exceeds 2000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 2001 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "similarity" : "COS", "dimensions" : 2001 } }:field cannot have more than 2000 dimensions for vector index SET documentdb.enableVectorHNSWIndex = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": -4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : -4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } }:hnsw index is not supported for this cluster tier SET documentdb.enableVectorHNSWIndex = on; -- HNSW create index, success cases SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "efConstruction": 32, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- HNSW search, success cases CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } (1 row) COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "48.59999847412109375" } } } { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "34.59999847412109375" } } } (2 rows) COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 2 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) COMMIT; BEGIN; SET LOCAL enable_seqscan = off; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8200_8200003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8200'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 16 } -> Index Scan using foo_1 on documentdb_data.documents_8200_8200003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 2 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "2" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8200_8200003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8200'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "2" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 2 } -> Index Scan using foo_1 on documentdb_data.documents_8200_8200003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "2" } }'::documentdb_core.bson) (18 rows) ROLLBACK; -- HNSW search, error cases SET documentdb.enableVectorHNSWIndex = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10000000 } } } ], "cursor": {} }'); ERROR: HNSW index type is currently unsupported DETAIL: hnsw index configuration is not enabled. Set ApiGucPrefix.enableVectorHNSWIndex to true to enable hnsw index. SET documentdb.enableVectorHNSWIndex = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10000000 } } } ], "cursor": {} }'); ERROR: $efSearch must be less than or equal to 1000. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": -5 } } } ], "cursor": {} }'); ERROR: The parameter $efSearch should have a value that is greater than or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": "5" } } } ], "cursor": {} }'); ERROR: $efSearch must be an integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5.5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 0 } } } ], "cursor": {} }'); ERROR: The parameter $efSearch should have a value that is greater than or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); ERROR: $vector is required field for using a vector index. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": -1, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); ERROR: The $k should always be a positive integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": "1", "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); ERROR: The parameter $k should always hold a valid integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 0, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); ERROR: The $k should always be a positive integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); ERROR: $k is required field for using a vector index. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1 } } } ], "cursor": {} }'); ERROR: $path is required field for using a vector index. -- check dimension of query vector exceeds 2000 DO $$ DECLARE dim_num integer := 2001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 2001 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement DO $$ DECLARE dim_num integer := 2000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 2000 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.1, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.8, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) -- efSearch = 1, get 1 document BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "5" }, "path" : "v", "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8200_8200003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8200'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "5" }, "path" : "v", "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 1 } -> Index Scan using foo_1 on documentdb_data.documents_8200_8200003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson) (18 rows) COMMIT; -- efSearch = 3, get 3 documents BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 3 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "5" }, "path" : "v", "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8200_8200003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8200'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "5" }, "path" : "v", "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 3 } -> Index Scan using foo_1 on documentdb_data.documents_8200_8200003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson) (18 rows) COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) --------------------------------------------------------------------- -- turn on vector pre-filtering, check dynamic efSearch select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 1, 150, 2000); NOTICE: Inserting 150 documents into aggregation_pipeline_hnsw_efsearch NOTICE: Begin id: 1, Batch size: 2000, batch count: 1 NOTICE: creating collection batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_efsearch", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_efsearch'); drop_primary_key --------------------------------------------------------------------- (1 row) ANALYZE; -- 150 less than 10000 documents, use efConstruction as efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 16 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- check efSeache with score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "1372662.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "1522564.0" } } { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "1676962.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "1834721.0" } } { "_id" : { "$numberInt" : "5" }, "rank" : { "$numberDouble" : "1995044.0" } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 16 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- generate 1000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 151, 1000, 2000); NOTICE: Inserting 1000 documents into aggregation_pipeline_hnsw_efsearch NOTICE: Begin id: 151, Batch size: 2000, batch count: 1 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 16 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 40 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- more than 10000 and less than 1M documents, use default efSearch 40 -- generate 9000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 1151, 9000, 2000); NOTICE: Inserting 9000 documents into aggregation_pipeline_hnsw_efsearch NOTICE: Begin id: 1151, Batch size: 2000, batch count: 5 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 40 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8201_8200016 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8201'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 40 } -> Index Scan using foo_1 on documentdb_data.documents_8201_8200016 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw search with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_filter'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SET documentdb.enableVectorPreFilter = on; -- filter without index SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a.b' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a.b' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); ERROR: $filter must be a document value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; --------------------------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'unknownPath' was not found, please check whether the index is created. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.c' was not found, please check whether the index is created. --------------------------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) -- check the vector index is forced to be used ALTER ROLE test_filter_user_hnsw SET documentdb.enableVectorPreFilter = "True"; SELECT current_setting('citus' || '.next_shard_id') as vector_citus__next_shard_id \gset SELECT current_setting('documentdb' || '.next_collection_id') as vector__next_collection_id \gset SELECT current_setting('documentdb' || '.next_collection_index_id') as vector__next_collection_index_id \gset \c - test_filter_user_hnsw SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) -- default efSearch = efConstruction(16) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) \c - :original_test_user SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT set_config('citus' || '.next_shard_id', '' || :vector_citus__next_shard_id, FALSE); set_config --------------------------------------------------------------------- 8200048 (1 row) SELECT set_config('documentdb' || '.next_collection_id', '' || :vector__next_collection_id, FALSE); set_config --------------------------------------------------------------------- 8203 (1 row) SELECT set_config('documentdb' || '.next_collection_index_id', '' || :vector__next_collection_index_id, FALSE); set_config --------------------------------------------------------------------- 8217 (1 row) --------------------------------------------------------------------- -- hnsw search: pre-filtering match with different indexes -- "filter": {"meta.a": [ { "b" : 3 } ]}, match with idx_meta.a BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- "filter": {"meta": { "a" : [ { "b" : 3 } ] }, match with documentIndex_meta BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "documentIndex_meta" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- "filter": {"meta.a.b": 3 }, match with idx_meta.a.b BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bson) (29 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw filter string: default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter string: with $and, efSearch = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter string: with $and, efSearch = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter string: with $or, efSearch = 3, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (34 rows) ROLLBACK; -- hnsw filter string: with $or, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (34 rows) ROLLBACK; -- hnsw filter string: with $or, $and, efSearch = 10, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "efSearch": 10 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "efSearch": 10 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "efSearch" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "efSearch" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "10" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "efSearch" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) OR (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "meta.a" : { "b" : { "$numberInt" : "3" } } }'::documentdb_api_internal.bsonindexbounds, '{ "meta.a" : { "b" : { "$numberInt" : "5" } } }'::documentdb_api_internal.bsonindexbounds])))) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '10'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 10, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "10" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson)) Filter: (((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) OR (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson) (35 rows) ROLLBACK; -- hnsw filter string:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw filter number, with default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter number, with $and, efSearch = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (34 rows) ROLLBACK; -- hnsw filter number, with $and, default efSearch, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (29 rows) ROLLBACK; -- hnsw filter number, with $or, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (34 rows) ROLLBACK; -- hnsw filter number, with $or, default efSearch, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter number: with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$eq": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lte": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$ne": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$in": [ 2,3 ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$nin": [ 2 ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gt": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lt": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw filter boolean: with default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : true }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 16, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : true }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter boolean, with efSearch = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : true }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : true }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter boolean, with c = false, efSearch = 1, match 2 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw filter boolean, with c = false, efSearch = 3, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: filter boolean, with $eq, $ne, $in, $nin, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$eq": true}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$ne": true}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$in": [true]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$nin": [true]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (4 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw search: with filter, different distance metric -- hnsw search: cosine similarity CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index_cos", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "99986.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "88331.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (documentdb_api_catalog.bson_dollar_regex(collection.document, '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index_cos on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@~) '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: inner product CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index_cos"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index_ip", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "4860000.0" } } { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (documentdb_api_catalog.bson_dollar_regex(collection.document, '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector))), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index_ip on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@~) '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: restore to euclidean distance CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index_ip"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; --------------------------------------------------------------------- -- hnsw search: with filter and score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: with filter and score projection, efSearch = 4, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "4" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "efSearch" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "4" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "documentIndex_meta" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: with filter and score projection, efSearch = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: with filter and score projection, $ne, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "rank" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (3 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE (documentdb_api_catalog.bson_dollar_ne(collection.document, '{ "meta.a" : "some sentence" }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "rank" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#>=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8202_8200036 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8202'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8202_8200036 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8202_8200036 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- hnsw search: with filter and score projection, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "rank" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (3 rows) ROLLBACK; --------------------------------------------------------------------- -- hnsw search: with filter and shard -- TODO, current implementation does not support sharded collection, need to fix in part 3 BEGIN; SET LOCAL client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_hnsw_filter', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) END; ANALYZE; -- hnsw search: with filter and shard, default efSearch, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- hnsw search: with filter and shard, $ne, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- hnsw search: with filter and shard, number, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- hnsw search: with filter and shard, boolean, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- hnsw search: with filter and shard, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; SET documentdb.enableVectorPreFilter = off; --------------------------------------------------------------------- -- create hnsw index and search with nProbes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5, "efSearch": 10 } } } ], "cursor": {} }'); ERROR: Only one search option can be specified. You have specified options efSearch already, and the second option efSearch is not allowed. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 5, "efSearch": 10 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) -- create ivf index and search with efSearch SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10, "nProbes": 5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10, "nProbes": 5 } } } ], "cursor": {} }'); ERROR: Only one search option can be specified. You have specified options nProbes already, and the second option nProbes is not allowed. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) -- create ivf index and search with efSearch, hnsw index is disabled SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) select documentdb_api.drop_collection('db', 'aggregation_pipeline_vector'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Vector search with empty vector field -- hnsw SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_empty_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "vectorIndex", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 3, "a": "some sentence" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 4, "a": "some other sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_empty_vector'); drop_primary_key --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 16 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "62863.0" } } (3 rows) EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> Limit -> Custom Scan (DocumentDBApiQueryScan) CosmosSearch Custom Params: { "efSearch" : 5 } -> Index Scan using "vectorIndex" on documents_8203_8200061 collection Order By: (vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(document, '{ "efSearch" : { "$numberInt" : "5" } }'::documentdb_core.bson) (12 rows) COMMIT; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 16 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "62863.0" } } (3 rows) EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> Limit -> Custom Scan (DocumentDBApiQueryScan) CosmosSearch Custom Params: { "efSearch" : 5 } -> Index Scan using "vectorIndex" on documents_8203_8200061 collection Order By: (vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(document, '{ "efSearch" : { "$numberInt" : "5" } }'::documentdb_core.bson) (12 rows) COMMIT; SELECT drop_collection('db','aggregation_pipeline_empty_vector'); drop_collection --------------------------------------------------------------------- t (1 row) DROP ROLE IF EXISTS test_filter_user_hnsw; --------------------------------------------------------------------- -- exact search SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector_hnsw_exact'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": {} } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": 123 } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": "abc" } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": [1,2,3] } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. -- COS BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) public.cosine_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.cosine_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - cosine_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))) -> Limit Output: collection.document, (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8204_8200073 collection Output: collection.document, cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- IP CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_hnsw_exact", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "6" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] }, "c" : false, "v" : [ { "$numberDouble" : "15.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "69.59999847412109375" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "63.59999847412109375" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8204_8200073 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- L2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_hnsw_exact", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "6" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8204_8200073 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- efSearch BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) ROLLBACK; -- exact = false BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": false } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": false } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) ROLLBACK; -- filter:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "200000.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "700000.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$in" : [ "some sentence", "other sentence" ] } }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE ((documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.a" : [ "some sentence", "other sentence" ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "meta.a" : "some sentence" }'::documentdb_api_internal.bsonindexbounds, '{ "meta.a" : "other sentence" }'::documentdb_api_internal.bsonindexbounds]))) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$in" : [ "some sentence", "other sentence" ] } }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8204_8200073 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ "some sentence", "other sentence" ] }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "eq" : "other sentence" } }, { "meta.b" : { "$lt" : { "$numberInt" : "10" } } } ] }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : { "eq" : "other sentence" } }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "eq" : "other sentence" } }, { "meta.b" : { "$lt" : { "$numberInt" : "10" } } } ] }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8204_8200073 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "10" } }'::documentdb_core.bson) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : { "eq" : "other sentence" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) (18 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "1" } } } ] }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8204_8200073 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery)) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8204'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "1" } } } ] }, "exact" : true, "efSearch" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Bitmap Heap Scan on documentdb_data.documents_8204_8200073 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) ROLLBACK; -- shard SELECT documentdb_api.shard_collection('db','aggregation_pipeline_vector_hnsw_exact', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 343_1 -> Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::public.vector) AS "?sort?" FROM documentdb_data.documents_8204_8200088 collection WHERE (documentdb_api_internal.bson_extract_vector(document, 'v'::text) IS NOT NULL) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::public.vector)) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8204_8200088 collection Output: document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('343_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_document_add_score_field(intermediate_result.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(intermediate_result.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Function Call: read_intermediate_result('343_1'::text, 'binary'::citus_copy_format) (31 rows) COMMIT; -- shard is not supported with filter yet BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; SELECT drop_collection('db','aggregation_pipeline_vector_hnsw_exact'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Half vector -- hnsw SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_halfvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- error cases, create index SET documentdb.enableVectorCompressionHalf = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "half" } }:Compression type 'half' is not enabled. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "none" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "none" } }:Invalid compression type of vector index: none SET documentdb.enableVectorCompressionHalf = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": "binary" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : "binary" } }:Invalid compression type of vector index: binary SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": "scalar" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : "scalar" } }:Invalid compression type of vector index: scalar SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": 123 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : 123 } }:compression must be a string not int SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": {} } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : { } } }:compression must be a string not object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": ["half"] } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : [ "half" ] } }:compression must be a string not array SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2001 } }:field cannot have more than 2000 dimensions for vector index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2000 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 2.5 } } } ], "cursor": {} }'); ERROR: oversampling is not allowed for non-compressed vector index. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4001, "compression": "half" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "half_index", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 4001, "compression" : "half" } }:field cannot have more than 4000 dimensions for vector index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4000, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- check index size of half vector and full vector SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_halfvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_halfvec', 10, 2000, 500, 1536); NOTICE: Inserting 2000 documents into aggregation_pipeline_hnsw_halfvec NOTICE: Begin id: 10, Batch size: 500, batch count: 4 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 1536, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_fullvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_fullvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_fullvec', 10, 2000, 500, 1536); NOTICE: Inserting 2000 documents into aggregation_pipeline_hnsw_fullvec NOTICE: Begin id: 10, Batch size: 500, batch count: 4 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_fullvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "full_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 1536 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- The index size of table includes meta pages(2 pages, 16kB) -- Each document has 1536 dimensions, therefore the vector index for each document is -- for half vector: 1536 * 2 = 3072 bytes, will take 1/2 page(<4kB), total 1000 pages -- for full vector: 1536 * 4 = 6144 bytes, will take 1 page(<8kB), total 2000 pages SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_hnsw_halfvec', 1024), '{"result":"$indexSizes"}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "half_index" : { "$numberLong" : "8120" } } } (1 row) SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_hnsw_fullvec', 1024), '{"result":"$indexSizes"}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "full_index" : { "$numberLong" : "16120" } } } (1 row) -- full vector index size - half vector index size -- (# of documents) * 0.5 * page size = 2000 * 0.5 * 8 = 8000kB with half_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8205','SELECT pg_indexes_size(''%s'')') as half_vec_size), full_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8206','SELECT pg_indexes_size(''%s'')') as full_vec_size) SELECT (full_vec_size.vec_size - half_vec_size.vec_size) as diff FROM half_vec_size, full_vec_size; diff --------------------------------------------------------------------- 8000 (1 row) SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_halfvec'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_fullvec'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_halfvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_halfvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- check half vector search, L2 similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- oversampling, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0.5 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": "0" } } } ], "cursor": {} }'); ERROR: $oversampling must be a number value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": [] } } } ], "cursor": {} }'); ERROR: $oversampling must be a number value. BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.040916277652364386" } } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT collection.document FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) -> Limit Output: collection.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) CosmosSearch Custom Params: { "efSearch" : 64 } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection Output: collection.document Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) (20 rows) ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 1.5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.040916277652364386" } } } { "_id" : { "$numberInt" : "9" }, "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] }, "c" : false, "v" : [ { "$numberDouble" : "15.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "12.034117834948670378" } } } (4 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 1.5 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT collection.document FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '8'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) -> Limit Output: collection.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) CosmosSearch Custom Params: { "efSearch" : 64 } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection Output: collection.document Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) (22 rows) ROLLBACK; -- filter BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- check filter with half vector, COS similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "99986.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "88331.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "78296.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '6'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" LIMIT '4'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (31 rows) ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- check exact search with half vector, IP similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "IP", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) ROLLBACK; -- oversampling failed with exact search SET documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: oversampling is not allowed for exact search. SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: oversampling is not allowed for exact search. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "exact" : true, "oversampling" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" }, "exact" : true, "oversampling" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) ROLLBACK; -- filter BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "6360000.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "4860000.0" } } { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('-1'::double precision OPERATOR(pg_catalog.*) (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$lte" : "some sentence" } }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8207_8200135 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8207'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector))), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8207_8200135 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8207_8200135 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; -- check value of vector is out of range -- create index failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 22222, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "larage_vector": [22222222222222.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); ERROR: "2.2222222e+13" is out of range for type halfvec CONTEXT: SQL statement "CREATE INDEX documents_rum_index_8258 ON documentdb_data.documents_8207 USING hnsw(CAST(documentdb_api_internal.bson_extract_vector(document, 'larage_vector'::text) AS public.halfvec(3)) public.halfvec_cosine_ops) WITH (m = 16, ef_construction = 64) WHERE documentdb_api_internal.bson_extract_vector(document, 'larage_vector'::text) IS NOT NULL" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- search failed SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 11111111111111.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: "1.1111111e+13" is out of range for type halfvec -- insert failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 33333, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [33333333333333.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50331778" }, "errmsg" : "\"3.3333333e+13\" is out of range for type halfvec" } ] } (1 row) -- check dimension of query vector exceeds 4000 DO $$ DECLARE dim_num integer := 4001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 4001 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement DO $$ DECLARE dim_num integer := 4000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 4000 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_halfvec'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- PQ vector -- hnsw SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_pq'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- error cases, create index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "pq" } }:Compression type 'pq' is not enabled. SET documentdb.enableVectorCompressionPQ = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4000, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 4000, "compression" : "pq" } }:Compression type 'pq' is not supported for hnsw index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2000, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "L2", "dimensions" : 2000, "compression" : "pq" } }:Compression type 'pq' is not supported for hnsw index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api.drop_collection('db', 'aggregation_pipeline_hnsw_pq'); drop_collection --------------------------------------------------------------------- t (1 row) DROP FUNCTION IF EXISTS batch_insert_testing_vector_documents; bson_aggregation_pipeline_tests_vector_hnsw_planner.out000066400000000000000000000403141507310017400433050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8400000; SET documentdb.next_collection_id TO 8400; SET documentdb.next_collection_index_id TO 8400; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents_hnsw_planner(collectionName text, beginId integer, numDocuments integer, docPerBatch integer) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS (SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || ' ] }') AS documentValue FROM r1), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('vector_db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------- -- HNSW -- HNSW create index, error cases SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; -- HNSW search, success cases SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- should not go via Citus planner (with pushdown to index) set documentdb.enable_force_push_vector_index to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_0 (actual rows=1 loops=1) -> Limit (actual rows=1 loops=1) -> Custom Scan (DocumentDBApiQueryScan) (actual rows=1 loops=1) CosmosSearch Custom Params: { "efSearch" : 1 } -> Index Scan using foo_1 on documents_8401_8400002 collection (actual rows=1 loops=1) Order By: (public.vector(bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) Filter: bson_search_param(document, '{ "efSearch" : { "$numberInt" : "1" } }'::bson) (7 rows) SELECT batch_insert_testing_vector_documents_hnsw_planner('agg_vector_hnsw_planner', 10, 100, 10); NOTICE: Inserting 100 documents into agg_vector_hnsw_planner NOTICE: Begin id: 10, Batch size: 10, batch count: 10 batch_insert_testing_vector_documents_hnsw_planner --------------------------------------------------------------------- (1 row) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_0 (actual rows=1 loops=1) -> Limit (actual rows=1 loops=1) -> Custom Scan (DocumentDBApiQueryScan) (actual rows=1 loops=1) CosmosSearch Custom Params: { "efSearch" : 1 } -> Index Scan using foo_1 on documents_8401_8400002 collection (actual rows=1 loops=1) Order By: (public.vector(bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) Filter: bson_search_param(document, '{ "efSearch" : { "$numberInt" : "1" } }'::bson) (7 rows) -- create indexes for vector filter SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "a": 1 }, "name": "a_1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "b": 1 }, "name": "b_1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "c": 1 }, "name": "c_1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set documentdb.enableVectorPreFilter to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "a": { "$lt": "s" }} } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=0 loops=1) Output: (bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (public.vector(bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector)))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) Sort Method: quicksort Memory: 25kB -> Subquery Scan on agg_stage_0 (actual rows=0 loops=1) Output: bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (public.vector(bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector))), (agg_stage_0."sortScore" + '0'::double precision) -> Limit (actual rows=0 loops=1) Output: collection_1.document, ((public.vector(bson_extract_vector(collection_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector)) -> Nested Loop (actual rows=0 loops=1) Output: collection_1.document, ((public.vector(bson_extract_vector(collection_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector)) Join Filter: (collection_1.ctid = collection.ctid) Rows Removed by Join Filter: 102 -> Custom Scan (DocumentDBApiQueryScan) (actual rows=102 loops=1) Output: collection_1.document, (public.vector(bson_extract_vector(collection_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using foo_1 on documentdb_data.documents_8401_8400002 collection_1 (actual rows=102 loops=1) Output: collection_1.document, collection_1.ctid Order By: (public.vector(bson_extract_vector(collection_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) Filter: bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::bson) -> Materialize (actual rows=1 loops=102) Output: collection.ctid -> Seq Scan on documentdb_data.documents_8401_8400002 collection (actual rows=1 loops=1) Output: collection.ctid Filter: (collection.document @< '{ "a" : "s" }'::bson) Rows Removed by Filter: 104 (25 rows) set documentdb.enableVectorPreFilterV2 to on; -- This is currently a post-filter and will not use the filter index. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "a": { "$lt": "s" }} } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=0 loops=1) Sort Key: (((public.vector(bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) + '0'::double precision)) Sort Method: quicksort Memory: 25kB -> Subquery Scan on agg_stage_0 (actual rows=0 loops=1) -> Limit (actual rows=0 loops=1) -> Custom Scan (DocumentDBApiQueryScan) (actual rows=0 loops=1) CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using foo_1 on documents_8401_8400002 collection (actual rows=0 loops=1) Order By: (public.vector(bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) Filter: ((document @< '{ "a" : "s" }'::bson) AND bson_search_param(document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::bson)) Rows Removed by Filter: 102 (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "_id": { "$lt": 5 }} } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=0 loops=1) Sort Key: (((public.vector(bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) + '0'::double precision)) Sort Method: quicksort Memory: 25kB -> Subquery Scan on agg_stage_0 (actual rows=0 loops=1) -> Limit (actual rows=0 loops=1) -> Custom Scan (DocumentDBApiQueryScan) (actual rows=0 loops=1) CosmosSearch Custom Params: { "efSearch" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using foo_1 on documents_8401_8400002 collection (actual rows=0 loops=1) Order By: (public.vector(bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4.9,1]'::public.vector) Filter: ((document @< '{ "_id" : { "$numberInt" : "5" } }'::bson) AND (object_id < '{ "" : { "$numberInt" : "5" } }'::bson) AND bson_search_param(document, '{ "efSearch" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::bson)) Rows Removed by Filter: 102 (11 rows) bson_aggregation_pipeline_tests_vector_ivf.out000066400000000000000000023300011507310017400413700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- init a test user and set vector pre-filtering on SELECT current_user as original_test_user \gset CREATE ROLE test_filter_user_ivf WITH LOGIN INHERIT SUPERUSER CREATEDB CREATEROLE IN ROLE :original_test_user; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8100000; SET documentdb.next_collection_id TO 8100; SET documentdb.next_collection_index_id TO 8100; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents(collectionName text, beginId integer, numDocuments integer, docPerBatch integer, numDimensions integer DEFAULT 3) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN if numDimensions < 3 then RAISE EXCEPTION 'Number of dimensions must be greater than or equal to 3'; end if; RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS ( SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), rv AS (SELECT counter, CASE WHEN numDimensions > 3 THEN array_to_string(array_agg(random()), ',') ELSE '' END AS vect FROM r1 LEFT JOIN generate_series(1, GREATEST(numDimensions-3, 0)) ON true GROUP BY counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || CASE WHEN numDimensions > 3 THEN ', ' || vect ELSE '' END || ' ] }') AS documentValue FROM rv order by counter), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------- -- IVF SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- check dimensions exceeds 2000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 2001 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 2, "similarity" : "COS", "dimensions" : 2001 } }:field cannot have more than 2000 dimensions for vector index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- numLists <= data size, using data as centroids, to avoid randomized centroids generated by pgvector ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 2 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) COMMIT; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } (1 row) COMMIT; -- IVF search, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10000000 } } } ], "cursor": {} }'); ERROR: The value of $nProbes must not exceed 32768. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": -5 } } } ], "cursor": {} }'); ERROR: The value of $nProbes should be at least 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": "5" } } } ], "cursor": {} }'); ERROR: $nProbes is required to be an integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 5.5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 0 } } } ], "cursor": {} }'); ERROR: The value of $nProbes should be at least 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); ERROR: $vector is required field for using a vector index. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": -1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); ERROR: The $k should always be a positive integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": "1", "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); ERROR: The parameter $k should always hold a valid integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 0, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); ERROR: The $k should always be a positive integer value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); ERROR: $k is required field for using a vector index. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1 } } } ], "cursor": {} }'); ERROR: $path is required field for using a vector index. -- check dimension of query vector exceeds 2000 DO $$ DECLARE dim_num integer := 2001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 2001 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement DO $$ DECLARE dim_num integer := 2000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 2000 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.8, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } (1 row) -- default nProbes = numLists(2) BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) COMMIT; -- numLists > data size, pgvector will generate randomized centroids, using original vector data to query CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1000, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1000 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) COMMIT; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) COMMIT; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL enable_seqscan to off; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v", "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8100_8100003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8100'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v", "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 1 } -> Index Scan using foo_1 on documentdb_data.documents_8100_8100003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8100_8100003 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8100'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 1000 } -> Index Scan using foo_1 on documentdb_data.documents_8100_8100003 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; select documentdb_api.drop_collection('db', 'aggregation_pipeline_vector'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- turn on vector pre-filtering, check dynamic nProbes select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 1, 150, 2000); NOTICE: Inserting 150 documents into aggregation_pipeline_ivf_nprobes NOTICE: Begin id: 1, Batch size: 2000, batch count: 1 NOTICE: creating collection batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_nprobes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 150, "similarity": "L2", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_nprobes'); drop_primary_key --------------------------------------------------------------------- (1 row) ANALYZE; -- 150 less than 10000 documents, use numLists as nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 150 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- check nProbes with score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "1372662.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "1522564.0" } } { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "1676962.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "1834721.0" } } { "_id" : { "$numberInt" : "5" }, "rank" : { "$numberDouble" : "1995044.0" } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 150 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- generate 1000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 151, 1000, 2000); NOTICE: Inserting 1000 documents into aggregation_pipeline_ivf_nprobes NOTICE: Begin id: 151, Batch size: 2000, batch count: 1 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 150 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 1 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- more than 10000 and less than 1M documents, nProbes = 10000/(numOfRows/numlist) = 10000/(10150/150) = 148 -- generate 9000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 1151, 9000, 2000); NOTICE: Inserting 9000 documents into aggregation_pipeline_ivf_nprobes NOTICE: Begin id: 1151, Batch size: 2000, batch count: 5 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } { "_id" : { "$numberInt" : "2" }, "a" : "some sentence", "v" : [ { "$numberInt" : "12" }, { "$numberInt" : "17" }, { "$numberDouble" : "3.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "15.225636516225479866" } } } { "_id" : { "$numberInt" : "3" }, "a" : "some sentence", "v" : [ { "$numberInt" : "13" }, { "$numberInt" : "18" }, { "$numberDouble" : "4.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "16.769615416601034497" } } } { "_id" : { "$numberInt" : "4" }, "a" : "some sentence", "v" : [ { "$numberInt" : "14" }, { "$numberInt" : "19" }, { "$numberDouble" : "5.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "18.347206738825054373" } } } { "_id" : { "$numberInt" : "5" }, "a" : "some sentence", "v" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" }, { "$numberDouble" : "6.0999999999999996447" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "19.950439081164354604" } } } (5 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 148 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "some sentence", "v" : [ { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberDouble" : "2.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "13.726616969513441902" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 1 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- nProbes = 10000/(numOfRows/numlist) = 10000/(10150/1) = 1 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_nprobes", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_nprobes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8101_8100018 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8101'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ] }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 1 } -> Index Scan using foo_1 on documentdb_data.documents_8101_8100018 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf search with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_filter'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); ERROR: $filter is not supported for vector search yet. SET documentdb.enableVectorPreFilter = on; -- filter without index SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a.b' was not found, please check whether the index is created. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.a.b' was not found, please check whether the index is created. ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); ERROR: $filter must be a document value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; --------------------------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'unknownPath' was not found, please check whether the index is created. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.c' was not found, please check whether the index is created. --------------------------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> Bitmap Index Scan on "boolIndex_c" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (36 rows) ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "c" : { "$eq" : false } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "c" : { "$eq" : false } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "c" : { "$eq" : false } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "wildcardIndex" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson)) (29 rows) ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery)) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson)) (30 rows) ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((documentdb_api_catalog.bson_dollar_regex(collection.document, '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@~) '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (30 rows) ROLLBACK; -- check the vector index is forced to be used ALTER ROLE test_filter_user_ivf SET documentdb.enableVectorPreFilter = "True"; SELECT current_setting('citus' || '.next_shard_id') as vector_citus__next_shard_id \gset SELECT current_setting('documentdb' || '.next_collection_id') as vector__next_collection_id \gset SELECT current_setting('documentdb' || '.next_collection_index_id') as vector__next_collection_index_id \gset \c - test_filter_user_ivf SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) -- default nProbes = numLists(4) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (29 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence"}}, { "meta.a": [ { "b" : 3 } ] } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence"}}, { "meta.a": [ { "b" : 3 } ] } ] }, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.a" : [ "some sentence", [ { "b" : { "$numberInt" : "3" } } ] ] }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ "some sentence", [ { "b" : { "$numberInt" : "3" } } ] ] }'::documentdb_core.bson) (29 rows) \c - :original_test_user SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT set_config('citus' || '.next_shard_id', '' || :vector_citus__next_shard_id, FALSE); set_config --------------------------------------------------------------------- 8100048 (1 row) SELECT set_config('documentdb' || '.next_collection_id', '' || :vector__next_collection_id, FALSE); set_config --------------------------------------------------------------------- 8103 (1 row) SELECT set_config('documentdb' || '.next_collection_index_id', '' || :vector__next_collection_index_id, FALSE); set_config --------------------------------------------------------------------- 8114 (1 row) --------------------------------------------------------------------- -- ivf search: pre-filtering match with different indexes -- "filter": {"meta.a": [ { "b" : 3 } ]}, match with idx_meta.a BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- "filter": {"meta": { "a" : [ { "b" : 3 } ] }, match with documentIndex_meta BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "documentIndex_meta" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- "filter": {"meta.a.b": 3 }, match with idx_meta.a.b BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bson) (29 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf filter string: default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : "some sentence" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter string: with $and, nProbes = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter string: with $and, nProbes = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter string: with $or, nProbes = 3, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (34 rows) ROLLBACK; -- ivf filter string: with $or, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (34 rows) ROLLBACK; -- ivf filter string: with $or, $and, nProbes = 10, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "nProbes": 10 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "nProbes": 10 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "nProbes" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "nProbes" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "10" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "$and" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.a" : { "$lt" : "some sentence" } } ] }, { "meta.a" : { "$in" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] } } ] }, "nProbes" : { "$numberInt" : "10" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery)) OR (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "meta.a" : { "b" : { "$numberInt" : "3" } } }'::documentdb_api_internal.bsonindexbounds, '{ "meta.a" : { "b" : { "$numberInt" : "5" } } }'::documentdb_api_internal.bsonindexbounds])))) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '10'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 10, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "10" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson)) Filter: (((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.a" : "some sentence" }'::documentdb_core.bson)) OR (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.a" : { "min" : "other sentence", "max" : "some sentence", "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "5" } } ] }'::documentdb_core.bson) (35 rows) ROLLBACK; -- ivf filter string: with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf filter number, with default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.b" : { "$numberInt" : "2" } } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter number, with $and, nProbes = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "meta.b" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter number, with $and, default nProbes, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (29 rows) ROLLBACK; -- ivf filter number, with $or, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$gt" : { "$numberInt" : "1" } } }, { "meta.b" : { "$lt" : { "$numberInt" : "5" } } } ] }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (34 rows) ROLLBACK; -- ivf filter number, with $or, default nProbes, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.b" : { "$eq" : { "$numberInt" : "1" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "2" } } }, { "meta.b" : { "$eq" : { "$numberInt" : "5" } } } ] } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter number, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$eq": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lte": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$ne": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$in": [ 2,3 ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$nin": [ 2 ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gt": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lt": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf filter boolean, with default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : true }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : true }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter boolean, with nProbes = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : true }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : true }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : true }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter boolean, with c = false, nProbes = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 1 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter boolean, with c = false, nProbes = 3, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 3 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "c" : false }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf filter boolean, with $eq, $ne, $in, $nin, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$eq": true}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$ne": true}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$in": [true]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$nin": [true]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (4 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf search: with filter, different distance metric -- ivf search: cosine similarity CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index_cos", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "99986.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "88331.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_regex(collection.document, '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index_cos on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@~) '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: inner product CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index_cos"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "4860000.0" } } { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_regex(collection.document, '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector))), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index_ip on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Seq Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@~) '{ "meta.a" : { "$regularExpression" : { "pattern" : "^some", "options" : "i" } } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: restore to euclidean distance CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index_ip"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; --------------------------------------------------------------------- -- ivf search: with filter and score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a.b" : { "$numberInt" : "3" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a.b" : { "$numberInt" : "3" } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: with filter and score projection, nProbes = 4, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "4" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }, "nProbes" : { "$numberInt" : "4" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 4, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "4" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "documentIndex_meta" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] } }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: with filter and score projection, nProbes = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "nProbes" : { "$numberInt" : "3" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 3, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "3" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: with filter and score projection, $ne, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "rank" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (3 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$ne" : "some sentence" } }, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (documentdb_api_catalog.bson_dollar_ne(collection.document, '{ "meta.a" : "some sentence" }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 1, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "1" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "rank" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "meta.b" : { "$gte" : { "$numberInt" : "2" } } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#>=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "filter" : { "c" : { "$eq" : false } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '2'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "boolIndex_c" on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (29 rows) ROLLBACK; -- ivf search: with filter and score projection, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "rank" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "rank" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "rank" : { "$numberDouble" : "1203412.0" } } (3 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "10" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$eq" : "some sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "2" } } }, { "c" : { "$eq" : false } } ] }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8102_8100032 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "c" : false }'::documentdb_core.bsonquery)) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8102'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '10'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using ivf_index on documentdb_data.documents_8102_8100032 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Bitmap Heap Scan on documentdb_data.documents_8102_8100032 collection Output: collection.ctid Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> Bitmap Index Scan on "boolIndex_c" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : false }'::documentdb_core.bson) (36 rows) ROLLBACK; --------------------------------------------------------------------- -- ivf search: with filter and shard -- TODO, current implementation does not support sharded collection, need to fix in part 3 BEGIN; SET LOCAL client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_ivf_filter', '{"c":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) END; ANALYZE; -- reindex, numLists = 2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "7" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- ivf search: with filter and shard, default nProbes, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 } } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 } } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, nProbes = 1, v= [ 3.0, 5.0, 1.1 ], no match document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 15.0, 5.0, 0.1 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 3.0, 4.9, 1.0 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 13.0, 5.0, 0.1 ], match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 2, v= [ 13.0, 5.0, 0.1 ], match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 2 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 2 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, number, nProbes = 1, v= [ 8.0, 5.0, 0.1 ], match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 8.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 8.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, filtering on shard field, nProbes = 1, v= [ 13.0, 5.0, 0.1 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; -- ivf search: with filter and shard, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; SET documentdb.enableVectorPreFilter = off; --------------------------------------------------------------------- -- Vector search with empty vector field SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_empty_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "vectorIndex", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 5, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: creating collection NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 3, "a": "some sentence" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 4, "a": "some other sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_empty_vector'); drop_primary_key --------------------------------------------------------------------- (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "62863.0" } } (3 rows) EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> Limit -> Custom Scan (DocumentDBApiQueryScan) CosmosSearch Custom Params: { "nProbes" : 5 } -> Index Scan using "vectorIndex" on documents_8103_8100056 collection Order By: (vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(document, '{ "nProbes" : { "$numberInt" : "5" } }'::documentdb_core.bson) (12 rows) COMMIT; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "62863.0" } } (3 rows) EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> Limit -> Custom Scan (DocumentDBApiQueryScan) CosmosSearch Custom Params: { "nProbes" : 5 } -> Index Scan using "vectorIndex" on documents_8103_8100056 collection Order By: (vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(document, '{ "nProbes" : { "$numberInt" : "5" } }'::documentdb_core.bson) (12 rows) COMMIT; SELECT drop_collection('db','aggregation_pipeline_empty_vector'); drop_collection --------------------------------------------------------------------- t (1 row) DROP ROLE IF EXISTS test_filter_user_ivf; --------------------------------------------------------------------- -- exact search SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector_ivf_exact'); drop_primary_key --------------------------------------------------------------------- (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": {} } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": 123 } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": "abc" } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": [1,2,3] } } } ], "cursor": {} }'); ERROR: $exact must represent a valid boolean value. -- COS BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99986126308999445644" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.88331075895982669177" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) public.cosine_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.cosine_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - cosine_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))) -> Limit Output: collection.document, (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8104_8100079 collection Output: collection.document, cosine_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- IP CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_ivf_exact", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "6" } } (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] }, "c" : false, "v" : [ { "$numberDouble" : "15.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "69.59999847412109375" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "63.59999847412109375" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8104_8100079 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- L2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_ivf_exact", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "6" } } (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '2'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8104_8100079 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (17 rows) COMMIT; -- nProbes BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) ROLLBACK; -- exact = false BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": false } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": false } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) ROLLBACK; -- filter:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "200000.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "700000.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (3 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$in" : [ "some sentence", "other sentence" ] } }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE ((documentdb_api_catalog.bson_dollar_in(collection.document, '{ "meta.a" : [ "some sentence", "other sentence" ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "meta.a" : "some sentence" }'::documentdb_api_internal.bsonindexbounds, '{ "meta.a" : "other sentence" }'::documentdb_api_internal.bsonindexbounds]))) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$in" : [ "some sentence", "other sentence" ] } }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8104_8100079 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "meta.a" : [ "some sentence", "other sentence" ] }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "eq" : "other sentence" } }, { "meta.b" : { "$lt" : { "$numberInt" : "10" } } } ] }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : { "eq" : "other sentence" } }'::documentdb_core.bsonquery) AND (collection.document OPERATOR(documentdb_api_catalog.#<) '{ "meta.b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$and" : [ { "meta.a" : { "eq" : "other sentence" } }, { "meta.b" : { "$lt" : { "$numberInt" : "10" } } } ] }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "numberIndex_meta.b" on documentdb_data.documents_8104_8100079 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "meta.b" : { "$numberInt" : "10" } }'::documentdb_core.bson) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : { "eq" : "other sentence" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) (18 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "1" } } } ] }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8104_8100079 collection WHERE (((collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.a" : "other sentence" }'::documentdb_core.bsonquery) OR (collection.document OPERATOR(documentdb_api_catalog.#>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery)) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8104'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "$or" : [ { "meta.a" : { "$gt" : "other sentence" } }, { "meta.b" : { "$gt" : { "$numberInt" : "1" } } } ] }, "exact" : true, "nProbes" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Bitmap Heap Scan on documentdb_data.documents_8104_8100079 collection Output: collection.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) -> BitmapOr -> Bitmap Index Scan on "idx_meta.a" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.a" : "other sentence" }'::documentdb_core.bson) -> Bitmap Index Scan on "numberIndex_meta.b" Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "meta.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) ROLLBACK; -- shard SET client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_vector_ivf_exact', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } (2 rows) EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 312_1 -> Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::public.vector) AS "?sort?" FROM documentdb_data.documents_8104_8100088 collection WHERE (documentdb_api_internal.bson_extract_vector(document, 'v'::text) IS NOT NULL) ORDER BY (public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::public.vector)) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: document, (l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (l2_distance(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Seq Scan on documentdb_data.documents_8104_8100088 collection Output: document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, public.l2_distance(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "nProbes" : { "$numberInt" : "1" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('312_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_document_add_score_field(intermediate_result.document, l2_distance(vector(documentdb_api_internal.bson_extract_vector(intermediate_result.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Function Call: read_intermediate_result('312_1'::text, 'binary'::citus_copy_format) (31 rows) COMMIT; -- shard is not supported with filter yet BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. ROLLBACK; SELECT drop_collection('db','aggregation_pipeline_vector_ivf_exact'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Half vector -- ivf SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_halfvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- error cases, create index SET documentdb.enableVectorCompressionHalf = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "half" } }:Compression type 'half' is not enabled. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "none" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "none" } }:Invalid compression type of vector index: none SET documentdb.enableVectorCompressionHalf = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": "binary" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : "binary" } }:Invalid compression type of vector index: binary SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": "scalar" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : "scalar" } }:Invalid compression type of vector index: scalar SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": 123 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : 123 } }:compression must be a string not int SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": {} } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : { } } }:compression must be a string not object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": ["half"] } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001, "compression" : [ "half" ] } }:compression must be a string not array SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001 } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2001 } }:field cannot have more than 2000 dimensions for vector index SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2000 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 2.5 } } } ], "cursor": {} }'); ERROR: oversampling is not allowed for non-compressed vector index. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4001, "compression": "half" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "half_index", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 4001, "compression" : "half" } }:field cannot have more than 4000 dimensions for vector index SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4000, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- check index size of half vector and full vector SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_halfvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT batch_insert_testing_vector_documents('aggregation_pipeline_ivf_halfvec', 10, 2000, 500, 1536); NOTICE: Inserting 2000 documents into aggregation_pipeline_ivf_halfvec NOTICE: Begin id: 10, Batch size: 500, batch count: 4 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 1536, "compression": "half" } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_fullvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_fullvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT batch_insert_testing_vector_documents('aggregation_pipeline_ivf_fullvec', 10, 2000, 500, 1536); NOTICE: Inserting 2000 documents into aggregation_pipeline_ivf_fullvec NOTICE: Begin id: 10, Batch size: 500, batch count: 4 batch_insert_testing_vector_documents --------------------------------------------------------------------- (1 row) SELECT setseed(0); setseed --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_fullvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "full_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 1536 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- Each document has 1536 dimensions, therefore the vector index for each document is -- for half vector: 1536 * 2 = 3072 bytes, will take 1/2 page(<4kB), total 1000 pages -- for full vector: 1536 * 4 = 6144 bytes, will take 1 page(<8kB), total 2000 pages SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_ivf_halfvec', 1024), '{"result":"$indexSizes"}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "half_index" : { "$numberLong" : "8184" } } } (1 row) SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_ivf_fullvec', 1024), '{"result":"$indexSizes"}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "full_index" : { "$numberLong" : "16184" } } } (1 row) -- full vector index size - half vector index size -- (# of documents) * 0.5 * page size = 2000 * 0.5 * 8 = 8000kB with half_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8105','SELECT pg_indexes_size(''%s'')') as half_vec_size), full_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8106','SELECT pg_indexes_size(''%s'')') as full_vec_size) SELECT (full_vec_size.vec_size - half_vec_size.vec_size) as diff FROM half_vec_size, full_vec_size; diff --------------------------------------------------------------------- 8000 (1 row) SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_halfvec'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_fullvec'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_halfvec'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_halfvec'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- check half vector search, L2 similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; -- oversampling, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0.5 } } } ], "cursor": {} }'); ERROR: $oversampling must be set to a value that is greater or equal to 1. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": "0" } } } ], "cursor": {} }'); ERROR: $oversampling must be a number value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": [] } } } ], "cursor": {} }'); ERROR: $oversampling must be a number value. BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.040916277652364386" } } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT collection.document FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '5'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) -> Limit Output: collection.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using half_index on documentdb_data.documents_8107_8100132 collection Output: collection.document Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson) (21 rows) ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } { "_id" : { "$numberInt" : "7" }, "meta" : { "a" : "some other sentence", "b" : { "$numberInt" : "2" } }, "c" : true, "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "5.0813383763359256662" } } } { "_id" : { "$numberInt" : "8" }, "meta" : { "a" : "other sentence", "b" : { "$numberInt" : "5" } }, "c" : false, "v" : [ { "$numberDouble" : "13.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.040916277652364386" } } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT collection.document FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "k" : { "$numberInt" : "5" }, "path" : "v", "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '8'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) -> Limit Output: collection.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using half_index on documentdb_data.documents_8107_8100132 collection Output: collection.document Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson) (23 rows) ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) -- check filter with half vector, cosine similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "99986.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8107_8100132 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8107_8100132 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (29 rows) ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "oversampling": 1.5 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "99986.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM (SELECT documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document, (public.vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "fullScoreVal" FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector_to_halfvec(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "oversampling" : { "$numberDouble" : "1.5" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '6'::bigint) agg_stage_0_1) agg_stage_0 ORDER BY "fullScoreVal" LIMIT '4'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)))), ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) Sort Key: ((vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Subquery Scan on agg_stage_0_1 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0_1.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))), (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0_1.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) -> Limit Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) -> Nested Loop Output: collection_1.document, ((vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec), collection_1.ctid CosmosSearch Custom Params: { "nProbes" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using half_index on documentdb_data.documents_8107_8100132 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector_to_halfvec(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <=> '[3,4.8984375,1]'::halfvec) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "nProbes" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Materialize Output: collection.ctid -> Index Scan using "idx_meta.a" on documentdb_data.documents_8107_8100132 collection Output: collection.ctid Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) (31 rows) ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- check exact search with half vector, IP similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "IP", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "exact" : true }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8107_8100132 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) ROLLBACK; -- oversampling failed with exact search SET documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: oversampling is not allowed for exact search. SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: oversampling is not allowed for exact search. BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "3460000.0" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "exact" : true, "oversampling" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8107_8100132 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : "some sentence" }'::documentdb_core.bsonquery) AND ((collection.shard_key_value OPERATOR(pg_catalog.=) '8107'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))) ORDER BY (public.vector_negative_inner_product(public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : { "$eq" : "some sentence" } }, "nProbes" : { "$numberInt" : "100" }, "exact" : true, "oversampling" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'vector'::text), 3, true))) LIMIT '4'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true), '[3,4.9,1]'::vector))), '{ "searchScore" : { "$round" : [ { "$multiply" : [ "$__cosmos_meta__.score", { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Sort Output: collection.document, (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) Sort Key: (vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector)) -> Index Scan using "idx_meta.a" on documentdb_data.documents_8107_8100132 collection Output: collection.document, vector_negative_inner_product(vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true), '[3,4.9,1]'::vector) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : "some sentence" }'::documentdb_core.bson) Filter: (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL) (18 rows) ROLLBACK; -- check value of vector is out of range -- create index failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 22222, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "larage_vector": [22222222222222.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); ERROR: "2.2222222e+13" is out of range for type halfvec CONTEXT: SQL statement "CREATE INDEX documents_rum_index_8153 ON documentdb_data.documents_8107 USING ivfflat(CAST(documentdb_api_internal.bson_extract_vector(document, 'larage_vector'::text) AS public.halfvec(3)) public.halfvec_cosine_ops) WITH (lists = 100) WHERE documentdb_api_internal.bson_extract_vector(document, 'larage_vector'::text) IS NOT NULL" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; -- search failed SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 11111111111111.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ERROR: "1.1111111e+13" is out of range for type halfvec -- insert failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 33333, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [33333333333333.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50331778" }, "errmsg" : "\"3.3333333e+13\" is out of range for type halfvec" } ] } (1 row) -- check dimension of query vector exceeds 4000 DO $$ DECLARE dim_num integer := 4001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 4001 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement DO $$ DECLARE dim_num integer := 4000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; ERROR: expected 3 dimensions, not 4000 CONTEXT: SQL statement "SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson)" PL/pgSQL function inline_code_block line 9 at SQL statement SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_halfvec'); drop_collection --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- PQ vector -- ivf SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_pq'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- error cases, create index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 3, "compression" : "pq" } }:Compression type 'pq' is not enabled. SET documentdb.enableVectorCompressionPQ = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4000, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 4000, "compression" : "pq" } }:Compression type 'pq' is not supported for ivf index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2000, "compression": "pq" } } ] }', true); ERROR: Error in specification { "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 16, "similarity" : "L2", "dimensions" : 2000, "compression" : "pq" } }:Compression type 'pq' is not supported for ivf index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api.drop_collection('db', 'aggregation_pipeline_ivf_pq'); drop_collection --------------------------------------------------------------------- t (1 row) DROP FUNCTION IF EXISTS batch_insert_testing_vector_documents; bson_aggregation_pipeline_tests_vector_native.out000066400000000000000000001436031507310017400421020ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8300000; SET documentdb.next_collection_id TO 8300; SET documentdb.next_collection_index_id TO 8300; SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; -- Vector search with vectorSearch BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 5.0, 1.1 ], "limit": 1, "path": "v" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8300_8300005 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8300'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 16 } -> Index Scan using foo_1 on documentdb_data.documents_8300_8300005 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": {"a": "some sentence"} } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 5.0, 1.1 ], "limit": 1, "path": "v", "filter": {} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) SELECT documentdb_api.shard_collection('db','aggregation_pipeline_native_vector', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) ANALYZE; -- vectorSearch with shard BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.0, 1.0 ], "limit": 2, "path": "v", "numCandidates": 100 } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.99482529697928390178" } } } { "_id" : { "$numberInt" : "7" }, "a" : "some other sentence", "v" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.91671110989441617622" } } } (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.0, 1.0 ], "limit": 2, "path": "v", "numCandidates": 100 } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 188_1 -> Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4,1]'::public.vector) AS "?sort?" FROM documentdb_data.documents_8300_8300016 collection WHERE (documentdb_api_internal.bson_search_param(document, '{ "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) '[3,4,1]'::public.vector) LIMIT '2'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, ((vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: document, (vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) <=> '[3,4,1]'::vector) CosmosSearch Custom Params: { "efSearch" : 100 } -> Index Scan using foo_1 on documentdb_data.documents_8300_8300016 collection Output: document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.0" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "2" }, "path" : "v", "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('188_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: documentdb_api_internal.bson_document_add_score_field(intermediate_result.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(intermediate_result.document, 'v'::text), 3, true) <=> '[3,4,1]'::vector))) Function Call: read_intermediate_result('188_1'::text, 'binary'::citus_copy_format) (32 rows) ROLLBACK; --------------------------------------------------------------------- -- vectorSearch with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"a": "some sentence"} } } ], "cursor": {} }'); ERROR: The index for filter path 'a' was not found, please check whether the index is created. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": {} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "meta" : { "a" : "some sentence", "b" : { "$numberInt" : "1" } }, "c" : true, "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.14142130855867909855" } } } (1 row) set documentdb.enableVectorPreFilter = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) --------------------------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } ], "cursor": {} }'); ERROR: The index for filter path 'unknownPath' was not found, please check whether the index is created. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } ], "cursor": {} }'); ERROR: The index for filter path 'meta.c' was not found, please check whether the index is created. -- wrong filter type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": "some sentence" } } ], "cursor": {} }'); ERROR: The BSON field 'filter' has an incorrect type 'string'; it should be of type 'object'. --------------------------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } { "_id" : { "$numberInt" : "9" }, "searchScore" : { "$numberDouble" : "1203412.0" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "searchScore" : { "$numberDouble" : "1004092.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "searchScore" : { "$numberDouble" : "14142.0" } } { "_id" : { "$numberInt" : "7" }, "searchScore" : { "$numberDouble" : "508134.0" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "numCandidates": 100 } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "meta" : { "a" : [ { "b" : { "$numberInt" : "3" } } ] }, "c" : false, "v" : [ { "$numberDouble" : "15.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "0.10000000000000000555" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "12.034117834948670378" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "numCandidates": 100 }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT c1.document, c1."orderVal" AS "sortScore" FROM ((SELECT collection.document, (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true)) AS "orderVal", collection.ctid FROM documentdb_data.documents_8301_8300030 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8301'::bigint) AND documentdb_api_internal.bson_search_param(collection.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "4" }, "path" : "v", "filter" : { "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }, "efSearch" : { "$numberInt" : "100" } }'::documentdb_core.bson, 'vector'::text), 3, true))) c1 JOIN (SELECT collection.ctid FROM documentdb_data.documents_8301_8300030 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '8301'::bigint))) c2 ON ((c2.ctid OPERATOR(pg_catalog.=) c1.ctid))) ORDER BY c1."orderVal" LIMIT '4'::bigint) agg_stage_0 ORDER BY ("sortScore" OPERATOR(pg_catalog.+) '0'::double precision) Node: host=localhost port=58070 dbname=regression -> Sort Output: (documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector))), ((agg_stage_0."sortScore" + '0'::double precision)) Sort Key: ((agg_stage_0."sortScore" + '0'::double precision)) -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)), (agg_stage_0."sortScore" + '0'::double precision) -> Limit Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Nested Loop Output: collection_1.document, ((vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) Join Filter: (collection_1.ctid = collection.ctid) -> Custom Scan (DocumentDBApiQueryScan) Output: collection_1.document, (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector), collection_1.ctid CosmosSearch Custom Params: { "efSearch" : 100, "iterativeScan" : "relaxed_order" } -> Index Scan using hnsw_index on documentdb_data.documents_8301_8300030 collection_1 Output: collection_1.document, collection_1.ctid Order By: (vector(documentdb_api_internal.bson_extract_vector(collection_1.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) Filter: documentdb_api_internal.bson_search_param(collection_1.document, '{ "efSearch" : { "$numberInt" : "100" }, "iterativeScan" : "relaxed_order" }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_8301_8300030 collection Output: collection.ctid Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "meta.a" : [ { "b" : { "$numberInt" : "3" } } ] }'::documentdb_core.bson) (27 rows) SELECT documentdb_api.shard_collection('db','aggregation_pipeline_native_vector_filter', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) ANALYZE; -- vectorSearch with filter and shard SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } } ], "cursor": {} }'); ERROR: Filter is not supported for vector search on sharded collection. set documentdb.enableVectorPreFilter = off; --------------------------------------------------------------------- -- Vector search with knnBeta SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_knnbeta", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_8302_8300052 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '8302'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 2 } -> Index Scan using foo_1 on documentdb_data.documents_8302_8300052 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; set documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: $filter is not supported for knnBeta queries. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some" } } } ], "cursor": {} }'); ERROR: $filter must be a document value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "score": {"a": "some sentence"} } } } ], "cursor": {} }'); ERROR: $score is not supported for knnBeta queries. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "score": 100 } } } ], "cursor": {} }'); ERROR: $score must be a document value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v", "score": {} } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : "some sentence", "v" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "1.0" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "unknowType": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ERROR: Unrecognized $search option: unknowType, should be one of: cosmosSearch, knnBeta. set documentdb.enableVectorPreFilter = off; bson_aggregation_set_operators_tests.out000066400000000000000000002670351507310017400402440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9000000; SET documentdb.next_collection_id TO 9000; SET documentdb.next_collection_index_id TO 9000; -- $setIntersection operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1,2,3],[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [["a","b","c"],["a","d","c"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ "a", "c" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"a" : { "$setIntersection" : [[1.1,2.2,3.3],[1.1,2.2,4.4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberDouble" : "2.2000000000000001776" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) -- $setIntersection operator: No matching element: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1,2,3],[4,5,6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"a" : { "$setIntersection" : [[1,1,2],[3,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) -- $setIntersection operator: Nested Elements: -- NOTE: we don't recurse into arrays and considers only the first/outer-level array select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[[1,{"a":1, "b":1}],2,3],[4,[1,{"a":1, "b":1}],6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[{"a":[1,2,3],"b":1},2,3],[4,{"a":[1,2,3],"b":1},6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "1" } } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[[1,2,3]],[[3,2,1]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[{"a":1,"b":1}],[{"b":1,"a":1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[["a","b","c"]],[["a","b","c"]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ [ "a", "b", "c" ] ] } (1 row) ---- $setIntersection operator: decimal,double and long: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "3.1000000000000000888" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "3.1000000000000000888" } ] } (1 row) ---- $setIntersection operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ { "$numberLong" : "1" },2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberLong" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ { "$numberDecimal" : "1" },2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberDecimal" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1,2,3],[{ "$numberDecimal" : "1" },2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1.1],[{ "$numberDecimal" : "1.1" }]]} }'); -- 1.1 is not fixed integer and type is different so not considering both as equal. bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1.00],[{ "$numberDecimal" : "1.00" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberDouble" : "1.0" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1],[{ "$numberDecimal" : "1.00" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "1" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1],[1.00]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "1" } ] } (1 row) ---- $setIntersection operator: Null,Nan,Infinity,undefined and undefined path: select bson_dollar_project('{"_id":"1" }', '{"setIntersection" : { "$setIntersection" : [null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setIntersection" : { "$setIntersection" : ["$a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : null} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [[1,2,3],null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [{ "$undefined" : true }]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : { "$undefined" : true }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"setIntersection" : { "$setIntersection" : ["$undefinePath", [1]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[null,{ "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ null, { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" }, { "$numberDouble" : "-Infinity" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [[NaN],[{"$numberDouble": "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setIntersection" : [ { "$numberDouble" : "NaN" } ] } (1 row) ---- $setIntersection operator: literals and operators: select bson_dollar_project('{"_id":"1", "a" :[1,2,3]}', '{"intersection" : { "$setIntersection" : ["$a",[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ {"$slice" : [[1,2,3,4,5,6,7],2,5]} ,[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1","a":[1,2,3] }', '{"intersection" : { "$setIntersection" : [ {"$slice" : ["$a",0,3]} ,[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) ---- $setIntersection operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$binary" : { "base64" : "ww==", "subType" : "01" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$timestamp" : { "t" : 1670981326, "i" : 1 } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$date" : { "$numberLong" : "1386829395134" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.135Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$oid" : "639926cee6bda3127f153bf1" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$code" : "var a = 1;" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" } } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$maxKey" : 1 } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ { "$minKey" : 1 } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "intersection" : [ ] } (1 row) ---- $setIntersection operator: Negative: select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : {} } }'); ERROR: All operands of $setIntersection must be arrays, but one provided argument has type: object select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : 1 } }'); ERROR: All operands of $setIntersection must be arrays, but one provided argument has type: int select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : [1] } }'); ERROR: All operands of $setIntersection must be arrays, but one provided argument has type: int select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : [[1],{}]} }'); ERROR: All operands of $setIntersection must be arrays, but one provided argument has type: object -- $setUnion operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [["a","b","c"],["a","d","c"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ "b", "a", "c", "d" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.2,3.3],[1.1,2.2,4.4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDouble" : "2.2000000000000001776" }, { "$numberDouble" : "3.2999999999999998224" }, { "$numberDouble" : "4.4000000000000003553" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) -- $setUnion operator: No matching element: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],[4,5,6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "6" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,1,2],[3,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) -- $setUnion operator: Nested Elements: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[[1,{"a":1, "b":1}],2,3],[4,[1,{"a":1, "b":1}],6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "6" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[{"a":[1,2,3],"b":1},2,3],[4,{"a":[1,2,3],"b":1},6]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "6" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "1" } } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[[1,2,3]],[[3,2,1]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[{"a":1,"b":1}],[{"b":1,"a":1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "b" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[["a","b","c"]],[["a","b","c"]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ [ "a", "b", "c" ] ] } (1 row) ---- $setUnion operator: decimal,double and long: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDouble" : "4.0" }, { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "3.1000000000000000888" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDouble" : "4.0" }, { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "3.1000000000000000888" } ] } (1 row) ---- $setUnion operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ { "$numberLong" : "1" },2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberLong" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ { "$numberDecimal" : "1" },2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberDecimal" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1,2,3],[{ "$numberDecimal" : "1" },2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1.1],[{ "$numberDecimal" : "1.1" }]]} }'); -- 1.1 is not fixed integer and type is different so not considering both as equal. bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDecimal" : "1.1" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1.00],[{ "$numberDecimal" : "1.00" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDouble" : "1.0" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1],[{ "$numberDecimal" : "1.00" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "1" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1],[1.00]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "1" } ] } (1 row) ---- $setUnion operator: Null,Nan,Infinity,undefined and undefined path: select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : ["$a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : null} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [{ "$undefined" : true }]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : { "$undefined" : true }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"setUnion" : { "$setUnion" : ["$undefinePath", [1]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setUnion" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[null,{ "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ null, { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" }, { "$numberDouble" : "-Infinity" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[NaN],[{"$numberDouble": "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberDouble" : "NaN" } ] } (1 row) ---- $setUnion operator: literals and operators: select bson_dollar_project('{"_id":"1", "a" :[1,2,3]}', '{"union" : { "$setUnion" : ["$a",[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ {"$slice" : [[1,2,3,4,5,6,7],2,5]} ,[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "6" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "7" } ] } (1 row) select bson_dollar_project('{"_id":"1","a":[1,2,3] }', '{"union" : { "$setUnion" : [ {"$slice" : ["$a",0,3]} ,[2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) ---- $setUnion operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$binary" : { "base64" : "zg==", "subType" : "01" } }, { "$binary" : { "base64" : "ww==", "subType" : "01" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$binary" : { "base64" : "ww==", "subType" : "01" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$binary" : { "base64" : "ww==", "subType" : "01" } }, { "$binary" : { "base64" : "ww==", "subType" : "02" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$timestamp" : { "t" : 1670981326, "i" : 1 } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$timestamp" : { "t" : 1770981326, "i" : 1 } }, { "$timestamp" : { "t" : 1870981326, "i" : 1 } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$timestamp" : { "t" : 1670981326, "i" : 2 } }, { "$timestamp" : { "t" : 1670981326, "i" : 1 } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$date" : { "$numberLong" : "1386829395134" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$date" : { "$numberLong" : "1386829395134" } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$oid" : "639926cee6bda3127f153bf1" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$oid" : "639926cee6bda3127f153bf1" }, { "$oid" : "739926cee6bda3127f153bf1" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$code" : "var a = 1;" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$code" : "var a = 1;" }, { "$code" : "var b = 1;" } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" } } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" } } }, { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" } } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" } } }, { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" } } } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$maxKey" : 1 } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$minKey" : 1 } ] } (1 row) select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "union" : [ { "$minKey" : 1 }, { "$maxKey" : 1 } ] } (1 row) ---- $setUnion operator: Negative: select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : {} } }'); ERROR: All operands of $setUnion are required to be arrays, but one provided argument has the type: object select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : 1 } }'); ERROR: All operands of $setUnion are required to be arrays, but one provided argument has the type: int select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : [1] } }'); ERROR: All operands of $setUnion are required to be arrays, but one provided argument has the type: int select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : [[1],{}]} }'); ERROR: All operands of $setUnion are required to be arrays, but one provided argument has the type: object -- $setEquals operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [["a","b","c"],["a","b","c"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1.1,2.1,3.1],[1.1,2.1,3.1]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [["a","b","c"],["b","b","c"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1.1,2.1,3.1],[1.2,2.2,3.2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[],[],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3,4],[1,2,3,4,5]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) -- $setEquals operator: Nested test: select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[[1,2],[1,2]],[[1,2],[1,2]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[[1,2],[1,2]],[[2,3],[1,2]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,1,2],[[2,3],[1,2]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{"a":1},{"b":1}],[{"a":1},{"b":1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{"a":1},{"b":1}],[{"a":1},{"b":2}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) -- $setEquals operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberLong" : "1" }],[1]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberLong" : "1" },{ "$numberDouble" : "1.0" }],[1],[{ "$numberDecimal" : "1.0" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberDouble" : "1.1" }],[1.1],[{ "$numberDecimal" : "1.1" }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) --$setEquals with operators and literals select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4,5] }', '{"setEqual" : { "$setEquals" : [["$a"],["$b"]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [["$a"],["$b"]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [[{"$slice": ["$a",1,3]}],[{"$slice": ["$b",1,3]}]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [[{"$slice": ["$a",1,4]}],[{"$slice": ["$b",1,3]}]] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) ---- $setEquals operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : true } (1 row) select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "setEqual" : false } (1 row) -- $setEquals operator: Negative test: select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : {} } }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : 1 } }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [1] } }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : ["$a",[1,2,3]] } }'); ERROR: All operands of $setEquals must be arrays; one provided argument is of type: missing select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1,2,3],"$a"] } }'); ERROR: All operands of $setEquals must be arrays; one provided argument is of type: missing select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1],{}]} }'); ERROR: All operands of $setEquals must be arrays; one provided argument is of type: object select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : null} }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : { "$undefined" : true}} }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [null]} }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [null,null]} }'); ERROR: All operands of $setEquals must be arrays; one provided argument is of type: null select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1,2,3],null]} }'); ERROR: All operands of $setEquals must be arrays; one provided argument is of type: null select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [{ "$undefined" : true}]} }'); ERROR: $setEquals requires a minimum of two arguments, but received 1 -- $setDifference operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,1,2,2,3,3],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3,4],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3,4],[1,2,5,6,7]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) ---- $setDifference operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDecimal" : "1.0"},{"$numberDouble" : "2.0"},3,4],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDecimal" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[1.1,2.1]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberDecimal" : "1.1" }, { "$numberDecimal" : "2.1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberLong" : "1"},{"$numberDouble" : "2.0"},3,4],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) -- $setDifference operator: different types and Nested case: select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [["a","b","c"],["a"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ "b", "c" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ null, { "$numberDouble" : "Infinity" }, { "$numberDouble" : "-Infinity" }, { "$numberDouble" : "NaN" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"}],[{ "$numberDouble" : "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ null, { "$numberDouble" : "Infinity" }, { "$numberDouble" : "-Infinity" } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$minKey" : 1 } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2019-01-30T07:30:10.137Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$date" : { "$numberLong" : "1386829395134" } } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[[1,2],[1,2,3]],[[1,2]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"a":1},{"b":1}],[{"a":1},{"b":2}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "b" : { "$numberInt" : "1" } } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null,null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null,[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : ["$a",[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [{"$undefined": true},[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],{"$undefined": true}]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : null } (1 row) -- $setDifference operator: with Inner Operators : select bson_dollar_project('{"_id":"1", "a": [1,2,3], "b": [1,2]}', '{"difference" : { "$setDifference" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a": [1,2,3,5], "b": [1,2,3,4]}', '{"difference" : { "$setDifference" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"difference" : { "$setDifference" : [{"$slice": ["$a",1,6]},{"$slice": ["$b",1,6]}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"difference" : { "$setDifference" : [{"$slice": ["$a",1,3]},{"$slice": ["$b",1,3]}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "difference" : [ ] } (1 row) -- $setDifference operator: Negative Cases : select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[],[]]} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 3 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1,2,3]} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 3 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : []} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 0 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1]} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null]} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [{"$undefined": true}]} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : null} }'); ERROR: The expression $setDifference requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1,2]} }'); ERROR: Both operands in $setDifference must be arrays, but the first provided argument is of type: int select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1],2]} }'); ERROR: Both operands in $setDifference need to be arrays, but the second one has type: int -- $setIsSubset operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3],[]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[1,2,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2],[1,2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,1,2,2,3,3],[1,2,3,4,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3,4],[1,2]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3,4],[1,2,5,6,7]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) ---- $setIsSubset operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDecimal" : "1.0"},{"$numberDouble" : "2.0"},3,4],[1,2,4,3]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDecimal" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[1.1,2.1,3,4,5]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4,5]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberLong" : "1"},{"$numberDouble" : "2.0"}],[1,2,3,4]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) -- $setIsSubset operator: different types and Nested case: select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [["a","b","c"],["a","b","c","d"]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"}],[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{ "$numberDouble" : "-NaN"}],[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[[1,2],[1,2,3]],[[1,2],[1,2,3],[1,2,3,4]]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"a":1},{"b":1}],[{"a":1},{"b":1},{"c":2}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"a":1},{"b":2}],[{"a":1},{"b":1},{"c":2}]]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) -- $setIsSubset operator: with Inner Operators : select bson_dollar_project('{"_id":"1", "a": [1,2,3], "b": [1,2,3,4]}', '{"isSubset" : { "$setIsSubset" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1", "a": [1,2,3,5], "b": [1,2,3,4]}', '{"isSubset" : { "$setIsSubset" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : false } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4,5,6] }', '{"isSubset" : { "$setIsSubset" : [{"$slice": ["$a",1,6]},{"$slice": ["$b",1,6]}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"isSubset" : { "$setIsSubset" : [{"$slice": ["$a",1,3]},{"$slice": ["$b",1,3]}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "isSubset" : true } (1 row) -- $setIsSubset operator: Negative Cases : select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[],[]]} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 3 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1,2,3]} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 3 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : []} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 0 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1]} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [null]} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1,2]} }'); ERROR: Both operands used with $setIsSubset should be arrays, but the first provided argument is of type: int select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1],2]} }'); ERROR: Both operands in $setIsSubset must be arrays, but the second operand provided is of type: int select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : null} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : [[1,2,3],null]} }'); ERROR: Both operands in $setIsSubset must be arrays, but the second operand provided is of type: null select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : [[1,2,3],"$a"]} }'); ERROR: Both operands in $setIsSubset must be arrays, but the second operand provided is of type: missing select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : ["$a",[1,2,3]]} }'); ERROR: Both operands used with $setIsSubset should be arrays, but the first provided argument is of type: missing select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : { "$undefined" : true}} }'); ERROR: The expression $setIsSubset requires exactly 2 arguments, but 1 arguments were actually provided. --$allElementsTrue : Test for True Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true,true]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1,"app", 11.2, {"$numberLong":"10"}, {"$numberDouble":"10"}, {"$numberDecimal":"10"}, [1,2,3], {"X": "Y"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a" : 1, "b" : "test"}', '{"result": { "$allElementsTrue": [["$a", "$b"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDouble" : "0.1"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDecimal" : "0.1"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[-1, -2.9, {"$numberDecimal" : "0.1"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1, {"$add": [0,1]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) --$allElementsTrue : Test for False Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true,false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, 0, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, null, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, "$b", 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$undefined" : true}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDouble" : "0.0"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDecimal" : "0.0"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberLong" : "0"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[false, 0, 0, 1]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1, {"$add": [0,0]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) --$allElementsTrue : Negative Test SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [1]}}'); ERROR: The argument provided for $allElementsTrue must be of array type, yet it is actually int. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": ["a"]}}'); ERROR: The argument provided for $allElementsTrue must be of array type, yet it is actually string. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [null]}}'); ERROR: The argument provided for $allElementsTrue must be of array type, yet it is actually null. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [{"$undefined" : true}]}}'); ERROR: The argument provided for $allElementsTrue must be of array type, yet it is actually undefined. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1,2,3],[3,4,5]]}}'); ERROR: The expression $allElementsTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1,2,3],1]}}'); ERROR: The expression $allElementsTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [1, [1,2,3]]}}'); ERROR: The expression $allElementsTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": ["$b"]}}'); ERROR: The argument provided for $allElementsTrue must be of array type, yet it is actually missing. --$anyElementTrue : Test for True Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true,false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,true,false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,false,null,"$b",{"$undefined": true}, true]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1,"app", 11.2, {"$numberLong":"10"}, {"$numberDouble":"10"}, {"$numberDecimal":"10"}, [1,2,3], {"X": "Y"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{"a" : 1, "b" : "test"}', '{"result": { "$anyElementTrue": [["$a", "$b"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1, {"$numberDouble" : "0.1"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1, {"$numberDecimal" : "0.1"}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 1, {"$undefined" : true}, 10]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, null, {"$numberDouble" : "0.1"}, 0]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, "$b", {"$numberDecimal" : "1.0"}, 0]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, {"$numberLong" : "1"}, 0]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0, {"$add": [0,1]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) --$anyElementTrue : Test for False Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false,false]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,false,null,"$b",{"$undefined": true}, {"$numberDecimal" : "0.0"}, {"$numberDouble" : "0.0"}, {"$numberLong" : "0"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, {"$undefined" : true}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, {"$numberDouble" : "0.0"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false,{"$numberDecimal" : "0.0"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, {"$numberLong" : "0"}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, null]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0, {"$add": [0,0]}]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) --$anyElementTrue : Negative Test SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [1]}}'); ERROR: The argument provided for $anyElementTrue must be of array type, yet it is actually int. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": ["a"]}}'); ERROR: The argument provided for $anyElementTrue must be of array type, yet it is actually string. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [null]}}'); ERROR: The argument provided for $anyElementTrue must be of array type, yet it is actually null. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [{"$undefined" : true}]}}'); ERROR: The argument provided for $anyElementTrue must be of array type, yet it is actually undefined. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[1,2,3],[3,4,5]]}}'); ERROR: The expression $anyElementTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[1,2,3],1]}}'); ERROR: The expression $anyElementTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [1, [1,2,3]]}}'); ERROR: The expression $anyElementTrue requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": ["$b"]}}'); ERROR: The argument provided for $anyElementTrue must be of array type, yet it is actually missing. bson_aggregation_stage_addfield_tests.out000066400000000000000000000646571507310017400402770ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 310000; SET documentdb.next_collection_id TO 3100; SET documentdb.next_collection_index_id TO 3100; SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 3100 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } 3100 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 3100 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- add newField SELECT bson_dollar_add_fields(document, '{ "newField" : "1", "a.y": ["p", "q"]}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } (3 rows) -- add field that evaluates $_id SELECT bson_dollar_add_fields(document, '{ "newField" : "3", "a": "$_id"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : "1", "newField" : "3" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : "2", "newField" : "3" } { "_id" : "3", "boolean" : false, "a" : "3", "b" : "yes", "c" : true, "newField" : "3" } (3 rows) -- Add integer field (note that, {"field" : 1} is treated as inclusion for $project but add for $addFields) SELECT bson_dollar_add_fields(document, '{ "int" : 1, "doble": 2.0, "bool": false, "a.d": false, "a.b.c": "$_id"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "1" }, "a" : { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ], "d" : false }, "doble" : { "$numberDouble" : "2.0" }, "bool" : false } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "2" }, "d" : false }, "int" : { "$numberInt" : "1" }, "doble" : { "$numberDouble" : "2.0" }, "bool" : false } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "int" : { "$numberInt" : "1" }, "doble" : { "$numberDouble" : "2.0" }, "bool" : false, "a" : { "d" : false, "b" : { "c" : "3" } } } (3 rows) -- addFields array duplication -- Expected value of the field "a" of dco(id=1), after the following addField: { "a.b.c": "_"} is: -- "a": {"b" : ["c" : "-", "c" : "-","c" : "-","c" : "-",]} SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "-"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "-" }, { "c" : "-" }, { "c" : "-" }, { "c" : "-" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "-" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "-" } } } (3 rows) -- addFields intege in a nested paths SELECT bson_dollar_add_fields(document, '{ "a" : {"b" : 1}}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "$numberInt" : "1" } } } (3 rows) -- addFields intege in a nested paths SELECT bson_dollar_add_fields(document, '{ "a" : {"b" : { "d": 2.5}}}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" }, "d" : { "$numberDouble" : "2.5" } } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "d" : { "$numberDouble" : "2.5" } } } } (3 rows) -- addFileds to check the a.b field of doc(id=2) changes -- from: {"a" : { "b" : {"c": 3}} -- to: "a" : { "b" : {"c": 3, "d": "-"} SELECT bson_dollar_add_fields(document, '{ "a.b.d" : "-"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "d" : "-" }, { "d" : "-" }, { "d" : "-" }, { "d" : "-" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" }, "d" : "-" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "d" : "-" } } } (3 rows) -- addFields: Applying multiple expressions with overlapping field paths SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "_c", "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "_c", "d" : "_d", "e" : "_e" } } } (3 rows) -- addFields: Applying multiple expressions with overlapping field paths SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "$_id", "a.b.d" : "$b", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "2", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "3", "d" : "yes", "e" : "_e" } } } (3 rows) -- addFields: If matching subpath in a document has an array, remaining path of the addFields spec tree is duplicated for all array elelemnts. Remain subpath may need recursion. SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } } } (3 rows) -- addFields where "$a.b" needs to be evaluated while writing a path SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "$a.b", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "d" : { "e" : { "c" : { "$numberInt" : "3" } } } }, "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : { "d" : { } }, "d" : "_d", "e" : "_e" } } } (3 rows) -- Evaluating array of expessions i.e., : [, ] is not a documented behavior SELECT bson_dollar_add_fields(document, '{ "newarray" : [{ "$literal": 1.0 }, {"copyId": "$_id"}]}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "1" } ] } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "2" } ] } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "3" } ] } (3 rows) -- add newField with concatArrays SELECT bson_dollar_add_fields(document, '{ "newField" : "1", "a.b": {"$concatArrays" : [[7], [8], [9]]}}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } } (3 rows) SELECT bson_dollar_add_fields(document, '{ "_id" : false}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : false, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : false, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : false, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_add_fields(document, '{ "_id" : 121}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "121" }, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : { "$numberInt" : "121" }, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : { "$numberInt" : "121" }, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_add_fields(document, '{ "_id" : 212.2}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "212.19999999999998863" }, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : { "$numberDouble" : "212.19999999999998863" }, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : { "$numberDouble" : "212.19999999999998863" }, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_add_fields(document, '{ "_id" : "someString"}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "someString", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "someString", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "someString", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- path collision tests SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "_c", "a.b.c" : "_d"}') FROM documentdb_api.collection('db', 'addFieldOps'); ERROR: Collision detected in specified path a.b.c SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "_c", "a.b" : "_d"}') FROM documentdb_api.collection('db', 'addFieldOps'); ERROR: Collision detected in specified path a.b SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path a.b.c remaining portion b.c SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path b SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path b SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : 1.0}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path c SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : "$a.b"}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path c SELECT bson_dollar_add_fields(document, '{"a.b.c": "$_id", "a.b": "1.0"}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path a.b SELECT bson_dollar_add_fields(document, '{"a" : { "b" : { "c": { "d": "$_id"}}}, "a.b": {"c" : 1.0}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; ERROR: Collision detected in specified path c -- Array Expression and Nested Expression evaluation tests SELECT bson_dollar_add_fields(document, '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "new" : [ "1" ] } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "new" : [ "2" ] } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "new" : [ "3" ] } (3 rows) SELECT bson_dollar_add_fields(document, '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "new" : [ { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } ] } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "new" : [ { "b" : { "c" : { "$numberInt" : "3" } } } ] } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "new" : [ "no" ] } (3 rows) SELECT bson_dollar_add_fields(document, '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "new" : [ [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] ] } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "new" : [ { "c" : { "$numberInt" : "3" } } ] } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "new" : [ null ] } (3 rows) SELECT bson_dollar_add_fields(document, '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "new" : { "val" : [ [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "new" : { "val" : [ { "c" : { "$numberInt" : "3" } } ] } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "new" : { "val" : [ null ] } } (3 rows) SELECT bson_dollar_add_fields(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'addFieldOps'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "field" : true } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "field" : false } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "field" : false } (3 rows) -- Spec trees are equivalent SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : "value"}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "value" }, { "c" : "value" }, { "c" : "value" }, { "c" : "value" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "value" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "value" } } } (3 rows) SELECT bson_dollar_add_fields(document, '{"a.b.c": "value"}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "value" }, { "c" : "value" }, { "c" : "value" }, { "c" : "value" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "value" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "value" } } } (3 rows) -- Test nested array projections SELECT bson_dollar_add_fields('{"_id":"1", "a" : [1, {"d":1}, [3, 4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "c" : { "d" : "1" } }, { "d" : { "$numberInt" : "1" }, "c" : { "d" : "1" } }, [ { "c" : { "d" : "1" } }, { "c" : { "d" : "1" } } ], { "c" : { "d" : "1" } } ] } (1 row) SELECT bson_dollar_add_fields('{"_id":"1", "a" : [1, {"d":1}, [ { "c" : { "b" : 1 } },4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "c" : { "d" : "1" } }, { "d" : { "$numberInt" : "1" }, "c" : { "d" : "1" } }, [ { "c" : { "b" : { "$numberInt" : "1" }, "d" : "1" } }, { "c" : { "d" : "1" } } ], { "c" : { "d" : "1" } } ] } (1 row) -- Empty spec is a no-op according to 4.4.13\jstests\aggregation\sources\addFields\use_cases.js SELECT bson_dollar_add_fields(document, '{}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) bson_aggregation_stage_bucket_tests.out000066400000000000000000000556071507310017400400130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5120000; SET documentdb.next_collection_id TO 51200; SET documentdb.next_collection_index_id TO 51200; -- Insert data SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 1, "product" : "almonds", "pricing" : { "bulk": 10, "store": 15 }, "stock" : 2, "year": 2020 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 2, "product" : "peach", "pricing" : { "bulk": 10, "store": 9 }, "stock" : 1, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 3, "product" : "banana", "pricing" : { "bulk": 10, "store": 15 }, "stock" : 5 , "year": 2020}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 4, "product" : "melon", "pricing" : { "bulk": 4, "store": 10 }, "stock" : 3 , "year": 2022}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 5, "product" : "banana", "pricing" : { "bulk": 75, "store": 100 }, "stock" : 1, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 6, "product" : "banana", "pricing" : { "bulk": 75, "store": 100 }, "stock" : 1, "year": 2021 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 7, "product" : "banana", "pricing" : { "store": 15, "bulk": 10 }, "stock" : 1, "year": 2020 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- positive cases: -- $bucket with only required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2022" }, "count" : { "$numberInt" : "1" } } (3 rows) -- $bucket with default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" } } { "_id" : "others", "count" : { "$numberInt" : "1" } } (3 rows) -- $bucket with output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2022" }, "count" : { "$numberInt" : "1" }, "averageStock" : { "$numberDouble" : "3.0" } } (3 rows) -- $bucket with output fields and default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "1.0" } } { "_id" : "others", "count" : { "$numberInt" : "1" }, "averageStock" : { "$numberDouble" : "3.0" } } (3 rows) -- $bucket with nested field path in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$pricing.bulk", "boundaries": [10, 20, 30], "default": "unknown" } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "count" : { "$numberInt" : "4" } } { "_id" : "unknown", "count" : { "$numberInt" : "3" } } (2 rows) -- $bucket with expression in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": { "$subtract": ["$year", 2019] }, "boundaries": [1, 2, 3, 4] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "count" : { "$numberInt" : "1" } } (3 rows) -- $bucket with another stage before it SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "2" } } (2 rows) -- $bucket without count in output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "averageStock": { "$avg": "$stock" }, "totalStock": { "$sum": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" }, "totalStock" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "2021" }, "averageStock" : { "$numberDouble" : "1.0" }, "totalStock" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2022" }, "averageStock" : { "$numberDouble" : "3.0" }, "totalStock" : { "$numberInt" : "3" } } (3 rows) -- $bucket with default value equals to the highest boundaries value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2021 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "4" } } (2 rows) -- groupBy non-integar field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$product", "boundaries": ["a", "c", "n"], "default": "others" } } ] }'); document --------------------------------------------------------------------- { "_id" : "a", "count" : { "$numberInt" : "5" } } { "_id" : "c", "count" : { "$numberInt" : "1" } } { "_id" : "others", "count" : { "$numberInt" : "1" } } (3 rows) -- groupBy array or document field SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 1, "valueArray" : [1, 2, 3], "valueDocument" : { "a": 1, "b": 2 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 2, "valueArray" : [4, 5, 6], "valueDocument" : { "a": 3, "b": 4 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 3, "valueArray" : [9, 8], "valueDocument" : { "a": 5, "b": 6 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketGroupBy", "pipeline": [ { "$bucket": { "groupBy": "$valueArray", "boundaries": [[0], [5], [10]] } } ] }'); document --------------------------------------------------------------------- { "_id" : [ { "$numberInt" : "0" } ], "count" : { "$numberInt" : "2" } } { "_id" : [ { "$numberInt" : "5" } ], "count" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketGroupBy", "pipeline": [ { "$bucket": { "groupBy": "$valueDocument", "boundaries": [{"a": 0}, {"a": 5}, {"a": 10}] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "a" : { "$numberInt" : "0" } }, "count" : { "$numberInt" : "2" } } { "_id" : { "a" : { "$numberInt" : "5" } }, "count" : { "$numberInt" : "1" } } (2 rows) -- negative cases, validations: -- required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "boundaries": [2020, 2021,2022,2023] } } ] }'); ERROR: The $bucket stage requires both 'groupBy' and 'boundaries' fields to be explicitly defined. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year"} } ] }'); ERROR: The $bucket stage requires both 'groupBy' and 'boundaries' fields to be explicitly defined. -- groupBy must be a path with prefix $ or expression SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); ERROR: $bucket was unable to locate a matching bucket for the provided input value "year", and no default bucket was defined. -- boundaries is acsending constant array, more than one element, same type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": 2020 } } ] }'); ERROR: The $bucket 'boundaries' field is required to be an array containing values, but instead it was found to be: int SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020] } } ] }'); ERROR: The $bucket 'boundaries' field requires a minimum of 2 values, but it detected: 1 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2020, 2022, 2023] } } ] }'); ERROR: The $bucket 'boundaries' field must be provided as an array containing values arranged in ascending order. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 1999, 2023] } } ] }'); ERROR: The $bucket 'boundaries' field must be provided as an array containing values arranged in ascending order. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, "a", 2022, 2023] } } ] }'); ERROR: The $bucket 'boundaries' field is required to be an array containing values that share the same data type. Detected differing types: int and string -- default must be a constant, the default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value, if having same type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "$pricing" } } ] }'); ERROR: The $bucket stage 'default' field needs to be a fixed constant value. Input provided: "$pricing" SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2020 } } ] }'); ERROR: The $bucket 'default' field should be either smaller than the minimum boundary value or greater than or equal to the maximum boundary value. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2022, 2023], "default": 2021 } } ] }'); ERROR: The $bucket 'default' field should be either smaller than the minimum boundary value or greater than or equal to the maximum boundary value. -- output must be document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "output": 1 } } ] }'); ERROR: The 'output' field in the $bucket must be a document type, but a different type was encountered: int -- More validations -- unknown argument of $bucket SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "averageStock": { "$avg": "$stock" }}, "unknown": 1 } } ] }'); ERROR: Unrecognized option to $bucket: unknown -- document cannot fall into any bucket with no default being set. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021] } } ] }'); ERROR: $bucket was unable to locate a matching bucket for the provided input value 2021, and no default bucket was defined. -- sharded collection SELECT documentdb_api.shard_collection('db', 'dollarBucket', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- $bucket with only required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "count" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } (3 rows) -- $bucket with default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others" } } ] }'); document --------------------------------------------------------------------- { "_id" : "others", "count" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } (3 rows) -- $bucket with output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "count" : { "$numberInt" : "1" }, "averageStock" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" } } (3 rows) -- $bucket with output fields and default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : "others", "count" : { "$numberInt" : "1" }, "averageStock" : { "$numberDouble" : "3.0" } } { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" } } (3 rows) -- $bucket with nested field path in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$pricing.bulk", "boundaries": [10, 20, 30], "default": "unknown" } } ] }'); document --------------------------------------------------------------------- { "_id" : "unknown", "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "10" }, "count" : { "$numberInt" : "4" } } (2 rows) -- $bucket with expression in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": { "$subtract": ["$year", 2019] }, "boundaries": [1, 2, 3, 4] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "count" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "count" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" }, "count" : { "$numberInt" : "3" } } (3 rows) -- $bucket with another stage before it SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "2" } } (2 rows) -- $bucket without count in output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "averageStock": { "$avg": "$stock" }, "totalStock": { "$sum": "$stock" } } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2022" }, "averageStock" : { "$numberDouble" : "3.0" }, "totalStock" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2021" }, "averageStock" : { "$numberDouble" : "1.0" }, "totalStock" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2020" }, "averageStock" : { "$numberDouble" : "2.6666666666666665186" }, "totalStock" : { "$numberInt" : "8" } } (3 rows) -- $bucket with default value equals to the highest boundaries value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2021 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2021" }, "count" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2020" }, "count" : { "$numberInt" : "3" } } (2 rows) -- groupBy non-integar field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$product", "boundaries": ["a", "c", "n"], "default": "others" } } ] }'); document --------------------------------------------------------------------- { "_id" : "others", "count" : { "$numberInt" : "1" } } { "_id" : "a", "count" : { "$numberInt" : "5" } } { "_id" : "c", "count" : { "$numberInt" : "1" } } (3 rows) bson_aggregation_stage_facet_tests.out000066400000000000000000000326461507310017400376160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9610000; SET documentdb.next_collection_id TO 961000; SET documentdb.next_collection_index_id TO 961000; -- Insert data SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 1, "product" : "beer", "unitPrice" : 12, "stock" : 2 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 2, "product" : "red wine", "unitPrice" : 20, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 3, "product" : "bread", "unitPrice" : 10, "stock" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 4, "product" : ["beer", "bread", "red wine"], "unitPrice" : 10, "stock" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 5, "product" : "beer", "unitPrice" : 12, "stock" : 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 6, "product" : "red wine", "unitPrice" : 20, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 7, "product" : "bread", "unitPrice" : 10, "stock" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 8, "product" : ["beer", "bread", "red wine"], "unitPrice" : 10, "stock" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test filter generation empty input SELECT bson_array_agg(document, 'myarray'::text) FROM documentdb_api.collection('db', 'facet1'); bson_array_agg --------------------------------------------------------------------- (1 row) -- Test filter generation SELECT bson_array_agg(document, 'myarray'::text) FROM documentdb_api.collection('db', 'facetTest'); bson_array_agg --------------------------------------------------------------------- { "myarray" : [ { "_id" : { "$numberInt" : "1" }, "product" : "beer", "unitPrice" : { "$numberInt" : "12" }, "stock" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "2" }, "product" : "red wine", "unitPrice" : { "$numberInt" : "20" }, "stock" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "3" }, "product" : "bread", "unitPrice" : { "$numberInt" : "10" }, "stock" : { "$numberInt" : "5" } }, { "_id" : { "$numberInt" : "4" }, "product" : [ "beer", "bread", "red wine" ], "unitPrice" : { "$numberInt" : "10" }, "stock" : { "$numberInt" : "5" } }, { "_id" : { "$numberInt" : "5" }, "product" : "beer", "unitPrice" : { "$numberInt" : "12" }, "stock" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "6" }, "product" : "red wine", "unitPrice" : { "$numberInt" : "20" }, "stock" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "7" }, "product" : "bread", "unitPrice" : { "$numberInt" : "10" }, "stock" : { "$numberInt" : "5" } }, { "_id" : { "$numberInt" : "8" }, "product" : [ "beer", "bread", "red wine" ], "unitPrice" : { "$numberInt" : "10" }, "stock" : { "$numberInt" : "5" } } ] } (1 row) SELECT bson_object_agg(document) FROM documentdb_api.collection('db', 'facetTest'); bson_object_agg --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "product" : [ "beer", "bread", "red wine" ], "unitPrice" : { "$numberInt" : "10" }, "stock" : { "$numberInt" : "5" } } (1 row) -- Test full facetSQL sql WITH "stage0" as ( SELECT documentdb_api_catalog.bson_dollar_add_fields(document, '{ "name" : { "$numberInt" : "1" } }'::bson) as document FROM documentdb_api.collection('db', 'facetTest') ), "stage1" as ( WITH FacetStage AS ( WITH "FacetStage00" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONFIRSTONSORTED( bson_expression_get(document, '{ "$first" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage01" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'first':: text, "acc0" ) AS document FROM "FacetStage00" ), "FacetStage10" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONLASTONSORTED( bson_expression_get(document, '{ "$last" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage11" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'last':: text, "acc0" ) AS document FROM "FacetStage10" ) select bson_array_agg(document :: bytea, 'facet1' :: text) as facet_row from "FacetStage01" UNION ALL select bson_array_agg(document :: bytea, 'facet2' :: text) as facet_row from "FacetStage11" ) SELECT bson_dollar_facet_project(bson_object_agg(facet_row), true) FROM FacetStage ) SELECT * from "stage1"; bson_dollar_facet_project --------------------------------------------------------------------- { "facet1" : [ { "_id" : { "$numberInt" : "10" }, "first" : { "$numberInt" : "5" } }, { "_id" : { "$numberInt" : "12" }, "first" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "20" }, "first" : { "$numberInt" : "1" } } ], "facet2" : [ { "_id" : { "$numberInt" : "10" }, "last" : { "$numberInt" : "5" } }, { "_id" : { "$numberInt" : "12" }, "last" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "20" }, "last" : { "$numberInt" : "1" } } ] } (1 row) -- Test full facetSQL sql BEGIN; set local parallel_tuple_cost TO 0.00001; set local parallel_setup_cost TO 0; set local min_parallel_table_scan_size TO 0; set local min_parallel_index_scan_size TO 0; set local max_parallel_workers to 4; set local max_parallel_workers_per_gather to 4; set local max_parallel_maintenance_workers to 4; set local enable_seqscan TO off; SET JIT To off; EXPLAIN(costs off) WITH "stage0" as ( SELECT documentdb_api_catalog.bson_dollar_add_fields(document, '{ "name" : { "$numberInt" : "1" } }'::bson) as document FROM documentdb_api.collection('db', 'facetTest') ), "stage1" as ( WITH FacetStage AS ( WITH "FacetStage00" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONFIRSTONSORTED( bson_expression_get(document, '{ "$first" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage01" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'first':: text, "acc0" ) AS document FROM "FacetStage00" ), "FacetStage10" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONLASTONSORTED( bson_expression_get(document, '{ "$last" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage11" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'last':: text, "acc0" ) AS document FROM "FacetStage10" ) select bson_array_agg(document :: bytea, 'facet1' :: text) as facet_row from "FacetStage01" UNION ALL select bson_array_agg(document :: bytea, 'facet2' :: text) as facet_row from "FacetStage11" ) SELECT bson_dollar_facet_project(bson_object_agg(facet_row), true) FROM FacetStage ) SELECT * from "stage1" ROLBACK; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Gather Workers Planned: 2 -> Parallel Append -> Aggregate -> GroupAggregate Group Key: (documentdb_api_catalog.bson_expression_get(collection.document, '{ "_id" : "$unitPrice" }'::documentdb_core.bson, true)) -> Sort Sort Key: (documentdb_api_catalog.bson_expression_get(collection.document, '{ "_id" : "$unitPrice" }'::documentdb_core.bson, true)) -> Bitmap Heap Scan on documents_961000_9610003 collection Recheck Cond: (shard_key_value = '961000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '961000'::bigint) -> Aggregate -> GroupAggregate Group Key: (documentdb_api_catalog.bson_expression_get(collection_1.document, '{ "_id" : "$unitPrice" }'::documentdb_core.bson, true)) -> Sort Sort Key: (documentdb_api_catalog.bson_expression_get(collection_1.document, '{ "_id" : "$unitPrice" }'::documentdb_core.bson, true)) -> Bitmap Heap Scan on documents_961000_9610003 collection_1 Recheck Cond: (shard_key_value = '961000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '961000'::bigint) (27 rows) bson_aggregation_stage_index_stats.out000066400000000000000000000237011507310017400376270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 385000; SET documentdb.next_collection_id TO 3850; SET documentdb.next_collection_index_id TO 3850; CREATE OR REPLACE FUNCTION query_and_flush(field text) RETURNS bson set enable_seqscan to false AS $$ DECLARE docText bson; BEGIN SELECT cursorPage INTO docText FROM documentdb_api.aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "indexstats1", "pipeline": [ { "$match": { "%s": { "$gt": 500 } } }, { "$count": "c" } ], "cursor": {} }', field)::documentdb_core.bson); IF VERSION() LIKE 'PostgreSQL 14%' THEN PERFORM pg_sleep(3); ELSE PERFORM pg_stat_force_next_flush(); END IF; RETURN docText; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.drop_collection('db', 'indexstats1'); drop_collection --------------------------------------------------------------------- f (1 row) -- fails on non existent collection SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- (0 rows) -- Create Collection SELECT documentdb_api.create_collection('db', 'indexstats1'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- { "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "0" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } } (1 row) -- Add 1000 docs SELECT COUNT(*) FROM (SELECT documentdb_api.insert_one('db','indexstats1',FORMAT('{ "a" : %s, "_id": %s }', i, i)::bson, NULL) FROM generate_series(1, 10000) i) ins; count --------------------------------------------------------------------- 10000 (1 row) -- create index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexstats1", "indexes": [ { "key": { "a": 1 }, "name": "a_1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- { "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "0" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } } { "name" : "a_1", "key" : { "a" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "0" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1" } } (2 rows) -- query using index. SELECT query_and_flush('_id'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT query_and_flush('_id'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT query_and_flush('a'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- { "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "2" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } } { "name" : "a_1", "key" : { "a" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "1" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1" } } (2 rows) -- shard SELECT documentdb_api.shard_collection('db', 'indexstats1', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- { "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "0" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } } { "name" : "a_1", "key" : { "a" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "0" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1" } } (2 rows) -- query using index. SELECT query_and_flush('_id'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT query_and_flush('_id'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT query_and_flush('a'); query_and_flush --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.indexstats1", "firstBatch" : [ { "c" : { "$numberInt" : "9500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); document --------------------------------------------------------------------- { "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "16" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } } { "name" : "a_1", "key" : { "a" : { "$numberInt" : "1" } }, "accesses" : { "ops" : { "$numberLong" : "8" } }, "spec" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1" } } (2 rows) -- invalid cases SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": { "a": 1 } }, { "$project": { "accesses.since": 0 }} ]}'); ERROR: The $indexStats stage specification is required to be provided as an empty object. SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$match": { "a": 1 } }, { "$indexStats": { } }, { "$project": { "accesses.since": 0 }} ]}'); ERROR: The $indexStats operator can only be used as the initial stage in the pipeline. bson_aggregation_stage_inversematch_tests.out000066400000000000000000001723561507310017400412270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9630000; SET documentdb.next_collection_id TO 963000; SET documentdb.next_collection_index_id TO 963000; -- Insert data SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 1, "city_id": 101, "city": "Beijing", "province": "Beijing", "airport": "Beijing Capital", "policy": { "flight_type": "domestic"} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 2, "city_id": 102, "city": "Shanghai", "province": "Shanghai", "airport": "Pudong International", "policy": { "$or": [ { "origin": "Guangdong"}, {"flight_type": "domestic"}] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 3, "city_id": 103, "city": "Guangzhou", "province": "Guangdong", "airport": "Baiyun International", "policy": { "$in": [{"is_emergency": true}, {"is_vip": true}] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 4, "city_id": 104, "city": "Shenzhen", "province": "Guangdong", "airport": "Baoan International", "policy": { "$or": [ {"$and": [{"flight_type": "domestic"}, {"origin": "Guangdong"}]}, {"$or": [{"is_emergency": true}, {"is_vip": true}]} ] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 5, "city_id": 105, "city": "Chengdu", "province": "Sichuan", "airport": "Shuangliu International", "policy": { "tags": { "$all": ["domestic", "vip"]}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- positive cases SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Beijing"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "international"}}}]}'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Beijing"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "domestic"}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "city_id" : { "$numberInt" : "101" }, "city" : "Beijing", "province" : "Beijing", "airport" : "Beijing Capital", "policy" : { "flight_type" : "domestic" } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Shanghai"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "international"}}}]}'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Shanghai"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "domestic"}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "city_id" : { "$numberInt" : "102" }, "city" : "Shanghai", "province" : "Shanghai", "airport" : "Pudong International", "policy" : { "$or" : [ { "origin" : "Guangdong" }, { "flight_type" : "domestic" } ] } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": {"is_emergency": true}}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "city_id" : { "$numberInt" : "103" }, "city" : "Guangzhou", "province" : "Guangdong", "airport" : "Baiyun International", "policy" : { "$in" : [ { "is_emergency" : true }, { "is_vip" : true } ] } } { "_id" : { "$numberInt" : "4" }, "city_id" : { "$numberInt" : "104" }, "city" : "Shenzhen", "province" : "Guangdong", "airport" : "Baoan International", "policy" : { "$or" : [ { "$and" : [ { "flight_type" : "domestic" }, { "origin" : "Guangdong" } ] }, { "$or" : [ { "is_emergency" : true }, { "is_vip" : true } ] } ] } } (2 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "domestic", "origin": "Guangdong" }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "city_id" : { "$numberInt" : "104" }, "city" : "Shenzhen", "province" : "Guangdong", "airport" : "Baoan International", "policy" : { "$or" : [ { "$and" : [ { "flight_type" : "domestic" }, { "origin" : "Guangdong" } ] }, { "$or" : [ { "is_emergency" : true }, { "is_vip" : true } ] } ] } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "international", "origin": "Guangdong" }}}]}'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "domestic", "origin": "Guangdong", "is_vip": true }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "city_id" : { "$numberInt" : "104" }, "city" : "Shenzhen", "province" : "Guangdong", "airport" : "Baoan International", "policy" : { "$or" : [ { "$and" : [ { "flight_type" : "domestic" }, { "origin" : "Guangdong" } ] }, { "$or" : [ { "is_emergency" : true }, { "is_vip" : true } ] } ] } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": [{ "flight_type": "domestic"}, {"is_emergency": true}]}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "city_id" : { "$numberInt" : "103" }, "city" : "Guangzhou", "province" : "Guangdong", "airport" : "Baiyun International", "policy" : { "$in" : [ { "is_emergency" : true }, { "is_vip" : true } ] } } { "_id" : { "$numberInt" : "4" }, "city_id" : { "$numberInt" : "104" }, "city" : "Shenzhen", "province" : "Guangdong", "airport" : "Baoan International", "policy" : { "$or" : [ { "$and" : [ { "flight_type" : "domestic" }, { "origin" : "Guangdong" } ] }, { "$or" : [ { "is_emergency" : true }, { "is_vip" : true } ] } ] } } (2 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "tags": ["domestic", "vip"]}}}]}'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "city_id" : { "$numberInt" : "102" }, "city" : "Shanghai", "province" : "Shanghai", "airport" : "Pudong International", "policy" : { "$or" : [ { "origin" : "Guangdong" }, { "flight_type" : "domestic" } ] } } (1 row) -- Validate errors SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"pathRule": "policy", "input": {"flight_type": "domestic"} }}]}'); ERROR: Unrecognized parameter supplied to $inverseMatch: 'pathRule' SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "inputValue": {"flight_type": "domestic"} }}]}'); ERROR: Unrecognized parameter supplied to $inverseMatch: 'inputValue' SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "", "input": {"flight_type": "domestic"} }}]}'); ERROR: Path parameter is missing for the operator $inverseMatch SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "input": ["flight_type", "domestic"] }}]}'); ERROR: $inverseMatch requires that if 'input' is an array its contents be documents, found: string SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "input": [{"flight_type": "domestic"}, ""] }}]}'); ERROR: $inverseMatch requires that if 'input' is an array its contents be documents, found: string SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": [{"path": "policy", "input": [{"flight_type": "domestic"}, ""] }, {"path": "policy2", "input": {}}]}]}'); ERROR: $inverseMatch requires a document as an input instead got: array -- insert a document with an invalid query SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 6, "city_id": 106, "city": "Hangzhou", "province": "Zhejiang", "airport": "Hangzhou Xiaoshan International", "specialPolicy": { "tags": { "$allValues": ["domestic", "vip"]}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- any inverseMatch that queries that path should fail SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "specialPolicy", "input": { "origin": "Guangdong" }, "defaultResult": false}}]}'); ERROR: Unrecognized operator specified: $allValues -- if we query "policy" path without defaultResult in the spec it should not match for the Hangzhou city which doesn't define the policy as the default value is false SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "city_id" : { "$numberInt" : "102" }, "city" : "Shanghai", "province" : "Shanghai", "airport" : "Pudong International", "policy" : { "$or" : [ { "origin" : "Guangdong" }, { "flight_type" : "domestic" } ] } } (1 row) -- with defaultResult true should return all documents that don't define the path and false shouldn't return them SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }, "defaultResult": true}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "city_id" : { "$numberInt" : "102" }, "city" : "Shanghai", "province" : "Shanghai", "airport" : "Pudong International", "policy" : { "$or" : [ { "origin" : "Guangdong" }, { "flight_type" : "domestic" } ] } } { "_id" : { "$numberInt" : "6" }, "city_id" : { "$numberInt" : "106" }, "city" : "Hangzhou", "province" : "Zhejiang", "airport" : "Hangzhou Xiaoshan International", "specialPolicy" : { "tags" : { "$allValues" : [ "domestic", "vip" ] } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }, "defaultResult": false}}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "city_id" : { "$numberInt" : "102" }, "city" : "Shanghai", "province" : "Shanghai", "airport" : "Pudong International", "policy" : { "$or" : [ { "origin" : "Guangdong" }, { "flight_type" : "domestic" } ] } } (1 row) -- add tests with lookup for RBAC "like" scenarios SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 1, "user_id": 100, "roles": ["basic"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 2, "user_id": 101, "roles": ["basic", "sales"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 3, "user_id": 102, "roles": ["admin"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 1, "order": 100, "paid": true, "total": 0, "rule": {"roles": {"$in": ["basic", "sales", "admin"]}}}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 2, "order": 102, "paid": true, "total": 1000, "rule": {"roles": {"$in": ["sales", "admin"]}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 3, "order": 103, "paid": true, "total": 1000, "rule": {"roles": {"$in": ["admin"]}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 100} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 101} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 102} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" } } (3 rows) -- use from collection instead of lookup (new feature) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 101}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}, {"$project": {"roles": 1, "_id": 0}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lt": 102 }}}, {"$limit": 1}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lte": 102 }}}, {"$limit": 2}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_963003_9630006 collection WHERE (documentdb_api_internal.bson_dollar_inverse_match(document, (SELECT documentdb_api_internal.bson_dollar_merge_documents('{ "path" : "rule", "defaultResult" : false }'::documentdb_core.bson, (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'input'::text), '{ "input" : [ ] }'::documentdb_core.bson) AS document FROM documentdb_data.documents_963002_9630004 collection_0_1 WHERE (documentdb_api_catalog.bson_dollar_ne(collection_0_1.document, '{ "user_id" : { "$numberInt" : "200" } }'::documentdb_core.bson) AND (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '963002'::bigint)) LIMIT '1'::bigint), false) AS spec)) AND (shard_key_value OPERATOR(pg_catalog.=) '963003'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_963003_9630006 collection Output: collection.document Recheck Cond: (collection.shard_key_value = '963003'::bigint) Filter: documentdb_api_internal.bson_dollar_inverse_match(collection.document, $1) InitPlan 2 (returns $1) -> Result Output: documentdb_api_internal.bson_dollar_merge_documents('{ "path" : "rule", "defaultResult" : false }'::documentdb_core.bson, $0, false) InitPlan 1 (returns $0) -> Limit Output: (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'input'::text), '{ "input" : [ ] }'::documentdb_core.bson)) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'input'::text), '{ "input" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_963002_9630004 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '963002'::bigint) Filter: (collection_0_1.document OPERATOR(documentdb_api_catalog.@!=) '{ "user_id" : { "$numberInt" : "200" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '963002'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '963003'::bigint) (27 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}]}} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_963003_9630006 collection WHERE (documentdb_api_internal.bson_dollar_inverse_match(document, (SELECT documentdb_api_internal.bson_dollar_merge_documents('{ "path" : "rule", "defaultResult" : false }'::documentdb_core.bson, (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'input'::text), '{ "input" : [ ] }'::documentdb_core.bson) AS document FROM documentdb_data.documents_963002_9630004 collection_0_1 WHERE (documentdb_api_catalog.bson_dollar_ne(collection_0_1.document, '{ "user_id" : { "$numberInt" : "200" } }'::documentdb_core.bson) AND (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '963002'::bigint))), false) AS spec)) AND (shard_key_value OPERATOR(pg_catalog.=) '963003'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_963003_9630006 collection Output: collection.document Recheck Cond: (collection.shard_key_value = '963003'::bigint) Filter: documentdb_api_internal.bson_dollar_inverse_match(collection.document, $1) InitPlan 2 (returns $1) -> Result Output: documentdb_api_internal.bson_dollar_merge_documents('{ "path" : "rule", "defaultResult" : false }'::documentdb_core.bson, $0, false) InitPlan 1 (returns $0) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'input'::text), '{ "input" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_963002_9630004 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '963002'::bigint) Filter: (collection_0_1.document OPERATOR(documentdb_api_catalog.@!=) '{ "user_id" : { "$numberInt" : "200" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '963002'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '963003'::bigint) (25 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": {}}} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documentdb_data.documents_963003_9630006 collection Output: document Recheck Cond: (collection.shard_key_value = '963003'::bigint) Filter: bson_dollar_inverse_match(collection.document, '{ "path" : "rule", "input" : { } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '963003'::bigint) (6 rows) -- test with sharded collections. SELECT documentdb_api.shard_collection('invmatch', 'sales', '{"order": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('invmatch', 'user_roles', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 100} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 101} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 102} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" } } (3 rows) -- use from collection instead of lookup (new feature) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } (1 row) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 101}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}, {"$project": {"roles": 1, "_id": 0}}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lt": 102 }}}, {"$limit": 1}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } (2 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lte": 102 }}}, {"$limit": 2}]}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "sales", "admin" ] } } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "paid" : true, "total" : { "$numberInt" : "0" }, "rule" : { "roles" : { "$in" : [ "basic", "sales", "admin" ] } } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "103" }, "paid" : true, "total" : { "$numberInt" : "1000" }, "rule" : { "roles" : { "$in" : [ "admin" ] } } } (3 rows) -- drop and recreate so that it is not sharded and test with group and sort SELECT documentdb_api.drop_database('invmatch'); drop_database --------------------------------------------------------------------- (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 2, "user_id": 101, "role": "admin"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 1, "user_id": 100, "role": "basic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 5, "user_id": 103, "role": "basic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 3, "user_id": 102, "role": "sales"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 4, "user_id": 100, "role": "sales"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 6, "user_id": 102, "role": "admin"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 5, "order": 102, "order_total": 1000, "amount": 100, "rule": "admin"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 1, "order": 100, "order_total": 50, "amount": 20, "rule": "basic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 2, "order": 102, "order_total": 1000, "amount": 300, "rule": "sales"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 4, "order": 100, "order_total": 50, "amount": 5, "rule": "basic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 3, "order": 102, "order_total": 1000, "amount": 200, "rule": "basic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "payed" : { "$numberInt" : "25" }, "rule" : { "role" : { "$in" : [ "basic", "basic" ] } } } { "_id" : { "$numberInt" : "102" }, "payed" : { "$numberInt" : "600" }, "rule" : { "role" : { "$in" : [ "admin", "sales", "basic" ] } } } (2 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "payed" : { "$numberInt" : "600" }, "rule" : { "role" : { "$in" : [ "admin", "sales", "basic" ] } } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "payed" : { "$numberInt" : "25" }, "rule" : { "role" : { "$in" : [ "basic", "basic" ] } } } { "_id" : { "$numberInt" : "102" }, "payed" : { "$numberInt" : "600" }, "rule" : { "role" : { "$in" : [ "admin", "sales", "basic" ] } } } (2 rows) SELECT documentdb_api.drop_collection('invmatch', 'payments'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 5, "order": 102, "order_total": 1000, "amount": 100, "rule": { "role": "admin"}}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 1, "order": 100, "order_total": 50, "amount": 20, "rule": { "role": "basic"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 2, "order": 102, "order_total": 1000, "amount": 300, "rule": { "role": "sales"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 4, "order": 100, "order_total": 50, "amount": 5, "rule": { "role": "basic"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 3, "order": 102, "order_total": 1000, "amount": 200, "rule": { "role": "admin"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "rule" : { "role" : "admin" }, "payed" : { "$numberInt" : "600" } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "rule" : { "role" : "basic" }, "payed" : { "$numberInt" : "25" } } (1 row) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "rule" : { "role" : "basic" }, "payed" : { "$numberInt" : "25" } } { "_id" : { "$numberInt" : "102" }, "rule" : { "role" : "admin" }, "payed" : { "$numberInt" : "600" } } (2 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "order_total" : { "$numberInt" : "50" }, "amount" : { "$numberInt" : "20" }, "rule" : { "role" : "basic" } } { "_id" : { "$numberInt" : "4" }, "order" : { "$numberInt" : "100" }, "order_total" : { "$numberInt" : "50" }, "amount" : { "$numberInt" : "5" }, "rule" : { "role" : "basic" } } { "_id" : { "$numberInt" : "5" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "100" }, "rule" : { "role" : "admin" } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "300" }, "rule" : { "role" : "sales" } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "200" }, "rule" : { "role" : "admin" } } (5 rows) SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": -1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "100" }, "rule" : { "role" : "admin" } } { "_id" : { "$numberInt" : "2" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "300" }, "rule" : { "role" : "sales" } } { "_id" : { "$numberInt" : "3" }, "order" : { "$numberInt" : "102" }, "order_total" : { "$numberInt" : "1000" }, "amount" : { "$numberInt" : "200" }, "rule" : { "role" : "admin" } } { "_id" : { "$numberInt" : "1" }, "order" : { "$numberInt" : "100" }, "order_total" : { "$numberInt" : "50" }, "amount" : { "$numberInt" : "20" }, "rule" : { "role" : "basic" } } { "_id" : { "$numberInt" : "4" }, "order" : { "$numberInt" : "100" }, "order_total" : { "$numberInt" : "50" }, "amount" : { "$numberInt" : "5" }, "rule" : { "role" : "basic" } } (5 rows) -- negative cases SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": {}, "input": "$roles"}} ], "cursor": {} }'); ERROR: The BSON field '$inverseMatch.path' has an incorrect type 'object'; it should be of type 'string'. SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "", "input": "$roles"}} ], "cursor": {} }'); ERROR: Path parameter is missing for the operator $inverseMatch SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": [true]}} ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": true}} ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": {}, "from": "collection"}} ], "cursor": {} }'); ERROR: 'input' and 'from' can't be used together in an $inverseMatch stage. SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "collection"}} ], "cursor": {} }'); ERROR: 'pipeline' argument is required when 'from' is specified in an $inverseMatch stage. SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"rule": "rule"}} ], "cursor": {} }'); ERROR: Unrecognized parameter supplied to $inverseMatch: 'rule' SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "mycoll", "pipeline": []}} ], "cursor": {} }'); ERROR: The 'from' collection 'invmatch.mycoll' could not be found. bson_aggregation_stage_lookup_pg17_tests.out000066400000000000000000006572031507310017400407050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 60000; SET documentdb.next_collection_id TO 6000; SET documentdb.next_collection_index_id TO 6000; \i sql/bson_aggregation_stage_lookup_tests_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:4: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 4, "item_name" : ["shirt", "hat", "pants"], "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 1, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 120 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:12: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 11, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 240 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 2, "item_code" : "hat", "product_description": "product 2", "stock_quantity" : 80 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 3, "item_code" : "shoes", "product_description": "product 3", "stock_quantity" : 60 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 4, "item_code" : "pants", "product_description": "product 4", "stock_quantity" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 5, "item_code" : null, "product_description": "product 4", "stock_quantity" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 6, "item_code" : {"a": "x", "b" : 1, "c" : [1, 2, 3]}, "product_description": "complex object" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 7, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 8, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "item_code" : [ "shirt" ] } { "item_code" : [ "pants" ] } { "item_code" : [ "hat" ] } { "item_code" : [ "shirt", "hat", "pants" ] } { "item_code" : [ null ] } { "item_code" : [ { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ] } (7 rows) -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } }, { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } }, { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : [ { "_id" : { "$numberInt" : "7" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" }, { "_id" : { "$numberInt" : "8" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } ] } (7 rows) -- Create Index on catalog_items SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "catalog_items", "indexes": [ {"key": {"item_code": 1}, "name": "idx_catalog_items_item_code"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Test Index pushdown SELECT documentdb_distributed_test_helpers.drop_primary_key('db','catalog_items'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop Left Join -> Bitmap Heap Scan on documents_6000_60000 collection Recheck Cond: (shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6000'::bigint) -> Aggregate -> Seq Scan on documents_6001_60016 t2 Filter: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson)) (14 rows) ROLLBACK; -- Insert data into a new collection to be sharded (shard key can't be an array, but can be null or object) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:68: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 5, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Shard customer_purchases collection on item_name SELECT documentdb_api.shard_collection('db','customer_purchases_sharded', '{"item_name":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- Test filter generation on sharded left collection SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases_sharded'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "item_code" : [ "pants" ] } { "item_code" : [ null ] } { "item_code" : [ { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "item_code" : [ "shirt" ] } { "item_code" : [ "hat" ] } (5 rows) -- Test Index pushdown on sharded left collection BEGIN; set local enable_seqscan TO off; SET JIT To off; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) -> Distributed Subplan X_X -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_6002_60048 documents_6002 Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop Left Join -> Function Scan on read_intermediate_result intermediate_result -> Aggregate -> Seq Scan on documents_6001_60016 t2 Filter: (document OPERATOR(documentdb_api_catalog.@*=) intermediate_result.match) (18 rows) ROLLBACK; SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'customer_purchases_sharded') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- -4688595418384734640 | { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } -9153250461281815030 | { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } 4967885567985676909 | { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } -4514028574017177401 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" } } 8428415592906042960 | { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (5 rows) -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:110: ERROR: CTEs that refer to other subqueries are not supported in multi-shard queries -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } (5 rows) -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "hello" : "newsubpipelinefield" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "hello" : "newsubpipelinefield" } ] } (5 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "matched_docs" : { "hello" : "newsubpipelinefield" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } (5 rows) -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "new" : "field" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "new" : "field" } ] } (5 rows) set citus.enable_local_execution to off; -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:191: ERROR: CTEs that refer to other subqueries are not supported in multi-shard queries -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } (5 rows) -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "hello" : "newsubpipelinefield" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "hello" : "newsubpipelinefield" } ] } (5 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "matched_docs" : { "hello" : "newsubpipelinefield" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } (5 rows) -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "new" : "field" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "new" : "field" } ] } (5 rows) set citus.enable_local_execution to on; -- Test coalesce path, return empty array when no match found SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 0, "a": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:265: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 1, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 0, "b": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:268: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 1, "b": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') FROM documentdb_api.collection('db', 'coalesce_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "nonex" : [ { "$numberInt" : "1" } ] } { "nonex" : [ null ] } { "nonex" : [ null ] } (3 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') AS match FROM documentdb_api.collection('db', 'coalesce_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'coalesce_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } (3 rows) -- Test dotted path SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 0, "a": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:286: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 1, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 3, "a": {"c": 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 0, "b": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:291: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 1, "b": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 3, "b": {"c" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 4, "b": {"c" : 2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') FROM documentdb_api.collection('db', 'dotted_path_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "b.c" : [ null ] } { "b.c" : [ null ] } { "b.c" : [ null ] } { "b.c" : [ { "$numberInt" : "1" } ] } (4 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_path_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : { "c" : { "$numberInt" : "1" } }, "matched_docs" : [ { "_id" : { "$numberInt" : "3" }, "b" : { "c" : { "$numberInt" : "1" } } } ] } (4 rows) -- Empty from collection tests SELECT * FROM documentdb_api.collection('db', 'from1NonExistent'); shard_key_value | object_id | document --------------------------------------------------------------------- (0 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'from1NonExistent') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : { "c" : { "$numberInt" : "1" } }, "matched_docs" : [ ] } (4 rows) -- Dotted path on mathched array name (some.documents) SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 0, "a": {"b" : 1}}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:327: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_foreign2','{"_id": 0, "target": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:329: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source2'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "target" : [ { "$numberInt" : "1" } ] } { "target" : [ null ] } (2 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source2')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'same.documents'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_foreign2') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "b" : { "$numberInt" : "1" } }, "same" : { "documents" : [ { "_id" : { "$numberInt" : "0" }, "target" : { "$numberInt" : "1" } } ] } } { "_id" : { "$numberInt" : "1" }, "same" : { "documents" : [ ] } } (2 rows) -- Dotted path that goes through objects and arrays SELECT documentdb_api.insert_one('db','dotted_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:345: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 0}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:346: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"_id" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) -- Dotted AS path that is already present in the left document SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:353: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 1, "c": [{"d": 1}, {"d": 2}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "c.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "c.d" : [ null ] } (2 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'a.b'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_source') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : [ { "b" : [ { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ] } ] }, { "b" : [ { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ] } ] } ] } { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ], "a" : { "b" : [ { "_id" : { "$numberInt" : "0" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } ] } } (2 rows) -- (B) Lookup with pipeline support -- (B).1 Data Ingestion SELECT documentdb_api.insert_one('db','establishments',' {"_id": 1, "establishment_name": "The Grand Diner", "dishes": ["burger", "fries"], "order_quantity": 100 , "drinks": ["soda", "juice"]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:372: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','establishments','{ "_id": 2, "establishment_name": "Pizza Palace", "dishes": ["veggie pizza", "meat pizza"], "order_quantity": 120, "drinks": ["soda"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 1, "item_name": "burger", "establishment_name": "The Grand Diner"}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:375: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 2, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "water"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 3, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "soda"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (B).1 Simple Lookup with pipeline -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $match : { order_quantity : { $gt, 110}} -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } (3 rows) -- (B).2 Index creation on the from collection SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "establishments", "indexes": [ {"key": {"establishment_name": 1}, "name": "idx_establishments_establishment_name"}, {"key": {"order_quantity": 1}, "name": "idx_establishments_order_quantity"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- (B).3.a Index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_order_quantity Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) (16 rows) ROLLBACK; -- Adding a $sort in the pipeline BEGIN; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(collection_0_1.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Seq Scan on documents_6012_60207 collection_0_1 Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text)) (15 rows) ROLLBACK; BEGIN; SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } (3 rows) ROLLBACK; -- (B).3.b Index usage with optimization: (if lookup has a join condition and the lookup pipeline has $match as the first -- stage we push the $match filter up with the join. If both conditions are one same property both the filters should be -- part of the index condition) BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_establishment_name Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson))) (16 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_establishment_name Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson))) (16 rows) ROLLBACK; -- (B).4 Nested lookup pipeline (lookup pipeline containing lookup) -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $lookup : { -- from : establishments, -- to: establishments, -- localField: _id, -- foreignField: _id, -- pipeline: { -- [ -- { unwind : "dishes"} -- ] -- } -- } -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : [ "burger", "fries" ], "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : "burger", "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ] }, { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : "fries", "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ] } ] } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "veggie pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] }, { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "meat pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "veggie pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] }, { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "meat pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } ] } (3 rows) -- (B).5 Nested lookup pipeline (lookup pipeline containing lookup) index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> ProjectSet -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> ProjectSet -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (27 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "bar": "$dishes" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (25 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$sort": { "dishes": 1 } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(lookup_subpipeline_substage_1_1.lookup_unwind, '{ "dishes" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(lookup_subpipeline_substage_1.lookup_unwind, '{ "dishes" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "_id": "bar" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (25 rows) ROLLBACK; -- Lookup Tests for array index-based paths SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 1, "a" : [{"x" : 1}] }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:526: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 2, "a" : {"x" : 1} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 3, "a" : [{"x": 2}, {"x": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 4, "a" : [{"y": 1}, {"x": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 5, "a" : [2, 3] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 6, "a" : {"x": [1, 2]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 7, "a" : [{"x": 1}, {"y": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 8, "a" : [{"x": [1, 2]}, {"y": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 9, "a" : [[{"x": [1, 2]}, {"y": 1}]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_items',' { "_id" : 1, "b" : 1 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:536: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "x" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "x" : { "$numberInt" : "2" } } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "y" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "x" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.1.y"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}') AS match FROM documentdb_api.collection('db', 'array_path_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ], "matched_docs" : [ ] } (9 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"a.0.x" : "b"}') AS match FROM documentdb_api.collection('db', 'array_path_items')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_purchases') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } ] } (1 row) -- test lookup with operator type document contents SELECT documentdb_api.insert_one('db', 'operator_lookup_left', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:571: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'operator_lookup_right', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:572: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "a", "foreignField": "a", "as": "myfoo" } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } }, "myfoo" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } }, "myfoo" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } } } ] } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6016_60270 collection Recheck Cond: (shard_key_value = '6016'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6016'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6017_60286 collection_0_1 Index Cond: ((shard_key_value = '6017'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$project": { "_id": "500" }}, { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6016_60270 collection Recheck Cond: (shard_key_value = '6016'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6016'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6017_60286 collection_0_1 Index Cond: ((shard_key_value = '6017'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : "500" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "_id" : "_id" }'::documentdb_core.bson)))) (13 rows) -- Test for Index push down crash when Foreign Field = '_id' and the target collection is sharded SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 1, "item_name" : "itemA", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:582: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test','{ "_id" : 2, "item_name" : "itemE", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 3, "item_name" : "itemC", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 4, "item_name" : ["itemA", "itemC", "itemE"], "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemA", "item_description": "product 1", "in_stock" : 120 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:590: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemB", "item_description": "product 1", "in_stock" : 240 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemC", "item_description": "product 2", "in_stock" : 80 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemD", "item_description": "product 3", "in_stock" : 60 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemE", "item_description": "product 4", "in_stock" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemF", "item_description": "product 4", "in_stock" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db','items_pushdown_test', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "purchases_pushdown_test", "pipeline": [ { "$lookup": { "from": "items_pushdown_test", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "itemA", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "itemE", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "itemC", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "itemA", "itemC", "itemE" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "myBar" : { "$numberInt" : "1" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, "idx" : { "$numberLong" : "0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (7 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '$matched_docs'::text) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_2."funcName", 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind) LIMIT '10'::bigint) agg_stage_sub_1_2), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true), '$matched_docs'::text) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Limit Output: (documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) (29 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true), '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) (21 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Materialize Output: collection_0_1.document, collection_0_1.object_id -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.document, collection_0_1.object_id (19 rows) -- UDF Unit test for merge documents at path SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(NULL, NULL, NULL); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{}', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'd'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : "text", "d" : { "b" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "random" : false } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a.b'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : { "random" : false }, "c" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "random" : false }', 'a.b'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : { "random" : false } } } (1 row) -- UDF tests for merge documents with override Array SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); bson_dollar_merge_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : true } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "c" : true, "b" : { "random" : false } } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : [ { "c" : true, "b" : { "random" : false } }, { "c" : false, "b" : { "random" : false } } ] } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); bson_dollar_merge_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : true } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "c" : true, "b" : { "random" : false } } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "b" : { "random" : false } } } (1 row) -- todo: remove these duplicated tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, "idx" : { "$numberLong" : "0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (7 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '$matched_docs'::text) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_2."funcName", 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind) LIMIT '10'::bigint) agg_stage_sub_1_2), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true), '$matched_docs'::text) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Limit Output: (documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) (29 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true), '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) (21 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Materialize Output: collection_0_1.document, collection_0_1.object_id -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.document, collection_0_1.object_id (19 rows) -- Test for removal of inner join SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "customer_purchases", "indexes": [ { "key": { "item_name": 1 }, "name": "customer_purchases_item_name_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "7" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "8" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } } (11 rows) ROLLBACK; BEGIN; set local enable_seqscan to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#>=) '{ "item_name" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint))) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'item_code'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) -> Index Scan using customer_purchases_item_name_1 on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "item_name" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using idx_catalog_items_item_code on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: (collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson), 'item_code'::text) (16 rows) ROLLBACK; -- do a multi layer lookup that matches on _id SELECT COUNT(documentdb_api.insert_one('db', 'source1', FORMAT('{ "_id": %s, "field1": "value%s", "fieldsource1": "foo" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:697: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source2', FORMAT('{ "_id": "value%s", "field2": "othervalue%s", "fieldsource2": "foobar" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:698: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source3', FORMAT('{ "_id": "othervalue%s", "field3": "someothervalue%s", "fieldsource3": "foobarfoo" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:699: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source4', FORMAT('{ "_id": "someothervalue%s", "field4": "yetsomeothervalue%s", "fieldsource4": "foobarbaz" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:700: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) -- create indexes on the intermediate fields SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "source1", "indexes": [ { "key": { "field1": 1 }, "name": "field1_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_6020; ANALYZE documentdb_data.documents_6021; ANALYZE documentdb_data.documents_6022; ANALYZE documentdb_data.documents_6023; -- should always pick up _id index. BEGIN; set local enable_indexscan to off; set local enable_bitmapscan to off; set local enable_material to off; set local documentdb.useLegacyForcePushdownBehavior to off; EXPLAIN (COSTS OFF, ANALYZE ON, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "source1", "pipeline": [ { "$match": { "field1": { "$eq": "value10" } } }, { "$lookup": { "from": "source2", "as": "source2_docs", "localField": "field1", "foreignField": "_id" } }, { "$unwind": { "path": "$source2_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source3", "as": "source3_docs", "localField": "source2_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source3_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source4", "as": "source4_docs", "localField": "source3_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source4_docs", "preserveNullAndEmptyArrays": true } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 142 bytes Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'source4_docs'::text) AS document FROM ((SELECT agg_stage_3.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_3.document, '{ "_id" : "source3_docs" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_1.document, COALESCE("lookupRight_stage_1_1".document, '{ }'::documentdb_core.bson), 'source3_docs'::text) AS document FROM ((SELECT agg_stage_2.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_2.document, '{ "_id" : "source2_docs" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_2.document, COALESCE("lookupRight_stage_1_2".document, '{ }'::documentdb_core.bson), 'source2_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "field1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6020_60338 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "field1" : "value10" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '6020'::bigint))) lookup_stage_1_2 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6021_60358 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6021'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_2.lookup_filter))) "lookupRight_stage_1_2" ON (true))) agg_stage_2) lookup_stage_1_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6022_60375 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6022'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_1.lookup_filter))) "lookupRight_stage_1_1" ON (true))) agg_stage_3) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6023_60384 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6023'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Tuple data received from node: 142 bytes Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join (actual rows=1 loops=1) Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), COALESCE(collection_0_1_1.document, '{ }'::documentdb_core.bson), 'source3_docs'::text), COALESCE(collection_0_1_2.document, '{ }'::documentdb_core.bson), 'source4_docs'::text) -> Nested Loop Left Join (actual rows=1 loops=1) Output: collection.document, collection_0_1.document, collection_0_1_1.document -> Nested Loop Left Join (actual rows=1 loops=1) Output: collection.document, collection_0_1.document -> Seq Scan on documentdb_data.documents_6020_60338 collection (actual rows=1 loops=1) Output: collection.shard_key_value, collection.object_id, collection.document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "field1" : "value10" }'::documentdb_core.bson) Rows Removed by Filter: 99 -> Index Scan using _id_ on documentdb_data.documents_6021_60358 collection_0_1 (actual rows=1 loops=1) Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: ((collection_0_1.shard_key_value = '6021'::bigint) AND (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "field1" }'::documentdb_core.bson)))) -> Index Scan using _id_ on documentdb_data.documents_6022_60375 collection_0_1_1 (actual rows=0 loops=1) Output: collection_0_1_1.shard_key_value, collection_0_1_1.object_id, collection_0_1_1.document Index Cond: ((collection_0_1_1.shard_key_value = '6022'::bigint) AND (collection_0_1_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), '{ "_id" : "source2_docs" }'::documentdb_core.bson)))) -> Index Scan using _id_ on documentdb_data.documents_6023_60384 collection_0_1_2 (actual rows=0 loops=1) Output: collection_0_1_2.shard_key_value, collection_0_1_2.object_id, collection_0_1_2.document Index Cond: ((collection_0_1_2.shard_key_value = '6023'::bigint) AND (collection_0_1_2.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), COALESCE(collection_0_1_1.document, '{ }'::documentdb_core.bson), 'source3_docs'::text), '{ "_id" : "source3_docs" }'::documentdb_core.bson)))) (28 rows) ROLLBACK; -- Test lookup query building works with aggregates EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "abc", "pipeline": [ { "$lookup": { "from": "def", "as": "lookup_count", "let" : { "a" : "$A", "b" : "$B", "c" : "$C" }, "pipeline": [ { "$group": { "_id": "$groupId", "total_score": { "$sum": "$Abc.score" }, "count": { "$sum": 1 } } }] }}]}'); QUERY PLAN --------------------------------------------------------------------- CTE Scan on lookup_join_cte_0 lookup_non_inlined_stage_1 Output: bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SubPlan 3), true) CTE lookup_join_cte_0 -> Nested Loop Output: lookup_stage_1.document, (COALESCE(bson_array_agg(collection_0_1.document, 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson)), bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "a" : "$A", "b" : "$B", "c" : "$C" }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) CTE lookup_join_cte_0 -> Function Scan on documentdb_api_internal.empty_data_table collection Output: collection.document, bson_dollar_lookup_expression_eval_merge(collection.document, '{ "a" : "$A", "b" : "$B", "c" : "$C" }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) Function Call: empty_data_table() -> Aggregate Output: COALESCE(bson_array_agg(collection_0_1.document, 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson) -> Function Scan on documentdb_api_internal.empty_data_table collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Function Call: empty_data_table() -> CTE Scan on lookup_join_cte_0 lookup_stage_1 Output: lookup_stage_1.document SubPlan 3 -> Aggregate Output: COALESCE(bson_array_agg(bson_repath_and_build(('_id'::text), (bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let)), ('total_score'::text), (bsonsum(bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$Abc.score" }'::bson, true, lookup_non_inlined_stage_1.let))), ('count'::text), (bsonsum(bson_expression_get('{ }'::bson, '{ "" : { "$numberInt" : "1" } }'::bson, true, lookup_non_inlined_stage_1.let)))), 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson) -> HashAggregate Output: '_id'::text, (bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let)), 'total_score'::text, bsonsum(bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$Abc.score" }'::bson, true, lookup_non_inlined_stage_1.let)), 'count'::text, bsonsum(bson_expression_get('{ }'::bson, '{ "" : { "$numberInt" : "1" } }'::bson, true, lookup_non_inlined_stage_1.let)) Group Key: bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let), lookup_subpipeline_substage_0.lookup_unwind Function Call: bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'lookup_count'::text) (25 rows) bson_aggregation_stage_lookup_tests.out000066400000000000000000006572031507310017400400470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 60000; SET documentdb.next_collection_id TO 6000; SET documentdb.next_collection_index_id TO 6000; \i sql/bson_aggregation_stage_lookup_tests_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:4: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 4, "item_name" : ["shirt", "hat", "pants"], "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 1, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 120 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:12: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 11, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 240 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 2, "item_code" : "hat", "product_description": "product 2", "stock_quantity" : 80 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 3, "item_code" : "shoes", "product_description": "product 3", "stock_quantity" : 60 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 4, "item_code" : "pants", "product_description": "product 4", "stock_quantity" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 5, "item_code" : null, "product_description": "product 4", "stock_quantity" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 6, "item_code" : {"a": "x", "b" : 1, "c" : [1, 2, 3]}, "product_description": "complex object" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 7, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 8, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "item_code" : [ "shirt" ] } { "item_code" : [ "pants" ] } { "item_code" : [ "hat" ] } { "item_code" : [ "shirt", "hat", "pants" ] } { "item_code" : [ null ] } { "item_code" : [ { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ] } (7 rows) -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } }, { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } }, { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : [ { "_id" : { "$numberInt" : "7" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" }, { "_id" : { "$numberInt" : "8" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } ] } (7 rows) -- Create Index on catalog_items SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "catalog_items", "indexes": [ {"key": {"item_code": 1}, "name": "idx_catalog_items_item_code"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Test Index pushdown SELECT documentdb_distributed_test_helpers.drop_primary_key('db','catalog_items'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop Left Join -> Bitmap Heap Scan on documents_6000_60000 collection Recheck Cond: (shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6000'::bigint) -> Aggregate -> Seq Scan on documents_6001_60016 t2 Filter: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson)) (14 rows) ROLLBACK; -- Insert data into a new collection to be sharded (shard key can't be an array, but can be null or object) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:68: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 5, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Shard customer_purchases collection on item_name SELECT documentdb_api.shard_collection('db','customer_purchases_sharded', '{"item_name":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- Test filter generation on sharded left collection SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases_sharded'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "item_code" : [ "pants" ] } { "item_code" : [ null ] } { "item_code" : [ { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "item_code" : [ "shirt" ] } { "item_code" : [ "hat" ] } (5 rows) -- Test Index pushdown on sharded left collection BEGIN; set local enable_seqscan TO off; SET JIT To off; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) -> Distributed Subplan X_X -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_6002_60048 documents_6002 Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> ProjectSet -> Nested Loop Left Join -> Function Scan on read_intermediate_result intermediate_result -> Aggregate -> Seq Scan on documents_6001_60016 t2 Filter: (document OPERATOR(documentdb_api_catalog.@*=) intermediate_result.match) (18 rows) ROLLBACK; SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'customer_purchases_sharded') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- -4688595418384734640 | { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } -9153250461281815030 | { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } 4967885567985676909 | { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } -4514028574017177401 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" } } 8428415592906042960 | { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (5 rows) -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:110: ERROR: CTEs that refer to other subqueries are not supported in multi-shard queries -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } (5 rows) -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "hello" : "newsubpipelinefield" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "hello" : "newsubpipelinefield" } ] } (5 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "matched_docs" : { "hello" : "newsubpipelinefield" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } (5 rows) -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "new" : "field" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "new" : "field" } ] } (5 rows) set citus.enable_local_execution to off; -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:191: ERROR: CTEs that refer to other subqueries are not supported in multi-shard queries -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } ] } (5 rows) -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "hello" : "newsubpipelinefield" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "hello" : "newsubpipelinefield" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "hello" : "newsubpipelinefield" } ] } (5 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "matched_docs" : { "hello" : "newsubpipelinefield" } }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "matched_docs" : { "hello" : "newsubpipelinefield" } } ] } (5 rows) -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "new" : "field" }, { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "4" }, "matched_docs" : [ { "_id" : { "$numberInt" : "5" }, "item_code" : null, "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" }, "new" : "field" } ] } { "_id" : { "$numberInt" : "5" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object", "new" : "field" } ] } (5 rows) set citus.enable_local_execution to on; -- Test coalesce path, return empty array when no match found SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 0, "a": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:265: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 1, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 0, "b": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:268: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 1, "b": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') FROM documentdb_api.collection('db', 'coalesce_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "nonex" : [ { "$numberInt" : "1" } ] } { "nonex" : [ null ] } { "nonex" : [ null ] } (3 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') AS match FROM documentdb_api.collection('db', 'coalesce_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'coalesce_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } (3 rows) -- Test dotted path SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 0, "a": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:286: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 1, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 3, "a": {"c": 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 0, "b": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:291: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 1, "b": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 3, "b": {"c" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 4, "b": {"c" : 2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') FROM documentdb_api.collection('db', 'dotted_path_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "b.c" : [ null ] } { "b.c" : [ null ] } { "b.c" : [ null ] } { "b.c" : [ { "$numberInt" : "1" } ] } (4 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_path_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ { "_id" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "1" }, "b" : null }, { "_id" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "3" }, "a" : { "c" : { "$numberInt" : "1" } }, "matched_docs" : [ { "_id" : { "$numberInt" : "3" }, "b" : { "c" : { "$numberInt" : "1" } } } ] } (4 rows) -- Empty from collection tests SELECT * FROM documentdb_api.collection('db', 'from1NonExistent'); shard_key_value | object_id | document --------------------------------------------------------------------- (0 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'from1NonExistent') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberInt" : "1" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "1" }, "a" : null, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : { "c" : { "$numberInt" : "1" } }, "matched_docs" : [ ] } (4 rows) -- Dotted path on mathched array name (some.documents) SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 0, "a": {"b" : 1}}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:327: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_foreign2','{"_id": 0, "target": 1}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:329: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source2'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "target" : [ { "$numberInt" : "1" } ] } { "target" : [ null ] } (2 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source2')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'same.documents'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_foreign2') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "b" : { "$numberInt" : "1" } }, "same" : { "documents" : [ { "_id" : { "$numberInt" : "0" }, "target" : { "$numberInt" : "1" } } ] } } { "_id" : { "$numberInt" : "1" }, "same" : { "documents" : [ ] } } (2 rows) -- Dotted path that goes through objects and arrays SELECT documentdb_api.insert_one('db','dotted_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:345: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 0}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:346: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"_id" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) -- Dotted AS path that is already present in the left document SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:353: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 1, "c": [{"d": 1}, {"d": 2}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source'); bson_dollar_lookup_extract_filter_expression --------------------------------------------------------------------- { "c.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "c.d" : [ null ] } (2 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'a.b'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_source') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : [ { "b" : [ { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ] } ] }, { "b" : [ { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ] } ] } ] } { "_id" : { "$numberInt" : "1" }, "c" : [ { "d" : { "$numberInt" : "1" } }, { "d" : { "$numberInt" : "2" } } ], "a" : { "b" : [ { "_id" : { "$numberInt" : "0" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } ] } } (2 rows) -- (B) Lookup with pipeline support -- (B).1 Data Ingestion SELECT documentdb_api.insert_one('db','establishments',' {"_id": 1, "establishment_name": "The Grand Diner", "dishes": ["burger", "fries"], "order_quantity": 100 , "drinks": ["soda", "juice"]}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:372: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','establishments','{ "_id": 2, "establishment_name": "Pizza Palace", "dishes": ["veggie pizza", "meat pizza"], "order_quantity": 120, "drinks": ["soda"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 1, "item_name": "burger", "establishment_name": "The Grand Diner"}', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:375: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 2, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "water"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','menu','{ "_id": 3, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "soda"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (B).1 Simple Lookup with pipeline -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $match : { order_quantity : { $gt, 110}} -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } (3 rows) -- (B).2 Index creation on the from collection SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "establishments", "indexes": [ {"key": {"establishment_name": 1}, "name": "idx_establishments_establishment_name"}, {"key": {"order_quantity": 1}, "name": "idx_establishments_order_quantity"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- (B).3.a Index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_order_quantity Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) (16 rows) ROLLBACK; -- Adding a $sort in the pipeline BEGIN; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(collection_0_1.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Seq Scan on documents_6012_60207 collection_0_1 Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "order_quantity" : { "$numberInt" : "110" } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text)) (15 rows) ROLLBACK; BEGIN; SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } (3 rows) ROLLBACK; -- (B).3.b Index usage with optimization: (if lookup has a join condition and the lookup pipeline has $match as the first -- stage we push the $match filter up with the join. If both conditions are one same property both the filters should be -- part of the index condition) BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_establishment_name Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson))) (16 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Bitmap Heap Scan on documents_6012_60207 collection_0_1 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Bitmap Index Scan on idx_establishments_establishment_name Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "establishment_name" : "Pizza Palace" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson))) (16 rows) ROLLBACK; -- (B).4 Nested lookup pipeline (lookup pipeline containing lookup) -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $lookup : { -- from : establishments, -- to: establishments, -- localField: _id, -- foreignField: _id, -- pipeline: { -- [ -- { unwind : "dishes"} -- ] -- } -- } -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "burger", "establishment_name" : "The Grand Diner", "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : [ "burger", "fries" ], "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : "burger", "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ] }, { "_id" : { "$numberInt" : "1" }, "establishment_name" : "The Grand Diner", "dishes" : "fries", "order_quantity" : { "$numberInt" : "100" }, "drinks" : [ "soda", "juice" ] } ] } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "water", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "veggie pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] }, { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "meat pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "veggie pizza", "establishment_name" : "Pizza Palace", "drink" : "soda", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : [ "veggie pizza", "meat pizza" ], "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ], "matched_docs_id" : [ { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "veggie pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] }, { "_id" : { "$numberInt" : "2" }, "establishment_name" : "Pizza Palace", "dishes" : "meat pizza", "order_quantity" : { "$numberInt" : "120" }, "drinks" : [ "soda" ] } ] } ] } (3 rows) -- (B).5 Nested lookup pipeline (lookup pipeline containing lookup) index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> ProjectSet -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> ProjectSet -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (27 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "bar": "$dishes" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (25 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$sort": { "dishes": 1 } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(lookup_subpipeline_substage_1_1.lookup_unwind, '{ "dishes" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(lookup_subpipeline_substage_1.lookup_unwind, '{ "dishes" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (29 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "_id": "bar" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6013_60220 collection Recheck Cond: (shard_key_value = '6013'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6013'::bigint) -> Aggregate -> Nested Loop -> Index Scan using _id_ on documents_6012_60207 collection_0_1 Index Cond: (shard_key_value = '6012'::bigint) -> Subquery Scan on "lookupRight_stage_sub_1_1" Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(documentdb_api_internal.bson_dollar_merge_documents(collection_0_1.document, (SubPlan 2), true), documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "establishment_name" : "establishment_name" }'::documentdb_core.bson), 'establishment_name'::text) -> Aggregate -> Index Scan using _id_ on documents_6012_60207 collection_0_2 Index Cond: ((shard_key_value = '6012'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection_0_1.object_id)) SubPlan 2 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1_1 SubPlan 1 -> Aggregate -> Function Scan on bson_lookup_unwind lookup_subpipeline_substage_1 (25 rows) ROLLBACK; -- Lookup Tests for array index-based paths SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 1, "a" : [{"x" : 1}] }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:526: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 2, "a" : {"x" : 1} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 3, "a" : [{"x": 2}, {"x": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 4, "a" : [{"y": 1}, {"x": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 5, "a" : [2, 3] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 6, "a" : {"x": [1, 2]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 7, "a" : [{"x": 1}, {"y": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 8, "a" : [{"x": [1, 2]}, {"y": 1}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 9, "a" : [[{"x": [1, 2]}, {"y": 1}]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','array_path_items',' { "_id" : 1, "b" : 1 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:536: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ { "x" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ { "x" : { "$numberInt" : "2" } } ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "y" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ { "x" : { "$numberInt" : "1" } } ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.1.y"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" } ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); bson_dollar_lookup_extract_filter_expression | document --------------------------------------------------------------------- { "b" : [ null ] } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "b" : [ null ] } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ null ] } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] } { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } | { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } (9 rows) -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}') AS match FROM documentdb_api.collection('db', 'array_path_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "x" : { "$numberInt" : "1" } }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "1" } } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "matched_docs" : [ ] } { "_id" : { "$numberInt" : "6" }, "a" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "matched_docs" : [ ] } { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ], "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ], "matched_docs" : [ ] } (9 rows) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"a.0.x" : "b"}') AS match FROM documentdb_api.collection('db', 'array_path_items')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_purchases') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; bson_dollar_lookup_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "matched_docs" : [ { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "7" }, "a" : [ { "x" : { "$numberInt" : "1" } }, { "y" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "8" }, "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] }, { "_id" : { "$numberInt" : "9" }, "a" : [ [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "y" : { "$numberInt" : "1" } } ] ] } ] } (1 row) -- test lookup with operator type document contents SELECT documentdb_api.insert_one('db', 'operator_lookup_left', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:571: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'operator_lookup_right', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:572: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "a", "foreignField": "a", "as": "myfoo" } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } }, "myfoo" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } }, "myfoo" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$isArray" : { "$numberInt" : "1" }, "OtherField" : { "$numberInt" : "1" } } } ] } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6016_60270 collection Recheck Cond: (shard_key_value = '6016'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6016'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6017_60286 collection_0_1 Index Cond: ((shard_key_value = '6017'::bigint) AND (object_id OPERATOR(documentdb_core.=) collection.object_id)) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$project": { "_id": "500" }}, { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_6016_60270 collection Recheck Cond: (shard_key_value = '6016'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6016'::bigint) -> Aggregate -> Index Scan using _id_ on documents_6017_60286 collection_0_1 Index Cond: ((shard_key_value = '6017'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_project(collection.document, '{ "_id" : "500" }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson), '{ "_id" : "_id" }'::documentdb_core.bson)))) (13 rows) -- Test for Index push down crash when Foreign Field = '_id' and the target collection is sharded SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 1, "item_name" : "itemA", "price" : 12, "order_quantity" : 2 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:582: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test','{ "_id" : 2, "item_name" : "itemE", "price" : 20, "order_quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 3, "item_name" : "itemC", "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 4, "item_name" : ["itemA", "itemC", "itemE"], "price" : 10, "order_quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemA", "item_description": "product 1", "in_stock" : 120 }', NULL); psql:sql/bson_aggregation_stage_lookup_tests_core.sql:590: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemB", "item_description": "product 1", "in_stock" : 240 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemC", "item_description": "product 2", "in_stock" : 80 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemD", "item_description": "product 3", "in_stock" : 60 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemE", "item_description": "product 4", "in_stock" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemF", "item_description": "product 4", "in_stock" : 70 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db','items_pushdown_test', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "purchases_pushdown_test", "pipeline": [ { "$lookup": { "from": "items_pushdown_test", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "itemA", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "2" }, "item_name" : "itemE", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "3" }, "item_name" : "itemC", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "itemA", "itemC", "itemE" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "5" }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : [ { "efe" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" }, "myBar" : { "$numberInt" : "1" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, "idx" : { "$numberLong" : "0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (7 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '$matched_docs'::text) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_2."funcName", 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind) LIMIT '10'::bigint) agg_stage_sub_1_2), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true), '$matched_docs'::text) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Limit Output: (documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) (29 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true), '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) (21 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Materialize Output: collection_0_1.document, collection_0_1.object_id -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.document, collection_0_1.object_id (19 rows) -- UDF Unit test for merge documents at path SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(NULL, NULL, NULL); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{}', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'd'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : "text", "d" : { "b" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "random" : false } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a.b'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : { "random" : false }, "c" : true } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "random" : false }', 'a.b'); bson_dollar_merge_documents_at_path --------------------------------------------------------------------- { "a" : { "b" : { "random" : false } } } (1 row) -- UDF tests for merge documents with override Array SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); bson_dollar_merge_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : true } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "c" : true, "b" : { "random" : false } } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', false); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : [ { "c" : true, "b" : { "random" : false } }, { "c" : false, "b" : { "random" : false } } ] } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); bson_dollar_merge_documents --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : "text" } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : true } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "c" : true, "b" : { "random" : false } } } (1 row) SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', true); bson_dollar_merge_documents --------------------------------------------------------------------- { "a" : { "b" : { "random" : false } } } (1 row) -- todo: remove these duplicated tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } }, "idx" : { "$numberLong" : "0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } (7 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '$matched_docs'::text) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_2."funcName", 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM (SELECT documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind) LIMIT '10'::bigint) agg_stage_sub_1_2), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true), '$matched_docs'::text) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)), 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Limit Output: (documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: documentdb_api_internal.bson_dollar_add_fields(lookup_subpipeline_substage_0.lookup_unwind, '{ "myBar" : { "$numberInt" : "1" } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) (29 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_catalog.bson_dollar_unwind(document, '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) AS document FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true))) agg_stage_1 Node: host=localhost port=58070 dbname=regression -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true), '{ "path" : "$matched_docs", "includeArrayIndex" : "idx" }'::documentdb_core.bson) -> Nested Loop Output: collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) (21 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint)) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'matched_docs'::text) Join Filter: (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "item_name" }'::documentdb_core.bson))) -> Bitmap Heap Scan on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '6000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6000'::bigint) -> Materialize Output: collection_0_1.document, collection_0_1.object_id -> Seq Scan on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.document, collection_0_1.object_id (19 rows) -- Test for removal of inner join SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "customer_purchases", "indexes": [ { "key": { "item_name": 1 }, "name": "customer_purchases_item_name_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } { "_id" : { "$numberInt" : "1" }, "item_name" : "shirt", "price" : { "$numberInt" : "12" }, "order_quantity" : { "$numberInt" : "2" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } } { "_id" : { "$numberInt" : "2" }, "item_name" : "pants", "price" : { "$numberInt" : "20" }, "order_quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } } { "_id" : { "$numberInt" : "3" }, "item_name" : "hat", "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "120" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "item_code" : "shirt", "product_description" : "product 1", "stock_quantity" : { "$numberInt" : "240" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "item_code" : "hat", "product_description" : "product 2", "stock_quantity" : { "$numberInt" : "80" } } } { "_id" : { "$numberInt" : "4" }, "item_name" : [ "shirt", "hat", "pants" ], "price" : { "$numberInt" : "10" }, "order_quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "item_code" : "pants", "product_description" : "product 4", "stock_quantity" : { "$numberInt" : "70" } } } { "_id" : { "$numberInt" : "6" }, "item_name" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "matched_docs" : { "_id" : { "$numberInt" : "6" }, "item_code" : { "a" : "x", "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "product_description" : "complex object" } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "7" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } } { "_id" : { "$numberInt" : "7" }, "item_name" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "matched_docs" : { "_id" : { "$numberInt" : "8" }, "item_code" : [ { "a" : { "b" : { "$numberInt" : "1" } } }, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "1" }, "x" ], "product_description" : "complex array" } } (11 rows) ROLLBACK; BEGIN; set local enable_seqscan to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'matched_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6000_60000 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#>=) '{ "item_name" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '6000'::bigint))) lookup_stage_1 JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_6001_60016 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6001'::bigint)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'item_code'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, collection_0_1.document, 'matched_docs'::text) -> Index Scan using customer_purchases_item_name_1 on documentdb_data.documents_6000_60000 collection Output: collection.shard_key_value, collection.object_id, collection.document Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "item_name" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using idx_catalog_items_item_code on documentdb_data.documents_6001_60016 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: (collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "item_code" : "item_name" }'::documentdb_core.bson), 'item_code'::text) (16 rows) ROLLBACK; -- do a multi layer lookup that matches on _id SELECT COUNT(documentdb_api.insert_one('db', 'source1', FORMAT('{ "_id": %s, "field1": "value%s", "fieldsource1": "foo" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:697: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source2', FORMAT('{ "_id": "value%s", "field2": "othervalue%s", "fieldsource2": "foobar" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:698: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source3', FORMAT('{ "_id": "othervalue%s", "field3": "someothervalue%s", "fieldsource3": "foobarfoo" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:699: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'source4', FORMAT('{ "_id": "someothervalue%s", "field4": "yetsomeothervalue%s", "fieldsource4": "foobarbaz" }', i, i)::bson)) FROM generate_series(1, 100) i; psql:sql/bson_aggregation_stage_lookup_tests_core.sql:700: NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) -- create indexes on the intermediate fields SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "source1", "indexes": [ { "key": { "field1": 1 }, "name": "field1_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_6020; ANALYZE documentdb_data.documents_6021; ANALYZE documentdb_data.documents_6022; ANALYZE documentdb_data.documents_6023; -- should always pick up _id index. BEGIN; set local enable_indexscan to off; set local enable_bitmapscan to off; set local enable_material to off; set local documentdb.useLegacyForcePushdownBehavior to off; EXPLAIN (COSTS OFF, ANALYZE ON, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "source1", "pipeline": [ { "$match": { "field1": { "$eq": "value10" } } }, { "$lookup": { "from": "source2", "as": "source2_docs", "localField": "field1", "foreignField": "_id" } }, { "$unwind": { "path": "$source2_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source3", "as": "source3_docs", "localField": "source2_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source3_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source4", "as": "source4_docs", "localField": "source3_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source4_docs", "preserveNullAndEmptyArrays": true } } ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 142 bytes Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::documentdb_core.bson), 'source4_docs'::text) AS document FROM ((SELECT agg_stage_3.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_3.document, '{ "_id" : "source3_docs" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_1.document, COALESCE("lookupRight_stage_1_1".document, '{ }'::documentdb_core.bson), 'source3_docs'::text) AS document FROM ((SELECT agg_stage_2.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_2.document, '{ "_id" : "source2_docs" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_2.document, COALESCE("lookupRight_stage_1_2".document, '{ }'::documentdb_core.bson), 'source2_docs'::text) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "field1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_6020_60338 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "field1" : "value10" }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '6020'::bigint))) lookup_stage_1_2 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6021_60358 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6021'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_2.lookup_filter))) "lookupRight_stage_1_2" ON (true))) agg_stage_2) lookup_stage_1_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6022_60375 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6022'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_1.lookup_filter))) "lookupRight_stage_1_1" ON (true))) agg_stage_3) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_6023_60384 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '6023'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) Tuple data received from node: 142 bytes Node: host=localhost port=58070 dbname=regression -> Nested Loop Left Join (actual rows=1 loops=1) Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), COALESCE(collection_0_1_1.document, '{ }'::documentdb_core.bson), 'source3_docs'::text), COALESCE(collection_0_1_2.document, '{ }'::documentdb_core.bson), 'source4_docs'::text) -> Nested Loop Left Join (actual rows=1 loops=1) Output: collection.document, collection_0_1.document, collection_0_1_1.document -> Nested Loop Left Join (actual rows=1 loops=1) Output: collection.document, collection_0_1.document -> Seq Scan on documentdb_data.documents_6020_60338 collection (actual rows=1 loops=1) Output: collection.shard_key_value, collection.object_id, collection.document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "field1" : "value10" }'::documentdb_core.bson) Rows Removed by Filter: 99 -> Index Scan using _id_ on documentdb_data.documents_6021_60358 collection_0_1 (actual rows=1 loops=1) Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: ((collection_0_1.shard_key_value = '6021'::bigint) AND (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(collection.document, '{ "_id" : "field1" }'::documentdb_core.bson)))) -> Index Scan using _id_ on documentdb_data.documents_6022_60375 collection_0_1_1 (actual rows=0 loops=1) Output: collection_0_1_1.shard_key_value, collection_0_1_1.object_id, collection_0_1_1.document Index Cond: ((collection_0_1_1.shard_key_value = '6022'::bigint) AND (collection_0_1_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), '{ "_id" : "source2_docs" }'::documentdb_core.bson)))) -> Index Scan using _id_ on documentdb_data.documents_6023_60384 collection_0_1_2 (actual rows=0 loops=1) Output: collection_0_1_2.shard_key_value, collection_0_1_2.object_id, collection_0_1_2.document Index Cond: ((collection_0_1_2.shard_key_value = '6023'::bigint) AND (collection_0_1_2.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path(collection.document, COALESCE(collection_0_1.document, '{ }'::documentdb_core.bson), 'source2_docs'::text), COALESCE(collection_0_1_1.document, '{ }'::documentdb_core.bson), 'source3_docs'::text), '{ "_id" : "source3_docs" }'::documentdb_core.bson)))) (28 rows) ROLLBACK; -- Test lookup query building works with aggregates EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "abc", "pipeline": [ { "$lookup": { "from": "def", "as": "lookup_count", "let" : { "a" : "$A", "b" : "$B", "c" : "$C" }, "pipeline": [ { "$group": { "_id": "$groupId", "total_score": { "$sum": "$Abc.score" }, "count": { "$sum": 1 } } }] }}]}'); QUERY PLAN --------------------------------------------------------------------- CTE Scan on lookup_join_cte_0 lookup_non_inlined_stage_1 Output: bson_dollar_merge_documents(lookup_non_inlined_stage_1."left", (SubPlan 3), true) CTE lookup_join_cte_0 -> Nested Loop Output: lookup_stage_1.document, (COALESCE(bson_array_agg(collection_0_1.document, 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson)), bson_dollar_lookup_expression_eval_merge(lookup_stage_1.document, '{ "a" : "$A", "b" : "$B", "c" : "$C" }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) CTE lookup_join_cte_0 -> Function Scan on documentdb_api_internal.empty_data_table collection Output: collection.document, bson_dollar_lookup_expression_eval_merge(collection.document, '{ "a" : "$A", "b" : "$B", "c" : "$C" }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) Function Call: empty_data_table() -> Aggregate Output: COALESCE(bson_array_agg(collection_0_1.document, 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson) -> Function Scan on documentdb_api_internal.empty_data_table collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Function Call: empty_data_table() -> CTE Scan on lookup_join_cte_0 lookup_stage_1 Output: lookup_stage_1.document SubPlan 3 -> Aggregate Output: COALESCE(bson_array_agg(bson_repath_and_build(('_id'::text), (bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let)), ('total_score'::text), (bsonsum(bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$Abc.score" }'::bson, true, lookup_non_inlined_stage_1.let))), ('count'::text), (bsonsum(bson_expression_get('{ }'::bson, '{ "" : { "$numberInt" : "1" } }'::bson, true, lookup_non_inlined_stage_1.let)))), 'lookup_count'::text), '{ "lookup_count" : [ ] }'::bson) -> HashAggregate Output: '_id'::text, (bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let)), 'total_score'::text, bsonsum(bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$Abc.score" }'::bson, true, lookup_non_inlined_stage_1.let)), 'count'::text, bsonsum(bson_expression_get('{ }'::bson, '{ "" : { "$numberInt" : "1" } }'::bson, true, lookup_non_inlined_stage_1.let)) Group Key: bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: bson_expression_get(lookup_subpipeline_substage_0.lookup_unwind, '{ "" : "$groupId" }'::bson, true, lookup_non_inlined_stage_1.let), lookup_subpipeline_substage_0.lookup_unwind Function Call: bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'lookup_count'::text) (25 rows) bson_aggregation_stage_merge_tests.out000066400000000000000000004227041507310017400376310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 7850000; SET documentdb.next_collection_id TO 7850; SET documentdb.next_collection_index_id TO 7850; --Test without Enabling feature flag of $merge SELECT documentdb_api.insert_one('sourceDB','withoutFlag',' { "_id" : 1, "country" : "India", "state" : "Rajasthan", "Code" : "RJ03" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "withoutFlag", "pipeline": [ {"$merge" : { "into": "targetwithoutFlag" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "sourceDB.withoutFlag", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) --Test without Enabling flag for $merge stage target collection creation SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "withoutFlag", "pipeline": [ {"$merge" : { "into": "targetwithoutFlag" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "sourceDB.withoutFlag", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- custom udf testing SELECT * FROM documentdb_api_internal.bson_dollar_merge_add_object_id('{"_id" : 1, "a" : 1}', documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}')); bson_dollar_merge_add_object_id --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_add_object_id('{"a" : 1, "_id" : 1}', documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}')); bson_dollar_merge_add_object_id --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT count(*) FROM documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}'); count --------------------------------------------------------------------- 1 (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : 1, "b" : 3}', 'a'::TEXT), 'a'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- t (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : 2, "b" : 2}', 'a'::TEXT), 'a'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- f (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : {"b" : 1 }, "c" : 2}', '{"a" : {"b" : 1}}', 'a.b'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- t (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : {"b" : 1 }, "c" : 2}', '{"a" : {"b" : 2}}', 'a.b'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- f (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : [1,2,3], "c" : 2}', '{"a" : 2}', 'a'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- t (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : [1,2,3], "c" : 2}', '{"a" : 4}', 'a'::TEXT); bson_dollar_merge_join --------------------------------------------------------------------- f (1 row) SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : [1,2,3], "b" : 3}','a'::TEXT), 'a'::TEXT); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"b" : 3}', 'a'::TEXT), 'a'::TEXT); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : null}','a' ::TEXT), 'a'::TEXT); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM documentdb_api_internal.bson_dollar_merge_fail_when_not_matched('{"a" : "this is a dummy bson"}', 'this is dummy text'::TEXT); ERROR: $merge failed to locate a corresponding document in the target collection for one or more documents from the source collection -- Merge with default option SELECT documentdb_api.insert_one('defDb','defSrc',' { "_id" : 1, "a" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('defDb','defSrc',' { "_id" : 2, "a" : 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('defDb','defTar',' { "_id" : 1, "b" : 2 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('defDb', '{ "aggregate": "defSrc", "pipeline": [ {"$merge" : { "into": "defTar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "defDb.defSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('defDb', 'defTar'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) -- simplest test case working SELECT documentdb_api.insert('db', '{"insert":"moviesDB", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : { "into": "budgets" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.moviesDB", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'budgets'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) -- simple test case target database is not same as source database SELECT documentdb_api.insert_one('sourceDB','sourceDumpData',' { "_id" : 1, "country" : "India", "state" : "Rajasthan", "Code" : "RJ03" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "sourceDumpData", "pipeline": [ {"$merge" : { "into": {"db" : "targetDB" , "coll" : "targetDumpData"}, "on" : "_id", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "sourceDB.sourceDumpData", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('targetDB', 'targetDumpData'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "country" : "India", "state" : "Rajasthan", "Code" : "RJ03" } (1 row) -- object id missing test SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$project" : {"_id" : 0}}, {"$merge" : { "into": "budgets2" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.moviesDB", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT count(document) FROM documentdb_api.collection('db', 'budgets2'); count --------------------------------------------------------------------- 6 (1 row) -- test when merge input is string SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : "normalString" } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.moviesDB", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : "dotted.String" } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.moviesDB", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','normalString'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dotted.String'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) -- unique index test SELECT documentdb_api.insert_one('db','uniqueIndexTestSrc',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1", "unique" : true}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"a": 1}, "name": "index_2", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"e": 1}, "name": "index_3", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"f": 1}, "name": "index_4", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["b" , "c" , "a"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.uniqueIndexTestSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["c" , "b" , "a"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.uniqueIndexTestSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : "_id", "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.uniqueIndexTestSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.uniqueIndexTestSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["_id"], "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.uniqueIndexTestSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'uniqueIndexTestTarget'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } } (1 row) -- _id unique index test SELECT documentdb_api.insert_one('db','objectIDUniqueIndex',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1, "field1" : 1, "field2" : 2}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"field1": 1, "field2" : 1, "_id" : 1}, "name": "index_id", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : "_id","into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.objectIDUniqueIndex", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["_id"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.objectIDUniqueIndex", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["field1","_id","field2"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.objectIDUniqueIndex", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.objectIDUniqueIndex", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) --test source collection is sharded. SELECT documentdb_api.insert('db', '{"insert":"soruceShardedTest", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.shard_collection('db', 'soruceShardedTest', '{ "employee": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "soruceShardedTest", "pipeline": [ {"$merge" : { "into": "soruceShardedTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.soruceShardedTest", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'soruceShardedTarget'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "soruceShardedTest", "pipeline": [{"$project" : { "_id" : 1, "employee" : 1, "Budget" : {"$add" : ["$Budget" , 1000]} }} ,{"$merge" : { "into": "soruceShardedTarget", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.soruceShardedTest", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'soruceShardedTarget'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "Budget" : { "$numberInt" : "180001000" } } { "_id" : { "$numberInt" : "2" }, "Budget" : { "$numberInt" : "170001000" } } { "_id" : { "$numberInt" : "3" }, "Budget" : { "$numberInt" : "160001000" } } { "_id" : { "$numberInt" : "4" }, "Budget" : { "$numberInt" : "150001000" } } { "_id" : { "$numberInt" : "5" }, "Budget" : { "$numberInt" : "140001000" } } { "_id" : { "$numberInt" : "6" }, "Budget" : { "$numberInt" : "130001000" } } (6 rows) -- simple replace scenario SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplace", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataReplace", "documents":[ { "_id" : 1, "a": 10 }, { "_id" : 3, "a": 30 }, { "_id" : 4, "a": 40 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplace", "pipeline": [ {"$merge": {"into": "targetDataReplace", "whenMatched": "replace", "whenNotMatched": "discard"}} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceDataReplace", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','targetDataReplace'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "a" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : "c" } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } (3 rows) -- let's create index and match on other key and try to replace _id field when source and target ID are same SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplaceId", "documents":[{ "_id" : 1, "a": 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataReplaceId", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataReplaceId", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceId", "pipeline": [ {"$merge" : { "into": "targetDataReplaceId", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceDataReplaceId", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','targetDataReplaceId'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "10" } } (1 row) -- let's create index and match on other key and try to replace _id field whe source and target ID's are different. SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplaceIdDiff", "documents":[{ "_id" : 1, "a": 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataReplaceIdDiff", "documents":[{ "_id" : 2, "a": 10, "b" : 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataReplaceIdDiff", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceIdDiff", "pipeline": [ {"$merge" : { "into": "targetDataReplaceIdDiff", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge could not update the target document as an immutable field (like '_id' or shardKey) was detected to be modified. -- Now let's see what happens when we are not projecting _id from source and source _id is getting generated and if source objectID is generated then it will be not same as targets. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceIdDiff", "pipeline": [ {"$project" : { "_id": 0 }}, {"$merge" : { "into": "targetDataReplaceIdDiff", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceDataReplaceIdDiff", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','targetDataReplaceIdDiff'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "10" } } (1 row) -- simple merge scenario SELECT documentdb_api.insert('db', '{"insert":"sourceWhenMatchMerge", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetWhenMatchMerge", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- As all doc from source matches with target so there should not be any change in target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceWhenMatchMerge", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) -- Let's Add one more column by projection and see if it merges in target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$project" : {"_id" : 1, "new_column" : "testing merge"}}, {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceWhenMatchMerge", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" }, "new_column" : "testing merge" } (6 rows) -- let's try to modify value of existing column of target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$project" : {"_id" : 1, "year" : {"$add" : ["$year" , 1]}}}, {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceWhenMatchMerge", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2012" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2012" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2013" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2013" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2014" }, "new_column" : "testing merge" } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2014" }, "new_column" : "testing merge" } (6 rows) -- let's create index and match on other key and try to merge when _id field on source and target ID are same SELECT documentdb_api.insert('db', '{"insert":"sourceDataMergeId", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataMergeId", "documents":[{ "_id" : 1, "a": 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMergeId", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeId", "pipeline": [ {"$merge" : { "into": "targetDataMergeId", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceDataMergeId", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','targetDataMergeId'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "10" } } (1 row) -- let's create index and match on other key and try to merge when _id field on source and target ID are different SELECT documentdb_api.insert('db', '{"insert":"sourceDataMergeIdDiff", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataMergeIdDiff", "documents":[{ "_id" : 2, "a": 10 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMergeIdDiff", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeIdDiff", "pipeline": [ {"$merge" : { "into": "targetDataMergeIdDiff", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge could not update the target document as an immutable field (like '_id' or shardKey) was detected to be modified. SELECT document FROM documentdb_api.collection('db','targetDataMergeIdDiff'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "10" } } (1 row) -- Now let's see what happens when we are not projecting _id from source and source _id is getting generated and if source objectID is generated then it will be not same as target's. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeIdDiff", "pipeline": [ {"$project" : { "_id": 0 }}, {"$merge" : { "into": "targetDataMergeIdDiff", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceDataMergeIdDiff", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','targetDataMergeIdDiff'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "10" } } (1 row) -- merge whenNotMatched fail -- 1) this will not fail as all the doc from source are matching with target SELECT documentdb_api.insert('db', '{"insert":"sourceNotMatchedFailed", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetNotMatchedFailed", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 3, "a": 3, "b": "g" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedFailed", "pipeline": [ {"$merge" : { "into": "targetNotMatchedFailed", "whenMatched" : "replace" , "whenNotMatched" : "fail" } } ], "cursor": { "batchSize": 1 } }', 4294967294 ); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceNotMatchedFailed", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document FROM documentdb_api.collection('db','targetNotMatchedFailed'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "a" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : "b" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : "c" } (3 rows) -- 2) this will fail as not one source doc is not matching with target and user has selected failure option. SELECT documentdb_api.insert_one('db','sourceNotMatchedFailed',' { "_id" : 10, "a" : 1, "b" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedFailed", "pipeline": [ {"$merge" : { "into": "targetNotMatchedFailed", "whenMatched" : "replace" , "whenNotMatched" : "fail" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge failed to locate a corresponding document in the target collection for one or more documents from the source collection select document FROM documentdb_api.collection('db','targetNotMatchedFailed'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "a" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : "b" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : "c" } (3 rows) -- merge whenNotMatched Discard SELECT documentdb_api.insert('db', '{"insert":"sourceNotMatchedDiscard", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetNotMatchedDiscard", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 5, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedDiscard", "pipeline": [ {"$merge" : { "into": "targetNotMatchedDiscard", "whenMatched" : "replace" , "whenNotMatched" : "discard" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceNotMatchedDiscard", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document FROM documentdb_api.collection('db','targetNotMatchedDiscard'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "a" } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "2" }, "b" : "f" } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "3" }, "b" : "g" } (3 rows) -- WhanMathched : keepexisting SELECT documentdb_api.insert('db', '{"insert":"sourceMatchedKeepExisting", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetMatchedKeepExisting", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedKeepExisting", "pipeline": [ {"$merge" : { "into": "targetMatchedKeepExisting", "whenMatched" : "keepExisting" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceMatchedKeepExisting", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select document from documentdb_api.collection('db','targetMatchedKeepExisting'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "e" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : "f" } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "3" }, "b" : "g" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : "c" } (4 rows) -- WhanMathched : fail SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedKeepExisting", "pipeline": [ {"$merge" : { "into": "targetMatchedKeepExisting", "whenMatched" : "fail" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge with whenMatched: fail found an existing document with the same values for the 'on' fields select document FROM documentdb_api.collection('db','targetMatchedKeepExisting'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "e" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : "f" } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "3" }, "b" : "g" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : "c" } (4 rows) -- whenMatched : _id are getting changed in case of replace SELECT documentdb_api.insert('db', '{"insert":"sourceMatchedIdTests", "documents":[ { "_id" : 4, "a": 1, "b": "a" }, { "_id" : 5, "a": 2, "b": "b" }, { "_id" : 6, "a": 3, "b": "c" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetMatchedIdTests", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetMatchedIdTests", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedIdTests", "pipeline": [ {"$merge" : { "on" : "a", "into": "targetMatchedIdTests", "whenMatched" : "replace" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge could not update the target document as an immutable field (like '_id' or shardKey) was detected to be modified. select document FROM documentdb_api.collection('db','targetMatchedIdTests'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : "e" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : "f" } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "3" }, "b" : "g" } (3 rows) -- complex pipeline with last stage merge with replace and insert mode. SELECT documentdb_api.insert_one('db','bson_agg_merge_src',' {"_id": 1, "company": "Company A", "products": ["product1", "product2"], "amount": 100 , "services": ["service1", "service2"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_src','{ "_id": 2, "company": "Company B", "products": ["product3", "product4"], "amount": 120, "services": ["service3"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 1, "item": "product1", "company_name": "Company A"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 2, "item": "product3", "company_name": "Company B", "extra": "value1"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 3, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_dest", "pipeline": [ { "$lookup": { "from": "bson_agg_merge_src", "pipeline": [ { "$match": { "amount": { "$gt": 110 } }}], "as": "joined_docs", "localField": "company_name", "foreignField": "company" } }, {"$sort" : {"_id" : -1}} , {"$group" :{"_id" : "$company_name"}}, {"$project" : {"joined_docs" : 0}}, {"$merge" : { "into": "bson_agg_merge_final", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bson_agg_merge_dest", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','bson_agg_merge_final'); document --------------------------------------------------------------------- { "_id" : "Company A" } { "_id" : "Company B" } (2 rows) -- when target collection has array SELECT documentdb_api.insert_one('db','bson_agg_merge_src_array',' { "_id" : 1, "a" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_src_array',' { "_id" : 2, "a" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_dest_array',' { "_id" : 1, "a" : [1,2,3,4] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bson_agg_merge_dest_array", "indexes": [{"key": {"a": 1}, "name": "index_2", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_src_array", "pipeline":[ {"$merge" : { "into": "bson_agg_merge_dest_array", "on" : "a", "whenMatched" : "replace", "whenNotMatched" : "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bson_agg_merge_src_array", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','bson_agg_merge_dest_array'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "5" } } (2 rows) -- when query has sort clause SELECT documentdb_api.insert_one('db','bson_agg_merge_sort_src','{ "_id": 1, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_agg_merge_sort_src','{ "_id": 2, "item": "product5", "company_name": "Company C", "extra": "value3"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_sort_src", "pipeline": [ {"$sort" : {"_id" : -1}} , {"$merge" : { "into": "bson_agg_merge_sort_dest", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bson_agg_merge_sort_src", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','bson_agg_merge_sort_dest'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "item" : "product5", "company_name" : "Company C", "extra" : "value3" } { "_id" : { "$numberInt" : "1" }, "item" : "product3", "company_name" : "Company B", "extra" : "value2" } (2 rows) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_dest", "pipeline": [ {"$sort" : {"_id" : -1}} , {"$group" : {"_id" : "$_id"}}, {"$merge" : { "into": "bson_agg_merge_sort_group", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bson_agg_merge_dest", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','bson_agg_merge_sort_group'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" } } (3 rows) -- when query has multiple sort clause or multiple resjunk columns SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 1, "a" : 45, "b" : 10 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 2, "a" : 87, "b" : 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 3, "a" : 29, "b" : 17 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 4, "a" : 13, "b" : 99 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 5, "a" : 45, "b" : 113 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 6, "a" : 87, "b" : 76 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 7, "a" : 29, "b" : 86 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 8, "a" : 13, "b" : 20 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "resJunkSrc", "pipeline": [ {"$sort" : {"a" : -1, "b" : 1}} , {"$merge" : { "into": "resJunkeTarget", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.resJunkSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db','resJunkeTarget'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "87" }, "b" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "87" }, "b" : { "$numberInt" : "76" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "45" }, "b" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "45" }, "b" : { "$numberInt" : "113" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "29" }, "b" : { "$numberInt" : "17" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "29" }, "b" : { "$numberInt" : "86" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "13" }, "b" : { "$numberInt" : "20" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "13" }, "b" : { "$numberInt" : "99" } } (8 rows) -- test when source collection is view SELECT documentdb_api.create_collection('db', 'sourceCollForView'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 2, "a" : 2, "b" : 2 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 3, "a" : 3, "b" : 3 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "sourceView", "viewOn": "sourceCollForView", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceView", "pipeline": [ {"$merge" : { "into" : "targetViewedOutput" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.sourceView", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'targetViewedOutput'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "6" } } (3 rows) -- Let's look at explain plan for unshared collection SELECT documentdb_api.create_collection('db', 'sourceExplain'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 2, "a" : 2, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 3, "a" : 3, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 4, "a" : 4, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 5, "a" : 5, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); NOTICE: creating collection QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) (cost=0.00..0.00 rows=0 width=0) MERGE INTO documents_7903 method: pull to coordinator -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id, remote_scan.extracted_4 Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, target_shard_key_value, generated_object_id, extracted_4 FROM (SELECT collection.document, '7903'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id, documentdb_api_internal.bson_dollar_extract_merge_filter(collection.document, '_id'::text) AS extracted_4 FROM documentdb_data.documents_7902_7850703 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7902'::bigint)) citus_insert_select_subquery Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_7902_7850703 collection (cost=4.18..12.66 rows=4 width=104) Output: collection.document, '7903'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document), documentdb_api_internal.bson_dollar_extract_merge_filter(collection.document, '_id'::text) Recheck Cond: (collection.shard_key_value = '7902'::bigint) -> Bitmap Index Scan on _id_ (cost=0.00..4.18 rows=4 width=0) Index Cond: (collection.shard_key_value = '7902'::bigint) (14 rows) --explain when merge is not first stage of pipeline EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{ "$match" : {"_id" :1}}, {"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) (cost=0.00..0.00 rows=0 width=0) MERGE INTO documents_7903 method: pull to coordinator -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id, remote_scan.extracted_4 Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, target_shard_key_value, generated_object_id, extracted_4 FROM (SELECT collection.document, '7903'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id, documentdb_api_internal.bson_dollar_extract_merge_filter(collection.document, '_id'::text) AS extracted_4 FROM documentdb_data.documents_7902_7850703 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '7902'::bigint))) citus_insert_select_subquery Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_7902_7850703 collection (cost=0.00..0.01 rows=1 width=104) Output: collection.document, '7903'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document), documentdb_api_internal.bson_dollar_extract_merge_filter(collection.document, '_id'::text) Index Cond: ((collection.shard_key_value = '7902'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (12 rows) -- Let's look at explain plan for sharded collection SELECT documentdb_api.shard_collection('db', 'sourceExplain', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) (cost=0.00..0.00 rows=0 width=0) MERGE INTO documents_7903 method: repartition -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=104) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id, remote_scan.extracted_4 Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, '7903'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(document) AS generated_object_id, documentdb_api_internal.bson_dollar_extract_merge_filter(document, '_id'::text) AS extracted_4 FROM documentdb_data.documents_7902_7850730 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7902_7850730 collection (cost=0.00..1.01 rows=1 width=104) Output: document, '7903'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(document), documentdb_api_internal.bson_dollar_extract_merge_filter(document, '_id'::text) (11 rows) -- Let's look at explain plan for when on field is indexed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "sourceExplain", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "explainTarget", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- citus will wrap our query in a subquery: SELECT document, target_shard_key_value FROM (our query) AS subquery EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "on" : "a", "whenMatched" : "replace" }} ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) (cost=0.00..0.00 rows=0 width=0) MERGE INTO documents_7903 method: repartition -> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=104) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id, remote_scan.extracted_4 Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, '7903'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(document) AS generated_object_id, documentdb_api_internal.bson_dollar_extract_merge_filter(document, 'a'::text) AS extracted_4 FROM documentdb_data.documents_7902_7850730 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7902_7850730 collection (cost=0.00..1.01 rows=1 width=104) Output: document, '7903'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(document), documentdb_api_internal.bson_dollar_extract_merge_filter(document, 'a'::text) (11 rows) -- source and target are same SELECT documentdb_api.create_collection('db', 'AsSourceAsTarget'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','AsSourceAsTarget',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "AsSourceAsTarget", "pipeline": [ {"$project" : {"new" : "data"}}, {"$merge" : { "into": "AsSourceAsTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.AsSourceAsTarget", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'AsSourceAsTarget'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "new" : "data" } (1 row) -- Negative tests : Invalid input SELECT documentdb_api.create_collection('db', 'negInvalidInput'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : 1} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The $merge operator needs a string or object input, but received int instead SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The required BSON field '$merge.into' is missing. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "xman" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The BSON field '$merge.xman' is not recognized as a valid field. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge 'into' field must contain either a string value or an object, but was given int instead SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "apple"} }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The 'into' field of $merge must define a collection name that is neither empty, null, nor undefined. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : 1} }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: BSON field 'into.db' has an incorrect type 'object'; the expected data type is 'string' SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "database", "coll" : 1} }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: BSON field 'into.coll' has an incorrect type 'object'; the expected data type is 'string' SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "apple", "haha" : "haha"} }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: BSON field 'into.haha' is not recognized as a valid field SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "on" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The $merge 'on' field must be provided as either a single string or an array containing multiple strings, but received int instead. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "on" : [1] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Array elements for $merge 'on' must be strings, but a int type was detected SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenMatched" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The 'whenMatched' field in $merge needs to be a string value, but a int type was provided. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenMatched" : "falsevalue" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The enumeration value 'falsevalue' specified for the 'whenMatched' field is invalid. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenNotMatched" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: BSON field '$merge.whenNotMatched' has an incorrect type 'int', but it should be of type 'string' SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenNotMatched" : "falsevalue" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The enumeration value 'falsevalue' provided for the field operator '$merge.whenNotMatched' is invalid. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl" }}, {} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: A pipeline stage specification object is required to have one and only one field. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl" }}, {"project" : {"a" : 1} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge must appear exclusively as the last stage in the pipeline SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into": "targetNotExists", "on" : [] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: When you explicitly set the operators merge to 'on', you are required to include at least one field. -- Negative test cases when on fields value are not unique index. SELECT documentdb_api.create_collection('db', 'indexNegColl'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','indexNegColl',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection('db', 'indexNegOutColl'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"b": 1}, "name": "index_2", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"c": 1}, "name": "index_3", "unique" : false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"d": 1}, "name": "index_A"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"e": 1, "f" : 1, "g" : 1}, "name": "index_4"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"x": 1, "y" : 1, "z" : 1}, "name": "index_5", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"parag": 1}, "name": "index_6", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"jain": 1}, "name": "index_7", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"partialTest": 1}, "name": "index_8", "unique" : true, "partialFilterExpression": {"a": {"$gt": 1}}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"partialTest": 1, "partialTest2" : 1}, "name": "index_9", "unique" : true, "partialFilterExpression": {"a": {"$gt": 1}}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "c" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "d" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "c"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "d"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "e" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["f","g"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["e","f","g"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "f" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","z","y","f"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "x" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","z"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","_id"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["parag","jain"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["partialTest"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "partialTest" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["partialTest", "partialTest2"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a", "a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Duplicate field a detected SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a", "b", "b"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Duplicate field b detected SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["c", "a", "c"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Duplicate field c detected SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","y"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["z","x"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique -- _id Negative unique test SELECT documentdb_api.insert_one('db','objectIDNegUniqueIndex',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"b": 1}, "name": "index_2", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"a": 1, "b" : 1}, "name": "index_3", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["_id", "a"],"into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["a", "_id"], "into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["a", "_id", "b"], "into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique -- Negative tests : when target collection does not exist SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["_id","a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["a","_id"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Unable to locate index required to confirm join fields are unique --Negative test when target collection is a view SELECT documentdb_api.create_collection('db', 'targetCollForView'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetCollForView", "documents":[{ "_id" : 1, "a" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "targetView", "viewOn": "targetCollForView", "pipeline": [ { "$sort": { "a": 1 } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "targetCollForView", "pipeline": [ {"$merge" : { "into" : "targetView" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The namespace db.targetView refers to a view object rather than a collection --Negative tests : when on field is missing/array in source document SELECT documentdb_api.insert('db', '{"insert":"sourceDataMissing", "documents":[{ "_id" : 3, "b": "c" }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"targetDataMissingTest", "documents":[{ "_id" : 3, "b": "c" }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMissingTest", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMissing", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMissing", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT documentdb_api.insert('db', '{"insert":"sourceDataArray", "documents":[{ "_id" : 3, "a" : [1,2,3], "b": "c" }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataArray", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataArray", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT documentdb_api.insert('db', '{"insert":"sourceDataNull", "documents":[{ "_id" : 3, "a" : null , "b": "c" }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataNull", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataNull", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array -- Negative test when non-Immutable function present in query -- As in below query we call empty_data_table() which is non-Immutable function because targetcollection in lookup stage is empty. SELECT documentdb_api.create_collection('db', 'nonImmutable'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db','nonImmutable',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ {"$lookup": {"from": "bar", "as": "x", "localField": "f_id", "foreignField": "_id"}}, {"$merge" : { "into": "bar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The query references collections that do not exist. Create the missing collections and retry. -- As below query usage system_rows and random function which are non-Immutable functions. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ { "$sample": { "size": 1000000 } }, {"$merge" : { "into": "bar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The $merge stage is not yet supported with the $sample aggregation stage. -- Merge inside transaction BEGIN; SELECT documentdb_api.insert('db', '{"insert":"insideTransaction", "documents":[{ "_id" : 3, "a" : 3, "b": "c" }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "insideTransaction", "pipeline": [ {"$merge" : { "into": "targetTransaction", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge is not permitted within an active transaction END; -- Option not supported failures SELECT documentdb_api.create_collection('db', 'optionNotSupported'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "optionNotSupportedOut", "whenMatched" : [] }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge 'whenMatched' with 'pipeline' not supported yet SELECT documentdb_api.shard_collection('db', 'optionNotSupportedOut', '{ "a": "hashed" }', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "optionNotSupported", "pipeline": [ {"$merge" : { "into" : "optionNotSupportedOut" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $merge for sharded output collection not supported yet SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "optionNotSupported", "pipeline": [ { "$match": { "name": "test" } }, { "$graphLookup": {"from": "optionNotSupported", "startWith": "$id", "connectFromField": "id", "connectToField": "ReportsTo", "as": "reportingHierarchy"}}, {"$merge":{ "into": "targetDataReplace"}}], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: $graphLookup is not supported with $merge stage yet. -- simple test case target database is not same as source database SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "sourceDumpData", "pipeline": [ {"$merge" : { "into": {"db" : "targetDB" , "coll" : "targetDumpData"}, "on" : "_id", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "sourceDB.sourceDumpData", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- let's verify we insert or update proper data in database. --try to insert 16 MB Document SELECT documentdb_api.insert_one('db','sourceDataValidation','{ "_id": 1, "item": "a" }' , NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); NOTICE: creating collection ERROR: Size 16777262 is larger than MaxDocumentSize 16777216 --try to insert bad _id field SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3]}}, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }'); NOTICE: creating collection ERROR: Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array -- try to update 16 MB document SELECT documentdb_api.insert_one('db','targetDataValidation','{ "_id": 1, "item": "a" }' , NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); ERROR: Size 16777262 is larger than MaxDocumentSize 16777216 --try to update bad _id field SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataValidation", "indexes": [{"key": {"item": 1}, "name": "index_1", "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3], "item" : 1}}, {"$merge" : {"into" : "targetDataValidation", "on" : "item"}} ], "cursor": { "batchSize": 1 } }'); ERROR: The '_id' field value must not be a type of array -- Basic Test with enable Native colocation SET documentdb.enableNativeColocation=true; SELECT documentdb_api.insert('db', '{"insert":"nativeSrc", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) --insert SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nativeSrc", "pipeline": [ {"$merge" : { "into": "nativeTar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.nativeSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'nativeTar'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) --replace SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nativeSrc", "pipeline": [ {"$merge" : { "into": "nativeTar"}} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.nativeSrc", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'nativeTar'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SET documentdb.enableNativeColocation=false; bson_aggregation_stage_out_tests_2.out000066400000000000000000001413621507310017400375600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 9830000; SET documentdb.next_collection_id TO 9830; SET documentdb.next_collection_index_id TO 9830; -- simplest test case working with db database SELECT documentdb_api.insert('db', '{"insert":"source", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : "target"} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "db", "coll" : "target2" } } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db', 'target2'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT documentdb_api.drop_collection('db','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db','target'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db','target2'); drop_collection --------------------------------------------------------------------- t (1 row) -- simplest test case working SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target"} ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('newdb', 'target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "newdb", "coll" : "target2" } } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('newdb', 'target2'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "movie" : "Iron Man 3", "Budget" : { "$numberInt" : "180000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "2" }, "movie" : "Captain America the winter soldier", "Budget" : { "$numberInt" : "170000000" }, "year" : { "$numberInt" : "2011" } } { "_id" : { "$numberInt" : "3" }, "movie" : "Aveneger Endgame", "Budget" : { "$numberInt" : "160000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "4" }, "movie" : "Spider Man", "Budget" : { "$numberInt" : "150000000" }, "year" : { "$numberInt" : "2012" } } { "_id" : { "$numberInt" : "5" }, "movie" : "Iron Man 2", "Budget" : { "$numberInt" : "140000000" }, "year" : { "$numberInt" : "2013" } } { "_id" : { "$numberInt" : "6" }, "movie" : "Iron Man 1", "Budget" : { "$numberInt" : "130000000" }, "year" : { "$numberInt" : "2013" } } (6 rows) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target2'); drop_collection --------------------------------------------------------------------- t (1 row) -- when source and target collection are same SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$project" : {"data" : "updating same"} } ,{"$out" : { "db" : "newdb", "coll" : "source" } } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The target collection cannot be the same as the source collection in $out stage. SELECT document FROM documentdb_api.collection('newdb', 'source'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "data" : "This is source collection" } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) -- case where target collection already exist: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('newdb', '{"insert":"target", "documents":[{ "_id" : 1, "data": "This is target collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "newdb", "coll" : "target" } } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('newdb', 'target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "data" : "This is source collection" } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- when target db is different: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "db2", "coll" : "target" } } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('db2', 'target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "data" : "This is source collection" } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db2','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- index validation: -- 1. If source and target are same collection, only data will get updated index should remain SELECT documentdb_api.insert('newdb', '{"insert":"src", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "src", "indexes": [{ "key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1" }] }'::documentdb_core.bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "src", "indexes": [{ "key": {"his is some index" :1}, "name": "index_2" }] }'::documentdb_core.bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "src" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, "name" : "index_1" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "his is some index" : { "$numberInt" : "1" } }, "name" : "index_2" } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "src", "pipeline": [ {"$project" : {"data" : "updating data"} }, {"$out" : { "db" : "newdb", "coll" : "src" } } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The target collection cannot be the same as the source collection in $out stage. SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "src" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, "name" : "index_1" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "his is some index" : { "$numberInt" : "1" } }, "name" : "index_2" } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT document FROM documentdb_api.collection('newdb', 'src'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "data" : "This is source collection" } (1 row) SELECT documentdb_api.drop_collection('newdb','src'); drop_collection --------------------------------------------------------------------- t (1 row) -- 2. if target already exist only data will get updated index should remain SELECT documentdb_api.insert('newdb', '{"insert":"src", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('newdb', '{"insert":"tar", "documents":[{ "_id" : 1, "data": "This is target collection"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "tar", "indexes": [{ "key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1" }] }'::documentdb_core.bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "tar", "indexes": [{ "key": {"his is some index" :1}, "name": "index_2" }] }'::documentdb_core.bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "tar" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, "name" : "index_1" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "his is some index" : { "$numberInt" : "1" } }, "name" : "index_2" } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "src", "pipeline": [ {"$project" : {"data" : "updating data"} }, {"$out" : { "db" : "newdb", "coll" : "tar" } } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.src", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "tar" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, "name" : "index_1" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.tar", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "his is some index" : { "$numberInt" : "1" } }, "name" : "index_2" } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT document FROM documentdb_api.collection('newdb', 'tar'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "data" : "updating data" } (1 row) SELECT documentdb_api.drop_collection('newdb','src'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','tar'); drop_collection --------------------------------------------------------------------- t (1 row) -- complex query with last stage $out: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "company": "Company A", "products": ["product1", "product2"], "amount": 100 , "services": ["service1", "service2"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('newdb','source','{ "_id": 2, "company": "Company B", "products": ["product3", "product4"], "amount": 120, "services": ["service3"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('newdb','target','{ "_id": 1, "item": "product1", "company_name": "Company A"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('newdb','target','{ "_id": 2, "item": "product3", "company_name": "Company B", "extra": "value1"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('newdb','target','{ "_id": 3, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "target", "pipeline": [ { "$lookup": { "from": "source", "pipeline": [ { "$match": { "quantity": { "$gt": 110 } }}], "as": "joined_docs", "localField": "company_name", "foreignField": "company" } }, {"$sort" : {"_id" : -1}} , {"$group" :{"_id" : "$company_name"}}, {"$project" : {"matched_docs" : 0}} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "newdb.target", "firstBatch" : [ { "_id" : "Company A" } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t | 4294967294 (1 row) SELECT document FROM documentdb_api.collection('newdb','target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "product1", "company_name" : "Company A" } { "_id" : { "$numberInt" : "2" }, "item" : "product3", "company_name" : "Company B", "extra" : "value1" } { "_id" : { "$numberInt" : "3" }, "item" : "product3", "company_name" : "Company B", "extra" : "value2" } (3 rows) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- case when _id is missing from last stage: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$project" : {"_id" : 0} } ,{"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT bson_dollar_project(document,'{"_id" : {"$gt" : ["$_id", null]} }') FROM documentdb_api.collection('newdb','target'); bson_dollar_project --------------------------------------------------------------------- { "_id" : true } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- test when source collection is view SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.create_collection_view('newdb', '{ "create": "sourceView", "viewOn": "source", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "sourceView", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.sourceView", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document FROM documentdb_api.collection('newdb', 'target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- test when source is sharded: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('newdb', 'source', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); NOTICE: creating collection cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "newdb.source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT document from documentdb_api.collection('newdb','target'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "Test Case" } (1 row) SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- Negative test cases SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : 1 } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Expected 'string' or 'document' type but found 'int' type SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll' SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll' SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"coll" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll' SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a", "coll" : "a", "other" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll' SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a", "coll" : 1} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: Field type mismatch in (coll): int expected string SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : 1, "coll" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: wrong type for field (db) int != string -- test when target is view: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Duplicate key violation on the requested collection: Index '_id_'"" } ] }",f) (1 row) SELECT documentdb_api.create_collection_view('newdb', '{ "create": "targetView", "viewOn": "source", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "targetView" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The namespace newdb.targetView refers to a view object rather than a collection SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) -- test when target is sharded: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('newdb','target',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('newdb', 'target', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: newdb.target cannot be sharded SELECT documentdb_api.drop_collection('newdb','source'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('newdb','target'); drop_collection --------------------------------------------------------------------- t (1 row) -- let's verify we insert or update proper data in database. --try to insert 16 MB Document SELECT documentdb_api.insert_one('newdb','sourceDataValidation','{ "_id": 1, "item": "a" }' , NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('newdb', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$out" : "targetDataValidation"} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); NOTICE: creating collection ERROR: Size 16777262 is larger than MaxDocumentSize 16777216 --try to insert bad _id field SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3]}}, {"$out" : "targetDataValidation"} ], "cursor": { "batchSize": 1 } }'); NOTICE: creating collection ERROR: The '_id' field value must not be a type of array -- Let's take a look at explain plan --1) colocated tables , single shard distributed SELECT documentdb_api.insert_one('newdb','explainsrc',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('newdb', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); NOTICE: creating collection QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Merge on documents_9862_9830118 documents_9862 -> Nested Loop Left Join -> Bitmap Heap Scan on documents_9861_9830116 collection Recheck Cond: (shard_key_value = '9861'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '9861'::bigint) -> Materialize -> Bitmap Heap Scan on documents_9862_9830118 documents_9862 Recheck Cond: (shard_key_value = '9862'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '9862'::bigint) (16 rows) --2) non colocated tables, hash shard distributed SELECT documentdb_api.insert_one('db','explainsrc',' {"_id": 1, "name": "Test Case"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); NOTICE: creating collection QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) MERGE INTO documents_9864 method: pull to coordinator -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, target_shard_key_value, generated_object_id FROM (SELECT collection.document, '9864'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id FROM documentdb_data.documents_9863_9830125 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '9863'::bigint)) citus_insert_select_subquery Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9863_9830125 collection Output: collection.document, '9864'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) Recheck Cond: (collection.shard_key_value = '9863'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '9863'::bigint) (14 rows) --3) sharded source SELECT documentdb_api.shard_collection('newdb', 'explainsrc', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus MERGE INTO ...) MERGE INTO documents_9864 method: pull to coordinator -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.target_shard_key_value, remote_scan.generated_object_id Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, target_shard_key_value, generated_object_id FROM (SELECT collection.document, '9864'::bigint AS target_shard_key_value, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id FROM documentdb_data.documents_9863_9830125 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '9863'::bigint)) citus_insert_select_subquery Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_9863_9830125 collection Output: collection.document, '9864'::bigint, documentdb_api_internal.bson_dollar_merge_generate_object_id(collection.document) Recheck Cond: (collection.shard_key_value = '9863'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '9863'::bigint) (14 rows) -- simplest test case working with db database SELECT documentdb_api.insert('db', '{"insert":"source", "documents":[ { "_id" : 11, "movie": "Thor", "Budget": 123456, "year": 1987 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) --validate empty collection check SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : ""} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: An invalid and empty namespace has been specified -- out should fail when query has mutable function, if query non existent collection or query has $sample stage SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ {"$lookup": {"from": "bar", "as": "x", "localField": "f_id", "foreignField": "_id"}}, {"$out" : "bar" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The query references collections that do not exist. Create the missing collections and retry. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ { "$sample": { "size": 1000000 } }, {"$out" : "bar" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: The $out stage is not yet supported with the $sample aggregation stage. bson_aggregation_stage_project_tests.out000066400000000000000000002513771507310017400402060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 32000; SET documentdb.next_collection_id TO 3200; SET documentdb.next_collection_index_id TO 3200; SELECT documentdb_api.insert_one('db','projectops','{"_id":"1", "a" : { "b" : 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"2", "a" : { "b" : [ 0, 1, 2]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"6", "a" : [ { "c" : 0 }, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"8", "a" : { "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectops','{"_id":"9", "c" : { "d" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 3200 | { "" : "1" } | { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } 3200 | { "" : "2" } | { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } 3200 | { "" : "3" } | { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } 3200 | { "" : "4" } | { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } 3200 | { "" : "5" } | { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } 3200 | { "" : "6" } | { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } 3200 | { "" : "7" } | { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } 3200 | { "" : "8" } | { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } 3200 | { "" : "9" } | { "_id" : "9", "c" : { "d" : { "$numberInt" : "1" } } } (9 rows) -- basic a.b query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { } ] } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a.b" : 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (9 rows) -- basic a.b expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": 1 }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { } ] } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a" : { "b": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (9 rows) -- basic a.b.1 query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b.1": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { } } { "a" : { "b" : [ ] } } { "a" : [ { }, { }, { } ] } { "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { } ] } { "a" : [ { }, { }, { } ] } { "a" : { } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a.b.1": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (9 rows) -- basic a.b.1 expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": { "1" : 1 } }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { } } { "a" : { "b" : [ ] } } { "a" : [ { }, { }, { } ] } { "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { } ] } { "a" : [ { }, { }, { } ] } { "a" : { } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a" : { "b": { "1" : 1 } } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (9 rows) -- path collsion due to conflicting paths SELECT bson_dollar_project(document, '{ "a.b.1": 1, "a.b": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b SELECT bson_dollar_project(document, '{ "a.b.1": 1, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b -- path collsion due to conflicting paths SELECT bson_dollar_project(document, '{ "a.b": 1, "a.b.1": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b.1 remaining portion b.1 SELECT bson_dollar_project(document, '{ "a.b": 1, "a.b.1": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b.1 remaining portion b.1 -- basic a.b, and a.c query with id excluded and included - should be both a.b and a.c SELECT bson_dollar_project(document, '{ "a.b": 1, "a.c": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a.b": 1, "a.c": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "9" } (9 rows) -- basic a.b and a.c expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": 1, "c": 1 }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a" : { "b": 1, "c": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "9" } (9 rows) -- Hybrid: a.c and a.b as object and dotted. SELECT bson_dollar_project(document, '{ "a" : { "b": 1 }, "a.c": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_dollar_project(document, '{ "a" : { "c": 1 }, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } } ] } { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "9" } (9 rows) -- basic a.b excluded query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { } } { "a" : { } } { "a" : [ { }, { }, { } ] } { "a" : [ { }, { }, { } ] } { "a" : { } } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { "c" : { "d" : { "$numberInt" : "1" } } } (9 rows) SELECT bson_dollar_project(document, '{ "a.b" : 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "2", "a" : { } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { }, { }, { } ] } { "_id" : "5", "a" : { } } { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { } ] } { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "9", "c" : { "d" : { "$numberInt" : "1" } } } (9 rows) -- basic a.b and a.c with mixed inclusion (error path) query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 1, "a.c": 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: exclusion cannot be applied to field a.c within the inclusion projection. SELECT bson_dollar_project(document, '{ "a.b" : 1, "a.c": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: exclusion cannot be applied to field a.c within the inclusion projection. -- special case projections SELECT bson_dollar_project(document, '{ "_id" : 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1" } { "_id" : "2" } { "_id" : "3" } { "_id" : "4" } { "_id" : "5" } { "_id" : "6" } { "_id" : "7" } { "_id" : "8" } { "_id" : "9" } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { "c" : { "d" : { "$numberInt" : "1" } } } (9 rows) -- field 'const' projections - this just projects a const value for all rows. SELECT bson_dollar_project(document, '{ "_id" : 1, "c": "someString", "a": [ 1, 2, 3] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "2", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "3", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "4", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "5", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "6", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "7", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "8", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "_id" : "9", "c" : "someString", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "c": "someString", "a": [ 1, 2, 3] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : "someString" } { "c" : "someString", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (9 rows) -- mix and match field path projection and const value projection. SELECT bson_dollar_project(document, '{ "_id" : 1, "c": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } }, "c" : [ "1" ] } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "c" : [ "1" ] } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], "c" : [ "1" ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], "c" : [ "1" ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, "c" : [ "1" ] } { "_id" : "6", "a" : [ { } ], "c" : [ "1" ] } { "_id" : "7", "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ], "c" : [ "1" ] } { "_id" : "8", "a" : { }, "c" : [ "1" ] } { "_id" : "9", "c" : [ "1" ] } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "c": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } }, "c" : [ "1" ] } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "c" : [ "1" ] } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], "c" : [ "1" ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], "c" : [ "1" ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, "c" : [ "1" ] } { "a" : [ { } ], "c" : [ "1" ] } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ], "c" : [ "1" ] } { "a" : { }, "c" : [ "1" ] } { "c" : [ "1" ] } (9 rows) -- const field and path projection with the same field name - see which one wins - it's the one on the right. SELECT bson_dollar_project(document, '{ "_id" : 0, "a": [ "1" ], "a": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a": 1, "a": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } { "a" : [ "1" ] } (9 rows) -- mix and match field path projection and const value projection. SELECT bson_dollar_project(document, '{ "_id" : 1, "a.g": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "3" }, "g" : [ "1" ] } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "g" : [ "1" ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "g" : [ "1" ] } } { "_id" : "6", "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "_id" : "7", "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "b" : { "$numberInt" : "2" }, "g" : [ "1" ] } ] } { "_id" : "8", "a" : { "g" : [ "1" ] } } { "_id" : "9", "a" : { "g" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.g": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] } } { "a" : [ { "b" : { "$numberInt" : "0" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "3" }, "g" : [ "1" ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "g" : [ "1" ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "g" : [ "1" ] } } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "b" : { "$numberInt" : "2" }, "g" : [ "1" ] } ] } { "a" : { "g" : [ "1" ] } } { "a" : { "g" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.g": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "g" : [ "1" ] } } { "a" : { "g" : [ "1" ] } } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : { "g" : [ "1" ] } } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : { "g" : [ "1" ] } } { "a" : { "g" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a": { "g": [ "1" ] }, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] } } { "a" : [ { "b" : { "$numberInt" : "0" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "3" }, "g" : [ "1" ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "g" : [ "1" ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "g" : [ "1" ] } } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "b" : { "$numberInt" : "2" }, "g" : [ "1" ] } ] } { "a" : { "g" : [ "1" ] } } { "a" : { "g" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a": { "g": [ "1" ], "b": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] } } { "a" : [ { "b" : { "$numberInt" : "0" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "1" }, "g" : [ "1" ] }, { "b" : { "$numberInt" : "3" }, "g" : [ "1" ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "g" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "g" : [ "1" ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "g" : [ "1" ] } } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] } ] } { "a" : [ { "g" : [ "1" ] }, { "g" : [ "1" ] }, { "b" : { "$numberInt" : "2" }, "g" : [ "1" ] } ] } { "a" : { "g" : [ "1" ] } } { "a" : { "g" : [ "1" ] } } (9 rows) -- mix and match field path projection and const values on different roots. SELECT bson_dollar_project(document, '{ "_id" : 0, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } }, "e" : { "f" : [ "1" ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "e" : { "f" : [ "1" ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], "e" : { "f" : [ "1" ] } } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], "e" : { "f" : [ "1" ] } } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, "e" : { "f" : [ "1" ] } } { "a" : [ { } ], "e" : { "f" : [ "1" ] } } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ], "e" : { "f" : [ "1" ] } } { "a" : { }, "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "c": 1, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "e" : { "f" : [ "1" ] } } { "c" : { "d" : { "$numberInt" : "1" } }, "e" : { "f" : [ "1" ] } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c.d": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "d" : [ "1" ] } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "d" : [ "1" ] } } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : { "d" : [ "1" ] } }, { "b" : { "$numberInt" : "1" }, "c" : { "d" : [ "1" ] } }, { "b" : { "$numberInt" : "3" }, "c" : { "d" : [ "1" ] } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "d" : [ "1" ] } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "d" : [ "1" ] } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : { "d" : [ "1" ] } } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : { "d" : [ "1" ] } } } { "a" : [ { "c" : { "d" : [ "1" ] } }, { "c" : { "d" : [ "1" ] } } ] } { "a" : [ { "c" : { "d" : [ "1" ] } }, { "c" : { "d" : [ "1" ] } }, { "b" : { "$numberInt" : "2" }, "c" : { "d" : [ "1" ] } } ] } { "a" : { "c" : { "d" : [ "1" ] } } } { "a" : { "c" : { "d" : [ "1" ] } } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : [ "1" ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ "1" ] } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : [ "1" ] }, { "b" : { "$numberInt" : "1" }, "c" : [ "1" ] }, { "b" : { "$numberInt" : "3" }, "c" : [ "1" ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ "1" ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : [ "1" ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : [ "1" ] } } { "a" : [ { "c" : [ "1" ] }, { "c" : [ "1" ] } ] } { "a" : [ { "c" : [ "1" ] }, { "c" : [ "1" ] }, { "b" : { "$numberInt" : "2" }, "c" : [ "1" ] } ] } { "a" : { "c" : [ "1" ] } } { "a" : { "c" : [ "1" ] } } (9 rows) -- field selector that is an object -- TODO - actual expression support SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c": { "$literal" : 1.0 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberDouble" : "1.0" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "1" }, "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "3" }, "c" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : { "$numberDouble" : "1.0" } } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : { "$numberDouble" : "1.0" } } } { "a" : [ { "c" : { "$numberDouble" : "1.0" } }, { "c" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "c" : { "$numberDouble" : "1.0" } }, { "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberDouble" : "1.0" } } ] } { "a" : { "c" : { "$numberDouble" : "1.0" } } } { "a" : { "c" : { "$numberDouble" : "1.0" } } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": { "$literal" : 1.0 } } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberDouble" : "1.0" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "1" }, "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "3" }, "c" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberDouble" : "1.0" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : { "$numberDouble" : "1.0" } } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : { "$numberDouble" : "1.0" } } } { "a" : [ { "c" : { "$numberDouble" : "1.0" } }, { "c" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "c" : { "$numberDouble" : "1.0" } }, { "c" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberDouble" : "1.0" } } ] } { "a" : { "c" : { "$numberDouble" : "1.0" } } } { "a" : { "c" : { "$numberDouble" : "1.0" } } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "c": "$a.b" }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } }, "c" : { "$numberInt" : "1" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], "c" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, "c" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a" : [ { } ], "c" : [ ] } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ], "c" : [ { "$numberInt" : "2" } ] } { "a" : { } } { } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": "$a.b" } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }, { "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }, { "b" : { "$numberInt" : "3" }, "c" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { "c" : [ ] }, { "c" : [ ] } ] } { "a" : [ { "c" : [ { "$numberInt" : "2" } ] }, { "c" : [ { "$numberInt" : "2" } ] }, { "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "2" } ] } ] } { "a" : { } } { "a" : { } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": "$a" } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "b" : { "$numberInt" : "1" } } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } } { "a" : [ { "b" : { "$numberInt" : "0" }, "c" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] }, { "b" : { "$numberInt" : "1" }, "c" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] }, { "b" : { "$numberInt" : "3" }, "c" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ], "c" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], "c" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } } { "a" : [ { "c" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] }, { "c" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } ] } { "a" : [ { "c" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] }, { "c" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] }, { "b" : { "$numberInt" : "2" }, "c" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } ] } { "a" : { "c" : { "c" : { "$numberInt" : "1" } } } } { "a" : { } } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberDouble" : "1.0" } } } { "a" : { "b" : { "$numberDouble" : "1.0" } } } { "a" : [ { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } } ] } { "a" : { "b" : { "$numberDouble" : "1.0" } } } { "a" : [ { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } } ] } { "a" : [ { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } }, { "b" : { "$numberDouble" : "1.0" } } ] } { "a" : { "b" : { "$numberDouble" : "1.0" } } } { "a" : { "b" : { "$numberDouble" : "1.0" } } } (9 rows) -- Fields selector, intermediate node having hasField set tests SELECT bson_dollar_project(document, '{ "_id" : 0, "c": { "b" : "1"} , "x" : "1"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } { "c" : { "b" : "1" }, "x" : "1" } (9 rows) SELECT bson_dollar_project(document, '{ "_id" : 0, "x" : "1", "c": { "b" : "1" }}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "x" : "1", "c" : { "b" : "1" } } { "c" : { "b" : "1" }, "x" : "1" } (9 rows) -- Add multiple function calls SELECT bson_dollar_project(document, '{ "a.b" : 1, "_id": 0 }'), bson_dollar_project(document, '{"a.c": 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project | bson_dollar_project --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" } } } | { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } | { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } | { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } | { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } | { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a" : [ { } ] } | { "a" : [ { }, { "$numberInt" : "2" } ] } { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } | { "a" : [ { }, { }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { } } | { "a" : { } } { } | { "c" : { "d" : { "$numberInt" : "1" } } } (9 rows) SELECT bson_dollar_unset('{ "_id": 1, "x": 1, "y": [{ "z": 1, "foo": 1 }] }', '{ "": ["x", "y.z"] }'); bson_dollar_unset --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "y" : [ { "foo" : { "$numberInt" : "1" } } ] } (1 row) SELECT bson_dollar_unset('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": "copies" }'); bson_dollar_unset --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "title" : "Bees Babble", "isbn" : "999999999333", "author" : { "last" : "Bumble", "first" : "Bee" } } (1 row) SELECT bson_dollar_unset('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": ["isbn", "author.first", "copies.warehouse"] }'); bson_dollar_unset --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "title" : "Bees Babble", "author" : { "last" : "Bumble" }, "copies" : [ { "qty" : { "$numberInt" : "2" } }, { "qty" : { "$numberInt" : "5" } } ] } (1 row) -- in aggregation you can unset or project the _id away. SELECT bson_dollar_unset('{"_id": 1, "a": 1, "b": 2 }', '{ "": "_id" }'); bson_dollar_unset --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) SELECT bson_dollar_project('{"_id": 1, "a": 1, "b": 2 }', '{ "_id": 0 }'); bson_dollar_project --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- Spec tree equivalency tests SELECT bson_dollar_project(document, '{"a.b.c" : "1"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } } { "_id" : "3", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "c" : "1" } ] } } { "_id" : "6", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "7", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "8", "a" : { "b" : { "c" : "1" } } } { "_id" : "9", "a" : { "b" : { "c" : "1" } } } (9 rows) SELECT bson_dollar_project(document, '{"a.b" : { "c": "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } } { "_id" : "3", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "c" : "1" } ] } } { "_id" : "6", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "7", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "8", "a" : { "b" : { "c" : "1" } } } { "_id" : "9", "a" : { "b" : { "c" : "1" } } } (9 rows) SELECT bson_dollar_project(document, '{"a" : { "b.c": "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } } { "_id" : "3", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "c" : "1" } ] } } { "_id" : "6", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "7", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "8", "a" : { "b" : { "c" : "1" } } } { "_id" : "9", "a" : { "b" : { "c" : "1" } } } (9 rows) SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : "1" } } } { "_id" : "2", "a" : { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } } { "_id" : "3", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] }, { "b" : [ { "c" : "1" }, { "c" : "1" }, { "c" : "1" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "c" : "1" } ] } } { "_id" : "6", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "7", "a" : [ { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } }, { "b" : { "c" : "1" } } ] } { "_id" : "8", "a" : { "b" : { "c" : "1" } } } { "_id" : "9", "a" : { "b" : { "c" : "1" } } } (9 rows) -- path collision tests SELECT bson_dollar_project(document, '{"a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b.c remaining portion b.c SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path b SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path b SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path b SELECT bson_dollar_project(document, '{"a.b": {"c" : 1.0}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path c SELECT bson_dollar_project(document, '{"a.b": {"c" : "$a.b"}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path c SELECT bson_dollar_project(document, '{"a.b.c": "$_id", "a.b": "1.0"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path a.b SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": { "d": "$_id"}}}, "a.b": {"c" : 1.0}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: Collision detected in specified path c -- Invalid key format tests SELECT bson_dollar_project(document, '{"$a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT bson_dollar_project(document, '{"$isArray": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT bson_dollar_project(document, '{"$keyName": "newVal"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT documentdb_api.insert_one('db','projectops','{"_id":"10", "a" : { "b" : { "c" : "abc" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Spec tree equivalency tests SELECT bson_dollar_project(document, '{"a.b.c" : 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "10", "a" : { "b" : { "c" : "abc" } } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (10 rows) SELECT bson_dollar_project(document, '{"a.b" : { "c": 1}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "10", "a" : { "b" : { "c" : "abc" } } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (10 rows) SELECT bson_dollar_project(document, '{"a" : { "b.c": 1}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "10", "a" : { "b" : { "c" : "abc" } } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (10 rows) SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": 1}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { } } { "_id" : "10", "a" : { "b" : { "c" : "abc" } } } { "_id" : "2", "a" : { "b" : [ ] } } { "_id" : "3", "a" : [ { }, { }, { } ] } { "_id" : "4", "a" : [ { "b" : [ ] }, { "b" : [ ] }, { "b" : [ ] } ] } { "_id" : "5", "a" : { "b" : [ { } ] } } { "_id" : "6", "a" : [ { } ] } { "_id" : "7", "a" : [ { }, { }, { } ] } { "_id" : "8", "a" : { } } { "_id" : "9" } (10 rows) SELECT documentdb_api.insert_one('db','projectops','{"_id":"11", "a" : { "b_" : { "c" : { "d" : 100 } }, "c" : { "d" : { "e" : "_e"}}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Spec tree test to check if a node is incorrectly marked with Intermediate_WithField SELECT bson_dollar_project(document, '{"a.b.c" : { "d" : 1 }, "a.c.d" : {"e" : "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "c" : { "d" : { "e" : "1" } } } } { "_id" : "10", "a" : { "b" : { }, "c" : { "d" : { "e" : "1" } } } } { "_id" : "11", "a" : { "c" : { "d" : { "e" : "1" } } } } { "_id" : "2", "a" : { "b" : [ ], "c" : { "d" : { "e" : "1" } } } } { "_id" : "3", "a" : [ { "c" : { "d" : { "e" : "1" } } }, { "c" : { "d" : { "e" : "1" } } }, { "c" : { "d" : { "e" : "1" } } } ] } { "_id" : "4", "a" : [ { "b" : [ ], "c" : { "d" : { "e" : "1" } } }, { "b" : [ ], "c" : { "d" : { "e" : "1" } } }, { "b" : [ ], "c" : { "d" : { "e" : "1" } } } ] } { "_id" : "5", "a" : { "b" : [ { } ], "c" : { "d" : { "e" : "1" } } } } { "_id" : "6", "a" : [ { "c" : { "d" : { "e" : "1" } } }, { "c" : { "d" : { "e" : "1" } } } ] } { "_id" : "7", "a" : [ { "c" : { "d" : { "e" : "1" } } }, { "c" : { "d" : { "e" : "1" } } }, { "c" : { "d" : { "e" : "1" } } } ] } { "_id" : "8", "a" : { "c" : { "d" : { "e" : "1" } } } } { "_id" : "9", "a" : { "c" : { "d" : { "e" : "1" } } } } (11 rows) -- test to check if internal "_id" respects the inclusion/exclusion SELECT documentdb_api.insert_one('db','projectops','{"_id":"12", "a" : { "_id" : { "idVal" : 100 }, "b" : { "c" : { "_id" : "idVal"}}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_project(document, '{"_id" : 1, "a" : {"_id" : 1}, "a.b" : { "c" : {"_id" : 0}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; ERROR: exclusion cannot be applied to field _id within the inclusion projection. -- Test nested array projections SELECT bson_dollar_project('{"_id":"1", "a" : [1, {"d":1}, [3, 4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "c" : { "d" : "1" } }, { "c" : { "d" : "1" } }, [ { "c" : { "d" : "1" } }, { "c" : { "d" : "1" } } ], { "c" : { "d" : "1" } } ] } (1 row) SELECT bson_dollar_project('{"_id":"1", "a" : [1, {"d":1}, [ { "c" : { "b" : 1 } },4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "c" : { "d" : "1" } }, { "c" : { "d" : "1" } }, [ { "c" : { "d" : "1" } }, { "c" : { "d" : "1" } } ], { "c" : { "d" : "1" } } ] } (1 row) -- a.b.0 excluded with _id included should still write out non-intermediate paths SELECT bson_dollar_project('{ "_id": 3, "x": { "y": 1 } }', '{ "_id" : 1, "x.y": 0 }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "x" : { } } (1 row) SELECT bson_dollar_project('{ "_id": 5, "x": { "y": [ 1, 2, 3]}, "v": { "w": [ 4, 5, 6 ]}}', '{ "_id" : 1, "x.y": 0 }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "x" : { }, "v" : { "w" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } (1 row) SELECT bson_dollar_project('{ "_id": 6, "x": { "y": 4}, "v": { "w": 4}}', '{ "_id" : 1, "x.y": 0 }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "x" : { }, "v" : { "w" : { "$numberInt" : "4" } } } (1 row) SELECT bson_dollar_project('{ "_id": 10, "a": 10, "x": 1 }', '{ "_id" : 1, "x.y": 0 }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "x" : { "$numberInt" : "1" } } (1 row) -- Empty spec is a no-op SELECT bson_dollar_project(document, '{}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "10", "a" : { "b" : { "c" : "abc" } } } { "_id" : "11", "a" : { "b_" : { "c" : { "d" : { "$numberInt" : "100" } } }, "c" : { "d" : { "e" : "_e" } } } } { "_id" : "12", "a" : { "_id" : { "idVal" : { "$numberInt" : "100" } }, "b" : { "c" : { "_id" : "idVal" } } } } { "_id" : "2", "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "3", "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : "4", "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "_id" : "5", "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "_id" : "6", "a" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "_id" : "7", "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : "8", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "9", "c" : { "d" : { "$numberInt" : "1" } } } (12 rows) bson_aggregation_stage_replaceroot_tests.out000066400000000000000000000224261507310017400410460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 33000; SET documentdb.next_collection_id TO 3300; SET documentdb.next_collection_index_id TO 3300; SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"1", "int": 10, "x" : {"y" : [1, 2]}, "a" : { "b" : { "arr": [ "x", 1, 2.0, true ]} } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"3", "boolean": false, "a" : {"x" : "no", "b": {"id": "$_id"}}, "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'replaceRootOps') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 3300 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "x" : { "y" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, "a" : { "b" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } } 3300 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 3300 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : { "x" : "no", "b" : { "id" : "$_id" } }, "b" : "yes", "c" : true } (3 rows) -- replace by newRoot SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "myArr" : [ "1", { "b" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } ] } { "myArr" : [ "2", { "b" : { "c" : { "$numberInt" : "3" } } } ] } { "myArr" : [ "3", { "x" : "no", "b" : { "id" : "$_id" } } ] } (3 rows) SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"], "2" : { "x" : "$a.b"} }}') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "myArr" : [ "1", { "b" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } ], "2" : { "x" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } } { "myArr" : [ "2", { "b" : { "c" : { "$numberInt" : "3" } } } ], "2" : { "x" : { "c" : { "$numberInt" : "3" } } } } { "myArr" : [ "3", { "x" : "no", "b" : { "id" : "$_id" } } ], "2" : { "x" : { "id" : "$_id" } } } (3 rows) -- Multiple "newRoot". Uses the most recent one. SELECT bson_dollar_replace_root(document, '{ "newRoot": {}, "newRoot": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "myArr" : [ "1", { "b" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } ] } { "myArr" : [ "2", { "b" : { "c" : { "$numberInt" : "3" } } } ] } { "myArr" : [ "3", { "x" : "no", "b" : { "id" : "$_id" } } ] } (3 rows) -- Can't have anything other than "newRoot" SELECT bson_dollar_replace_root(document, '{ "newRoot1": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The BSON field '$replaceRoot.newRoot1' is not recognized as a valid or supported field name. SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"]}, "b": "c"}') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The BSON field '$replaceRoot.b' is not recognized as a valid or supported field name. -- 'newRoot' is empty document SELECT bson_dollar_replace_root(document, '{ "newRoot": { } }') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { } { } { } (3 rows) -- newRoot is required SELECT bson_dollar_replace_root(document, '{ }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The required BSON field '$replaceRoot.newRoot' is not present in the data. SELECT bson_dollar_replace_root(document, '{ "newRoot": 10 }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must produce an object value, but instead it yielded: 10. The type of this resulting value is: 'int'. SELECT bson_dollar_replace_root(document, '{ "newRoot": "$a" }') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "b" : { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "b" : { "c" : { "$numberInt" : "3" } } } { "x" : "no", "b" : { "id" : "$_id" } } (3 rows) SELECT bson_dollar_replace_root(document, '{ "newRoot": "$a.b" }') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } { "c" : { "$numberInt" : "3" } } { "id" : "$_id" } (3 rows) SELECT bson_dollar_replace_root(document, '{ "newRoot": "$x.y" }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must produce an object value, but instead it yielded: [ 1, 2 ]. The type of this resulting value is: 'array'. -- newRoot is an operator expression SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$isArray" : "$a.b.arr"} }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must produce an object value, but instead it yielded: true. The type of this resulting value is: 'bool'. SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$literal" : 2.0 } }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must produce an object value, but instead it yielded: 2. The type of this resulting value is: 'double'. -- if the operator expression references a field which is a field path expression in the original document {"a": {"b": {"id": "$_id"}}}, "$_id" should be treated as a literal. SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$mergeObjects": [ { "dogs": 0, "cats": 0, "birds": 0, "fish": 0 }, "$a.b" ] } }') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_dollar_replace_root --------------------------------------------------------------------- { "dogs" : { "$numberInt" : "0" }, "cats" : { "$numberInt" : "0" }, "birds" : { "$numberInt" : "0" }, "fish" : { "$numberInt" : "0" }, "arr" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } { "dogs" : { "$numberInt" : "0" }, "cats" : { "$numberInt" : "0" }, "birds" : { "$numberInt" : "0" }, "fish" : { "$numberInt" : "0" }, "c" : { "$numberInt" : "3" } } { "dogs" : { "$numberInt" : "0" }, "cats" : { "$numberInt" : "0" }, "birds" : { "$numberInt" : "0" }, "fish" : { "$numberInt" : "0" }, "id" : "$_id" } (3 rows) -- SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$mergeObjects": [ ["dogs", "cats", "birds", "fish"], "$a.b" ] } }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: Expected 'document' type for $mergeObjects but value [ "dogs", "cats", "birds", "fish" ] has 'array' type -- negative SELECT bson_dollar_replace_root('{}', '{ "newRoot": 1 }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must produce an object value, but instead it yielded: 1. The type of this resulting value is: 'int'. SELECT bson_dollar_replace_root('{}', '{ "newRoot": "$x" }') FROM documentdb_api.collection('db', 'replaceRootOps'); ERROR: The expression 'newRoot' must result in an object, however the computed value was missing, with type identified as 'missing'. bson_aggregation_stage_sample_tests.out000066400000000000000000000146461507310017400400150ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- CREATE EXTENSION IF NOT EXISTS tsm_system_rows; SET citus.next_shard_id TO 70000; SET documentdb.next_collection_id TO 7000; SET documentdb.next_collection_index_id TO 7000; -- Insert data SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 1, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 2, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 3, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 4, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 5, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 6, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Tests and explain for collection with data -- SYSTEM sampling method, SYSTEM_ROWS performs block-level sampling, -- so that the sample is not completely random but may be subject to clustering effects. -- especially if only a small number of rows are requested. -- https://www.postgresql.org/docs/current/tsm-system-rows.html -- Sample with cursor for unsharded collection not supported - use persisted cursor SELECT * FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => '{ "aggregate": "sampleTest", "pipeline": [ { "$sample": { "size": 3 } }, { "$project": { "_id": 0 } } ], "cursor": { "batchSize": 1 } }', cursorId => 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.sampleTest", "firstBatch" : [ { "product" : "beer", "unitPrice" : { "$numberInt" : "1" }, "stock" : { "$numberInt" : "1" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967294" }, "qp" : true, "qk" : { "$numberInt" : "2" }, "qn" : "cursor_4294967294", "numIters" : { "$numberInt" : "0" }, "sn" : NOW_SYS_VARIABLE } | t | 4294967294 (1 row) -- Shard orders collection on item SELECT documentdb_api.shard_collection('db','sampleTest', '{"product":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- If the collection is sharded, have to call TABLESAMPLE SYSTEM_ROWS(n) LIMIT n -- SYSTEM_ROWS(n) may always be optimal, but important, as one but all shards may be -- emptty. If we use SYSTEM_ROWS( Distributed Subplan X_X -> Limit -> Sort Sort Key: remote_scan."?sort?" -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Sort Sort Key: (random()) -> Sample Scan on documents_7000_70016 collection Sampling: system_rows ('3'::bigint) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Function Scan on read_intermediate_result intermediate_result (20 rows) bson_aggregation_stage_set_tests.out000066400000000000000000000376631507310017400373330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 360000; SET documentdb.next_collection_id TO 3600; SET documentdb.next_collection_index_id TO 3600; SELECT documentdb_api.insert_one('db','setOps','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setOps','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','setOps','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'setOps') ORDER BY object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 3600 | { "" : "1" } | { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } 3600 | { "" : "2" } | { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } 3600 | { "" : "3" } | { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) -- add newField SELECT bson_dollar_set(document, '{ "newField" : "1", "a.y": ["p", "q"]}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ], "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } }, "y" : [ "p", "q" ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "y" : [ "p", "q" ] } } (3 rows) -- add field that evaluates $_id SELECT bson_dollar_set(document, '{ "newField" : "3", "a": "$_id"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : "1", "newField" : "3" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : "2", "newField" : "3" } { "_id" : "3", "boolean" : false, "a" : "3", "b" : "yes", "c" : true, "newField" : "3" } (3 rows) -- Add integer field (note that, {"field" : 1} is treated as inclusion for $project but add for $set) SELECT bson_dollar_set(document, '{ "int" : 1, "doble": 2.0, "bool": false, "a.b": false, "a.b.c": 2.0, "a": "$_id"}') FROM documentdb_api.collection('db', 'setOps'); ERROR: Collision detected in specified path a.b.c remaining portion b.c -- $set array duplication -- Expected value of the field "a" of dco(id=1), after the following $set: { "a.b.c": "_"} is: -- "a": {"b" : ["c" : "-", "c" : "-","c" : "-","c" : "-",]} SELECT bson_dollar_set(document, '{ "a.b.c" : "-"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "-" }, { "c" : "-" }, { "c" : "-" }, { "c" : "-" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "-" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "-" } } } (3 rows) -- $set integer in a nested paths SELECT bson_dollar_set(document, '{ "a" : {"b" : 1}}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "$numberInt" : "1" } } } (3 rows) -- $set integer in a nested paths SELECT bson_dollar_set(document, '{ "a" : {"b" : { "d": 2.5}}}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } }, { "d" : { "$numberDouble" : "2.5" } } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" }, "d" : { "$numberDouble" : "2.5" } } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "d" : { "$numberDouble" : "2.5" } } } } (3 rows) -- $set to check the a.b field of doc(id=2) changes -- from: {"a" : { "b" : {"c": 3}} -- to: "a" : { "b" : {"c": 3, "d": "-"} SELECT bson_dollar_set(document, '{ "a.b.d" : "-"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "d" : "-" }, { "d" : "-" }, { "d" : "-" }, { "d" : "-" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" }, "d" : "-" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "d" : "-" } } } (3 rows) -- $set: Applying multiple expressions with overlapping field paths SELECT bson_dollar_set(document, '{ "a.b.c" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" }, { "c" : "_c", "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "_c", "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "_c", "d" : "_d", "e" : "_e" } } } (3 rows) -- $set: Applying multiple expressions with overlapping field paths SELECT bson_dollar_set(document, '{ "a.b.c" : "$_id", "a.b.d" : "$b", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" }, { "c" : "1", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : "2", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : "3", "d" : "yes", "e" : "_e" } } } (3 rows) -- $set: If matching subpath in a document has an array, remaining path of the $set spec tree is duplicated for all array elelemnts. Remain subpath may need recursion. SELECT bson_dollar_set(document, '{ "a.b.c.d.e" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : { "d" : { "e" : "_c" } }, "d" : "_d", "e" : "_e" } } } (3 rows) -- $set where "$a.b" needs to be evaluated while writing a path SELECT bson_dollar_set(document, '{ "a.b.c.d.e" : "$a.b", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" }, { "c" : { "d" : { "e" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } }, "d" : "_d", "e" : "_e" } ] } } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "d" : { "e" : { "c" : { "$numberInt" : "3" } } } }, "d" : "_d", "e" : "_e" } } } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "a" : { "b" : { "c" : { "d" : { } }, "d" : "_d", "e" : "_e" } } } (3 rows) -- Evaluating array expression i.e., : [, ] is not a documented behavior SELECT bson_dollar_set(document, '{ "newarray" : [{ "$literal": 1.0 }, {"copyId": "$_id"}]}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] }, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "1" } ] } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } }, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "2" } ] } { "_id" : "3", "boolean" : false, "a" : "no", "b" : "yes", "c" : true, "newarray" : [ { "$numberDouble" : "1.0" }, { "copyId" : "3" } ] } (3 rows) -- add newField with concatArrays SELECT bson_dollar_set(document, '{ "newField" : "1", "a.b": {"$concatArrays" : [[7]]}}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "1", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "7" } ] }, "newField" : "1" } { "_id" : "2", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : [ { "$numberInt" : "7" } ] }, "newField" : "1" } { "_id" : "3", "boolean" : false, "b" : "yes", "c" : true, "newField" : "1", "a" : { "b" : [ { "$numberInt" : "7" } ] } } (3 rows) SELECT bson_dollar_set(document, '{ "_id" : false}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : false, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : false, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : false, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_set(document, '{ "_id" : 121}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : { "$numberInt" : "121" }, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : { "$numberInt" : "121" }, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : { "$numberInt" : "121" }, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_set(document, '{ "_id" : 212.2}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "212.19999999999998863" }, "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : { "$numberDouble" : "212.19999999999998863" }, "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : { "$numberDouble" : "212.19999999999998863" }, "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) SELECT bson_dollar_set(document, '{ "_id" : "someString"}') FROM documentdb_api.collection('db', 'setOps'); bson_dollar_set --------------------------------------------------------------------- { "_id" : "someString", "int" : { "$numberInt" : "10" }, "a" : { "b" : [ "x", { "$numberInt" : "1" }, { "$numberDouble" : "2.0" }, true ] } } { "_id" : "someString", "double" : { "$numberDouble" : "2.0" }, "a" : { "b" : { "c" : { "$numberInt" : "3" } } } } { "_id" : "someString", "boolean" : false, "a" : "no", "b" : "yes", "c" : true } (3 rows) bson_aggregation_stage_unwind_tests.out000066400000000000000000000251541507310017400400340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4800000; SET documentdb.next_collection_id TO 4800; SET documentdb.next_collection_index_id TO 4800; -- Test basic usage SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "3" } } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [[1, 2], [2, 3], [4, 5]] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "1", "a" : { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : "1", "a" : { "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- (0 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- (0 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "4" } } } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : { "c" : 1 } } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : [1, 2, 3] }', '$a'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "$numberInt" : "1" } } { "_id" : "1", "a" : { "$numberInt" : "2" } } { "_id" : "1", "a" : { "$numberInt" : "3" } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : [1, {"c":1}, [3,4], "x"] }', '$a'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "$numberInt" : "1" } } { "_id" : "1", "a" : { "c" : { "$numberInt" : "1" } } } { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : "1", "a" : "x" } (4 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [{"a":1}, {"a":2}, {"a":3}] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "a" : { "$numberInt" : "1" } } } } { "_id" : "1", "a" : { "b" : { "a" : { "$numberInt" : "2" } } } } { "_id" : "1", "a" : { "b" : { "a" : { "$numberInt" : "3" } } } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : [1, 2] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "x" : "y", "a" : { "b" : { "$numberInt" : "1" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "1", "x" : "y", "a" : { "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : "1", "x" : "y", "a" : { "b" : { "$numberInt" : "3" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : { "x" : [1, 2] } } }', '$a.c'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "x" : "y", "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : { "x" : [1, 2] } } }', '$a.c.x'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "x" : "y", "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : { "x" : { "$numberInt" : "1" } } } } { "_id" : "1", "x" : "y", "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : { "x" : { "$numberInt" : "2" } } } } (2 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3, null] } }', '$a.b'); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "3" } } } { "_id" : "1", "a" : { "b" : null } } (4 rows) -- Preserve null and empty SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "3" } } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { } } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : null } } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { } } (1 row) -- Project idx field SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":"idx"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } }, "idx" : { "$numberLong" : "0" } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "2" } }, "idx" : { "$numberLong" : "1" } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "3" } }, "idx" : { "$numberLong" : "2" } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":false, "includeArrayIndex":"idx"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- (0 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":false, "includeArrayIndex":"idx"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- (0 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true, "includeArrayIndex":"idx"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { }, "idx" : null } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true, "includeArrayIndex":"idx"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : null }, "idx" : null } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":""}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } }, "" : { "$numberLong" : "0" } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "2" } }, "" : { "$numberLong" : "1" } } { "_id" : "1", "a" : { "b" : { "$numberInt" : "3" } }, "" : { "$numberLong" : "2" } } (3 rows) SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "includeArrayIndex":"","preserveNullAndEmptyArrays":true}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : "1", "a" : { }, "" : null } (1 row) SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "includeArrayIndex":"","preserveNullAndEmptyArrays":false}'::bson); bson_dollar_unwind --------------------------------------------------------------------- (0 rows) -- Project conflicting idx SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":"_id"}'::bson); bson_dollar_unwind --------------------------------------------------------------------- { "_id" : { "$numberLong" : "0" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberLong" : "1" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberLong" : "2" }, "a" : { "b" : { "$numberInt" : "3" } } } (3 rows) -- Test invalid paths SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', 'a.b'); ERROR: $unwind path must be prefixed by $ SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', ''); ERROR: $unwind path should have at least two characters SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', '$'); ERROR: $unwind path should have at least two characters -- Invalid Arguments SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":"a"}'::bson); ERROR: $unwind preserveNullAndEmptyArrays must be a bool value bson_aggregation_string_operators_tests.out000066400000000000000000012760751507310017400407640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 620000; SET documentdb.next_collection_id TO 6200; SET documentdb.next_collection_index_id TO 6200; -- $concat operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : []} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : "apple"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : "â„¹ï¸ â¤ï¸ documentdb"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "â„¹ï¸ â¤ï¸ documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ab" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple ","is ","a ","fruit", " ", "."]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple is a fruit ." } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["ℹï¸","â¤ï¸","documentdb"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ℹï¸â¤ï¸documentdb" } (1 row) -- $concat operator: with literals and operators test: select bson_dollar_project('{"_id":"1", "x": "1"}', '{"result" : { "$concat" : "$x"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1" } (1 row) select bson_dollar_project('{"_id":"1", "x": "3"}', '{"result" : { "$concat" : ["1", {"$concat": ["foo","$x","bar"]}, "2"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1foo3bar2" } (1 row) select bson_dollar_project('{"_id":"1", "product": "mango", "qty": "10"}', '{"result" : { "$concat" : ["$product","-","$qty"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "mango-10" } (1 row) -- $concat operator: null undefined test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : null} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", "a", null, "fruit"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : {"$undefined": true}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [{"$undefined": true}]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", "a", {"$undefined": true} , "fruit"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) --$concat with large input data select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2string1string2" } (1 row) -- $concat operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u0000"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ab\u0000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u000Ac"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ab\nc" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u0022"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ab\"" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u000C"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ab\f" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["Copyright 2023 ","\u00A9 ","Concatstring ", "Inc.", " All rights reserved"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Copyright 2023 © Concatstring Inc. All rights reserved" } (1 row) -- $concat operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : 1} }'); ERROR: Expected 'string' type for $concat but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : true} }'); ERROR: Expected 'string' type for $concat but found 'bool' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : 1.2} }'); ERROR: Expected 'string' type for $concat but found 'double' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [1]} }'); ERROR: Expected 'string' type for $concat but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [{"$numberDecimal": "10"}]} }'); ERROR: Expected 'string' type for $concat but found 'decimal' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", 1, "fruit"]} }'); ERROR: Expected 'string' type for $concat but found 'int' type select bson_dollar_project('{"_id":"1", "x": ["hello ","this ","is ","test"]}', '{"result" : { "$concat" : "$x"} }'); ERROR: Expected 'string' type for $concat but found 'array' type -- $split operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["hello, this is a test case"," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "hello,", "this", "is", "a", "test", "case" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["mango,banana,lemon,grapes",","]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "mango", "banana", "lemon", "grapes" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["Iâ¤ï¸documentdb","â¤ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "I", "documentdb" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["1abcd2abcd3abcd4abcd","abcd"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "1", "2", "3", "4", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["app","apple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "app" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["app","app"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "", "" ] } (1 row) -- $split operaator: delimeter in front and end select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["abcabcabc","abc"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "", "", "", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["testcase "," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "testcase", "", "", "", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [" testcase "," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "", "", "", "testcase", "", "", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["testcase "," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "testcase", "", "", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["test case "," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "test", "", "case", "", "", "" ] } (1 row) -- $split operator: with literals and operators test: select bson_dollar_project('{"_id":"1", "x": "apple is a fruit", "y" : " "}', '{"result" : { "$split" : ["$x","$y"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "apple", "is", "a", "fruit" ] } (1 row) select bson_dollar_project('{"_id":"1", "x": "name,age,address,height,weight", "y" : ","}', '{"result" : { "$split" : ["$x","$y"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "name", "age", "address", "height", "weight" ] } (1 row) select bson_dollar_project('{"_id":"1","a":"ram"}', '{"result" : { "$split" : [{"$concat" : ["apple ","is ", "a " , "fruit "] }," "]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "apple", "is", "a", "fruit", "" ] } (1 row) select bson_dollar_project('{"_id":"1","a":"ram"}', '{"result" : { "$split" : [{"$concat" : ["apple is a fruit"] }, {"$concat" : [" "] }]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "apple", "is", "a", "fruit" ] } (1 row) -- $split operator: null undefined output test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [null,null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true},{"$undefined": true}]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1,null]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true},"app"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "a": "apple is a fruit"}', '{"result" : { "$split" : ["$a","$b"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $split operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a\u0000b\u0000c\u0000d","\u0000"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "a", "b", "c", "d" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["\u000A","\u000A"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "", "" ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022","\u00A9"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ "\"", "\"", "\"", "\"" ] } (1 row) -- $split operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : "apple"} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["apple", ""]} }'); ERROR: $split requires a separator that is not empty select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1, "test"]} }'); ERROR: $split needs its first argument to be an expression that results in a string, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["test", 1]} }'); ERROR: $split needs a second argument that is an expression evaluating to a string, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$numberDecimal" : "1.231"}, 1]} }'); ERROR: $split needs its first argument to be an expression that results in a string, but received: decimal select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : []} }'); ERROR: The expression $split requires exactly 2 arguments, but 0 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : null} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [null]} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a"]} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : {"$undefined": true}} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true}]} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a","b","c"]} }'); ERROR: The expression $split requires exactly 2 arguments, but 3 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1]} }'); ERROR: The expression $split requires exactly 2 arguments, but 1 arguments were actually provided. -- $strLenBytes operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ""} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "A"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "Apple"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "🙈"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "155" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["Apple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "abcdefghijklmnopqrstuvwxyz"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "26" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "1234567890"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "10" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "!@#$%^&*(){}[];:<>?"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "19" } } (1 row) -- $strLenBytes operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["I â¤ï¸ documentdb"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "19" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "I â¤ï¸ documentdb"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "19" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "A\u0000B"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "\uA000BCD"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "6" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "68" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "👩ðŸ½ðŸ‘¨ðŸ½ðŸ§‘ðŸ½ðŸ‘§ðŸ½ðŸ‘¦ðŸ½ðŸ§’ðŸ½ðŸ‘¨ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦°ðŸ§“ðŸ½ðŸ‘´ðŸ½ðŸ‘µðŸ½ðŸ‘¶ðŸ½ðŸ§‘ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦±ðŸ‘¨ðŸ½â€ðŸ¦±ðŸ§‘ðŸ½â€ðŸ¦±ðŸ‘©ðŸ½â€ðŸ¦²ðŸ‘¨ðŸ½â€ðŸ¦²ðŸ§‘ðŸ½â€ðŸ¦²ðŸ‘©ðŸ½â€ðŸ¦³ðŸ‘¨ðŸ½â€ðŸ¦³ðŸ§‘ðŸ½â€ðŸ¦³ðŸ‘±ðŸ½â€â™€ï¸ðŸ‘±ðŸ½â€â™‚ï¸ðŸ‘±ðŸ½ðŸ‘¸ðŸ½ðŸ¤´ðŸ½ðŸ«…ðŸ½ðŸ‘³ðŸ½â€â™€ï¸ðŸ‘³ðŸ½â€â™‚ï¸ðŸ‘³ðŸ½ðŸ‘²ðŸ½ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ‘¼ðŸ½"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "426" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "12" } } (1 row) -- $strLenBytes operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenBytes" : "$a"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "34" } } (1 row) select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenBytes" : {"$concat" : ["$a", "Apple is a fruit"]} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "50" } } (1 row) -- $strLenBytes operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : 1} }'); ERROR: Expected 'string' type for $strLenBytes but found 'int' type select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$strLenBytes" : "$a"} }'); ERROR: Expected 'string' type for $strLenBytes but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [1]} }'); ERROR: Expected 'string' type for $strLenBytes but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["apple","cat"]} }'); ERROR: The expression $strLenBytes requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [1,"cat"]} }'); ERROR: The expression $strLenBytes requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["cat",1]} }'); ERROR: The expression $strLenBytes requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : null} }'); ERROR: Expected 'string' type for $strLenBytes but found 'null' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [null]} }'); ERROR: Expected 'string' type for $strLenBytes but found 'null' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : {"$undefined": true}} }'); ERROR: Expected 'string' type for $strLenBytes but found 'undefined' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [{"$undefined": true}]} }'); ERROR: Expected 'string' type for $strLenBytes but found 'undefined' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["$a"]} }'); ERROR: Expected 'string' type for $strLenBytes but found 'missing' type -- $strLenCP operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ""} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "A"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "Apple"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "🙈"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "131" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["Apple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "abcdefghijklmnopqrstuvwxyz"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "26" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "1234567890"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "10" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "!@#$%^&*(){}[];:<>?"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "19" } } (1 row) -- $strLenCP operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["I â¤ï¸ documentdb"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "15" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "I â¤ï¸ documentdb"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "15" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "A\u0000B"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "\uA000BCD"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "17" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "👩ðŸ½ðŸ‘¨ðŸ½ðŸ§‘ðŸ½ðŸ‘§ðŸ½ðŸ‘¦ðŸ½ðŸ§’ðŸ½ðŸ‘¨ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦°ðŸ§“ðŸ½ðŸ‘´ðŸ½ðŸ‘µðŸ½ðŸ‘¶ðŸ½ðŸ§‘ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦±ðŸ‘¨ðŸ½â€ðŸ¦±ðŸ§‘ðŸ½â€ðŸ¦±ðŸ‘©ðŸ½â€ðŸ¦²ðŸ‘¨ðŸ½â€ðŸ¦²ðŸ§‘ðŸ½â€ðŸ¦²ðŸ‘©ðŸ½â€ðŸ¦³ðŸ‘¨ðŸ½â€ðŸ¦³ðŸ§‘ðŸ½â€ðŸ¦³ðŸ‘±ðŸ½â€â™€ï¸ðŸ‘±ðŸ½â€â™‚ï¸ðŸ‘±ðŸ½ðŸ‘¸ðŸ½ðŸ¤´ðŸ½ðŸ«…ðŸ½ðŸ‘³ðŸ½â€â™€ï¸ðŸ‘³ðŸ½â€â™‚ï¸ðŸ‘³ðŸ½ðŸ‘²ðŸ½ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ‘¼ðŸ½"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "114" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "8" } } (1 row) -- $strLenCP operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenCP" : "$a"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "34" } } (1 row) select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenCP" : {"$concat" : ["$a", "Apple is a fruit"]} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "50" } } (1 row) -- $strLenCP operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : 1} }'); ERROR: $strLenCP needs a string input, but received: int select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$strLenCP" : "$a"} }'); ERROR: $strLenCP needs a string input, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [1]} }'); ERROR: $strLenCP needs a string input, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["apple","cat"]} }'); ERROR: The expression $strLenCP requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [1,"cat"]} }'); ERROR: The expression $strLenCP requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["cat",1]} }'); ERROR: The expression $strLenCP requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : null} }'); ERROR: $strLenCP needs a string input, but received: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [null]} }'); ERROR: $strLenCP needs a string input, but received: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : {"$undefined": true}} }'); ERROR: $strLenCP needs a string input, but received: undefined select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [{"$undefined": true}]} }'); ERROR: $strLenCP needs a string input, but received: undefined select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["$a"]} }'); ERROR: $strLenCP needs a string input, but received: missing --$trim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "", "chars" :""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "111apple111", "chars" :"1"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "123apple321", "chars" :"333333222222111111"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple ", "chars" :"pl"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple ", "chars" :" ppl"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple ", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple ", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "ABCDOGABC", "chars" :"ABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "DOG" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA Remove this too", "chars" :"Removthiscarto "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "AAAAAAAAAAAAAAAAAA" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) --$trim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": ""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "ABCDOGABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDOGABC" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\napple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0000 \n apple \t \u200A "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "âapple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "âappleâ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0080\u00E2apple\u0080"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\u0080âapple\u0080" } (1 row) --$trim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I 💗 documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😎😎😋😎😎" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\napple", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0080âapple" } (1 row) -- $trim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "this is test" } (1 row) select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0this is test0" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "string" } (1 row) -- $trim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$z","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a","chars": "$z"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": null, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :null}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $trim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : 1} }'); ERROR: Expected 'document' type but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {}} }'); ERROR: $trim needs to have an 'input' field select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": 1}} }'); ERROR: Expected 'string' type for $trim but value 1 has 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": 1, "unknowarG": "1"}} }'); ERROR: $trim encountered an unrecognized input argument: unknowarG select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "", "chars" : ["apple"]}} }'); ERROR: $trim requires that 'chars' be a string, but instead received [ "apple" ] which is of type array. select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$trim" : {"input": "$a"}} }'); ERROR: Expected 'string' type for $trim but value 1 has 'int' type select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$trim" : {"input": "apple", "chars" : "$a"}} }'); ERROR: $trim requires that 'chars' be a string, but instead received 1 which is of type int. --$ltrim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "", "chars" :""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "111apple", "chars" :"1"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "123apple", "chars" :"333333222222111111"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple ", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "ABCDOG", "chars" :"ABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "DOG" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA", "chars" :"Removthiscarto "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "AAAAAAAAAAAAAAAAAA" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "1234apple", "chars" :"12345678"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple5678" } (1 row) --$ltrim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": ""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "ABCDOGABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDOGABC" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\napple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0000 \n apple \t \u200A "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple \t   " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "âapple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "âappleâ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0080\u00E2apple\u0080"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\u0080âapple\u0080" } (1 row) --$ltrim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I 💗 documentdb \n" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😎😎😋😎😎ðŸ˜ðŸ˜" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\napple", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple \t   " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "appleâ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0080âapple\u0080" } (1 row) -- $ltrim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "this is test 0" } (1 row) select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0this is test0 " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "string123" } (1 row) -- $ltrim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$z","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a","chars": "$z"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": null, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :null}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $ltrim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : 1} }'); ERROR: Expected 'document' type but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {}} }'); ERROR: $ltrim needs to have an 'input' field select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": 1}} }'); ERROR: Expected 'string' type for $ltrim but value 1 has 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": 1, "unknowarG": "1"}} }'); ERROR: $ltrim encountered an unrecognized input argument: unknowarG select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "", "chars" : ["apple"]}} }'); ERROR: $ltrim requires that 'chars' be a string, but instead received [ "apple" ] which is of type array. select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$ltrim" : {"input": "$a"}} }'); ERROR: Expected 'string' type for $ltrim but value 1 has 'int' type select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$ltrim" : {"input": "apple", "chars" : "$a"}} }'); ERROR: $ltrim requires that 'chars' be a string, but instead received 1 which is of type int. --$rtrim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "", "chars" :""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple111", "chars" :"1"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple321", "chars" :"333333222222111111"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :"pl"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :" ppl"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :" "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "DOGABC", "chars" :"ABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "DOG" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA Remove this too", "chars" :"Removthiscarto "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Remove this characters AAAAAAAAAAAAAAAAAA" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234apple" } (1 row) --$rtrim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": ""}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "DOGABC"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "DOGABC" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\napple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\napple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0000 \n apple \t \u200A "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0000 \n apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " âapple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " âappleâ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0080\u00E2apple\u0080"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0080âapple\u0080" } (1 row) --$rtrim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\n I 💗 documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😀😀😎😎😋😎😎" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\napple", "chars" :"\n "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\napple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0000 \n apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " âapple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " âapple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " \u0080âapple" } (1 row) -- $rtrim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0 this is test" } (1 row) select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " 0this is test0" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "123string" } (1 row) -- $rtrim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$z","chars": "$b"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a","chars": "$z"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": null, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :null}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $rtrim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : 1} }'); ERROR: Expected 'document' type but found 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {}} }'); ERROR: $rtrim needs to have an 'input' field select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": 1}} }'); ERROR: Expected 'string' type for $rtrim but value 1 has 'int' type select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": 1, "unknowarG": "1"}} }'); ERROR: $rtrim encountered an unrecognized input argument: unknowarG select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "", "chars" : ["apple"]}} }'); ERROR: $rtrim requires that 'chars' be a string, but instead received [ "apple" ] which is of type array. select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$rtrim" : {"input": "$a"}} }'); ERROR: Expected 'string' type for $rtrim but value 1 has 'int' type select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$rtrim" : {"input": "apple", "chars" : "$a"}} }'); ERROR: $rtrim requires that 'chars' be a string, but instead received 1 which is of type int. --$indexOfBytes operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["",""]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["apple","ple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",0,10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",10,0]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","xyz"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["","",1,3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4,5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4,6]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",2147483647,7]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,2147483647]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) --$indexOfBytes operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\n\u200A"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",4,7]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",7]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "8" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["I â¤ï¸ documentdb ","â¤ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "12" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "12" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2,4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",3,4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜ŸðŸ˜´ðŸ¥²ðŸ˜€ðŸ˜‹ðŸ˜ŽðŸ™ˆðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ˜²ðŸ˜â¤ï¸ðŸ•·ï¸ðŸ™ˆðŸ’”👳ðŸ½â€â™‚ï¸","😎🙈🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "24" } } (1 row) -- $indexOfBytes operator: literals and operators : select bson_dollar_project('{"_id":"1","a":"1234567", "b":"456","c":2, "d":9 }', '{"result" : { "$indexOfBytes" : ["$a","$b","$c","$d"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [{"$concat" : ["a","p","p","l","e"]},{"$concat" : ["p","l"]},{"$add": [0,1]},{"$add" :[3,2]}]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) -- $indexOfBytes operator: null test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [null,"a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [{"$undefined": true},"a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["$x","y"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $indexOfBytes operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : 1} }'); ERROR: The expression $indexOfBytes requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : []} }'); ERROR: The expression $indexOfBytes requires no fewer than 2 arguments and no more than 4 arguments, but 0 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a"]} }'); ERROR: The expression $indexOfBytes requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [1]} }'); ERROR: The expression $indexOfBytes requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a",1]} }'); ERROR: $indexOfBytes expects its second argument to be a string, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a",null]} }'); ERROR: $indexOfBytes expects its second argument to be a string, but received: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","$x"]} }'); ERROR: $indexOfBytes expects its second argument to be a string, but received: missing select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",-1]} }'); ERROR: $indexOfBytes needs a nonnegative starting index, but received: -1 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b","x"]} }'); ERROR: An integral starting index is required for $indexOfBytes, but the provided value has type: string with actual value: "x" select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,-3]} }'); ERROR: $indexOfBytes requires the ending index to be nonnegative, but received: -3 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,"z"]} }'); ERROR: $indexOfBytes needs an integral ending index but received a value of type string with the value "z" select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,"$t"]} }'); ERROR: $indexOfBytes needs an integral ending index but received a value of type missing with the value MISSING select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",2147483648,7]} }'); ERROR: $indexOfBytes needs a nonnegative starting index, but received: -2147483648 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,2147483648]} }'); ERROR: $indexOfBytes requires the ending index to be nonnegative, but received: -2147483648 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1.2]} }'); ERROR: An integral starting index is required for $indexOfBytes, but the provided value has type: double with actual value: 1.2 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,1.3]} }'); ERROR: $indexOfBytes needs an integral ending index but received a value of type double with the value 1.3 --$indexOfCP operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["",""]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["apple","ple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",0,10]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",10,0]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","xyz"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "5" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["","",2,3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4,5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4,6]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",2147483647,7]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,2147483647]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) --$indexOfCP operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["\u0000\u00E2\t\n\u200A\u0080","\n\u200A"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",7]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["I â¤ï¸ documentdb ","â¤ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2,4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",3,4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜ŸðŸ˜´ðŸ¥²ðŸ˜€ðŸ˜‹ðŸ˜ŽðŸ™ˆðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ˜²ðŸ˜â¤ï¸ðŸ•·ï¸ðŸ™ˆðŸ’”👳ðŸ½â€â™‚ï¸","😎🙈🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "6" } } (1 row) -- $indexOfCP operator: literals and operators : select bson_dollar_project('{"_id":"1","a":"1234567", "b":"456","c":2, "d":9 }', '{"result" : { "$indexOfCP" : ["$a","$b","$c","$d"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "3" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [{"$concat" : ["a","p","p","l","e"]},{"$concat" : ["p","l"]},{"$add": [0,1]},{"$add" :[3,2]}]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "2" } } (1 row) -- $indexOfCP operator: null test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [null,"a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [{"$undefined": true},"a"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["$x","y"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $indexOfCP operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : 1} }'); ERROR: The expression $indexOfCP requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : []} }'); ERROR: The expression $indexOfCP requires no fewer than 2 arguments and no more than 4 arguments, but 0 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a"]} }'); ERROR: The expression $indexOfCP requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [1]} }'); ERROR: The expression $indexOfCP requires no fewer than 2 arguments and no more than 4 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a",1]} }'); ERROR: $indexOfCP expects its second argument to be a string, but received: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a",null]} }'); ERROR: $indexOfCP expects its second argument to be a string, but received: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","$x"]} }'); ERROR: $indexOfCP expects its second argument to be a string, but received: missing select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",-1]} }'); ERROR: $indexOfCP needs a nonnegative starting index, but received: -1 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b","x"]} }'); ERROR: An integral starting index is required for $indexOfCP, but the provided value has type: string with actual value: "x" select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,-3]} }'); ERROR: $indexOfCP requires the ending index to be nonnegative, but received: -3 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,"z"]} }'); ERROR: $indexOfCP needs an integral ending index but received a value of type string with the value "z" select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,"$t"]} }'); ERROR: $indexOfCP needs an integral ending index but received a value of type missing with the value MISSING select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",2147483648,7]} }'); ERROR: $indexOfCP needs a nonnegative starting index, but received: -2147483648 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,2147483648]} }'); ERROR: $indexOfCP requires the ending index to be nonnegative, but received: -2147483648 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1.2]} }'); ERROR: An integral starting index is required for $indexOfCP, but the provided value has type: double with actual value: 1.2 select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,1.3]} }'); ERROR: $indexOfCP needs an integral ending index but received a value of type double with the value 1.3 -- $toUpper operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ""} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : null} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "A"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "A" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "Apple"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "APPLE" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "🙈"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "🙈" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I USE TO EAT ONE APPLE 🎠A DAY THAT BECAME REASON OF MY BREAKUP 💔 AS ONE APPLE A DAY KEEPS DOCTOR AWAY AND SHE👧🽠WAS A DOCTOR 🧑ðŸ½â€âš•ï¸" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["Apple"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "APPLE" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "abcdefghijklmnopqrstuvwxyz"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "1234567890"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234567890" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "!@#$%^&*(){}[];:<>?"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "!@#$%^&*(){}[];:<>?" } (1 row) -- $toUpper operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["I â¤ï¸ documentdb"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I â¤ï¸ DOCUMENTDB" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "I â¤ï¸ documentdb"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I â¤ï¸ DOCUMENTDB" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "A\u0000B"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "A\u0000B" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "a\u0000B\u000d"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "A\u0000B\r" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "\uA000Bcd"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ꀀBCD" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "a\u0000B\u0000\u0000z"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "A\u0000B\u0000\u0000Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\"©\"©\"©\"©" } (1 row) -- $toUpper operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : 55.5} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "55.5" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : 1234567899877345} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234567899877345" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberInt": "3456"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberLong": "3456213324342"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberDecimal": "3456213324342.324789234567934"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342.324789234567934" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberDecimal": "1e10"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1E+10" } (1 row) -- $toUpper operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "0" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:00:00.000Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "86401" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:01:26.401Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "-33563519937977" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0906-06-01T08:01:02.023Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$timestamp": { "t" : 1671991326 , "i": 0}} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "DEC 25 18:02:06:000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$timestamp": { "t" : 0 , "i": 0}} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "JAN 01 00:00:00:000" } (1 row) -- $toUpper operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$toUpper": "abcde" } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDE" } (1 row) select bson_dollar_project('{"_id":"2", "test": "this is a test"}', '{"result" : { "$toUpper" : "$test" } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "THIS IS A TEST" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toUpper" : {"$concat":["a","b","c","1"]} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "ABC1" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toUpper" : "$test" } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "" } (1 row) -- $toUpper operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["a","b"] } }'); ERROR: The expression $toUpper requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : [1,"b"] } }'); ERROR: The expression $toUpper requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : true } }'); ERROR: Unable to convert from BSON type bool into a String value -- $toLower operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ""} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : null} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "A"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "Apple"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "🙈"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "🙈" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "I USE To Eat One aPple 🎠a dAy That Became rEasOn of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["aPPLE"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "apple" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "abcLHKSFHdefghijklmnopqrstuvwxyz"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "abclhksfhdefghijklmnopqrstuvwxyz" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "1234567890"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234567890" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "!@#$%^&*(){}[];:<>?"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "!@#$%^&*(){}[];:<>?" } (1 row) -- $toLower operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["I â¤ï¸ documentdb"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i â¤ï¸ documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "I â¤ï¸ documentdb"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i â¤ï¸ documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "A\u0000B"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000b" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "a\u0000B\u000d"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000b\r" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "\uA000Bcd"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ꀀbcd" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "a\u0000B\u0000\u0000z"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000b\u0000\u0000z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\"©\"©\"©\"©" } (1 row) -- $toLower operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : 55.5} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "55.5" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : 1234567899877345} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234567899877345" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberInt": "3456"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberLong": "3456213324342"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberDecimal": "3456213324342.324789234567934"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342.324789234567934" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberDecimal": "1e10"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1e+10" } (1 row) -- $toLower operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "0" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01t00:00:00.000z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "86400" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01t00:01:26.400z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "-33563519937977" }} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0906-06-01t08:01:02.023z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$timestamp": { "t" : 1671991326 , "i": 0}} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "dec 25 18:02:06:000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$timestamp": { "t" : 0 , "i": 0}} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "jan 01 00:00:00:000" } (1 row) -- $toLower operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$toUpper": "abcde" } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "abcde" } (1 row) select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$toLower" : "$test" } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "this is a test" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toLower" : {"$concat":["A","B","C","1"]} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "abc1" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toLower" : "$test" } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "" } (1 row) -- $toLower operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["a","b"] } }'); ERROR: The expression $toLower requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : [1,"b"] } }'); ERROR: The expression $toLower requires exactly 1 arguments, but 2 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : true } }'); ERROR: Unable to convert from BSON type bool into a String value -- $strcasecmp operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "\u0080D\u20ac", "\u0080d\u20ac"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "\u0080D\u20ac\u000D", "\u0080d\u20ac\u000d"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "I â¤ï¸ documentdb", "I â¤ï¸ documentdb" ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟" ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) -- $strcasecmp operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["1.2345",1.2345] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["1.234512345566666234324",1.234512345566666234324] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [1.234512345566666234324, "1.234512345566666234324"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.234512345566666234324"}, "1.234512345566666234324"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.2e10"}, "1e10"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.2e10"}, "1e10"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "-1" } } (1 row) -- $strcasecmp operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "1970-01-01T00:00:00.000Z", {"$date": { "$numberLong" : "0" }} ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "1970-01-01T00:00:00.000Z", {"$date": { "$numberLong" : "0" }} ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "0906-06-01T08:01:02.023Z", {"$date": { "$numberLong" : "-33563519937977" }} ] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "$numberInt" : "0" } } (1 row) -- select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "DEC 25 18:02:06:000", {"$timestamp": { "t" : 1671991326 , "i": 0}} ] } }'); -- $strcasecmp operator: expressions: select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$strcasecmp" : ["$test", "this is a test"] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : { "$numberInt" : "0" } } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$strcasecmp" : ["$test", ""] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : { "$numberInt" : "0" } } (1 row) -- $strcasecmp operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "0906-06-01T08:01:02.023Z", true ] } }'); ERROR: Unable to convert from BSON type bool into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ ""] } }'); ERROR: The expression $strCaseCmp requires exactly 2 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["", ["a"]] } }'); ERROR: Unable to convert from BSON type array into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$binary": {"base64": "ww==", "subType": "01"}},"a"] } }'); ERROR: Unable to convert from BSON type binData into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["", {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); ERROR: Unable to convert from BSON type regex into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "" , "a2", 123] } }'); ERROR: The expression $strCaseCmp requires exactly 2 arguments, but 3 arguments were actually provided. -- $substr operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 0 , 0]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 0 , 5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hello" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2 , 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ll" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2 , -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) -- $substr operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [55.5, 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "55.5" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [1234567899877345, 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1234567899877345" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberInt": "3456"}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberLong": "3456213324342"}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberDecimal": "3456213324342.324789234567934"}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342.324789234567934" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberDecimal": "1e10"}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1E+10" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberLong": "2342342"}, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "This isa test" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberLong": "2"}, 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "s " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 2.9, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "is isa test" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 1, 4.2] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "his " } (1 row) -- $substr operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "0" }}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:00:00.000Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "86400" }}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:01:26.400Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "-33563519937977" }}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0906-06-01T08:01:02.023Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Dec 25 18:02:06:000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Jan 01 00:00:00:000" } (1 row) -- $substr operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["I â¤ï¸ documentdb", 1, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " â¤ï¸ documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["A\u0000B", 1, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\u0000B" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["a\u0000B\u000d", 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000B\r" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "B\u0000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 16]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😋😎🥲🙈" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\"©\"©\"©\"©" } (1 row) -- $substr operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$toUpper": "abcde" }, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDE" } (1 row) select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substr" : ["$test", 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "THIS IS a test" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substr" : [{"$concat":["A","B","C","1"]}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "ABC1" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substr" : ["$test", 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "" } (1 row) -- $substr negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", -1, 1]}}'); ERROR: $substrBytes: starting index cannot be negative (received: -1) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [[1, 2], 1, 1]}}'); ERROR: Unable to convert from BSON type array into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"a" : "b"}, -1, 1]}}'); ERROR: Unable to convert from BSON type object into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); ERROR: Unable to convert from BSON type objectId into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [NaN, -1, 1]}}'); ERROR: $substrBytes: starting index cannot be negative (received: -1) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["I â¤ï¸ documentdb", 2, 4]} }'); ERROR: $substrBytes: Invalid range, ending index falls within a UTF-8 character boundary. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["\uA000Bcd", 1, 2]} }'); ERROR: $substrBytes: Invalid range detected, as the starting index is a UTF-8 continuation byte. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); ERROR: Unable to convert from BSON type binData into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); ERROR: Unable to convert from BSON type regex into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", null, -1] } }'); ERROR: The starting index for $substrBytes must be of a numeric data type, but the current BSON type is null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 1, null] } }'); ERROR: $substrBytes: the length must be a numeric value (currently BSON type null) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : {"a" : "b"} } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : null } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substr" : "$a.b" } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. -- $substrBytes operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 0 , 0]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 0 , 5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hello" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2 , 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ll" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2 , -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) -- $substrBytes operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [55.5, 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "55.5" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [1234567899877345, 3, 6]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "456789" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberInt": "3456"}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberLong": "3456213324342"}, 6, 15] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3324342" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberDecimal": "3456213324342.324789234567934"}, 13, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : ".3247" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberDecimal": "1e10"}, 2, 2] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "+1" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberLong": "2342342"}, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "This isa test" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberLong": "2"}, 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "s " } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 2.9, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "is isa test" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 1, 4.2] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "his " } (1 row) -- $substrBytes operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "0" }}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:00:00.000Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "86400" }}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:01:26.400Z" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "-33563519937977" }}, 5, 8] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "06-01T08" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 4, 12] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "25 18:02:06:" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Jan 01 00:00:00:000" } (1 row) -- $substrBytes operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["I â¤ï¸ documentdb", 1, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " â¤ï¸ documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["A\u0000B", 1, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\u0000B" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["a\u0000B\u000d", 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000B\r" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "B\u0000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 16]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "😋😎🥲🙈" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 0, -1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\"©\"©\"©\"©" } (1 row) -- $substrBytes operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$toUpper": "abcde" }, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDE" } (1 row) select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substrBytes" : ["$test", 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "THIS IS a test" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrBytes" : [{"$concat":["A","B","C","1"]}, 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "ABC1" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrBytes" : ["$test", 0, -1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "" } (1 row) -- $substrBytes negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", -1, 1]}}'); ERROR: $substrBytes: starting index cannot be negative (received: -1) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [[1, 2], 1, 1]}}'); ERROR: Unable to convert from BSON type array into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"a" : "b"}, -1, 1]}}'); ERROR: Unable to convert from BSON type object into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); ERROR: Unable to convert from BSON type objectId into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [NaN, -1, 1]}}'); ERROR: $substrBytes: starting index cannot be negative (received: -1) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["I â¤ï¸ documentdb", 2, 4]} }'); ERROR: $substrBytes: Invalid range, ending index falls within a UTF-8 character boundary. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["\uA000Bcd", 1, 2]} }'); ERROR: $substrBytes: Invalid range detected, as the starting index is a UTF-8 continuation byte. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); ERROR: Unable to convert from BSON type binData into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); ERROR: Unable to convert from BSON type regex into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", null, -1] } }'); ERROR: The starting index for $substrBytes must be of a numeric data type, but the current BSON type is null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 1, null] } }'); ERROR: $substrBytes: the length must be a numeric value (currently BSON type null) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : {"a" : "b"} } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : null } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substrBytes" : "$a.b" } }'); ERROR: The expression $substrBytes requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [null, 1, null] } }'); ERROR: $substrBytes: the length must be a numeric value (currently BSON type null) -- $substrCP operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 0 , 0]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 0 , 5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hello" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2 , 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ll" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2 , 51]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "llo" } (1 row) -- $substrCP operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [55.5, 0, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "55." } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [1234567899877345, 0, 9]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "123456789" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberInt": "3456"}, 0, 4] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberLong": "3456213324342"}, 0, 10] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberDecimal": "3456213324342.324789234567934"}, 0, 25] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "3456213324342.32478923456" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberDecimal": "1e10"}, 0, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1E+10" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberLong": "2342342"}, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "This isa test" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberLong": "2"}, 1] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "i" } (1 row) -- $substrCP operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "0" }}, 0, 20] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:00:00." } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "86400" }}, 0, 20] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "1970-01-01T00:01:26." } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "-33563519937977" }}, 0, 20] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "0906-06-01T08:01:02." } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 0, 20] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Dec 25 18:02:06:000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, 20] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Jan 01 00:00:00:000" } (1 row) -- $substrCP operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["jalapeño", 4, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "peñ" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["jalapeño", 6, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ño" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "cafétéria", 5, 4]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "éria" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "cafétéria", 7, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ia" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "寿å¸sushi", 0, 3]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "寿å¸s" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["I â¤ï¸ documentdb", 2, 1]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "â¤" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["I â¤ï¸ documentdb", 1, 5]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : " â¤ï¸ d" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["A\u0000B", 1, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "\u0000B" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["a\u0000B\u000d", 0, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["\uA000Bcd", 1, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "Bc" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$susbtrCP" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); ERROR: Unrecognized expression format: $susbtrCP select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 13]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2]} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "©\"" } (1 row) -- $substrCP operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$toUpper": "abcde" }, 0, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "ABCDE" } (1 row) select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substrCP" : ["$test", 0, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "THIS " } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrCP" : [{"$concat":["A","B","C","1"]}, 0, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "ABC1" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrCP" : ["$test", 0, 5] } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : "" } (1 row) select bson_dollar_project('{"_id":"2"}', '{"output":{"$substrCP" : ["∫aÆ’",0,{"$subtract" : [{"$strLenCP" : "∫aÆ’"},0]}]}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "output" : "∫aÆ’" } (1 row) -- $substrCP negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", -1, 1]}}'); ERROR: The starting index value for $substrCP must be a nonnegative integer. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [[1, 2], 1, 1]}}'); ERROR: Unable to convert from BSON type array into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"a" : "b"}, -1, 1]}}'); ERROR: Unable to convert from BSON type object into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); ERROR: Unable to convert from BSON type objectId into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [NaN, -1, 1]}}'); ERROR: The starting index value for $substrCP must be a nonnegative integer. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); ERROR: Unable to convert from BSON type binData into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); ERROR: Unable to convert from BSON type regex into a String value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", null, -1] } }'); ERROR: $substrCP: starting index must be provided as a numeric value, but it is currently of BSON type null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, null] } }'); ERROR: $substrCP: length value must be numeric type (currently BSON type null) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : {"a" : "b"} } }'); ERROR: The expression $substrCP requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : null } }'); ERROR: The expression $substrCP requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substrCP" : "$a.b" } }'); ERROR: The expression $substrCP requires exactly 3 arguments, but 1 arguments were actually provided. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [null, 1, null] } }'); ERROR: $substrCP: length value must be numeric type (currently BSON type null) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1.1, 1] } }'); ERROR: $substrCP: starting index is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, 1.1] } }'); ERROR: $substrCP: length value is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", -1, 1] } }'); ERROR: The starting index value for $substrCP must be a nonnegative integer. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, -1] } }'); ERROR: $substrCP: length needs to be a valid non-negative integer. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, NaN] } }'); ERROR: $substrCP: length value is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", NaN, 1] } }'); ERROR: $substrCP: starting index is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); ERROR: $substrCP: starting index is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); ERROR: $substrCP: length value is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 2.9, -1] } }'); ERROR: $substrCP: starting index is not representable as a valid 32-bit integer value select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 1, 4.2] } }'); ERROR: $substrCP: length value is not representable as a valid 32-bit integer value -- $regexMatch operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"", "regex" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"a", "regex" : "a" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"a", "regex" : "b" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"v_core", "regex" : "Ru-Based" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple is a fruit", "regex" : "is" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : false } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexMatch" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : true } (1 row) -- $regexMatch operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexMatch" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : true } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexMatch" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : true } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexMatch" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : true } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexMatch" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : true } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : true } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexMatch" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : true } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexMatch" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : true } (1 row) -- $regexMatch operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexMatch" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : true } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexMatch" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : true } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexMatch" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : true } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexMatch" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : true } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : true } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexMatch" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : true } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexMatch" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : true } (1 row) -- $regexMatch operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexMatch" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "10", "result" : true } (1 row) select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexMatch" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "11", "result" : true } (1 row) select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexMatch" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "12", "result" : true } (1 row) select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexMatch" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "13", "result" : true } (1 row) select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "14", "result" : true } (1 row) -- $regexMatch operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexMatch" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "15", "result" : true } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : true } (1 row) select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexMatch" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "17", "result" : true } (1 row) select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexMatch" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "18", "result" : true } (1 row) select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexMatch" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "20", "result" : true } (1 row) -- $regexMatch operator: false cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"a","regex" : null }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"a","regex" : "$z" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"apple","regex" : "boy" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : false } (1 row) select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexMatch" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "19", "result" : false } (1 row) -- $regexMatch operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexMatch" : {"input":"$a", "regex" : "$b" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexMatch" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } (1 row) -- $regexMatch operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"", "regex" : "", "extra" : "" }} }'); ERROR: $regexMatch encountered an unrecognized input argument: extra select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : { "regex" : ""}} }'); ERROR: $regexMatch needs the 'input' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : { "input" : ""}} }'); ERROR: $regexMatch needs the 'regex' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": 1, "regex" : "", "options" : "" }} }'); ERROR: The $regexMatch requires that the 'input' parameter must be of type string. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : 1, "options" : "" }} }'); ERROR: $regexMatch requires that 'regex' must be provided as either a string or a regular expression select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : "a", "options" : 1 }} }'); ERROR: $regexMatch requires that 'options' must be provided as a string select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); ERROR: $regexMatch detected that regex options have been defined in both the 'regex' and 'option' fields select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : "a", "options" : "g" }} }'); ERROR: $regexMatch Invalid flag detected in regex options: g select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : null} }'); ERROR: $regexMatch requires an object containing named arguments, but encountered: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : 1} }'); ERROR: $regexMatch requires an object containing named arguments, but encountered: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); ERROR: $regexMatch: Regular expression options must not include an embedded null byte select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); ERROR: $regexMatch: regular expression cannot include an embedded null character select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"(m(p)"} } }'); ERROR: Invalid Regex in $regexMatch: missing closing parenthesis -- $regexFind operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"", "regex" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"a", "regex" : "a" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "a", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple is a fruit", "regex" : "is" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "is", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "fruit", "idx" : { "$numberInt" : "11" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexFind" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : { "match" : "Banana", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) -- $regexFind operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFind" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFind" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : { "match" : "World", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFind" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : { "match" : "ID", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFind" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : { "match" : ",", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFind" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : { "match" : "john@example.com", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFind" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : { "match" : "

Paragraph 1

", "idx" : { "$numberInt" : "14" }, "captures" : [ "Paragraph 1" ] } } (1 row) -- $regexFind operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFind" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFind" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : { "match" : "World", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFind" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : { "match" : "ID", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFind" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : { "match" : ",", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFind" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : { "match" : "john@example.com", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFind" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : { "match" : "

Paragraph 1

", "idx" : { "$numberInt" : "14" }, "captures" : [ "Paragraph 1" ] } } (1 row) -- $regexFind operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexFind" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "10", "result" : { "match" : "John Doe, 25 years old", "idx" : { "$numberInt" : "0" }, "captures" : [ "John", "Doe", "25" ] } } (1 row) select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexFind" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "11", "result" : { "match" : "Date: 2023-07-14", "idx" : { "$numberInt" : "0" }, "captures" : [ "2023-07-14" ] } } (1 row) select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexFind" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "12", "result" : { "match" : "Product: Apple iPhone 12", "idx" : { "$numberInt" : "0" }, "captures" : [ "Apple", "iPhone", "12" ] } } (1 row) select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexFind" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "13", "result" : { "match" : "Email: john@example.com", "idx" : { "$numberInt" : "0" }, "captures" : [ "john@example.com" ] } } (1 row) select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "14", "result" : { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ "Lorem" ] } } (1 row) -- $regexFind operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexFind" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "15", "result" : { "match" : "world", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : { "match" : "FOX", "idx" : { "$numberInt" : "16" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexFind" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "17", "result" : { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexFind" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "18", "result" : { "match" : "long text", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexFind" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "20", "result" : { "match" : "Hello there", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) -- $regexFind operator: null cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"a","regex" : null }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"a","regex" : "$z" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"apple","regex" : "boy" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : null } (1 row) select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexFind" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "19", "result" : null } (1 row) -- $regexFind operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexFind" : {"input":"$a", "regex" : "$b" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "app", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexFind" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "APP", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } (1 row) -- $regexFind operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"", "regex" : "", "extra" : "" }} }'); ERROR: $regexFind encountered an unrecognized input argument: extra select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : { "regex" : ""}} }'); ERROR: $regexFind needs the 'input' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : { "input" : ""}} }'); ERROR: $regexFind needs the 'regex' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": 1, "regex" : "", "options" : "" }} }'); ERROR: The $regexFind requires that the 'input' parameter must be of type string. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : 1, "options" : "" }} }'); ERROR: $regexFind requires that 'regex' must be provided as either a string or a regular expression select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : "a", "options" : 1 }} }'); ERROR: $regexFind requires that 'options' must be provided as a string select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); ERROR: $regexFind detected that regex options have been defined in both the 'regex' and 'option' fields select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : "a", "options" : "g" }} }'); ERROR: $regexFind Invalid flag detected in regex options: g select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : null} }'); ERROR: $regexFind requires an object containing named arguments, but encountered: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : 1} }'); ERROR: $regexFind requires an object containing named arguments, but encountered: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); ERROR: $regexFind: Regular expression options must not include an embedded null byte select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); ERROR: $regexFind: regular expression cannot include an embedded null character select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"(m(p)"} } }'); ERROR: Invalid Regex in $regexFind: missing closing parenthesis -- $regexFindAll operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"", "regex" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"a", "regex" : "a" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "a", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple is a fruit", "regex" : "is" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "is", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "fruit", "idx" : { "$numberInt" : "11" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE", "regex" : "apple" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexFindAll" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "2", "result" : [ { "match" : "Banana", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) -- $regexFindAll operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFindAll" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : [ { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] }, { "match" : "456", "idx" : { "$numberInt" : "3" }, "captures" : [ ] }, { "match" : "789", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFindAll" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : [ { "match" : "World", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFindAll" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : [ { "match" : "ID", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFindAll" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : [ { "match" : ",", "idx" : { "$numberInt" : "5" }, "captures" : [ ] }, { "match" : "!", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : [ { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ ] }, { "match" : "ipsum", "idx" : { "$numberInt" : "6" }, "captures" : [ ] }, { "match" : "dolor", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFindAll" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : [ { "match" : "john@example.com", "idx" : { "$numberInt" : "12" }, "captures" : [ ] }, { "match" : "555-123-4567", "idx" : { "$numberInt" : "37" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFindAll" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : [ { "match" : "

Paragraph 1

", "idx" : { "$numberInt" : "14" }, "captures" : [ "Paragraph 1" ] }, { "match" : "

Paragraph 2

", "idx" : { "$numberInt" : "32" }, "captures" : [ "Paragraph 2" ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 100, 'a') || '", "regex": "((((((((((((((()))))))))))))))"}} }')::bson); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "", "idx" : { "$numberInt" : "0" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "1" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "2" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "3" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "4" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "5" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "6" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "7" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "8" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "9" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "10" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "11" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "12" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "13" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "14" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "15" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "16" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "17" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "18" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "19" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "20" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "21" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "22" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "23" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "24" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "25" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "26" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "27" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "28" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "29" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "30" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "31" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "32" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "33" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "34" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "35" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "36" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "37" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "38" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "39" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "40" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "41" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "42" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "43" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "44" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "45" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "46" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "47" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "48" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "49" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "50" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "51" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "52" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "53" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "54" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "55" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "56" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "57" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "58" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "59" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "60" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "61" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "62" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "63" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "64" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "65" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "66" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "67" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "68" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "69" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "70" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "71" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "72" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "73" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "74" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "75" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "76" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "77" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "78" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "79" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "80" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "81" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "82" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "83" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "84" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "85" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "86" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "87" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "88" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "89" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "90" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "91" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "92" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "93" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "94" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "95" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "96" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "97" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "98" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] }, { "match" : "", "idx" : { "$numberInt" : "99" }, "captures" : [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 50000, 'c') || LPAD('', 50000, 'd') || 'e", "regex": "' || LPAD('',2500*3,'(d)') || 'e"}} }')::bson); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddde", "idx" : { "$numberInt" : "97500" }, "captures" : [ "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d", "d" ] } ] } (1 row) -- $regexFindAll operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFindAll" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "4", "result" : [ { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] }, { "match" : "456", "idx" : { "$numberInt" : "3" }, "captures" : [ ] }, { "match" : "789", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFindAll" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "3", "result" : [ { "match" : "World", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFindAll" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "5", "result" : [ { "match" : "ID", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFindAll" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "6", "result" : [ { "match" : ",", "idx" : { "$numberInt" : "5" }, "captures" : [ ] }, { "match" : "!", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "7", "result" : [ { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ ] }, { "match" : "ipsum", "idx" : { "$numberInt" : "6" }, "captures" : [ ] }, { "match" : "dolor", "idx" : { "$numberInt" : "12" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFindAll" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "8", "result" : [ { "match" : "john@example.com", "idx" : { "$numberInt" : "12" }, "captures" : [ ] }, { "match" : "555-123-4567", "idx" : { "$numberInt" : "37" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFindAll" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "9", "result" : [ { "match" : "

Paragraph 1

", "idx" : { "$numberInt" : "14" }, "captures" : [ "Paragraph 1" ] }, { "match" : "

Paragraph 2

", "idx" : { "$numberInt" : "32" }, "captures" : [ "Paragraph 2" ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "ABCDXYZABCDXYZABCDXYZ", "regex" : "BC(P(DE)?)?"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "BC", "idx" : { "$numberInt" : "1" }, "captures" : [ null, null ] }, { "match" : "BC", "idx" : { "$numberInt" : "8" }, "captures" : [ null, null ] }, { "match" : "BC", "idx" : { "$numberInt" : "15" }, "captures" : [ null, null ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "aaa aa", "regex" : "(a*?)"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "", "idx" : { "$numberInt" : "0" }, "captures" : [ "" ] }, { "match" : "", "idx" : { "$numberInt" : "1" }, "captures" : [ "" ] }, { "match" : "", "idx" : { "$numberInt" : "2" }, "captures" : [ "" ] }, { "match" : "", "idx" : { "$numberInt" : "3" }, "captures" : [ "" ] }, { "match" : "", "idx" : { "$numberInt" : "4" }, "captures" : [ "" ] }, { "match" : "", "idx" : { "$numberInt" : "5" }, "captures" : [ "" ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "aaaaa aaaa", "regex" : "(aa)"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "aa", "idx" : { "$numberInt" : "0" }, "captures" : [ "aa" ] }, { "match" : "aa", "idx" : { "$numberInt" : "2" }, "captures" : [ "aa" ] }, { "match" : "aa", "idx" : { "$numberInt" : "6" }, "captures" : [ "aa" ] }, { "match" : "aa", "idx" : { "$numberInt" : "8" }, "captures" : [ "aa" ] } ] } (1 row) -- $regexFindAll operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexFindAll" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "10", "result" : [ { "match" : "John Doe, 25 years old", "idx" : { "$numberInt" : "0" }, "captures" : [ "John", "Doe", "25" ] } ] } (1 row) select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexFindAll" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "11", "result" : [ { "match" : "Date: 2023-07-14", "idx" : { "$numberInt" : "0" }, "captures" : [ "2023-07-14" ] } ] } (1 row) select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexFindAll" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "12", "result" : [ { "match" : "Product: Apple iPhone 12", "idx" : { "$numberInt" : "0" }, "captures" : [ "Apple", "iPhone", "12" ] } ] } (1 row) select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexFindAll" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "13", "result" : [ { "match" : "Email: john@example.com", "idx" : { "$numberInt" : "0" }, "captures" : [ "john@example.com" ] } ] } (1 row) select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "14", "result" : [ { "match" : "Lorem", "idx" : { "$numberInt" : "0" }, "captures" : [ "Lorem" ] }, { "match" : "ipsum", "idx" : { "$numberInt" : "6" }, "captures" : [ "ipsum" ] }, { "match" : "dolor", "idx" : { "$numberInt" : "12" }, "captures" : [ "dolor" ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "", "regex" : "(missing)|()"} } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "", "idx" : { "$numberInt" : "0" }, "captures" : [ null, "" ] } ] } (1 row) -- $regexFindAll operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexFindAll" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "15", "result" : [ { "match" : "world", "idx" : { "$numberInt" : "6" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ { "match" : "FOX", "idx" : { "$numberInt" : "16" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexFindAll" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "17", "result" : [ { "match" : "123", "idx" : { "$numberInt" : "0" }, "captures" : [ ] }, { "match" : "456", "idx" : { "$numberInt" : "4" }, "captures" : [ ] }, { "match" : "789", "idx" : { "$numberInt" : "8" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexFindAll" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "18", "result" : [ { "match" : "long text", "idx" : { "$numberInt" : "10" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexFindAll" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "20", "result" : [ { "match" : "Hello there", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) -- $regexFindAll operator: empty cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"a","regex" : null }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"a","regex" : "$z" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"apple","regex" : "boy" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "16", "result" : [ ] } (1 row) select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexFindAll" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "19", "result" : [ ] } (1 row) -- $regexFindAll operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexFindAll" : {"input":"$a", "regex" : "$b" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "app", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexFindAll" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "APP", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : [ { "match" : "APPLE", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } (1 row) -- $regexFindAll operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"", "regex" : "", "extra" : "" }} }'); ERROR: $regexFindAll encountered an unrecognized input argument: extra select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : { "regex" : ""}} }'); ERROR: $regexFindAll needs the 'input' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : { "input" : ""}} }'); ERROR: $regexFindAll needs the 'regex' parameter specified select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": 1, "regex" : "", "options" : "" }} }'); ERROR: The $regexFindAll requires that the 'input' parameter must be of type string. select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : 1, "options" : "" }} }'); ERROR: $regexFindAll requires that 'regex' must be provided as either a string or a regular expression select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : "a", "options" : 1 }} }'); ERROR: $regexFindAll requires that 'options' must be provided as a string select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); ERROR: $regexFindAll detected that regex options have been defined in both the 'regex' and 'option' fields select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : "a", "options" : "g" }} }'); ERROR: $regexFindAll Invalid flag detected in regex options: g select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : null} }'); ERROR: $regexFindAll requires an object containing named arguments, but encountered: null select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : 1} }'); ERROR: $regexFindAll requires an object containing named arguments, but encountered: int select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); ERROR: $regexFindAll: Regular expression options must not include an embedded null byte select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); ERROR: $regexFindAll: regular expression cannot include an embedded null character select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"(m(p)"} } }'); ERROR: Invalid Regex in $regexFindAll: missing closing parenthesis select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('',100000, 'a') || '", "regex": "(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"}} }')::bson); ERROR: $regexFindAll: buffer size for storing output has exceeded the maximum allowed limit of 64MB select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 50000, 'c') || LPAD('', 50000, 'd') || 'e", "regex": "' || LPAD('',2728*3,'(d)') || 'e"}} }')::bson); ERROR: There isn't enough available memory to perform the evaluation of the regular expression. --regex Operators : with multiple document in collection --creating collection SELECT create_collection('db','regexMultiDocumentTest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) --inserting data SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":1, "input" : "apple", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":2, "input" : "apple is sweet", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":3, "input" : "apple is lime", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":4, "input" : "lime is blue", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":5, "input" : "blue is berry", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":6, "input" : "need apple for nothing", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":7, "input" : "One apple a day keeps doctor away", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":8, "input" : "red apple is red ?", "regex" : "apple", "option" : "i"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --case 1: when regex and options are constant we compile regex only once SELECT bson_dollar_project(document, '{"result" : { "$regexMatch" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : true } { "_id" : { "$numberInt" : "2" }, "result" : true } { "_id" : { "$numberInt" : "3" }, "result" : true } { "_id" : { "$numberInt" : "4" }, "result" : false } { "_id" : { "$numberInt" : "5" }, "result" : false } { "_id" : { "$numberInt" : "6" }, "result" : true } { "_id" : { "$numberInt" : "7" }, "result" : true } { "_id" : { "$numberInt" : "8" }, "result" : true } (8 rows) SELECT bson_dollar_project(document, '{"result" : { "$regexFind" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "2" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "3" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "4" }, "result" : null } { "_id" : { "$numberInt" : "5" }, "result" : null } { "_id" : { "$numberInt" : "6" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "7" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "8" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } } (8 rows) SELECT bson_dollar_project(document, '{"result" : { "$regexFindAll" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "2" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "3" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "4" }, "result" : [ ] } { "_id" : { "$numberInt" : "5" }, "result" : [ ] } { "_id" : { "$numberInt" : "6" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "7" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "8" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } ] } (8 rows) --case 2: when regex and options are not constant we compile regex every document SELECT bson_dollar_project(document, '{"result" : { "$regexMatch" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : true } { "_id" : { "$numberInt" : "2" }, "result" : true } { "_id" : { "$numberInt" : "3" }, "result" : true } { "_id" : { "$numberInt" : "4" }, "result" : false } { "_id" : { "$numberInt" : "5" }, "result" : false } { "_id" : { "$numberInt" : "6" }, "result" : true } { "_id" : { "$numberInt" : "7" }, "result" : true } { "_id" : { "$numberInt" : "8" }, "result" : true } (8 rows) SELECT bson_dollar_project(document, '{"result" : { "$regexFind" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "2" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "3" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "4" }, "result" : null } { "_id" : { "$numberInt" : "5" }, "result" : null } { "_id" : { "$numberInt" : "6" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "7" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } } { "_id" : { "$numberInt" : "8" }, "result" : { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } } (8 rows) SELECT bson_dollar_project(document, '{"result" : { "$regexFindAll" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "2" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "3" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "0" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "4" }, "result" : [ ] } { "_id" : { "$numberInt" : "5" }, "result" : [ ] } { "_id" : { "$numberInt" : "6" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "5" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "7" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } ] } { "_id" : { "$numberInt" : "8" }, "result" : [ { "match" : "apple", "idx" : { "$numberInt" : "4" }, "captures" : [ ] } ] } (8 rows) --dropping collection SELECT drop_collection('db','regexMultiDocumentTest'); drop_collection --------------------------------------------------------------------- t (1 row) -- $replaceOne basic tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint", "find": "blue and green paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "blue paint" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint with blue paintbrush" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint with green paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint with green paintbrush" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "ross", "replacement": "rachel"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatrachel" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": "one"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "onealbatross" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "", "replacement": "foo"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "foo" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "rachel", "replacement": "ross"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "rachel", "replacement": "ross"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "rachel", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) -- $replaceOne null tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": "ross", "replacement": "rachel"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": null, "replacement": "yelo"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": null, "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": "f", "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": null, "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $replaceOne with path select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hchandlerlo" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "$test.nest", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hchandlerlo" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "wandering hellostater", "find": "$test.nest", "replacement": "phoebe"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "wandering phoebestater" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "wandering cheapskate", "find": "cheap", "replacement": "$test.nest"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "wandering helloskate" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"input": "hello", "find": "ello", replacement: "atred"}}', '{"result": {"$replaceOne": {"input": "$input", "find": "$find", "replacement": "$replacement"}}}'); ERROR: invalid input syntax JSON for BSON: Code: '1', Message 'Got parse error at "r", position 55: "SPECIAL_EXPECTED"' LINE 1: select bson_dollar_project('{"_id":"1", "test": {"input": "h... ^ -- $replaceOne with missing path select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "$test.nesty", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "$madame", "replacement": "non"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "replacement": "$non"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $replaceOne unsupported data types select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": 1, "find": "el", "replacement": "chandler"}}}'); ERROR: $replaceOne expects 'input' to be provided as a string, but it was given: 1 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": 2, "replacement": "chandler"}}}'); ERROR: $replaceOne expects 'find' to be provided as a string, but it was given: 2 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": "el", "replacement": 3}}}'); ERROR: $replaceOne requires 'replacement' to be provided as a string type, but it was given: 3 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2], "find": "el", "replacement": 3}}}'); ERROR: $replaceOne expects 'input' to be provided as a string, but it was given: [ "\"©\"©\"©\"©", 1, 2 ] select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": {"$binary": {"base64": "ww==", "subType": "01"}}, "replacement": 3}}}'); ERROR: $replaceOne expects 'find' to be provided as a string, but it was given: { "$binary" : { "base64" : "ww==", "subType" : "01" } } select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": "el", "replacement": {"$regex": "/ab/cdsd/abc", "$options" : ""}}}}'); ERROR: $replaceOne requires 'replacement' to be provided as a string type, but it was given: { "$regularExpression" : { "pattern" : "/ab/cdsd/abc", "options" : "" } } select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": NaN, "replacement": "chandler"}}}'); ERROR: $replaceOne expects 'find' to be provided as a string, but it was given: NaN select bson_dollar_project('{"_id":"1", "test": {"a": "this is a string"}}', '{"result": {"$replaceOne": {"input": "$test", "find": "is", "replacement": "chandler"}}}'); ERROR: $replaceOne expects 'input' to be provided as a string, but it was given: { "a" : "this is a string" } -- $replaceOne missing/additional argument select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"find": NaN, "replacement": "chandler"}}}'); ERROR: $replaceOne requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "replacement": "chandler"}}}'); ERROR: The $replaceOne requires that 'find' be explicitly specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": "asdf"}}}'); ERROR: The $replaceOne cannot proceed because the 'replacement' parameter has not been specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test"}}}'); ERROR: The $replaceOne requires that 'find' be explicitly specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"replacement": "chandler"}}}'); ERROR: $replaceOne requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"find": NaN}}}'); ERROR: $replaceOne requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "replacement": "$non", "newField": "he"}}}'); ERROR: $replaceOne encountered an unrecognized input argument: newField select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "newField": "he"}}}'); ERROR: $replaceOne encountered an unrecognized input argument: newField -- $replaceOne operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "I â¤ï¸ documentdb", "find": "â¤ï¸", "replacement": "\u0000B"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I \u0000B documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "jalapeño", "find": "peñ", "replacement": "寿å¸"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "jala寿å¸o" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "a\u0000B\u000d", "find": "\u000d", "replacement": "🥲"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000B🥲" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "cafétéria", "find": "caf", "replacement": "é"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "éétéria" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "cafe\u0301", "find": "café", "replacement": "CAFE" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "cafeÌ" } (1 row) -- $replaceAll basic tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "f bar" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": "O"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "fOO bar" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": "OO"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "fOOOO bar" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foooo bar", "find": "o", "replacement": "O"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "fOOOO bar" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint", "find": "blue and green paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "blue paint" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint with red paintbrush" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with green paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "red paint with green paintbrush" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "ross", "replacement": "rachel"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatrachel" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": "one"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "oneaoneloneboneaonetoneroneoonesonesone" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "", "replacement": "foo"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "foo" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "rachel", "replacement": "ross"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "rachel", "replacement": "ross"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "rachel", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": ""}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatross" } (1 row) -- $replaceAll null tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": "ross", "replacement": "rachel"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": null, "replacement": "yelo"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": null, "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": "f", "replacement": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": null, "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $replaceAll with path select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hchandlerlo" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "$test.nest", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "hchandlerlo" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "wandering hellostater", "find": "$test.nest", "replacement": "phoebe"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "wandering phoebestater" } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "wandering cheapskate", "find": "cheap", "replacement": "$test.nest"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "wandering helloskate" } (1 row) -- $replaceAll with missing path select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "$test.nesty", "find": "el", "replacement": "chandler"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "$madame", "replacement": "non"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "replacement": "$non"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : null } (1 row) -- $replaceAll unsupported data types select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": 1, "find": "el", "replacement": "chandler"}}}'); ERROR: $replaceAll expects 'input' to be provided as a string, but it was given: 1 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": 2, "replacement": "chandler"}}}'); ERROR: $replaceAll expects 'find' to be provided as a string, but it was given: 2 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "el", "replacement": 3}}}'); ERROR: $replaceAll requires 'replacement' to be provided as a string type, but it was given: 3 select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2], "find": "el", "replacement": 3}}}'); ERROR: $replaceAll expects 'input' to be provided as a string, but it was given: [ "\"©\"©\"©\"©", 1, 2 ] select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": {"$binary": {"base64": "ww==", "subType": "01"}}, "replacement": 3}}}'); ERROR: $replaceAll expects 'find' to be provided as a string, but it was given: { "$binary" : { "base64" : "ww==", "subType" : "01" } } select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "el", "replacement": {"$regex": "/ab/cdsd/abc", "$options" : ""}}}}'); ERROR: $replaceAll requires 'replacement' to be provided as a string type, but it was given: { "$regularExpression" : { "pattern" : "/ab/cdsd/abc", "options" : "" } } select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": NaN, "replacement": "chandler"}}}'); ERROR: $replaceAll expects 'find' to be provided as a string, but it was given: NaN select bson_dollar_project('{"_id":"1", "test": {"a": "this is a string"}}', '{"result": {"$replaceAll": {"input": "$test", "find": "is", "replacement": "chandler"}}}'); ERROR: $replaceAll expects 'input' to be provided as a string, but it was given: { "a" : "this is a string" } -- $replaceAll missing/additional argument select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"find": NaN, "replacement": "chandler"}}}'); ERROR: $replaceAll requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "replacement": "chandler"}}}'); ERROR: The $replaceAll requires that 'find' be explicitly specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": "asdf"}}}'); ERROR: The $replaceAll cannot proceed because the 'replacement' parameter has not been specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test"}}}'); ERROR: The $replaceAll requires that 'find' be explicitly specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"replacement": "chandler"}}}'); ERROR: $replaceAll requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"find": NaN}}}'); ERROR: $replaceAll requires 'input' to be specified select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "replacement": "$non", "newField": "he"}}}'); ERROR: $replaceAll encountered an unrecognized input argument: newField select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "newField": "he"}}}'); ERROR: $replaceAll encountered an unrecognized input argument: newField -- $replaceAll operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "I â¤ï¸ documentdb", "find": "â¤ï¸", "replacement": "\u0000B"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "I \u0000B documentdb" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "jalapeño", "find": "peñ", "replacement": "寿å¸"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "jala寿å¸o" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "a\u0000B\u000d", "find": "\u000d", "replacement": "🥲"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "a\u0000B🥲" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "cafétéria", "find": "caf", "replacement": "é"}}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "éétéria" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "cafe\u0301", "find": "café", "replacement": "CAFE" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "cafeÌ" } (1 row) -- $replaceAll multiple replacements select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "The quick fox jumped over the laze dog", "find": "d", "replacement": "cat" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "The quick fox jumpecat over the laze catog" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross and its wings", "find": " ", "replacement": "huge" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "albatrosshugeandhugeitshugewings" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "green paint" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "green paint with green paintbrush" } (1 row) select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "", "replacement": "z" }}}'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : "zyzezlzlzozwz" } (1 row) bson_aggregation_tests_lookup_inner_join.out000066400000000000000000001030521507310017400410620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 731000; SET documentdb.next_collection_id TO 7310; SET documentdb.next_collection_index_id TO 7310; \i sql/bson_aggregation_tests_lookup_inner_join_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 1, "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:4: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes','{ "_id" : 2, "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 3, "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 4, "model" : "737", "price" : 50, "quantity" : 30 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 1, "plane_model" : "A330", "gates" : 30 }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:9: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 11, "plane_model" : "A340", "gates" : 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 2, "plane_model" : "A380", "gates" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 3, "plane_model" : "A350", "gates" : 20 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 4, "plane_model" : "737", "gates" : 110 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- set up indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "planes", "indexes": [ { "key": { "model": 1 }, "name": "planes_model_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "gate_availability", "indexes": [ { "key": { "plane_model": 1 }, "name": "plane_model_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Remove primary key ALTER TABLE documentdb_data.documents_7311 DROP CONSTRAINT collection_pk_7311; ALTER TABLE documentdb_data.documents_7312 DROP CONSTRAINT collection_pk_7312; ANALYZE documentdb_data.documents_7311; ANALYZE documentdb_data.documents_7312; BEGIN; set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "model" : "A330", "price" : { "$numberInt" : "10" }, "quantity" : { "$numberInt" : "5" }, "matched_docs" : { "_id" : { "$numberInt" : "1" }, "plane_model" : "A330", "gates" : { "$numberInt" : "30" } } } { "_id" : { "$numberInt" : "2" }, "model" : "A340", "price" : { "$numberInt" : "140" }, "quantity" : { "$numberInt" : "1" }, "matched_docs" : { "_id" : { "$numberInt" : "11" }, "plane_model" : "A340", "gates" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "1" }, "model" : "A380", "price" : { "$numberInt" : "280" }, "quantity" : { "$numberInt" : "20" }, "matched_docs" : { "_id" : { "$numberInt" : "2" }, "plane_model" : "A380", "gates" : { "$numberInt" : "5" } } } { "_id" : { "$numberInt" : "4" }, "model" : "737", "price" : { "$numberInt" : "50" }, "quantity" : { "$numberInt" : "30" }, "matched_docs" : { "_id" : { "$numberInt" : "4" }, "plane_model" : "737", "gates" : { "$numberInt" : "110" } } } (4 rows) ROLLBACK; -- Insert a lot more data DO $$ DECLARE i int; BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes','{ "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "737", "price" : 50, "quantity" : 30 }', NULL); END LOOP; END; $$; DO $$ DECLARE i int; BEGIN FOR i IN 1..250 LOOP PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A330", "gates" : 30 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A340", "gates" : 10 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A380", "gates" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A350", "gates" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "737", "gates" : 110 }', NULL); END LOOP; END; $$; -- Now test index usage BEGIN; set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) -> Bitmap Heap Scan on documents_7311_731002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Materialize -> Seq Scan on documents_7312_731004 collection_0_1 Filter: (document IS NOT NULL) (14 rows) set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) -> Bitmap Heap Scan on documents_7311_731002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Materialize -> Seq Scan on documents_7312_731004 collection_0_1 (13 rows) set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_7311_731002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using plane_model_1 on documents_7312_731004 collection_0_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) (13 rows) set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Nested Loop -> Bitmap Heap Scan on documents_7311_731002 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on planes_model_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "model" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Index Scan using plane_model_1 on documents_7312_731004 collection_0_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson)) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "plane_model" : "model" }'::documentdb_core.bson), 'plane_model'::text) (13 rows) ROLLBACK; -- Cleanup SELECT documentdb_api.drop_collection('lookupdb', 'planes'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('lookupdb', 'gate_availability'); drop_collection --------------------------------------------------------------------- t (1 row) -- lookup with point read where inner plan depends on external param crash fix scenario SELECT documentdb_api.insert_one('lookupdb','Dishes',' { "_id" : 1, "dishId" : 1, "ingredients": [1, 2, 3, 4] }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:104: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 1, "shopId" : 101, "name": "Salt" }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:105: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 2, "shopId" : 101, "name": "Clove" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 3, "shopId" : 101, "name": "Olive" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 4, "shopId" : 101, "name": "Pepper" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('lookupdb','Shops',' { "_id" : 101, "name": "ABC Mart" }', NULL); psql:sql/bson_aggregation_tests_lookup_inner_join_core.sql:109: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Get collection IDs for each collection and store them in variables SELECT collection_id AS dishes_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Dishes' \gset SELECT collection_id AS ingredients_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Ingredients' \gset SELECT collection_id AS shops_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Shops' \gset -- Dynamically run ANALYZE commands using the collection IDs SELECT 'ANALYZE documentdb_data.documents_' || :'dishes_id' \gexec ANALYZE documentdb_data.documents_7313 SELECT 'ANALYZE documentdb_data.documents_' || :'ingredients_id' \gexec ANALYZE documentdb_data.documents_7314 SELECT 'ANALYZE documentdb_data.documents_' || :'shops_id' \gexec ANALYZE documentdb_data.documents_7315 BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "1" }, "ingredient_info" : { "_id" : { "$numberInt" : "1" }, "shopId" : { "$numberInt" : "101" }, "name" : "Salt" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "2" }, "ingredient_info" : { "_id" : { "$numberInt" : "2" }, "shopId" : { "$numberInt" : "101" }, "name" : "Clove" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "3" }, "ingredient_info" : { "_id" : { "$numberInt" : "3" }, "shopId" : { "$numberInt" : "101" }, "name" : "Olive" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } { "_id" : { "$numberInt" : "1" }, "dishId" : { "$numberInt" : "1" }, "ingredients" : { "$numberInt" : "4" }, "ingredient_info" : { "_id" : { "$numberInt" : "4" }, "shopId" : { "$numberInt" : "101" }, "name" : "Pepper" }, "shop_info" : { "_id" : { "$numberInt" : "101" }, "name" : "ABC Mart" } } (4 rows) ROLLBACK; BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; EXPLAIN (COSTS OFF, SUMMARY OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1.document, "lookupRight_stage_1".document, 'shop_info'::text) AS document FROM ((SELECT agg_stage_3.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_3.document, '{ "_id" : "ingredient_info.shopId" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(lookup_stage_1_1.document, "lookupRight_stage_1_1".document, 'ingredient_info'::text) AS document FROM ((SELECT agg_stage_2.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_array(agg_stage_2.document, '{ "_id" : "ingredients" }'::documentdb_core.bson) AS lookup_filter FROM (SELECT documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text) AS document FROM documentdb_data.documents_7313_731006 collection WHERE ((collection.document OPERATOR(documentdb_api_catalog.#=) '{ "dishId" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (collection.shard_key_value OPERATOR(pg_catalog.=) '7313'::bigint))) agg_stage_2) lookup_stage_1_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_7314_731008 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '7314'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1_1.lookup_filter))) "lookupRight_stage_1_1" ON (true)) WHERE ("lookupRight_stage_1_1".document IS NOT NULL)) agg_stage_3) lookup_stage_1 LEFT JOIN LATERAL (SELECT lookup_right_query_stage_0.document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_7315_731010 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '7315'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) ANY (lookup_stage_1.lookup_filter))) "lookupRight_stage_1" ON (true)) WHERE ("lookupRight_stage_1".document IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents_at_path(documentdb_api_internal.bson_dollar_merge_documents_at_path((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), collection_0_1.document, 'ingredient_info'::text), collection_0_1_1.document, 'shop_info'::text) -> Nested Loop Output: (documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), collection_0_1.document -> ProjectSet Output: documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text) -> Seq Scan on documentdb_data.documents_7313_731006 collection Output: collection.shard_key_value, collection.object_id, collection.document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "dishId" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Index Scan using _id_ on documentdb_data.documents_7314_731008 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: ((collection_0_1.shard_key_value = '7314'::bigint) AND (collection_0_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), '{ "_id" : "ingredients" }'::documentdb_core.bson)))) Filter: (collection_0_1.document IS NOT NULL) -> Index Scan using _id_ on documentdb_data.documents_7315_731010 collection_0_1_1 Output: collection_0_1_1.shard_key_value, collection_0_1_1.object_id, collection_0_1_1.document Index Cond: ((collection_0_1_1.shard_key_value = '7315'::bigint) AND (collection_0_1_1.object_id OPERATOR(documentdb_core.=) ANY (documentdb_api_internal.bson_dollar_lookup_extract_filter_array(documentdb_api_internal.bson_dollar_merge_documents_at_path((documentdb_api_catalog.bson_dollar_unwind(collection.document, '$ingredients'::text)), collection_0_1.document, 'ingredient_info'::text), '{ "_id" : "ingredient_info.shopId" }'::documentdb_core.bson)))) Filter: (collection_0_1_1.document IS NOT NULL) (24 rows) ROLLBACK; bson_aggregation_timestamp_operators_tests.out000066400000000000000000000172251507310017400414460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8800000; SET documentdb.next_collection_id TO 8800; SET documentdb.next_collection_index_id TO 8800; -- $tsSecond operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": null }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": {"$undefined":true} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": { "$timestamp": { "t": 1622431468, "i": 1 }} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1622431468" } } (1 row) -- $tsSecond operator , input document tests SELECT * FROM bson_dollar_project('{"a": { "$timestamp": { "t": 1622431468, "i": 1 }} }', '{"result": { "$tsSecond": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1622431468" } } (1 row) -- $tsSecond operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": "" }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: string SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": [1,2] }}'); ERROR: The expression $tsSecond requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": [1] }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": 11 }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": true }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: bool SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$tsSecond": "$a" }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: int SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": {"$regex": "a*b", "$options":""} }}'); ERROR: The $tsSecond operator needs a valid timestamp argument, but instead received: regex -- $tsIncrement operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": null }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": {"$undefined":true} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": { "$timestamp": { "t": 1622431468, "i": 1 }} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1" } } (1 row) -- Create Collection SELECT documentdb_api.create_collection('db', 'timestampTest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- $tsIncrement/$tsSecond operator , input document tests SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "a", "tsValue": { "$timestamp": { "t": 1622431468, "i": 1 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "a", "tsValue": { "$timestamp": { "t": 1622431468, "i": 2 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124193, "i": 1 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124192, "i": 1 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124192, "i": 2 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{"aggregate": "timestampTest", "pipeline": [{ "$project": {"_id": 0, "tsValue": 1, "incrementValue": {"$tsIncrement": "$tsValue"}, "secondValue": {"$tsSecond": "$tsValue"}}} ]}'); document --------------------------------------------------------------------- { "tsValue" : { "$timestamp" : { "t" : 1622431468, "i" : 1 } }, "incrementValue" : { "$numberLong" : "1" }, "secondValue" : { "$numberLong" : "1622431468" } } { "tsValue" : { "$timestamp" : { "t" : 1622431468, "i" : 2 } }, "incrementValue" : { "$numberLong" : "2" }, "secondValue" : { "$numberLong" : "1622431468" } } { "tsValue" : { "$timestamp" : { "t" : 1714124193, "i" : 1 } }, "incrementValue" : { "$numberLong" : "1" }, "secondValue" : { "$numberLong" : "1714124193" } } { "tsValue" : { "$timestamp" : { "t" : 1714124192, "i" : 1 } }, "incrementValue" : { "$numberLong" : "1" }, "secondValue" : { "$numberLong" : "1714124192" } } { "tsValue" : { "$timestamp" : { "t" : 1714124192, "i" : 2 } }, "incrementValue" : { "$numberLong" : "2" }, "secondValue" : { "$numberLong" : "1714124192" } } (5 rows) -- $tsIncrement operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": "" }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'string' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": [1,2] }}'); ERROR: The expression $tsIncrement requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": [1] }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": 11 }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": true }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'bool' type SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$tsIncrement": "$a" }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'int' type SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": {"$regex": "a*b", "$options":""} }}'); ERROR: Expected 'timestamp' type for $tsIncrement but found 'regex' type bson_aggregation_trigonometric_operators_tests.out000066400000000000000000004320041507310017400423240ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 7800000; SET documentdb.next_collection_id TO 7800; SET documentdb.next_collection_index_id TO 7800; -- SET client_min_messages TO DEBUG3; -- $degreesToRadians operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 45 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": -45 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 90 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 180 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.141592653589793116" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 270 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "4.712388980384689674" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 1000 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "17.453292519943296668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": -1000 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-17.453292519943296668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.745329251994327777777777777777778E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.745329251994327777777777777777778E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.000001745329251994327777777777777777778" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.000001745329251994327777777777777777778" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "90" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.570796326794895000000000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.017453292519943122002" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$degreesToRadians": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.52359877559829881566" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": null }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "NaN"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "Infinity"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "-Infinity"} }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-Infinity" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": "str" }}'); ERROR: $degreesToRadians works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": ["str"] }}'); ERROR: $degreesToRadians works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": true }}'); ERROR: $degreesToRadians works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": false }}'); ERROR: $degreesToRadians works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$degreesToRadians": [2, "$a"] }}'); ERROR: The expression $degreesToRadians requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$degreesToRadians": ["$a", 5] }}'); ERROR: The expression $degreesToRadians requires exactly 1 arguments, but 2 arguments were actually provided. -- $radiansToDegrees operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 3.141592653589793}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "180.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": -3.141592653589793}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-180.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 6.283185307179586}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "360.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 12.566370614359172}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "720.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5729.5779513082325138" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "5.729577951308237993927443244998426E-9" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": { "$numberDecimal": "9.42477796076938" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "540.0000000000005729577951308237994" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-Infinity" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": "str"}}'); ERROR: $radiansToDegrees works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": ["str"]}}'); ERROR: $radiansToDegrees works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": true}}'); ERROR: $radiansToDegrees works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": false}}'); ERROR: $radiansToDegrees works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$radiansToDegrees": [2, "$a"]}}'); ERROR: The expression $radiansToDegrees requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$radiansToDegrees": ["$a", 5]}}'); ERROR: The expression $radiansToDegrees requires exactly 1 arguments, but 2 arguments were actually provided. -- $sin operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.84147098480789650488" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.84147098480789650488" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.2246467991473532072e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.4492935982947064143e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.50636564110975879061" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.50636564110975879061" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "9.999999999999999999983333333333332E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-9.999999999999999999983333333333332E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.00009999999983333333341666666664682538" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.00009999999983333333341666666664682538" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999999999999999998" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$sin": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.70710678118654746172" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.70710678118654746172" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.2246467991473532072e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.98480775301220790929" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.98480775301220790929" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.745329251994327777777776891681622E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.745329251994327777777776891681622E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.000001745329251993441681622076617462208" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.000001745329251993441681622076617462208" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999999999999986890" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.017452406437283338181" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$sin": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.49999999999999994449" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "Infinity"}}}'); ERROR: Unable to use operator $sin on Infinity, as the value must fall within the range (-inf, inf) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "-Infinity"}}}'); ERROR: Unable to use operator $sin on -Infinity, as the value must fall within the range (-inf, inf) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": "str"}}'); ERROR: $sin works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": ["str"]}}'); ERROR: $sin works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": true}}'); ERROR: $sin works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": false}}'); ERROR: $sin works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$sin": [2, "$a"]}}'); ERROR: The expression $sin requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$sin": ["$a", 5]}}'); ERROR: The expression $sin requires exactly 1 arguments, but 2 arguments were actually provided. -- $cos operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54030230586813976501" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54030230586813976501" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "6.1232339957367660359e-17" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.8369701987210296875e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.86231887228768389075" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.86231887228768389075" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999950000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999950000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999950000000041666666652777778" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999950000000041666666652777778" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.923132169163975144209858469968755E-17" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$cos": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-3.8468979719437751534e-10" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.70710678118654757274" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.70710678118654757274" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "6.1232339957367660359e-17" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.8369701987210296875e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.17364817766693124712" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.17364817766693124712" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999999984769129011" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999999999999999984769129011" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999984769129010668467757534" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9999999999984769129010668467757534" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.619231321691639751442098584698980E-15" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99984769515639126958" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$cos": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.86602540378443870761" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "Infinity"}}}'); ERROR: Cannot use $cos with Infinity; the value must lie within the range (-inf, inf). SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "-Infinity"}}}'); ERROR: Cannot use $cos with -Infinity; the value must lie within the range (-inf, inf). -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": "str"}}'); ERROR: $cos works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": ["str"]}}'); ERROR: $cos works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": true}}'); ERROR: $cos works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": false}}'); ERROR: $cos works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$cos": [2, "$a"]}}'); ERROR: The expression $cos requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cos": ["$a", 5]}}'); ERROR: The expression $cos requires exactly 1 arguments, but 2 arguments were actually provided. -- $tan operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5574077246549022924" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.5574077246549022924" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "16331239353195370.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.2246467991473532072e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5443746451065123.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.4492935982947064143e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.58721391515692911156" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.58721391515692911156" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000003333333333333E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.000000000000000000003333333333333E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.0001000000003333333346666666720634921" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.0001000000003333333346666666720634921" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "51998506188720270.66019474166122687" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$tan": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2599497068.2695703506" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99999999999999988898" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.99999999999999988898" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "16331239353195370.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.2246467991473532072e-16" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5443746451065123.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-5.6712818196176799646" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5.6712818196176799646" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.745329251994327777777779549970089E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.745329251994327777777779549970089E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.000001745329251996099970089182527691841" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.000001745329251996099970089182527691841" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "617576986440258.7149573171913478141" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.017455064928217411957" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$tan": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.57735026918962573106" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "Infinity"}}}'); ERROR: Unable to use operators tan on Infinity since the value must lie within the range (-inf, inf) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "-Infinity"}}}'); ERROR: Unable to use operators tan on -Infinity since the value must lie within the range (-inf, inf) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": "str"}}'); ERROR: $tan works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": ["str"]}}'); ERROR: $tan works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": true}}'); ERROR: $tan works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": false}}'); ERROR: $tan works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$tan": [2, "$a"]}}'); ERROR: The expression $tan requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$tan": ["$a", 5]}}'); ERROR: The expression $tan requires exactly 1 arguments, but 2 arguments were actually provided. -- $sinh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.1752011936438013784" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.1752011936438013784" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.3012989023072947248" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.548739357257748139" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.654397599417542608" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "267.74489404101643686" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3440585709080678047e+43" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.3440585709080678047e+43" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000001666666666667E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.000000000000000000001666666666667E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.0001000000001666666667500000000198413" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.0001000000001666666667500000000198413" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2.301298902307294825208221518622109" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$sinh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.65439757800441356" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.86867096148600952965" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.86867096148600952965" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.3012989023072947248" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.548739357257748139" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.654397599417542608" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "19003720.607039816678" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-19003720.607039816678" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.745329251994327777777778663873934E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.745329251994327777777778663873934E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.000001745329251995213873933479208013673" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.000001745329251995213873933479208013673" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2.301298902307290810522655665734274" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.017454178629594939431" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$sinh": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54785347388803973256" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-Infinity" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": "str"}}'); ERROR: $sinh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": ["str"]}}'); ERROR: $sinh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": true}}'); ERROR: $sinh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": false}}'); ERROR: $sinh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$sinh": [2, "$a"]}}'); ERROR: The expression $sinh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$sinh": ["$a", 5]}}'); ERROR: The expression $sinh requires exactly 1 arguments, but 2 arguments were actually provided. -- $cosh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5430806348152437124" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5430806348152437124" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.5091784786580566546" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.591953275521518663" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.663380890438666881" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "267.7467614837481733" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3440585709080678047e+43" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3440585709080678047e+43" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000005000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000005000000000000" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000005000000004166666668055556" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000005000000004166666668055556" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2.509178478658056737752976144380378" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$cosh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.663380869029005282" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3246090892520057114" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.3246090892520057114" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.5091784786580566546" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.591953275521518663" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "55.663380890438666881" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "19003720.60703984648" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "19003720.60703984648" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000000001523087099" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000000001523087099" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000001523087098933926489017" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000001523087098933926489017" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "2.509178478658053055674732452711869" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0001523125762563637" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$cosh": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.1402383210764286403" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": "str"}}'); ERROR: $cosh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": ["str"]}}'); ERROR: $cosh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": true}}'); ERROR: $cosh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": false}}'); ERROR: $cosh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$cosh": [2, "$a"]}}'); ERROR: The expression $cosh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cosh": ["$a", 5]}}'); ERROR: The expression $cosh requires exactly 1 arguments, but 2 arguments were actually provided. -- $tanh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.76159415595576485103" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": -1}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.76159415595576485103" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 0}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$divide": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.91715233566727438763" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 3.141592653589793 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99627207622074998028" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$multiply": [3.141592653589793, 1.5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99983861398863260739" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$multiply": [3.141592653589793, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99999302533961065276" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": -100}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "9.999999999999999999966666666666667E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-9.999999999999999999966666666666667E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.00009999999966666666799999999460317462" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.00009999999966666666799999999460317462" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "1.5707963267948966" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9171523356672743433185514582011665" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$tanh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99983861398850848445" } } (1 row) -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.6557942026326724072" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": -45 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.6557942026326724072" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 0 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 90 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.91715233566727438763" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 180 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99627207622074998028" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 270 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99983861398863260739" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.99999999999999866773" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": -1000 }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.99999999999999866773" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.745329251994327777777776005585467E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.745329251994327777777776005585467E-12" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.000001745329251992555585466377346588910" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.000001745329251992555585466377346588910" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.9171523356672740891880023700994649" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.017451520543541355901" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$tanh": { "$degreesToRadians": "$a" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.48047277815645161869" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Infinity/-Infinity returns Infinity/-Infinitytively SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": "str"}}'); ERROR: $tanh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": ["str"]}}'); ERROR: $tanh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": true}}'); ERROR: $tanh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": false}}'); ERROR: $tanh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$tanh": [2, "$a"]}}'); ERROR: The expression $tanh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$tanh": ["$a", 5]}}'); ERROR: The expression $tanh requires exactly 1 arguments, but 2 arguments were actually provided. -- $asin operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5707821846586877967" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.5707821846586877967" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$divide": [1, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$multiply": [-0.5, 1] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000001666666666667E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.000000000000000000001666666666667E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.7071067811865475 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.78539816339744816798" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.7071067811865475 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.78539816339744816798" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.8660254037844386 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0471975511965976313" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.8660254037844386 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.0471975511965976313" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "0.1" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.1001674211615597963455231794526933" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-0.1" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.1001674211615597963455231794526933" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.0001000000001666666674166666711309524" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-0.0001000000001666666674166666711309524" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$asin": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$asin": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.52359877559829892668" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression lies outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 1.0000000001 }}'); ERROR: Unable to apply $asin to 1 because the provided value must fall within the range [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -1.0000000001 }}'); ERROR: Unable to apply $asin to -1 because the provided value must fall within the range [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 10 }}'); ERROR: Unable to apply $asin to 10 because the provided value must fall within the range [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -10.9999999999 }}'); ERROR: Unable to apply $asin to -11 because the provided value must fall within the range [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "Infinity"}}}'); ERROR: Unable to apply $asin to Infinity because the provided value must fall within the range [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "-Infinity"}}}'); ERROR: Unable to apply $asin to -Infinity because the provided value must fall within the range [-1, 1] -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": "str"}}'); ERROR: $asin works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": ["str"]}}'); ERROR: $asin works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": true}}'); ERROR: $asin works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": false}}'); ERROR: $asin works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$asin": [2, "$a"]}}'); ERROR: The expression $asin requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$asin": ["$a", 5]}}'); ERROR: The expression $asin requires exactly 1 arguments, but 2 arguments were actually provided. -- $acos operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.141592653589793116" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.4142136208911563873e-05" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.1415785114535843547" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$divide": [1, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0471975511965978534" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$multiply": [-0.5, 1] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0943951023931957067" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.570796326694896619231321691639585" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.570796326894896619231321691639918" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.7071067811865475 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.78539816339744839002" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.7071067811865475 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.8660254037844386 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.52359877559829892668" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.8660254037844386 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.6179938779914944114" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "0.1" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.470628905633336822885798512187058" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-0.1" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.670963747956456415576844871092445" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.570696326794729952563905024968620" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-0.0001" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.570896326795063285898738358310882" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0471975511965978534" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0943951023931957067" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$acos": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.0471975511965978534" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$acos": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.0943951023931957067" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error if expression lies outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 1.0000000001 }}'); ERROR: $acos cannot be applied to 1 because its value must fall within the range [-1,1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -1.0000000001 }}'); ERROR: $acos cannot be applied to -1 because its value must fall within the range [-1,1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 10 }}'); ERROR: $acos cannot be applied to 10 because its value must fall within the range [-1,1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -10.9999999999 }}'); ERROR: $acos cannot be applied to -11 because its value must fall within the range [-1,1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "Infinity"}}}'); ERROR: $acos cannot be applied to Infinity because its value must fall within the range [-1,1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "-Infinity"}}}'); ERROR: $acos cannot be applied to -Infinity because its value must fall within the range [-1,1] -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": "str"}}'); ERROR: $acos works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": ["str"]}}'); ERROR: $acos works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": true}}'); ERROR: $acos works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": false}}'); ERROR: $acos works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$acos": [2, "$a"]}}'); ERROR: The expression $acos requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$acos": ["$a", 5]}}'); ERROR: The expression $acos requires exactly 1 arguments, but 2 arguments were actually provided. -- $atan operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.78539816334744827486" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.78539816334744827486" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "9.999999999999999999966666666666667E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-9.999999999999999999966666666666667E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 10 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.4711276743037347003" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -10 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.4711276743037347003" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 100 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5607966601082314817" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -100 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.5607966601082314817" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$divide": [1, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$multiply": [-0.5, 1] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$add": [10, 5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.5042281630190728059" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$subtract": [10, 15] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.3734007669450158939" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$atan": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$atan": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$atan": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.4711276743037347003" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -10}', '{"result": { "$atan": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.4711276743037347003" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.570796326794896558" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": "str"}}'); ERROR: $atan works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": ["str"]}}'); ERROR: $atan works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": true}}'); ERROR: $atan works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": false}}'); ERROR: $atan works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$atan": [2, "$a"]}}'); ERROR: The expression $atan requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$atan": ["$a", 5]}}'); ERROR: The expression $atan requires exactly 1 arguments, but 2 arguments were actually provided. -- $atan2 operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-1, -1] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, 0] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0.9999999999, 0.9999999999] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-0.9999999999, -0.9999999999] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 0] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-1, 0] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-1.570796326794896558" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, 1] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, -1] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.141592653589793116" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0.5, 0.5] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-0.5, -0.5] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [10, 10] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-10, -10] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [100, 100] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-100, -100] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$divide": [1, 2]}, {"$divide": [1, 2] }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$multiply": [-0.5, 1]}, {"$multiply": [-0.5, 1] }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$add": [10, 5]}, {"$add": [10, 5] }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$subtract": [10, 15]}, {"$subtract": [10, 15] }]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "0.1" }, { "$numberDecimal": "0.2" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "0.4636476090008061162142562314612144" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "-0.1" }, { "$numberDecimal": "-0.2" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-2.677945044588987122248387151818289" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "100" }, { "$numberDecimal": "-0.2" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.572796324128236352546369367576073" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDouble": "0.1" }, { "$numberDouble": "0.2" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDouble": "-0.1" }, { "$numberDouble": "-0.2" }] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.677945044588986967" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5, "b": 0.5}', '{"result": { "$atan2": ["$a", "$b"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5, "b": -0.5}', '{"result": { "$atan2": ["$a", "$b"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 10, "b": 10}', '{"result": { "$atan2": ["$a", "$b"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.785398163397448279" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -10, "b": -10}', '{"result": { "$atan2": ["$a", "$b"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.356194490192344837" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, null] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["$a", null] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, "$a"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, 50] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [50, 100] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.46364760900080609352" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, "$a"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN, returns NaN. NaN, null returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [10, NaN] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [NaN, 10] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, NaN] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "NaN"}, null] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, {"$numberDouble": "Infinity"}] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "Infinity"}, null] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, {"$numberDouble": "-Infinity"}] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "-Infinity"}, null] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["str", 1] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept string or int as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, "str"] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept int or string as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [true, 1] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept bool or int as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, true] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept int or bool as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [false, 1] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept bool or int as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, false] }}'); ERROR: $atan2 can operate solely on numeric types, and does not accept int or bool as valid inputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["$a", 1] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- Should error for wrong number of arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1, 1] }}'); ERROR: The expression $atan2 requires exactly 2 arguments, but 3 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1] }}'); ERROR: The expression $atan2 requires exactly 2 arguments, but 1 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [] }}'); ERROR: The expression $atan2 requires exactly 2 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1, 1] }}'); ERROR: The expression $atan2 requires exactly 2 arguments, but 3 arguments were actually provided. -- $asinh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.88137358701954304774" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.88137358701954304774" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.88137358694883238819" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.88137358694883238819" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "9.999999999999999999983333333333334E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-9.999999999999999999983333333333334E-11" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 10 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.9982229502979698132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -10 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.9982229502979698132" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 100 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5.2983423656105888" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -100 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-5.2983423656105888" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$divide": [1, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$multiply": [-0.5, 1] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$add": [10, 5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.4023066454805945824" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$subtract": [10, 15] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.3124383412727524956" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$asinh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$asinh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.48121182505960347076" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$asinh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.9982229502979698132" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -10}', '{"result": { "$asinh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-2.9982229502979698132" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "-Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-Infinity" } } (1 row) -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": "str"}}'); ERROR: $asinh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": ["str"]}}'); ERROR: $asinh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": true}}'); ERROR: $asinh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": false}}'); ERROR: $asinh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$asinh": [2, "$a"]}}'); ERROR: The expression $asinh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$asinh": ["$a", 5]}}'); ERROR: The expression $asinh requires exactly 1 arguments, but 2 arguments were actually provided. -- $acosh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 10 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.9932228461263807873" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 100 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "5.2982923656104841115" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$add": [10, 5] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "3.4000844141133397258" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 1.5}', '{"result": { "$acosh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.96242365011920694151" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$acosh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "2.9932228461263807873" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "Infinity"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "NaN"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error for values less than 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0 }}'); ERROR: Cannot use operator acosh on 0 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$subtract": [10, 15] }}}'); ERROR: Cannot use operator acosh on -5 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$numberDecimal": "1e-10" }}}'); ERROR: Cannot use operator acosh on 1E-10 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$numberDecimal": "-1e-10" }}}'); ERROR: Cannot use operator acosh on -1E-10 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0.5 }}'); ERROR: Cannot use operator acosh on 0.5 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -0.5 }}'); ERROR: Cannot use operator acosh on -0.5 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -1 }}'); ERROR: Cannot use operator acosh on -1 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -10 }}'); ERROR: Cannot use operator acosh on -10 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0.9999999999 }}'); ERROR: Cannot use operator acosh on 1 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -0.9999999999 }}'); ERROR: Cannot use operator acosh on -1 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$divide": [1, 2] }}}'); ERROR: Cannot use operator acosh on 0.5 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$multiply": [-0.5, 1] }}}'); ERROR: Cannot use operator acosh on -0.5 as the value must lie within the range [1, infinity] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "-Infinity"}}}'); ERROR: Cannot use operator acosh on -Infinity as the value must lie within the range [1, infinity] -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": "str"}}'); ERROR: $acosh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": ["str"]}}'); ERROR: $acosh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": true}}'); ERROR: $acosh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": false}}'); ERROR: $acosh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$acosh": [2, "$a"]}}'); ERROR: The expression $acosh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$acosh": ["$a", 5]}}'); ERROR: The expression $acosh requires exactly 1 arguments, but 2 arguments were actually provided. -- $atanh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.0" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -1 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-Infinity" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "11.859499013855018035" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -0.9999999999 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-11.859499013855018035" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$numberDecimal": "1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "1.000000000000000000003333333333333E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$numberDecimal": "-1e-10" }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDecimal" : "-1.000000000000000000003333333333333E-10" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54930614433405478003" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -0.5 }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.54930614433405478003" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$divide": [1, 2] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54930614433405478003" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$multiply": [-0.5, 1] }}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.54930614433405478003" } } (1 row) SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$atanh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "0.54930614433405478003" } } (1 row) SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$atanh": "$a" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "-0.54930614433405478003" } } (1 row) -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": NaN}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberDouble" : "NaN" } } (1 row) -- Should error for values outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": {"$numberDouble": "Infinity"}}}'); ERROR: Unable to use operator atanh on Infinity because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": {"$numberDouble": "-Infinity"}}}'); ERROR: Unable to use operator atanh on -Infinity because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 1.0000000001 }}'); ERROR: Unable to use operator atanh on 1 because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -1.0000000001 }}'); ERROR: Unable to use operator atanh on -1 because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 10 }}'); ERROR: Unable to use operator atanh on 10 because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -10 }}'); ERROR: Unable to use operator atanh on -10 because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 100 }}'); ERROR: Unable to use operator atanh on 100 because the value must be within the range [-1, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -100 }}'); ERROR: Unable to use operator atanh on -100 because the value must be within the range [-1, 1]. -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": "str"}}'); ERROR: $atanh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": ["str"]}}'); ERROR: $atanh works exclusively with numeric data types, not with string SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": true}}'); ERROR: $atanh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": false}}'); ERROR: $atanh works exclusively with numeric data types, not with bool SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$atanh": [2, "$a"]}}'); ERROR: The expression $atanh requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$atanh": ["$a", 5]}}'); ERROR: The expression $atanh requires exactly 1 arguments, but 2 arguments were actually provided. bson_aggregation_type_operators_tests.out000066400000000000000000003616061507310017400404310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6910000; SET documentdb.next_collection_id TO 69100; SET documentdb.next_collection_index_id TO 69100; -- $isNumber: return true for numbers false otherwise SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [["not null"]]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$add": [1, 2]}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [true]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [false]}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": "1"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberLong": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberDecimal": "1"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberDouble": "1.0"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $isNumber: returns null with null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": null}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": "$a"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : false } (1 row) -- $isNumber: error number of args should be 1 SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": []}}'); ERROR: The expression $isNumber requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [1, 2]}}'); ERROR: The expression $isNumber requires exactly 1 arguments, but 2 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [[], 2]}}'); ERROR: The expression $isNumber requires exactly 1 arguments, but 2 arguments were actually provided. -- $type: returns expected type SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "1", "value": {"$numberDouble": "1.0"}, "expected": "double"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "2", "value": "string", "expected": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "3", "value": {}, "expected": "object"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "4", "value": [], "expected": "array"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "5", "value": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}, "expected": "binData"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "6", "value": {"$oid" : "639926cee6bda3127f153bf1" }, "expected": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "7", "value": true, "expected": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "8", "value": {"$date": "2022-01-01T00:00:00.000Z"}, "expected": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "9", "value": null, "expected": "null"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "10", "value": { "$regex": "a.*b", "$options": "" }, "expected": "regex"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "11", "value": { "$code": "var a = 1;"}, "expected": "javascript"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "12", "value": 1, "expected": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "13", "value": {"$timestamp" : { "t": 1670981326, "i": 1 }}, "expected": "timestamp"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "14", "value": {"$numberLong" : "1"}, "expected": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "15", "value": {"$numberDecimal" : "1"}, "expected": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "16", "value": {"$minKey" : 1}, "expected": "minKey"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "17", "value": {"$maxKey" : 1}, "expected": "maxKey"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "18", "expected": "missing"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_project(document, '{"output": {"$type": "$value"}, "expected": 1}') FROM documentdb_api.collection('db', 'dollarType'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "expected" : "double", "output" : "double" } { "_id" : "2", "expected" : "string", "output" : "string" } { "_id" : "3", "expected" : "object", "output" : "object" } { "_id" : "4", "expected" : "array", "output" : "array" } { "_id" : "5", "expected" : "binData", "output" : "binData" } { "_id" : "6", "expected" : "objectId", "output" : "objectId" } { "_id" : "7", "expected" : "bool", "output" : "bool" } { "_id" : "8", "expected" : "date", "output" : "date" } { "_id" : "9", "expected" : "null", "output" : "null" } { "_id" : "10", "expected" : "regex", "output" : "regex" } { "_id" : "11", "expected" : "javascript", "output" : "javascript" } { "_id" : "12", "expected" : "int", "output" : "int" } { "_id" : "13", "expected" : "timestamp", "output" : "timestamp" } { "_id" : "14", "expected" : "long", "output" : "long" } { "_id" : "15", "expected" : "decimal", "output" : "decimal" } { "_id" : "16", "expected" : "minKey", "output" : "minKey" } { "_id" : "17", "expected" : "maxKey", "output" : "maxKey" } { "_id" : "18", "expected" : "missing", "output" : "missing" } (18 rows) -- $convert: returns expected values -- double value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "1", "value": {"$numberDouble": "1.3"}, "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "2", "value": {"$numberDouble": "1.3"}, "expected": "1.3", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "3", "value": {"$numberDouble": "1.3"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "4", "value": {"$numberDouble": "0.0"}, "expected": false, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "5", "value": {"$numberDouble": "-0.1"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "6", "value": {"$numberDouble": "1.3"}, "expected": {"$date": "1970-01-01T00:00:00.001Z"}, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "7", "value": {"$numberDouble": "1.3"}, "expected": 1, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "8", "value": {"$numberDouble": "1.3"}, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "9", "value": {"$numberDouble": "1.3"}, "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- str value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "10", "value": "myString", "expected": "myString", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "11", "value": "1.3", "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "12", "value": "1E-2", "expected": {"$numberDouble": "0.01"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "13", "value": "13423423E-25", "expected": {"$numberDouble": "1.3423423e-18"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "14", "value": "0000000.0000000", "expected": {"$numberDouble": "0.0"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "15", "value": "1.3", "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "16", "value": "1E-2", "expected": {"$numberDecimal": "0.01"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "17", "value": "-13423423E25", "expected": {"$numberDecimal": "-1.3423423E+32"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "18", "value": "000000.000000", "expected": {"$numberDecimal": "0.000000"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "19", "value": "-1232", "expected": {"$numberLong": "-1232"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "20", "value": "00053235", "expected": {"$numberLong": "53235"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "21", "value": "00053235", "expected": 53235, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "22", "value": "00000000000", "expected": 0, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "23", "value": "665a1c0f8a2b4f7cd317a2b4", "expected": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "24", "value": "", "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objectId value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "26", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "27", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": "665a1c0f8a2b4f7cd317a2b4", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "28", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "29", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": {"$date": "2024-05-31T18:50:55.000Z"}, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- bool value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "30", "value": false, "expected": {"$numberDouble": "0"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "31", "value": true, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "32", "value": false, "expected": {"$numberDecimal": "0"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "33", "value": true, "expected": {"$numberDecimal": "1"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "34", "value": false, "expected": {"$numberLong": "0"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "35", "value": true, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "36", "value": false, "expected": 0, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "37", "value": true, "expected": 1, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "38", "value": false, "expected": "false", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "39", "value": true, "expected": "true", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "40", "value": false, "expected": false, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "45", "value": true, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- date value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "46", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$date": "2024-05-31T18:50:55.000Z"}, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "47", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": "2024-05-31T18:50:55.000Z", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "48", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "49", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberLong": "1717181455000"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "50", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberDouble": "1717181455000"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "51", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberDecimal": "1717181455000"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- int value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "52", "value": 1, "expected": 1, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "53", "value": 1, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "54", "value": -11, "expected": {"$numberDouble": "-11"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "55", "value": 523453, "expected": {"$numberDecimal": "523453"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "56", "value": 523453, "expected": {"$numberLong": "523453"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "57", "value": 1, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "58", "value": 0, "expected": false, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "59", "value": 25, "expected": "25", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- long value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "61", "value": {"$numberLong": "1" }, "expected": {"$numberLong": "1" }, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "62", "value": {"$numberLong": "1" }, "expected": 1, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "63", "value": {"$numberLong": "1" }, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "64", "value": {"$numberLong": "-11" }, "expected": {"$numberDouble": "-11"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "65", "value": {"$numberLong": "523453" }, "expected": {"$numberDecimal": "523453"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "66", "value": {"$numberLong": "523453" }, "expected": {"$numberLong": "523453"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "67", "value": {"$numberLong": "1" }, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "68", "value": {"$numberLong": "0" }, "expected": false, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "69", "value": {"$numberLong": "25" }, "expected": "25", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "70", "value": {"$numberLong": "25" }, "expected": {"$date": "1970-01-01T00:00:00.025Z"}, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- decimal value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "71", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "72", "value": {"$numberDecimal": "1.3"}, "expected": "1.3", "convertTo": "string"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "73", "value": {"$numberDecimal": "1.3"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "74", "value": {"$numberDecimal": "0.0"}, "expected": false, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "75", "value": {"$numberDecimal": "-0.1"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "76", "value": {"$numberDecimal": "1.3"}, "expected": {"$date": "1970-01-01T00:00:00.001Z"}, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "77", "value": {"$numberDecimal": "1.3"}, "expected": 1, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "78", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "79", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- other supported types to bool SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "80", "value": {"$minKey": 1}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "81", "value": {"foo": 1}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "82", "value": ["foo", 1], "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "83", "value": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "84", "value": { "$regex": "a.*b", "$options": "" }, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "85", "value": { "$code": "var a = 1;"}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "86", "value": {"$maxKey": 1}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "87", "value": {"$timestamp" : { "t": 1670981326, "i": 1 }}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "88", "value": { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}, "expected": true, "convertTo": "bool"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- str to date is not yet supported, will be added with $dateFromString -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "89", "value": "2024-05-31", "expected": {"$date": "2024-05-31T00:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "90", "value": "2024-05-31T00:00:00.001Z", "expected": {"$date": "2024-05-31T00:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "91", "value": "2024-05-31T00:00:00.001+0500", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "92", "value": "2024-05-31 00:00:00.001 +0500", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "93", "value": "2024-05-31T00:00:00.001+5", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "94", "value": "2024-05-31T00:00:00.001+05", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "95", "value": "2024-05-31T00:00:00.001+050", "expected": {"$date": "1969-12-31T23:10:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "96", "value": "2024-05-31T00:00:00.001+0510", "expected": {"$date": "1969-12-31T18:50:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "97", "value": "2024-05-31T00:00:00.001+0501", "expected": {"$date": "1969-12-31T18:59:00.001Z"}, "convertTo": "date"}'); -- call convert with the value and convertTo and check if the output is equal to the expected output. SELECT bson_dollar_project(document, '{"result": { "$eq": [{"$convert": { "input": "$value", "to": "$convertTo"}}, "$expected"]}}') FROM documentdb_api.collection('db', 'convertColl'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } { "_id" : "2", "result" : true } { "_id" : "3", "result" : true } { "_id" : "4", "result" : true } { "_id" : "5", "result" : true } { "_id" : "6", "result" : true } { "_id" : "7", "result" : true } { "_id" : "8", "result" : true } { "_id" : "9", "result" : true } { "_id" : "10", "result" : true } { "_id" : "11", "result" : true } { "_id" : "12", "result" : true } { "_id" : "13", "result" : true } { "_id" : "14", "result" : true } { "_id" : "15", "result" : true } { "_id" : "16", "result" : true } { "_id" : "17", "result" : true } { "_id" : "18", "result" : true } { "_id" : "19", "result" : true } { "_id" : "20", "result" : true } { "_id" : "21", "result" : true } { "_id" : "22", "result" : true } { "_id" : "23", "result" : true } { "_id" : "24", "result" : true } { "_id" : "26", "result" : true } { "_id" : "27", "result" : true } { "_id" : "28", "result" : true } { "_id" : "29", "result" : true } { "_id" : "30", "result" : true } { "_id" : "31", "result" : true } { "_id" : "32", "result" : true } { "_id" : "33", "result" : true } { "_id" : "34", "result" : true } { "_id" : "35", "result" : true } { "_id" : "36", "result" : true } { "_id" : "37", "result" : true } { "_id" : "38", "result" : true } { "_id" : "39", "result" : true } { "_id" : "40", "result" : true } { "_id" : "45", "result" : true } { "_id" : "46", "result" : true } { "_id" : "47", "result" : true } { "_id" : "48", "result" : true } { "_id" : "49", "result" : true } { "_id" : "50", "result" : true } { "_id" : "51", "result" : true } { "_id" : "52", "result" : true } { "_id" : "53", "result" : true } { "_id" : "54", "result" : true } { "_id" : "55", "result" : true } { "_id" : "56", "result" : true } { "_id" : "57", "result" : true } { "_id" : "58", "result" : true } { "_id" : "59", "result" : true } { "_id" : "61", "result" : true } { "_id" : "62", "result" : true } { "_id" : "63", "result" : true } { "_id" : "64", "result" : true } { "_id" : "65", "result" : true } { "_id" : "66", "result" : true } { "_id" : "67", "result" : true } { "_id" : "68", "result" : true } { "_id" : "69", "result" : true } { "_id" : "70", "result" : true } { "_id" : "71", "result" : true } { "_id" : "72", "result" : true } { "_id" : "73", "result" : true } { "_id" : "74", "result" : true } { "_id" : "75", "result" : true } { "_id" : "76", "result" : true } { "_id" : "77", "result" : true } { "_id" : "78", "result" : true } { "_id" : "79", "result" : true } { "_id" : "80", "result" : true } { "_id" : "81", "result" : true } { "_id" : "82", "result" : true } { "_id" : "83", "result" : true } { "_id" : "84", "result" : true } { "_id" : "85", "result" : true } { "_id" : "86", "result" : true } { "_id" : "87", "result" : true } { "_id" : "88", "result" : true } (82 rows) -- $convert to BinData SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "SGVsbG8gd29ybGQh", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "RG9jdW1lbnREQiBpcyBjb29sbGwh", "to": {"type": "binData", "subtype": 8}, "format": "base64"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "RG9jdW1lbnREQiBpcyBjb29sbGwh", "subType" : "08" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "base64"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "SGVsbG8gd29ybGQh", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "RG9jdW1lbnREQiBpcyBjb29sbGwh", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "RG9jdW1lbnREQiBpcyBjb29sbGwh", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "UEdNb25nbyBpcyBHQSE", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "UEdNb25nbyBpcyBHQSE=", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "SGVsbG8gd29ybGQh", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "EAAAABAAEAAQABAAAAAAAA==", "subType" : "04" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "RR5FZ+ibQtOkVlVmQkQAAA==", "subType" : "04" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 0}, "format": "hex"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Sm9obiBEb2U=", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Sm9obiBEb2U=", "subType" : "05" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 6}, "format": "hex"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Sm9obiBEb2U=", "subType" : "06" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "a27", "to": {"type": "binData", "subtype": 0}, "format": "utf8"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "YTI3", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "UEdNb25nbyBpcyBHQSE=", "to": {"type": "binData"}, "format": "utf8"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "VUVkTmIyNW5ieUJwY3lCSFFTRT0=", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": {"$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Fn3uUsMxSE6S0cVkebjmcA==", "subType" : "04" } } } (1 row) SELECT * from bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": {"$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "base64"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "SGVsbG8gd29ybGQh", "subType" : "00" } } } (1 row) SELECT * from bson_dollar_project('{"tt": "binData", "f": "hex"}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "$tt", "subtype": 0}, "format": "$f"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Sm9obiBEb2U=", "subType" : "00" } } } (1 row) -- error: $convert to BinData with no format SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData"}}}'); ERROR: A specific format must be provided when attempting to convert from string into 'binData'. -- error: $convert to BinData with non-string input SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": 123, "to": "binData", "format": "base64"}}}'); ERROR: Unsupported conversion from int to binData in $convert with no onError value SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": false, "to": "binData", "format": "base64"}}}'); ERROR: Unsupported conversion from bool to binData in $convert with no onError value -- error: uuid format and uuid subtype violations SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 4}, "format": "base64"}}}'); ERROR: Unable to interpret BinData 'SGVsbG8gd29ybGQh' during $convert operation due to missing onError parameter: Only the UUID subtype (4) is allowed with the 'uuid' format SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData"}, "format": "uuid"}}}'); ERROR: Unable to interpret BinData '451e4567-e89b-42d3-a456-556642440000' during $convert operation due to missing onError parameter: Only the UUID subtype (4) is allowed with the 'uuid' format -- error: $convert to BinData with input-format mismatch SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "123", "to": "binData", "format": "base64"}}}'); ERROR: Unable to interpret BinData '123' during $convert operation due to missing onError parameter: The provided input does not represent a valid base64-encoded string. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3uUsMxSE6S0cVkebjm=fg==", "to": {"type": "binData", "subtype": 4}, "format": "base64"}}}'); ERROR: Unable to interpret BinData 'hn3uUsMxSE6S0cVkebjm=fg==' during $convert operation due to missing onError parameter: Only the UUID subtype (4) is allowed with the 'uuid' format SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 0}, "format": "base64"}}}'); ERROR: Unable to interpret BinData '451e4567-e89b-42d3-a456-556642440000' during $convert operation due to missing onError parameter: The provided input does not represent a valid base64-encoded string. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3u+UsMxSE6S0cVkebjmfg==", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); ERROR: Unable to interpret BinData 'hn3u+UsMxSE6S0cVkebjmfg==' during $convert operation due to missing onError parameter: The provided input does not represent a valid base64-encoded string. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3u+UsMxSE6S0cVkebjm/fg==", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); ERROR: Unable to interpret BinData 'hn3u+UsMxSE6S0cVkebjm/fg==' during $convert operation due to missing onError parameter: The provided input does not represent a valid base64-encoded string. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "äöäöä", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); ERROR: Unable to interpret BinData 'äöäöä' during $convert operation due to missing onError parameter: The provided input does not represent a properly formatted UUID string %s. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); ERROR: Unable to interpret BinData 'SGVsbG8gd29ybGQh' during $convert operation due to missing onError parameter: The provided input does not represent a properly formatted UUID string %s. SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 4}, "format": "hex"}}}'); ERROR: Unable to interpret BinData '451e4567-e89b-42d3-a456-556642440000' during $convert operation due to missing onError parameter: Only the UUID subtype (4) is allowed with the 'uuid' format -- error: auto format not supported for to BinData SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "auto"}}}'); ERROR: Format 'auto' is not supported for string to 'binData' conversion -- error: auto format not supported for BinData to string yet SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex" } }, "to": "string", "format": "auto" } }}'); ERROR: Convert to string from binData with format 'auto' is not supported yet. -- BinData to string using $convert SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "base64" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "SGVsbG8gd29ybGQh" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "utf8" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "Hello world!" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "💻🤠🔫", "to": "binData", "format": "utf8" } }, "to": "string", "format": "utf8" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "💻🤠🔫" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "base64url" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "SGVsbG8gd29ybGQh" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "167dee52-c331-484e-92d1-c56479b8e670", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "167dee52-c331-484e-92d1-c56479b8e670" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "hex" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "48656C6C6F20776F726C6421" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "10000000-1000-1000-1000-100000000000" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": "binData", "format": "hex" } }, "to": "string", "format": "hex" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "4A6F686E20446F65" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex" } }, "to": "string", "format": "hex" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "4A6F686E20446F65" } (1 row) SELECT * FROM bson_dollar_project('{"i": "a27", "tt": "binData", "f": "hex"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "$tt", "subtype": 0}, "format": "$f" } }, "to": "string", "format": "$f" } }}'); ERROR: invalid hexadecimal data: odd number of digits SELECT * FROM bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "167dee52-c331-484e-92d1-c56479b8e670" } (1 row) -- $convert from BinData to BinData SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": {"type": "binData", "subtype": 4} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "SGVsbG8gd29ybGQh", "subType" : "04" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "💻🤠🔫", "to": "binData", "format": "utf8" } }, "to": {"type": "binData", "subtype": 0} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "8J+Su/CfpKDwn5Sr", "subType" : "00" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 0} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "EAAAABAAEAAQABAAAAAAAA==", "subType" : "00" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 4} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "EAAAABAAEAAQABAAAAAAAA==", "subType" : "04" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": "binData", "format": "hex" } }, "to": {"type": "binData", "subtype": 130} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Sm9obiBEb2U=", "subType" : "82" } } } (1 row) SELECT * FROM bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "utf8" } }, "to": {"type": "binData", "subtype": "$ts"} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "U0dWc2JHOGdkMjl5YkdRaA==", "subType" : "00" } } } (1 row) SELECT * FROM bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 4} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Fn3uUsMxSE6S0cVkebjmcA==", "subType" : "04" } } } (1 row) SELECT * FROM bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "utf8" } }, "to": {"type": "binData", "subtype": 0} } }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "U0dWc2JHOGdkMjl5YkdRaA==", "subType" : "00" } } } (1 row) -- $convert with null to type should return null with and without onNull SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": null}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": "$missingField"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": null, "onNull": "Input was null"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": "$missingField", "onNull": "Input was null"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) -- $convert with null input should return null without onNull and onNull expression if specified even if 'to' is null SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": "string"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": "bool"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": null, "onNull": "Input was null"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "Input was null" } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": null, "onNull": "Input was null"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : "Input was null" } (1 row) -- $convert with null and undefined/missing onNull should return empty SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": null, "onNull": "$onNullField"}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": null, "onNull": "$onNullField"}}}'); bson_dollar_project --------------------------------------------------------------------- { } (1 row) -- $convert with error outside of parsing should honor onError SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "1", "value": {"$numberDouble": "1.3"}, "convertTo": "objectId"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "2", "value": {"$numberDouble": "1.3"}, "convertTo": "array"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "3", "value": {"$numberDouble": "1.3"}, "convertTo": "object"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "4", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "double"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "5", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "6", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "long"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "7", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "decimal"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "8", "value": true, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "9", "value": false, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "10", "value": {"$date": "2024-05-31T00:00:00.000Z"}, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "11", "value": {"$date": "2024-05-31T00:00:00.000Z"}, "convertTo": "int"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "12", "value": 1, "convertTo": "date"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "13", "value": 1.3, "convertTo": "minKey"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "14", "value": 1.3, "convertTo": "missing"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "15", "value": 1.3, "convertTo": "object"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "16", "value": 1.3, "convertTo": "array"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "17", "value": 1.3, "convertTo": "binData"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "18", "value": 1.3, "convertTo": "undefined"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "19", "value": 1.3, "convertTo": "null"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "20", "value": 1.3, "convertTo": "regex"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "21", "value": 1.3, "convertTo": "dbPointer"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "22", "value": 1.3, "convertTo": "javascript"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "23", "value": 1.3, "convertTo": "symbol"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "24", "value": 1.3, "convertTo": "javascriptWithScope"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "25", "value": 1.3, "convertTo": "timestamp"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "26", "value": 1.3, "convertTo": "maxKey"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "27", "value": 1, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "28", "value": {"$numberLong": "1"}, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "29", "value": {"$numberDecimal": "1"}, "convertTo": "objectId"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_project(document, '{"output": {"$convert": { "input": "$value", "to": "$convertTo", "onError": "There was an error in $convert"}}}') FROM documentdb_api.collection('db', 'convertCollWithErrors'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "output" : "There was an error in $convert" } { "_id" : "2", "output" : "There was an error in $convert" } { "_id" : "3", "output" : "There was an error in $convert" } { "_id" : "4", "output" : "There was an error in $convert" } { "_id" : "5", "output" : "There was an error in $convert" } { "_id" : "6", "output" : "There was an error in $convert" } { "_id" : "7", "output" : "There was an error in $convert" } { "_id" : "8", "output" : "There was an error in $convert" } { "_id" : "9", "output" : "There was an error in $convert" } { "_id" : "10", "output" : "There was an error in $convert" } { "_id" : "11", "output" : "There was an error in $convert" } { "_id" : "12", "output" : "There was an error in $convert" } { "_id" : "13", "output" : "There was an error in $convert" } { "_id" : "14", "output" : "There was an error in $convert" } { "_id" : "15", "output" : "There was an error in $convert" } { "_id" : "16", "output" : "There was an error in $convert" } { "_id" : "17", "output" : "There was an error in $convert" } { "_id" : "18", "output" : "There was an error in $convert" } { "_id" : "19", "output" : "There was an error in $convert" } { "_id" : "20", "output" : "There was an error in $convert" } { "_id" : "21", "output" : "There was an error in $convert" } { "_id" : "22", "output" : "There was an error in $convert" } { "_id" : "23", "output" : "There was an error in $convert" } { "_id" : "24", "output" : "There was an error in $convert" } { "_id" : "25", "output" : "There was an error in $convert" } { "_id" : "26", "output" : "There was an error in $convert" } { "_id" : "27", "output" : "There was an error in $convert" } { "_id" : "28", "output" : "There was an error in $convert" } { "_id" : "29", "output" : "There was an error in $convert" } (29 rows) -- $convert undefined/missing field used for onError should return empty result SELECT bson_dollar_project(document, '{"output": {"$convert": { "input": "$value", "to": "$convertTo", "onError": "$missingField"}}}') FROM documentdb_api.collection('db', 'convertCollWithErrors'); bson_dollar_project --------------------------------------------------------------------- { "_id" : "1" } { "_id" : "2" } { "_id" : "3" } { "_id" : "4" } { "_id" : "5" } { "_id" : "6" } { "_id" : "7" } { "_id" : "8" } { "_id" : "9" } { "_id" : "10" } { "_id" : "11" } { "_id" : "12" } { "_id" : "13" } { "_id" : "14" } { "_id" : "15" } { "_id" : "16" } { "_id" : "17" } { "_id" : "18" } { "_id" : "19" } { "_id" : "20" } { "_id" : "21" } { "_id" : "22" } { "_id" : "23" } { "_id" : "24" } { "_id" : "25" } { "_id" : "26" } { "_id" : "27" } { "_id" : "28" } { "_id" : "29" } (29 rows) -- $convert errors in parsing should be honored even if onError is set SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": {"$divide": [1, 0]}, "to": "string", "onError": "There was an error in $convert"}}}'); ERROR: $divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": "$myField"}}'); ERROR: $convert requires an object containing named arguments, but instead received: string SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "onError": "There was an error"}}}'); ERROR: 'to' parameter is missing for $convert SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"to": 1, "onError": "There was an error"}}}'); ERROR: Missing 'input' parameter to $convert SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"myCustomInput": 1, "onError": "There was an error"}}}'); ERROR: $convert encountered an unrecognized argument: myCustomInput SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": "someType", "onError": "There was an error"}}}'); ERROR: Unrecognized data type alias: someType SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "1.1"}, "onError": "There was an error"}}}'); ERROR: In $convert, numeric 'to' argument is not an integer SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "255"}, "onError": "There was an error"}}}'); ERROR: During $convert, the numeric value provided for 'to' is not a valid BSON type: 255 SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "-2.0"}, "onError": "There was an error"}}}'); ERROR: During $convert, the numeric value provided for 'to' is not a valid BSON type: -2 SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": [], "onError": "There was an error"}}}'); ERROR: The 'to' parameter in $convert must contain either a string value or a numeric value, but it currently holds array -- $convert identifies the target types with numbers SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": -1}}}'); ERROR: Unsupported conversion from object to minKey in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 127}}}'); ERROR: Unsupported conversion from object to maxKey in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 0}}}'); ERROR: Unsupported conversion from object to missing in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 1}}}'); ERROR: Unsupported conversion from object to double in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 2}}}'); ERROR: Unsupported conversion from object to string in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 3}}}'); ERROR: Unsupported conversion from object to object in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 4}}}'); ERROR: Unsupported conversion from object to array in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 5}}}'); ERROR: Unsupported conversion from object to binData in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 6}}}'); ERROR: Unsupported conversion from object to undefined in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 7}}}'); ERROR: Unsupported conversion from object to objectId in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 8}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : true } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 9}}}'); ERROR: Unsupported conversion from object to date in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 10}}}'); ERROR: Unsupported conversion from object to null in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 11}}}'); ERROR: Unsupported conversion from object to regex in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 12}}}'); ERROR: Unsupported conversion from object to dbPointer in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 13}}}'); ERROR: Unsupported conversion from object to javascript in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 14}}}'); ERROR: Unsupported conversion from object to symbol in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 15}}}'); ERROR: Unsupported conversion from object to javascriptWithScope in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 16}}}'); ERROR: Unsupported conversion from object to int in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 17}}}'); ERROR: Unsupported conversion from object to timestamp in $convert with no onError value -- double max + 1 and min-1 range $convert, $toLong SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "9223372036854775296"}, "to": "long"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 9.22337E+18 SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "-9223372036854776833"}, "to": "long"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -9.22337E+18 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "9223372036854775296"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 9.22337E+18 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-9223372036854776833"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -9.22337E+18 -- min supported value for $convert, $toLong SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "-9223372036854776832"}, "to": "long"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-9223372036854775808" } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-9223372036854776832"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-9223372036854775808" } } (1 row) -- -- -- $to* alias tests. -- call the shorthand convert $to* aliases. WITH toQuery AS (SELECT bson_dollar_project( document, format( '{"expected": 1, "output": { "$%s": "$value" } }', CASE TRIM(BOTH '"' FROM document->>'convertTo') WHEN 'double' THEN 'toDouble' WHEN 'string' THEN 'toString' WHEN 'objectId' THEN 'toObjectId' WHEN 'bool' THEN 'toBool' WHEN 'date' THEN 'toDate' WHEN 'int' THEN 'toInt' WHEN 'long' THEN 'toLong' WHEN 'decimal' THEN 'toDecimal' ELSE 'toInvalid' -- fail for easier diagnostics END )::bson ) as outDoc FROM documentdb_api.collection('db', 'convertColl')) SELECT bson_dollar_project(outDoc, '{"result": {"$eq": ["$output", "$expected"]}}') FROM toQuery; bson_dollar_project --------------------------------------------------------------------- { "_id" : "1", "result" : true } { "_id" : "2", "result" : true } { "_id" : "3", "result" : true } { "_id" : "4", "result" : true } { "_id" : "5", "result" : true } { "_id" : "6", "result" : true } { "_id" : "7", "result" : true } { "_id" : "8", "result" : true } { "_id" : "9", "result" : true } { "_id" : "10", "result" : true } { "_id" : "11", "result" : true } { "_id" : "12", "result" : true } { "_id" : "13", "result" : true } { "_id" : "14", "result" : true } { "_id" : "15", "result" : true } { "_id" : "16", "result" : true } { "_id" : "17", "result" : true } { "_id" : "18", "result" : true } { "_id" : "19", "result" : true } { "_id" : "20", "result" : true } { "_id" : "21", "result" : true } { "_id" : "22", "result" : true } { "_id" : "23", "result" : true } { "_id" : "24", "result" : true } { "_id" : "26", "result" : true } { "_id" : "27", "result" : true } { "_id" : "28", "result" : true } { "_id" : "29", "result" : true } { "_id" : "30", "result" : true } { "_id" : "31", "result" : true } { "_id" : "32", "result" : true } { "_id" : "33", "result" : true } { "_id" : "34", "result" : true } { "_id" : "35", "result" : true } { "_id" : "36", "result" : true } { "_id" : "37", "result" : true } { "_id" : "38", "result" : true } { "_id" : "39", "result" : true } { "_id" : "40", "result" : true } { "_id" : "45", "result" : true } { "_id" : "46", "result" : true } { "_id" : "47", "result" : true } { "_id" : "48", "result" : true } { "_id" : "49", "result" : true } { "_id" : "50", "result" : true } { "_id" : "51", "result" : true } { "_id" : "52", "result" : true } { "_id" : "53", "result" : true } { "_id" : "54", "result" : true } { "_id" : "55", "result" : true } { "_id" : "56", "result" : true } { "_id" : "57", "result" : true } { "_id" : "58", "result" : true } { "_id" : "59", "result" : true } { "_id" : "61", "result" : true } { "_id" : "62", "result" : true } { "_id" : "63", "result" : true } { "_id" : "64", "result" : true } { "_id" : "65", "result" : true } { "_id" : "66", "result" : true } { "_id" : "67", "result" : true } { "_id" : "68", "result" : true } { "_id" : "69", "result" : true } { "_id" : "70", "result" : true } { "_id" : "71", "result" : true } { "_id" : "72", "result" : true } { "_id" : "73", "result" : true } { "_id" : "74", "result" : true } { "_id" : "75", "result" : true } { "_id" : "76", "result" : true } { "_id" : "77", "result" : true } { "_id" : "78", "result" : true } { "_id" : "79", "result" : true } { "_id" : "80", "result" : true } { "_id" : "81", "result" : true } { "_id" : "82", "result" : true } { "_id" : "83", "result" : true } { "_id" : "84", "result" : true } { "_id" : "85", "result" : true } { "_id" : "86", "result" : true } { "_id" : "87", "result" : true } { "_id" : "88", "result" : true } (82 rows) -- $toObjectId negative tests -- only supports 24 char hex string, objectId, null/undefined, and requires exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": {"input": ""}}}'); ERROR: Unsupported conversion from object to objectId in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": []}}'); ERROR: The expression $toObjectId requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "this is a string"}}'); ERROR: Failed to parse objectId 'this is a string' in $convert with no onError value: Invalid string length for parsing to OID, expected 24 but found 16 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "asdsfsdzzzzsersdfrtghtsz"}}'); ERROR: Failed to parse objectId 'asdsfsdzzzzsersdfrtghtsz' in $convert with no onError value: Invalid character found in hex string: 's' SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "639926cee6bda3127f153bfZ"}}'); ERROR: Failed to parse objectId '639926cee6bda3127f153bfZ' in $convert with no onError value: Invalid character found in hex string: 'Z' -- $toInt negative tests -- only supports numeric, bool or string and must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"input": ""}}}'); ERROR: Unsupported conversion from object to int in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": []}}'); ERROR: The expression $toInt requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": [{"$date": "2022-01-01T00:00:00.000Z"}]}}'); ERROR: Unsupported conversion from date to int in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "2147483648"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 2.14748E+09 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "-Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "NaN"}}}'); ERROR: Attempt to convert NaN value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "-Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "NaN"}}}'); ERROR: Attempt to convert NaN value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "-2147483649"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -2147483649 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberLong": "-2147483649"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -2147483649 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "-2147483649" }}'); ERROR: Unable to interpret number '-2147483649' within $convert, as no onError value was specified: Overflow SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "2147483648" }}'); ERROR: Unable to interpret number '2147483648' within $convert, as no onError value was specified: Overflow SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "This contains a number: 324423" }}'); ERROR: Unable to interpret number 'This contains a number: 324423' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": " 324423" }}'); ERROR: Unable to interpret number ' 324423' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "324423 " }}'); ERROR: Unable to interpret number '324423 ' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "0x01" }}'); ERROR: Invalid hexadecimal input detected in $convert without a specified onError handler: 0x01 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "" }}'); ERROR: Unable to interpret number '' within $convert, as no onError value was specified: No digits -- $toLong negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"input": ""}}}'); ERROR: Unsupported conversion from object to long in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": []}}'); ERROR: The expression $toLong requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "9223372036854775808"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 9.22337E+18 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "NaN"}}}'); ERROR: Attempt to convert NaN value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "-Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "Infinity"}}}'); ERROR: Attempt to convert infinity value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "NaN"}}}'); ERROR: Attempt to convert NaN value to integer type in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "-9223372036854775809"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -9223372036854775809 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "-9223372036854775809" }}'); ERROR: Unable to interpret number '-9223372036854775809' within $convert, as no onError value was specified: Overflow SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "9223372036854775808" }}'); ERROR: Unable to interpret number '9223372036854775808' within $convert, as no onError value was specified: Overflow SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "This contains a number: 324423" }}'); ERROR: Unable to interpret number 'This contains a number: 324423' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": " 324423" }}'); ERROR: Unable to interpret number ' 324423' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "324423 " }}'); ERROR: Unable to interpret number '324423 ' within $convert, as no onError value was specified: Failed to process the entire string. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "0x01" }}'); ERROR: Invalid hexadecimal input detected in $convert without a specified onError handler: 0x01 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "" }}'); ERROR: Unable to interpret number '' within $convert, as no onError value was specified: No digits -- $toDouble negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"input": ""}}}'); ERROR: Unsupported conversion from object to double in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": []}}'); ERROR: The expression $toDouble requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"$numberDecimal": "1.8E309"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 1.8E+309 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"$numberDecimal": "-1.8E309"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -1.8E+309 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "1.8E309" }}'); ERROR: Unable to interpret number '1.8E309' within $convert, as no onError value was specified: Value exceeds allowed range SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "-1.8E309" }}'); ERROR: Unable to interpret number '-1.8E309' within $convert, as no onError value was specified: Value exceeds allowed range SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "This contains a number: 324423.23" }}'); ERROR: Unable to interpret number 'This contains a number: 324423.23' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": " 324423.0" }}'); ERROR: Unable to interpret number ' 324423.0' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "324423.00001 " }}'); ERROR: Unable to interpret number '324423.00001 ' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "0x01" }}'); ERROR: Invalid hexadecimal input detected in $convert without a specified onError handler: 0x01 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "" }}'); ERROR: Unable to interpret number '' within $convert, as no onError value was specified: Empty string -- $toDecimal negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": {"input": ""}}}'); ERROR: Unsupported conversion from object to decimal in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": []}}'); ERROR: The expression $toDecimal requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "123423.8E6145" }}'); ERROR: Unable to interpret number '123423.8E6145' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "-123423.8E6145" }}'); ERROR: Unable to interpret number '-123423.8E6145' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "This contains a number: 324423.23" }}'); ERROR: Unable to interpret number 'This contains a number: 324423.23' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": " 324423.0" }}'); ERROR: Unable to interpret number ' 324423.0' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "324423.00001 " }}'); ERROR: Unable to interpret number '324423.00001 ' within $convert, as no onError value was specified: Unable to convert the provided string into a valid decimal format SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "0x01" }}'); ERROR: Invalid hexadecimal input detected in $convert without a specified onError handler: 0x01 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "" }}'); ERROR: Unable to interpret number '' within $convert, as no onError value was specified: Empty string -- $toString negative tests -- only support numeric, date, bool, string, objectId. Takes exactly 1 argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": {"input": ""}}}'); ERROR: Unsupported conversion from object to string in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": []}}'); ERROR: The expression $toString requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": {"$timestamp" : { "t": 1670981326, "i": 1 }}}}'); ERROR: Unsupported conversion from timestamp to string in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": [[]]}}'); ERROR: Unsupported conversion from array to string in $convert with no onError value -- $toDate negative tests -- Currently double, decimal128, long, objectId, timestamp, date and string are supported. -- Numeric, will be added to the Unix epoch 0 and shouldn't exceed int64 limits. Takes exactly 1 argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"input": ""}}}'); ERROR: Unsupported conversion from object to date in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": []}}'); ERROR: The expression $toDate requires exactly 1 arguments, but 0 arguments were actually provided. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": [[]]}}'); ERROR: Unsupported conversion from array to date in $convert with no onError value SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDouble": "9223372036854775808"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 9.22337E+18 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDecimal": "9223372036854775808"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: 9223372036854775808 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDecimal": "-9223372036854775809"}}}'); ERROR: Conversion would overflow target type in $convert with no onError value: -9223372036854775809 SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDouble": "-9223372036854775809"}}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "-9223372036854775808" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": 1}}'); ERROR: Unsupported conversion from int to date in $convert with no onError value -- $toDate test for string case SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2022-01-01T00:00:00.000Z"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1641024000000" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2022-01-01 00:00:00.000"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1641024000000" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2018-03-20T12:00:00+0500"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1521554400000" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2018-03-20"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1521529200000" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2017-Jul-04 noon"}}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$date" : { "$numberLong" : "1499194800000" } } } (1 row) -- $$toHashedIndexKey tests --test int select *from bson_dollar_project('{"tests": 3}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-4918719581749358852" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 3 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-4918719581749358852" } } (1 row) --test double select *from bson_dollar_project('{"tests": 3.1}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4843356556253255961" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 3.1 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4843356556253255961" } } (1 row) --test string select *from bson_dollar_project('{"tests": "abc"}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-6969118462091671691" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": "abc" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-6969118462091671691" } } (1 row) --test int64 select *from bson_dollar_project('{"tests": 123456789012345678}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1821714458417502614" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 123456789012345678 } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1821714458417502614" } } (1 row) --test array select *from bson_dollar_project('{"tests": [1, 2, 3.1]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "9190027316038958342" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [1, 2, 3.1] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "9190027316038958342" } } (1 row) --test nested array select *from bson_dollar_project('{"tests": [1, 2, 3.1,[4, 5], 6]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-5553235042546732581" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [1, 2, 3.1,[4, 5], 6] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-5553235042546732581" } } (1 row) --test nested object select *from bson_dollar_project('{"tests": [{"$numberDecimal": "1.2"},3]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-893570203633809211" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [{"$numberDecimal": "1.2"},3] } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-893570203633809211" } } (1 row) --test null select *from bson_dollar_project('{"tests": null}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-4514028574017177401" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": null } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-4514028574017177401" } } (1 row) --test NaN select *from bson_dollar_project('{"tests": {"$numberDouble": "NaN"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-2341399240614902273" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "NaN"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-2341399240614902273" } } (1 row) --test Infinity select *from bson_dollar_project('{"tests": {"$numberDouble": "Infinity"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-3715419061678165155" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "Infinity"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "-3715419061678165155" } } (1 row) --test -Infinity select *from bson_dollar_project('{"tests": {"$numberDouble": "-Infinity"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "8076669524792135709" } } (1 row) select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "-Infinity"} } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "8076669524792135709" } } (1 row) --test path select *from bson_dollar_project('{"tests": {"test" : 5}}', '{"result": { "$toHashedIndexKey": "$tests.test" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "1786987034919379147" } } (1 row) select *from bson_dollar_project('{"tests": 3}', '{"result": { "$toHashedIndexKey": "$test" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4154612158245552303" } } (1 row) select *from bson_dollar_project('{"tests": {"test" : 5}}', '{"result": { "$toHashedIndexKey": "$tests.tes" } }'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$numberLong" : "4154612158245552303" } } (1 row) -- $toUUID tests -- equivalent $convert query should be tested after extended $convert syntax is supported -- positive tests SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": null }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : null } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": "123e4567-e89b-12d3-a456-426614174000" }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Ej5FZ+ibEtOkVkJmFBdAAA==", "subType" : "04" } } } (1 row) SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": ["123e4567-e89b-12d3-a456-426614174000"] }}'); bson_dollar_project --------------------------------------------------------------------- { "result" : { "$binary" : { "base64" : "Ej5FZ+ibEtOkVkJmFBdAAA==", "subType" : "04" } } } (1 row) -- negative tests -- invalid string SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": "invalid-uuid-1234" }}'); ERROR: The provided UUID string 'invalid-uuid-1234' is not valid -- invalid type SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": 1234 }}'); ERROR: Unsupported conversion from int to binData in $convert with no onError value -- invalid count number of array input SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": ["123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174000"] }}'); ERROR: The expression $toUUID requires exactly 1 arguments, but 2 arguments were actually provided. bson_base_aggregates_tests_runtime.out000066400000000000000000000711301507310017400376370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 61000; SET documentdb.next_collection_id TO 6100; SET documentdb.next_collection_index_id TO 6100; -- insert basic numeric data. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"1", "i32": { "$numberInt" : "11" }, "i64": { "$numberLong" : "11" }, "idbl": { "$numberDouble" : "11.0" }}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"2", "i32": { "$numberInt" : "-2" }, "i64": { "$numberLong" : "-2" }, "idbl": { "$numberDouble" : "-2.0" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"3", "i32": { "$numberInt" : "20" }, "i64": { "$numberLong" : "20" }, "idbl": { "$numberDouble" : "20" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Compute sum/Avg; they should be in the respective types. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } | { "" : { "$numberLong" : "29" } } | { "" : { "$numberDouble" : "29.0" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "9.6666666666666660745" } } | { "" : { "$numberDouble" : "9.6666666666666660745" } } | { "" : { "$numberDouble" : "9.6666666666666660745" } } (1 row) -- Now add some values that are non numeric. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"4", "i32": "stringValue", "i64": "stringValue", "idbl": "stringValue"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"5", "i32": true, "i64": false, "idbl": true}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"6", "i32": [1, 2, 3], "i64": [4, 5, 6], "idbl": [7, 8, 9]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Compute sum and average for filters that result in 0 rows. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } | { "" : { "$numberInt" : "0" } } | { "" : { "$numberInt" : "0" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : null } | { "" : null } | { "" : null } (1 row) SELECT BSONSUM(document), BSONAVERAGE(document) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; bsonsum | bsonaverage --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } | { "" : null } (1 row) -- Compute sum/Avg; They should be the same since non-numeric values do not impact the sum/avg. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } | { "" : { "$numberLong" : "29" } } | { "" : { "$numberDouble" : "29.0" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "9.6666666666666660745" } } | { "" : { "$numberDouble" : "9.6666666666666660745" } } | { "" : { "$numberDouble" : "9.6666666666666660745" } } (1 row) SELECT BSONSUM(document), BSONAVERAGE(document) FROM documentdb_api.collection('db', 'testAggregates'); ERROR: invalid input BSON: Should have only 1 entry in the bson document -- Now add values that cause int32/int64 to roll over to the next highest type (mixed type sum) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"7", "i32": { "$numberInt" : "2147483645" }, "i64": { "$numberLong" : "9223372036854775801" }, "idbl": { "$numberDouble" : "1e20" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- sum/Avg should now move to the next available type SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberLong" : "2147483674" } } | { "" : { "$numberDouble" : "9223372036854775808.0" } } | { "" : { "$numberDouble" : "1e+20" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "536870918.5" } } | { "" : { "$numberDouble" : "2305843009213693952.0" } } | { "" : { "$numberDouble" : "25000000000000000000.0" } } (1 row) -- Now add a field that only exists in i32 - for i64/dbl it won't be there and it'll be a double field to test upgrade when the value type changes. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"8", "i32": { "$numberDouble" : "31.6" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- sum/Avg They all should be dbl and partial data should be ignored for i64/idbl SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberDouble" : "2147483705.5999999046" } } | { "" : { "$numberDouble" : "9223372036854775808.0" } } | { "" : { "$numberDouble" : "1e+20" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "429496741.12000000477" } } | { "" : { "$numberDouble" : "2305843009213693952.0" } } | { "" : { "$numberDouble" : "25000000000000000000.0" } } (1 row) -- Query non existent field. SELECT BSONSUM(document -> 'nao existe'), BSONAVERAGE(document -> 'nao existe') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonaverage --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } | { "" : null } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"9", "a" : { "b" : 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"10", "a" : { "b" : 2 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"11", "a" : { "b" : [ 0, 1, 2 ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"12", "a" : [ { "b" : 1 }, { "b" : 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"13", "a" : [ { "b" : 0 }, { "b" : 1 }, { "b" : 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"14", "a" : [ { "b" : 0 }, { "b" : 1 }, { "b" : 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"15", "a" : [ { "b" : [ -1, 1, 2 ] }, { "b" : [ 0, 1, 2 ] }, { "b" : [ 0, 1, 7 ] } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"16", "a" : [ { "b" : 9 } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONMAX(bson_expression_get(document, '{ "": "$a.b" }')) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @? '{ "a.b": 1}'; bsonmax --------------------------------------------------------------------- { "" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } (1 row) SELECT BSONMIN(bson_expression_get(document, '{ "": "$a.b" }')) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @? '{ "a.b": 1}'; bsonmin --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } (1 row) -- Rebuild bson objects from aggregates SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); bson_repath_and_build --------------------------------------------------------------------- { "max" : true, "sum" : { "$numberDouble" : "2147483705.5999999046" }, "average" : { "$numberDouble" : "429496741.12000000477" } } (1 row) -- Null values in aggregates SELECT BSONMAX(document-> 'nao existe') FROM documentdb_api.collection('db', 'testAggregates'); bsonmax --------------------------------------------------------------------- { "" : null } (1 row) SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'nao existe'), 'sum'::text, BSONSUM(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); bson_repath_and_build --------------------------------------------------------------------- { "max" : null, "sum" : { "$numberDouble" : "2147483705.5999999046" } } (1 row) -- Rebuild with prepared statement PREPARE q1 (text, text, text) AS SELECT bson_repath_and_build($1, BSONMAX(document-> 'i32'), $2, BSONSUM(document-> 'i32'), $3, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); EXECUTE q1 ('max', 'sum', 'average'); bson_repath_and_build --------------------------------------------------------------------- { "max" : true, "sum" : { "$numberDouble" : "2147483705.5999999046" }, "average" : { "$numberDouble" : "429496741.12000000477" } } (1 row) -- Invalid rebuild arguments SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); bson_repath_and_build --------------------------------------------------------------------- { "max" : true, "sum" : { "$numberDouble" : "2147483705.5999999046" }, "average" : { "$numberDouble" : "429496741.12000000477" } } (1 row) SELECT bson_repath_and_build(BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); ERROR: argument list must have an even number of elements DETAIL: The arguments of bson_repath_and_build() must consist of alternating keys and values. SELECT bson_repath_and_build('max'::text, 'max2', BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); ERROR: argument list must have an even number of elements DETAIL: The arguments of bson_repath_and_build() must consist of alternating keys and values. SELECT bson_repath_and_build(BSONMAX(document-> 'i32'), 'max'::text, 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); ERROR: Invalid type: expected a text type field, but received bson instead -- Shard the collection SELECT documentdb_api.shard_collection('db', 'testAggregates', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- Try basic aggregates when sharded SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberDouble" : "2147483705.5999999046" } } | { "" : { "$numberDouble" : "9223372036854775808.0" } } | { "" : { "$numberDouble" : "1e+20" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "429496741.12000000477" } } | { "" : { "$numberDouble" : "2305843009213693952.0" } } | { "" : { "$numberDouble" : "25000000000000000000.0" } } (1 row) SELECT BSONMIN(document-> 'i32'), BSONMIN(document-> 'i64'), BSONMIN(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonmin | bsonmin | bsonmin --------------------------------------------------------------------- { "" : { "$numberInt" : "-2" } } | { "" : { "$numberLong" : "-2" } } | { "" : { "$numberDouble" : "-2.0" } } (1 row) SELECT BSONMAX(document-> 'i32'), BSONMAX(document-> 'i64'), BSONMAX(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonmax | bsonmax | bsonmax --------------------------------------------------------------------- { "" : true } | { "" : false } | { "" : true } (1 row) -- shard on a path that not all documents have: SELECT documentdb_api.shard_collection('db', 'testAggregates', '{"_id":"hashed"}', false); NOTICE: Skipping Sharding for collection db.testAggregates as the same options were passed in. shard_collection --------------------------------------------------------------------- (1 row) SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonsum | bsonsum | bsonsum --------------------------------------------------------------------- { "" : { "$numberDouble" : "2147483705.5999999046" } } | { "" : { "$numberDouble" : "9223372036854775808.0" } } | { "" : { "$numberDouble" : "1e+20" } } (1 row) SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonaverage | bsonaverage | bsonaverage --------------------------------------------------------------------- { "" : { "$numberDouble" : "429496741.12000000477" } } | { "" : { "$numberDouble" : "2305843009213693952.0" } } | { "" : { "$numberDouble" : "25000000000000000000.0" } } (1 row) SELECT BSONMIN(document-> 'i32'), BSONMIN(document-> 'i64'), BSONMIN(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonmin | bsonmin | bsonmin --------------------------------------------------------------------- { "" : { "$numberInt" : "-2" } } | { "" : { "$numberLong" : "-2" } } | { "" : { "$numberDouble" : "-2.0" } } (1 row) SELECT BSONMAX(document-> 'i32'), BSONMAX(document-> 'i64'), BSONMAX(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); bsonmax | bsonmax | bsonmax --------------------------------------------------------------------- { "" : true } | { "" : false } | { "" : true } (1 row) -- validation from field_name_validation.js SELECT documentdb_api.insert_one('db', 'testAggregates', '{ "_id": { "a": 1, "b": 2 }, "c.d": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONSUM(bson_expression_get(document, '{ "": "$c.d" }')) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "0" } } (2 rows) SELECT BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }')) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "2" } } (2 rows) SELECT bson_repath_and_build('e.f'::text, BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }'))) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); bson_repath_and_build --------------------------------------------------------------------- { "e.f" : { "$numberInt" : "0" } } { "e.f" : { "$numberInt" : "2" } } (2 rows) SELECT bson_repath_and_build('$e'::text, BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }'))) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); ERROR: Cannot use $e as a field name. Dollar prefixed paths are not allowed. SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 1, "a": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 2, "a": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 3, "a": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 4, "a": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 5, "a": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- simulate a count BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } (1 row) ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_6101_61027 collection Recheck Cond: (shard_key_value = '6101'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6101'::bigint) (10 rows) ROLLBACK; -- create an index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('testAggregatesWithIndex', 'idx_1', '{ "a": 1 }'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- repeat BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } (1 row) ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Index Only Scan using _id_ on documents_6101_61027 collection Index Cond: (shard_key_value = '6101'::bigint) (8 rows) ROLLBACK; -- now shard the collection. SELECT documentdb_api.shard_collection('db', 'testAggregatesWithIndex', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- repeat BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); bsonsum --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } (1 row) ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); QUERY PLAN --------------------------------------------------------------------- Aggregate -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Index Only Scan using _id_ on documents_6101_61040 documents_6101 (8 rows) ROLLBACK; bson_base_operators.out000066400000000000000000000204271507310017400345620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 4700000; SET documentdb.next_collection_id TO 4700; SET documentdb.next_collection_index_id TO 4700; SELECT '{"a":1,"b":"c"}'::bson->'a'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } (1 row) SELECT '{"a":1,"b":"c"}'::bson->'b'; ?column? --------------------------------------------------------------------- { "" : "c" } (1 row) SELECT '{"a":1,"b":["c"]}'::bson->'b'; ?column? --------------------------------------------------------------------- { "" : [ "c" ] } (1 row) SELECT '{"a":1,"b":{"c":3}}'::bson->'b'; ?column? --------------------------------------------------------------------- { "" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT '{"a":1,"b":"c"}'::bson->'c' IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT '{"a":1,"b":"c"}'::bson->NULL IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_get_value('{"a":1,"b":"c"}', 'a'); bson_get_value --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } (1 row) SELECT bson_get_value('{"a":1,"b":"c"}', 'b'); bson_get_value --------------------------------------------------------------------- { "" : "c" } (1 row) SELECT bson_get_value('{"a":1,"b":["c"]}', 'b'); bson_get_value --------------------------------------------------------------------- { "" : [ "c" ] } (1 row) SELECT bson_get_value('{"a":1,"b":{"c":3}}', 'b'); bson_get_value --------------------------------------------------------------------- { "" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT bson_get_value('{"a":1,"b":"c"}', 'c') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_get_value('{"a":1,"b":"c"}', NULL) IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT * FROM bson_object_keys('{"a":1,"b":2}'); bson_object_keys --------------------------------------------------------------------- a b (2 rows) SELECT * FROM bson_object_keys('{"b":1,"a":2}'); bson_object_keys --------------------------------------------------------------------- b a (2 rows) SELECT * FROM bson_object_keys('{"b":1,"b":2}'); bson_object_keys --------------------------------------------------------------------- b b (2 rows) SELECT * FROM bson_object_keys(NULL); bson_object_keys --------------------------------------------------------------------- (0 rows) SELECT '{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- 10 (1 row) SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::int; int4 --------------------------------------------------------------------- 10 (1 row) SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::int8; int8 --------------------------------------------------------------------- 10 (1 row) SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 10 (1 row) SELECT '{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::int; int4 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::int8; int8 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 11 (1 row) SELECT '{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- 11.12 (1 row) SELECT ('{ "a": { "$numberDouble": "11" }, "b" : "c" }'::bson->>'a')::int; int4 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::int; ERROR: invalid input syntax for type integer: "11.12" SELECT ('{ "a": { "$numberDouble": "11" }, "b" : "c" }'::bson->>'a')::int8; int8 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::int8; ERROR: invalid input syntax for type bigint: "11.12" SELECT ('{ "a": { "$numberDouble": "1.23e100" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 1.23e+100 (1 row) SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 11.12 (1 row) SELECT '{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- 11.12 (1 row) SELECT ('{ "a": { "$numberDecimal": "11" }, "b" : "c" }'::bson->>'a')::int; int4 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::int; ERROR: invalid input syntax for type integer: "11.12" SELECT ('{ "a": { "$numberDecimal": "11" }, "b" : "c" }'::bson->>'a')::int8; int8 --------------------------------------------------------------------- 11 (1 row) SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::int8; ERROR: invalid input syntax for type bigint: "11.12" SELECT ('{ "a": { "$numberDecimal": "1.23e100" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 1.23e+100 (1 row) SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::float; float8 --------------------------------------------------------------------- 11.12 (1 row) SELECT ('{ "a": { "$numberDecimal": "1123123e2000" }, "b" : "c" }'::bson->>'a')::float; ERROR: "1.123123E+2006" is out of range for type double precision SELECT '{ "a": true, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- true (1 row) SELECT '{ "a": false, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- false (1 row) SELECT ('{ "a": true, "b" : "c" }'::bson->>'a')::boolean; bool --------------------------------------------------------------------- t (1 row) SELECT ('{ "a": false, "b" : "c" }'::bson->>'a')::boolean; bool --------------------------------------------------------------------- f (1 row) -- other types other than string are returned as an object when used with ->> SELECT '{ "a": {"$oid": "62e034e129274a635b24d895"}, "b" : "c" }'::bson->>'a'; ?column? --------------------------------------------------------------------- { "$oid" : "62e034e129274a635b24d895" } (1 row) WITH r1 AS (SELECT 1.0::float8 as dbl, 'text' AS txt, 3::int4 as int32, 44::int8 as int64, '{ "": [1, 2, 3]}'::bson as bsonValue, '{"a": 1, "b": 2}'::bson as bsonObj) SELECT row_get_bson(r) FROM r1 r; row_get_bson --------------------------------------------------------------------- { "dbl" : { "$numberDouble" : "1.0" }, "txt" : "text", "int32" : { "$numberInt" : "3" }, "int64" : { "$numberInt" : "44" }, "bsonvalue" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "bsonobj" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } } (1 row) SELECT '{"a":1,"b":"c"}'::bson::bytea::bson = '{"a":1,"b":"c"}'::bson; ?column? --------------------------------------------------------------------- t (1 row) bson_composite_index_only_scan_pg16_tests.out000066400000000000000000001263011507310017400410650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 6920000; SET documentdb.next_collection_id TO 692000; SET documentdb.next_collection_index_id TO 692000; \i sql/bson_composite_index_only_scan_tests_core.sql SET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET documentdb.enableExtendedExplainPlans to on; SET documentdb.enableIndexOnlyScan to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) SELECT documentdb_api.drop_collection('idx_only_scan_db', 'idx_only_scan_coll') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('idx_only_scan_db', 'idx_only_scan_coll'); psql:sql/bson_composite_index_only_scan_tests_core.sql:10: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT collection_id as coll_id FROM documentdb_api_catalog.collections WHERE collection_name = 'idx_only_scan_coll' AND database_name = 'idx_only_scan_db' \gset SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 1, "country": "USA", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 2, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 3, "country": "Mexico", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 4, "country": "India", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 5, "country": "Brazil", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 6, "country": "Brazil", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 7, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 8, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 9, "country": "India", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 10, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 11, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 12, "country": "Spain", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 13, "country": "Italy", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 14, "country": "France", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 15, "country": "France", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 16, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 'ANALYZE documentdb_data.documents_' || :'coll_id' \gexec ANALYZE documentdb_data.documents_692001 set enable_seqscan to off; set enable_bitmapscan to off; -- test index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=1 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> GroupAggregate (actual rows=1 loops=1) Output: '_id'::text, '{ "" : "1" }'::bson, 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Brazil", { })] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=16 loops=1) Index Cond: (collection.document @>= '{ "country" : "Brazil" }'::bson) Heap Fetches: 16 (14 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : "1", "n" : { "$numberInt" : "16" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=1 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> GroupAggregate (actual rows=1 loops=1) Output: '_id'::text, '{ "" : "1" }'::bson, 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Fetches: 7 (14 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : "1", "n" : { "$numberInt" : "7" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 4 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "4" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now run VACUUM should see the heap blocks go down SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec VACUUM documentdb_data.documents_692001 EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 0 (12 rows) -- now update a document to change the country SELECT documentdb_api.update('idx_only_scan_db', '{"update": "decimal128", "updates":[{"q": {"_id": 8},"u":{"$set":{"country": "Italy"}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "4" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]], ["country": ["Italy", "Italy"]] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4), (isInequality: false, estimatedEntryCount: 1)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=5 loops=1) Index Cond: (collection.document @*= '{ "country" : [ "USA", "Italy" ] }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "5" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- match with count EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "7" } } (1 row) -- range queries should also use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ("Brazil", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=5 loops=1) Index Cond: ((collection.document @> '{ "country" : "Brazil" }'::bson) AND (collection.document @< '{ "country" : "Mexico" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "5" } } (1 row) -- No filters and not sharded should use _id_ index EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{"$match": {}}, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Index Only Scan using _id_ on documentdb_data.documents_692001_6920002 collection (actual rows=16 loops=1) Output: collection.shard_key_value, collection.object_id Index Cond: (collection.shard_key_value = '692001'::bigint) Heap Fetches: 0 (6 rows) -- now test with compound index SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1, "provider": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_provider_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: country_provider_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"], "provider": ["AWS", "AWS"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 3)] -> Index Only Scan using country_provider_1 on documentdb_data.documents_692001_6920002 collection (actual rows=3 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : "AWS" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "3" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: country_provider_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"], "provider": ["GCP", "GCP"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 1)] -> Index Only Scan using country_provider_1 on documentdb_data.documents_692001_6920002 collection (actual rows=1 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : "GCP" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "1" } } (1 row) -- if the filter doesn't match the first field in the index, shouldn't use the compound index and not index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Index Scan using _id_ on documentdb_data.documents_692001_6920002 collection (actual rows=6 loops=1) Output: collection.shard_key_value, collection.object_id, collection.document Index Cond: (collection.shard_key_value = '692001'::bigint) Filter: (collection.document @= '{ "provider" : "AWS" }'::bson) Rows Removed by Filter: 10 (7 rows) -- if we project something out it shouldn't do index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Mexico"}} }, { "$group" : { "_id" : "$country", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=3 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> HashAggregate (actual rows=3 loops=1) Output: '_id'::text, (bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson)), 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) Group Key: bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) Batches: 1 Memory Usage: 24kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) Output: bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", { })] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=9 loops=1) Output: collection.document Index Cond: (collection.document @>= '{ "country" : "Mexico" }'::bson) (17 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) Output: document indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=4 loops=1) Output: document Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) (11 rows) -- negation, elemMatch, type and size queries should not use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$ne": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=12 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": [MinKey, MaxKey]] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 12)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=12 loops=1) Index Cond: (collection.document @!= '{ "country" : "Mexico" }'::bson) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$type": "string"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", { })] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=16 loops=1) Index Cond: (collection.document @# '{ "country" : "string" }'::bson) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$size": 2}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": [MinKey, MaxKey]] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=0 loops=1) Index Cond: (collection.document @@# '{ "country" : { "$numberInt" : "2" } }'::bson) Rows Removed by Index Recheck: 16 (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$elemMatch": {"$eq": "Mexico"}}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=0 loops=1) Index Cond: (collection.document @<> '{ "country" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "Mexico", "isTopLevel" : true } ] } }'::bson) Filter: (collection.document @#? '{ "country" : { "$eq" : "Mexico" } }'::bson) Rows Removed by Filter: 4 (13 rows) -- if we turn the GUC off by it shouldn't use index only scan set documentdb.enableIndexOnlyScan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documentdb_data.documents_692001_6920002 collection (actual rows=7 loops=1) Recheck Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on country_1 (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) (14 rows) set documentdb.enableIndexOnlyScan to on; -- if we insert a multi-key value, it shouldn't use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 17, "country": "Mexico", "provider": ["AWS", "GCP"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": ["AWS", "GCP"]}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: country_provider_1 isMultiKey: true indexBounds: ["country": ["Mexico", "Mexico"], "provider": [[ "AWS", "GCP" ], [ "AWS", "GCP" ]]], ["country": ["Mexico", "Mexico"], "provider": ["AWS", "AWS"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_provider_1 on documentdb_data.documents_692001_6920002 collection (actual rows=1 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : [ "AWS", "GCP" ] }'::bson)) Rows Removed by Index Recheck: 3 (12 rows) CALL documentdb_api.drop_indexes('idx_only_scan_db', '{ "dropIndexes": "idx_only_scan_coll", "index": "country_provider_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) -- now insert a truncated term, should not use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', FORMAT('{ "_id": 18, "country": { "key": "%s", "provider": "%s" } }', repeat('a', 10000), repeat('a', 10000))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 5)] -> Index Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=5 loops=1) Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) (11 rows) -- if we delete it and vacuum it should use index only scan again SELECT documentdb_api.delete('idx_only_scan_db', '{ "delete": "idx_only_scan_coll", "deletes": [ {"q": {"_id": {"$eq": 18} }, "limit": 0} ]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec VACUUM documentdb_data.documents_692001 EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 5)] -> Index Only Scan using country_1 on documentdb_data.documents_692001_6920002 collection (actual rows=5 loops=1) Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) Heap Fetches: 0 (12 rows) -- TODO support sharded collections, currently we don't because of the shard_key_value filter -- SELECT documentdb_api.shard_collection('idx_only_scan_db', 'idx_only_scan_coll', '{ "country": "hashed" }', FALSE); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); bson_composite_index_only_scan_tests.out000066400000000000000000001264431507310017400402370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 690000; SET documentdb.next_collection_id TO 69000; SET documentdb.next_collection_index_id TO 69000; \i sql/bson_composite_index_only_scan_tests_core.sql SET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET documentdb.enableExtendedExplainPlans to on; SET documentdb.enableIndexOnlyScan to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) SELECT documentdb_api.drop_collection('idx_only_scan_db', 'idx_only_scan_coll') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('idx_only_scan_db', 'idx_only_scan_coll'); psql:sql/bson_composite_index_only_scan_tests_core.sql:10: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT collection_id as coll_id FROM documentdb_api_catalog.collections WHERE collection_name = 'idx_only_scan_coll' AND database_name = 'idx_only_scan_db' \gset SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 1, "country": "USA", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 2, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 3, "country": "Mexico", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 4, "country": "India", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 5, "country": "Brazil", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 6, "country": "Brazil", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 7, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 8, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 9, "country": "India", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 10, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 11, "country": "USA", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 12, "country": "Spain", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 13, "country": "Italy", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 14, "country": "France", "provider": "Azure"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 15, "country": "France", "provider": "GCP"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 16, "country": "Mexico", "provider": "AWS"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 'ANALYZE documentdb_data.documents_' || :'coll_id' \gexec ANALYZE documentdb_data.documents_69001 set enable_seqscan to off; set enable_bitmapscan to off; -- test index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=1 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> GroupAggregate (actual rows=1 loops=1) Output: '_id'::text, ('{ "" : "1" }'::bson), 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) Group Key: '{ "" : "1" }'::bson -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) Output: '{ "" : "1" }'::bson indexName: country_1 isMultiKey: false indexBounds: ["country": ["Brazil", { })] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=16 loops=1) Index Cond: (collection.document @>= '{ "country" : "Brazil" }'::bson) Heap Fetches: 16 (16 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : "1", "n" : { "$numberInt" : "16" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=1 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> GroupAggregate (actual rows=1 loops=1) Output: '_id'::text, ('{ "" : "1" }'::bson), 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) Group Key: '{ "" : "1" }'::bson -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) Output: '{ "" : "1" }'::bson indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Fetches: 7 (16 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); document --------------------------------------------------------------------- { "_id" : "1", "n" : { "$numberInt" : "7" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 4 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "4" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now run VACUUM should see the heap blocks go down SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec VACUUM documentdb_data.documents_69001 EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 0 (12 rows) -- now update a document to change the country SELECT documentdb_api.update('idx_only_scan_db', '{"update": "decimal128", "updates":[{"q": {"_id": 8},"u":{"$set":{"country": "Italy"}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=4 loops=1) Index Cond: (collection.document @= '{ "country" : "USA" }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "4" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_dollar_merge_documents(bson_repath_and_build('n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)), '{ "ok" : { "$numberDouble" : "1.0" } }'::bson, false) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["USA", "USA"]], ["country": ["Italy", "Italy"]] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4), (isInequality: false, estimatedEntryCount: 1)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=5 loops=1) Index Cond: (collection.document @*= '{ "country" : [ "USA", "Italy" ] }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); document --------------------------------------------------------------------- { "n" : { "$numberInt" : "5" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- match with count EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "7" } } (1 row) -- range queries should also use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ("Brazil", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=5 loops=1) Index Cond: ((collection.document @> '{ "country" : "Brazil" }'::bson) AND (collection.document @< '{ "country" : "Mexico" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "5" } } (1 row) -- No filters and not sharded should use _id_ index EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{"$match": {}}, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Index Only Scan using _id_ on documentdb_data.documents_69001_690002 collection (actual rows=16 loops=1) Output: collection.shard_key_value, collection.object_id Index Cond: (collection.shard_key_value = '69001'::bigint) Heap Fetches: 0 (6 rows) -- now test with compound index SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1, "provider": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_provider_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: country_provider_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"], "provider": ["AWS", "AWS"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 3)] -> Index Only Scan using country_provider_1 on documentdb_data.documents_69001_690002 collection (actual rows=3 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : "AWS" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "3" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: country_provider_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"], "provider": ["GCP", "GCP"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 1)] -> Index Only Scan using country_provider_1 on documentdb_data.documents_69001_690002 collection (actual rows=1 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : "GCP" }'::bson)) Heap Fetches: 0 (12 rows) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "1" } } (1 row) -- if the filter doesn't match the first field in the index, shouldn't use the compound index and not index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Index Scan using _id_ on documentdb_data.documents_69001_690002 collection (actual rows=6 loops=1) Output: collection.shard_key_value, collection.object_id, collection.document Index Cond: (collection.shard_key_value = '69001'::bigint) Filter: (collection.document @= '{ "provider" : "AWS" }'::bson) Rows Removed by Filter: 10 (7 rows) -- if we project something out it shouldn't do index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Mexico"}} }, { "$group" : { "_id" : "$country", "n" : { "$sum" : 1 } } }]}'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=3 loops=1) Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> HashAggregate (actual rows=3 loops=1) Output: '_id'::text, (bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson)), 'n'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) Group Key: bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) Batches: 1 Memory Usage: 24kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) Output: bson_expression_get(collection.document, '{ "" : "$country" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", { })] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=9 loops=1) Output: collection.document Index Cond: (collection.document @>= '{ "country" : "Mexico" }'::bson) (17 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) Output: document indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=4 loops=1) Output: document Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) (11 rows) -- negation, elemMatch, type and size queries should not use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$ne": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=12 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": [MinKey, MaxKey]] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 12)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=12 loops=1) Index Cond: (collection.document @!= '{ "country" : "Mexico" }'::bson) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$type": "string"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", { })] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=16 loops=1) Index Cond: (collection.document @# '{ "country" : "string" }'::bson) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$size": 2}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": [MinKey, MaxKey]] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 16)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=0 loops=1) Index Cond: (collection.document @@# '{ "country" : { "$numberInt" : "2" } }'::bson) Rows Removed by Index Recheck: 16 (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$elemMatch": {"$eq": "Mexico"}}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=0 loops=1) Index Cond: (collection.document @<> '{ "country" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "Mexico", "isTopLevel" : true } ] } }'::bson) Filter: (collection.document @#? '{ "country" : { "$eq" : "Mexico" } }'::bson) Rows Removed by Filter: 4 (13 rows) -- if we turn the GUC off by it shouldn't use index only scan set documentdb.enableIndexOnlyScan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["", "Mexico")] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documentdb_data.documents_69001_690002 collection (actual rows=7 loops=1) Recheck Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on country_1 (actual rows=7 loops=1) Index Cond: (collection.document @< '{ "country" : "Mexico" }'::bson) (14 rows) set documentdb.enableIndexOnlyScan to on; -- if we insert a multi-key value, it shouldn't use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 17, "country": "Mexico", "provider": ["AWS", "GCP"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": ["AWS", "GCP"]}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: country_provider_1 isMultiKey: true indexBounds: ["country": ["Mexico", "Mexico"], "provider": [[ "AWS", "GCP" ], [ "AWS", "GCP" ]]], ["country": ["Mexico", "Mexico"], "provider": ["AWS", "AWS"]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 4)] -> Index Scan using country_provider_1 on documentdb_data.documents_69001_690002 collection (actual rows=1 loops=1) Index Cond: ((collection.document @= '{ "country" : "Mexico" }'::bson) AND (collection.document @= '{ "provider" : [ "AWS", "GCP" ] }'::bson)) Rows Removed by Index Recheck: 3 (12 rows) CALL documentdb_api.drop_indexes('idx_only_scan_db', '{ "dropIndexes": "idx_only_scan_coll", "index": "country_provider_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) -- now insert a truncated term, should not use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', FORMAT('{ "_id": 18, "country": { "key": "%s", "provider": "%s" } }', repeat('a', 10000), repeat('a', 10000))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 5)] -> Index Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=5 loops=1) Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) (11 rows) -- if we delete it and vacuum it should use index only scan again SELECT documentdb_api.delete('idx_only_scan_db', '{ "delete": "idx_only_scan_coll", "deletes": [ {"q": {"_id": {"$eq": 18} }, "limit": 0} ]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec VACUUM documentdb_data.documents_69001 EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); QUERY PLAN --------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) Output: bson_repath_and_build('count'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: country_1 isMultiKey: false indexBounds: ["country": ["Mexico", "Mexico"]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 5)] -> Index Only Scan using country_1 on documentdb_data.documents_69001_690002 collection (actual rows=5 loops=1) Index Cond: (collection.document @= '{ "country" : "Mexico" }'::bson) Heap Fetches: 0 (12 rows) -- TODO support sharded collections, currently we don't because of the shard_key_value filter -- SELECT documentdb_api.shard_collection('idx_only_scan_db', 'idx_only_scan_coll', '{ "country": "hashed" }', FALSE); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); bson_composite_index_prepare_for_unique_tests.out000066400000000000000000000355711507310017400421450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_core,documentdb_api_catalog; SET citus.next_shard_id TO 5880000; SET documentdb.next_collection_id TO 588000; SET documentdb.next_collection_index_id TO 588000; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{ "createIndexes": "collection", "indexes": [ { "name": "a_1", "key": { "a": 1 }, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true } } ] }', TRUE); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_588001; Table "documentdb_data.documents_588001" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_588001" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_588002" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "a" ]', tl='2691'), documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" } }'::bson, false) documentdb_extended_rum_catalog.bson_extended_rum_unique_shard_path_ops) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '588001'::bigint) -- inserting and querying works fine. select COUNT(documentdb_api.insert_one('prep_unique_db', 'collection', FORMAT('{ "a": %s, "b": %s }', i, 100-i)::bson)) FROM generate_series(1, 100) i; count --------------------------------------------------------------------- 100 (1 row) -- insert a duplicate, should not fail SELECT documentdb_api.insert_one('prep_unique_db', 'collection', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE documentdb_data.documents_588001; set citus.propagate_set_commands to 'local'; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local enable_seqscan to off; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=98 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 3528 bytes Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_588001_5880002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '588001'::bigint)) Tuple data received from node: 3528 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=98 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": (2, Infinity]] innerScanLoops: 99 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 98)] -> Bitmap Heap Scan on documentdb_data.documents_588001_5880002 collection (actual rows=98 loops=1) Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bson) Heap Blocks: exact=2 -> Bitmap Index Scan on a_1 (actual rows=98 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bson) (23 rows) ROLLBACK; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.enableIndexOrderByPushdown to on; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}}, "sort": {"a": 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=98 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 3528 bytes Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_588001_5880002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '588001'::bigint) AND documentdb_api_internal.bson_dollar_fullscan(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson)) ORDER BY (documentdb_api_catalog.bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Tuple data received from node: 3528 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=98 loops=1) Output: document, documentdb_api_catalog.bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) indexName: a_1 isMultiKey: false indexBounds: ["a": (2, Infinity]] innerScanLoops: 99 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 98)] -> Index Scan using a_1 on documentdb_data.documents_588001_5880002 collection (actual rows=98 loops=1) Output: document Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bson) Order By: (collection.document OPERATOR(documentdb_api_catalog.|-<>) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (21 rows) ROLLBACK; -- multiple fields work fine SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{ "createIndexes": "collection", "indexes": [ { "name": "a_1_b_1", "key": { "a": 1, "b": 1 }, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true } } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('prep_unique_db', '{ "listIndexes": "collection" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "prep_unique_db.collection", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "prep_unique_db.collection", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1", "enableOrderedIndex" : { "$numberInt" : "1" }, "buildAsUnique" : { "$numberInt" : "1" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "prep_unique_db.collection", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }, "name" : "a_1_b_1", "enableOrderedIndex" : { "$numberInt" : "1" }, "buildAsUnique" : { "$numberInt" : "1" } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) \d documentdb_data.documents_588001; Table "documentdb_data.documents_588001" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_588001" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_588002" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "a" ]', tl='2691'), documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" } }'::bson, false) documentdb_extended_rum_catalog.bson_extended_rum_unique_shard_path_ops) "documents_rum_index_588003" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "a", "b" ]', tl='2691'), documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }'::bson, false) documentdb_extended_rum_catalog.bson_extended_rum_unique_shard_path_ops) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '588001'::bigint) ANALYZE documentdb_data.documents_588001; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local enable_seqscan to off; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}, "b": 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_588001_5880002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '588001'::bigint)) Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) Output: document indexName: a_1_b_1 isMultiKey: false indexBounds: ["a": (2, Infinity], "b": [3, 3]] innerScanLoops: 99 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documentdb_data.documents_588001_5880002 collection (actual rows=1 loops=1) Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "3" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on a_1_b_1 (actual rows=1 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (23 rows) ROLLBACK; -- test error paths SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{"createIndexes": "collection", "indexes": [{"key": {"a": 1 }, "storageEngine": { "enableOrderedIndex": false, "buildAsUnique": true }, "name": "invalid"}]}',true); ERROR: Error in specification { "key" : { "a" : 1 }, "storageEngine" : { "enableOrderedIndex" : false, "buildAsUnique" : true }, "name" : "invalid" }:enableOrderedIndex must be specified when preparing for a unique index. SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{"createIndexes": "collection", "indexes": [{"key": {"b": 1 }, "unique": true, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true }, "name": "invalid"}]}',true); ERROR: Error in specification { "key" : { "b" : 1 }, "unique" : true, "storageEngine" : { "enableOrderedIndex" : true, "buildAsUnique" : true }, "name" : "invalid" }:buildAsUnique can only be set when unique is false. bson_composite_order_by_index_tests.out000066400000000000000000005040331507310017400400520ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 680000; SET documentdb.next_collection_id TO 68000; SET documentdb.next_collection_index_id TO 68000; set documentdb.enableExtendedExplainPlans to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) SELECT documentdb_api.drop_collection('comp_db', 'query_orderby') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('comp_db', 'query_orderby'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby", "indexes": [ { "key": { "a": 1, "c": 1 }, "storageEngine": { "enableCompositeTerm": true }, "name": "a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_68001 Table "documentdb_data.documents_68001" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_68001" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_68002" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "a", "c" ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '68001'::bigint) -- now insert some sample docs SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 1, "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 2, "a": -2, "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 3, "a": "string", "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 4, "a": { "$minKey": 1 }, "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 5, "a": true, "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 6, "a": null, "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 7, "a": { "b": 1 }, "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE documentdb_data.documents_68001; set enable_seqscan to off; -- no pushdown EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=7 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: a_c isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_68001_680002 collection (actual rows=7 loops=1) Recheck Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_c (actual rows=7 loops=1) Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) (15 rows) -- now the order by succeeds with an index scan SET documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: a_c isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Scan using a_c on documents_68001_680002 collection (actual rows=7 loops=1) Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) -- do a reverse walk EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: a_c isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Scan using a_c on documents_68001_680002 collection (actual rows=7 loops=1) Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- now check the correctness (things are ordered) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$minKey" : 1 }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : null, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "-2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "string", "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "1" } }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : true, "c" : { "$numberInt" : "2" } } (7 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : true, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "1" } }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "string", "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "-2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : null, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$minKey" : 1 }, "c" : { "$numberInt" : "2" } } (7 rows) -- validate type bracketing SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": -100 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "-2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gte": -2 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "-2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": false }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : true, "c" : { "$numberInt" : "2" } } (1 row) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": true }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gte": true }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : true, "c" : { "$numberInt" : "2" } } (1 row) -- validate runtime recheck functions SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^str" }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "string", "c" : { "$numberInt" : "2" } } (1 row) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^str" }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "string", "c" : { "$numberInt" : "2" } } (1 row) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- (0 rows) -- validate ordering with truncation SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 10, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '2', 'cd1233')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 11, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '1', 'cd1234')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 9, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '3', 'cd1235')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 12, "a": "%s", "c": "%s" }', 'abcde', 'cd1232' || repeat('z', 3000) || '1')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 13, "a": "%s", "c": "%s" }', 'abcde', 'cd1232')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "projection": { "_id": 1 }, "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "_id" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "9" } } (5 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "projection": { "_id": 1 }, "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" } } { "_id" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "13" } } (5 rows) -- validate sort works after an array is inserted SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 8, "a": [ 1, 2, 3 ], "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": -100 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "-2" }, "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : { "$numberInt" : "2" } } (3 rows) -- validate that we use disjoint sets more efficiently SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf_arr", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a_1_id_1" }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- insert an array to make this a multi-key index SELECT documentdb_api.insert_one('comp_db', 'query_orderby_perf_arr', '{ "_id": 0, "a": [ true, false ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert documents 1 - 100 SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf_arr', FORMAT('{ "_id": %s, "a": [ %s, %s ] }', i, i, 100 - i)::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) -- now query the index with an order by set documentdb.forceDisableSeqScan to on; ANALYZE documentdb_data.documents_68002; -- should not use the index for sort (since it's a multi-key index) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=5 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] innerScanLoops: 8 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=5 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) (12 rows) -- now check the performance SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "97" } ] } { "_id" : { "$numberInt" : "97" }, "a" : [ { "$numberInt" : "97" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "90" } ] } { "_id" : { "$numberInt" : "90" }, "a" : [ { "$numberInt" : "90" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "49" }, "a" : [ { "$numberInt" : "49" }, { "$numberInt" : "51" } ] } { "_id" : { "$numberInt" : "51" }, "a" : [ { "$numberInt" : "51" }, { "$numberInt" : "49" } ] } (6 rows) -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "99" } ] } { "_id" : { "$numberInt" : "99" }, "a" : [ { "$numberInt" : "99" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "98" } ] } { "_id" : { "$numberInt" : "98" }, "a" : [ { "$numberInt" : "98" }, { "$numberInt" : "2" } ] } (5 rows) -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "99" }, "a" : [ { "$numberInt" : "99" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "99" } ] } { "_id" : { "$numberInt" : "98" }, "a" : [ { "$numberInt" : "98" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "98" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "97" } ] } { "_id" : { "$numberInt" : "97" }, "a" : [ { "$numberInt" : "97" }, { "$numberInt" : "3" } ] } (7 rows) -- only pushes filter down SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "99" } ] } { "_id" : { "$numberInt" : "99" }, "a" : [ { "$numberInt" : "99" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "98" } ] } { "_id" : { "$numberInt" : "98" }, "a" : [ { "$numberInt" : "98" }, { "$numberInt" : "2" } ] } (5 rows) set documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=6 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [3, 3], "_id": (MinKey, MaxKey)], ["a": [49, 49], "_id": (MinKey, MaxKey)], ["a": [90, 90], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=6 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "49" }, { "$numberInt" : "90" } ] }'::bson) (12 rows) -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=5 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] innerScanLoops: 8 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=5 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) (12 rows) -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=7 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=7 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": (96, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 10 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=7 loops=1) Index Cond: (document @> '{ "a" : { "$numberInt" : "96" } }'::bson) (12 rows) -- only pushes filter down EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=5 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)], ["a": (96, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 7 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5), (isInequality: true, estimatedEntryCount: 7)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=5 loops=1) Index Cond: ((document @< '{ "a" : { "$numberInt" : "3" } }'::bson) AND (document @> '{ "a" : { "$numberInt" : "96" } }'::bson)) (12 rows) -- test the same for non multi-key index --------------------------------------------------------------------- -- validate that we use disjoint sets more efficiently SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a_1" }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now insert documents 1 - 100 SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf', FORMAT('{ "_id": %s, "a": %s }', i, i)::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) -- now query the index with an order by set documentdb.forceDisableSeqScan to on; ANALYZE documentdb_data.documents_68003; -- should use the index for sort EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- now check correctness. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "49" }, "a" : { "$numberInt" : "49" } } { "_id" : { "$numberInt" : "90" }, "a" : { "$numberInt" : "90" } } (3 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "90" }, "a" : { "$numberInt" : "90" } } { "_id" : { "$numberInt" : "49" }, "a" : { "$numberInt" : "49" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } (3 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "97" }, "a" : { "$numberInt" : "97" } } { "_id" : { "$numberInt" : "98" }, "a" : { "$numberInt" : "98" } } { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "100" } } (4 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } { "_id" : { "$numberInt" : "98" }, "a" : { "$numberInt" : "98" } } { "_id" : { "$numberInt" : "97" }, "a" : { "$numberInt" : "97" } } (4 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "91" }, "a" : { "$numberInt" : "91" } } { "_id" : { "$numberInt" : "92" }, "a" : { "$numberInt" : "92" } } { "_id" : { "$numberInt" : "93" }, "a" : { "$numberInt" : "93" } } (3 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "93" }, "a" : { "$numberInt" : "93" } } { "_id" : { "$numberInt" : "92" }, "a" : { "$numberInt" : "92" } } { "_id" : { "$numberInt" : "91" }, "a" : { "$numberInt" : "91" } } (3 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": -1 } }'); document --------------------------------------------------------------------- (0 rows) -- now check the performance EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [3, 3], "_id": (MinKey, MaxKey)], ["a": [49, 49], "_id": (MinKey, MaxKey)], ["a": [90, 90], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=3 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "49" }, { "$numberInt" : "90" } ] }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [3, 3], "_id": (MinKey, MaxKey)], ["a": [49, 49], "_id": (MinKey, MaxKey)], ["a": [90, 90], "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 9 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=3 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "49" }, { "$numberInt" : "90" } ] }'::bson) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [-Infinity, 3), "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @< '{ "a" : { "$numberInt" : "3" } }'::bson) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (96, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=4 loops=1) Index Cond: (document @> '{ "a" : { "$numberInt" : "96" } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (96, Infinity], "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=4 loops=1) Index Cond: (document @> '{ "a" : { "$numberInt" : "96" } }'::bson) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- only scans th relevant entries EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (90, 94), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 3)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=3 loops=1) Index Cond: ((document @< '{ "a" : { "$numberInt" : "94" } }'::bson) AND (document @> '{ "a" : { "$numberInt" : "90" } }'::bson)) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (90, 94), "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 7 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 3)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=3 loops=1) Index Cond: ((document @< '{ "a" : { "$numberInt" : "94" } }'::bson) AND (document @> '{ "a" : { "$numberInt" : "90" } }'::bson)) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- scans only > 96 and stops. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (96, 3), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=0 loops=1) Index Cond: ((document @< '{ "a" : { "$numberInt" : "3" } }'::bson) AND (document @> '{ "a" : { "$numberInt" : "96" } }'::bson)) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (96, 3), "_id": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=0 loops=1) Index Cond: ((document @< '{ "a" : { "$numberInt" : "3" } }'::bson) AND (document @> '{ "a" : { "$numberInt" : "96" } }'::bson)) Order By: (document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) (11 rows) -- groupby pushdown works for non-multi-key indexes EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$exists": true } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=100 loops=1) -> GroupAggregate (actual rows=100 loops=1) Group Key: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 100 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=100 loops=1) Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (13 rows) set enable_bitmapscan to off; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_0 (actual rows=100 loops=1) -> GroupAggregate (actual rows=100 loops=1) Group Key: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 100 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=100 loops=1) Index Cond: (document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (13 rows) -- the same does not work on multi-key indexes EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$exists": true } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 (actual rows=101 loops=1) -> HashAggregate (actual rows=101 loops=1) Group Key: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) Batches: 1 Memory Usage: 56kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=101 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] numDuplicates: 100 entries innerScanLoops: 201 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 201)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=101 loops=1) Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) (14 rows) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); ERROR: Could not find any valid index to push down for query set enable_bitmapscan to off; -- for non-multi-key requires, prefix equality until the min order by key only. -- can't push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=2 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)], ["a": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); ERROR: Could not find any valid index to push down for query -- can push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=1 loops=1) Index Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::bson) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)], ["a": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$gte": 1 } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 100 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=100 loops=1) Index Cond: (document @>= '{ "a" : { "$numberInt" : "1" } }'::bson) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 100 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=100 loops=1) Index Cond: ((document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson)) (10 rows) -- but not these EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1, "a": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=2 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)], ["a": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1)] -> Index Scan using a_1 on documents_68003_680006 collection (actual rows=2 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) (12 rows) -- for multi-key indexes, we can push down the order by only if there's equality until the max order by key. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=4 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)], ["a": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=4 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); ERROR: Could not find any valid index to push down for query -- can push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=2 loops=1) Index Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::bson) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=101 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] numDuplicates: 100 entries innerScanLoops: 201 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 201)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=101 loops=1) Index Cond: ((document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson)) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "a": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=101 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] numDuplicates: 100 entries innerScanLoops: 201 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 201)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=101 loops=1) Index Cond: (document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (11 rows) -- but not these EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=4 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [1, 1], "_id": (MinKey, MaxKey)], ["a": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 2)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=4 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$gte": 1 } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=100 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 36kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1_id_1 isMultiKey: true indexBounds: ["a": [1, Infinity], "_id": (MinKey, MaxKey)] numDuplicates: 98 entries innerScanLoops: 199 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 198)] -> Index Scan using a_1_id_1 on documents_68002_680004 collection (actual rows=100 loops=1) Index Cond: (document @>= '{ "a" : { "$numberInt" : "1" } }'::bson) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "_id": 1, "a": 1 } } ] }'); ERROR: Could not find any valid index to push down for query -- now insert composite rows that cause truncation and assert that it gets ordered properly. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf2", "indexes": [ { "key": { "b": 1, "c": 1 }, "enableCompositeTerm": true, "name": "b_1" }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf2', FORMAT('{ "_id": %s, "b": "%s", "c": %s }', i * 5 + j, repeat('aaaa', 10 * i), j)::bson)) FROM generate_series(50, 500) i JOIN generate_series(1, 5) AS j ON True; count --------------------------------------------------------------------- 2255 (1 row) ANALYZE documentdb_data.documents_68004; SET documentdb.enableIndexOrderbyPushdown to on; set documentdb.forceUseIndexIfAvailable to on; set enable_bitmapscan to off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Index Scan using b_1 on documents_68004_680008 collection Index Cond: (document @>= '{ "b" : { "$minKey" : 1 } }'::bson) Order By: (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson) (4 rows) EXPLAIN (COSTS OFF) WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' >= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; QUERY PLAN --------------------------------------------------------------------- Aggregate -> WindowAgg -> Subquery Scan on s1 -> Custom Scan (DocumentDBApiExplainQueryScan) -> Index Scan using b_1 on documents_68004_680008 collection Index Cond: (document @>= '{ "b" : { "$minKey" : 1 } }'::bson) Order By: (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Index Scan using b_1 on documents_68004_680008 collection Index Cond: (document @>= '{ "b" : { "$minKey" : 1 } }'::bson) Order By: (document <>-| '{ "b" : { "$numberInt" : "-1" } }'::bson) (4 rows) EXPLAIN (COSTS OFF) WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' <= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; QUERY PLAN --------------------------------------------------------------------- Aggregate -> WindowAgg -> Subquery Scan on s1 -> Custom Scan (DocumentDBApiExplainQueryScan) -> Index Scan using b_1 on documents_68004_680008 collection Index Cond: (document @>= '{ "b" : { "$minKey" : 1 } }'::bson) Order By: (document <>-| '{ "b" : { "$numberInt" : "-1" } }'::bson) (7 rows) -- validate the order is correct WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' >= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; min | max --------------------------------------------------------------------- 1 | 1 (1 row) WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' <= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; min | max --------------------------------------------------------------------- 1 | 1 (1 row) reset documentdb.forceDisableSeqScan; -- add the complex tests that were in the composite filter order by select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 1, "a": { "b": 1 } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 2, "a": { "b": null } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 3, "a": { "b": "string value" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 4, "a": { "b": true } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 5, "a": { "b": false } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 6, "a": { "b": [] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 7, "a": { "b": [1, 2, 3] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 8, "a": { "b": [1, { "$minKey": 1 }, 3, true] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 9, "a": { "b": [1, { "$maxKey": 1 }, 3, true] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 10, "a": { "b": { "c": 1 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 11, "a": { "b": { "$maxKey": 1 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now some more esoteric values select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 12, "a": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 13, "a": [ {} ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 14, "a": [ 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 15, "a": [ 1, { "b": 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 16, "a": [ null, { "b": 4 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 17, "a": [ {}, { "b": 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 18, "a": [ { "c": 1 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 19, "a": [ { "c": 1 }, { "b": 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- baseline select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 20, "a": { "b": 0 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 21, "a": { "b": { "$minKey": 1 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test ordering in the composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now sort manually (we can't rely on the index pushdown feature yet since that requires a filter) BEGIN; set local documentdb.forceDisableSeqScan to on; set local documentdb.enableIndexOrderbyPushdown to on; set local documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=21 loops=1) Task Count: 1 Tuple data received from nodes: 741 bytes Tasks Shown: All -> Task Tuple data received from node: 741 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=21 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 33)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=21 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "orderByScan" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Order By: (document OPERATOR(documentdb_api_catalog.|-<>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (18 rows) ROLLBACK; BEGIN; set local documentdb.forceDisableSeqScan to on; set local documentdb.enableIndexOrderbyPushdown to on; SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": 1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$minKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "21" }, "a" : { "b" : { "$minKey" : 1 } } } { "_id" : { "$numberInt" : "12" }, "a" : null } { "_id" : { "$numberInt" : "13" }, "a" : [ { } ] } { "_id" : { "$numberInt" : "14" }, "a" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "18" }, "a" : [ { "c" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "15" }, "a" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "16" }, "a" : [ null, { "b" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "17" }, "a" : [ { }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "19" }, "a" : [ { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ ] } } { "_id" : { "$numberInt" : "20" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$maxKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "string value" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : false } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : { "$maxKey" : 1 } } } (21 rows) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": -1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$maxKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$minKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : false } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "string value" } } { "_id" : { "$numberInt" : "16" }, "a" : [ null, { "b" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "19" }, "a" : [ { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "17" }, "a" : [ { }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "15" }, "a" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "20" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "18" }, "a" : [ { "c" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "14" }, "a" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "13" }, "a" : [ { } ] } { "_id" : { "$numberInt" : "12" }, "a" : null } { "_id" : { "$numberInt" : "21" }, "a" : { "b" : { "$minKey" : 1 } } } (21 rows) ROLLBACK; set documentdb.forceDisableSeqScan to on; set documentdb.enableIndexOrderbyPushdown to on; set documentdb.enableExtendedExplainPlans to on; -- can't push this down (no equality prefix) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); ERROR: Could not find any valid index to push down for query -- can't push order by down here: EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=17 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 26kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=17 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=17 loops=1) Index Cond: (document @>= '{ "a.b" : { "$minKey" : 1 } }'::bson) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$gt": 5 } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=0 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": (5, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=0 loops=1) Index Cond: (document @> '{ "a.b" : { "$numberInt" : "5" } }'::bson) (12 rows) -- but this is okay EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=4 loops=1) Index Cond: (document @= '{ "a.b" : { "$numberInt" : "1" } }'::bson) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) (10 rows) -- this one isn't okay since we need to resort across a.b EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=4 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)], ["a.b": [2, 2], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4), (isInequality: true, estimatedEntryCount: 1)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=4 loops=1) Index Cond: (document @*= '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) (12 rows) -- but this is fine: EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$in": [ 1 ] } } }, { "$sort": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=4 loops=1) Index Cond: (document @= '{ "a.b" : { "$numberInt" : "1" } }'::bson) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) (10 rows) -- allows incremental sorting set enable_sort to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$eq": 1 } } }, { "$sort": { "_id": 1, "c": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Incremental Sort (actual rows=4 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "c" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Presorted Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) Full-sort Groups: 1 Sort Method: quicksort Average Memory: 25kB Peak Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=4 loops=1) Index Cond: (document @= '{ "a.b" : { "$numberInt" : "1" } }'::bson) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) (14 rows) -- forced order by pushdown respects ordering when there is none. set documentdb_rum.forceRumOrderedIndexScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=17 loops=1) indexName: a.b_1 isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Index Scan using "a.b_1" on documents_68005_680010 collection (actual rows=17 loops=1) Index Cond: (document @>= '{ "a.b" : { "$minKey" : 1 } }'::bson) (10 rows) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$minKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "21" }, "a" : { "b" : { "$minKey" : 1 } } } { "_id" : { "$numberInt" : "15" }, "a" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "16" }, "a" : [ null, { "b" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "17" }, "a" : [ { }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "19" }, "a" : [ { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ ] } } { "_id" : { "$numberInt" : "20" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$maxKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "string value" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : false } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : { "$maxKey" : 1 } } } (17 rows) -- test order by with primary key _id and composite index on _id with _id filter & order reset documentdb.forceDisableSeqScan; select COUNT(documentdb_api.insert_one('comp_db', 'idIndexOrder', FORMAT('{ "_id": %s, "a": %s }', i , i)::bson)) FROM generate_series(1, 100) AS i; NOTICE: creating collection count --------------------------------------------------------------------- 100 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "idIndexOrder", "indexes": [ { "key": { "_id": 1 }, "enableCompositeTerm": true, "name": "id_2" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now validate pushdown set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "idIndexOrder", "pipeline": [ { "$match": { "_id": { "$gte": 10, "$lte": 25 } } }, { "$sort": { "_id": 1 } }, { "$skip": 5 }, { "$limit": 5 } ] }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=5 loops=1) -> Subquery Scan on agg_stage_3 (actual rows=5 loops=1) -> Limit (actual rows=5 loops=1) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=10 loops=1) indexName: id_2 isMultiKey: false indexBounds: ["_id": [10, 25]] innerScanLoops: 10 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Index Scan using id_2 on documents_68006_680012 collection (actual rows=10 loops=1) Index Cond: ((document @>= '{ "_id" : { "$numberInt" : "10" } }'::bson) AND (document @<= '{ "_id" : { "$numberInt" : "25" } }'::bson)) Order By: (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson) Filter: ((object_id >= '{ "" : { "$numberInt" : "10" } }'::bson) AND (object_id <= '{ "" : { "$numberInt" : "25" } }'::bson)) (14 rows) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "idIndexOrder", "pipeline": [ { "$match": { "_id": { "$gte": 10, "$lte": 25 } } }, { "$sort": { "_id": 1 } }, { "$skip": 5 }, { "$limit": 5 } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "a" : { "$numberInt" : "15" } } { "_id" : { "$numberInt" : "16" }, "a" : { "$numberInt" : "16" } } { "_id" : { "$numberInt" : "17" }, "a" : { "$numberInt" : "17" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$numberInt" : "18" } } { "_id" : { "$numberInt" : "19" }, "a" : { "$numberInt" : "19" } } (5 rows) -- now repeat sort for nulls with 3 dotted paths set documentdb.forceDisableSeqScan to off; SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 1, "a": { "b": { "c": 1 } } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 2, "a": { "b": [ { "c": 2 } ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 3, "a": [ { "b": [ { "c": 1 } ] } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- combinations of those paths going missing SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 4, "a": { "b": { "d": 1 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 5, "a": { "b": [ { "c": 2 }, {} ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 6, "a": { "b": [ { "c": 2 }, 2 ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 7, "a": { "b": [ 2 ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 8, "a": { "b": [ {} ] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 9, "a": [ { "b": { "c": 3 } }, { "b": { "d": 1 } } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 10, "a": [ { "b": { "c": 3 } }, { "b": 2 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 11, "a": [ { "b": { "c": 3 } }, { } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 12, "a": [ { "b": { "c": 3 } }, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- baseline SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 13, "a": { "b": { "c": 0 } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) set documentdb.forceDisableSeqScan to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b.c_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "d" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "d" : { "$numberInt" : "1" } } } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { } ] } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "$numberInt" : "0" } } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "1" } } ] } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } } ] } } (13 rows) -- with forced order by scans, recheck of the index on the runtime needs to happen. reset documentdb.forceDisableSeqScan; SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 1, "a": "%s" }', repeat('a', 9999) || 'bb')::bson); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 2, "a": "%s" }', repeat('a', 9999) || 'cb')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 3, "a": "%s" }', repeat('a', 9999) || 'ab')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 4 does not match SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 4, "a": "%s" }', repeat('a', 9999) || 'ac')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "large_keys", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_2" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "large_keys", "pipeline": [ { "$match": { "a": { "$regex": ".+b$" } } }, { "$sort": { "a": 1 } }, { "$project": { "_id": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: a_2 isMultiKey: false indexBounds: ["a": ["", { })], ["a": [{ "$regularExpression" : { "pattern" : ".+b$", "options" : "" } }, { "$regularExpression" : { "pattern" : ".+b$", "options" : "" } }]] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4), (isInequality: false, estimatedEntryCount: 0)] -> Index Scan using a_2 on documents_68008_680016 collection (actual rows=3 loops=1) Index Cond: (document @~ '{ "a" : { "$regularExpression" : { "pattern" : ".+b$", "options" : "" } } }'::bson) Rows Removed by Index Recheck: 1 Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (11 rows) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "large_keys", "pipeline": [ { "$match": { "a": { "$regex": ".+b$" } } }, { "$sort": { "a": 1 } }, { "$project": { "_id": 1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } (3 rows) reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b.c_-1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b_-1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=13 loops=1) indexName: a.b.c_-1 isMultiKey: true indexBounds: ["a.b.c": DESC(MinKey, MaxKey), "_id": DESC(MinKey, MaxKey)] numDuplicates: 6 entries innerScanLoops: 19 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 19)] -> Index Scan using "a.b.c_-1" on documents_68007_680014 collection (actual rows=13 loops=1) Index Cond: ((document @<> '{ "a.b.c" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson)) Order By: ((document |-<> '{ "a.b.c" : { "$numberInt" : "-1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "-1" } }'::bson)) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=21 loops=1) indexName: a.b_-1 isMultiKey: true indexBounds: ["a.b": DESC(MinKey, MaxKey), "_id": DESC(MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 33)] -> Index Scan using "a.b_-1" on documents_68005_680010 collection (actual rows=21 loops=1) Index Cond: ((document @<> '{ "a.b" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson)) Order By: ((document |-<> '{ "a.b" : { "$numberInt" : "-1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "-1" } }'::bson)) (11 rows) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "d" : { "$numberInt" : "1" } } } ] } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } } ] } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "1" } } ] } ] } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "$numberInt" : "0" } } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "d" : { "$numberInt" : "1" } } } } (13 rows) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$maxKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$minKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : false } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "string value" } } { "_id" : { "$numberInt" : "16" }, "a" : [ null, { "b" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "19" }, "a" : [ { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "17" }, "a" : [ { }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "15" }, "a" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "20" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "18" }, "a" : [ { "c" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "14" }, "a" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "13" }, "a" : [ { } ] } { "_id" : { "$numberInt" : "12" }, "a" : null } { "_id" : { "$numberInt" : "21" }, "a" : { "b" : { "$minKey" : 1 } } } (21 rows) -- partial sort pushdown EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Incremental Sort (actual rows=13 loops=1) Sort Key: (bson_orderby(document, '{ "a.b.c" : { "$numberInt" : "-1" } }'::bson)) USING >>> NULLS LAST, (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Presorted Key: (bson_orderby(document, '{ "a.b.c" : { "$numberInt" : "-1" } }'::bson)) Full-sort Groups: 1 Sort Method: quicksort Average Memory: 26kB Peak Memory: 26kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=13 loops=1) indexName: a.b.c_-1 isMultiKey: true indexBounds: ["a.b.c": DESC(MinKey, MaxKey), "_id": DESC(MinKey, MaxKey)] numDuplicates: 6 entries innerScanLoops: 19 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 19)] -> Index Scan using "a.b.c_-1" on documents_68007_680014 collection (actual rows=13 loops=1) Index Cond: ((document @<> '{ "a.b.c" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson)) Order By: (document |-<> '{ "a.b.c" : { "$numberInt" : "-1" } }'::bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Incremental Sort (actual rows=21 loops=1) Sort Key: (bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::bson)) USING >>> NULLS LAST, (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Presorted Key: (bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::bson)) Full-sort Groups: 1 Sort Method: quicksort Average Memory: 27kB Peak Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=21 loops=1) indexName: a.b_-1 isMultiKey: true indexBounds: ["a.b": DESC(MinKey, MaxKey), "_id": DESC(MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 33)] -> Index Scan using "a.b_-1" on documents_68005_680010 collection (actual rows=21 loops=1) Index Cond: ((document @<> '{ "a.b" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson)) Order By: (document |-<> '{ "a.b" : { "$numberInt" : "-1" } }'::bson) (15 rows) -- mixed asc/desc indexes reset documentdb.forceDisableSeqScan; CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "sortcoll3", "index": "a.b.c_-1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "sortcoll", "index": "a.b_-1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) -- recreate with mixed asc/desc SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": 1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b.c_1_id-1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": -1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b_-1_id_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=13 loops=1) indexName: a.b.c_1_id-1 isMultiKey: true indexBounds: ["a.b.c": (MinKey, MaxKey), "_id": DESC(MinKey, MaxKey)] numDuplicates: 6 entries innerScanLoops: 19 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 19)] -> Index Scan using "a.b.c_1_id-1" on documents_68007_680014 collection (actual rows=13 loops=1) Index Cond: ((document @<> '{ "a.b.c" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson)) Order By: ((document |-<> '{ "a.b.c" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "-1" } }'::bson)) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=21 loops=1) indexName: a.b_-1_id_1 isMultiKey: true indexBounds: ["a.b": DESC(MinKey, MaxKey), "_id": (MinKey, MaxKey)] numDuplicates: 12 entries innerScanLoops: 33 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 33)] -> Index Scan using "a.b_-1_id_1" on documents_68005_680010 collection (actual rows=21 loops=1) Index Cond: ((document @<> '{ "a.b" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "_id" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson)) Order By: ((document |-<> '{ "a.b" : { "$numberInt" : "-1" } }'::bson) AND (document |-<> '{ "_id" : { "$numberInt" : "1" } }'::bson)) (11 rows) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": -1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "d" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "b" : { "c" : { "$numberInt" : "3" } } }, { "b" : { "d" : { "$numberInt" : "1" } } } ] } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } }, { } ] } } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "$numberInt" : "0" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "1" } } ] } ] } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } } ] } } (13 rows) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$maxKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$minKey" : 1 }, { "$numberInt" : "3" }, true ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : false } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "string value" } } { "_id" : { "$numberInt" : "16" }, "a" : [ null, { "b" : { "$numberInt" : "4" } } ] } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "15" }, "a" : [ { "$numberInt" : "1" }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "17" }, "a" : [ { }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "19" }, "a" : [ { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "20" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ ] } } { "_id" : { "$numberInt" : "12" }, "a" : null } { "_id" : { "$numberInt" : "13" }, "a" : [ { } ] } { "_id" : { "$numberInt" : "14" }, "a" : [ { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "18" }, "a" : [ { "c" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "21" }, "a" : { "b" : { "$minKey" : 1 } } } (21 rows) -- test order by functionality with group reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "ordering_groups", "indexes": [ { "key": { "a": 1 }, "enableOrderedIndex": true, "name": "a_1" }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- a is either 0 or 1 or 2 select COUNT(documentdb_api.insert_one('comp_db', 'ordering_groups', FORMAT('{ "_id": %s, "a": %s }', i , i % 3)::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) ANALYZE documentdb_data.documents_68009; set documentdb.forceDisableSeqScan to on; set documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "ordering_groups", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_0 (actual rows=3 loops=1) -> GroupAggregate (actual rows=3 loops=1) Group Key: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_1 isMultiKey: false indexBounds: ["a": (MinKey, MaxKey)] innerScanLoops: 3 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_1 on documents_68009_680018 collection (actual rows=100 loops=1) Index Cond: (document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) Order By: (document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) (13 rows) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "ordering_groups", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "c" : { "$numberInt" : "33" } } { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "34" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "33" } } (3 rows) -- sorting on prefix with missing path is not allowed unless it's equality. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "compOrderSkip", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1}, "name": "idx1", "enableOrderedIndex": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select COUNT(documentdb_api.insert_one('comp_db', 'compOrderSkip', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i , i, i % 5, i % 10, i % 20 )::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) -- now given that it's not multi-key, we can push down sorts to the index fully *iff* missing fields are equality. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": 2 }, "sort": { "a": 1, "b": 1, "d": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: idx1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [2, 2], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [1, 1], "b": [3, 3], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [3, 3], "c": [2, 2], "d": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using idx1 on documents_68010_680020 collection (actual rows=1 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "c" : { "$numberInt" : "2" } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "d" : { "$numberInt" : "1" } }'::bson)) (10 rows) -- cannot push non equality in the non-sorted prefix EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 5, 6 ]} }, "sort": { "a": 1, "b": 1, "d": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Incremental Sort (actual rows=0 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "b" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "d" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Presorted Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)), (bson_orderby(document, '{ "b" : { "$numberInt" : "1" } }'::bson)) Full-sort Groups: 1 Sort Method: quicksort Average Memory: 25kB Peak Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: idx1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "c": [5, 5], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [2, 2], "c": [5, 5], "d": (MinKey, MaxKey)], ["a": [1, 1], "b": [3, 3], "c": [5, 5], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [3, 3], "c": [5, 5], "d": (MinKey, MaxKey)], ["a": [1, 1], "b": [2, 2], "c": [6, 6], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [2, 2], "c": [6, 6], "d": (MinKey, MaxKey)], ["a": [1, 1], "b": [3, 3], "c": [6, 6], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [3, 3], "c": [6, 6], "d": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using idx1 on documents_68010_680020 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @*= '{ "c" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson)) (14 rows) -- once it's multi-key this isn't allowed. SELECT documentdb_api.insert_one('comp_db', 'compOrderSkip', FORMAT('{ "_id": %s, "a": [ %s, 2, 3 ], "b": %s, "c": %s, "d": %s }', 200, 201, 202, 203, 204 )::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": 2 }, "sort": { "a": 1, "b": 1, "d": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=1 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "b" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "d" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: idx1 isMultiKey: true indexBounds: ["a": [1, 1], "b": [2, 2], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [2, 2], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [1, 1], "b": [3, 3], "c": [2, 2], "d": (MinKey, MaxKey)], ["a": [2, 2], "b": [3, 3], "c": [2, 2], "d": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using idx1 on documents_68010_680020 collection (actual rows=1 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "c" : { "$numberInt" : "2" } }'::bson)) (12 rows) --composite index selection with order by. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_c_d_1" }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_d_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- insert 100 docs select COUNT(documentdb_api.insert_one('comp_db', 'index_orderby_selection', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i, i % 3, i % 10, i % 100, i )::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) ANALYZE documentdb_data.documents_68010; -- order by should use the order by filter index (a_b_c_1) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_b_c_d_1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [2, 2], "b": [2, 2], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [1, 1], "b": [3, 3], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [2, 2], "b": [3, 3], "c": (MinKey, MaxKey), "d": [10, 10]] innerScanLoops: 15 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using a_b_c_d_1 on documents_68011_680022 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "d" : { "$numberInt" : "10" } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "c" : { "$numberInt" : "1" } }'::bson)) (10 rows) -- if we're querying just filters, use a_b_d since it's better EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_b_d_1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "d": [10, 10]], ["a": [2, 2], "b": [2, 2], "d": [10, 10]], ["a": [1, 1], "b": [3, 3], "d": [10, 10]], ["a": [2, 2], "b": [3, 3], "d": [10, 10]] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Index Scan using a_b_d_1 on documents_68011_680022 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "d" : { "$numberInt" : "10" } }'::bson)) (9 rows) set documentdb.enableIndexOrderbyPushdownLegacy to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Incremental Sort (actual rows=0 loops=1) Sort Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "b" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST, (bson_orderby(document, '{ "c" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Presorted Key: (bson_orderby(document, '{ "a" : { "$numberInt" : "1" } }'::bson)), (bson_orderby(document, '{ "b" : { "$numberInt" : "1" } }'::bson)) Full-sort Groups: 1 Sort Method: quicksort Average Memory: 25kB Peak Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_b_d_1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "d": [10, 10]], ["a": [2, 2], "b": [2, 2], "d": [10, 10]], ["a": [1, 1], "b": [3, 3], "d": [10, 10]], ["a": [2, 2], "b": [3, 3], "d": [10, 10]] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Index Scan using a_b_d_1 on documents_68011_680022 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "d" : { "$numberInt" : "10" } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson)) (14 rows) -- the same should work if the indexes were created in the reverse order CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_c_d_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_d_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_d_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_c_d_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set documentdb.enableIndexOrderbyPushdownLegacy to off; -- order by should use the order by filter index (a_b_c_1) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_b_c_d_1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [2, 2], "b": [2, 2], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [1, 1], "b": [3, 3], "c": (MinKey, MaxKey), "d": [10, 10]], ["a": [2, 2], "b": [3, 3], "c": (MinKey, MaxKey), "d": [10, 10]] innerScanLoops: 15 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Index Scan using a_b_c_d_1 on documents_68011_680022 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "d" : { "$numberInt" : "10" } }'::bson)) Order By: ((document |-<> '{ "a" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "b" : { "$numberInt" : "1" } }'::bson) AND (document |-<> '{ "c" : { "$numberInt" : "1" } }'::bson)) (10 rows) -- if we're querying just filters, use a_b_d since it's better EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: a_b_d_1 isMultiKey: false indexBounds: ["a": [1, 1], "b": [2, 2], "d": [10, 10]], ["a": [2, 2], "b": [2, 2], "d": [10, 10]], ["a": [1, 1], "b": [3, 3], "d": [10, 10]], ["a": [2, 2], "b": [3, 3], "d": [10, 10]] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Index Scan using a_b_d_1 on documents_68011_680022 collection (actual rows=0 loops=1) Index Cond: ((document @*= '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::bson) AND (document @*= '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (document @= '{ "d" : { "$numberInt" : "10" } }'::bson)) (9 rows) -- order by backward scan with unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "unique_sort", "indexes": [ { "key": { "a": 1, "b": 1 }, "enableOrderedIndex": true, "name": "a_b_1", "unique": true }] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select COUNT(documentdb_api.insert_one('comp_db', 'unique_sort', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i, i, i, i, i )::bson)) FROM generate_series(1, 100) AS i; count --------------------------------------------------------------------- 100 (1 row) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "unique_sort", "sort": { "a": -1, "b": -1 }}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: a_b_1 isMultiKey: false indexBounds: ["a": (MinKey, MaxKey), "b": (MinKey, MaxKey)] isBackwardScan: true innerScanLoops: 100 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 100)] -> Index Scan using a_b_1 on documents_68012_680024 collection (actual rows=100 loops=1) Index Cond: ((document @<> '{ "a" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson) AND (document @<> '{ "b" : { "orderByScan" : { "$numberInt" : "-1" } } }'::bson)) Order By: ((document <>-| '{ "a" : { "$numberInt" : "-1" } }'::bson) AND (document <>-| '{ "b" : { "$numberInt" : "-1" } }'::bson)) (11 rows) -- test index selectivity for orderby vs filters. CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_c_d_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_d_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) TRUNCATE documentdb_data.documents_68011; ANALYZE documentdb_data.documents_68011; -- now create 2 types of indexes: One that only matches the order by and one that matches the order and filters SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "orderKey": 1, "otherPath": 1 }, "enableOrderedIndex": true, "name": "sortIndex_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "filter1": 1, "filter2": 1, "orderKey": 1, "filter3": 1 }, "enableOrderedIndex": true, "name": "filterSortIndex_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT COUNT(*) FROM ( SELECT documentdb_api.insert_one('comp_db', 'index_orderby_selection', FORMAT('{ "_id": %s, "filter1": "filter1-%s", "filter2": "filter2-%s", "filter3": %s, "orderKey": %s, "otherPath": "somePath-%s" }', i, i % 10, i, i % 100, i, i)::bson) FROM generate_series(1, 10000) i) j; count --------------------------------------------------------------------- 10000 (1 row) set documentdb.enableIndexOrderbyPushdown to on; reset enable_sort; -- this has all the paths matching. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": "filter2-55", "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=1 loops=1) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: filterSortIndex_1 isMultiKey: false indexBounds: ["filter1": ["filter1-5", "filter1-5"], "filter2": ["filter2-55", "filter2-55"], "orderKey": (MinKey, MaxKey), "filter3": (50, Infinity]] innerScanLoops: 2 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Index Scan using "filterSortIndex_1" on documents_68011_680022 collection (actual rows=1 loops=1) Index Cond: ((document @= '{ "filter1" : "filter1-5" }'::bson) AND (document @= '{ "filter2" : "filter2-55" }'::bson) AND (document @> '{ "filter3" : { "$numberInt" : "50" } }'::bson)) Order By: (document |-<> '{ "orderKey" : { "$numberInt" : "1" } }'::bson) (11 rows) -- this one can't push the order by but should prefer the filter. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": { "$gte": "filter2-55" }, "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Sort (actual rows=10 loops=1) Sort Key: (bson_orderby(document, '{ "orderKey" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=255 loops=1) indexName: filterSortIndex_1 isMultiKey: false indexBounds: ["filter1": ["filter1-5", "filter1-5"], "filter2": ["filter2-55", { }), "orderKey": (MinKey, MaxKey), "filter3": (50, Infinity]] innerScanLoops: 501 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 36)] -> Index Scan using "filterSortIndex_1" on documents_68011_680022 collection (actual rows=255 loops=1) Index Cond: ((document @= '{ "filter1" : "filter1-5" }'::bson) AND (document @>= '{ "filter2" : "filter2-55" }'::bson) AND (document @> '{ "filter3" : { "$numberInt" : "50" } }'::bson)) (13 rows) SELECT documentdb_api.coll_mod('comp_db', 'index_orderby_selection', '{ "collMod": "index_orderby_selection", "index": { "name": "filterSortIndex_1", "hidden": true }}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : false, "hidden_new" : true } (1 row) -- now it picks the sort index EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": { "$gte": "filter2-55" }, "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=10 loops=1) indexName: sortIndex_1 isMultiKey: false indexBounds: ["orderKey": (MinKey, MaxKey), "otherPath": (MinKey, MaxKey)] innerScanLoops: 595 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 595)] -> Index Scan using "sortIndex_1" on documents_68011_680022 collection (actual rows=10 loops=1) Index Cond: (document @<> '{ "orderKey" : { "orderByScan" : { "$numberInt" : "1" } } }'::bson) Order By: (document |-<> '{ "orderKey" : { "$numberInt" : "1" } }'::bson) Filter: ((document @= '{ "filter1" : "filter1-5" }'::bson) AND (document @>= '{ "filter2" : "filter2-55" }'::bson) AND (document @> '{ "filter3" : { "$numberInt" : "50" } }'::bson)) Rows Removed by Filter: 585 (13 rows) bson_composite_prefer_ordered_tests.out000066400000000000000000000735331507310017400400530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 685000; SET documentdb.next_collection_id TO 68500; SET documentdb.next_collection_index_id TO 68500; set documentdb.enableExtendedExplainPlans to on; set documentdb.enableIndexOrderbyPushdown to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) SELECT documentdb_api.drop_collection('comp_db2', 'query_ordered_pref') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('comp_db2', 'query_ordered_pref'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "query_ordered_pref", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_68501 Table "documentdb_data.documents_68501" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_68501" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_68502" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "a" ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '68501'::bigint) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'query_ordered_pref', FORMAT('{ "_id": %s, "a": %s }', i, i)::bson)) FROM generate_series(1, 10000) AS i; count --------------------------------------------------------------------- 10000 (1 row) ANALYZE documentdb_data.documents_68501; set enable_bitmapscan to off; set documentdb.forceDisableSeqScan to on; set documentdb_rum.preferOrderedIndexScan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50 } }, "projection": { "_id": 1 }, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=5 loops=1) Output: (bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) Output: bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: a_1 isMultiKey: false indexBounds: ["a": (50, Infinity]] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9950)] -> Index Scan using a_1 on documentdb_data.documents_68501_685002 collection (actual rows=5 loops=1) Output: document Index Cond: (collection.document @> '{ "a" : { "$numberInt" : "50" } }'::bson) (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50, "$lt": 900 } }, "projection": { "_id": 1 }, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=5 loops=1) Output: (bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" }, "$lt" : { "$numberInt" : "900" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) Output: bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" }, "$lt" : { "$numberInt" : "900" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: a_1 isMultiKey: false indexBounds: ["a": (50, 900)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 849)] -> Index Scan using a_1 on documentdb_data.documents_68501_685002 collection (actual rows=5 loops=1) Output: document Index Cond: ((collection.document @> '{ "a" : { "$numberInt" : "50" } }'::bson) AND (collection.document @< '{ "a" : { "$numberInt" : "900" } }'::bson)) (13 rows) set documentdb_rum.preferOrderedIndexScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50 } }, "projection": { "_id": 1 }, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=5 loops=1) Output: (bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) Output: bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: a_1 isMultiKey: false indexBounds: ["a": (50, Infinity]] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Scan using a_1 on documentdb_data.documents_68501_685002 collection (actual rows=5 loops=1) Output: document Index Cond: (collection.document @> '{ "a" : { "$numberInt" : "50" } }'::bson) (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50, "$lt": 900 } }, "projection": { "_id": 1 }, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=5 loops=1) Output: (bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" }, "$lt" : { "$numberInt" : "900" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson)) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) Output: bson_dollar_project_find(document, '{ "_id" : { "$numberInt" : "1" } }'::bson, '{ "a" : { "$gt" : { "$numberInt" : "50" }, "$lt" : { "$numberInt" : "900" } } }'::bson, '{ "now" : NOW_SYS_VARIABLE }'::bson) indexName: a_1 isMultiKey: false indexBounds: ["a": (50, 900)] innerScanLoops: 6 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Index Scan using a_1 on documentdb_data.documents_68501_685002 collection (actual rows=5 loops=1) Output: document Index Cond: ((collection.document @> '{ "a" : { "$numberInt" : "50" } }'::bson) AND (collection.document @< '{ "a" : { "$numberInt" : "900" } }'::bson)) (13 rows) -- test ordered scan in the presence of deletes set documentdb.enableExtendedExplainPlans to off; reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "ordered_delete", "indexes": [ { "key": { "a": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": %s }', i, i % 50)::bson)) FROM generate_series(1, 100) i; count --------------------------------------------------------------------- 100 (1 row) ANALYZE documentdb_data.documents_68502; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using a_1 on documentdb_data.documents_68502_685004 collection (actual rows=8 loops=1) Output: document Index Cond: (collection.document @< '{ "a" : { "$numberInt" : "4" } }'::bson) (3 rows) -- now delete everthing reset documentdb.forceDisableSeqScan; DELETE FROM documentdb_data.documents_68502; -- vacuum the table VACUUM documentdb_data.documents_68502; -- query the data set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using a_1 on documentdb_data.documents_68502_685004 collection (actual rows=0 loops=1) Output: document Index Cond: (collection.document @< '{ "a" : { "$numberInt" : "4" } }'::bson) (3 rows) -- now try with a posting tree at the end. reset documentdb.forceDisableSeqScan; CALL documentdb_api.drop_indexes('comp_db2', '{ "dropIndexes": "ordered_delete", "index": "a_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "ordered_delete", "indexes": [ { "key": { "a": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 1 }', i)::bson)) FROM generate_series(1, 5000) i; count --------------------------------------------------------------------- 5000 (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 2 }', i)::bson)) FROM generate_series(10001, 15000) i; count --------------------------------------------------------------------- 5000 (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 3 }', i)::bson)) FROM generate_series(20001, 25000) i; count --------------------------------------------------------------------- 5000 (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 4 }', i)::bson)) FROM generate_series(30001, 35000) i; count --------------------------------------------------------------------- 5000 (1 row) ANALYZE documentdb_data.documents_68502; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lte": 4 } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using a_1 on documentdb_data.documents_68502_685004 collection (actual rows=20000 loops=1) Output: document Index Cond: (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) (3 rows) -- delete the first half of TIDs from some of the posting trees DELETE FROM documentdb_data.documents_68502 WHERE object_id >= '{ "": 10001 }' AND object_id < '{ "": 12000 }'; DELETE FROM documentdb_data.documents_68502 WHERE object_id >= '{ "": 20001 }' AND object_id < '{ "": 22500 }'; VACUUM documentdb_data.documents_68502; reset documentdb.forceDisableSeqScan; set enable_indexscan to off; set enable_bitmapscan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lte": 4 } } }'); QUERY PLAN --------------------------------------------------------------------- Seq Scan on documentdb_data.documents_68502_685004 collection (actual rows=15502 loops=1) Output: document Filter: (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) (3 rows) SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5000" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3001" } } { "_id" : { "$numberInt" : "4" }, "c" : { "$numberInt" : "5000" } } { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2501" } } (4 rows) reset enable_indexscan; reset enable_bitmapscan; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE OFF, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); QUERY PLAN --------------------------------------------------------------------- Subquery Scan on agg_stage_1 Output: bson_repath_and_build(agg_stage_1.c1, agg_stage_1.c2, agg_stage_1.c3, agg_stage_1.c4) -> HashAggregate Output: '_id'::text, (bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson)), 'c'::text, bsonsum('{ "" : { "$numberInt" : "1" } }'::bson) Group Key: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) -> Bitmap Heap Scan on documentdb_data.documents_68502_685004 collection Output: bson_expression_get(collection.document, '{ "" : "$a" }'::bson, true, '{ "now" : NOW_SYS_VARIABLE }'::bson) Recheck Cond: (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) -> Bitmap Index Scan on a_1 Index Cond: (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) (10 rows) SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "5000" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3001" } } { "_id" : { "$numberInt" : "4" }, "c" : { "$numberInt" : "5000" } } { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2501" } } (4 rows) -- now delete everthing reset documentdb.forceDisableSeqScan; DELETE FROM documentdb_data.documents_68502; -- vacuum the table VACUUM documentdb_data.documents_68502; -- query the data set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using a_1 on documentdb_data.documents_68502_685004 collection (actual rows=0 loops=1) Output: document Index Cond: (collection.document @< '{ "a" : { "$numberInt" : "4" } }'::bson) (3 rows) -- test scan skipping behavior. reset documentdb.forceDisableSeqScan; SELECT COUNT(documentdb_api.insert_one('comp_db2', 'skip_entry_asc', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s }', ((i * 100) + (j * 10) + k), i, j, k)::bson)) FROM generate_series(1, 5) i, generate_series(1, 10) j, generate_series(1, 100) k; NOTICE: creating collection count --------------------------------------------------------------------- 5000 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "skip_entry_asc", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT COUNT(documentdb_api.insert_one('comp_db2', 'skip_entry_desc', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s }', ((i * 100) + (j * 10) + k), i, j, k)::bson)) FROM generate_series(1, 5) i, generate_series(1, 10) j, generate_series(1, 100) k; NOTICE: creating collection count --------------------------------------------------------------------- 5000 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "skip_entry_desc", "indexes": [ { "key": { "a": -1, "b": -1, "c": -1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_68503; -- now test the behavior of partial skipping set documentdb.forceDisableSeqScan to on; set documentdb.enableExtendedExplainPlans to on; set documentdb_rum.enableSkipIntermediateEntry to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=90 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": [2, 4], "b": (MinKey, MaxKey), "c": [3, 5]] innerScanLoops: 301 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 90)] -> Index Scan using a_1 on documentdb_data.documents_68503_685006 collection (actual rows=90 loops=1) Output: document Index Cond: ((collection.document @>= '{ "a" : { "$numberInt" : "2" } }'::bson) AND (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_desc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=90 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": DESC[2, 4], "b": DESC(MinKey, MaxKey), "c": DESC[3, 5]] innerScanLoops: 301 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 90)] -> Index Scan using a_1 on documentdb_data.documents_68504_685008 collection (actual rows=90 loops=1) Output: document Index Cond: ((collection.document @>= '{ "a" : { "$numberInt" : "2" } }'::bson) AND (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$in": [ 2, 3 ] }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=60 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": [2, 2], "b": (MinKey, MaxKey), "c": [3, 5]], ["a": [3, 3], "b": (MinKey, MaxKey), "c": [3, 5]] innerScanLoops: 60 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 30), (isInequality: true, estimatedEntryCount: 30)] -> Index Scan using a_1 on documentdb_data.documents_68503_685006 collection (actual rows=60 loops=1) Output: document Index Cond: ((collection.document @*= '{ "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) -- with skip entries on we skip relevant portions of the tree set documentdb_rum.enableSkipIntermediateEntry to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=90 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": [2, 4], "b": (MinKey, MaxKey), "c": [3, 5]] innerScanLoops: 151 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 21)] -> Index Scan using a_1 on documentdb_data.documents_68503_685006 collection (actual rows=90 loops=1) Output: document Index Cond: ((collection.document @>= '{ "a" : { "$numberInt" : "2" } }'::bson) AND (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_desc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=90 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": DESC[2, 4], "b": DESC(MinKey, MaxKey), "c": DESC[3, 5]] innerScanLoops: 151 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 15)] -> Index Scan using a_1 on documentdb_data.documents_68504_685008 collection (actual rows=90 loops=1) Output: document Index Cond: ((collection.document @>= '{ "a" : { "$numberInt" : "2" } }'::bson) AND (collection.document @<= '{ "a" : { "$numberInt" : "4" } }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$in": [ 2, 3 ] }, "c": { "$gte": 3, "$lte": 5 } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=60 loops=1) Output: document indexName: a_1 isMultiKey: false indexBounds: ["a": [2, 2], "b": (MinKey, MaxKey), "c": [3, 5]], ["a": [3, 3], "b": (MinKey, MaxKey), "c": [3, 5]] innerScanLoops: 60 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 30), (isInequality: true, estimatedEntryCount: 30)] -> Index Scan using a_1 on documentdb_data.documents_68503_685006 collection (actual rows=60 loops=1) Output: document Index Cond: ((collection.document @*= '{ "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::bson) AND (collection.document @>= '{ "c" : { "$numberInt" : "3" } }'::bson) AND (collection.document @<= '{ "c" : { "$numberInt" : "5" } }'::bson)) (11 rows) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/bson_decimal128.out000066400000000000000000002465631507310017400334750ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 176000; SET documentdb.next_collection_id TO 17600; SET documentdb.next_collection_index_id TO 17600; SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1.0" },"_id":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1" },"_id":2,"b":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-1.0" },"_id":3,"b":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "NaN" },"_id":4,"b":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-NaN" },"_id":5,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "Infinity" },"_id":6,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-Infinity" },"_id":7,"b":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "2234567832345678423.28293013835682" },"_id":8,"b":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "141592653.950332e2013" },"_id":9,"b":9}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "0" },"_id":10,"b":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberLong": "1" },"_id":11,"b":11}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberLong": "-1" },"_id":12,"b":12}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberInt": "1" },"_id":13,"b":13}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberInt": "-1" },"_id":14,"b":14}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "-1.00" },"_id":15,"b":15}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "1.00" },"_id":16,"b":16}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": [{ "$numberDecimal": "1.00" }, { "$numberDecimal": "2.00" }, { "$numberDecimal": "3.50" }, { "$numberDecimal": "5.00001" }],"_id":17,"b":17}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "NaN" },"_id":18,"b":15}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- Basic find queries SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "Inf"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-Inf"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "NaN"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-NaN"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "1"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "1.0000000"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-1"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-1.00000"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "2234567832345678423.28293013835682"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } (1 row) --find with order by SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') ORDER BY bson_orderby(document, '{ "a": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') ORDER BY bson_orderby(document, '{ "a": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (18 rows) -- comparision operations SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (14 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @<= '{ "a": {"$numberDecimal": "Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (15 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "Infinity"} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "-Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (14 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @>= '{ "a": {"$numberDecimal": "-Infinity"} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (15 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "-Infinity"} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : 2} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "5.00001"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "5.00001"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "5.02"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "5.00001"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$in" : [{"$numberDecimal": "5.00001"}, {"$numberDecimal": "inf"}] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$ne" : {"$numberDecimal": "5.00001"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (17 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$nin" : [{"$numberDecimal": "-1"}, {"$numberDecimal": "inf"}, {"$numberDecimal": "-inf"}]} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (12 rows) -- logical find queries SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-Infinity"}}}, {"a" : {"$lt" : { "$numberDecimal" : "Infinity"}}}] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$or": [{ "a": {"$gt": { "$numberDecimal" : "5"}}}, {"a" : {"$lt" : { "$numberDecimal" : "-5"}}}] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$nor": [{ "a": {"$gt": { "$numberDecimal" : "5"}}}, {"a" : {"$lt" : { "$numberDecimal" : "-5"}}}] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-1.0" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberLong" : "-1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "-1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDouble" : "-1.0" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": { "$not": {"$gt": { "$numberDecimal" : "-5"} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "NaN" }, "b" : { "$numberInt" : "5" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "-Infinity" }, "b" : { "$numberInt" : "7" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : { "$numberDouble" : "NaN" }, "b" : { "$numberInt" : "15" } } (4 rows) -- query element operator SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$exists": true, "$gt": { "$numberDecimal" : "5"} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "Infinity" }, "b" : { "$numberInt" : "6" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDecimal" : "2234567832345678423.28293013835682" }, "b" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "$numberDecimal" : "1.41592653950332E+2021" }, "b" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (4 rows) -- array query operators SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$all": [{ "$numberDecimal": "1.00" }, { "$numberDecimal": "2.00" }, { "$numberDecimal": "3.50" }, { "$numberDecimal": "5.00001" }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$elemMatch": { "$gt": {"$numberDecimal": "3"}, "$lt": {"$numberDecimal": "5.2"}} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (1 row) -- Update operations with $mul and $inc BEGIN; SELECT documentdb_api.update('db', '{"update": "decimal128", "updates":[{"q": {"a": -1},"u":{"$mul":{"a": {"$numberDecimal": "11.1"}}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""4"" }, ""n"" : { ""$numberInt"" : ""4"" } }",t) (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gte": { "$numberDecimal" : "-11.1"}}}, {"a" : {"$lte" : { "$numberDecimal" : "11.1"}}}] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1.0" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1" }, "b" : { "$numberInt" : "2" } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "-11.10" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "$numberDecimal" : "0" }, "b" : { "$numberInt" : "10" } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : { "$numberLong" : "1" }, "b" : { "$numberInt" : "11" } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : { "$numberDecimal" : "-11.1" }, "b" : { "$numberInt" : "12" } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "13" } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "$numberDecimal" : "-11.1" }, "b" : { "$numberInt" : "14" } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "$numberDecimal" : "-11.100000000000000" }, "b" : { "$numberInt" : "15" } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "$numberDouble" : "1.0" }, "b" : { "$numberInt" : "16" } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ { "$numberDecimal" : "1.00" }, { "$numberDecimal" : "2.00" }, { "$numberDecimal" : "3.50" }, { "$numberDecimal" : "5.00001" } ], "b" : { "$numberInt" : "17" } } (11 rows) ROLLBACK; BEGIN; SELECT documentdb_api.update('db', '{"update": "decimal128", "updates":[{"q": {"a": 1},"u":{"$inc":{"a": {"$numberDecimal": "50.012e2"}}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""67108893"" }, ""errmsg"" : ""Operation $inc cannot be performed because the target value is not numeric. Document { _id: 17 } contains the field 'a' which is of non-numeric type array."" } ] }",f) (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gte": {"$numberInt": "5000"}}}, {"a" : {"$lte" : {"$numberInt": "5003"}}}] }'; object_id | document --------------------------------------------------------------------- (0 rows) ROLLBACK; -- Overflow operation with decimal128 SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "9.999999999999999999999999999999999e6144"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "Infinity" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-9.999999999999999999999999999999999e6144"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-Infinity" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "9.999999999999999999999999999999999e6144"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "1.111111111111111111111111111111111e6144"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "Infinity" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-9.999999999999999999999999999999999e6144"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "-1.111111111111111111111111111111111e6144"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-Infinity" } } } (1 row) -- Testing index on decimal 128 values -- BUG: Without this queries always seem to prefer the primary key index. SELECT documentdb_distributed_test_helpers.drop_primary_key('db','decimal128'); drop_primary_key --------------------------------------------------------------------- (1 row) -- Creating an index on the 'a' which is d128 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('decimal128', 'd128_path_a', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- EXPLAIN QUERIES EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberDecimal" : "Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @<= '{ "a": {"$numberDecimal": "Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberDecimal" : "Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberDecimal" : "Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "-Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberDecimal" : "-Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @>= '{ "a": {"$numberDecimal": "-Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberDecimal" : "-Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "-Infinity"} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberDecimal" : "-Infinity" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-Infinity"}}}, {"a" : {"$lt" : { "$numberDecimal" : "Infinity"}}}] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberDecimal" : "-Infinity" }, "max" : { "$numberDecimal" : "Infinity" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-2"}}}, {"a" : {"$lt" : { "$numberDecimal" : "2"}}}] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using d128_path_a on documents_17600_176000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberDecimal" : "-2" }, "max" : { "$numberDecimal" : "2" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (7 rows) ROLLBACK; -- Testing cases where decimal128 operations will signal exception with intel math lib and validating if these matches protocol defined behavior -- Testing to decimal128 conversion methods using $mul, because $convert is not implemented yet (decimal128 to other types can't be tested now) -- TODO Add proper test after implementing $convert SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "2147483647" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "-2147483648"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-2147483648" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "9223372036854775807" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "-9223372036854775808"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-9223372036854775808" } } } (1 row) -- normal & inexact double conversion SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "-9.99000000000000000e+02"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-999.000000000000" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "9.535874331e+301"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "9.53587433100000E+301" } } } (1 row) -- Inexact result SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+6794057649266099302E-6176"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+4548926796094754899573057849605421E+2026"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "3.090567089495909909951447112206867E-4098" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+6794057649266099302E-6176"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "+4548926796094754899573057849605421E+2026"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "4.548926796094754899573057849605421E+2059" } } } (1 row) -- Overflow signal with inexact SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+9579756848909076089047118570486504E+6111"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+1938648456739575048278564590634903E+6111"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "Infinity" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+9579756848909076089047118570486504E+6111"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "+1938648456739575048278564590634903E+6111"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "Infinity" } } } (1 row) -- Underflow signal with inexact (no test case found for $inc) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-7548269564658974956438658719038456E-6120"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+9875467895987245907845734785643106E-2179"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "-0E-6176" } } } (1 row) -- Invalid exceptions are skipped because no valid test cases found (this is generally signalled if "SNaN" is part of operation which is not valid Decimal128 value to store) -- TEST for double and decimal128 ordering SELECT documentdb_api.delete('db', '{"delete":"decimal128", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""18"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "0.3" },"_id":1,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "0.3" },"_id":2,"b":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "0.2999999999999999889" }, "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "0.3"}} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "0.3" }, "b" : { "$numberInt" : "2" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "0.2999999999999999889" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "0.3" }, "b" : { "$numberInt" : "2" } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDouble": "0.3"}} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDouble": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "0.3" }, "b" : { "$numberInt" : "2" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDouble": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "0.2999999999999999889" }, "b" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "0.3" }, "b" : { "$numberInt" : "2" } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDouble": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "0.2999999999999999889" }, "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDouble": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "0.2999999999999999889" }, "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDecimal": "0.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "0.3" }, "b" : { "$numberInt" : "2" } } (1 row) SELECT documentdb_api.delete('db', '{"delete":"decimal128", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "1.3" },"_id":3,"b":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1.3" },"_id":4,"b":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "1.3"}} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.3000000000000000444" }, "b" : { "$numberInt" : "3" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.3000000000000000444" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "1.3" }, "b" : { "$numberInt" : "4" } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "1.3" }, "b" : { "$numberInt" : "4" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDouble": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "1.3" }, "b" : { "$numberInt" : "4" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDouble": "1.3"}} }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDouble": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.3000000000000000444" }, "b" : { "$numberInt" : "3" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDouble": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.3000000000000000444" }, "b" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "1.3" }, "b" : { "$numberInt" : "4" } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDouble": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.3000000000000000444" }, "b" : { "$numberInt" : "3" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDecimal": "1.3"}} }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "1.3" }, "b" : { "$numberInt" : "4" } } (1 row) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/bson_deduplicate.out000066400000000000000000000061151507310017400341120ustar00rootroot00000000000000SET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 4600000; SET documentdb.next_collection_id TO 4600; SET documentdb.next_collection_index_id TO 4600; SELECT documentdb_api_internal.bson_deduplicate_fields(null); ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields(null)... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{}') = '{}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{}')... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{"a":1, "a": 1}') = '{"a":1}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{"a"... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{"a":1, "a": 1}') = '{"a":1}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{"a"... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "b": [{"c": 1, "c": 2}, {"c": {"e": 1, "z": [], "e": 2}}], "a": null}') = '{"a": null, "b" : [{"c": 2}, {"c": {"e": 2, "z": []}}]}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{"a"... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "b": [{"c": 1, "c": [1, 1, "text", {"d": 1, "d": 2}]}, {"c": {"e": 1, "e": 2}}], "a": 2}') = '{"a": 2, "b": [{"c": [1, 1, "text", {"d": 2}]}, {"c": {"e": 2}}]}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{"a"... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "a.b": 2, "a.b.c": "text"}') = '{"a": 1, "a.b": 2, "a.b.c": "text"}'; ERROR: function documentdb_api_internal.bson_deduplicate_fields(unknown) does not exist LINE 1: SELECT documentdb_api_internal.bson_deduplicate_fields('{"a"... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. bson_dollar_operators_negation_tests_explain_index.out000066400000000000000000000512171507310017400431430ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 514000; SET documentdb.next_collection_id TO 5140; SET documentdb.next_collection_index_id TO 5140; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests_explain'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'simple_negation_tests_explain'); create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "simple_negation_tests_explain", "indexes": [{ "key": { "$**": 1 }, "name": "myIdx1" }] }'::documentdb_core.bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET local search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_explain_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @> '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @> '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) -- do the complement EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @<= '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @<= '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) -- do the NOTs EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE (documentdb_api_internal.bson_dollar_not_gt(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_internal.@!>) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document OPERATOR(documentdb_api_internal.@!>) '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE (documentdb_api_internal.bson_dollar_not_lte(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_internal.@!<=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document OPERATOR(documentdb_api_internal.@!<=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) -- Now try $gte/$lt EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @>= '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @>= '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @< '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @< '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE (documentdb_api_internal.bson_dollar_not_gte(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_internal.@!>=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document OPERATOR(documentdb_api_internal.@!>=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE (documentdb_api_internal.bson_dollar_not_lt(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_internal.@!<) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document OPERATOR(documentdb_api_internal.@!<) '{ "a.b" : { "$numberInt" : "2" } }'::bson) (12 rows) -- $gte: Minkey (Exists doesn't factor in this) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": true } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @>= '{ "a.b" : { "$minKey" : 1 } }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @>= '{ "a.b" : { "$minKey" : 1 } }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": false } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE (documentdb_api_catalog.bson_dollar_exists(document, '{ "a.b" : false }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.document @? '{ "a.b" : false }'::bson) -> Bitmap Index Scan on "myIdx1" Index Cond: (collection.document @? '{ "a.b" : false }'::bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((NOT COALESCE((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery), false)) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.shard_key_value = '5140'::bigint) Filter: (NOT COALESCE((collection.document #>= '{ "a.b" : { "$minKey" : 1 } }'::bsonquery), false)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5140'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5140_514007 collection WHERE ((NOT COALESCE(documentdb_api_catalog.bson_dollar_exists(document, '{ "a.b" : false }'::documentdb_core.bson), false)) AND (shard_key_value OPERATOR(pg_catalog.=) '5140'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5140_514007 collection Output: document Recheck Cond: (collection.shard_key_value = '5140'::bigint) Filter: (NOT COALESCE(bson_dollar_exists(collection.document, '{ "a.b" : false }'::bson), false)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5140'::bigint) (13 rows) ROLLBACK; bson_dollar_operators_negation_tests_explain_runtime.out000066400000000000000000000503441507310017400435170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 513000; SET documentdb.next_collection_id TO 5130; SET documentdb.next_collection_index_id TO 5130; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests_explain'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'simple_negation_tests_explain'); create_collection --------------------------------------------------------------------- t (1 row) BEGIN; SET local search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; \o /dev/null \o set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_explain_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @> '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) -- do the complement EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @<= '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) -- do the NOTs EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE (documentdb_api_internal.bson_dollar_not_gt(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document OPERATOR(documentdb_api_internal.@!>) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE (documentdb_api_internal.bson_dollar_not_lte(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document OPERATOR(documentdb_api_internal.@!<=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) -- Now try $gte/$lt EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @>= '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @< '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE (documentdb_api_internal.bson_dollar_not_gte(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document OPERATOR(documentdb_api_internal.@!>=) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE (documentdb_api_internal.bson_dollar_not_lt(document, '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document OPERATOR(documentdb_api_internal.@!<) '{ "a.b" : { "$numberInt" : "2" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) -- $gte: Minkey (Exists doesn't factor in this) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": true } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @>= '{ "a.b" : { "$minKey" : 1 } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": false } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE (documentdb_api_catalog.bson_dollar_exists(document, '{ "a.b" : false }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (collection.document @? '{ "a.b" : false }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((NOT COALESCE((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery), false)) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (NOT COALESCE((collection.document #>= '{ "a.b" : { "$minKey" : 1 } }'::bsonquery), false)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5130_513007 collection WHERE ((NOT COALESCE(documentdb_api_catalog.bson_dollar_exists(document, '{ "a.b" : false }'::documentdb_core.bson), false)) AND (shard_key_value OPERATOR(pg_catalog.=) '5130'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_5130_513007 collection Output: document Recheck Cond: (collection.shard_key_value = '5130'::bigint) Filter: (NOT COALESCE(bson_dollar_exists(collection.document, '{ "a.b" : false }'::bson), false)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '5130'::bigint) (13 rows) ROLLBACK; bson_dollar_operators_negation_tests_index.out000066400000000000000000000557201507310017400414260ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 512000; SET documentdb.next_collection_id TO 5120; SET documentdb.next_collection_index_id TO 5120; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests') IS NULL; ?column? --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'simple_negation_tests') IS NULL; ?column? --------------------------------------------------------------------- f (1 row) \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "simple_negation_tests", "indexes": [{ "key": { "$**": 1 }, "name": "myIdx1" }] }', TRUE); \o BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (1 row) -- do the complement SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } (3 rows) -- do the NOTs SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (7 rows) -- Now try $gte/$lt SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) -- $gte: Minkey (Exists doesn't factor in this) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": true } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": false } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) ROLLBACK; SELECT documentdb_api.shard_collection('db', 'simple_negation_tests', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (1 row) -- do the complement SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (3 rows) -- do the NOTs SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (7 rows) -- Now try $gte/$lt SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) -- $gte: Minkey (Exists doesn't factor in this) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": true } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": false } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) ROLLBACK; bson_dollar_operators_negation_tests_runtime.out000066400000000000000000000554341507310017400420040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 512000; SET documentdb.next_collection_id TO 5120; SET documentdb.next_collection_index_id TO 5120; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests') IS NULL; ?column? --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'simple_negation_tests') IS NULL; ?column? --------------------------------------------------------------------- f (1 row) \o /dev/null \o BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (1 row) -- do the complement SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } (3 rows) -- do the NOTs SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (7 rows) -- Now try $gte/$lt SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) -- $gte: Minkey (Exists doesn't factor in this) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": true } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": false } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) ROLLBACK; SELECT documentdb_api.shard_collection('db', 'simple_negation_tests', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 4, "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a search SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } (1 row) -- do the complement SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (3 rows) -- do the NOTs SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (7 rows) -- Now try $gte/$lt SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (8 rows) -- $gte: Minkey (Exists doesn't factor in this) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": true } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": false } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : null } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberDouble" : "Infinity" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : "stringb8" } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : "stringb9" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : "stringb10" } } (10 rows) ROLLBACK; bson_dollar_ops_basic_compare_tests_errors.out000066400000000000000000000126001507310017400413670ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/* Insert with a.b being an object with various types*/ set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 390000; SET documentdb.next_collection_id TO 3900; SET documentdb.next_collection_index_id TO 3900; SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 1, "a" : { "b" : 0 }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Negative test for $in/$nin SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartesterrors') WHERE document @@ '{ "h.b": { "$in" : [{"$elemMatch": {"b": 1}}] }}'; ERROR: cannot nest $ under $in SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartesterrors') WHERE document @@ '{ "h.b": { "$nin" : [{"$elemMatch": {"b": 1}}] }}'; ERROR: cannot nest $ under $nin bson_dollar_ops_basic_compare_tests_explain_index.out000066400000000000000000001006631507310017400427110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; SELECT documentdb_api.drop_collection('db', 'querydollartest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'querydollartest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SET client_min_messages=WARNING; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('querydollartest', 'index_2', '{"$**": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ 1, 2, true ]}'::bson; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (9 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 0 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "1" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "1" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [0, 1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [[0]] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ [ { "$numberInt" : "0" } ] ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ [ { "$numberInt" : "0" } ] ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5100_510006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ ] }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ ] }'::documentdb_core.bson) (9 rows) ROLLBACK; bson_dollar_ops_basic_compare_tests_explain_index_no_bitmap.out000066400000000000000000000642471507310017400447500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedNOTICE: identifier "pg_regress/bson_dollar_ops_basic_compare_tests_explain_index_no_bitmap" will be truncated to "pg_regress/bson_dollar_ops_basic_compare_tests_explain_index_no" set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; SELECT documentdb_api.drop_collection('db', 'querydollartest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'querydollartest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SET client_min_messages=WARNING; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('querydollartest', 'index_2', '{"$**": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'querydollartest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; set local enable_bitmapscan to off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ 1, 2, true ]}'::bson; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (7 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 0 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "1" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [0, 1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [[0]] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ [ { "$numberInt" : "0" } ] ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_2 on documents_5100_510006 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ ] }'::documentdb_core.bson) (7 rows) ROLLBACK; bson_dollar_ops_basic_compare_tests_explain_runtime.out000066400000000000000000000735331507310017400432720ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 52000; SET documentdb.next_collection_id TO 5200; SET documentdb.next_collection_index_id TO 5200; SELECT documentdb_api.drop_collection('db', 'querydollartest'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'querydollartest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SET client_min_messages=WARNING; -- avoid plans that use primary key index \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ 1, 2, true ]}'::bson; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": [ true, false ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a.b" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 0 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@?) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "1" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [0, 1] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [[0]] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ [ { "$numberInt" : "0" } ] ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5200_52002 collection Recheck Cond: (shard_key_value = '5200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@&=) '{ "a.b" : [ ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5200'::bigint) (10 rows) bson_dollar_ops_basic_compare_tests_index.out000066400000000000000000003521271507310017400411750ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (10 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (14 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (11 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : [ 2 ] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 1 }'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 1 }'; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 1 }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 0 }'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 1}'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 0}'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "string" }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "int" }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": 16 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ "int", "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ 16, "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": "array" }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": [ "array", "object" ] }'; count --------------------------------------------------------------------- 12 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @@ '{ "a": { "$type": "number" } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @!*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (10 rows) -- Test double type ordering (see nan.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 16, "e" : {"$numberDouble": "-Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 17, "e" : {"$numberDouble": "-3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 18, "e" : {"$numberDouble": "0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 19, "e" : {"$numberDouble": "3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 20, "e" : {"$numberDouble": "Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 21, "e" : {"$numberDouble": "NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 22, "e" : {"$numberDouble": "-NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 23, "e" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 24, "e" : [] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 25, "e" : { "c": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$numberDouble": "NaN" } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) -- Test for nulls (null.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 26, "f" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 27, "f" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": null, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$eq" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 0 (1 row) -- Test for nulls (null2.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 28, "h" : [ { "b": 5 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 29, "h" : [ { }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 30, "h" : [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 31, "h" : [{}, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 32, "h" : [5, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": null, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$in" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$ne": null }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$nin" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 33, "j" : { "$numberInt" : "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 34 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 35, "j" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 36, "j" : { "k" : { "$numberInt" : "1" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 37, "j" : { "k" : { "$numberInt" : "2" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "j.k": null }' AND document @>= '{ "_id": 33 }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } { "" : { "$numberInt" : "34" } } { "" : { "$numberInt" : "35" } } (3 rows) -- Test for nulls/undefined SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 38, "l": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 39, "l": {"$undefined": true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 41, "l": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": null, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$in": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$all": [ null ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$ne": null }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$nin": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) ROLLBACK; bson_dollar_ops_basic_compare_tests_index_backcompat.out000066400000000000000000003522201507310017400433530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (10 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (14 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (11 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : [ 2 ] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 1 }'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 1 }'; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 1 }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 0 }'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 1}'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 0}'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "string" }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "int" }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": 16 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ "int", "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ 16, "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": "array" }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": [ "array", "object" ] }'; count --------------------------------------------------------------------- 12 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @@ '{ "a": { "$type": "number" } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @!*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (10 rows) -- Test double type ordering (see nan.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 16, "e" : {"$numberDouble": "-Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 17, "e" : {"$numberDouble": "-3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 18, "e" : {"$numberDouble": "0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 19, "e" : {"$numberDouble": "3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 20, "e" : {"$numberDouble": "Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 21, "e" : {"$numberDouble": "NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 22, "e" : {"$numberDouble": "-NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 23, "e" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 24, "e" : [] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 25, "e" : { "c": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$numberDouble": "NaN" } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) -- Test for nulls (null.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 26, "f" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 27, "f" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": null, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$eq" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 0 (1 row) -- Test for nulls (null2.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 28, "h" : [ { "b": 5 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 29, "h" : [ { }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 30, "h" : [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 31, "h" : [{}, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 32, "h" : [5, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": null, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$in" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$ne": null }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$nin" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 33, "j" : { "$numberInt" : "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 34 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 35, "j" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 36, "j" : { "k" : { "$numberInt" : "1" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 37, "j" : { "k" : { "$numberInt" : "2" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "j.k": null }' AND document @>= '{ "_id": 33 }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } { "" : { "$numberInt" : "34" } } { "" : { "$numberInt" : "35" } } (3 rows) -- Test for nulls/undefined SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 38, "l": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 39, "l": {"$undefined": true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 41, "l": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": null, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$in": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$all": [ null ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$ne": null }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$nin": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) ROLLBACK; bson_dollar_ops_basic_compare_tests_index_no_bitmap.out000066400000000000000000003521731507310017400432260ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (10 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (14 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (11 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : [ 2 ] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 1 }'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 1 }'; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 1 }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 0 }'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 1}'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 0}'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "string" }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "int" }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": 16 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ "int", "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ 16, "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": "array" }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": [ "array", "object" ] }'; count --------------------------------------------------------------------- 12 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @@ '{ "a": { "$type": "number" } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @!*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (10 rows) -- Test double type ordering (see nan.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 16, "e" : {"$numberDouble": "-Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 17, "e" : {"$numberDouble": "-3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 18, "e" : {"$numberDouble": "0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 19, "e" : {"$numberDouble": "3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 20, "e" : {"$numberDouble": "Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 21, "e" : {"$numberDouble": "NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 22, "e" : {"$numberDouble": "-NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 23, "e" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 24, "e" : [] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 25, "e" : { "c": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$numberDouble": "NaN" } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) -- Test for nulls (null.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 26, "f" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 27, "f" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": null, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$eq" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 0 (1 row) -- Test for nulls (null2.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 28, "h" : [ { "b": 5 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 29, "h" : [ { }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 30, "h" : [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 31, "h" : [{}, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 32, "h" : [5, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": null, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$in" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$ne": null }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$nin" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 33, "j" : { "$numberInt" : "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 34 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 35, "j" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 36, "j" : { "k" : { "$numberInt" : "1" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 37, "j" : { "k" : { "$numberInt" : "2" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "j.k": null }' AND document @>= '{ "_id": 33 }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } { "" : { "$numberInt" : "34" } } { "" : { "$numberInt" : "35" } } (3 rows) -- Test for nulls/undefined SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 38, "l": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 39, "l": {"$undefined": true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 41, "l": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": null, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$in": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$all": [ null ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$ne": null }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$nin": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) ROLLBACK; bson_dollar_ops_basic_compare_tests_runtime.out000066400000000000000000003520401507310017400415430ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan = on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (10 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (11 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": true }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": "c" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (14 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b.1": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (11 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : 1 } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (13 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (12 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 3 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 0, 1] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 1, 2] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [true, false] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0" : { "d" : [ [ -1, 1, 2 ] ] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ [ -1, 1, 2 ] ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : [ -1, 1, 2 ] }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.0" : -1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.1" : 1 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.2" : 2 }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : [ 2 ] }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : -1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.1" : 1 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.2" : 2 }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 1 }'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 1 }'; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 1 }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 0 }'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 1}'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 0}'; count --------------------------------------------------------------------- 11 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 1}'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 0}'; count --------------------------------------------------------------------- 14 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "string" }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "int" }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": 16 }'; count --------------------------------------------------------------------- 5 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ "int", "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ 16, "string" ] }'; count --------------------------------------------------------------------- 6 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": "array" }'; count --------------------------------------------------------------------- 4 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": [ "array", "object" ] }'; count --------------------------------------------------------------------- 12 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @@ '{ "a": { "$type": "number" } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @!*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (10 rows) -- Test double type ordering (see nan.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 16, "e" : {"$numberDouble": "-Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 17, "e" : {"$numberDouble": "-3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 18, "e" : {"$numberDouble": "0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 19, "e" : {"$numberDouble": "3" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 20, "e" : {"$numberDouble": "Infinity" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 21, "e" : {"$numberDouble": "NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 22, "e" : {"$numberDouble": "-NaN" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 23, "e" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 24, "e" : [] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 25, "e" : { "c": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$numberDouble": "NaN" } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gt" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gte" : { "$numberDouble": "NaN" } } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberDouble" : "NaN" } } { "" : { "$numberDouble" : "NaN" } } (2 rows) -- Test for nulls (null.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 26, "f" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 27, "f" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": null, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$eq" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$ne" : null }, "_id": { "$gte": 26 } }'; count --------------------------------------------------------------------- 0 (1 row) -- Test for nulls (null2.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 28, "h" : [ { "b": 5 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 29, "h" : [ { }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 30, "h" : [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 31, "h" : [{}, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 32, "h" : [5, { "b": 5 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": null, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$in" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "29" } } { "" : { "$numberInt" : "31" } } (2 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$ne": null }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$nin" : [ null ] }, "_id": { "$gte": 28 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "28" } } { "" : { "$numberInt" : "30" } } { "" : { "$numberInt" : "32" } } (3 rows) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 33, "j" : { "$numberInt" : "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 34 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 35, "j" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 36, "j" : { "k" : { "$numberInt" : "1" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 37, "j" : { "k" : { "$numberInt" : "2" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "j.k": null }' AND document @>= '{ "_id": 33 }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } { "" : { "$numberInt" : "34" } } { "" : { "$numberInt" : "35" } } (3 rows) -- Test for nulls/undefined SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 38, "l": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 39, "l": {"$undefined": true} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 41, "l": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": null, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$in": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$all": [ null ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "38" } } { "" : { "$numberInt" : "39" } } { "" : { "$numberInt" : "40" } } (3 rows) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$ne": null }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$nin": [ null, 5 ] }, "_id": { "$gte": 38 } }'; ?column? --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } (1 row) ROLLBACK; bson_dollar_ops_basic_text_ops_tests_explain_index.out000066400000000000000000000066341507310017400431330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1500000; SET documentdb.next_collection_id TO 1500; SET documentdb.next_collection_index_id TO 1500; SELECT documentdb_api.drop_collection('db', 'queryregexopstest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryregexopstest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api_internal.create_indexes_non_concurrently. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('queryregexopstest', 'index_2', '{"$**": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','queryregexopstest'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api.drop_collection('db', 'querytextopstest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'querytextopstest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','querytextopstest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan = off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_text_ops_tests_explain_core.sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "a.b": "^.+$" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1500_1500007 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@~) '{ "a.b" : "^.+$" }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@~) '{ "a.b" : "^.+$" }'::documentdb_core.bson) (9 rows) END; bson_dollar_ops_basic_text_ops_tests_explain_runtime.out000066400000000000000000000027671507310017400435120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1400000; SET documentdb.next_collection_id TO 1400; SET documentdb.next_collection_index_id TO 1400; SELECT documentdb_api.create_collection('db', 'queryregexopstest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'querytextopstest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \i sql/bson_dollar_ops_basic_text_ops_tests_explain_core.sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "a.b": "^.+$" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1400_1400007 collection Recheck Cond: (shard_key_value = '1400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@~) '{ "a.b" : "^.+$" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '1400'::bigint) (10 rows) bson_dollar_ops_basic_text_ops_tests_index.out000066400000000000000000000101601507310017400414000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 450000; SET documentdb.next_collection_id TO 4500; SET documentdb.next_collection_index_id TO 4500; BEGIN; set local enable_seqscan = off; \i sql/bson_dollar_ops_basic_text_ops_tests_core.sql SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 1, "address" : "sfo0001", "comment" : "This is a dentist clinic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 2, "address" : "sfo0010", "comment" : "Here you can get\nthe most delicious food\nin the world"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 3, "address" : "Sfo0010", "comment" : "[dupe] Here you can get\nthe most delicious food\nin the world"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 4, "address" : "la0001", "comment" : "I never been here"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 5, "address" : "la7777", "comment" : "The dog in the yard\nalways barks at me" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* now query regex */ /* db.queryregexopstest.find( { address: { $regex: /0001$/ } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "0001$" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "address" : "la0001", "comment" : "I never been here" } (2 rows) /* TODO: passing options: db.queryregexopstest.find( { address: { $regex: /^SFO/i } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "^sfo" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "address" : "sfo0010", "comment" : "Here you can get\nthe most delicious food\nin the world" } (2 rows) /* Match multiple spaces */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "comment": "\\s\\s+" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } (1 row) ROLLBACK; bson_dollar_ops_basic_text_ops_tests_runtime.out000066400000000000000000000101571507310017400417620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 450000; SET documentdb.next_collection_id TO 4500; SET documentdb.next_collection_index_id TO 4500; BEGIN; set local enable_seqscan = on; \i sql/bson_dollar_ops_basic_text_ops_tests_core.sql SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 1, "address" : "sfo0001", "comment" : "This is a dentist clinic"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 2, "address" : "sfo0010", "comment" : "Here you can get\nthe most delicious food\nin the world"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 3, "address" : "Sfo0010", "comment" : "[dupe] Here you can get\nthe most delicious food\nin the world"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 4, "address" : "la0001", "comment" : "I never been here"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 5, "address" : "la7777", "comment" : "The dog in the yard\nalways barks at me" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* now query regex */ /* db.queryregexopstest.find( { address: { $regex: /0001$/ } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "0001$" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "address" : "la0001", "comment" : "I never been here" } (2 rows) /* TODO: passing options: db.queryregexopstest.find( { address: { $regex: /^SFO/i } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "^sfo" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "address" : "sfo0010", "comment" : "Here you can get\nthe most delicious food\nin the world" } (2 rows) /* Match multiple spaces */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "comment": "\\s\\s+" }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "address" : "sfo0001", "comment" : "This is a dentist clinic" } (1 row) ROLLBACK; bson_dollar_ops_collation_tests_runtime.out000066400000000000000000014273521507310017400407520ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7990000; SET documentdb.next_collection_id TO 7990; SET documentdb.next_collection_index_id TO 7990; -- (1) insert some docs SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 1, "a": "Cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 2, "a": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 3, "a": "cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 4, "a": "Dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 5, "a": "caT" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 6, "a": "doG" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 7, "a": "goat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 8, "a": "Goat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 9, "b": "Cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 10, "b": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 11, "b": "cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 12, "b": "Dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 13, "b": "caT", "a" : "raBbIt" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 14, "b": "doG" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 15, "b": "goat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 16, "b": "Goat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 17, "a": ["Cat", "CAT", "dog"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 18, "a": ["dog", "cat", "CAT"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 19, "a": ["cat", "rabbit", "bAt"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 20, "a": ["Cat"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 21, "a": ["dog"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 22, "a": ["cat"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 23, "a": ["CAT"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 24, "a": ["cAt"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 25, "a": { "b" : "cAt"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 26, "a": [{ "b": "CAT"}] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SET documentdb_core.enableCollation TO off; -- With collation off and colation string in find and aggregate commands should not throw an error SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "a": { "$eq": "cat" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "b" : "cat" } (1 row) SET documentdb_core.enableCollation TO on; -- (2) Find query unsharded collection SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } (5 rows) EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7990_7990004 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '7990'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_7990_7990004 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '7990'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7990'::bigint) (18 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "b" : "Cat" } { "_id" : { "$numberInt" : "11" }, "b" : "cat" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt" } (3 rows) EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7990_7990004 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '7990'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_7990_7990004 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '7990'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7990'::bigint) (18 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "Dog" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 10, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "10" }, "b" : "dog" } { "_id" : { "$numberInt" : "12" }, "b" : "Dog" } { "_id" : { "$numberInt" : "14" }, "b" : "doG" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "20" }, "a" : [ "Cat" ] } (10 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$all": ["cAt", "DOG"] } }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength": 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 5} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "Dog" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "6" }, "a" : "doG" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "20" }, "a" : [ "Cat" ] } { "_id" : { "$numberInt" : "21" }, "a" : [ "dog" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } { "_id" : { "$numberInt" : "23" }, "a" : [ "CAT" ] } { "_id" : { "$numberInt" : "24" }, "a" : [ "cAt" ] } (14 rows) -- range query without index on path "a" SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$gt": "CAT" }, "a" : {"$lt" : "RABBIT"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "Dog" } { "_id" : { "$numberInt" : "6" }, "a" : "doG" } { "_id" : { "$numberInt" : "7" }, "a" : "goat" } { "_id" : { "$numberInt" : "8" }, "a" : "Goat" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "21" }, "a" : [ "dog" ] } (9 rows) EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$gt": "CAT" }, "a" : {"$lt" : "RABBIT"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7990_7990004 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<) '{ "a" : "RABBIT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '7990'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_7990_7990004 collection Output: document Recheck Cond: (collection.shard_key_value = '7990'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a" : "RABBIT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7990'::bigint) (13 rows) -- (3) Shard collection SELECT documentdb_api.shard_collection('db', 'ci_search', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- (4) Find query sharded collection BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } (5 rows) END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_7990_7990016 collection WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_7990_7990016 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "b" : "Cat" } { "_id" : { "$numberInt" : "11" }, "b" : "cat" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt" } (3 rows) END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_7990_7990016 collection WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_7990_7990016 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) END; -- elemMatch with collation BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$eq": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } { "_id" : { "$numberInt" : "20" }, "a" : [ "Cat" ] } { "_id" : { "$numberInt" : "23" }, "a" : [ "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "24" }, "a" : [ "cAt" ] } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$gt": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "a" : [ "dog" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$lt": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$eq": "cAt", "gte" : "BAT"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) END; -- (5) Aggregation queries sharded collection BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "a": { "$eq": "cat" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "20" }, "a" : [ "Cat" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } { "_id" : { "$numberInt" : "23" }, "a" : [ "CAT" ] } { "_id" : { "$numberInt" : "24" }, "a" : [ "cAt" ] } (10 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$gt": "DOG" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : "Goat" } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "7" }, "a" : "goat" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt" } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$eq": "RABBIT" } } }, { "$project": { "b": 1 } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" } } { "_id" : { "$numberInt" : "13" }, "b" : "caT" } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "_id": { "$gt": 1 } } }, { "$project": { "b": 1, "c": "$a", "_id": 0 } }, { "$match": { "c": { "$eq": "rAbBiT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "c" : [ "cat", "rabbit", "bAt" ] } { "b" : "caT", "c" : "raBbIt" } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$unwind": "$a" }, {"$match": { "a": { "$gt": "POP", "$lt": "TOP" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "a" : "rabbit" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt" } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$gte": "hobbit" } } }, { "$unwind": "$a" } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "a" : "cat" } { "_id" : { "$numberInt" : "19" }, "a" : "rabbit" } { "_id" : { "$numberInt" : "19" }, "a" : "bAt" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt" } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$addFields": { "x": "mANgO" } }, { "$addFields": { "Y": "TANGO" } }, { "$match": { "$and" : [{ "a": { "$gte": "POMELO" }}, { "x": { "$eq": "MANGO" }}]}} ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ], "x" : "mANgO", "Y" : "TANGO" } { "_id" : { "$numberInt" : "13" }, "b" : "caT", "a" : "raBbIt", "x" : "mANgO", "Y" : "TANGO" } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$addFields": { "e": { "f": "$a" } } }, { "$replaceRoot": { "newRoot": "$e" } }, { "$match" : { "f": { "$elemMatch": {"$eq": "cAt"} } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "f" : [ "cat" ] } { "f" : [ "Cat" ] } { "f" : [ "CAT" ] } { "f" : [ "cat", "rabbit", "bAt" ] } { "f" : [ "cAt" ] } { "f" : [ "Cat", "CAT", "dog" ] } { "f" : [ "dog", "cat", "CAT" ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 5} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "Dog" } { "_id" : { "$numberInt" : "5" }, "a" : "caT" } { "_id" : { "$numberInt" : "6" }, "a" : "doG" } { "_id" : { "$numberInt" : "17" }, "a" : [ "Cat", "CAT", "dog" ] } { "_id" : { "$numberInt" : "18" }, "a" : [ "dog", "cat", "CAT" ] } { "_id" : { "$numberInt" : "19" }, "a" : [ "cat", "rabbit", "bAt" ] } { "_id" : { "$numberInt" : "20" }, "a" : [ "Cat" ] } { "_id" : { "$numberInt" : "21" }, "a" : [ "dog" ] } { "_id" : { "$numberInt" : "22" }, "a" : [ "cat" ] } { "_id" : { "$numberInt" : "23" }, "a" : [ "CAT" ] } { "_id" : { "$numberInt" : "24" }, "a" : [ "cAt" ] } (14 rows) END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : [[{ "b" : "caT"}], [{ "c" : "caT"}]] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_7990_7990016 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "a" : [ [ { "b" : "caT" } ], [ { "c" : "caT" } ] ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_internal.##=) ANY ('{"{ \"a\" : [ { \"b\" : \"caT\" } ], \"collation\" : \"en-u-ks-level1\" }","{ \"a\" : [ { \"c\" : \"caT\" } ], \"collation\" : \"en-u-ks-level1\" }"}'::documentdb_api_internal.bsonindexbounds[]))) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '100'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_7990_7990016 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ [ { "b" : "caT" } ], [ { "c" : "caT" } ] ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) END; -- (6) currently unsupported scenarions: -- unsupported: $bucket SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$bucket": { "groupBy": "$price", "boundaries": [0, 10, 20, 30], "default": "Other", "output": { "categoryMatch": { "$sum": { "$cond": [ { "$eq": ["$a", "PETS"] }, 1, 0 ] } } } } } ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: Collation is currently unsupported in the $bucket stage. -- unsupported: $geoNear SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [ 0 , 10 ] }, "distanceField": "dist.calculated", "maxDistance": 2, "query": { "a": "cAT" } } } ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: collation is not supported in the $geoNear stage yet. -- unsupported: $fill SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$fill": { "sortBy": { "timestamp": 1 }, "partitionBy": "$status", "output": { "$cond": { "if": { "$eq": ["$a", "cAt"] }, "then": { "type": "feline" }, "else": { "type": "other" } } } } } ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: collation is not supported in the $fill stage yet. -- unsupported: $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$group": { "_id": "$a", "set": { "$addToSet": "$a" } }} ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: collation is not supported in $group stage yet. -- unsupported: $setWindowFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$setWindowFields": { "sortBy": { "_id": 1 }, "output": { "total": { "$eq": ["$a", "cAt"] } } }} ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: collation is not supported in the $setWindowFields stage yet. -- unsupported: $sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sortByCount": { "input": "$a", "as": "a", "by": { "$cond": { "if": { "$eq": [ "$a", "caT" ] }, "then": [{"x": 30}] , "else": [{"x": 30}] }} }} ], "collation": { "locale": "en", "strength": 1 } }'); ERROR: collation is not supported in the $sortByCount stage yet. -- (6.B) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$addFields": { "e": { "f": "$a" } } }, { "$replaceRoot": { "newRoot": "$e" } }, { "$match" : { "f": { "$elemMatch": {"$eq": "cAt"} } } }, {"$project": { "items" : { "$filter" : { "input" : "$f", "as" : "animal", "cond" : { "$eq" : ["$$animal", "CAT"] } }} }} ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "items" : [ "Cat", "CAT" ] } { "items" : [ "cat", "CAT" ] } { "items" : [ "cat" ] } { "items" : [ "Cat" ] } { "items" : [ "cat" ] } { "items" : [ "CAT" ] } { "items" : [ "cAt" ] } (7 rows) END; -- (7) Insert More docs SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 1, "a": "Cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 2, "a": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 3, "a": "cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 4, "a": "CaT" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 5, "b": "Dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 6, "b": "DoG" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (8) Query results with different collations SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3, "caseLevel": true, "caseFirst": "off", "numericOrdering": true } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1.93 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) -- (8) a. collation has no effect on $regex SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "a": { "$regex": "^c", "$options": "" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } (1 row) -- (9) Error message Tests SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "none"} }'); ERROR: unable to parse collation :: caused by :: Enumeration value 'none' for field 'collation.alternate' is not a valid value. SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en_DB", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "shifted"} }'); ERROR: unable to parse collation :: caused by :: Field 'locale' is invalid in: { locale: "en_DB", strength: 1 }. SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: Enumeration value 'bad' for field 'collation.caseFirst' is not a valid value. SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 0, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: Enumeration value '0' for field 'collation.strength' is not a valid value SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : -1, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: BSON field 'strength' value must be >= 0, actual value '-1' SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 6, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: BSON field 'strength' value must be <= 5, actual value '6' SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "abcd", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: Field 'locale' is invalid in: { locale: "abcd", strength: 1 }. SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "fr_FR", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true} }'); ERROR: unable to parse collation :: caused by :: Field 'locale' is invalid in: { locale: "fr_FR", strength: 1 }. SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "shifted", "backwards" : "0"} }'); ERROR: unable to parse collation :: caused by :: BSON field 'collation.backwards' is the wrong type 'string', expected type 'bool' SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true, "alternate": "non-ignorable", "backwards" : true, "normalization" : 1} }'); ERROR: unable to parse collation :: caused by :: BSON field 'collation.normalization' is the wrong type 'int', expected type 'bool' SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true, "alternate": "non-ignorable", "backwards" : true, "normalization" : true} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 0.9 } }'); ERROR: unable to parse collation :: caused by :: Enumeration value '0' for field 'collation.strength' is not a valid value -- (10) collation variations SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "fr", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "de", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "bn", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "Cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cat" } { "_id" : { "$numberInt" : "4" }, "a" : "CaT" } { "_id" : { "$numberInt" : "5" }, "b" : "Dog" } { "_id" : { "$numberInt" : "6" }, "b" : "DoG" } (5 rows) -- collation with sort/order by SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CaT", "a": "cat", "b": "CaT"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CAt", "a": "cat", "b": "CAt"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CAT", "a": "cat", "b": "CAT"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "cAT", "a": "cat", "b": "cAT"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) -- collation with sort/order by with collation-aware _id SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); document --------------------------------------------------------------------- { "_id" : "cAT", "a" : "cat", "b" : "cAT" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CAT", "a" : "cat", "b" : "CAT" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "cat", "b" : "CAT" } { "_id" : "CAt", "a" : "cat", "b" : "CAt" } { "_id" : "CaT", "a" : "cat", "b" : "CaT" } { "_id" : "cAT", "a" : "cat", "b" : "cAT" } (4 rows) -- collation with sort/order by: numericOrdering is respected SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 1, "a": "cat", "b": "10"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 2, "a": "cat", "b": "2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 3, "a": "cat", "b": "3"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : false } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "b" : "10" } { "_id" : { "$numberInt" : "2" }, "a" : "cat", "b" : "2" } { "_id" : { "$numberInt" : "3" }, "a" : "cat", "b" : "3" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : true } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "cat", "b" : "2" } { "_id" : { "$numberInt" : "3" }, "a" : "cat", "b" : "3" } { "_id" : { "$numberInt" : "1" }, "a" : "cat", "b" : "10" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : false } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cat", "b" : "3" } { "_id" : { "$numberInt" : "2" }, "a" : "cat", "b" : "2" } { "_id" : { "$numberInt" : "1" }, "a" : "cat", "b" : "10" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : true } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "b" : "10" } { "_id" : { "$numberInt" : "3" }, "a" : "cat", "b" : "3" } { "_id" : { "$numberInt" : "2" }, "a" : "cat", "b" : "2" } (3 rows) -- collation with sort/order by: setWindowFields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "coll_order_tests1", "pipeline": [{"$setWindowFields": { "sortBy": {"b": -1}, "output": {"res": { "$push": "$b", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "collation": { "locale": "en", "numericOrdering" : false } }'); ERROR: collation is not supported in the $setWindowFields stage yet. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "coll_order_tests1", "pipeline": [{"$setWindowFields": { "sortBy": {"b": -1}, "output": {"res": { "$push": "$b", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "collation": { "locale": "en", "numericOrdering" : true } }'); ERROR: collation is not supported in the $setWindowFields stage yet. -- (11) Unsupported scenarios SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "ci_search2", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "collation" : {"locale" : "en", "strength": 1} }'); ERROR: findAndModify.collation is not implemented yet SELECT documentdb_api.update('update', '{"update":"ci_search2", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "collation" : {"locale" : "en", "strength": 1}, "arrayFilters": [ { "a": 2 } ]}]}'); ERROR: BSON field 'update.updates.collation' is not yet supported SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ci_search2", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true, "collation" : {"locale" : "en", "strength": 1}}]}', TRUE); ERROR: Error in specification { "key" : { "asparse" : 1 }, "name" : "my_sparse_idx1", "sparse" : true, "collation" : { "locale" : "en", "strength" : 1 } }:createIndex.collation has not been implemented yet -- (12) Test Id filters respect collation SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "Cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "CaT" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "Dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "DoG" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": { "a" : "cat" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3',' { "_id": { "a": "CAT"} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "a": { "a": "Dog" } } '); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": [ "cat", "CAT "] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "The '_id' field value must not be a type of array" } ] } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "Cat" } { "_id" : "cat" } { "_id" : "CaT" } { "_id" : "dog" } { "_id" : "Dog" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "a" : "cat" } } { "_id" : { "a" : "CAT" } } (2 rows) EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7994_7990072 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "_id.a" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7994'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_7994_7990072 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '7994'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "_id.a" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7994'::bigint) (18 rows) SELECT documentdb_api.shard_collection('db', 'ci_search', '{ "_id": "hashed" }', false); NOTICE: Skipping Sharding for collection db.ci_search as the same options were passed in. shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "Cat" } { "_id" : "cat" } { "_id" : "CaT" } { "_id" : "dog" } { "_id" : "Dog" } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7994_7990072 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "_id" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7994'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_7994_7990072 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '7994'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7994'::bigint) (18 rows) END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "a" : "cat" } } { "_id" : { "a" : "CAT" } } (2 rows) END; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7994_7990072 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "_id.a" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7994'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_7994_7990072 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '7994'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "_id.a" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7994'::bigint) (18 rows) -- (12) Check index with partial filter expression with collation SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 1, "a" : { "b" : "DOG" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 2, "a" : { "b" : "dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 3, "a" : { "b" : "Cat" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 4, "a" : { "b" : "Dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 5, "a" : { "b" : "cAT" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 6, "a" : { "b" : "DoG" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 7, "a" : { "b" : "DOG" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search4", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$eq": "dog" } }, "collation" : {"locale" : "en", "strength" : 2} } ] }', TRUE ); ERROR: Error in specification { "key" : { "a.b" : 1 }, "name" : "my_idx_1", "partialFilterExpression" : { "a.b" : { "$eq" : "dog" } }, "collation" : { "locale" : "en", "strength" : 2 } }:createIndex.collation has not been implemented yet SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search4", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$eq": "dog" } } } ] }', TRUE ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query pushed to the index when no collattion SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7995_7990095 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.b" : "dog" }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_dollar_ne(document, '{ "a" : null }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7995'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_7995_7990095 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.#=) '{ "a.b" : "dog" }'::documentdb_core.bsonquery) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : "dog" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on my_idx_1 (12 rows) ROLLBACK; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query not pushed to the index when collattion is specified SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } }, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "Dog" } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : "DoG" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : "DOG" } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } }, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7995_7990095 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.b" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_dollar_ne(document, '{ "a" : null, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7995'::bigint)) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_7995_7990095 collection Output: document Index Cond: (collection.shard_key_value = '7995'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (11 rows) END; SELECT documentdb_api.shard_collection('db', 'ci_search4', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "Cat" } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "Dog" } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : "cAT" } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_7995_7990104 collection WHERE documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_7995_7990104 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) END; -- (13) Check index behavior with collation (TODO: update when index pushdown of collation is supported) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 1, "a" : { "b" : "DOG" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 2, "a" : { "b" : "dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 3, "a" : { "b" : "Cat" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 4, "a" : { "b" : "Dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 5, "a" : { "b" : "cAT" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 6, "a" : { "b" : "DoG" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 7, "a" : { "b" : "DOG" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search5", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "collation" : {"locale" : "en", "strength" : 2} } ] }', TRUE ); ERROR: Error in specification { "key" : { "a.b" : 1 }, "name" : "my_idx_1", "collation" : { "locale" : "en", "strength" : 2 } }:createIndex.collation has not been implemented yet SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search5", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1" } ] }', TRUE ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query pushed to the index when no collattion SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : "DOG" } } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7996_7990114 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "DOG" ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7996'::bigint)) ORDER BY (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Sort Output: document, (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Sort Key: (documentdb_api_catalog.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Index Scan using my_idx_1 on documentdb_data.documents_7996_7990114 collection Output: document, documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "DOG" ] }'::documentdb_core.bson) (15 rows) ROLLBACK; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query not pushed to the index when collation is specified SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "Cat" } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "Dog" } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : "cAT" } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7996_7990114 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '7996'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Index Scan using _id_ on documentdb_data.documents_7996_7990114 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Index Cond: (collection.shard_key_value = '7996'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (16 rows) END; -- range query with index on path "a.b" SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "a.b": { "$gt": "CAT" }, "a.b" : {"$lte" : "DOG"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "Dog" } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : "DoG" } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : "DOG" } } (5 rows) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "a.b": { "$gt": "CAT" }, "a.b" : {"$lte" : "DOG"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_7996_7990114 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<=) '{ "a.b" : "DOG", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '7996'::bigint)) Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7996_7990114 collection Output: document Filter: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : "DOG", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (10 rows) END; SELECT documentdb_api.shard_collection('db', 'ci_search5', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : "DOG" } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : "Cat" } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "Dog" } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : "cAT" } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_7996_7990128 collection WHERE documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_7996_7990128 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "DOG" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) END; -- nested pipleline tests SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "DOG", "a" : { "b" : "DOG" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "dog", "a" : { "b" : "dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "Cat", "a" : { "b" : "Cat" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "Dog", "a" : { "b" : "Dog" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "cAT", "a" : { "b" : "cAT" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "DoG", "a" : { "b" : "DoG" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "dOg", "a" : { "b" : "dOg" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- lookup with id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : { "b" : "DOG" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "Dog", "a" : { "b" : "Dog" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } (7 rows) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "_id" : "_id", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_7997_7990140 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_7997_7990140 collection_0_1 WHERE (documentdb_api_catalog.bson_dollar_in(collection_0_1.document, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint))) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, '_id'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true) -> Bitmap Heap Scan on documentdb_data.documents_7997_7990140 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '7997'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7997'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_7997_7990140 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '7997'::bigint) Filter: ((collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "_id" : "_id", "collation" : "en-u-ks-level1" }'::documentdb_core.bson), '_id'::text)) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '7997'::bigint) (22 rows) END; -- lookup with id join optimized (explicitly asked to make _id join collation agnostic) BEGIN; SET LOCAL documentdb.enableLookupIdJoinOptimizationOnCollation to true; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : { "b" : "DOG" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "matched_docs" : [ { "_id" : "dog", "a" : { "b" : "dog" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } } ] } { "_id" : "Dog", "a" : { "b" : "Dog" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "matched_docs" : [ { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "matched_docs" : [ { "_id" : "DoG", "a" : { "b" : "DoG" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "matched_docs" : [ { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } (7 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents("left", (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_subpipeline_substage_0.lookup_unwind, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS "funcName" FROM documentdb_api_catalog.bson_lookup_unwind(lookup_non_inlined_stage_1."right", 'matched_docs'::text) lookup_subpipeline_substage_0(lookup_unwind) WHERE documentdb_api_catalog.bson_dollar_in(lookup_subpipeline_substage_0.lookup_unwind, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson)), true) AS document FROM (SELECT lookup_stage_1.document AS "left", "lookupRight_stage_1".document AS "right" FROM ((SELECT collection.document, collection.object_id AS lookup_filter FROM documentdb_data.documents_7997_7990140 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document, collection_0_1.object_id AS "objectId" FROM documentdb_data.documents_7997_7990140 collection_0_1 WHERE (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint)) lookup_right_query_stage_0 WHERE (lookup_right_query_stage_0."objectId" OPERATOR(documentdb_core.=) lookup_stage_1.lookup_filter)) "lookupRight_stage_1" ON (true))) lookup_non_inlined_stage_1 Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (SubPlan 1), true) -> Bitmap Heap Scan on documentdb_data.documents_7997_7990140 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '7997'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7997'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Index Scan using _id_ on documentdb_data.documents_7997_7990140 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Index Cond: ((collection_0_1.shard_key_value = '7997'::bigint) AND (collection_0_1.object_id OPERATOR(documentdb_core.=) collection.object_id)) SubPlan 1 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(lookup_subpipeline_substage_0.lookup_unwind, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Function Scan on documentdb_api_catalog.bson_lookup_unwind lookup_subpipeline_substage_0 Output: lookup_subpipeline_substage_0.lookup_unwind Function Call: documentdb_api_catalog.bson_lookup_unwind((COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), 'matched_docs'::text) Filter: documentdb_api_catalog.bson_dollar_in(lookup_subpipeline_substage_0.lookup_unwind, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (26 rows) END; -- lookup with non-id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : { "b" : "DOG" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "Dog", "a" : { "b" : "Dog" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "matched_docs" : [ { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } (7 rows) -- lookup with non-id join (collation aware - explain) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT collection.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "a.b" : "a.b", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_7997_7990140 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT collection_0_1.document FROM documentdb_data.documents_7997_7990140 collection_0_1 WHERE (documentdb_api_catalog.bson_dollar_in(collection_0_1.document, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '7997'::bigint))) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'a.b'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, (COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true) -> Bitmap Heap Scan on documentdb_data.documents_7997_7990140 collection Output: collection.shard_key_value, collection.object_id, collection.document Recheck Cond: (collection.shard_key_value = '7997'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7997'::bigint) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(collection_0_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Bitmap Heap Scan on documentdb_data.documents_7997_7990140 collection_0_1 Output: collection_0_1.shard_key_value, collection_0_1.object_id, collection_0_1.document Recheck Cond: (collection_0_1.shard_key_value = '7997'::bigint) Filter: ((collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_1.document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(collection.document, '{ "a.b" : "a.b", "collation" : "en-u-ks-level1" }'::documentdb_core.bson), 'a.b'::text)) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_1.shard_key_value = '7997'::bigint) (22 rows) END; -- $facet and $unionwith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$facet": { "a" : [ { "$match": { "a.b": "cat" } }, { "$count": "catCount" } ], "b" : [ { "$match": { "a.b": "dog" } }, { "$count": "dogCount" } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1}}'); document --------------------------------------------------------------------- { "a" : [ { "catCount" : { "$numberInt" : "2" } } ], "b" : [ { "dogCount" : { "$numberInt" : "5" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$unionWith": { "coll": "ci_search6", "pipeline" : [ { "$match": { "a.b": "cat" }}] } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : { "b" : "DOG" } } { "_id" : "dog", "a" : { "b" : "dog" } } { "_id" : "Cat", "a" : { "b" : "Cat" } } { "_id" : "Dog", "a" : { "b" : "Dog" } } { "_id" : "cAT", "a" : { "b" : "cAT" } } { "_id" : "DoG", "a" : { "b" : "DoG" } } { "_id" : "dOg", "a" : { "b" : "dOg" } } { "_id" : "Cat", "a" : { "b" : "Cat" } } { "_id" : "cAT", "a" : { "b" : "cAT" } } (9 rows) -- $graphLookup SELECT documentdb_api.insert_one('db','ci_search7', '{"_id": "alice", "pet" : "dog" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search7', '{"_id": "bob", "pet" : "cat" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "DOG", "name" : "DOG" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "dog", "name" : "dog" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "CAT", "name" : "CAT" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "cAT", "name" : "cAT" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'destinations'::text), '{ "destinations" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_7999_7990175 collection_0_2 WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '7999'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", '_id'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_7999_7990175 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '7999'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "_id" : { "$makeArray" : "$name" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true) AS document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "destinations" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "_id" : { "$makeArray" : "$pet" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson, 'en-u-ks-level3'::text) AS "inputExpr" FROM documentdb_data.documents_7998_7990152 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7998'::bigint)) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_7998_7990152 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "destinations" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.shard_key_value = '7998'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7998'::bigint) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), 'destinations'::text), '{ "destinations" : [ ] }'::documentdb_core.bson) -> Unique Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_7999_7990175 collection_0_2 Output: collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.shard_key_value = '7999'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "_id" : { "$makeArray" : "$pet" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2.shard_key_value = '7999'::bigint) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "_id" : { "$makeArray" : "$name" } }'::documentdb_core.bson, false, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: (NOT "lookupRecursive_stage_1".is_cycle) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_7999_7990175 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.shard_key_value = '7999'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2_1.shard_key_value = '7999'::bigint) -> Sort Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ ] } (2 rows) END; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$graphLookup": { "from": "ci_search6", "startWith": "$a.b", "connectFromField": "a.b", "connectToField": "a.b", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : { "b" : "DOG" }, "destinations" : [ { "_id" : "DOG", "a" : { "b" : "DOG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "DoG", "a" : { "b" : "DoG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "Dog", "a" : { "b" : "Dog" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dOg", "a" : { "b" : "dOg" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "a" : { "b" : "dog" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "destinations" : [ { "_id" : "DOG", "a" : { "b" : "DOG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "DoG", "a" : { "b" : "DoG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "Dog", "a" : { "b" : "Dog" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dOg", "a" : { "b" : "dOg" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "a" : { "b" : "dog" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "destinations" : [ { "_id" : "Cat", "a" : { "b" : "Cat" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "a" : { "b" : "cAT" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "Dog", "a" : { "b" : "Dog" }, "destinations" : [ { "_id" : "DOG", "a" : { "b" : "DOG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "DoG", "a" : { "b" : "DoG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "Dog", "a" : { "b" : "Dog" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dOg", "a" : { "b" : "dOg" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "a" : { "b" : "dog" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "destinations" : [ { "_id" : "Cat", "a" : { "b" : "Cat" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "a" : { "b" : "cAT" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "destinations" : [ { "_id" : "DOG", "a" : { "b" : "DOG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "DoG", "a" : { "b" : "DoG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "Dog", "a" : { "b" : "Dog" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dOg", "a" : { "b" : "dOg" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "a" : { "b" : "dog" }, "depth" : { "$numberInt" : "0" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "destinations" : [ { "_id" : "DOG", "a" : { "b" : "DOG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "DoG", "a" : { "b" : "DoG" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "Dog", "a" : { "b" : "Dog" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dOg", "a" : { "b" : "dOg" }, "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "a" : { "b" : "dog" }, "depth" : { "$numberInt" : "0" } } ] } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "DOG", "name" : "DOG", "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ { "_id" : "CAT", "name" : "CAT", "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "name" : "cAT", "depth" : { "$numberInt" : "0" } } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "DOG", "name" : "DOG", "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ { "_id" : "CAT", "name" : "CAT", "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "name" : "cAT", "depth" : { "$numberInt" : "0" } } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "fr", "strength" : 1, "alternate": "shifted" } }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "DOG", "name" : "DOG", "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ { "_id" : "CAT", "name" : "CAT", "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "name" : "cAT", "depth" : { "$numberInt" : "0" } } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "hi", "strength" : 2, "caseFirst": "lower" } }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "DOG", "name" : "DOG", "depth" : { "$numberInt" : "0" } }, { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ { "_id" : "CAT", "name" : "CAT", "depth" : { "$numberInt" : "0" } }, { "_id" : "cAT", "name" : "cAT", "depth" : { "$numberInt" : "0" } } ] } (2 rows) -- test $graphlookup without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, "addFields", true) AS document FROM (SELECT "graphLookupBase_stage_1".document, COALESCE((SELECT COALESCE(documentdb_api_catalog.bson_array_agg(agg_stage_sub_1_0.document, 'destinations'::text), '{ "destinations" : [ ] }'::documentdb_core.bson) AS document FROM (WITH RECURSIVE "graphLookupRecurseStage" AS (SELECT "*TLOCRN*".document, "*TLOCRN*".depth, "*TLOCRN*"."baseDocId", false AS is_cycle, ARRAY[ROW("*TLOCRN*"."baseDocId")] AS path FROM (SELECT collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId" FROM documentdb_data.documents_7999_7990175 collection_0_2 WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '7999'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, "graphLookupBase_stage_1"."inputExpr", '_id'::text))) "*TLOCRN*"(document, depth, "baseDocId") UNION ALL SELECT "*TROCRN*".document, "*TROCRN*".depth, "*TROCRN*"."baseDocId", CASE WHEN (ROW("*TROCRN*"."baseDocId") OPERATOR(pg_catalog.=) ANY ("*TROCRN*".path)) THEN true ELSE false END AS is_cycle, array_cat("*TROCRN*".path, ARRAY[ROW("*TROCRN*"."baseDocId")]) AS path FROM (SELECT collection_0_2.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson) AS depth, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson) AS "baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path FROM documentdb_data.documents_7999_7990175 collection_0_2, "graphLookupRecurseStage" "lookupRecursive_stage_1" WHERE ((collection_0_2.shard_key_value OPERATOR(pg_catalog.=) '7999'::bigint) AND documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "_id" : { "$makeArray" : "$name" } }'::documentdb_core.bson, false, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text))) "*TROCRN*"(document, depth, "baseDocId", is_cycle, path) WHERE ("*TROCRN*".is_cycle OPERATOR(pg_catalog.<>) true)) SELECT DISTINCT ON ("graphLookup_stage_2"."baseDocId") documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true) AS document FROM "graphLookupRecurseStage" "graphLookup_stage_2" ORDER BY "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth) agg_stage_sub_1_0), '{ "destinations" : [ ] }'::documentdb_core.bson) AS "addFields" FROM (SELECT collection.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "_id" : { "$makeArray" : "$pet" } }'::documentdb_core.bson, false, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) AS "inputExpr" FROM documentdb_data.documents_7998_7990152 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '7998'::bigint)) "graphLookupBase_stage_1") "graphLookup_stage_1" Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_7998_7990152 collection Output: documentdb_api_internal.bson_dollar_merge_documents(collection.document, COALESCE((SubPlan 2), '{ "destinations" : [ ] }'::documentdb_core.bson), true) Recheck Cond: (collection.shard_key_value = '7998'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '7998'::bigint) SubPlan 2 -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg((documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), 'destinations'::text), '{ "destinations" : [ ] }'::documentdb_core.bson) -> Unique Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth CTE graphLookupRecurseStage -> Recursive Union -> Bitmap Heap Scan on documentdb_data.documents_7999_7990175 collection_0_2 Output: collection_0_2.document, '{ "depth" : { "$numberInt" : "0" } }'::documentdb_core.bson, documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), false, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))] Recheck Cond: (collection_0_2.shard_key_value = '7999'::bigint) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2.document, documentdb_api_internal.bson_expression_get(collection.document, '{ "_id" : { "$makeArray" : "$pet" } }'::documentdb_core.bson, false, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2.shard_key_value = '7999'::bigint) -> Nested Loop Output: collection_0_2_1.document, documentdb_api_catalog.bson_dollar_add_fields("lookupRecursive_stage_1".depth, '{ "depth" : { "$add" : [ "$depth", { "$numberInt" : "1" } ] } }'::documentdb_core.bson), documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false), CASE WHEN (ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false)) = ANY ("lookupRecursive_stage_1".path)) THEN true ELSE false END, array_cat("lookupRecursive_stage_1".path, ARRAY[ROW(documentdb_api_catalog.bson_expression_get(collection_0_2_1.document, '{ "_id" : "$_id" }'::documentdb_core.bson, false))]) Join Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(collection_0_2_1.document, documentdb_api_internal.bson_expression_get("lookupRecursive_stage_1".document, '{ "_id" : { "$makeArray" : "$name" } }'::documentdb_core.bson, false, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text), '_id'::text) -> WorkTable Scan on "graphLookupRecurseStage" "lookupRecursive_stage_1" Output: "lookupRecursive_stage_1".document, "lookupRecursive_stage_1".depth, "lookupRecursive_stage_1"."baseDocId", "lookupRecursive_stage_1".is_cycle, "lookupRecursive_stage_1".path Filter: (NOT "lookupRecursive_stage_1".is_cycle) -> Materialize Output: collection_0_2_1.document -> Bitmap Heap Scan on documentdb_data.documents_7999_7990175 collection_0_2_1 Output: collection_0_2_1.document Recheck Cond: (collection_0_2_1.shard_key_value = '7999'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection_0_2_1.shard_key_value = '7999'::bigint) -> Sort Output: (documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true)), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth Sort Key: "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth -> CTE Scan on "graphLookupRecurseStage" "graphLookup_stage_2" Output: documentdb_api_internal.bson_dollar_merge_documents("graphLookup_stage_2".document, "graphLookup_stage_2".depth, true), "graphLookup_stage_2"."baseDocId", "graphLookup_stage_2".depth (43 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : "alice", "pet" : "dog", "destinations" : [ { "_id" : "dog", "name" : "dog", "depth" : { "$numberInt" : "0" } } ] } { "_id" : "bob", "pet" : "cat", "destinations" : [ ] } (2 rows) END; --- $graphLookup on sharded collection: unsupported SELECT documentdb_api.shard_collection('db', 'ci_search7', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db', 'ci_search8', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "fr", "strength" : 1, "alternate": "shifted" } }'); ERROR: $graphLookup using 'from' on a sharded collection is currently unsupported -- unsupported $merge SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [{"$merge" : { "into": "ci_search9", "whenMatched" : "replace" }} ], "collation": { "locale": "en", "strength" : 1} }'); ERROR: collation is not supported with $merge yet SELECT documentdb_api.shard_collection('db', 'ci_search6', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- lookup with id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "Dog", "a" : { "b" : "Dog" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "DOG", "a" : { "b" : "DOG" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } (7 rows) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 382_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.lookup_filter Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(document, '{ "_id" : "_id", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_7997_7990200 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7997_7990200 collection Output: document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(document, '{ "_id" : "_id", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Distributed Subplan 382_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_7997_7990200 collection_0_1 WHERE documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7997_7990200 collection_0_1 Output: document Filter: (collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT intermediate_result.document, intermediate_result.lookup_filter FROM read_intermediate_result('382_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, lookup_filter documentdb_core.bson)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('382_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, '_id'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result.document, (COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document, intermediate_result.lookup_filter Function Call: read_intermediate_result('382_1'::text, 'binary'::citus_copy_format) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result_1 Output: intermediate_result_1.document Function Call: read_intermediate_result('382_2'::text, 'binary'::citus_copy_format) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(intermediate_result_1.document, intermediate_result.lookup_filter, '_id'::text) (39 rows) END; -- lookup with non-id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "Dog", "a" : { "b" : "Dog" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "DOG", "a" : { "b" : "DOG" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dog", "a" : { "b" : "dog" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "DoG", "a" : { "b" : "DoG" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "dOg", "a" : { "b" : "dOg" }, "matched_docs" : [ { "_id" : "Dog", "a" : { "b" : "Dog" } }, { "_id" : "DOG", "a" : { "b" : "DOG" } }, { "_id" : "dog", "a" : { "b" : "dog" } }, { "_id" : "DoG", "a" : { "b" : "DoG" } }, { "_id" : "dOg", "a" : { "b" : "dOg" } } ] } { "_id" : "Cat", "a" : { "b" : "Cat" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } { "_id" : "cAT", "a" : { "b" : "cAT" }, "matched_docs" : [ { "_id" : "Cat", "a" : { "b" : "Cat" } }, { "_id" : "cAT", "a" : { "b" : "cAT" } } ] } (7 rows) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document -> Distributed Subplan 390_1 -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.lookup_filter Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(document, '{ "a.b" : "a.b", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AS lookup_filter FROM documentdb_data.documents_7997_7990200 collection WHERE true Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7997_7990200 collection Output: document, documentdb_api_internal.bson_dollar_lookup_extract_filter_expression(document, '{ "a.b" : "a.b", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Distributed Subplan 390_2 -> Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_7997_7990200 collection_0_1 WHERE documentdb_api_catalog.bson_dollar_in(document, '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_7997_7990200 collection_0_1 Output: document Filter: (collection_0_1.document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ "cat", "dog" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_merge_documents(lookup_stage_1.document, "lookupRight_stage_1".document, true) AS document FROM ((SELECT intermediate_result.document, intermediate_result.lookup_filter FROM read_intermediate_result('390_1'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson, lookup_filter documentdb_core.bson)) lookup_stage_1 JOIN LATERAL (SELECT COALESCE(documentdb_api_catalog.bson_array_agg(lookup_right_query_stage_0.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) AS document FROM (SELECT intermediate_result.document FROM read_intermediate_result('390_2'::text, 'binary'::citus_copy_format) intermediate_result(document documentdb_core.bson)) lookup_right_query_stage_0 WHERE documentdb_api_internal.bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'a.b'::text)) "lookupRight_stage_1" ON (true)) Node: host=localhost port=58070 dbname=regression -> Nested Loop Output: documentdb_api_internal.bson_dollar_merge_documents(intermediate_result.document, (COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson)), true) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result Output: intermediate_result.document, intermediate_result.lookup_filter Function Call: read_intermediate_result('390_1'::text, 'binary'::citus_copy_format) -> Aggregate Output: COALESCE(documentdb_api_catalog.bson_array_agg(intermediate_result_1.document, 'matched_docs'::text), '{ "matched_docs" : [ ] }'::documentdb_core.bson) -> Function Scan on pg_catalog.read_intermediate_result intermediate_result_1 Output: intermediate_result_1.document Function Call: read_intermediate_result('390_2'::text, 'binary'::citus_copy_format) Filter: documentdb_api_internal.bson_dollar_lookup_join_filter(intermediate_result_1.document, intermediate_result.lookup_filter, 'a.b'::text) (39 rows) END; -- $facet and $unionwith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$facet": { "a" : [ { "$match": { "a.b": "cat" } }, { "$count": "catCount" } ], "b" : [ { "$match": { "a.b": "dog" } }, { "$count": "dogCount" } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1}}'); document --------------------------------------------------------------------- { "a" : [ { "catCount" : { "$numberInt" : "2" } } ], "b" : [ { "dogCount" : { "$numberInt" : "5" } } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$unionWith": { "coll": "ci_search6", "pipeline" : [ { "$match": { "a.b": "cat" }}] } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "Dog", "a" : { "b" : "Dog" } } { "_id" : "DOG", "a" : { "b" : "DOG" } } { "_id" : "dog", "a" : { "b" : "dog" } } { "_id" : "DoG", "a" : { "b" : "DoG" } } { "_id" : "dOg", "a" : { "b" : "dOg" } } { "_id" : "Cat", "a" : { "b" : "Cat" } } { "_id" : "cAT", "a" : { "b" : "cAT" } } { "_id" : "Cat", "a" : { "b" : "Cat" } } { "_id" : "cAT", "a" : { "b" : "cAT" } } (9 rows) -- unsupported $merge SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [{"$merge" : { "into": "ci_search7", "whenMatched" : "replace" }} ], "collation": { "locale": "en", "strength" : 1} }'); ERROR: collation is not supported with $merge yet -- $expr SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 1, "a": "cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 2, "a": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 3, "a": "cAt" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 4, "a": "dOg" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": "hen", "a": "hen" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": "bat", "a": "bat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "hi", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$ne": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fi", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "bat", "a" : "bat" } { "_id" : "hen", "a" : "hen" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$lte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : "bat", "a" : "bat" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr_CA", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "es@collation=search", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gt": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$or": [{"$gte": [ "$a", "DOG" ]}, {"$gte": [ "$a", "CAT" ]}] } }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$and": [{"$lte": [ "$a", "DOG" ]}, {"$lte": [ "$a", "CAT" ]}] } }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : "bat", "a" : "bat" } (3 rows) -- test $expr without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_8000_7990215 collection WHERE (documentdb_api_internal.bson_dollar_expr(document, '{ "" : { "$eq" : [ "$a", "CAT" ] }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson, '{ }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST Node: host=localhost port=58070 dbname=regression -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) Filter: documentdb_api_internal.bson_dollar_expr(collection.document, '{ "" : { "$eq" : [ "$a", "CAT" ] }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson, '{ }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (16 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; -- en_US_POSIX uses a c-style comparison. POSIX locale ignores case insensitivity. This is the ICU semantics. SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en_US_POSIX", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en_US_POSIX", "strength" : 1 } }'); document --------------------------------------------------------------------- (0 rows) -- simple collation SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple"} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple"} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) -- simple locale ignores other options SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "strength": 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "strength": 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "caseFirst": "upper"} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "caseFirst": "lower"} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } (1 row) -- support for $filter SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$eq": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$eq": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 3 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$ne": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "bat", "a" : "bat" } { "_id" : "hen", "a" : "hen" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$or": [{"$gte": [ "$$item", "DOG" ]}, {"$gte": [ "$$item", "CAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$and": [{"$gte": [ "$$item", "DOG" ]}, {"$gte": [ "$$item", "CAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "hen", "a" : "hen" } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$_id"], { "$filter": { "input": ["$_id"], "as": "item", "cond": { "$and": [{"$gte": [ "$$item", "HEN" ]}, {"$gte": [ "$$item", "BAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); document --------------------------------------------------------------------- { "_id" : "hen", "a" : "hen" } (1 row) -- support for $in SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$_id", ["HEN", "BAT"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : "bat", "a" : "bat" } { "_id" : "hen", "a" : "hen" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$_id", ["HEN", "BAT"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- (0 rows) -- support for $indexOfArray SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfArray": [ ["CAT", "DOG"], "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfArray": [ ["CAT", "DOG"], "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- (0 rows) -- support for $indexOfBytes (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "$a", "aT" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "$a", "AT" ] }, -1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "2" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } { "_id" : { "$numberInt" : "4" }, "a" : "dOg" } { "_id" : "bat", "a" : "bat" } { "_id" : "hen", "a" : "hen" } (6 rows) -- support for $indexOfCP (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "$a", "at" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : "bat", "a" : "bat" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "$a", "AT" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- (0 rows) -- support for $strcasecmp (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "cAt" } (2 rows) -- $addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) -- test $addFields auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (12 rows) ROLLBACK; -- $set SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) -- test $set auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_add_fields(document, '{ "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (12 rows) ROLLBACK; -- project SELECT documentdb_api_internal.bson_dollar_project(document, '{ "newField": { "$eq": ["$a", "CAT"] } }', NULL, 'en-u-ks-level1') FROM documentdb_api.collection('db', 'coll_agg_proj'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "newField" : true } { "_id" : { "$numberInt" : "2" }, "newField" : false } { "_id" : { "$numberInt" : "3" }, "newField" : true } { "_id" : { "$numberInt" : "4" }, "newField" : false } { "_id" : "hen", "newField" : false } { "_id" : "bat", "newField" : false } (6 rows) SELECT documentdb_api_internal.bson_dollar_project(document, '{ "newField": { "$eq": ["$a", "DOG"] } }', NULL, 'en-u-ks-level1') FROM documentdb_api.collection('db', 'coll_agg_proj'); bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "newField" : false } { "_id" : { "$numberInt" : "2" }, "newField" : true } { "_id" : { "$numberInt" : "3" }, "newField" : false } { "_id" : { "$numberInt" : "4" }, "newField" : true } { "_id" : "hen", "newField" : false } { "_id" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) -- test $project auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_project(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'fr-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (12 rows) ROLLBACK; -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$eq": ["$a", "CAT"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : false } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : false } { "a" : "hen", "newField" : false } { "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$ne": ["$a", "CAT"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : true } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : true } { "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$lte": ["$a", "DoG"] } } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : true } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : false } { "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : false } { "a" : "dog", "newField" : false } { "a" : "cAt", "newField" : false } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : true } { "a" : "bat", "newField" : false } (6 rows) -- test $replaceRoot auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : false } { "a" : "dog", "newField" : false } { "a" : "cAt", "newField" : false } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : true } { "a" : "bat", "newField" : false } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_replace_root(document, '{ "newRoot" : { "a" : "$a", "newField" : { "$gte" : [ "$a", "doG" ] } } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_replace_root(document, '{ "newRoot" : { "a" : "$a", "newField" : { "$gte" : [ "$a", "doG" ] } } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (12 rows) ROLLBACK; -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$eq": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : false } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : false } { "a" : "hen", "newField" : false } { "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : true } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : true } { "a" : "bat", "newField" : true } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$lte": ["$a", "DoG"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : true } { "a" : "dog", "newField" : true } { "a" : "cAt", "newField" : true } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : false } { "a" : "bat", "newField" : true } (6 rows) -- test $replaceWith auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "a" : "cat", "newField" : false } { "a" : "dog", "newField" : false } { "a" : "cAt", "newField" : false } { "a" : "dOg", "newField" : true } { "a" : "hen", "newField" : true } { "a" : "bat", "newField" : false } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_replace_root(document, '{ "newRoot" : { "a" : "$a", "newField" : { "$gte" : [ "$a", "doG" ] } } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_replace_root(document, '{ "newRoot" : { "a" : "$a", "newField" : { "$gte" : [ "$a", "doG" ] } } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (12 rows) ROLLBACK; -- $documents SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); documents_aggregate --------------------------------------------------------------------- { "result" : "case insensitive" } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); documents_aggregate --------------------------------------------------------------------- { "res" : "case sensitive" } (1 row) -- test $documents without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); documents_aggregate --------------------------------------------------------------------- { "res" : "case sensitive" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Function Scan on documentdb_api_catalog.bson_lookup_unwind documents Output: documents Function Call: bson_lookup_unwind('{ "$documents" : [ { "res" : "case sensitive" } ] }'::bson, '$documents'::text) (3 rows) ROLLBACK; -- $sortArray SELECT documentdb_api.insert_one('db', 'coll_sortArray', '{"_id":1,"a":"one", "b":["10","1"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_sortArray', '{"_id":2,"a":"two", "b":["2","020"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sortArray", "pipeline": [ { "$project": { "sortedArray": { "$sortArray": { "input": ["cat", "dog", "DOG"], "sortBy": 1 } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "sortedArray" : [ "cat", "dog", "DOG" ] } { "_id" : { "$numberInt" : "2" }, "sortedArray" : [ "cat", "dog", "DOG" ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sortArray", "pipeline": [ { "$project": { "sortedArray": { "$sortArray": { "input": ["cat", "dog", "DOG"], "sortBy": 1 } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "sortedArray" : [ "cat", "dog", "DOG" ] } { "_id" : { "$numberInt" : "2" }, "sortedArray" : [ "cat", "dog", "DOG" ] } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sortArray", "filter": { "a": {"$lte": "two"} }, "projection": { "sortedArray": { "$sortArray": { "input": "$b", "sortBy": 1 } } }, "collation": { "locale": "en", "numericOrdering" : false }, "limit": 5 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "sortedArray" : [ "1", "10" ] } { "_id" : { "$numberInt" : "2" }, "sortedArray" : [ "020", "2" ] } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sortArray", "filter": { "a": {"$lte": "two"} }, "projection": { "sortedArray": { "$sortArray": { "input": "$b", "sortBy": 1 } } }, "collation": { "locale": "en", "numericOrdering" : true }, "limit": 5 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "sortedArray" : [ "1", "10" ] } { "_id" : { "$numberInt" : "2" }, "sortedArray" : [ "2", "020" ] } (2 rows) SELECT documentdb_api.drop_collection('db', 'coll_sortArray'); drop_collection --------------------------------------------------------------------- t (1 row) -- find SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : true } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : true } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (5 rows) -- test $find auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "bat", "a" : "bat", "newField" : false } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level3'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text)), (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level3'::text)) -> Sort Output: (documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text)), (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level3'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level3'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$gte" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level3'::text), documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level3'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (17 rows) ROLLBACK; -- $redact SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 2, "level": "restricted", "content": "content 2", "details": { "level": "public", "value": "content 2.1", "moreDetails": { "level": "restricted", "info": "content 2.1.1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 3, "level": "public", "content": "content 3", "details": { "level": "restricted", "value": "content 3.1", "moreDetails": { "level": "public", "info": "content 3.1.1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 4, "content": "content 4", "details": { "level": "public", "value": "content 4.1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 5, "level": "public", "content": "content 5", "details": { "level": "public", "value": "content 5.1", "moreDetails": [{ "level": "restricted", "info": "content 5.1.1" }, { "level": "public", "info": "content 5.1.2" }] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "PUBLIC"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : "public", "content" : "content 1", "details" : { "level" : "public", "value" : "content 1.1", "moreDetails" : { "level" : "restricted", "info" : "content 1.1.1" } } } { "_id" : { "$numberInt" : "3" }, "level" : "public", "content" : "content 3", "details" : { "level" : "restricted", "value" : "content 3.1", "moreDetails" : { "level" : "public", "info" : "content 3.1.1" } } } { "_id" : { "$numberInt" : "5" }, "level" : "public", "content" : "content 5", "details" : { "level" : "public", "value" : "content 5.1", "moreDetails" : [ { "level" : "restricted", "info" : "content 5.1.1" }, { "level" : "public", "info" : "content 5.1.2" } ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "puBliC"] }, "then": "$$DESCEND", "else": "$$PRUNE" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "level" : "public", "content" : "content 1", "details" : { "level" : "public", "value" : "content 1.1" } } { "_id" : { "$numberInt" : "3" }, "level" : "public", "content" : "content 3" } { "_id" : { "$numberInt" : "5" }, "level" : "public", "content" : "content 5", "details" : { "level" : "public", "value" : "content 5.1", "moreDetails" : [ { "level" : "public", "info" : "content 5.1.2" } ] } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "level" : "restricted", "content" : "content 2", "details" : { "level" : "public", "value" : "content 2.1", "moreDetails" : { "level" : "restricted", "info" : "content 2.1.1" } } } { "_id" : { "$numberInt" : "4" }, "content" : "content 4", "details" : { "level" : "public", "value" : "content 4.1" } } (5 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "level" : "restricted", "content" : "content 2", "details" : { "level" : "public", "value" : "content 2.1", "moreDetails" : { "level" : "restricted", "info" : "content 2.1.1" } } } { "_id" : { "$numberInt" : "4" }, "content" : "content 4", "details" : { "level" : "public", "value" : "content 4.1" } } (5 rows) -- test $redact auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "level" : "restricted", "content" : "content 2", "details" : { "level" : "public", "value" : "content 2.1", "moreDetails" : { "level" : "restricted", "info" : "content 2.1.1" } } } { "_id" : { "$numberInt" : "4" }, "content" : "content 4", "details" : { "level" : "public", "value" : "content 4.1" } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_redact(document, '{ "$switch" : { "branches" : [ { "case" : { "$eq" : [ "$level", "PUBLIC" ] }, "then" : "$$PRUNE" }, { "case" : { "$eq" : [ "$classification", "RESTRICTED" ] }, "then" : { "$cond" : { "if" : { "$eq" : [ "$content", null ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } } } ], "default" : "$$KEEP" } }'::documentdb_core.bson, ''::text, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS document FROM documentdb_data.documents_8002_7990240 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8002'::bigint) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_8002_7990240 collection Output: documentdb_api_internal.bson_dollar_redact(document, '{ "$switch" : { "branches" : [ { "case" : { "$eq" : [ "$level", "PUBLIC" ] }, "then" : "$$PRUNE" }, { "case" : { "$eq" : [ "$classification", "RESTRICTED" ] }, "then" : { "$cond" : { "if" : { "$eq" : [ "$content", null ] }, "then" : "$$KEEP", "else" : "$$PRUNE" } } } ], "default" : "$$KEEP" } }'::documentdb_core.bson, ''::text, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8002'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8002'::bigint) (12 rows) ROLLBACK; -- support for $setEquals SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) -- support for $setIntersection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ ] } { "_id" : "bat", "a" : "bat", "newField" : [ ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ ] } { "_id" : "bat", "a" : "bat", "newField" : [ ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ ] } { "_id" : "bat", "a" : "bat", "newField" : [ ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "dog" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "dog" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "dog" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "dog" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "dog" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "cAT", "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "dog" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "cAT", "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "cAT", "dog" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "cAT", "dog" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ ] } { "_id" : "bat", "a" : "bat", "newField" : [ ] } (6 rows) -- support for $setUnion SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "CAT", "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "CAT", "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "CAT", "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "CAT", "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "DOG" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "DOG" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen", "DOG" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "DOG", "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "DOG" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "DOG" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen", "DOG" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "DOG", "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "dog" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "CAT", "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "dog" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "CAT", "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "CAT", "dog", "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "CAT", "bat", "dog" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "dog" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "cAT", "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "dog" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "cAT", "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "cAT", "dog", "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "cAT", "bat", "dog" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "CAT", "DOG", "dog", "cat", "cAT" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "CAT", "DOG", "dog", "cAT" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "CAT", "DOG", "dog", "cAT", "cAt" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "CAT", "DOG", "dog", "dOg", "cAT" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "CAT", "DOG", "dog", "hen", "cAT" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "CAT", "DOG", "bat", "dog", "cAT" ] } (6 rows) -- support for $setDifference SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat" ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ "cat", "cAT", "dog" ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ "dog", "cAT" ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ "cAt", "cAT", "dog" ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ "dOg", "cAT", "dog" ] } { "_id" : "hen", "a" : "hen", "newField" : [ "hen", "cAT", "dog" ] } { "_id" : "bat", "a" : "bat", "newField" : [ "bat", "cAT", "dog" ] } (6 rows) -- support for $setIsSubset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "hen", "a" : "hen", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (6 rows) -- support in $let SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$let": { "vars": { "var1": "$a" }, "in": { "$cond": { "if": { "$eq": ["$$var1", "CAT"] }, "then": 1, "else": 0 } } } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : { "$numberInt" : "0" } } { "_id" : "hen", "a" : "hen", "newField" : { "$numberInt" : "0" } } { "_id" : "bat", "a" : "bat", "newField" : { "$numberInt" : "0" } } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$let": { "vars": { "var1": "$a" }, "in": { "$cond": { "if": { "$eq": ["$$var1", "CAT"] }, "then": 1, "else": 0 } } } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : { "$numberInt" : "0" } } { "_id" : "hen", "a" : "hen", "newField" : { "$numberInt" : "0" } } { "_id" : "bat", "a" : "bat", "newField" : { "$numberInt" : "0" } } (6 rows) -- support for $zip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$zip": { "inputs": [ {"$cond": [{"$eq": ["CAT", "$a"]}, ["$a"], ["null"]]}, ["$a"]] } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ [ "cat", "cat" ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ [ "null", "dog" ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ [ "cAt", "cAt" ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ [ "null", "dOg" ] ] } { "_id" : "hen", "a" : "hen", "newField" : [ [ "null", "hen" ] ] } { "_id" : "bat", "a" : "bat", "newField" : [ [ "null", "bat" ] ] } (6 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$zip": { "inputs": [ {"$cond": [{"$eq": ["CAT", "$a"]}, ["$a"], ["null"]]}, ["$a"]] } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : [ [ "null", "cat" ] ] } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : [ [ "null", "dog" ] ] } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : [ [ "null", "cAt" ] ] } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : [ [ "null", "dOg" ] ] } { "_id" : "hen", "a" : "hen", "newField" : [ [ "null", "hen" ] ] } { "_id" : "bat", "a" : "bat", "newField" : [ [ "null", "bat" ] ] } (6 rows) -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true } { "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false } { "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true } { "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false } { "_id" : "bat", "a" : "bat", "newField" : false } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$eq" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS document FROM documentdb_data.documents_8000_7990215 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8000'::bigint) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: (documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$eq" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text)), (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: (documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$eq" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text)), (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_8000_7990215 collection Output: documentdb_api_internal.bson_dollar_project_find(document, '{ "a" : { "$numberInt" : "1" }, "newField" : { "$eq" : [ "$a", "CAT" ] } }'::documentdb_core.bson, '{ }'::documentdb_core.bson, '{ }'::documentdb_core.bson, 'en-u-ks-level1'::text), documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8000'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8000'::bigint) (17 rows) ROLLBACK; -- query match -- ignore collation (make sure all 3 GUCs are off) SET documentdb.enableLetAndCollationForQueryMatch TO off; SET documentdb.enableVariablesSupportForWriteCommands TO off; SET documentdb_core.enableCollation TO off; SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "CAT"}', NULL, 'en-u-ks-level1'); NOTICE: using bson_query_match implementation bson_query_match --------------------------------------------------------------------- f (1 row) -- enforce collation SET documentdb_core.enableCollation TO on; SET documentdb.enableLetAndCollationForQueryMatch TO on; -- query match: _id tests SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-u-ks-level2'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-US-u-ks-level2'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: $eq SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "CAT"}', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$eq" : "CAT"} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$eq" : "càt"} }', NULL, 'fr-u-ks-level3'); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'sv-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: $ne SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$ne" : "CAT"} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$ne" : "càt"} }', NULL, 'fr-u-ks-level3'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'sv-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: $gt/$gte SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$gt" : "CAT"} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$gte" : "CAT"} }', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: $lt/$lte SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "CAT"} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "càt"} }', NULL, 'fr-u-ks-level3'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "càt"} }', NULL, 'fr-CA-u-ks-level3'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: $in SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$in" : ["CAT", "DOG"]} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$in" : ["càt", "dòg"]} }', NULL, 'fr-u-ks-level3'); bson_query_match --------------------------------------------------------------------- f (1 row) -- query match: $nin SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$nin" : ["CAT", "DOG"]} }', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$nin" : ["càt", "dòg"]} }', NULL, 'fr-u-ks-level3'); bson_query_match --------------------------------------------------------------------- t (1 row) -- query match: sharded collection ALTER SYSTEM SET documentdb_core.enablecollation='on'; SELECT pg_reload_conf(); pg_reload_conf --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "cat", "a": "cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "dog", "a": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": 3, "a": "peacock" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- query match: single shard key SELECT documentdb_api.shard_collection('db', 'coll_qm_sharded', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- we expect the query to be distributed: shard key value is collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT" }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } (1 row) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT" }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8003_7990272 documents_8003 Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (7 rows) ROLLBACK; -- we do not expect the query to be distributed: shard key value is not collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3 }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "peacock" } (1 row) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3 }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_8003_7990273 collection Index Cond: ((shard_key_value = '-4918719581749358852'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "3" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (8 rows) ROLLBACK; -- query match: compound shard key SELECT documentdb_api.drop_collection('db', 'coll_qm_sharded'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "cAt", "a": "cAt" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "doG", "a": "DOg" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": 3, "a": "doG" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db', 'coll_qm_sharded', '{ "_id": "hashed", "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- we expect the query to be distributed: shard key filter values is collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT", "a": "CAT" }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- { "_id" : "cAt", "a" : "cAt" } (1 row) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT", "a": "CAT" }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8004_7990296 documents_8004 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (7 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$and": [{"_id": "cat", "a": "1"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$and": [{"_id": "cat", "a": "1"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_8004_7990300 collection Recheck Cond: (shard_key_value = '-5490684746852247962'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "1", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '-5490684746852247962'::bigint) (10 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "doG" } { "_id" : "cAt", "a" : "cAt" } (2 rows) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": "cat", "a": "CAT"}, {"_id": 3, "a": "dog"}] }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8004_7990296 documents_8004 Filter: (((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bson))) (7 rows) ROLLBACK; -- we do not expect the query to be distributed BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 1, "a": "CAT" }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 1, "a": "CAT" }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8004_7990296 documents_8004 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (7 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3, "a": 4 }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3, "a": 4 }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_8004_7990300 collection Index Cond: ((shard_key_value = '-6813820020108376455'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "3" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (8 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": 3, "a": "dog"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "doG" } (1 row) EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": 3, "a": "dog"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8004_7990296 documents_8004 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson))) (7 rows) ROLLBACK; -- collation on sharded collections: aggregation SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cat", "a": "cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cAt", "a": "cAt" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "dog", "a": "dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "dOg", "a": "dOg" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- simple shard key SELECT documentdb_api.shard_collection('db', 'coll_sharded_agg', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- query is distributed to all shards SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } { "_id" : "cAt", "a" : "cAt" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_8005_7990320 collection WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_8005_7990320 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (20 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": "CAT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } { "_id" : "cAt", "a" : "cAt" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": "CAT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_8005_7990320 collection WHERE (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "CAT", "collation" : "en-u-ks-level2" }'::documentdb_core.bsonquery) Node: host=localhost port=58070 dbname=regression -> Seq Scan on documentdb_data.documents_8005_7990320 collection Output: document Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level2" }'::documentdb_core.bson) (10 rows) -- query is not distributed to all shards (shard key value is not collation-aware) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": 2 } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": 2 } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_8005_7990321 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "2" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '-1389566185330078543'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Index Scan using _id_ on documentdb_data.documents_8005_7990321 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Index Cond: ((collection.shard_key_value = '-1389566185330078543'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "2" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) (16 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": 1 } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": 1 } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_8005_7990327 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level2" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '4322365043291501017'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documentdb_data.documents_8005_7990327 collection Output: document Index Cond: ((collection.shard_key_value = '4322365043291501017'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level2" }'::documentdb_core.bson) (11 rows) -- compound shard key SELECT documentdb_api.drop_collection('db', 'coll_sharded_agg'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cAt", "a": "cAt" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "doG", "a": "Dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db', 'coll_sharded_agg', '{ "_id": "hashed", "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- query is distributed to all shards (filter by shard_key_value is omitted) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "a": { "$eq": "Cat" }, "_id": "caT" }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "cAt", "a" : "cAt" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "a": { "$eq": "Cat" }, "_id": "caT" }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_8006_7990344 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "Cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "caT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_8006_7990344 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "Cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "caT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (20 rows) BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": "CAT", "a": "CAT"} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "cAt", "a" : "cAt" } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": "CAT", "a": "CAT"} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8006_7990344 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (7 rows) ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "cAt", "a" : "cAt" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_8006_7990344 collection WHERE (((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery)) OR ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery))) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_8006_7990344 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bson))) (20 rows) BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "1", "a": "CaT"}, {"_id": "DOG"}]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : "doG", "a" : "Dog" } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "1", "a": "CaT"}, {"_id": "DOG"}]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8006_7990344 collection Filter: (((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "1", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CaT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "DOG", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (7 rows) ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$and": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$and": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Limit Output: remote_scan.document, remote_scan."?sort?" -> Sort Output: remote_scan.document, remote_scan."?sort?" Sort Key: remote_scan."?sort?" USING <<< NULLS FIRST -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan."?sort?" Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) AS "?sort?" FROM documentdb_data.documents_8006_7990344 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bsonquery)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Seq Scan on documentdb_data.documents_8006_7990344 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "3" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : "dog", "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (20 rows) BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "cat", "a": 2 }, {"_id": 1, "a": 1 }]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "cat", "a": 2 }, {"_id": 1, "a": 1 }]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_8006_7990344 collection Filter: (((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : "cat", "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "2" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson))) (7 rows) ROLLBACK; -- query is not distributed to all shards BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": 1, "a": 1 } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": 1, "a": 1 } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_8006_7990349 collection Index Cond: ((shard_key_value = '-1082522962276288030'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) (8 rows) ROLLBACK; -- nested arrays SELECT documentdb_api_internal.bson_query_match('{"a": ["cat"]}', '{ "a": {"$in" : [["CAT"], "DOG"]} }', NULL, 'de-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": ["cat"]}', '{ "a": {"$in" : [["CAT"], ["DOG"]] } }', NULL, 'de-u-ks-level3'); bson_query_match --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 1, "a": ["dog"] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 2, "a": ["cat", "dog"] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 3, "a": [[["cat"]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [ ["dOG"] ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ "dog" ] } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [ [["CAT"]] ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ [ [ "cat" ] ] ] } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [["CAT"], ["DOG"]] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ "dog" ] } (1 row) -- nested documents SELECT documentdb_api_internal.bson_query_match('{"a": {"b": "cat"}}', '{ "a": {"b": "CAT"} }', NULL, 'en-u-ks-level1'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.bson_query_match('{"a": {"b": {"c": "cat"}}}', '{ "a": {"b": {"c": "CAT"}} }', NULL, 'en-u-ks-level2'); bson_query_match --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 1, "a": { "b": "cat" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 2, "a": { "b": "dog" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 3, "a": { "b": { "c": "cat" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 4, "a": { "b": { "c": "dog" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 5, "a": { "b": { "c": { "d": "cat" } } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": "dOG"} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : "dog" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": { "c": "dOg" }} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "c" : "dog" } } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": { "c": { "d": "dOg" }}} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) -- nested documents: keys are collation-agnostic SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"B": "dOG"} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) -- nested arrays and documents SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 1, "a": { "b": ["cat"] } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 2, "a": { "b": ["dog"] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 3, "a": { "b": ["cat", "dog"] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 4, "a": {"b": [["dog"]] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 5, "a": { "b": [[["cat"]]] } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 6, "a": "cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ "dog" ] } } { "_id" : { "$numberInt" : "6" }, "a" : "cat" } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": [["dOg"]] } ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ "dog" ] ] } } (1 row) -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ "dog" ] } } { "_id" : { "$numberInt" : "6" }, "a" : "cat" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_8009_7990389 collection WHERE ((documentdb_api_catalog.bson_dollar_in(document, '{ "a" : [ { "b" : [ "dOG" ] }, "CAT" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "a" : { "b" : [ "dOG" ] }, "collation" : "en-u-ks-level1" }'::documentdb_api_internal.bsonindexbounds, '{ "a" : "CAT", "collation" : "en-u-ks-level1" }'::documentdb_api_internal.bsonindexbounds]))) AND (shard_key_value OPERATOR(pg_catalog.=) '8009'::bigint)) ORDER BY (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING OPERATOR(documentdb_api_internal.<<<) NULLS FIRST LIMIT '5'::bigint Node: host=localhost port=58070 dbname=regression -> Limit Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) -> Sort Output: document, (documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) Sort Key: (documentdb_api_internal.bson_orderby(collection.document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text)) USING <<< NULLS FIRST -> Bitmap Heap Scan on documentdb_data.documents_8009_7990389 collection Output: document, documentdb_api_internal.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson, 'en-u-ks-level1'::text) Recheck Cond: (collection.shard_key_value = '8009'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "b" : [ "dOG" ] }, "CAT" ], "collation" : "en-u-ks-level1" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '8009'::bigint) (18 rows) ROLLBACK; SET documentdb.enableLetAndCollationForQueryMatch to off; -- delete SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "dog", "a":"dog"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "DOG", "a":"DOG"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "cat", "a":"cat"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "CAT", "a":"CAT"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- GUC off: collation ignored SET documentdb_core.enableCollation TO off; BEGIN; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "DoG" }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); ERROR: BSON field 'delete.deletes.collation' is not yet supported CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8010 WHERE shard_key_value = 8010" ROLLBACK; -- enable GUC SET documentdb_core.enableCollation TO on; BEGIN; -- query on _id SET citus.log_remote_commands TO ON; -- _id is not collation-aware SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": 1 }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE (shard_key_value OPERATOR(pg_catalog.=) 8010) NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "1" }, "collation" : "fr-u-ks-level2" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '8010'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "DoG" }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE (shard_key_value OPERATOR(pg_catalog.=) 8010) NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "DoG", "collation" : "fr-u-ks-level2" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '8010'::bigint)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "cAT" }, "limit": 0, "collation": { "locale": "fr", "strength" : 3}} ]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE (shard_key_value OPERATOR(pg_catalog.=) 8010) NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_8010_7990407 documents_8010 WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "cAT", "collation" : "fr-u-ks-level3" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '8010'::bigint)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ROLLBACK; BEGIN; --- deleteMany SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } { "_id" : "cat", "a" : "cat" } { "_id" : "CAT", "a" : "CAT" } (4 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } { "_id" : "cat", "a" : "cat" } { "_id" : "CAT", "a" : "CAT" } (4 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : "DOG" } { "_id" : "CAT", "a" : "CAT" } (2 rows) ROLLBACK; BEGIN; -- more operators in query SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": {"$lt": "DeG"} },"limit": 1, "collation": { "locale": "fr", "strength" : 1} }] }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": {"$lt": "DoG"}, "a": {"$lt": "Goat"} },"limit": 1, "collation": { "locale": "fr", "strength" : 2} }] }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": { "$exists": true }, "a": {"$gt": "DoG"}, "a": {"$lt": "goat"} },"limit": 1, "collation": { "locale": "fr", "strength" : 1 } }] }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } (2 rows) ROLLBACK; -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "a" : "CaT" }, "limit" : { "$numberInt" : "0" }, "collation" : { "locale" : "en", "strength" : { "$numberInt" : "3" } } } ] }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "a" : "CaT" }, "limit" : { "$numberInt" : "1" }, "collation" : { "locale" : "en", "strength" : { "$numberInt" : "3" } } } ] }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; -- delete with sort obeys collation SELECT documentdb_api.insert_one('db', 'coll_delete_sort', '{"_id": "dog", "a": "dog"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete_sort', '{"_id": "DOG", "a": "dog"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; -- sort respects collation: ASC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "dog" } (2 rows) SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : true, "objectId" : { "" : "dog" } } (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : "dog" } (1 row) ROLLBACK; BEGIN; -- sort respects collation: DESC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "dog" } (2 rows) SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : true, "objectId" : { "" : "DOG" } } (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } (1 row) ROLLBACK; -- delete on sharded collection SELECT documentdb_api.shard_collection('db', 'coll_delete', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; --- deleteMany SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } { "_id" : "CAT", "a" : "CAT" } { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } (4 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; -- deleteOne: error: no _id filter and no shard key value filter SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"b": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""delete query with limit 1 must include either _id or shard key filter"" } ] }",f) (1 row) -- deleteOne: error: no _id filter and collation-aware shard key value filter SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""delete query with limit 1 must include either _id or collation-insensitive shard key filter"" } ] }",f) (1 row) BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } { "_id" : "CAT", "a" : "CAT" } { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } (4 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT", "a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "dog", "a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "CAT" } { "_id" : "DOG", "a" : "DOG" } (2 rows) ROLLBACK; BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "cat", "a" : "cat" } { "_id" : "CAT", "a" : "CAT" } { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "DOG" } (4 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : "CAT", "a" : "CAT" } { "_id" : "DOG", "a" : "DOG" } (2 rows) ROLLBACK; SELECT documentdb_api.shard_collection('db', 'coll_delete_sort', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; -- sort respects collation: ASC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "dog" } (2 rows) SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "_id": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : true, "objectId" : { "" : "dog" } } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } (8 rows) SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "DOG", "a" : "dog" } (1 row) ROLLBACK; BEGIN; -- sort respects collation: DESC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } { "_id" : "DOG", "a" : "dog" } (2 rows) SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : true, "objectId" : { "" : "DOG" } } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } { "isRowDeleted" : false } (8 rows) SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); document --------------------------------------------------------------------- { "_id" : "dog", "a" : "dog" } (1 row) ROLLBACK; -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "a" : "CaT" }, "limit" : { "$numberInt" : "0" }, "collation" : { "locale" : "en", "strength" : { "$numberInt" : "3" } } } ] }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "_id" : "DoG" }, "limit" : { "$numberInt" : "1" }, "collation" : { "locale" : "en", "strength" : { "$numberInt" : "3" } } } ] }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; SELECT documentdb_api.drop_collection('db', 'coll_delete'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'coll_delete_sort'); drop_collection --------------------------------------------------------------------- t (1 row) ALTER SYSTEM SET documentdb_core.enablecollation='off'; SELECT pg_reload_conf(); pg_reload_conf --------------------------------------------------------------------- t (1 row) bson_dollar_ops_expr_tests.out000066400000000000000000000075541507310017400361760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7500000; SET documentdb.next_collection_id TO 7500; SET documentdb.next_collection_index_id TO 7500; SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 1, "a": [ 1, 2, 3 ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 2, "a": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 3, "a": "someValue" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 4, "a": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$in": [ "$a", [ 2, "someValue" ] ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "someValue" } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "2" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$gte": [ "$a", 3 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "3" }, "a" : "someValue" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$isArray": "$a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": "$a.0" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) -- invalid scenarios SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "a": { "$elemMatch": { "$expr": { "$isArray": "$a" } } } }'; ERROR: $expr can only be applied to the top-level document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$expr": "$a" } } } }', '{}'); ERROR: $expr can only be applied to the top-level document SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": "$$a" }'; ERROR: Attempting to use an undefined variable: a bson_dollar_ops_json_schema_build_tree_tests.out000066400000000000000000000746441507310017400417130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7600000; SET documentdb.next_collection_id TO 7600; SET documentdb.next_collection_index_id TO 7600; -- The tests in this file ensure that schema provided is valid, and throws error on all invalid scenarios. -- Test for validating documents against valid json schema is provided in separate test file. --------------------------------------------------------------------- -- Object Validators -- --------------------------------------------------------------------- ------------------------ properties ------------------------------------------- -- Must be an object SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": "name" } }'); ERROR: $jsonSchema keyword 'properties' must be an object -- Each property must be an object SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": { "name":"pazu" } } }'); ERROR: Nested schema for $jsonSchema property 'name' must be an object -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": { "name" : { } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ required --------------------------------------------- -- Must be an array SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": "name" } }'); ERROR: Expected an array for 'required' in $jsonSchema, but got string -- duplicated fields SELECT bson_dollar_json_schema('{ "name":"pazu", "name":"tst" }','{ "$jsonSchema": { "required": ["name", "age" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Must be unique SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name", "name" ] } }'); ERROR: Duplicate field name in $jsonSchema 'required' array -- Each element must be a string SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ 1 ] } }'); ERROR: All elements in 'required' array must be strings, but encountered int SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name",1,"age" ] } }'); ERROR: All elements in 'required' array must be strings, but encountered int SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": ["name", ["a","b","c"], "age" ] } }'); ERROR: All elements in 'required' array must be strings, but encountered array -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name","age" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name","age" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "":1 }','{ "$jsonSchema": { "required": [ "" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "a":1 }','{ "$jsonSchema": { "required": [ "" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{ "":1, "name":"pazu","age":10 }','{ "$jsonSchema": { "required": [ "","name","age" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "":1, "age":10 }','{ "$jsonSchema": { "required": [ "","name","age" ] } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) --------------------------------------------------------------------- -- Common Validators -- --------------------------------------------------------------------- ------------------------ type ------------------------------------------------- -- Must be a string or array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": 1 } } } }'); ERROR: The 'type' property in $jsonSchema must be defined as either a single string or an array containing multiple strings -- Must be a valid json type SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "hello" } } } }'); ERROR: Unrecognized data type alias: hello -- Json type "integer" not supported SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "integer" } } } }'); ERROR: The 'integer' type in $jsonSchema is not supported at this time. -- Array must not be empty SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ ] } } } }'); ERROR: $jsonSchema keyword 'type' must name at least one type -- Array elements must be strings SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ 2 ] } } } }'); ERROR: $jsonSchema keyword 'type' array elements must be strings -- Array elements must not contain duplicate values SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ "string", "string" ] } } } }'); ERROR: $jsonSchema keyword 'type' has duplicate value: string -- Valid case - string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "string" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Valid case - array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": ["string", "object"] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ bsonType --------------------------------------------- -- Must be a string or array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": 1 } } } }'); ERROR: $jsonSchema keyword 'bsonType' must be either a string or an array of strings -- Must be a valid json type SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "hello" } } } }'); ERROR: Unrecognized data type alias: hello -- Bson type "integer" not supported. "int" is supported SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "integer" } } } }'); ERROR: The 'integer' type in $jsonSchema is not supported at this time. -- Array must not be empty SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ ] } } } }'); ERROR: $jsonSchema keyword 'bsonType' must name at least one type -- Array elements must be strings SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ 2 ] } } } }'); ERROR: $jsonSchema keyword 'bsonType' array elements must be strings -- Array elements must not contain duplicate values SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ "string", "string" ] } } } }'); ERROR: $jsonSchema keyword 'bsonType' has duplicate value: string -- Valid case - string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "string" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Valid case - array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": ["string", "object"] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Numeric Validators -- --------------------------------------------------------------------- ------------------------ multipleOf ------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": "hello" } } } }'); ERROR: $jsonSchema keyword 'multipleOf' must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": null } } } }'); ERROR: $jsonSchema keyword 'multipleOf' must be a number -- Must be a non-zero SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": 0 } } } }'); ERROR: $jsonSchema keyword 'multipleOf' must have a positive value -- Must not be NaN SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "NaN"} } } } }'); ERROR: A divisor value must not be NaN SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "-NaN"} } } } }'); ERROR: A divisor value must not be NaN SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "NaN"} } } } }'); ERROR: A divisor value must not be NaN SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "-NaN"} } } } }'); ERROR: A divisor value must not be NaN -- Must not be INF SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "INF"} } } } }'); ERROR: Division by an infinite value is not allowed SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "-INF"} } } } }'); ERROR: Division by an infinite value is not allowed SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "INF"} } } } }'); ERROR: Division by an infinite value is not allowed SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "-INF"} } } } }'); ERROR: Division by an infinite value is not allowed -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberInt": "1"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble": "2.2"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) ------------------------ maximum ---------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": "hello" } } } }'); ERROR: $jsonSchema keyword 'maximum' must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": null } } } }'); ERROR: $jsonSchema keyword 'maximum' must be a number -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": {"$numberDouble": "99.9"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ exclusiveMaximum ------------------------------------- -- Must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": "hello" } } } }'); ERROR: $jsonSchema keyword 'exclusiveMaximum' must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": null } } } }'); ERROR: $jsonSchema keyword 'exclusiveMaximum' must be a boolean -- if exclusiveMaximum is present, maximum must be present too SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": true } } } }'); ERROR: $jsonSchema keyword 'maximum' must be a present if exclusiveMaximum is present -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": true, "maximum" : 99 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ minimum ---------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": "hello" } } } }'); ERROR: $jsonSchema keyword 'minimum' must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": null } } } }'); ERROR: $jsonSchema keyword 'minimum' must be a number -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": {"$numberDouble": "4.0"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ exclusiveMinimum ------------------------------------- -- Must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": "hello" } } } }'); ERROR: $jsonSchema keyword 'exclusiveMinimum' must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": null } } } }'); ERROR: $jsonSchema keyword 'exclusiveMinimum' must be a boolean -- if exclusiveMaximum is present, maximum must be present too SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": true } } } }'); ERROR: $jsonSchema keyword 'minimum' must be a present if exclusiveMinimum is present -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": true, "minimum" : 5 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- String Validators -- --------------------------------------------------------------------- ------------------------ maxLength -------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": "hello" } } } }'); ERROR: A numeric value was expected in maxLength, but instead "hello" was encountered SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": null } } } }'); ERROR: A numeric value was expected in maxLength, but instead null was encountered -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "9223372036854775809"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxLength: 9.22337E+18 SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "NaN"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxLength: NaN SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxLength: Infinity SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "-INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxLength: -Infinity -- Must be integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "10.3"} } } } }'); ERROR: Expected value of integer type: maxLength: 10.3 -- Must be positive integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "-10"} } } } }'); ERROR: Value for maxLength cannot be zero or negative. Got -10 -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "10"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ minLength -------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": "hello" } } } }'); ERROR: A numeric value was expected in minLength, but instead "hello" was encountered SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": null } } } }'); ERROR: A numeric value was expected in minLength, but instead null was encountered -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "9223372036854775809"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minLength: 9.22337E+18 SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "NaN"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minLength: NaN SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minLength: Infinity SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "-INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minLength: -Infinity -- Must be integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "1.3"} } } } }'); ERROR: Expected value of integer type: minLength: 1.3 -- Must be positive integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "-1"} } } } }'); ERROR: Value for minLength cannot be zero or negative. Got -1 -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "1"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ pattern ---------------------------------------------- -- Must be a string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": 1 } } } }'); ERROR: $jsonSchema keyword 'pattern' must be a string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": null} } } }'); ERROR: $jsonSchema keyword 'pattern' must be a string -- Must be a valid regex SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "\\" } } } }'); ERROR: The provided regular expression format is invalid: \ at end of pattern -- Valid Schemas SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "^[a-zA-Z_]*$" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Array Validators -- --------------------------------------------------------------------- ------------------------ items ------------------------------------------------ -- Must be an object or an array of objects SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": 1 } } } }'); ERROR: $jsonSchema keyword 'items' must be an array or an object, not int SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": null } } } }'); ERROR: $jsonSchema keyword 'items' must be an array or an object, not null -- if its an array, it must contain all objects SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [{ }, 1] } } } }'); ERROR: $jsonSchema keyword 'items' requires that each element of the array is an object, but found a int -- Valid Schemas SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [{ }, {"bsonType":"int"} ] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": { } } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ additionalItems -------------------------------------- -- Must be an object/bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": 1 } } } }'); ERROR: $jsonSchema keyword 'additionalItems' must be either an object or a boolean, but got a int SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": null } } } }'); ERROR: $jsonSchema keyword 'additionalItems' must be either an object or a boolean, but got a null -- Valid Schema - Object SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": { } } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Valid Schema - Bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ maxItems --------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": "hello" } } } }'); ERROR: A numeric value was expected in maxItems, but instead "hello" was encountered SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": null } } } }'); ERROR: A numeric value was expected in maxItems, but instead null was encountered -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "9223372036854775809"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxItems: 9.22337E+18 SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxItems: Infinity SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "NaN"} } } } }'); ERROR: Unable to store value as a 64-bit integer: maxItems: NaN -- Must be integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "10.3"} } } } }'); ERROR: Expected value of integer type: maxItems: 10.3 -- Must be positive integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "-10"} } } } }'); ERROR: Value for maxItems cannot be zero or negative. Got -10 -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "10"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ minItems --------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": "hello" } } } }'); ERROR: A numeric value was expected in minItems, but instead "hello" was encountered SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": null } } } }'); ERROR: A numeric value was expected in minItems, but instead null was encountered -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "9223372036854775809"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minItems: 9.22337E+18 SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "INF"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minItems: Infinity SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "NaN"} } } } }'); ERROR: Unable to store value as a 64-bit integer: minItems: NaN -- Must be integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "1.3"} } } } }'); ERROR: Expected value of integer type: minItems: 1.3 -- Must be positive integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "-1"} } } } }'); ERROR: Value for minItems cannot be zero or negative. Got -1 -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "1"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ------------------------ uniqueItems ------------------------------------------ -- Must be a bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": "hello" } } } }'); ERROR: $jsonSchema keyword 'uniqueItems' must be a boolean SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": null } } } }'); ERROR: $jsonSchema keyword 'uniqueItems' must be a boolean -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Unsupported Keywords -- --------------------------------------------------------------------- SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "$ref" : "hello", "$id" : 2 } }'); ERROR: The '$ref' keyword in $jsonSchema is not supported at this time SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "$schema" : "hello" } }'); ERROR: The '$schema' keyword in $jsonSchema is not supported at this time SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "default" : "hello" } }'); ERROR: The 'default' keyword in $jsonSchema is not supported at this time SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "definitions" : "hello" } }'); ERROR: The 'definitions' keyword in $jsonSchema is not supported at this time SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "format" : "hello" } }'); ERROR: The 'format' keyword in $jsonSchema is not supported at this time SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "id" : "hello" } }'); ERROR: The 'id' keyword in $jsonSchema is not supported at this time --------------------------------------------------------------------- -- Unknown Keywords -- --------------------------------------------------------------------- SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "hello" : "hello" } }'); ERROR: Unknown $jsonSchema keyword: hello bson_dollar_ops_json_schema_query_tests.out000066400000000000000000002602771507310017400407410ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7700000; SET documentdb.next_collection_id TO 7700; SET documentdb.next_collection_index_id TO 7700; SELECT documentdb_api.insert_one('db', 'col_bson_dollar_ops_json_schema_query', '{ "_id": 0, "itemType": "alpha", "count" : 4, "flag" : true, "height" : 5.8, "width" : { "$numberDecimal": "4.2" }, "details" : { "year" : 2020, "shade" : "black" }, "features": ["optionA", {"drive": "front"}, {"extra": true, "free": true} ], "engine": { "cc": 1500, "fuel": "petrol" } }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'col_bson_dollar_ops_json_schema_query', '{ "_id": 1, "itemType": 20, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : 10, "lower" : 20 }, "details" : 2010, "features": null, "engine": 1500 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --------------------------------------------------------------------- -- Common Validations -- --------------------------------------------------------------------- ---------------------------- "type" ------------------------------------------- -- All docs Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } { "_id" : { "$numberInt" : "1" }, "itemType" : { "$numberInt" : "20" }, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : { "$numberInt" : "10" }, "lower" : { "$numberInt" : "20" } }, "details" : { "$numberInt" : "2010" }, "features" : null, "engine" : { "$numberInt" : "1500" } } (2 rows) -- All docs Match, as none of docs have given field SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "cosmosdb" : { "type" : "string" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } { "_id" : { "$numberInt" : "1" }, "itemType" : { "$numberInt" : "20" }, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : { "$numberInt" : "10" }, "lower" : { "$numberInt" : "20" } }, "details" : { "$numberInt" : "2010" }, "features" : null, "engine" : { "$numberInt" : "1500" } } (2 rows) -- No Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "boolean" } } } }'); document --------------------------------------------------------------------- (0 rows) -- Matches where "itemType" is "string" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "string" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "count" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "number" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "height" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "height" : { "type" : "number" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "width" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "width" : { "type" : "number" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "details" is "object" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "details" : { "type" : "object" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "features" is "array" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "features" : { "type" : "array" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "flag" is "boolean" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "flag" : { "type" : "boolean" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "itemType" is "string" and "count" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "string" }, "count" : { "type" : "number" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Unsupported: "integer" type SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "integer" } } } }'); ERROR: The 'integer' type in $jsonSchema is not supported at this time. ---------------------------- "bsonType" ------------------------------------------- -- All docs Match, as none of docs have given field SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "cosmosdb" : { "bsonType" : "string" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } { "_id" : { "$numberInt" : "1" }, "itemType" : { "$numberInt" : "20" }, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : { "$numberInt" : "10" }, "lower" : { "$numberInt" : "20" } }, "details" : { "$numberInt" : "2010" }, "features" : null, "engine" : { "$numberInt" : "1500" } } (2 rows) -- No Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "bool" } } } }'); document --------------------------------------------------------------------- (0 rows) -- Matches where "itemType" is "string" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "string" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "count" is "int" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "bsonType" : "int" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "height" is "double" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "height" : { "bsonType" : "double" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "width" is "decimal" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "width" : { "bsonType" : "decimal" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "details" is "object" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "details" : { "bsonType" : "object" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "features" is "array" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "features" : { "bsonType" : "array" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "flag" is "boolean" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "flag" : { "bsonType" : "bool" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Matches where "itemType" is "string" and "count" is "int" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "string" }, "count" : { "bsonType" : "int" } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } (1 row) -- Unsupported: "integer" type SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "integer" } } } }'); ERROR: The 'integer' type in $jsonSchema is not supported at this time. --------------------------------------------------------------------- -- Numeric Validations -- --------------------------------------------------------------------- --------------------------- multipleOf ---------------------------------------- -- Doc is valid as field's value is a multiple of "multipleOf" SELECT bson_dollar_json_schema('{"size": 0}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2.2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --In the following test doc is evaluated as invalid, because psql converts double value of 1.1 to 1.1000000000000001, which is not a multiple of 11 --This would not happen when req comes from gateway. So commenting out this test in psql, but will add this test as JS test in Gateway --SELECT bson_dollar_json_schema('{"size": 11}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : {"$numberDouble" : "1.1"} } } } }'); -- Doc is invalid as field's value is not a multiple of "multipleOf" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 3 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------- maximum ---------------------------------------- -- Doc is valid as field's value is less than or equal to given value of "maximum" SELECT bson_dollar_json_schema('{"size": 2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as field's value is more than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------- exclusiveMaximum ------------------------------- -- When "exclusiveMaximum" is true, these doc are valid as field's value is strictly less than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- When "exclusiveMaximum" is true, these doc are invalid as field's value is more than or equal to the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- When "exclusiveMaximum" is false, these doc are valid as field's value is less than or equal to the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- When "exclusiveMaximum" is false, these doc are invalid as field's value is more than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------- minimum ---------------------------------------- -- Doc is valid as field's value is more than or equal to given value of "minimum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as field's value is less than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 3.9}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.11 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------- exclusiveMinimum ------------------------------- -- When "exclusiveMinimum" is true, these doc are valid as field's value is strictly more than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.11}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- When "exclusiveMinimum" is true, these doc are invalid as field's value is less than or equal to the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"}, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- When "exclusiveMinimum" is false, these doc are valid as field's value is more than or equal to the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- When "exclusiveMinimum" is false, these doc are invalid as field's value is less than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 3.9}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.11, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"size": [3] }','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- String Validations -- --------------------------------------------------------------------- --------------------------- maxLength ---------------------------------------- -- Doc is valid as length of string is less than or eq to maxLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 10 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as length of string is less than or eq to maxLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if property is not a string SELECT bson_dollar_json_schema('{"name": 2}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------- minLength ---------------------------------------- -- Doc is valid as length of string is more than or eq to minLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as length of string is more than the minLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 10 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid if property is not a string SELECT bson_dollar_json_schema('{"name": 2}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 4 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ---------------------------- pattern ----------------------------------------- -- Doc is valid as given pattern matches the string SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "^P" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "[auzP]" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as given pattern does not matches the string SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "^a" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "$z" } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) --------------------------------------------------------------------- -- Array Validations -- --------------------------------------------------------------------- ---------------------------- items -------------------------------------------- -- Doc is valid as "data" array's each value matches the schema given in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" } ] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as "data" array's each value does matches the schema given in "items" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "object" }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"number" }] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid when "items" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" } ] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : "Hello" }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "number" } ] } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ---------------------------- additionalItems ---------------------------------- -- Doc is valid as "data" array values matches the schema given in "items", and data array has no more members than the number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as "data" array has more members than the number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid as "data" array values matches the schema given in "items", while data array can have more members than number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is valid, if "items" keyword is not provided, since "additionalItems" has no effect without "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is valid, if "additionalItems" is provided for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ---------------------------- maxItems ----------------------------------------- -- Doc is valid as "data" array members are less than or equal to given "maxItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 0 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as "data" array members are more than the given "maxItems" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid when "maxItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ---------------------------- minItems ----------------------------------------- -- Doc is valid as "data" array members are more than or equal to given "minItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 0 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as "data" array members are less than the given "minItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid when "minItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 1 } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) ---------------------------- uniqueItems -------------------------------------- -- Doc is valid as all items in the given array are unique SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, 1.1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"1":1}, "1" ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"1":1}, "1", true ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1}, {"b":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":1}, {"a":2, "b":2} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":1}, {"a":2, "b":2} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- Doc is invalid as all items in the given array are not unique SELECT bson_dollar_json_schema('{"data" : [ 1, 1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, 1.0 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, true, true ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ false, 1, false ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ "Hi", "Hi", 1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is invalid, as objects that have same key-value pairs, even in different orders, are not unique. Applicable to objects recursively (i.e. objects in objects) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":2}, {"b":2, "a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a": {"x":5, "y": 6}, "b":2}, {"b":2, "a": {"y":6, "x":5}} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) -- Doc is valid when "uniqueItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 1 }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) --------------------------------------------------------------------- -- Binary Validations -- --------------------------------------------------------------------- SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : 1}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- f (1 row) SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"keyId": ["9e4cfa3e-2b56-4e20-9fd3-3c3708056a18"], "algorithm":"AEAD_AES_256_CBC_HMAC_SHA_512-Random", "bsonType":"string"} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": {"encryptMetadata": {"keyId": ["9e4cfa3e-2b56-4e20-9fd3-3c3708056a18"], "algorithm":"AEAD_AES_256_CBC_HMAC_SHA_512-Random"} } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- negative test cases SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": "test"} }'); ERROR: $jsonSchema keyword 'encryptMetadata' must be a document SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {}} }'); ERROR: $jsonSchema keyword 'encryptMetadata' cannot be an empty object SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"unknown":"hello"}} }'); ERROR: The BSON field 'encryptMetadata.unknown' is not recognized as a valid or supported field. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"keyId":1}} }'); ERROR: The BSON field 'encryptMetadata.keyId' has an incorrect type 'int'; it should be of type 'array'. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"algorithm":[]}} }'); ERROR: The BSON field 'encryptMetadata.algorithm' has an incorrect type 'array'; it should be of type 'string'. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"a":1} } } } }'); ERROR: The BSON field 'encrypt.a' is not recognized as a valid field. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"keyId":1} } } } }'); ERROR: The BSON field 'encrypt.keyId' has an incorrect type 'int'; it should be of type 'array'. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"algorithm":[]} } } } }'); ERROR: The BSON field 'encrypt.algorithm' has an incorrect type 'array'; it should be of type 'string'. SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"bsonType": 123} } } } }'); ERROR: $jsonSchema keyword 'bsonType' must be either a string or an array of strings SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : "" } } } }'); ERROR: $jsonSchema keyword 'encrypt' must be a document SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {}, "type":"string" } } } }'); ERROR: 'encrypt' implies 'bsonType: BinData' and cannot be combined with 'type' in $jsonSchema SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {}, "bsonType":"string" } } } }'); ERROR: 'encrypt' implies 'bsonType: BinData' and cannot be combined with 'type' in $jsonSchema -- guc test cases set documentdb.enableSchemaEnforcementForCSFLE = false; SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : 1}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); bson_dollar_json_schema --------------------------------------------------------------------- t (1 row) -- $jsonSchema will be supported in query condition later --------------------------------------------------------------------- -- $jsonSchema in query condition -- --------------------------------------------------------------------- -- All docs Match SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { } } }, "$db" : "db" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.col_bson_dollar_ops_json_schema_query", "firstBatch" : [ { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } }, { "_id" : { "$numberInt" : "1" }, "itemType" : { "$numberInt" : "20" }, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : { "$numberInt" : "10" }, "lower" : { "$numberInt" : "20" } }, "details" : { "$numberInt" : "2010" }, "features" : null, "engine" : { "$numberInt" : "1500" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- -- No Match SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { "itemType" : { "type" : "boolean" } } } }, "$db" : "db" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.col_bson_dollar_ops_json_schema_query", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- -- Matches where "vehicle" is "string" SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { "itemType" : { "type" : "string" } } } }, "$db" : "db" }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.col_bson_dollar_ops_json_schema_query", "firstBatch" : [ { "_id" : { "$numberInt" : "0" }, "itemType" : "alpha", "count" : { "$numberInt" : "4" }, "flag" : true, "height" : { "$numberDouble" : "5.7999999999999998224" }, "width" : { "$numberDecimal" : "4.2" }, "details" : { "year" : { "$numberInt" : "2020" }, "shade" : "black" }, "features" : [ "optionA", { "drive" : "front" }, { "extra" : true, "free" : true } ], "engine" : { "cc" : { "$numberInt" : "1500" }, "fuel" : "petrol" } } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) bson_dollar_ops_query_all_tests_index.out000066400000000000000000001053411507310017400403750ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none NOTICE: creating collection -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_all_tests_core.sql -- top level SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 1, "a": "b"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 2, "a": ["a", "b"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 3, "a": ["a", "b", "c"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 4, "a": ["y", "z", "a"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 5, "a": ["y", "z", "a", { "d": 1 }, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested and empty arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 6, "a": [[["x", "y"], ["z"]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 7, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 8, "a": [[]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested objects SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 9, "a": {"b": [ ["a", "z", "b"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 10, "a": {"b": [ ["a", "z", "b"], ["x", "y"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 11, "a": {"b": [ ["a", "z", "b"], ["x", "y"], ["c"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 12, "a": {"b": { "c": ["d"] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 13, "a": {"b": { "c": { "d": 1 }}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with elements that sort after arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 14, "foo": true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 15, "foo": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 16, "foo": [ 1, "a", true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 17, "foo": [true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 18, "other": [ 1, null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 19, "other": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 20, "other": [1, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 21, "other": [1, 0.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 22, "other": [1, 0.0, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 23, "other": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents inside array SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 24, "array": [ {"x": 1}, {"x": 2}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 25, "array": [ {"x": 2}, {"x": 3}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 26, "array": [ {"x": 3}, {"x": 4}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- top level simple SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "a"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "c"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }, "a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 2 }]}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [2]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- array indexes selector SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0" : ["b"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.1" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y", "x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.1" : [ ["z"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0.0" : ["x"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.3" : [{ "d": 1 }] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- top level nested arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["z"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"], ["z"]]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) -- empty arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [ [] ] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (1 row) -- nested objects and arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) -- nested objects and arrays with objects SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ "d" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ [ "d" ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ { "d": 1 } ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [{ }] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1, 2 ] }'; document --------------------------------------------------------------------- (0 rows) -- objects with elements that sort after arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- null and NaN SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (23 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null, "foo" ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ "foo", null, null, null ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ], [null] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (3 rows) -- all with repeated elements SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [[true], [true], [true], [true]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false, false, false, false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false, true, false, true ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a", "a", "a", "a", "a", 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, 1, 1, 1, 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- query for path inside array SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 2 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 2, 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 3 ] }'; document --------------------------------------------------------------------- (0 rows) ROLLBACK; \set QUIET off bson_dollar_ops_query_all_tests_index_backcompat.out000066400000000000000000001054321507310017400425620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none NOTICE: creating collection -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_all_tests_core.sql -- top level SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 1, "a": "b"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 2, "a": ["a", "b"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 3, "a": ["a", "b", "c"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 4, "a": ["y", "z", "a"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 5, "a": ["y", "z", "a", { "d": 1 }, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested and empty arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 6, "a": [[["x", "y"], ["z"]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 7, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 8, "a": [[]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested objects SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 9, "a": {"b": [ ["a", "z", "b"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 10, "a": {"b": [ ["a", "z", "b"], ["x", "y"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 11, "a": {"b": [ ["a", "z", "b"], ["x", "y"], ["c"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 12, "a": {"b": { "c": ["d"] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 13, "a": {"b": { "c": { "d": 1 }}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with elements that sort after arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 14, "foo": true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 15, "foo": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 16, "foo": [ 1, "a", true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 17, "foo": [true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 18, "other": [ 1, null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 19, "other": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 20, "other": [1, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 21, "other": [1, 0.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 22, "other": [1, 0.0, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 23, "other": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents inside array SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 24, "array": [ {"x": 1}, {"x": 2}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 25, "array": [ {"x": 2}, {"x": 3}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 26, "array": [ {"x": 3}, {"x": 4}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- top level simple SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "a"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "c"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }, "a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 2 }]}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [2]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- array indexes selector SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0" : ["b"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.1" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y", "x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.1" : [ ["z"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0.0" : ["x"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.3" : [{ "d": 1 }] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- top level nested arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["z"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"], ["z"]]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) -- empty arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [ [] ] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (1 row) -- nested objects and arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) -- nested objects and arrays with objects SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ "d" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ [ "d" ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ { "d": 1 } ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [{ }] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1, 2 ] }'; document --------------------------------------------------------------------- (0 rows) -- objects with elements that sort after arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- null and NaN SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (23 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null, "foo" ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ "foo", null, null, null ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ], [null] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (3 rows) -- all with repeated elements SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [[true], [true], [true], [true]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false, false, false, false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false, true, false, true ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a", "a", "a", "a", "a", 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, 1, 1, 1, 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- query for path inside array SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 2 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 2, 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 3 ] }'; document --------------------------------------------------------------------- (0 rows) ROLLBACK; \set QUIET off bson_dollar_ops_query_all_tests_runtime.out000066400000000000000000001052531507310017400407530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none NOTICE: creating collection -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_all_tests_core.sql -- top level SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 1, "a": "b"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 2, "a": ["a", "b"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 3, "a": ["a", "b", "c"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 4, "a": ["y", "z", "a"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 5, "a": ["y", "z", "a", { "d": 1 }, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested and empty arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 6, "a": [[["x", "y"], ["z"]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 7, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 8, "a": [[]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested objects SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 9, "a": {"b": [ ["a", "z", "b"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 10, "a": {"b": [ ["a", "z", "b"], ["x", "y"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 11, "a": {"b": [ ["a", "z", "b"], ["x", "y"], ["c"] ]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 12, "a": {"b": { "c": ["d"] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 13, "a": {"b": { "c": { "d": 1 }}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with elements that sort after arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 14, "foo": true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 15, "foo": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 16, "foo": [ 1, "a", true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 17, "foo": [true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 18, "other": [ 1, null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 19, "other": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 20, "other": [1, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 21, "other": [1, 0.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 22, "other": [1, 0.0, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 23, "other": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents inside array SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 24, "array": [ {"x": 1}, {"x": 2}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 25, "array": [ {"x": 2}, {"x": 3}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 26, "array": [ {"x": 3}, {"x": 4}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- top level simple SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "a"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "c"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }, "a", "y", "z"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 2 }]}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [2]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- array indexes selector SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0" : ["b"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.1" : ["b"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y", "x"] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.1" : [ ["z"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0.0" : ["x"] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.3" : [{ "d": 1 }] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } (1 row) -- top level nested arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["z"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"]]] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"], ["z"]]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } (1 row) -- empty arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [ [] ] ]}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } (1 row) -- nested objects and arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["c"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["x", "y"] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } (2 rows) -- nested objects and arrays with objects SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ "d" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ [ "d" ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ { "d": 1 } ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [{ }] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1, 2 ] }'; document --------------------------------------------------------------------- (0 rows) -- objects with elements that sort after arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- null and NaN SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "b" } { "_id" : { "$numberInt" : "2" }, "a" : [ "a", "b" ] } { "_id" : { "$numberInt" : "3" }, "a" : [ "a", "b", "c" ] } { "_id" : { "$numberInt" : "4" }, "a" : [ "y", "z", "a" ] } { "_id" : { "$numberInt" : "5" }, "a" : [ "y", "z", "a", { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "6" }, "a" : [ [ [ "x", "y" ], [ "z" ] ] ] } { "_id" : { "$numberInt" : "7" }, "a" : [ ] } { "_id" : { "$numberInt" : "8" }, "a" : [ [ ] ] } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ [ "a", "z", "b" ] ] } } { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ] ] } } { "_id" : { "$numberInt" : "11" }, "a" : { "b" : [ [ "a", "z", "b" ], [ "x", "y" ], [ "c" ] ] } } { "_id" : { "$numberInt" : "12" }, "a" : { "b" : { "c" : [ "d" ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } } { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (23 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "15" }, "foo" : false } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } { "_id" : { "$numberInt" : "18" }, "other" : [ { "$numberInt" : "1" }, null ] } { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null, "foo" ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ "foo", null, null, null ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ], [null] ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "other" : [ null ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0, NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ NaN ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "20" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "22" }, "other" : [ { "$numberInt" : "1" }, { "$numberDouble" : "0.0" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "23" }, "other" : [ null, { "$numberDouble" : "NaN" } ] } (3 rows) -- all with repeated elements SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "foo" : true } { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [[true], [true], [true], [true]] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "17" }, "foo" : [ true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false, false, false, false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "foo" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false, true, false, true ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a", "a", "a", "a", "a", 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, 1, 1, 1, 1, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "foo" : [ { "$numberInt" : "1" }, "a", true ] } (1 row) -- query for path inside array SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 2 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "24" }, "array" : [ { "x" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 2, 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 3 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "array" : [ { "x" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" } } ] } { "_id" : { "$numberInt" : "26" }, "array" : [ { "x" : { "$numberInt" : "3" } }, { "x" : { "$numberInt" : "4" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 3 ] }'; document --------------------------------------------------------------------- (0 rows) ROLLBACK; \set QUIET off bson_dollar_ops_query_array_size_tests_index.out000066400000000000000000000151611507310017400417750ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 430000; SET documentdb.next_collection_id TO 4300; SET documentdb.next_collection_index_id TO 4300; \set QUIET on \set prevEcho :ECHO \set ECHO none ?column? --------------------------------------------------------------------- t (1 row) NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','arraysize'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_array_size_tests_core.sql -- top level SELECT documentdb_api.insert_one('db','arraysize','{"_id": 1, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 2, "a": [1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 3, "a": ["a", "a"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 4, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 5, "b": [1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested object SELECT documentdb_api.insert_one('db','arraysize','{"_id": 6, "a": {"b":[]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 7, "a": {"b":[1, 2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 8, "a": {"b":["a", "a"]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 9, "a": {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 10, "b": {"b":[1, 2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested array SELECT documentdb_api.insert_one('db','arraysize','{"_id": 11, "c": [{"b":[]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 12, "c": [{"b":[1, 2]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 13, "c": [{"b":["a", "a"]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 14, "c": [{"b":1}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 15, "b": [{"b":[1, 2]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- assert that size returns the correct number of rows. SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) ROLLBACK; \set QUIET off bson_dollar_ops_query_array_size_tests_runtime.out000066400000000000000000000150731507310017400423530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 430000; SET documentdb.next_collection_id TO 4300; SET documentdb.next_collection_index_id TO 4300; \set QUIET on \set prevEcho :ECHO \set ECHO none ?column? --------------------------------------------------------------------- t (1 row) NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','arraysize'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_array_size_tests_core.sql -- top level SELECT documentdb_api.insert_one('db','arraysize','{"_id": 1, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 2, "a": [1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 3, "a": ["a", "a"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 4, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 5, "b": [1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested object SELECT documentdb_api.insert_one('db','arraysize','{"_id": 6, "a": {"b":[]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 7, "a": {"b":[1, 2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 8, "a": {"b":["a", "a"]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 9, "a": {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 10, "b": {"b":[1, 2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested array SELECT documentdb_api.insert_one('db','arraysize','{"_id": 11, "c": [{"b":[]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 12, "c": [{"b":[1, 2]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 13, "c": [{"b":["a", "a"]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 14, "c": [{"b":1}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','arraysize','{"_id": 15, "b": [{"b":[1, 2]}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- assert that size returns the correct number of rows. SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 0 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 2 }'; count --------------------------------------------------------------------- 2 (1 row) ROLLBACK; \set QUIET off bson_dollar_ops_query_bits_tests_explain.out000066400000000000000000001112471507310017400411210ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 9500000; SET documentdb.next_collection_id TO 9500; SET documentdb.next_collection_index_id TO 9500; SELECT documentdb_api.create_collection('db', 'bitwiseOperators'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) --insert data SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 54}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 88}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 255}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"9", "a": {"$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"10", "a": {"$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Explain Plan on runtime SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bitwiseOperators'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO ON; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; --$bitsAllClear runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAnyClear runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAllSet runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: ((document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAnySet runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: ((document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9500_9500007 collection Filter: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) END; -- Explain Plan on Index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bitwiseOperators', 'index_1', '{"a": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; --$bitsAllClear Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!&) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAnyClear Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@!|) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAllSet Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@&) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) --$bitsAnySet Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$lt": 10} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [1,5,7]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_1 on documents_9500_9500007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@|) '{ "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "23" } ] }'::documentdb_core.bson) (7 rows) END; bson_dollar_ops_query_bits_tests_index.out000066400000000000000000004124321507310017400405700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 420000; SET documentdb.next_collection_id TO 4200; SET documentdb.next_collection_index_id TO 4200; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_bits_tests_core.sql; set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Tests on numbers. SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 54}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 88}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 255}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 16 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 129 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 12984 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 18 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 24 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (4 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 16 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 54 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 55 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 88 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 9 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (4 rows) --Test with bit position $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } (1 row) --Test with bit position $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1, 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 3, 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (4 rows) --Test with bit position $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1, 2, 4, 5 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 4, 5 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 3, 4, 6 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) --Test with bit position $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1, 3 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (4 rows) --Test On negative Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""5"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": -1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -54}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test With BitMask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 53 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } (1 row) --Test With BitMask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 53 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With BitMask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 74 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With BitMask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 5, 4, 2, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } (1 row) --Test With bit positions $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2, 4, 5, 100 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 7, 6, 3 ,100 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test With bit positions $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test With bit positions with not int32 Type $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test On BinData with different subtypes SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"9", "a": {"$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"10", "a": {"$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"11", "a": {"$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"12", "a": {"$binary": { "base64": "////////////////////////////", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"13", "a": {"$binary": { "base64": "////////////////////////////", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"14", "a": {"$binary": { "base64": "////////////////////////////", "subType": "03"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bin data $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) --Test with bin data $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } (3 rows) --Test with bin data $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (3 rows) --Test with bin data $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (5 rows) --Sign Extension Check SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": -8}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Sign Extension check with $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- (0 rows) --Sign Extension check with $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) --Sign Extension check with $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } (1 row) --Sign Extension check with $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (5 rows) --Test when Document has neither bindata nor Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""5"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": "B"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 1.2832}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": "apple"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": "A"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 10 } }'; document --------------------------------------------------------------------- (0 rows) --Test on Double , Int64, Decimal128 SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": {"$numberDouble" : "1.00000000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": {"$numberDouble" : "2.00000000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": {"$numberLong" : "6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": {"$numberLong" : "9999999999999999"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (3 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (1 row) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) -- Tests on array. SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [10,12,14,16]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [10,12,14,16,1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [1,3,5,7]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": [1,3,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": [10.01, "hello", "Test", 11, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": [10.01, "hello", "Test"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": ["hello", "Test"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": [10.11, 11.12, 13.24]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": [10.0, 11.0, 13.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": [1, 1, 1, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (7 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } (2 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } (2 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (7 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (4 rows) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (4 rows) --insert multiple field in document SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0, "b":3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1, "b":2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2, "b":1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 3, "b":0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test on array of array SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [[1,2,3],[3,2,1]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [[1,3,5],[5,3,1]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,2,4],[4,2,0]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,0,0],[0,0,0]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Multiple Bits Operator Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 6}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": 7}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": 8}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 9}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "9" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "8" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3, "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "9" } } (5 rows) --Decimal 128 Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 0, "a": { "$numberDecimal" : "0" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": { "$numberDecimal" : "1" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": { "$numberDecimal" : "1.1234" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": { "$numberDecimal" : "1.0000" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": { "$numberDecimal" : "2.0020" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": { "$numberDecimal" : "3.0000" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": { "$numberDecimal" : "NaN" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": { "$numberDecimal" : "Infinity" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0" }, { "$numberDecimal" : "1" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0.112"}, { "$numberDecimal" : "1.321" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.000"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.000"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.1234" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "1.0000" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "0"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.1234" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "1.0000" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "0.000"} } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "0.000"} } }'; document --------------------------------------------------------------------- (0 rows) -- double range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""8"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-whole", "a" : { "$numberDouble" : "42.0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-zero", "a" : { "$numberDouble" : "0.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-big", "a" : { "$numberDouble" : "2305843009213693952.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-1", "a" : { "$numberDouble" : "-9223372036854775808"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-2", "a" : { "$numberDouble" : "-123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-3", "a" : { "$numberDouble" : "123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-4", "a" : { "$numberDouble" : "9223372036854775807"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDouble" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDouble" : "1.7976931348623157e+308"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDouble" : "5e-324"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; document --------------------------------------------------------------------- { "_id" : "double-whole", "a" : { "$numberDouble" : "42.0" } } { "_id" : "double-zero", "a" : { "$numberDouble" : "0.0" } } { "_id" : "double-big", "a" : { "$numberDouble" : "2305843009213693952.0" } } { "_id" : "double-1", "a" : { "$numberDouble" : "-9223372036854775808.0" } } { "_id" : "double-2", "a" : { "$numberDouble" : "-123456789.0" } } { "_id" : "double-3", "a" : { "$numberDouble" : "123456789.0" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; document --------------------------------------------------------------------- { "_id" : "double-zero", "a" : { "$numberDouble" : "0.0" } } { "_id" : "double-big", "a" : { "$numberDouble" : "2305843009213693952.0" } } { "_id" : "double-1", "a" : { "$numberDouble" : "-9223372036854775808.0" } } { "_id" : "double-3", "a" : { "$numberDouble" : "123456789.0" } } (4 rows) -- decimal range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-whole", "a" : { "$numberDecimal" : "42.0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-zero", "a" : { "$numberDecimal" : "0.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-2", "a" : { "$numberDecimal" : "-123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-3", "a" : { "$numberDecimal" : "123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-4", "a" : { "$numberDecimal" : "9223372036854775807"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDecimal" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDecimal" : "1.7976931348623157e+308"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDecimal" : "5e-324"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; document --------------------------------------------------------------------- { "_id" : "decimal-whole", "a" : { "$numberDecimal" : "42.0" } } { "_id" : "decimal-zero", "a" : { "$numberDecimal" : "0.0" } } { "_id" : "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0" } } { "_id" : "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : "decimal-2", "a" : { "$numberDecimal" : "-123456789" } } { "_id" : "decimal-3", "a" : { "$numberDecimal" : "123456789" } } { "_id" : "decimal-4", "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : "int64-max", "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : "double-smallest", "a" : { "$numberDecimal" : "5E-324" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; document --------------------------------------------------------------------- { "_id" : "decimal-zero", "a" : { "$numberDecimal" : "0.0" } } { "_id" : "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0" } } { "_id" : "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : "decimal-3", "a" : { "$numberDecimal" : "123456789" } } { "_id" : "double-smallest", "a" : { "$numberDecimal" : "5E-324" } } (5 rows) ROLLBACK; --Negative Test Cases $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAllClear: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAllClear: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllClear: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAllClear: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllClear": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAllClear" : 1 } } }:Expression not supported in partial index: a $bitsAllClear [ 0 ] --Negative Test Cases $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAnyClear: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAnyClear: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnyClear: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAnyClear: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnyClear": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAnyClear" : 1 } } }:Expression not supported in partial index: a $bitsAnyClear [ 0 ] --Negative Test Cases $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAllSet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAllSet: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllSet: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAllSet: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllSet": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAllSet" : 1 } } }:Expression not supported in partial index: a $bitsAllSet [ 0 ] --Negative Test Cases $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAnySet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAnySet: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnySet: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAnySet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "NaN" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: NaN.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "Infinity" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: Infinity.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnySet": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAnySet" : 1 } } }:Expression not supported in partial index: a $bitsAnySet [ 0 ] --drop collection SELECT drop_collection('db','bitwiseOperators'); drop_collection --------------------------------------------------------------------- t (1 row) bson_dollar_ops_query_bits_tests_runtime.out000066400000000000000000004123441507310017400411460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 420000; SET documentdb.next_collection_id TO 4200; SET documentdb.next_collection_index_id TO 4200; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_bits_tests_core.sql; set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Tests on numbers. SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 54}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 88}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 255}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 16 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 129 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 12984 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 18 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 24 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (4 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 16 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 54 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 55 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 88 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 9 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 255 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (4 rows) --Test with bit position $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } (1 row) --Test with bit position $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1, 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 3, 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } (4 rows) --Test with bit position $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 4 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1, 2, 4, 5 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 4, 5 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 3, 4, 6 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (1 row) --Test with bit position $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1, 3 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "54" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "88" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "255" } } (4 rows) --Test On negative Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""5"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": -1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -54}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test With BitMask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 53 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } (1 row) --Test With BitMask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 53 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With BitMask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 74 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With BitMask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 127 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 5, 4, 2, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } (1 row) --Test With bit positions $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2, 4, 5, 100 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 7, 6, 3 ,100 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test With bit positions $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-54" } } (2 rows) --Test With bit positions with not int32 Type $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test With bit positions with not int32 Type $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "-1" } } (1 row) --Test On BinData with different subtypes SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"9", "a": {"$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"10", "a": {"$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"11", "a": {"$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"12", "a": {"$binary": { "base64": "////////////////////////////", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"13", "a": {"$binary": { "base64": "////////////////////////////", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"14", "a": {"$binary": { "base64": "////////////////////////////", "subType": "03"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bin data $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) --Test with bin data $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } (3 rows) --Test with bin data $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "9", "a" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (3 rows) --Test with bin data $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; document --------------------------------------------------------------------- { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; document --------------------------------------------------------------------- { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "$binary" : { "base64" : "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" } } } { "_id" : "11", "a" : { "$binary" : { "base64" : "JANgqwetkqwklEWRbWERKKJREtbq", "subType" : "01" } } } { "_id" : "12", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "01" } } } { "_id" : "13", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "02" } } } { "_id" : "14", "a" : { "$binary" : { "base64" : "////////////////////////////", "subType" : "03" } } } (5 rows) --Sign Extension Check SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""6"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": -8}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Sign Extension check with $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- (0 rows) --Sign Extension check with $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) --Sign Extension check with $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } (1 row) --Sign Extension check with $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 2000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "-2" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "-8" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "5" } } (5 rows) --Test when Document has neither bindata nor Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""5"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": "B"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 1.2832}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": "apple"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": "A"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 10 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 10 } }'; document --------------------------------------------------------------------- (0 rows) --Test on Double , Int64, Decimal128 SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": {"$numberDouble" : "1.00000000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": {"$numberDouble" : "2.00000000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": {"$numberLong" : "6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": {"$numberLong" : "9999999999999999"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } (3 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (1 row) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberLong" : "6" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberLong" : "9999999999999999" } } (4 rows) -- Tests on array. SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [10,12,14,16]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [10,12,14,16,1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [1,3,5,7]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": [1,3,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": [10.01, "hello", "Test", 11, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": [10.01, "hello", "Test"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": ["hello", "Test"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": [10.11, 11.12, 13.24]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": [10.0, 11.0, 13.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": [1, 1, 1, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (7 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } (2 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } (2 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" } ] } { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (7 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (4 rows) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$gt" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "5" }, "a" : [ { "$numberDouble" : "10.009999999999999787" }, "hello", "Test", { "$numberInt" : "11" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberDouble" : "10.0" }, { "$numberDouble" : "11.0" }, { "$numberDouble" : "13.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$lte" : 5 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "12" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "7" } ] } { "_id" : { "$numberInt" : "4" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "10" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (4 rows) --insert multiple field in document SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0, "b":3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1, "b":2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2, "b":1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 3, "b":0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllSet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with non exist field or on multi field document $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test on array of array SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [[1,2,3],[3,2,1]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [[1,3,5],[5,3,1]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,2,4],[4,2,0]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,0,0],[0,0,0]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; document --------------------------------------------------------------------- (0 rows) --Multiple Bits Operator Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""4"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": 5}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 6}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": 7}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": 8}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 9}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$bitsAllSet" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "9" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$bitsAllClear" : 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "8" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3, "$bitsAnyClear" : 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "9" } } (5 rows) --Decimal 128 Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 0, "a": { "$numberDecimal" : "0" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": { "$numberDecimal" : "1" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": { "$numberDecimal" : "1.1234" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": { "$numberDecimal" : "1.0000" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": { "$numberDecimal" : "2.0020" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": { "$numberDecimal" : "3.0000" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": { "$numberDecimal" : "NaN" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": { "$numberDecimal" : "Infinity" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0" }, { "$numberDecimal" : "1" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0.112"}, { "$numberDecimal" : "1.321" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.000"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.000"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.1234" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "1.0000" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "0"} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : { "$numberDecimal" : "0" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDecimal" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.1234" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDecimal" : "1.0000" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberDecimal" : "2.0020" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "3.0000" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDecimal" : "NaN" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "Infinity" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "0.000"} } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "0.000"} } }'; document --------------------------------------------------------------------- (0 rows) -- double range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""8"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-whole", "a" : { "$numberDouble" : "42.0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-zero", "a" : { "$numberDouble" : "0.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-big", "a" : { "$numberDouble" : "2305843009213693952.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-1", "a" : { "$numberDouble" : "-9223372036854775808"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-2", "a" : { "$numberDouble" : "-123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-3", "a" : { "$numberDouble" : "123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-4", "a" : { "$numberDouble" : "9223372036854775807"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDouble" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDouble" : "1.7976931348623157e+308"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDouble" : "5e-324"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; document --------------------------------------------------------------------- { "_id" : "double-whole", "a" : { "$numberDouble" : "42.0" } } { "_id" : "double-zero", "a" : { "$numberDouble" : "0.0" } } { "_id" : "double-big", "a" : { "$numberDouble" : "2305843009213693952.0" } } { "_id" : "double-1", "a" : { "$numberDouble" : "-9223372036854775808.0" } } { "_id" : "double-2", "a" : { "$numberDouble" : "-123456789.0" } } { "_id" : "double-3", "a" : { "$numberDouble" : "123456789.0" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; document --------------------------------------------------------------------- { "_id" : "double-zero", "a" : { "$numberDouble" : "0.0" } } { "_id" : "double-big", "a" : { "$numberDouble" : "2305843009213693952.0" } } { "_id" : "double-1", "a" : { "$numberDouble" : "-9223372036854775808.0" } } { "_id" : "double-3", "a" : { "$numberDouble" : "123456789.0" } } (4 rows) -- decimal range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-whole", "a" : { "$numberDecimal" : "42.0" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-zero", "a" : { "$numberDecimal" : "0.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-2", "a" : { "$numberDecimal" : "-123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-3", "a" : { "$numberDecimal" : "123456789"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-4", "a" : { "$numberDecimal" : "9223372036854775807"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDecimal" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDecimal" : "1.7976931348623157e+308"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDecimal" : "5e-324"} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; document --------------------------------------------------------------------- { "_id" : "decimal-whole", "a" : { "$numberDecimal" : "42.0" } } { "_id" : "decimal-zero", "a" : { "$numberDecimal" : "0.0" } } { "_id" : "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0" } } { "_id" : "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : "decimal-2", "a" : { "$numberDecimal" : "-123456789" } } { "_id" : "decimal-3", "a" : { "$numberDecimal" : "123456789" } } { "_id" : "decimal-4", "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : "int64-max", "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : "double-smallest", "a" : { "$numberDecimal" : "5E-324" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; document --------------------------------------------------------------------- { "_id" : "decimal-zero", "a" : { "$numberDecimal" : "0.0" } } { "_id" : "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0" } } { "_id" : "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : "decimal-3", "a" : { "$numberDecimal" : "123456789" } } { "_id" : "double-smallest", "a" : { "$numberDecimal" : "5E-324" } } (5 rows) ROLLBACK; --Negative Test Cases $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAllClear: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAllClear: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllClear: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllClear: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAllClear: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllClear": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAllClear" : 1 } } }:Expression not supported in partial index: a $bitsAllClear [ 0 ] --Negative Test Cases $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAnyClear: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAnyClear: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnyClear: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnyClear: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAnyClear: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnyClear": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAnyClear" : 1 } } }:Expression not supported in partial index: a $bitsAnyClear [ 0 ] --Negative Test Cases $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAllSet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAllSet: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllSet: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAllSet: -1.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllSet": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAllSet" : 1 } } }:Expression not supported in partial index: a $bitsAllSet [ 0 ] --Negative Test Cases $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : -1 } }'; ERROR: A positive number was expected in the following context: $bitsAnySet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 23.04 } }'; ERROR: Expected value of integer type: $bitsAnySet: 23.04 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : "NegTest" } }'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnySet: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 99999999999 } }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ -1 ] } }'; ERROR: bit positions must be >= 0 but got: 0: \-1\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 99999999999 ] } }'; ERROR: Expected an integer but got 'long' type for element 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ "NegTest" ] } }'; ERROR: bit positions must be an integer but got: 0: \"NegTest"\ SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "99999999999" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 99999999999.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.0232" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: 1.0232.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "-1" }} }'; ERROR: A positive number was expected in the following context: $bitsAnySet: -1.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "NaN" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAnySet: NaN.0 SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "Infinity" }} }'; ERROR: Unable to store as a 32-bit integer: $bitsAllSet: Infinity.0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnySet": 1}} } ] }', TRUE); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$bitsAnySet" : 1 } } }:Expression not supported in partial index: a $bitsAnySet [ 0 ] --drop collection SELECT drop_collection('db','bitwiseOperators'); drop_collection --------------------------------------------------------------------- t (1 row) bson_dollar_ops_query_mod_tests_explain.out000066400000000000000000000515741507310017400407450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 9600000; SET documentdb.next_collection_id TO 9600; SET documentdb.next_collection_index_id TO 9600; --insert data SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 100, "a": 10}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 201, "a": [-10, -11]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 302, "a": [[[10, 11], [5]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 104, "a": {"b": [10, 11], "c": 11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 105, "a": {"b": { "c": [10, 11] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 202, "a": {"b": -10}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 204, "a": {"b": [-10, -11], "c": -11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 106, "a": [ {"b": 10}, {"c": 11}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 110, "a": {"$numberDecimal" : "10.6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 207, "a": {"$numberInt" : "-10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 311, "a": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 313, "a": ["Hello", "World"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 314, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 315, "a": { "$date": { "$numberLong" : "1234567890000" }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 123, "a": NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 126, "a": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 127, "a": {"$numberDecimal" : "NaN"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Explain Plan on runtime SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'dollarmodtests_explain'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO ON; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.c" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b.c" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.c" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9600_9600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b.c" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) END; -- Explain Plan on Index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_a1', '{"a": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_ab1', '{"a.b": -1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_ac1', '{"a.c": 1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_abc1', '{"a.b.c": -1}'), TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_a1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_ab1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_ac1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.c" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_abc1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b.c" : [ { "$numberInt" : "5" }, { "$numberInt" : "0" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_a1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_ab1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_ac1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.c" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_mod_abc1 on documents_9600_9600000 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@%) '{ "a.b.c" : [ { "$numberInt" : "3" }, { "$numberInt" : "-2" } ] }'::documentdb_core.bson) (7 rows) END; bson_dollar_ops_query_mod_tests_index.out000066400000000000000000002126671507310017400404160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 410000; SET documentdb.next_collection_id TO 4100; SET documentdb.next_collection_index_id TO 4100; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_mod_tests_core.sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Basic SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 100, "a": 10}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 101, "a": [10, 11]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 200, "a": -10}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 201, "a": [-10, -11]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested and empty arrays. These docs should not be in result set as $mod can not be applied on arr of arr SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 300, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 301, "a": [[]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 302, "a": [[[10, 11], [5]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 303, "a": [[[-10, -11], [-5]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested objects SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 102, "a": {"b": 10}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 103, "a": {"b": [10, 11]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 104, "a": {"b": [10, 11], "c": 11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 105, "a": {"b": { "c": [10, 11] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 202, "a": {"b": -10}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 203, "a": {"b": [-10, -11]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 204, "a": {"b": [-10, -11], "c": -11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 205, "a": {"b": { "c": [-10, -11] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents inside array SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 106, "a": [ {"b": 10}, {"c": 11}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 206, "a": [ {"b": -10}, {"c": -11}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --various numeric types SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 107, "a": {"$numberInt" : "10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 108, "a": {"$numberLong" : "10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 109, "a": {"$numberDouble" : "10.4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 110, "a": {"$numberDecimal" : "10.6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 207, "a": {"$numberInt" : "-10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 208, "a": {"$numberLong" : "-10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 209, "a": {"$numberDouble" : "-10.4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 210, "a": {"$numberDecimal" : "-10.6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Min Max Boundary -- Int32 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 130, "a": {"$numberInt" : "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 131, "a": {"$numberInt" : "-2147483648"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Int64 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 132, "a": {"$numberLong" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 133, "a": {"$numberLong" : "-9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Double - (double only takes 15 significand digits) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 134, "a": {"$numberDouble" : "922337203685477e4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 135, "a": {"$numberDouble" : "-922337203685477e4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Decimal128 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 136, "a": {"$numberDecimal" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 137, "a": {"$numberDecimal" : "-9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Decimal128 - values that are more than 64 bits SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 140, "a": {"$numberDecimal" : "9223372036854775807.5"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 141, "a": {"$numberDecimal" : "9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 142, "a": {"$numberDecimal" : "-9223372036854775808.5"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 143, "a": {"$numberDecimal" : "-9223372036854775809"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- non-numeric fields SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 310, "a": true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 311, "a": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 312, "a": "Hello"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 313, "a": ["Hello", "World"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 314, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 315, "a": { "$date": { "$numberLong" : "1234567890000" }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 121, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 122, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 123, "a": NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 124, "a": [10, null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 125, "a": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 126, "a": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 127, "a": {"$numberDecimal" : "NaN"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 221, "a": [-10, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 222, "a": [-0, -0.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test for $mod with positive divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "a" : { "b" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "202" }, "a" : { "b" : { "$numberInt" : "-10" } } } { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (8 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (2 rows) -- Test for $mod with negative divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "a" : { "b" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "202" }, "a" : { "b" : { "$numberInt" : "-10" } } } { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (8 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (2 rows) -- Test for $mod with positive divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } (1 row) -- Test for $mod with positive divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (1 row) -- Test for $mod with negative divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } (1 row) -- Test for $mod with negative divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (1 row) -- Tests where Positive Divisor is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "5"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-5"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-5.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "3"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-3"}, -2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.0"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-3.0"}, -2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) -- Tests where remainder is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberInt" : "-2"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberLong" : "2"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "-2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) -- Tests where Divisor is not a decimal number SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.2"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-3.5"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.9"}, {"$numberDouble" : "-2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) -- Tests for overflow check. If Dividend is INT_MAX and divisor is -1, mod operation should not overflow SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-1.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-1.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) -- Tests for overflow check. Divison if INT_MIN/MAX value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "2147483647"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-2147483648"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "9223372036854775807"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-9223372036854775808"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (5 rows) ROLLBACK; -- Error case : Divisor Zero SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [0,2]} }'; ERROR: divide by 0 is not allowed -- Error case : Less than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : []} }'; ERROR: malformed mod, not enough elements SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [2]} }'; ERROR: malformed mod, not enough elements -- Error case : More than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [1,2,3]} }'; ERROR: malformed mod, too many elements SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-1,-2,3,4]} }'; ERROR: malformed mod, too many elements -- Error case : NaN, Inf and overflow (Double & Decimal128) in Divisor SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "9223372036854775808"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "NaN"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "Inf"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-Inf"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "9223372036854775808"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "NaN"}, 0]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "Inf"}, 0]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-Inf"}, 1]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type -- Error case : NaN, Inf and overflow (Double & Decimal128) in Remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "9223372036854775808"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "NaN"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "-Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "9223372036854775808"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "NaN"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "-Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type bson_dollar_ops_query_mod_tests_runtime.out000066400000000000000000002126011507310017400407560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 410000; SET documentdb.next_collection_id TO 4100; SET documentdb.next_collection_index_id TO 4100; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection BEGIN; set local enable_seqscan TO ON; \i sql/bson_dollar_ops_query_mod_tests_core.sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Basic SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 100, "a": 10}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 101, "a": [10, 11]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 200, "a": -10}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 201, "a": [-10, -11]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested and empty arrays. These docs should not be in result set as $mod can not be applied on arr of arr SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 300, "a": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 301, "a": [[]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 302, "a": [[[10, 11], [5]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 303, "a": [[[-10, -11], [-5]]]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- nested objects SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 102, "a": {"b": 10}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 103, "a": {"b": [10, 11]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 104, "a": {"b": [10, 11], "c": 11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 105, "a": {"b": { "c": [10, 11] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 202, "a": {"b": -10}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 203, "a": {"b": [-10, -11]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 204, "a": {"b": [-10, -11], "c": -11}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 205, "a": {"b": { "c": [-10, -11] }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents inside array SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 106, "a": [ {"b": 10}, {"c": 11}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 206, "a": [ {"b": -10}, {"c": -11}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --various numeric types SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 107, "a": {"$numberInt" : "10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 108, "a": {"$numberLong" : "10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 109, "a": {"$numberDouble" : "10.4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 110, "a": {"$numberDecimal" : "10.6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 207, "a": {"$numberInt" : "-10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 208, "a": {"$numberLong" : "-10"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 209, "a": {"$numberDouble" : "-10.4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 210, "a": {"$numberDecimal" : "-10.6"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Min Max Boundary -- Int32 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 130, "a": {"$numberInt" : "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 131, "a": {"$numberInt" : "-2147483648"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Int64 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 132, "a": {"$numberLong" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 133, "a": {"$numberLong" : "-9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Double - (double only takes 15 significand digits) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 134, "a": {"$numberDouble" : "922337203685477e4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 135, "a": {"$numberDouble" : "-922337203685477e4"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Decimal128 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 136, "a": {"$numberDecimal" : "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 137, "a": {"$numberDecimal" : "-9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Decimal128 - values that are more than 64 bits SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 140, "a": {"$numberDecimal" : "9223372036854775807.5"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 141, "a": {"$numberDecimal" : "9223372036854775808"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 142, "a": {"$numberDecimal" : "-9223372036854775808.5"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 143, "a": {"$numberDecimal" : "-9223372036854775809"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- non-numeric fields SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 310, "a": true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 311, "a": false}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 312, "a": "Hello"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 313, "a": ["Hello", "World"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 314, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 315, "a": { "$date": { "$numberLong" : "1234567890000" }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 121, "a": 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 122, "a": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 123, "a": NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 124, "a": [10, null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 125, "a": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 126, "a": [null, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 127, "a": {"$numberDecimal" : "NaN"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 221, "a": [-10, NaN]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 222, "a": [-0, -0.0]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test for $mod with positive divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "a" : { "b" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "202" }, "a" : { "b" : { "$numberInt" : "-10" } } } { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (8 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (2 rows) -- Test for $mod with negative divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "a" : { "b" : { "$numberInt" : "10" } } } { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "202" }, "a" : { "b" : { "$numberInt" : "-10" } } } { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (8 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-5,0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (2 rows) -- Test for $mod with positive divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } (1 row) -- Test for $mod with positive divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (1 row) -- Test for $mod with negative divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "103" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "104" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ], "c" : { "$numberInt" : "11" } } } { "_id" : { "$numberInt" : "106" }, "a" : [ { "b" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "a" : { "b" : { "c" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } (1 row) -- Test for $mod with negative divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "203" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "a" : { "b" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ], "c" : { "$numberInt" : "-11" } } } { "_id" : { "$numberInt" : "206" }, "a" : [ { "b" : { "$numberInt" : "-10" } }, { "c" : { "$numberInt" : "-11" } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,-2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "205" }, "a" : { "b" : { "c" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } } } (1 row) -- Tests where Positive Divisor is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "5"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-5"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-5.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "3"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-3"}, -2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.0"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-3.0"}, -2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) -- Tests where remainder is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberInt" : "-2"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberLong" : "2"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "-2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) -- Tests where Divisor is not a decimal number SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.2"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-3.5"}, 2]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.9"}, {"$numberDouble" : "-2.0"}]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } (6 rows) -- Tests for overflow check. If Dividend is INT_MAX and divisor is -1, mod operation should not overflow SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-1"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-1.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-1.0"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } { "_id" : { "$numberInt" : "200" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "201" }, "a" : [ { "$numberInt" : "-10" }, { "$numberInt" : "-11" } ] } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberLong" : "10" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberDouble" : "10.400000000000000355" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberDecimal" : "10.6" } } { "_id" : { "$numberInt" : "207" }, "a" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "208" }, "a" : { "$numberLong" : "-10" } } { "_id" : { "$numberInt" : "209" }, "a" : { "$numberDouble" : "-10.400000000000000355" } } { "_id" : { "$numberInt" : "210" }, "a" : { "$numberDecimal" : "-10.6" } } { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "134" }, "a" : { "$numberDouble" : "9223372036854769664.0" } } { "_id" : { "$numberInt" : "135" }, "a" : { "$numberDouble" : "-9223372036854769664.0" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "124" }, "a" : [ { "$numberInt" : "10" }, null ] } { "_id" : { "$numberInt" : "221" }, "a" : [ { "$numberInt" : "-10" }, { "$numberDouble" : "NaN" } ] } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (26 rows) -- Tests for overflow check. Divison if INT_MIN/MAX value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "2147483647"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-2147483648"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "131" }, "a" : { "$numberInt" : "-2147483648" } } { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "9223372036854775807"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "132" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "136" }, "a" : { "$numberDecimal" : "9223372036854775807" } } { "_id" : { "$numberInt" : "140" }, "a" : { "$numberDecimal" : "9223372036854775807.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-9223372036854775808"}, 0]} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "133" }, "a" : { "$numberLong" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "137" }, "a" : { "$numberDecimal" : "-9223372036854775808" } } { "_id" : { "$numberInt" : "142" }, "a" : { "$numberDecimal" : "-9223372036854775808.5" } } { "_id" : { "$numberInt" : "121" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "222" }, "a" : [ { "$numberInt" : "0" }, { "$numberDouble" : "-0.0" } ] } (5 rows) ROLLBACK; -- Error case : Divisor Zero SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [0,2]} }'; ERROR: divide by 0 is not allowed -- Error case : Less than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : []} }'; ERROR: malformed mod, not enough elements SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [2]} }'; ERROR: malformed mod, not enough elements -- Error case : More than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [1,2,3]} }'; ERROR: malformed mod, too many elements SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-1,-2,3,4]} }'; ERROR: malformed mod, too many elements -- Error case : NaN, Inf and overflow (Double & Decimal128) in Divisor SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "9223372036854775808"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "NaN"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "Inf"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-Inf"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "9223372036854775808"}, 2]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "NaN"}, 0]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "Inf"}, 0]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-Inf"}, 1]} }'; ERROR: malformed mod, divisor value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type -- Error case : NaN, Inf and overflow (Double & Decimal128) in Remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "9223372036854775808"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "NaN"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "-Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "9223372036854775808"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Out of bounds coercing to integral value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "NaN"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "-Inf"}]} }'; ERROR: malformed mod, remainder value is invalid :: caused by :: Unable to coerce NaN/Inf to integral type bson_dollar_ops_text_search_tests.out000066400000000000000000001605341507310017400375270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7980000; SET documentdb.next_collection_id TO 7980; SET documentdb.next_collection_index_id TO 7980; -- insert some docs SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 1, "a": "this is a cat" }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 2, "a": "this is a dog" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 3, "a": "these are dogs" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 4, "a": "these are cats" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 5, "a": "these are catatonic" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a $text query. Should fail (there's no index) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; ERROR: A text index is necessary to perform a $text query. -- create a text index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now do a $text query. Should succeed. SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "this is a cat" } { "_id" : { "$numberInt" : "4" }, "a" : "these are cats" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "dog" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "this is a dog" } { "_id" : { "$numberInt" : "3" }, "a" : "these are dogs" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat | dog" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "this is a cat" } { "_id" : { "$numberInt" : "2" }, "a" : "this is a dog" } { "_id" : { "$numberInt" : "3" }, "a" : "these are dogs" } { "_id" : { "$numberInt" : "4" }, "a" : "these are cats" } (4 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiQueryScan) -> Bitmap Heap Scan on documents_7980_7980005 collection Filter: documentdb_api_internal.bson_text_meta_qual(document, '''cat'''::tsquery, '\x0400000000000000ffffffff000000000000000000000000000000002800000000000000010000000000803f000000000000803f000000000000803f000000000000803f00000000010000006100'::bytea, true) -> Bitmap Index Scan on a_text Index Cond: (document OPERATOR(documentdb_api_catalog.@#%) '''cat'''::tsquery) (10 rows) -- invalid queries -- $text on subsequent stages should fail. WITH r1 AS (SELECT bson_dollar_project(document, '{ "a": 1 }') AS document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search')) SELECT document FROM r1 WHERE document @@ '{ "$text": { "$search": "cat" } }'; ERROR: A text index is necessary to perform a $text query. -- no more than 1 $text: SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$and": [ { "$text": { "$search": "cat" } }, { "$text": { "$search": "dogs" } }] }'; ERROR: Excessive number of text expressions CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "a_text" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 11, "topic": "apple", "writer": "Carol", "score": 50, "location": "New York", "published": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 12, "topic": "Apple Store", "writer": "Bob", "score": 5, "location": "San Francisco", "published": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 13, "topic": "Picking a berry", "writer": "Alice", "score": 90, "location": "London", "published": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 14, "topic": "picking", "writer": "Carol", "score": 100, "location": "Berlin", "published": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 15, "topic": "apple and berry", "writer": "Alice", "score": 200, "location": "Paris", "published": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 16, "topic": "Яблоко", "writer": "David", "score": 80, "location": "Moscow", "published": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 17, "topic": "pear and berry", "writer": "Bob", "score": 10, "location": "Madrid", "published": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 18, "topic": "Pear with Berry", "writer": "Carol", "score": 10, "location": "Rome", "published": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 30, "topic": "Me encanta la miel natural", "writer": "Alice", "score": 10, "location": "Barcelona", "published": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "topic": "text" }, "name": "topic_text" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "pick apple" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "13" }, "topic" : "Picking a berry", "writer" : "Alice", "score" : { "$numberInt" : "90" }, "location" : "London", "published" : true } { "_id" : { "$numberInt" : "14" }, "topic" : "picking", "writer" : "Carol", "score" : { "$numberInt" : "100" }, "location" : "Berlin", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "\"apple store\"" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple -store" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (2 rows) -- TODO: this is incorrect, we aren’t diacritic insensitive by default, it should return more documents. -- See: https://www.postgresql.org/docs/current/unaccent.html SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Ñблоко" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "topic" : "Яблоко", "writer" : "David", "score" : { "$numberInt" : "80" }, "location" : "Moscow", "published" : false } (1 row) -- this partially works: SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "miel", "$language": "es" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "topic" : "Me encanta la miel natural", "writer" : "Alice", "score" : { "$numberInt" : "10" }, "location" : "Barcelona", "published" : true } (1 row) -- invalid language SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "miel", "$language": "xx" } }'; ERROR: unsupported language: "xx" for text index version 3 -- try these with the function. SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "apple" } }') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "pick apple" } }') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "13" }, "topic" : "Picking a berry", "writer" : "Alice", "score" : { "$numberInt" : "90" }, "location" : "London", "published" : true } { "_id" : { "$numberInt" : "14" }, "topic" : "picking", "writer" : "Carol", "score" : { "$numberInt" : "100" }, "location" : "Berlin", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "\"apple store\"" } }') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } (1 row) -- shard collection & try the query again SELECT documentdb_api.shard_collection('db', 'bson_dollar_ops_text_search', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (3 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "pick apple" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } { "_id" : { "$numberInt" : "13" }, "topic" : "Picking a berry", "writer" : "Alice", "score" : { "$numberInt" : "90" }, "location" : "London", "published" : true } { "_id" : { "$numberInt" : "14" }, "topic" : "picking", "writer" : "Carol", "score" : { "$numberInt" : "100" }, "location" : "Berlin", "published" : false } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "\"apple store\"" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "topic" : "Apple Store", "writer" : "Bob", "score" : { "$numberInt" : "5" }, "location" : "San Francisco", "published" : false } (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple -store" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "topic" : "apple", "writer" : "Carol", "score" : { "$numberInt" : "50" }, "location" : "New York", "published" : true } { "_id" : { "$numberInt" : "15" }, "topic" : "apple and berry", "writer" : "Alice", "score" : { "$numberInt" : "200" }, "location" : "Paris", "published" : true } (2 rows) -- now repeat the above with default_languages. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "topic_text" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 21, "titular": "Manzana", "writer": "xyz", "score": 50 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 22, "titular": "Comprar Manzana", "writer": "efg", "score": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 23, "titular": "Cosechando una baya", "writer": "abc", "score": 90 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 24, "titular": "Cosechar", "writer": "xyz", "score": 100 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 25, "titular": "Manzana con baya", "writer": "abc", "score": 200 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 27, "titular": "Manzana con pera", "writer": "efg", "score": 10 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 28, "titular": "Manzana con pera y baya", "writer": "xyz", "score": 10 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "titular": "text" }, "name": "titular_text", "default_language": "es" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "writer" : "xyz", "score" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "writer" : "efg", "score" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "writer" : "abc", "score" : { "$numberInt" : "200" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "writer" : "efg", "score" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "writer" : "xyz", "score" : { "$numberInt" : "10" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Cosechar" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "writer" : "abc", "score" : { "$numberInt" : "90" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "writer" : "xyz", "score" : { "$numberInt" : "100" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Comprando Manzana" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "writer" : "xyz", "score" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "writer" : "efg", "score" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "writer" : "abc", "score" : { "$numberInt" : "200" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "writer" : "efg", "score" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "writer" : "xyz", "score" : { "$numberInt" : "10" } } (5 rows) -- now add projection. SELECT bson_dollar_project(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "rank" : { "$numberDouble" : "1.0" } } (7 rows) SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "writer" : "xyz", "score" : { "$numberInt" : "50" }, "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "writer" : "efg", "score" : { "$numberInt" : "5" }, "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "writer" : "xyz", "score" : { "$numberInt" : "10" }, "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "writer" : "abc", "score" : { "$numberInt" : "90" }, "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "writer" : "abc", "score" : { "$numberInt" : "200" }, "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "writer" : "efg", "score" : { "$numberInt" : "10" }, "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "writer" : "xyz", "score" : { "$numberInt" : "100" }, "rank" : { "$numberDouble" : "1.0" } } (7 rows) SELECT bson_dollar_project_find(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "rank" : { "$numberDouble" : "1.0" } } (7 rows) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page('db', '{ "find": "bson_dollar_ops_text_search", "filter": { "$text": { "$search": "Manzana baya cosechar" } }, "projection": { "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }} }'); cursorpage | continuation | persistconnection --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bson_dollar_ops_text_search", "firstBatch" : [ { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "rank" : { "$numberDouble" : "1.0" } }, { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "rank" : { "$numberDouble" : "1.0" } }, { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "rank" : { "$numberDouble" : "2.0" } }, { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "rank" : { "$numberDouble" : "2.0" } }, { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "rank" : { "$numberDouble" : "2.0" } }, { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "rank" : { "$numberDouble" : "1.0" } }, { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "rank" : { "$numberDouble" : "1.0" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f (1 row) -- pipeline cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$project": { "_id": 1 } }, { "$match": { "$text": { "$search": "Manzana baya cosechar" } } } ] }'); ERROR: A text index is necessary to perform a $text query. CONTEXT: while executing command on localhost:58070 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$match": { "$text": { "$search": "Manzana baya cosechar" } } }, { "$sort": { "_id": 1 } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "writer" : "xyz", "score" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "writer" : "efg", "score" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "writer" : "abc", "score" : { "$numberInt" : "90" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "writer" : "xyz", "score" : { "$numberInt" : "100" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "writer" : "abc", "score" : { "$numberInt" : "200" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "writer" : "efg", "score" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "writer" : "xyz", "score" : { "$numberInt" : "10" } } (7 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$match": { "$text": { "$search": "Manzana baya cosechar" } } }, { "$project": { "_id": 1, "titular": 1, "rank": { "$meta": "textScore" } } } ] }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "rank" : { "$numberDouble" : "1.0" } } (7 rows) -- now add sort SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana Cosechando" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "writer" : "xyz", "score" : { "$numberInt" : "50" } } { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "writer" : "efg", "score" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "writer" : "xyz", "score" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "writer" : "abc", "score" : { "$numberInt" : "90" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "writer" : "abc", "score" : { "$numberInt" : "200" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "writer" : "efg", "score" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "24" }, "titular" : "Cosechar", "writer" : "xyz", "score" : { "$numberInt" : "100" } } (7 rows) -- now add project & sort SELECT bson_dollar_project(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana Comprando baya" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "titular" : "Comprar Manzana", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "28" }, "titular" : "Manzana con pera y baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "25" }, "titular" : "Manzana con baya", "rank" : { "$numberDouble" : "2.0" } } { "_id" : { "$numberInt" : "21" }, "titular" : "Manzana", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "23" }, "titular" : "Cosechando una baya", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "27" }, "titular" : "Manzana con pera", "rank" : { "$numberDouble" : "1.0" } } (6 rows) -- now do group WITH r1 AS (SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana" } }' ) SELECT BSONMAX(bson_expression_get(document, '{ "": "$score" }')), bson_expression_get(document, '{ "": { "$meta": "textScore" } }') FROM r1 GROUP BY bson_expression_get(document, '{ "": { "$meta": "textScore" } }'); bsonmax | bson_expression_get --------------------------------------------------------------------- { "" : { "$numberInt" : "200" } } | { "" : { "$numberDouble" : "1.0" } } (1 row) -- scenarios without $text should return 'query requires text score metadata, but it is not available' SELECT bson_dollar_project(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; ERROR: The query needs text score metadata, but this required information is currently unavailable. CONTEXT: while executing command on localhost:58070 SELECT bson_dollar_add_fields(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; ERROR: The query needs text score metadata, but this required information is currently unavailable. CONTEXT: while executing command on localhost:58070 SELECT bson_dollar_project_find(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; ERROR: The query needs text score metadata, but this required information is currently unavailable. CONTEXT: while executing command on localhost:58070 SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; ERROR: The query needs text score metadata, but this required information is currently unavailable. CONTEXT: while executing command on localhost:58070 WITH r1 AS (SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }' ) SELECT BSONMAX(bson_expression_get(document, '{ "": "$score" }')) FROM r1 GROUP BY bson_expression_get(document, '{ "": { "$meta": "textScore" } }'); ERROR: The query needs text score metadata, but this required information is currently unavailable. CONTEXT: while executing command on localhost:58070 -- test with custom weights. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "titular_text" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 31, "alpha": "red blue green", "beta": "yellow orange" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 32, "alpha": "yellow orange blue", "beta": "red blue purple" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "alpha": "text" }, "name": "alpha_1", "weights": { "alpha": 10, "beta": 1 } } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- returns 31, 32 SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "red" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "alpha" : "red blue green", "beta" : "yellow orange", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "32" }, "alpha" : "yellow orange blue", "beta" : "red blue purple", "rank" : { "$numberDouble" : "0.10000000149011611938" } } (2 rows) -- Returns 32, 31 SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "orange" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; bson_dollar_add_fields --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "alpha" : "yellow orange blue", "beta" : "red blue purple", "rank" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "31" }, "alpha" : "red blue green", "beta" : "yellow orange", "rank" : { "$numberDouble" : "0.10000000149011611938" } } (2 rows) -- test wildcard handling -- this is a variant of the JS test: blog_textwild.js CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "alpha_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 33, "heading": "my travel story", "content": "this is a new travel blog I am writing. cheers sam" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 34, "heading": "my 2nd story", "content": "this is a new travel blog I am writing. cheers" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 35, "heading": "mountains are Beautiful for writing sam", "content": "this is a new travel blog I am writing. cheers" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "dummy": "text", "$**": "text" }, "name": "alpha_1" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "travel" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "heading" : "my travel story", "content" : "this is a new travel blog I am writing. cheers sam" } { "_id" : { "$numberInt" : "34" }, "heading" : "my 2nd story", "content" : "this is a new travel blog I am writing. cheers" } { "_id" : { "$numberInt" : "35" }, "heading" : "mountains are Beautiful for writing sam", "content" : "this is a new travel blog I am writing. cheers" } (3 rows) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "alpha_1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- recreate this so that test output for further tests does not change SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "alpha": "text" }, "name": "alpha_1", "weights": { "alpha": 10, "beta": 1 } } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Test TSQuery generation. SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"mental health\"" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'mental' <-> 'health' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"mental health\" wellbeing nutrition" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- ( 'wellb' | 'nutrit' ) & 'mental' <-> 'health' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "hydrate stretch recover" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'hydrat' | 'stretch' | 'recov' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\"" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' <-> 'train' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "cardio -training" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' & !'train' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "cardio -training -burnout" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' & !'train' & !'burnout' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" -fatigue -burnout" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' <-> 'train' & !'fatigu' & !'burnout' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' <-> 'train' & ( 'diet' | 'plan' ) & !'fatigu' & !'burnout' (1 row) SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); bson_query_to_tsquery --------------------------------------------------------------------- 'cardio' <-> 'train' & ( 'diet' | 'plan' | 'wellb' ) & !'fatigu' & !'burnout' (1 row) -- this matches SELECT to_tsvector('consistent cardio training with a diet plan improves wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- t (1 row) -- this shouldn't match SELECT to_tsvector('cardio training with a diet plan can lead to fatigue') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- f (1 row) SELECT to_tsvector('stretching improves general wellbeing and focus') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- f (1 row) SELECT to_tsvector('burnout is a risk when doing cardio training without breaks') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- f (1 row) -- Phrase: First one doesn't match, second one does. SELECT to_tsvector('consistent stretching is the cornerstone of wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- f (1 row) SELECT to_tsvector('a good diet plan improves long-term wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- t (1 row) -- Use language check -- synonyms within a language work. SELECT to_tsvector('portuguese', 'Em atualidade, sempre é possível manter-se saudável') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "atualmente", "$language": "pt" }'::documentdb_core.bson); ?column? --------------------------------------------------------------------- t (1 row) -- Only one text index allowed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search2", "indexes": [ { "key": { "gamma": "text" }, "name": "gamma_text" } ] }', TRUE); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search2", "indexes": [ { "key": { "gamma": "text" }, "name": "gamma_text" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "desc": "text", "extra": "text" }, "name": "desc_text" } ] }', TRUE); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "desc" : "text", "extra" : "text" }, "name" : "desc_text" }, existing index: { "v" : 2, "key" : { "alpha" : "text" }, "name" : "alpha_1", "weights" : { "alpha" : 10, "beta" : 1 } } bson_expr_eval_tests.out000066400000000000000000000624701507310017400347650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 400000; SET documentdb.next_collection_id TO 4000; SET documentdb.next_collection_index_id TO 4000; -- test explicit equality operator SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) -- test $in/$nin SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$in": [ 2, 3, 4] }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$in": [ 2, 3, 4] }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nin": [ 2, 3, 4] }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nin": [ 2, 3, 4] }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) -- test $gte/$lte SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 5 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 5 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 5 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 5 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$type": "string" }', '{ "": 5 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$type": "string" }', '{ "": "hello" }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": "hello" }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": [ 1, 2 ] }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": [ 1, 2, 3 ] }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$ne": 4 }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$ne": 4 }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$exists": false }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$exists": true }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": 4 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "someString" }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "aaab" }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "asomethingb" }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) -- negative test to validate options SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "g" }', '{ "": 4 }'); ERROR: Invalid flag detected within the specified regex options g SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "hw" }', '{ "": 4 }'); ERROR: Invalid flag detected within the specified regex options h SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": {"$regex": "\\d[3]", "$options": "s"} }', '{ "": 4 }'); ERROR: Invalid flag detected within the specified regex options s SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": {"$regex": "\\d[3]", "$options": "x"} }', '{ "": 4 }'); ERROR: Invalid flag detected within the specified regex options x SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": [ "asomethingb" ] }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": [ "asomethingb" ] }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "c": "asomethingb" } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "b": "asomethingb" } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 7 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 8 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 9 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 7 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 8 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 9 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 7 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 8 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 9 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 7 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 8 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 9 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) -- test $and/$or/$nor SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 0 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 0 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 0 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 3 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 3 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": 0 }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": { "a": 0 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": { "b": 2 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) -- $elemMatch SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": 1 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": 2 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ 1 ] } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ [ 2 ] ] } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ 2 ] } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": 1 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": 2 }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ 1 ] }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ [ 2 ] ] }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ 2 ] }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) -- $all SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 2 ] } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": 2 } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 3, 7 ] } }'); evaluate_query_expression --------------------------------------------------------------------- f (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 3, 5, 8 ] } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 1, 3, 5 ] } }'); evaluate_query_expression --------------------------------------------------------------------- t (1 row) -- projection of the value SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$gt": 2 }', '{ "": [ 0, 1, 2 ] }'); evaluate_expression_get_first_match --------------------------------------------------------------------- (1 row) SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$gt": 2 }', '{ "": [ 0, 5, 3, 8 ] }'); evaluate_expression_get_first_match --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } (1 row) SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$in": [ 6, 7, 8] }', '{ "": [ 0, 5, 3, 8 ] }'); evaluate_expression_get_first_match --------------------------------------------------------------------- { "" : { "$numberInt" : "8" } } (1 row) SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$in": [ 6, 7, 8] }', '{ "": [ 0, 5, 3, 1 ] }'); evaluate_expression_get_first_match --------------------------------------------------------------------- (1 row) bson_get_indexes_a.out000066400000000000000000000453041507310017400343510ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 2100000; SET documentdb.next_collection_id TO 21000; SET documentdb.next_collection_index_id TO 21000; --Test 1 Collection exist with only one Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'total_price_idx', '{"total_price": 1}'), true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "order_data" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""orderdb.order_data"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""total_price"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""total_price_idx"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) --Test 2 Collection exist with multiple Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'shipping_distance_idx', '{"shipping_distance": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'delivery_hours_idx', '{"delivery_hours": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'customer_rating_idx', '{"customer_rating": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'item_count_idx', '{"item_count": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'to_city_idx', '{"to_city": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "order_data" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""orderdb.order_data"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""total_price"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""total_price_idx"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""shipping_distance"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""shipping_distance_idx"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""delivery_hours"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""delivery_hours_idx"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""customer_rating"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""customer_rating_idx"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""item_count"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""item_count_idx"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""to_city"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""to_city_idx"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) --Test 3: Collection not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "nonexistent_collection" }') ORDER BY 1; ERROR: Namespace does not currently exist: orderdb.nonexistent_collection --Test 4: DB not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('db_not_exist','{ "listIndexes": "order_data" }') ORDER BY 1; ERROR: Namespace does not currently exist: db_not_exist.order_data --Test 5: DB and collection both does not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('db_not_exist','{ "listIndexes": "nonexistent_collection" }') ORDER BY 1; ERROR: Namespace does not currently exist: db_not_exist.nonexistent_collection -- Test 6: Sparse is included in result only when specified: SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"promo_code": 1}, "name": "promo_sparse_idx1", "sparse": true}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"order_status": 1}, "name": "status_non_sparse_idx1", "sparse": false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"payment_method": 1}, "name": "payment_idx1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"gift_message": 1}, "name": "gift_idx2", "sparse": 1.0}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"gift_message": 1}, "name": "gift_idx3", "sparse": 0.0}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"coupon_code": 1}, "name": "coupon_idx4", "sparse": 0.0, "expireAfterSeconds" : 3600}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('sparsedb','{ "listIndexes": "sparse_orders" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""sparsedb.sparse_orders"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""promo_code"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""promo_sparse_idx1"", ""sparse"" : true }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""order_status"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""status_non_sparse_idx1"", ""sparse"" : false }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""payment_method"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""payment_idx1"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""gift_message"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""gift_idx2"", ""sparse"" : true }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""gift_message"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""gift_idx3"", ""sparse"" : false }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""coupon_code"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""coupon_idx4"", ""sparse"" : false, ""expireAfterSeconds"" : { ""$numberInt"" : ""3600"" } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) -- Test 7: Unique indexes is included if it is specified and true. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "unique_orders", "indexes": [{"key": {"order_number": 1}, "name": "order_idx3", "unique": 0.0}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "unique_orders", "indexes": [{"key": {"tracking_number": 1}, "name": "tracking_idx4", "unique": 1.0, "sparse": 1.0, "expireAfterSeconds" : 5400}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('uniquedb','{ "listIndexes": "unique_orders" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""uniquedb.unique_orders"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""order_number"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""order_idx3"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""tracking_number"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""tracking_idx4"", ""sparse"" : true, ""unique"" : true, ""expireAfterSeconds"" : { ""$numberInt"" : ""5400"" } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) bson_get_indexes_b.out000066400000000000000000000211671507310017400343530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2200000; SET documentdb.next_collection_id TO 22000; SET documentdb.next_collection_index_id TO 22000; -- --Test 1 Compound index test -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('compound_orders', 'comp_index', '{"total_price": 1,"shipping_distance":1}'), true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('compound_orders', 'comp_index1', '{"delivery_hours": 1,"customer_rating":1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "compound_orders" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""orderdb.compound_orders"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""total_price"" : { ""$numberInt"" : ""1"" }, ""shipping_distance"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""comp_index"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""delivery_hours"" : { ""$numberInt"" : ""1"" }, ""customer_rating"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""comp_index1"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) --Test 2 Descending Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_items', 'test1', '{"item_count": -1}'), true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_items', 'test2', '{"to_city": -1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "order_items" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""orderdb.order_items"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""item_count"" : { ""$numberInt"" : ""-1"" } }, ""name"" : ""test1"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""to_city"" : { ""$numberInt"" : ""-1"" } }, ""name"" : ""test2"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) --Test 3 Ascending Descending Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_shipments', 'test1', '{"promo_code": 1}'), true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_shipments', 'test2', '{"order_status": -1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "order_shipments" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""orderdb.order_shipments"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""promo_code"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""test1"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""order_status"" : { ""$numberInt"" : ""-1"" } }, ""name"" : ""test2"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) bson_hash_indexes.out000066400000000000000000000330111507310017400342050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 530000; SET documentdb.next_collection_id TO 5300; SET documentdb.next_collection_index_id TO 5300; -- insert a document SELECT documentdb_api.create_collection('db', 'queryhashindex'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','queryhashindex'); drop_primary_key --------------------------------------------------------------------- (1 row) -- Create a hash index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryhashindex", "indexes": [ { "key" : { "a.b": "hashed" }, "name": "hashIndex" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryhashindex') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5300 | 5301 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : "hashed" }, "name" : "hashIndex" } | t (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "queryhashindex" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.queryhashindex"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a.b"" : ""hashed"" }, ""name"" : ""hashIndex"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) -- Explain various hash index scenarios. BEGIN; set local enable_seqscan to off; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5300_530001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on "hashIndex" Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, true ]}'::bson); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5300_530001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) -> Bitmap Index Scan on "hashIndex" Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, true ] }'::documentdb_core.bson) (9 rows) -- these should not use the index. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_ne(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_5300_530001 collection Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_gt(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_5300_530001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_gte(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_5300_530001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_lt(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_5300_530001 collection Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_lte(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_5300_530001 collection Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) -- null can be pushed down. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": null }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5300_530001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : null }'::documentdb_core.bson) -> Bitmap Index Scan on "hashIndex" Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : null }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, null ]}'::bson); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5300_530001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, null ] }'::documentdb_core.bson) -> Bitmap Index Scan on "hashIndex" Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, null ] }'::documentdb_core.bson) (9 rows) -- now insert some documents and run the queries above. SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 2 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 3 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": "string" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": null } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": false } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "c": 1, "a": "c only field" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": {"$undefined" : true } } }'); -- null should also get undefined values insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": 1 }'); ?column? --------------------------------------------------------------------- { "" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, true ]}'::bson); ?column? --------------------------------------------------------------------- { "" : { "b" : { "$numberInt" : "1" } } } { "" : { "b" : { "$numberInt" : "2" } } } (2 rows) SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": null }'); ?column? --------------------------------------------------------------------- { "" : { "b" : null } } { "" : "c only field" } { "" : { "b" : { "$undefined" : true } } } (3 rows) SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, null ]}'::bson); ?column? --------------------------------------------------------------------- { "" : { "b" : { "$numberInt" : "1" } } } { "" : { "b" : { "$numberInt" : "2" } } } { "" : { "b" : null } } { "" : "c only field" } { "" : { "b" : { "$undefined" : true } } } (5 rows) ROLLBACK; bson_index_hints_pushdown_tests.out000066400000000000000000000715631507310017400372460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 695000; SET documentdb.next_collection_id TO 69500; SET documentdb.next_collection_index_id TO 69500; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('hint_db', 'query_index_hints') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('hint_db', 'query_index_hints'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create various kinds of indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "name": "a_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "b": 1, "c": 1 }, "name": "b_1_c_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "d": "hashed" }, "name": "d_hashed" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "$**": "text" }, "name": "e_text" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "f": 1 }, "name": "f_1", "sparse": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "g.$**": 1 }, "name": "g_1" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "h": 1 }, "name": "h_1", "sparse": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "i": 1, "j": 1 }, "name": "i_1_j_1", "unique": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "k": 1, "l": 1 }, "name": "k_1_l_1", "sparse": true, "unique": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_69501 Table "documentdb_data.documents_69501" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_69501" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_69502" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) "documents_rum_index_69503" documentdb_rum (document bson_rum_single_path_ops (path=b, tl='2691'), document bson_rum_single_path_ops (path=c, tl='2691')) "documents_rum_index_69504" documentdb_rum (document documentdb_rum_hashed_ops (path=d)) "documents_rum_index_69505" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true')) "documents_rum_index_69506" documentdb_rum (document bson_rum_single_path_ops (path=f, tl='2699')) "documents_rum_index_69507" documentdb_rum (document bson_rum_single_path_ops (path=g, iswildcard='true', tl='2699')) "documents_rum_index_69508" documentdb_rum (document bson_rum_single_path_ops (path=h, tl='2699')) "documents_rum_index_69509" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "i" : { "$numberInt" : "1" }, "j" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=i, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=j, tl='2691', generatenotfoundterm='true') WITH =?=) "documents_rum_index_69510" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "k" : { "$numberInt" : "1" }, "l" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=k, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=l, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '69501'::bigint) -- now insert some sample docs SELECT documentdb_api.insert_one('hint_db', 'query_index_hints', '{ "_id": 1, "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- query index hints by name - every index works except text index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on a_1 Index Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "b_1_c_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "b" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on b_1_c_1 Index Cond: (document @<> '{ "b" : { "fullScan" : true } }'::bson) (6 rows) -- this pushes to a seqscan because the index is hashed EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "d_hashed" }'); QUERY PLAN --------------------------------------------------------------------- Seq Scan on documents_69501_695002 collection Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) (2 rows) -- this should fail. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "e_text" }'); ERROR: index specified by index hint is not found or invalid for the filters -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "f_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "f" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on f_1 Index Cond: (document @>= '{ "f" : { "$minKey" : 1 } }'::bson) (6 rows) -- cannot push to wildcard index since it is a wildcard index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "g_1" }'); ERROR: index specified by index hint is not found or invalid for the filters EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "i_1_j_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "i" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on i_1_j_1 Index Cond: (document @<> '{ "i" : { "fullScan" : true } }'::bson) (6 rows) -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "h_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "h" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on h_1 Index Cond: (document @>= '{ "h" : { "$minKey" : 1 } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "k_1_l_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "k" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on k_1_l_1 Index Cond: (document @>= '{ "k" : { "$minKey" : 1 } }'::bson) (6 rows) -- query index hint by key - works the same as name EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on a_1 Index Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "b": 1, "c": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "b" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on b_1_c_1 Index Cond: (document @<> '{ "b" : { "fullScan" : true } }'::bson) (6 rows) -- this pushes to a seqscan because the index is hashed EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "d": "hashed" } }'); QUERY PLAN --------------------------------------------------------------------- Seq Scan on documents_69501_695002 collection Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) (2 rows) -- this should fail. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$**": "text" } }'); ERROR: index specified by index hint is not found or invalid for the filters -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "f": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "f" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on f_1 Index Cond: (document @>= '{ "f" : { "$minKey" : 1 } }'::bson) (6 rows) -- cannot push to wildcard index since it is a wildcard index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "g.$**": 1 } }'); ERROR: index specified by index hint is not found or invalid for the filters EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "i": 1, "j": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "i" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on i_1_j_1 Index Cond: (document @<> '{ "i" : { "fullScan" : true } }'::bson) (6 rows) -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "h": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "h" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on h_1 Index Cond: (document @>= '{ "h" : { "$minKey" : 1 } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "k": 1, "l": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "k" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on k_1_l_1 Index Cond: (document @>= '{ "k" : { "$minKey" : 1 } }'::bson) (6 rows) -- hints when no index exists EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "nonexistent" }'); ERROR: index specified by index hint is not found: hint provided does not correspond to an existing index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "nonexistent": 1 } }'); ERROR: index specified by index hint is not found: hint provided does not correspond to an existing index -- natural hint picks _id index. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$natural": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (shard_key_value = '69501'::bigint) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '69501'::bigint) (5 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$natural": -1 } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (shard_key_value = '69501'::bigint) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '69501'::bigint) (5 rows) -- more error cases SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "sparse": true, "name": "a_2" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "10" }, "numIndexesAfter" : { "$numberInt" : "11" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- fails due to multiple indexes matching. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "a": 1 } }'); ERROR: index specified by index hint is ambiguous. please specify hint by name EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_2" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on a_2 Index Cond: (document @>= '{ "a" : { "$minKey" : 1 } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_1" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on a_1 Index Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) (6 rows) -- try with composite indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_3" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "11" }, "numIndexesAfter" : { "$numberInt" : "12" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "k": 1, "l": 1 }, "enableCompositeTerm": true, "name": "k_1_l_1-2" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "12" }, "numIndexesAfter" : { "$numberInt" : "13" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_3" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on a_3 Index Cond: (document @<> '{ "a" : { "fullScan" : true } }'::bson) (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "k_1_l_1-2" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) -> Bitmap Heap Scan on documents_69501_695002 collection Recheck Cond: (document @<> '{ "k" : { "fullScan" : true } }'::bson) Filter: (document @= '{ "x" : { "$numberInt" : "1" } }'::bson) -> Bitmap Index Scan on "k_1_l_1-2" Index Cond: (document @<> '{ "k" : { "fullScan" : true } }'::bson) (6 rows) -- try natural and id hint with no filters on sharded collections. SELECT documentdb_api.shard_collection('hint_db', 'query_index_hints', '{"_id": "hashed"}', FALSE); shard_collection --------------------------------------------------------------------- (1 row) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { }, "hint": { "$natural": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_69501_695004 collection (6 rows) EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { }, "hint": { "_id": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_69501_695004 collection (6 rows) bson_index_rum_index_scan_to_bitmap_heap_scan.out000066400000000000000000000320341507310017400417730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 50100; SET documentdb.next_collection_id TO 5010; SET documentdb.next_collection_index_id TO 5010; SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 1, "order_id" : "ORD1", "price" : 12, "quantity" : 2 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan','{ "_id" : 2, "order_id" : "ORD1", "fruit" : "apple", "price" : 20, "quantity" : 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 3, "order_id" : "ORD1", "fruit" : "banana", "price" : 10, "quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 4, "order_id" : "ORD1", "fruit" : ["orange", "banana", "apple"], "price" : 10, "quantity" : 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) do $$ begin for r in 1..500 loop PERFORM documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "order_id" : "ORD1", "fruit" : ["orange", "banana", "apple"], "price" : 10, "quantity" : 5 }', NULL); end loop; end; $$; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','bson_index_rum_index_scan_to_bitmap_heap_scan'); drop_primary_key --------------------------------------------------------------------- (1 row) EXPLAIN(costs off) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Seq Scan on documents_5010_50100 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (9 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bson_index_rum_index_scan_to_bitmap_heap_scan", "indexes": [{"key": {"order_id": 1}, "name": "order_id_1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Even if there is an index order_id_1, performs BitmapHeapScan instead of Index Scan BEGIN; set local enable_seqscan TO off; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Bitmap Heap Scan on documents_5010_50100 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) -> Bitmap Index Scan on order_id_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (11 rows) END; -- Tets for paralell BitmapHeapScan. Needs all the 5 config and at 500 docs in the collection to enable parallel bitmap scan. BEGIN; set local parallel_tuple_cost TO 0.00001; set local parallel_setup_cost TO 0; set local min_parallel_table_scan_size TO 0; set local min_parallel_index_scan_size TO 0; SET local enable_seqscan to OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) WITH t1 as (SELECT document FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD2" , "$and": [{"timestamp" : { "$lte":2000000}}]}'::bson ) SELECT bson_repath_and_build('rxCount'::text, BSONAVERAGE(document -> 'month')) from t1 group by bson_expression_get(document, '{ "": "$product_name" }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> GroupAggregate Group Key: (documentdb_api_catalog.bson_expression_get(collection.document, '{ "" : "$product_name" }'::documentdb_core.bson, false)) -> Gather Merge Workers Planned: 2 -> Sort Sort Key: (documentdb_api_catalog.bson_expression_get(collection.document, '{ "" : "$product_name" }'::documentdb_core.bson, false)) -> Parallel Bitmap Heap Scan on documents_5010_50100 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD2" }'::documentdb_core.bson) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "timestamp" : { "$numberInt" : "2000000" } }'::documentdb_core.bson) -> Bitmap Index Scan on order_id_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD2" }'::documentdb_core.bson) (16 rows) ROLLBACK; -- IndexScan is overritten by BitmapHeapScan when documentdb_api.forceRumIndexScantoBitmapHeapScan is toggled to off and then to on BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO true; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Bitmap Heap Scan on documents_5010_50100 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) -> Bitmap Index Scan on order_id_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (11 rows) END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO off BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO off; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Index Scan using order_id_1 on documents_5010_50100 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (9 rows) END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO "off" BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO off; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Index Scan using order_id_1 on documents_5010_50100 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (9 rows) END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO false BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO false; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Index Scan using order_id_1 on documents_5010_50100 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (9 rows) END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO "false" BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO "false"; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Aggregate -> Index Scan using order_id_1 on documents_5010_50100 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "order_id" : "ORD1" }'::documentdb_core.bson) (9 rows) END; bson_index_selection_tests.out000066400000000000000000000711151507310017400361500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 50000; SET documentdb.next_collection_id TO 5000; SET documentdb.next_collection_index_id TO 5000; SELECT documentdb_api.create_collection('db', 'indexselection'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a wildcard index on path a.b. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_a_b', '{"a.b.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create a non wildcard index on path 'b.c' SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_b_c', '{"b.c": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create a wildcard projection index with include paths at specific trees 'd.e.f' and 'g.h' SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexselection", "indexes": [ { "key": { "$**": 1 }, "name": "indexsel_path_wild_def_gh", "wildcardProjection": { "d.e.f": 1, "g.h": 1 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create two overlapping indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_overl_2', '{"r.s.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_overl_1', '{"r.s.t": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'some_long_index_name_that_is_definitely_over_64_characters_to_test_explain_index_name_length', '{"randomPath": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create a wildcard projection index that excludes all the above paths. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexselection", "indexes": [ { "key": { "$**": 1 }, "name": "indexsel_path_wild_excl_1", "wildcardProjection": { "d": 0, "g": 0, "a": 0, "b": 0, "r": 0, "randomPath": 0 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5000 Table "documentdb_data.documents_5000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5000" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5001" documentdb_rum (document bson_rum_single_path_ops (path='a.b', iswildcard='true', tl='2699')) "documents_rum_index_5002" documentdb_rum (document bson_rum_single_path_ops (path='b.c', tl='2699')) "documents_rum_index_5003" documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "d.e.f", "g.h" ]', isexclusion='false')) "documents_rum_index_5004" documentdb_rum (document bson_rum_single_path_ops (path='r.s', iswildcard='true', tl='2699')) "documents_rum_index_5005" documentdb_rum (document bson_rum_single_path_ops (path='r.s.t', tl='2699')) "documents_rum_index_5006" documentdb_rum (document bson_rum_single_path_ops (path='randomPath', tl='2699')) "documents_rum_index_5007" documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "d", "g", "a", "b", "r", "randomPath" ]', isexclusion='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5000'::bigint) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; -- now explain queries -- filter on a.b - should select indexsel_path_a_b EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_a_b Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b.c.d": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_a_b Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- does not match a_b (sequential scan) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.bar": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.bar" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) -- path root at is not exactly 'a' - matches excl_1. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "abc": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "abc" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_wild_excl_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "abc" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- filter on b.c - should select indexsel_path_b_c EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_b_c Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- not a wildcard - does not match. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.car": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b.car" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c.d": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) -- wildcard matches a projection EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "d.e.f.g": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "d.e.f.g" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_wild_def_gh Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "d.e.f.g" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g.1": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (shard_key_value = '5000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "g.1" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5000'::bigint) (10 rows) -- any other root paths or nested paths match the wildcard projection index. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "e": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_wild_excl_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "k.l.m": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "k.l.m" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_wild_excl_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "k.l.m" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "graph": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "graph" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_wild_excl_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "graph" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- on the overlapping indexes, last path wins. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "r.s.t": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "r.s.t" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_overl_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "r.s.t" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "r.s.u.1": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "r.s.u.1" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_overl_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "r.s.u.1" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- intersect two indexes EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "$and": [ { "a.b.c.d": { "$gte" : 1 } }, { "b.c": 2 } ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b.c" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> BitmapAnd -> Bitmap Index Scan on indexsel_path_b_c Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.c" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_a_b Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "$or": [ { "a.b.c.d": { "$gte" : 1 } }, { "b.c": 2 } ]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b.c" : { "$numberInt" : "2" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on indexsel_path_a_b Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.c.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on indexsel_path_b_c Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.c" : { "$numberInt" : "2" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "randomPath": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5000_50000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "randomPath" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on some_long_index_name_that_is_definitely_over_64_characters_to_test_explain_index_name_length Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "randomPath" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) -- now insert documents that match each of the filters -- matches a.b SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 1, "a" : { "b" : { "c": 1 } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- matches b.c SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 2, "b" : { "c" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- matches g.h SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 3, "g" : { "h" : { "i" : 0 } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- matches wildcard SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 4, "k" : { "l" : { "m" : 0 } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- matches none. SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 5, "g" : 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now query each one to see documents being returned. SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b.c" : 1 }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c" : { "$eq": 0 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g.h.i" : { "$gt": -1 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "k.l.m" : { "$lt": 1 } }'; count --------------------------------------------------------------------- 1 (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g" : { "$exists": 1 } }'; count --------------------------------------------------------------------- 2 (1 row) ROLLBACK; bson_index_term_generation.out000066400000000000000000005104651507310017400361310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 370000; SET documentdb.next_collection_id TO 3700; SET documentdb.next_collection_index_id TO 3700; -- now get terms for a simple document ( { a: { b : 1 }}) -- test root, 'a', 'a.b', 'a.b.1' with wildcard/non-wildcard SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "d" : { "$numberInt" : "1" } } { "" : true } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "" : true } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "1" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "1" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" } } { "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0" : { "$numberInt" : "0" } } { "a" : { "$numberInt" : "0" } } { "a.1" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "1" } } { "a.2" : { "$numberInt" : "2" } } { "a" : { "$numberInt" : "2" } } { "" : true } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0" : { "$numberInt" : "0" } } { "a" : { "$numberInt" : "0" } } { "a.1" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "1" } } { "a.2" : { "$numberInt" : "2" } } { "a" : { "$numberInt" : "2" } } { "" : true } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "$numberInt" : "0" } } { "a" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "2" } } { "" : true } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (10 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a.0" : { "b" : { "$numberInt" : "0" } } } { "a.0.b" : { "$numberInt" : "0" } } { "a" : { "b" : { "$numberInt" : "0" } } } { "a.b" : { "$numberInt" : "0" } } { "a.1" : { "b" : { "$numberInt" : "1" } } } { "a.1.b" : { "$numberInt" : "1" } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a.b" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberDouble" : "3.0" } } } { "a.2.b" : { "$numberDouble" : "3.0" } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a.0" : { "b" : { "$numberInt" : "0" } } } { "a.0.b" : { "$numberInt" : "0" } } { "a" : { "b" : { "$numberInt" : "0" } } } { "a.b" : { "$numberInt" : "0" } } { "a.1" : { "b" : { "$numberInt" : "1" } } } { "a.1.b" : { "$numberInt" : "1" } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a.b" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberDouble" : "3.0" } } } { "a.2.b" : { "$numberDouble" : "3.0" } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (15 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a" : { "b" : { "$numberInt" : "0" } } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (52 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (51 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (23 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (14 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (46 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (45 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (20 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (21 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (20 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (19 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "" : true } { "" : [ ] } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : "7" } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a.0" : { "c" : { "$numberInt" : "0" } } } { "a.0.c" : { "$numberInt" : "0" } } { "a" : { "c" : { "$numberInt" : "0" } } } { "a.c" : { "$numberInt" : "0" } } { "a.1" : { "c" : { "$numberInt" : "1" } } } { "a.1.c" : { "$numberInt" : "1" } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a.c" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberInt" : "2" } } } { "a.2.b" : { "$numberInt" : "2" } } { "a" : { "b" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a.0" : { "c" : { "$numberInt" : "0" } } } { "a.0.c" : { "$numberInt" : "0" } } { "a" : { "c" : { "$numberInt" : "0" } } } { "a.c" : { "$numberInt" : "0" } } { "a.1" : { "c" : { "$numberInt" : "1" } } } { "a.1.c" : { "$numberInt" : "1" } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a.c" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberInt" : "2" } } } { "a.2.b" : { "$numberInt" : "2" } } { "a" : { "b" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (15 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a" : { "c" : { "$numberInt" : "0" } } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a" : { "b" : { "$numberInt" : "2" } } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b.1', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b.1', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } { "" : [ ] } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "" : true } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "d" : { "$numberInt" : "1" } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "d" : { "$numberInt" : "1" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "d" : { "$numberInt" : "1" } } { "" : true } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" } } { "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0" : { "$numberInt" : "0" } } { "a" : { "$numberInt" : "0" } } { "a.1" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "1" } } { "a.2" : { "$numberInt" : "2" } } { "a" : { "$numberInt" : "2" } } { "" : true } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (10 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "" : true } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a.0" : { "b" : { "$numberInt" : "0" } } } { "a.0.b" : { "$numberInt" : "0" } } { "a" : { "b" : { "$numberInt" : "0" } } } { "a.b" : { "$numberInt" : "0" } } { "a.1" : { "b" : { "$numberInt" : "1" } } } { "a.1.b" : { "$numberInt" : "1" } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a.b" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberDouble" : "3.0" } } } { "a.2.b" : { "$numberDouble" : "3.0" } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberDouble" : "3.0" } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a.0" : { "b" : { "$numberInt" : "0" } } } { "a.0.b" : { "$numberInt" : "0" } } { "a" : { "b" : { "$numberInt" : "0" } } } { "a.1" : { "b" : { "$numberInt" : "1" } } } { "a.1.b" : { "$numberInt" : "1" } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a.2" : { "b" : { "$numberDouble" : "3.0" } } } { "a.2.b" : { "$numberDouble" : "3.0" } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "" : true } { "" : [ ] } (13 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "a.0" : { "b" : { "$numberInt" : "0" } } } { "a.0.b" : { "$numberInt" : "0" } } { "a" : { "b" : { "$numberInt" : "0" } } } { "a.1" : { "b" : { "$numberInt" : "1" } } } { "a.1.b" : { "$numberInt" : "1" } } { "a" : { "b" : { "$numberInt" : "1" } } } { "a.2" : { "b" : { "$numberDouble" : "3.0" } } } { "a.2.b" : { "$numberDouble" : "3.0" } } { "a" : { "b" : { "$numberDouble" : "3.0" } } } { "" : true } { "" : [ ] } (12 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (52 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (24 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "" : true } { "" : [ ] } (31 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "" : true } { "" : [ ] } (30 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a.b.0" : { "$numberInt" : "-1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.0" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.0" : { "$numberInt" : "0" } } { "a.b.1" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" } } { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (46 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "a.0" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0" : { "$numberInt" : "-1" } } { "a.0.b" : { "$numberInt" : "-1" } } { "a.0.b.1" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a.0.b.2" : { "$numberInt" : "2" } } { "a.0.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "-1" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.1" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0" : { "$numberInt" : "0" } } { "a.1.b" : { "$numberInt" : "0" } } { "a.1.b.1" : { "$numberInt" : "1" } } { "a.1.b" : { "$numberInt" : "1" } } { "a.1.b.2" : { "$numberInt" : "2" } } { "a.1.b" : { "$numberInt" : "2" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "2" } } { "a.b" : { "$numberInt" : "2" } } { "a.2" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0" : { "$numberInt" : "0" } } { "a.2.b" : { "$numberInt" : "0" } } { "a.2.b.1" : { "$numberInt" : "1" } } { "a.2.b" : { "$numberInt" : "1" } } { "a.2.b.2" : { "$numberInt" : "7" } } { "a.2.b" : { "$numberInt" : "7" } } { "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b" : { "$numberInt" : "0" } } { "a.b" : { "$numberInt" : "1" } } { "a.b.2" : { "$numberInt" : "7" } } { "a.b" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (45 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (46 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (21 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "" : true } { "" : [ ] } (28 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "" : true } { "" : [ ] } (27 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "-1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "2" } } { "a.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.b.0.0" : { "$numberInt" : "0" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.2" : { "$numberInt" : "7" } } { "" : true } { "" : [ ] } (15 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (34 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "a.0" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.0.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0.b.0" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.b.0.0" : { "$numberInt" : "-1" } } { "a.0.b.0.1" : { "$numberInt" : "1" } } { "a.0.b.0.2" : { "$numberInt" : "2" } } { "a.0.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.1.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.1.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.1.b.0.0" : { "$numberInt" : "0" } } { "a.1.b.0.1" : { "$numberInt" : "1" } } { "a.1.b.0.2" : { "$numberInt" : "2" } } { "a.1.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.2" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.2.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.2.b.0" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a.2.b.0.0" : { "$numberInt" : "0" } } { "a.2.b.0.1" : { "$numberInt" : "1" } } { "a.2.b.0.2" : { "$numberInt" : "7" } } { "a.2.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "a" : { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } } { "a.b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "a.b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } { "" : true } { "" : [ ] } (33 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (21 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (20 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a.b.0" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "a.b.0.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.0.1.0" : { "$numberInt" : "1" } } { "a.b.0.1" : { "$numberInt" : "1" } } { "a.b.0.1.1" : { "$numberInt" : "2" } } { "a.b.0.1" : { "$numberInt" : "2" } } { "a.b.0.1.2" : { "$numberInt" : "3" } } { "a.b.0.1" : { "$numberInt" : "3" } } { "a.b.1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "a.b.1.0" : { "$numberInt" : "1" } } { "a.b.1" : { "$numberInt" : "1" } } { "a.b.1.1" : { "$numberInt" : "2" } } { "a.b.1" : { "$numberInt" : "2" } } { "a.b.1.2" : { "$numberInt" : "3" } } { "a.b.1" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (18 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" } } { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "" : true } { "" : [ ] } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "a.b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "a.b" : { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } { "" : true } { "" : [ ] } (5 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : "7" } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a.0" : { "c" : { "$numberInt" : "0" } } } { "a.0.c" : { "$numberInt" : "0" } } { "a" : { "c" : { "$numberInt" : "0" } } } { "a.c" : { "$numberInt" : "0" } } { "a.1" : { "c" : { "$numberInt" : "1" } } } { "a.1.c" : { "$numberInt" : "1" } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a.c" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberInt" : "2" } } } { "a.2.b" : { "$numberInt" : "2" } } { "a" : { "b" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : "7" } { "" : true } (2 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "" : { "$undefined" : true } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : "7" } { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "_id" : "7" } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a.0" : { "c" : { "$numberInt" : "0" } } } { "a.0.c" : { "$numberInt" : "0" } } { "a" : { "c" : { "$numberInt" : "0" } } } { "a.c" : { "$numberInt" : "0" } } { "a.1" : { "c" : { "$numberInt" : "1" } } } { "a.1.c" : { "$numberInt" : "1" } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a.c" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberInt" : "2" } } } { "a.2.b" : { "$numberInt" : "2" } } { "a" : { "b" : { "$numberInt" : "2" } } } { "" : true } { "" : [ ] } (15 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, false); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "a.0" : { "c" : { "$numberInt" : "0" } } } { "a.0.c" : { "$numberInt" : "0" } } { "a" : { "c" : { "$numberInt" : "0" } } } { "a.c" : { "$numberInt" : "0" } } { "a.1" : { "c" : { "$numberInt" : "1" } } } { "a.1.c" : { "$numberInt" : "1" } } { "a" : { "c" : { "$numberInt" : "1" } } } { "a.c" : { "$numberInt" : "1" } } { "a.2" : { "b" : { "$numberInt" : "2" } } } { "a.2.b" : { "$numberInt" : "2" } } { "a" : { "b" : { "$numberInt" : "2" } } } { "" : true } { "" : [ ] } (14 rows) --Nested Array or Array has document SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [{"b" : "old"}] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : [ { "b" : "old" } ] } { "a.0" : { "b" : "old" } } { "a.0.b" : "old" } { "a" : { "b" : "old" } } { "a.b" : "old" } { "" : true } { "" : [ ] } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [[{"b" : "old"}]] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : [ [ { "b" : "old" } ] ] } { "a.0" : [ { "b" : "old" } ] } { "a.0.0" : { "b" : "old" } } { "a.0.0.b" : "old" } { "a.0.b" : "old" } { "a" : [ { "b" : "old" } ] } { "" : true } { "" : [ ] } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [[1,{"b" : "old"},3]] }', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" } } { "a" : [ [ { "$numberInt" : "1" }, { "b" : "old" }, { "$numberInt" : "3" } ] ] } { "a.0" : [ { "$numberInt" : "1" }, { "b" : "old" }, { "$numberInt" : "3" } ] } { "a.0.0" : { "$numberInt" : "1" } } { "a.0.1" : { "b" : "old" } } { "a.0.1.b" : "old" } { "a.0.b" : "old" } { "a.0.2" : { "$numberInt" : "3" } } { "a" : [ { "$numberInt" : "1" }, { "b" : "old" }, { "$numberInt" : "3" } ] } { "" : true } { "" : [ ] } (11 rows) -- generate terms with and without truncation -- string SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33" } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0I" } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 1000); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhE" } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 2500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9Nt" } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdLdlmMgxCMBE7wYDrvtfhGZymTmmjdCJ28ka0fnN47BeKymTmmjdCJ28ka0CPRgeDPGOR4FTVP0521ulBAnAdoxuboxub63"}', '', true, true, false, 45); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9Z" } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) -- binary SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 45); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$binary" : { "base64" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVo=", "subType" : "00" } } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 100); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$binary" : { "base64" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdS", "subType" : "00" } } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 20); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$binary" : { "base64" : "cDg2UFhxRw==", "subType" : "00" } } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$binary" : { "base64" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType" : "00" } } } { "" : true } (3 rows) -- code SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$code" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 40); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$code" : "cDg2UFhxR3B5a2dGNHByRjlYMG9" } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 20); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$code" : "cDg2UFh" } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) -- symbol SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$symbol" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 40); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$symbol" : "cDg2UFhxR3B5a2dGNHByRjlYMG9" } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 20); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$symbol" : "cDg2UFh" } } { "" : true } { "" : { "$maxKey" : 1 } } (4 rows) -- regex SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$regularExpression" : { "pattern" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options" : "" } } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 50); ERROR: Truncation size limit specified 50, but index term with type regex was larger 334 - isTruncated 0 SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 20); ERROR: Truncation size limit specified 20, but index term with type regex was larger 334 - isTruncated 0 -- regex with options SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "imxs" } } }', '', true, true, false, 500); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$regularExpression" : { "pattern" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options" : "imsx" } } } { "" : true } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "imxs" } } }', '', true, true, false, 50); ERROR: Truncation size limit specified 50, but index term with type regex was larger 338 - isTruncated 0 -- codewscope SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "$scope": { "a": "b" } } }', '', true, true, false, 50); ERROR: Truncation size limit specified 50, but index term with type javascriptWithScope was larger 355 - isTruncated 0 -- dbref SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$ref": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "$id": { "a": "b" } } }', '', true, true, false, 50); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "$ref" : "cDg2UFhxR3B5a2dGNHByRjl" } } { "a.$ref" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZH" } { "a.$id" : { "a" : "b" } } { "a.$id.a" : "b" } { "" : true } { "" : { "$maxKey" : 1 } } (7 rows) -- object SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "field": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "field2": "short field" } } }', '', true, true, false, 50); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : { "field" : { "pattern" : { "$maxKey" : 1 } } } } { "a.field" : { "pattern" : "cDg2UFhxR3B5a2" } } { "a.field.pattern" : "cDg2UFhxR3B5a2dGNHByRjl" } { "a.field.field2" : "short field" } { "" : true } { "" : { "$maxKey" : 1 } } (7 rows) -- array SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "short field" ] }', '', true, true, false, 50); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" } } { "a" : [ "cDg2UFhxR3B5a2dGNHByRjlYMG9" ] } { "a.0" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21" } { "a" : "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rU" } { "a.1" : "short field" } { "a" : "short field" } { "" : true } { "" : { "$maxKey" : 1 } } (8 rows) -- Section for unique index terms SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', false, true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : { "$numberInt" : "2" } } { "" : true } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "c" : 2 } ] }', 'a.b', false, true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : null } { "" : { "$undefined" : true } } { "" : [ ] } (3 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : null } ] }', 'a.b', false, true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.b" : null } { "" : null } { "" : true } { "" : [ ] } (4 rows) -- addMetadata true SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', true, false, true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : "7", "t" : false } { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], "t" : false } { "a.0" : { "c" : { "$numberInt" : "0" } }, "t" : false } { "a.0.c" : { "$numberInt" : "0" }, "t" : false } { "a" : { "c" : { "$numberInt" : "0" } }, "t" : false } { "a.c" : { "$numberInt" : "0" }, "t" : false } { "a.1" : { "c" : { "$numberInt" : "1" } }, "t" : false } { "a.1.c" : { "$numberInt" : "1" }, "t" : false } { "a" : { "c" : { "$numberInt" : "1" } }, "t" : false } { "a.c" : { "$numberInt" : "1" }, "t" : false } { "a.2" : { "b" : { "$numberInt" : "2" } }, "t" : false } { "a.2.b" : { "$numberInt" : "2" }, "t" : false } { "a" : { "b" : { "$numberInt" : "2" } }, "t" : false } { "a.b" : { "$numberInt" : "2" }, "t" : false } { "" : true, "t" : false } { "" : [ ], "t" : false } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, false, true); gin_bson_get_wildcard_project_generated_terms --------------------------------------------------------------------- { "a" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], "t" : false } { "a.0" : { "c" : { "$numberInt" : "0" } }, "t" : false } { "a.0.c" : { "$numberInt" : "0" }, "t" : false } { "a" : { "c" : { "$numberInt" : "0" } }, "t" : false } { "a.c" : { "$numberInt" : "0" }, "t" : false } { "a.1" : { "c" : { "$numberInt" : "1" } }, "t" : false } { "a.1.c" : { "$numberInt" : "1" }, "t" : false } { "a" : { "c" : { "$numberInt" : "1" } }, "t" : false } { "a.c" : { "$numberInt" : "1" }, "t" : false } { "a.2" : { "b" : { "$numberInt" : "2" } }, "t" : false } { "a.2.b" : { "$numberInt" : "2" }, "t" : false } { "a" : { "b" : { "$numberInt" : "2" } }, "t" : false } { "" : true, "t" : false } { "" : [ ], "t" : false } (14 rows) -- add array ancestor for wildcard SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "b": { "c": 1 } } ] }', 'a', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a" : [ { "b" : { "c" : { "$numberInt" : "1" } } } ] } { "a.0" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "a.0.b" : { "c" : { "$numberInt" : "1" } } } { "a.0.b.c" : { "$numberInt" : "1" } } { "a" : { "b" : { "c" : { "$numberInt" : "1" } } } } { "a.b" : { "c" : { "$numberInt" : "1" } } } { "a.b.c" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (9 rows) -- test when non exists term generation is off should generate min key root term BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "a" : 1 }', 'b', true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$minKey" : 1 } } (1 row) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "a" : 1 }', 'b', false); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "" : { "$minKey" : 1 } } (1 row) COMMIT; SELECT documentdb_api.create_collection('db', 'indextermgeneration'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create all of these indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_1', '{"$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_2', '{"a.b.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_3', '{"a.b": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create a compound index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_comp_path_1', '{"a.b": 1, "a.c": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indextermgeneration", "indexes": [ { "key": { "$**": 1 }, "name": "indexgen_wildcard_1", "wildcardProjection": { "a.b": 1 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indextermgeneration", "indexes": [ { "key": { "$**": 1 }, "name": "indexgen_wildcard_2", "wildcardProjection": { "a.b": 0, "a.c": 0 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_3700 Table "documentdb_data.documents_3700" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_3700" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_3701" documentdb_rum (document bson_rum_single_path_ops (path='', iswildcard='true', tl='2699', wkl='200')) "documents_rum_index_3702" documentdb_rum (document bson_rum_single_path_ops (path='a.b', iswildcard='true', tl='2699')) "documents_rum_index_3703" documentdb_rum (document bson_rum_single_path_ops (path='a.b', tl='2699')) "documents_rum_index_3704" documentdb_rum (document bson_rum_single_path_ops (path='a.b', tl='2691'), document bson_rum_single_path_ops (path='a.c', tl='2691')) "documents_rum_index_3705" documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a.b" ]', isexclusion='false')) "documents_rum_index_3706" documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a.b", "a.c" ]', isexclusion='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '3700'::bigint) -- now insert some documents - we still can't query it at this point but this is a sanity validation. SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) bson_index_truncation_binary_tests.out000066400000000000000000010115361507310017400377170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_core; SET citus.next_shard_id TO 1150000; SET documentdb.next_collection_id TO 11500; SET documentdb.next_collection_index_id TO 11500; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_binary_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11500 Table "documentdb_data.documents_11500" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11500" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11501" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='20')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11500'::bigint) -- Insert binary BSON data with all subtypes SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 1, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 2, "ikey": { "$binary" : { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 3, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 4, "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 5, "ikey": { "$binary" : { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 6, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item": "F", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 7, "ikey": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item": "G", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 8, "ikey": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 9, "ikey": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item": "H", "customKey": 8 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 10, "ikey": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item": "H", "customKey": 9 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11500) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbQ==", "subType" : "00" } }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IA==", "subType" : "01" } }, "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbQ==", "subType" : "04" } }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 20 | { "$" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } }, "t" : false } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IA==", "subType" : "06" } }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbQ==", "subType" : "07" } }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IA==", "subType" : "01" } }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 20 | { "$" : { "$binary" : { "base64" : "dGhpcyBpcw==", "subType" : "00" } }, "t" : true } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "8" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "9" } } | 20 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IA==", "subType" : "04" } }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 20 | { "$" : { "$binary" : { "base64" : "dGhpcyBpcw==", "subType" : "01" } }, "t" : true } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "10" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (29 rows) /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11500) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 40 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjog", "subType" : "00" } }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 31 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } }, "t" : false } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 40 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjog", "subType" : "04" } }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 20 | { "$" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } }, "t" : false } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 31 | { "$" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } }, "t" : false } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 40 | { "$" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjog", "subType" : "07" } }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 40 | { "$" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIz", "subType" : "01" } }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 34 | { "$" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } }, "t" : false } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 40 | { "$" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIz", "subType" : "04" } }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 34 | { "$" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "t" : false } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } (25 rows) /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (3 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "00" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "00" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "00" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "00" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (8 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) /* $in/$nin/$ne/$all (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } }'::documentdb_api_internal.bsonindexbounds, '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_api_internal.bsonindexbounds])) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_nin(document, '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!*=) '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!*=) '{ "ikey" : [ { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson)) -> Bitmap Index Scan on ikey_1 Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$binary" : { "base64" : "MTIzNDUxMjM0NQ==", "subType" : "07" } } }'::documentdb_core.bson)) (12 rows) /* $bitsAllClear (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 0 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 32 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 54 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 0 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 32 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 54 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_clear(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) (12 rows) /* $bitsAllClear (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_clear(document, '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_clear(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_clear(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) (12 rows) /* $bitsAllSet (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "YWJvYm9yYQ==", "subType": "05"}} } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 32 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 54 } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "YWJvYm9yYQ==", "subType": "05"}} } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 1 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 32 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "5" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 54 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_all_set(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@&) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) (12 rows) /* $bitsAnySet (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$binary" : { "base64" : "YWJvYm9yYQ==", "subType" : "05" } } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$binary" : { "base64" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$binary" : { "base64" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": 0 } }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_set(document, '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "11" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "37" }, { "$numberInt" : "40" }, { "$numberInt" : "43" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "61" }, { "$numberInt" : "64" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "77" }, { "$numberInt" : "82" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "88" }, { "$numberInt" : "90" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "106" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "117" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "130" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "137" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "144" }, { "$numberInt" : "147" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "165" }, { "$numberInt" : "166" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_set(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "25" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "41" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "48" }, { "$numberInt" : "53" }, { "$numberInt" : "54" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_set(document, '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" }, { "$numberInt" : "12" }, { "$numberInt" : "13" }, { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" }, { "$numberInt" : "19" }, { "$numberInt" : "20" }, { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" }, { "$numberInt" : "24" }, { "$numberInt" : "25" }, { "$numberInt" : "26" }, { "$numberInt" : "27" }, { "$numberInt" : "28" }, { "$numberInt" : "29" }, { "$numberInt" : "30" }, { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" }, { "$numberInt" : "35" }, { "$numberInt" : "36" }, { "$numberInt" : "37" }, { "$numberInt" : "38" }, { "$numberInt" : "39" }, { "$numberInt" : "40" }, { "$numberInt" : "41" }, { "$numberInt" : "42" }, { "$numberInt" : "43" }, { "$numberInt" : "44" }, { "$numberInt" : "45" }, { "$numberInt" : "46" }, { "$numberInt" : "47" }, { "$numberInt" : "48" }, { "$numberInt" : "49" }, { "$numberInt" : "50" }, { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" }, { "$numberInt" : "54" }, { "$numberInt" : "55" }, { "$numberInt" : "56" }, { "$numberInt" : "57" }, { "$numberInt" : "58" }, { "$numberInt" : "59" }, { "$numberInt" : "60" }, { "$numberInt" : "61" }, { "$numberInt" : "62" }, { "$numberInt" : "63" }, { "$numberInt" : "64" }, { "$numberInt" : "65" }, { "$numberInt" : "66" }, { "$numberInt" : "67" }, { "$numberInt" : "68" }, { "$numberInt" : "69" }, { "$numberInt" : "70" }, { "$numberInt" : "71" }, { "$numberInt" : "72" }, { "$numberInt" : "73" }, { "$numberInt" : "74" }, { "$numberInt" : "75" }, { "$numberInt" : "76" }, { "$numberInt" : "77" }, { "$numberInt" : "78" }, { "$numberInt" : "79" }, { "$numberInt" : "80" }, { "$numberInt" : "81" }, { "$numberInt" : "82" }, { "$numberInt" : "83" }, { "$numberInt" : "84" }, { "$numberInt" : "85" }, { "$numberInt" : "86" }, { "$numberInt" : "87" }, { "$numberInt" : "88" }, { "$numberInt" : "89" }, { "$numberInt" : "90" }, { "$numberInt" : "91" }, { "$numberInt" : "92" }, { "$numberInt" : "93" }, { "$numberInt" : "94" }, { "$numberInt" : "95" }, { "$numberInt" : "96" }, { "$numberInt" : "97" }, { "$numberInt" : "98" }, { "$numberInt" : "99" }, { "$numberInt" : "100" }, { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" }, { "$numberInt" : "105" }, { "$numberInt" : "106" }, { "$numberInt" : "107" }, { "$numberInt" : "108" }, { "$numberInt" : "109" }, { "$numberInt" : "110" }, { "$numberInt" : "111" }, { "$numberInt" : "112" }, { "$numberInt" : "113" }, { "$numberInt" : "114" }, { "$numberInt" : "115" }, { "$numberInt" : "116" }, { "$numberInt" : "117" }, { "$numberInt" : "118" }, { "$numberInt" : "119" }, { "$numberInt" : "120" }, { "$numberInt" : "121" }, { "$numberInt" : "122" }, { "$numberInt" : "123" }, { "$numberInt" : "124" }, { "$numberInt" : "125" }, { "$numberInt" : "126" }, { "$numberInt" : "127" }, { "$numberInt" : "128" }, { "$numberInt" : "129" }, { "$numberInt" : "130" }, { "$numberInt" : "131" }, { "$numberInt" : "132" }, { "$numberInt" : "133" }, { "$numberInt" : "134" }, { "$numberInt" : "135" }, { "$numberInt" : "136" }, { "$numberInt" : "137" }, { "$numberInt" : "138" }, { "$numberInt" : "139" }, { "$numberInt" : "140" }, { "$numberInt" : "141" }, { "$numberInt" : "142" }, { "$numberInt" : "143" }, { "$numberInt" : "144" }, { "$numberInt" : "145" }, { "$numberInt" : "146" }, { "$numberInt" : "147" }, { "$numberInt" : "148" }, { "$numberInt" : "149" }, { "$numberInt" : "150" }, { "$numberInt" : "151" }, { "$numberInt" : "152" }, { "$numberInt" : "153" }, { "$numberInt" : "154" }, { "$numberInt" : "155" }, { "$numberInt" : "156" }, { "$numberInt" : "157" }, { "$numberInt" : "158" }, { "$numberInt" : "159" }, { "$numberInt" : "160" }, { "$numberInt" : "161" }, { "$numberInt" : "162" }, { "$numberInt" : "163" }, { "$numberInt" : "164" }, { "$numberInt" : "165" }, { "$numberInt" : "166" }, { "$numberInt" : "167" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": 0 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11500_1150003 collection WHERE (documentdb_api_catalog.bson_dollar_bits_any_set(document, '{ "ikey" : [ ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11500'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11500_1150003 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@|) '{ "ikey" : [ ] }'::documentdb_core.bson) (12 rows) -- insert binary BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_binary_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11501 Table "documentdb_data.documents_11501" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11501" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11503" documentdb_rum (document bson_rum_single_path_ops (path=ikey2, tl='100')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11501'::bigint) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11501) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmE=", "subType" : "00" } } } } } }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 93 | { "$" : [ [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2I=", "subType" : "00" } } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 91 | { "$" : [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 30 | { "$" : [ [ "a" ] ], "t" : false } { "" : { "$numberInt" : "3" } } | 22 | { "$" : [ "a" ], "t" : false } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasad" } } } } } }, "t" : true } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "5" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 80 | { "$" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$maxKey" : 1 } } } } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 94 | { "$" : [ [ [ [ [ { "a" : { "b" : { "c" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMyw=", "subType" : "00" } } } } } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (23 rows) /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "test" : "a", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "test" : "b", "ikey2" : [ [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] ] ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "test" : "c", "ikey2" : [ [ "a" ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "test" : "d", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "test" : "e", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "test" : "f", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "test" : "g", "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ] ] ] ] ] ], "item" : "A" } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } ] ] ] } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11501_1150018 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11501'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11501_1150018 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$binary" : { "base64" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) bson_index_truncation_code_tests.out000066400000000000000000002355571507310017400373570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1160000; SET documentdb.next_collection_id TO 11600; SET documentdb.next_collection_index_id TO 11600; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_code_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11600 Table "documentdb_data.documents_11600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11601" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='20')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11600'::bigint) -- Insert code BSON data SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 1, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 2, "ikey": { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 3, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 4, "ikey": { "$code" : "YWJvYm9yYQ==" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 5, "ikey": { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 6, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "F", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 7, "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 8, "ikey": { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 9, "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "H", "customKey": 8 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 10, "ikey": { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item": "H", "customKey": 9 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11600) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 20 | { "$" : { "$code" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 20 | { "$" : { "$code" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 20 | { "$" : { "$code" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 20 | { "$" : { "$code" : "YWJvYm9" }, "t" : true } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "5" } } | 20 | { "$" : { "$code" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 20 | { "$" : { "$code" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 20 | { "$" : { "$code" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 20 | { "$" : { "$code" : "dGhpcyB" }, "t" : true } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "8" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "9" } } | 20 | { "$" : { "$code" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 20 | { "$" : { "$code" : "dGhpcyB" }, "t" : true } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "10" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (30 rows) /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11600) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 40 | { "$" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 37 | { "$" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" }, "t" : false } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 40 | { "$" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 25 | { "$" : { "$code" : "YWJvYm9yYQ==" }, "t" : false } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 37 | { "$" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" }, "t" : false } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 40 | { "$" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 40 | { "$" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjo" }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 40 | { "$" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5" }, "t" : true } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "8" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "9" } } | 40 | { "$" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjo" }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 40 | { "$" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5" }, "t" : true } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "10" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (27 rows) /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiYSI6IDEsICJiIjogMyB9" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "YWJvYm9yYQ==" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "G" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "G" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiYSI6IDEsICJiIjogMyB9" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "YWJvYm9yYQ==" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$code" : "YWJvYm9yYQ==" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11600_1160007 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11600'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11600_1160007 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$code" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $in/$nin/$ne/$all (all terms truncated) */ -- TODO upgrade libbson to fix seg fault errors -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "YWJvYm9yYQ==" } } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "YWJvYm9yYQ==" } } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- insert $code BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_code_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11601 Table "documentdb_data.documents_11601" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11601" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11603" documentdb_rum (document bson_rum_single_path_ops (path=ikey2, tl='100')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11601'::bigint) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11601) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjo" } } } } }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 93 | { "$" : [ [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywg" } } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 94 | { "$" : [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlI" } } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 30 | { "$" : [ [ "a" ] ], "t" : false } { "" : { "$numberInt" : "3" } } | 22 | { "$" : [ "a" ], "t" : false } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasad" } } } } } }, "t" : true } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "5" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 80 | { "$" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$maxKey" : 1 } } } } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 94 | { "$" : [ [ [ [ [ { "a" : { "b" : { "c" : { "$code" : "eyAiZXhhbXBsZSI6I" } } } } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (23 rows) /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "test" : "a", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "test" : "b", "ikey2" : [ [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] ] ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "test" : "c", "ikey2" : [ [ "a" ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "test" : "d", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "test" : "e", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "test" : "f", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "test" : "g", "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ], "item" : "A" } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "a" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } ] ] ] } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11601_1160019 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11601'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11601_1160019 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) bson_index_truncation_index_tests.out000066400000000000000000011270571507310017400375500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 640000; SET documentdb.next_collection_id TO 6400; SET documentdb.next_collection_index_id TO 6400; -- Set configs to something reasonable for testing. set documentdb.indexTermLimitOverride to 100; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now we have an index with truncation enabled and 100 chars. \d documentdb_data.documents_6400; Table "documentdb_data.documents_6400" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6400" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6401" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='100')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6400'::bigint) --------------------------------------------------------------------- ---- DATA TYPE: UTF8 --------------------------------------------------------------------- SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end"}', '', true, true, false, 100) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "13" } } 100 | { "ikey" : "this is another string that does violate the index term limit as it goes much over t" } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end"}', 'ikey', false, true, false, 100) term; length | term --------------------------------------------------------------------- 100 | { "$" : "this is another string that does violate the index term limit as it goes much over the " } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (3 rows) -- now insert some documents that don't exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 1, "ikey": "this is a string that does not violate the index term limit" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 2, "ikey": "this is another string that doesnt violate the index term limit" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some documents that technically do violate the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 3, "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 4, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- only changes beyond the index term limit SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 5, "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 6, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this is less than _id: 6 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 7, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this is less than _id: 7 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 8, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now that they've succeeded query all of them. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does not violate the index term limit" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that doesnt violate the index term limit" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (1 row) -- test $gt -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (8 rows) -- all "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is aa" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- no strings SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that doesnt violate the index term limit" } }'; document --------------------------------------------------------------------- (0 rows) -- all long strings with 'another' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- only the string that has the change in the end & the one that doesnt' violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (2 rows) -- only the one with 'in' and 'of' in the suffix & the one that doesn't violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } (4 rows) -- test $gte -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (8 rows) -- all "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is aa" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- unlike $gt with no strings - this returns the equality on that exact string. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that doesnt violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } (1 row) -- all strings with 'another' (unlike $gt since we have $eq as well) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- all strings but this one SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- all but 'in' and 'of' in the suffix & the one that doesn't violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- test $lt -- no records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is a" } }'; document --------------------------------------------------------------------- (0 rows) -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is b" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (8 rows) -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is aa" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- Matches all that are "this is a string". Also matches all the 'another' strings that are 'after', 'in', but not 'of' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) -- Matches all that are "this is a string". SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- test $lte -- no records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is a" } }'; document --------------------------------------------------------------------- (0 rows) -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is b" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (8 rows) -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is aa" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) -- All strings except 'this is another string that doesnt' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (6 rows) -- Matches all that are "this is a string" & equality on exact match on the string. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (4 rows) -- $range -- repeat checks with $gt/$lt SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lt": "this is an" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is a string that does not violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is another string that does not violate the index term limit" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end", "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (3 rows) -- $in SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (3 rows) -- $ne SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (7 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "3" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } (7 rows) -- $nin SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (6 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : "this is another string that doesnt violate the index term limit" } { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } (5 rows) -- $regex scenarios SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", { "$regex": "the end$", "$options": "" } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$regex": "the end$", "$options": "" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (4 rows) -- $all scenarios SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ "this is a string that does not violate the index term limit", { "$regex": "\\s+", "$options": "" } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ { "$regex": "\\d+", "$options": "" }, { "$regex": "\\s+another\\s+", "$options": "" } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } { "_id" : { "$numberInt" : "6" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } { "_id" : { "$numberInt" : "7" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" } { "_id" : { "$numberInt" : "8" }, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ "this is a string that does not violate the index term limit" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : "this is a string that does not violate the index term limit" } (1 row) --------------------------------------------------------------------- ---- DATA TYPE: Array --------------------------------------------------------------------- -- with 60 byte truncation limit, the real limit is 60-21 = 39 bytes. We can tolerate any entries over 39 bytes as long as they're also marked truncated. -- the base structural overhead for an array is 5 (bson Doc) + 2 (path) + 1 (typecode) + 5 (array header) = 13 bytes -- each path takes 2-4 characters (index as a string), 1 byte (type code) + path Value (variable) = 3-5 bytes + valueLength -- track truncation with simple int4 -- empty array (13 bytes) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ ]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 13 | { "$" : [ ], "t" : false } 8 | { "" : true, "t" : false } (2 rows) -- int array: int overhead = 3 + sizeof(int) = 7 -- Expectation is 13 bytes of overhead + (2 * 7) = 27 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 1))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 27 | { "$" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 8 | { "" : true, "t" : false } (4 rows) -- Expectation is 13 bytes of overhead + (3 * 7) = 34 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 2))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 34 | { "$" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 8 | { "" : true, "t" : false } (5 rows) -- Expectation is 13 bytes of overhead + (4 * 7) = 41 bytes -> 41 bytes and truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 3))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 41 | { "$" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "t" : true } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (7 rows) -- Expectation is 13 bytes of overhead + (5 * 7) = 51 bytes -> 41 bytes and truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 41 | { "$" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "t" : true } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (8 rows) -- track truncation with bools: size overhead = 3 + sizeof(bool) = 4 -- Expectation is 13 bytes of overhead + (4 * 4) = 29 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 3))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 29 | { "$" : [ false, true, true, true ], "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 8 | { "" : true, "t" : false } (6 rows) -- Expectation is 13 bytes of overhead + (5 * 4) = 33 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', false', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 33 | { "$" : [ false, false, false, false, false ], "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : false, "t" : false } 8 | { "" : true, "t" : false } (7 rows) -- Expectation is 13 bytes of overhead + (6 * 4) = 37 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 5))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 37 | { "$" : [ false, true, true, true, true, true ], "t" : false } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 8 | { "" : true, "t" : false } (8 rows) -- Expectation is 13 bytes of overhead + (7 * 4) = 41 bytes -> 41 bytes (truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 6))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 41 | { "$" : [ false, true, true, true, true, true, true ], "t" : true } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (10 rows) -- Expectation is 13 bytes of overhead + (8 * 4) = 45 bytes -> 41 bytes (truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 7))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 41 | { "$" : [ false, true, true, true, true, true, true ], "t" : true } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (11 rows) -- decimal128 overhead = 3 + sizeof(decimal128) = 19 bytes -- Expectation is 13 bytes of overhead + (1 * 19) = 32 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 32 | { "$" : [ { "$numberDecimal" : "1.29E+402" } ], "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 8 | { "" : true, "t" : false } (3 rows) -- 2 decimal128 : 13 + 38 = 51 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 51 | { "$" : [ { "$numberDecimal" : "1.29E+402" }, { "$numberDecimal" : "1.29E+402" } ], "t" : true } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (5 rows) -- 3 decimal128 : 13 + 57 = 70 bytes-> 51 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 51 | { "$" : [ { "$numberDecimal" : "1.29E+402" }, { "$numberDecimal" : "1.29E+402" } ], "t" : true } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) -- decimal 127 + bool (truncated at decimal128) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }, false]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 51 | { "$" : [ { "$numberDecimal" : "1.29E+402" }, { "$numberDecimal" : "1.29E+402" } ], "t" : true } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 9 | { "$" : false, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) -- bool + decimal128 (truncated but has all values) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ false, { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 55 | { "$" : [ false, { "$numberDecimal" : "1.29E+402" }, { "$numberDecimal" : "1.29E+402" } ], "t" : true } 9 | { "$" : false, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) -- 5 bool + int: Expected is 13 + (5 * 4) + 7 = 33 + 7 = 40 -> Truncated with all values SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s, 1234 ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 40 | { "$" : [ false, true, true, true, true, { "$numberInt" : "1234" } ], "t" : true } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (9 rows) -- 5 bool + decimal128: Expected is 13 + (5 * 4) + 19 = 33 + 19 = 52 -> Truncated with all values SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s, { "$numberDecimal": "129e400" } ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 52 | { "$" : [ false, true, true, true, true, { "$numberDecimal" : "1.29E+402" } ], "t" : true } 9 | { "$" : false, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 9 | { "$" : true, "t" : false } 24 | { "$" : { "$numberDecimal" : "1.29E+402" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (9 rows) -- array with mixed fixed + variable. SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberDecimal": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 58 | { "$" : [ { "$numberInt" : "1234" }, "This is a string that needs to" ], "t" : true } 24 | { "$" : { "$numberDecimal" : "1234" }, "t" : false } 60 | { "$" : "This is a string that needs to be truncated aft", "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (5 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberInt": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 58 | { "$" : [ { "$numberInt" : "1234" }, "This is a string that needs to" ], "t" : true } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 60 | { "$" : "This is a string that needs to be truncated aft", "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (5 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberLong": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 58 | { "$" : [ { "$numberInt" : "1234" }, "This is a string that needs to" ], "t" : true } 16 | { "$" : { "$numberLong" : "1234" }, "t" : false } 60 | { "$" : "This is a string that needs to be truncated aft", "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (5 rows) -- Expectation is 13 bytes of overhead + (3 * 7) = 34 bytes + 1 bools == 38 bytes. Now add a string - it shouldn't fail since it will still go over the soft limit of 39 SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s, true, "abcde" ]}', repeat(', 1234', 2))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 51 | { "$" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, true, "abcde" ], "t" : true } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 12 | { "$" : { "$numberInt" : "1234" }, "t" : false } 9 | { "$" : true, "t" : false } 18 | { "$" : "abcde", "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (8 rows) -- start fresh with arrays SELECT documentdb_api.drop_collection('db','index_truncation_tests'); drop_collection --------------------------------------------------------------------- t (1 row) set documentdb.indexTermLimitOverride to 60; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_6401 Table "documentdb_data.documents_6401" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6401" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6403" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='60')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6401'::bigint) -- empty array SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 1, "ikey": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- bool arrays SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 2, "ikey": [ false ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 3, "ikey": [ false %s ] }', repeat(', true', 3))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 4, "ikey": [ false %s ] }', repeat(', true', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 5, "ikey": [ false %s ] }', repeat(', true', 5))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 6, "ikey": [ false %s ] }', repeat(', true', 6))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- int arrays SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 7, "ikey" : [ 1234 %s ]}', repeat(', 1234', 1))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 8, "ikey" : [ 1234 %s ]}', repeat(', 1234', 2))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 9, "ikey" : [ 1234 %s ]}', repeat(', 1234', 3))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 10, "ikey" : [ 1234 %s ]}', repeat(', 1234', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 21, "ikey" : [ 1234 %s, 3457 ]}', repeat(', 1234', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- decimal array SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 11, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 1))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 12, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 2))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 13, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 3))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 14, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 15, "ikey" : [ { "$numberDecimal": "1234" } %s, 2345 ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 16, "ikey" : [ { "$numberDecimal": "1234" } %s, 3456 ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 17, "ikey" : [ { "$numberDecimal": "1e406" } %s ]}', repeat(', { "$numberDecimal": "1e406" }', 1))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 18, "ikey" : [ { "$numberDecimal": "1e406" } %s ]}', repeat(', { "$numberDecimal": "1e406" }', 2))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 19, "ikey" : [ { "$numberDecimal": "1e406" } %s, 1 ]}', repeat(', { "$numberDecimal": "1e406" }', 3))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 20, "ikey" : [ { "$numberDecimal": "1e406" } %s, 5 ]}', repeat(', { "$numberDecimal": "1e406" }', 4))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- mixed types SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 22, "ikey" : [ 1234, 1234, "This is a string after the numbers" ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 23, "ikey" : [ { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" }, "This is a string after the numbers" ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 24, "ikey" : [ "String before", 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 25, "ikey" : [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 26, "ikey" : [ "String before", 1234, 1234, "This is a string after the numbers" ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 27, "ikey" : [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" }, "This is a string after the numbers" ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test $eq SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false, true, true, true, true, true, false ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false, true, true, true, true, true, true ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "13" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234, 1234 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "14" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234, 1234, 3457 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, 1 ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, 2 ] }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, "This is a string after the numbers" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" } ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ "String before", { "$numberLong": "1234" }, { "$numberLong": "1234" }, "This is a string after the numbers" ] }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (2 rows) -- test $gt/$gte SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ false, true, true, true, true, true, false ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ false, true, true, true, true, true, true ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 1233 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "13" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "14" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "15" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "2345" } ] } { "_id" : { "$numberInt" : "16" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "3456" } ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (26 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 1234, 1234, 1234, 1234, 1234, 3000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } { "_id" : { "$numberInt" : "16" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "3456" } ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (17 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, 1234, 1234, 1234, 3457 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (16 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, "This is a string after the numbers greater" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (13 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, "This is a string after the number" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (15 rows) -- $size SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ false ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 2 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "17" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 3 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "18" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" } ] } { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "24" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "25" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } (7 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 4 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : [ false, true, true, true ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "13" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 5 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ false, true, true, true, true ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "14" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" } ] } { "_id" : { "$numberInt" : "19" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "1" } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 6 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : [ false, true, true, true, true, true ] } { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } { "_id" : { "$numberInt" : "15" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "2345" } ] } { "_id" : { "$numberInt" : "16" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "3456" } ] } { "_id" : { "$numberInt" : "20" }, "ikey" : [ { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberDecimal" : "1E+406" }, { "$numberInt" : "5" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 7 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "ikey" : [ false, true, true, true, true, true, true ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 8 } }'; document --------------------------------------------------------------------- (0 rows) -- $all SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, 3457 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, "This is a string after the numbers" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, { "$regex": ".+string.+numbers", "$options": "" } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "23" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "26" }, "ikey" : [ "String before", { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string after the numbers" ] } { "_id" : { "$numberInt" : "27" }, "ikey" : [ "String before", { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, "This is a string after the numbers" ] } (4 rows) -- $all with $elemMatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$elemMatch": { "$gt": 1000, "$lt": 2000 } }, { "$elemMatch": { "$gt": 2000, "$lt": 3000 } } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "2345" } ] } (1 row) -- $elemMatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$gt": 3000, "$lt": 4000 }} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "21" }, "ikey" : [ { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "3457" } ] } { "_id" : { "$numberInt" : "16" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "3456" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$all": [ 2345 ] }} }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "ikey" : [ { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberDecimal" : "1234" }, { "$numberInt" : "2345" } ] } (1 row) DELETE FROM documentdb_data.documents_6401; -- Specific operator tests. -- $gt BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ null, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2340, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2344, 1235 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) ROLLBACk; BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ null, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2340, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2344, 1235 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 31, 32, 34, 35 have values in position 4 that would be > and match, 36 matches on the last index. Only 33 is a mismatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numerDouble" : "1234" }, { "$numberDecimal" : "1451" } ] } (7 rows) -- Now only 31, 32, 34, 35 match SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 2 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numerDouble" : "1234" }, { "$numberDecimal" : "1451" } ] } (5 rows) ROLLBACK; -- integer + string + integer. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars", 2 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, { "$maxKey": 1 } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberDouble" : "2345.0999999999999091" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, { "$maxKey": 1 } ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some maximal string" ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some large string that should theoretically" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberDouble" : "2345.0999999999999091" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then less", -1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", -1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 1 ] } }'; document --------------------------------------------------------------------- (0 rows) ROLLBACK; -- $lt BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ true, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2340, 2345 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2346, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2344, 1235 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, 1234, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1449" } ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1450" }, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } (4 rows) ROLLBACK; -- $gte BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ null, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2340, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2344, 1235 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) ROLLBACk; BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ null, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2340, 2345 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2344" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (2 rows) -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2344, 1235 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } (1 row) ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 31, 32, 34, 35 have values in position 4 that would be > and match, 36 matches on the last index. Only 33 is a mismatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numerDouble" : "1234" }, { "$numberDecimal" : "1451" } ] } (7 rows) -- Now only 31, 32, 34, 35 match SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 2 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numerDouble" : "1234" }, { "$numberDecimal" : "1451" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberDecimal" : "2345" }, { "$numberInt" : "1234" }, { "$numerDouble" : "1234" }, { "$numberDecimal" : "1451" } ] } (7 rows) ROLLBACK; -- integer + string + integer. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars", 2 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, { "$maxKey": 1 } ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberDouble" : "2345.0999999999999091" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, { "$maxKey": 1 } ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some maximal string" ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some large string that should theoretically" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberDouble" : "2345.0999999999999091" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberDouble" : "2345.0999999999999091" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars", { "$numberInt" : "2" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then less", -1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", -1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberDecimal" : "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", { "$numberInt" : "0" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 1 ] } }'; document --------------------------------------------------------------------- (0 rows) ROLLBACK; -- $in/$nin/$ne/$all(eq) BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ [ 2345, 1234, 1234, { "$numberInt": "1450" } ], [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ [ 2345, 1234, 1234, { "$numberInt": "1450" } ], [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ { "$elemMatch": { "$eq": 1 }}, { "$elemMatch": { "$eq": 1451 } } ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$eq": 1 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1450" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDecimal" : "1451" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberDouble" : "1449.0" }, { "$numberInt" : "1" } ] } (3 rows) ROLLBACK; -- $elemMatch (regex) BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, "This is a string that goes over the index truncation limit" ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$all": [ { "$regex": "limit$", "$options": "" } ] }}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, "This is a string that goes over the index truncation limit" ] } (1 row) ROLLBACK; -- $range BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1235 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1237 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1238 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1239 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1242 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 39, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1243 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 40, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1244 ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- matches nothing. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, 1234, 1234, 1235 ], "$lt": [ 2346, 1234, 1234, 1234, 1234, 1234, 1234 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lte": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1241" } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1236" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lte": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1236" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1241" } ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey": 1 } , "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } { "_id" : { "$numberInt" : "32" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1235" } ] } { "_id" : { "$numberInt" : "33" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1236" } ] } { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": { "$maxKey": 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "34" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1237" } ] } { "_id" : { "$numberInt" : "35" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1238" } ] } { "_id" : { "$numberInt" : "36" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1239" } ] } { "_id" : { "$numberInt" : "37" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1241" } ] } { "_id" : { "$numberInt" : "38" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1242" } ] } { "_id" : { "$numberInt" : "39" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1243" } ] } { "_id" : { "$numberInt" : "40" }, "ikey" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1244" } ] } (7 rows) ROLLBACK; --------------------------------------------------------------------- ---- DATA TYPE: Document --------------------------------------------------------------------- -- with 60 byte truncation limit, the real limit is 60-18 = 42 bytes. We can tolerate any entries over 42 bytes as long as they're also marked truncated. -- the base structural overhead for an array is 5 (bson Doc) + 2 (path) + 1 (typecode) + 5 (doc header) = 13 bytes -- each path takes some characters (string), 1 byte (type code) + path Value (variable) = 1+ bytes + valueLength -- empty doc (13 bytes) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : {} }'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 13 | { "$" : { }, "t" : false } 8 | { "" : true, "t" : false } (2 rows) -- single path (13 bytes + 4 bytes (path) + 1 byte type Code, 9 byte string, 1 for the \0, 4 byte string length) = 32 bytes (not truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : { "abc": "123456789" } }'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 32 | { "$" : { "abc" : "123456789" }, "t" : false } 8 | { "" : true, "t" : false } (2 rows) -- single path truncated on path - path should be truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('abcdefg', 10))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 58 | { "$" : { "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefga" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- single path truncated on path since path is greater than soft limit less than hard limit - path should not be truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('abcdefg', 6))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 57 | { "$" : { "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefg" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- value doesn't show up until we're under the soft limit. -- overhead: 13 bytes, 1 byte type code: for a 42 byte soft limit we're looking at a 28 byte path: from paths >= 29 bytes values Must be maxkey SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 41))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 56 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 30))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 45 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 29))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 44 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 43 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 27))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 56 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaa" : "123456789" }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- value gets truncated when it appears SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789123451234512345", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 43 | { "$" : { "aaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "%s", "b": 1, "c": 1 } }', repeat('a', 5), repeat('b', 40))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 57 | { "$" : { "aaaaa" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- truncation with object + string after works SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "a": { "b": 1 }, "%s": "123456789123451234512345", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 58 | { "$" : { "a" : { "b" : { "$numberInt" : "1" } }, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- sample docs from subsequent stages SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'::bson, 'ikey', false, true, true, 60) term; length | term --------------------------------------------------------------------- 52 | { "$" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- start fresh with documents DELETE FROM documentdb_data.documents_6401; -- $eq on something that's past truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": { "$maxKey": 1 } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } (3 rows) ROLLBACK; -- $gt/$lt/$gte/$gt/$range on something past truncation BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : { "userName": "myFirstUserName", "address1": { "$maxKey": 1 } }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho", "MaxField": { "$maxKey": 1 } }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "0th avenue, Rua Amalho", "apartment": "compartamento" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 39, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 40, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "2nd avenue, Rua Amalho", "apartment": "compartamento" }}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "35" }, "ikey" : { "userName" : "myFirstUserName", "address1" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "37" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "35" }, "ikey" : { "userName" : "myFirstUserName", "address1" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "37" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "35" }, "ikey" : { "userName" : "myFirstUserName", "address1" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "37" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "35" }, "ikey" : { "userName" : "myFirstUserName", "address1" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "37" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "38" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "0th avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "38" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "0th avenue, Rua Amalho", "apartment" : "compartamento" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "38" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "0th avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "38" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "0th avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "39" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "ikey" : { "userName" : "myFirstUserName", "address" : "2nd avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "33" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho" } } { "_id" : { "$numberInt" : "34" }, "ikey" : { "userName" : "myFirstUserName", "address" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "35" }, "ikey" : { "userName" : "myFirstUserName", "address1" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "36" }, "ikey" : { "userName" : "myFirstUserName", "address" : "0th avenue, Rua Amalho", "MaxField" : { "$maxKey" : 1 } } } { "_id" : { "$numberInt" : "37" }, "ikey" : { "userName" : "myFirstUserName", "address" : "1st avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "38" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "0th avenue, Rua Amalho", "apartment" : "compartamento" } } { "_id" : { "$numberInt" : "40" }, "ikey" : { "userName" : "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address" : "2nd avenue, Rua Amalho", "apartment" : "compartamento" } } (8 rows) ROLLBACK; -- finally shard_collection and ensure it's Truncation limit is still there. SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6401 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6401 | 6402 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6401 | 6403 | (ikey_1,"{ ""ikey"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,"{ ""enableLargeIndexKeys"" : { ""$numberInt"" : ""1"" } }") | t (2 rows) SELECT documentdb_api.shard_collection('db', 'index_truncation_tests', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) \d documentdb_data.documents_6401 Table "documentdb_data.documents_6401" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6401" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6404" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='60')) "documents_rum_index_6405" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='60')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = get_shard_key_value('{ "_id" : "hashed" }'::bson, 6401::bigint, document)) /* testing wildcard indexes */ SET documentdb.indexTermLimitOverride TO 100; SET documentdb.maxWildcardIndexKeySize TO 50; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests", "indexes": [ { "key": { "$**": 1 }, "name": "wkey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_6402 Table "documentdb_data.documents_6402" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6402" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6407" documentdb_rum (document bson_rum_single_path_ops (path='', iswildcard='true', tl='100', wkl='50')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6402'::bigint) /* should fail fue to maximum size exceeded */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{"_id": 1, "thiskeyislargerthanthemaximumallowedsizeof50characters" : "sample_value"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "Wildcard index key exceeded the maximum allowed size of 50." } ] } (1 row) /* should succeed due to maximum size not exceeded */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{"_id": 1, "ikey1" : "this is a string that does not violate the index term limit"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{ "_id": 2, "ikey2": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* query all and check if same index is used for both */ SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey1": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey1" : "this is a string that does not violate the index term limit" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey1": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6402_640040 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey1" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6402'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6402_640040 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey1" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey1" : "this is a" }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey2": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey2" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey2": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6402_640040 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey2" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6402'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6402_640040 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey2" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey2" : "this is a" }'::documentdb_core.bson) (12 rows) /* create collection again and test with single field wildcard. */ set documentdb.indexTermLimitOverride to 60; /* should create wildcard for single path */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests_single_field", "indexes": [ { "key": { "a.b.$**": 1 }, "name": "wkey_2", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_6403 Table "documentdb_data.documents_6403" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6403" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6409" documentdb_rum (document bson_rum_single_path_ops (path='a.b', iswildcard='true', tl='60')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6403'::bigint) /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{ "_id": 1, "a": { "b": { "c": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{ "_id": 2, "a": { "d": { "c": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{"_id": 3, "a" : { "b": { "c": [ 2345, 1234, 1234, 1234, 1234 ] } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* making sure the array is being truncated */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "a.b.c": [ 2345, 1234, 1234, 1234, 1234 ] }', '', true, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "3" } } 45 | { "a.b.c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } 18 | { "a.b.c.0" : { "$numberInt" : "2345" } } 16 | { "a.b.c" : { "$numberInt" : "2345" } } 18 | { "a.b.c.1" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.2" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.3" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.4" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (14 rows) /* making sure the wildcard index terms are being generated correctly for a truncated value */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 3, "a.b.c": [ 2345, 1234, 1234, 1234, 1234, 76, 85 ] }', '["a"]', false, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "3" } } 45 | { "a.b.c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } 18 | { "a.b.c.0" : { "$numberInt" : "2345" } } 16 | { "a.b.c" : { "$numberInt" : "2345" } } 18 | { "a.b.c.1" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.2" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.3" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.4" : { "$numberInt" : "1234" } } 16 | { "a.b.c" : { "$numberInt" : "1234" } } 18 | { "a.b.c.5" : { "$numberInt" : "76" } } 16 | { "a.b.c" : { "$numberInt" : "76" } } 18 | { "a.b.c.6" : { "$numberInt" : "85" } } 16 | { "a.b.c" : { "$numberInt" : "85" } } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (18 rows) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* making sure the document is being truncated */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }', '', true, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "4" } } 57 | { "a" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "12334141424124" } } } 51 | { "a.b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "12334141424124" } } 16 | { "a.b.c" : { "$numberInt" : "1" } } 16 | { "a.b.d" : { "$numberInt" : "2" } } 31 | { "a.b.e" : "12334141424124" } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (8 rows) /* making sure the wildcard index terms are being generated correctly for a truncated value */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }', '["a"]', false, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "4" } } 57 | { "a" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "12334141424124" } } } 51 | { "a.b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "12334141424124" } } 16 | { "a.b.c" : { "$numberInt" : "1" } } 16 | { "a.b.d" : { "$numberInt" : "2" } } 31 | { "a.b.e" : "12334141424124" } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } (8 rows) /* second element in array shouldn't appear as a term */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a": [{ "b": { "c": 1, "d": 2, "e": "1" } }, { "oi": 2} ], "c": 1}', '["a.0"]', false, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "6" } } 46 | { "a.0" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } } 40 | { "a.0.b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } 18 | { "a.0.b.c" : { "$numberInt" : "1" } } 18 | { "a.0.b.d" : { "$numberInt" : "2" } } 20 | { "a.0.b.e" : "1" } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } 12 | { "" : [ ] } (9 rows) /* term key "c" shouldn't appear as a term */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a": [{ "b": { "c": 1, "d": 2, "e": "1" } }, { "oi": 2} ], "c": 1}', '["a"]', false, true, false, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "6" } } 43 | { "a" : [ { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" } } } ] } 46 | { "a.0" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } } 40 | { "a.0.b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } 18 | { "a.0.b.c" : { "$numberInt" : "1" } } 18 | { "a.0.b.d" : { "$numberInt" : "2" } } 20 | { "a.0.b.e" : "1" } 44 | { "a" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } } 38 | { "a.b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "1" } } 16 | { "a.b.c" : { "$numberInt" : "1" } } 16 | { "a.b.d" : { "$numberInt" : "2" } } 18 | { "a.b.e" : "1" } 23 | { "a.1" : { "oi" : { "$numberInt" : "2" } } } 17 | { "a.1.oi" : { "$numberInt" : "2" } } 21 | { "a" : { "oi" : { "$numberInt" : "2" } } } 15 | { "a.oi" : { "$numberInt" : "2" } } 8 | { "" : true } 7 | { "" : { "$maxKey" : 1 } } 12 | { "" : [ ] } (19 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6403_640061 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b.c" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6403'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6403_640061 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b.c" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b.c" : "this is a" }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.d.c": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "d" : { "c" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.d.c": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6403_640061 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.d.c" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6403'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6403_640061 collection Output: document Recheck Cond: (collection.shard_key_value = '6403'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.d.c" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6403'::bigint) (13 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6403_640061 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b.c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<=) '{ "a.b.c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ] }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6403'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6403_640061 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b.c" : { "min" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ], "max" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ], "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b.c" : { "min" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ], "max" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ], "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": 1 }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" }, "e" : "12334141424124" } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6403_640061 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.b.c" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6403'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6403_640061 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.b.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.b.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$elemMatch": { "$eq": 2345 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "c" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ] } } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$elemMatch": { "$eq": 2345 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6403_640061 collection WHERE (documentdb_api_catalog.bson_dollar_elemmatch(document, '{ "a.b.c" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '6403'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6403_640061 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b.c" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b.c" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) (12 rows) /* create collection again and test with wildcard projection. */ set documentdb.indexTermLimitOverride to 60; /* should create wildcard index with projection */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests_wildcard_projection", "indexes": [ { "key": { "$**": 1 }, "name": "wkey_3", "enableLargeIndexKeys": true , "wildcardProjection": { "a": 1, "b": 1 } } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_6404 Table "documentdb_data.documents_6404" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6404" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6411" documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='60', wkl='50', pathspec='[ "a", "b" ]', isexclusion='false')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6404'::bigint) /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{ "_id": 1, "a": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{ "_id": 2, "b": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{"_id": 3, "a" : [ 2345, 1234, 1234, 1234, 1234 ], "b": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{"_id": 4, "a": { "l": { "j": 1 } }, "d": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c" : { "$numberInt" : "2" } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_3 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : "this is a" }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "b": { "$gt": "this is a" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "b" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "b" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (2 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "b": { "$gt": "this is a" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "b" : "this is a" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "b" : "this is a" }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_3 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "b" : "this is a" }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "b" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "a" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<=) '{ "a" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ] }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ], "max" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ], "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_3 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1230" } ], "max" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1240" } ], "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a.l.j": 1 }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "l" : { "j" : { "$numberInt" : "1" } } }, "d" : { "$numberInt" : "2" } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a.l.j": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.l.j" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.l.j" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_3 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a.l.j" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$elemMatch": { "$eq": 2345 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : [ { "$numberInt" : "2345" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" }, { "$numberInt" : "1234" } ], "b" : "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$elemMatch": { "$eq": 2345 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE (documentdb_api_catalog.bson_dollar_elemmatch(document, '{ "a" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) -> Bitmap Index Scan on wkey_3 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$eq" : { "$numberInt" : "2345" } } }'::documentdb_core.bson) (12 rows) /* should not use index when query uses key not specified in the projection */ SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "c": 1 }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "c": 1 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "c" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.shard_key_value = '6404'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6404'::bigint) (13 rows) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "d": 2 }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "l" : { "j" : { "$numberInt" : "1" } } }, "d" : { "$numberInt" : "2" } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "d": 2 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6404_640074 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "d" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6404'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_6404_640074 collection Output: document Recheck Cond: (collection.shard_key_value = '6404'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "d" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6404'::bigint) (13 rows) /* test that term truncation is enabled by default if user doesn't explicitly disable it. */ set documentdb.indexTermLimitOverride to 60; /* enableLargeIndexKeys should be false because it was explicitly set to false */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc1", "indexes": [ { "key": { "a.b": 1 }, "name": "key" } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6405 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6405 | 6412 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6405 | 6413 | (key,"{ ""a.b"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t (2 rows) /* enableLargeIndexKeys should be true because it was not explicitly set to false */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc2", "indexes": [ { "key": { "a.b": 1 }, "name": "key" } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6406 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6406 | 6414 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6406 | 6415 | (key,"{ ""a.b"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t (2 rows) /* enableLargeIndexKeys should be false because index does not support it (ttl index) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc3", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6407 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6407 | 6416 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6407 | 6417 | (ttl_index,"{ ""ttl"" : { ""$numberInt"" : ""1"" } }",,,,,1,5,,) | t (2 rows) /* enableLargeIndexKeys should be false because index does not support it (hashed) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc4", "indexes": [ { "key": { "a.b": "hashed" }, "name": "key" } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6408 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6408 | 6418 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6408 | 6419 | (key,"{ ""a.b"" : ""hashed"" }",,,,,2,,,) | t (2 rows) /* enableLargeIndexKeys should be false because index does not support it (text) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc5", "indexes": [ { "key": { "a.b": "text" }, "name": "key" } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6409 ORDER BY index_id; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6409 | 6420 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6409 | 6421 | (key,"{ ""a.b"" : ""text"" }",,,,,2,,,) | t (2 rows) -- Additional tests for bug where index term length optimization with '$' was not consistent, i.e., we would generate prefix like 'ikey' and '$.0' SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', false, true , true, 500) term; length | term --------------------------------------------------------------------- 29 | { "$" : [ "abcdefgh" ], "t" : false } 21 | { "$" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', false, true , true) term; length | term --------------------------------------------------------------------- 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', true, true , true, 500) term; length | term --------------------------------------------------------------------- 29 | { "$" : [ "abcdefgh" ], "t" : false } 23 | { "$.0" : "abcdefgh", "t" : false } 21 | { "$" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', true, true , true) term; length | term --------------------------------------------------------------------- 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 28 | { "ikey.a.0" : "abcdefgh", "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '', true, true , true, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "2" }, "t" : false } 40 | { "ikey" : { "a" : [ "abcdefgh" ] }, "t" : true } 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 28 | { "ikey.a.0" : "abcdefgh", "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '', true, true , true) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "2" }, "t" : false } 40 | { "ikey" : { "a" : [ "abcdefgh" ] }, "t" : false } 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 28 | { "ikey.a.0" : "abcdefgh", "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '["ikey"]', false, true , true, 60) term; length | term --------------------------------------------------------------------- 14 | { "_id" : { "$numberInt" : "2" }, "t" : false } 40 | { "ikey" : { "a" : [ "abcdefgh" ] }, "t" : true } 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 28 | { "ikey.a.0" : "abcdefgh", "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey', true, true, true, 500) term; length | term --------------------------------------------------------------------- 37 | { "$" : { "a" : [ "abcdefgh" ] }, "t" : false } 31 | { "$.a" : [ "abcdefgh" ], "t" : false } 25 | { "$.a.0" : "abcdefgh", "t" : false } 23 | { "$.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (5 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey', true, true, true) term; length | term --------------------------------------------------------------------- 40 | { "ikey" : { "a" : [ "abcdefgh" ] }, "t" : false } 34 | { "ikey.a" : [ "abcdefgh" ], "t" : false } 28 | { "ikey.a.0" : "abcdefgh", "t" : false } 26 | { "ikey.a" : "abcdefgh", "t" : false } 8 | { "" : true, "t" : false } (5 rows) SELECT FORMAT('{ "visits": [ "1" %s ] }', repeat(', { "estimatedTimeOfArrival": { "$date": 101010 }, "estimatedTimeOfDeparture": { "$date": 101010 }, "visitId": "someVisitIdValueString", "visitDocuments": { } } ', 5)) AS documentvalue \gset SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(:'documentvalue'::bson, '', true, true, true, 500) term; length | term --------------------------------------------------------------------- 486 | { "visits" : [ "1", { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$maxKey" : 1 } } ], "t" : true } 21 | { "visits.0" : "1", "t" : false } 19 | { "visits" : "1", "t" : false } 143 | { "visits.1" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 46 | { "visits.1.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.1.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 50 | { "visits.1.visitId" : "someVisitIdValueString", "t" : false } 35 | { "visits.1.visitDocuments" : { }, "t" : false } 141 | { "visits" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 44 | { "visits.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 46 | { "visits.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.visitId" : "someVisitIdValueString", "t" : false } 33 | { "visits.visitDocuments" : { }, "t" : false } 143 | { "visits.2" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 46 | { "visits.2.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.2.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 50 | { "visits.2.visitId" : "someVisitIdValueString", "t" : false } 35 | { "visits.2.visitDocuments" : { }, "t" : false } 141 | { "visits" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 44 | { "visits.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 46 | { "visits.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.visitId" : "someVisitIdValueString", "t" : false } 33 | { "visits.visitDocuments" : { }, "t" : false } 143 | { "visits.3" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 46 | { "visits.3.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.3.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 50 | { "visits.3.visitId" : "someVisitIdValueString", "t" : false } 35 | { "visits.3.visitDocuments" : { }, "t" : false } 141 | { "visits" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 44 | { "visits.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 46 | { "visits.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.visitId" : "someVisitIdValueString", "t" : false } 33 | { "visits.visitDocuments" : { }, "t" : false } 143 | { "visits.4" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 46 | { "visits.4.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.4.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 50 | { "visits.4.visitId" : "someVisitIdValueString", "t" : false } 35 | { "visits.4.visitDocuments" : { }, "t" : false } 141 | { "visits" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 44 | { "visits.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 46 | { "visits.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.visitId" : "someVisitIdValueString", "t" : false } 33 | { "visits.visitDocuments" : { }, "t" : false } 143 | { "visits.5" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 46 | { "visits.5.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.5.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 50 | { "visits.5.visitId" : "someVisitIdValueString", "t" : false } 35 | { "visits.5.visitDocuments" : { }, "t" : false } 141 | { "visits" : { "estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "visitId" : "someVisitIdValueString", "visitDocuments" : { } }, "t" : false } 44 | { "visits.estimatedTimeOfArrival" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 46 | { "visits.estimatedTimeOfDeparture" : { "$date" : { "$numberLong" : "101010" } }, "t" : false } 48 | { "visits.visitId" : "someVisitIdValueString", "t" : false } 33 | { "visits.visitDocuments" : { }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (56 rows) bson_index_truncation_nested_objects_tests.out000066400000000000000000075011631507310017400414340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1040000; SET documentdb.next_collection_id TO 10400; SET documentdb.next_collection_index_id TO 10400; -- Set configs to something reasonable for testing. set documentdb.indexTermLimitOverride to 50; --------------------------------------------------------------------- ---- Nested Array --------------------------------------------------------------------- -- gin_bson_get_single_path_generated_terms( -- document bson, -- path text, -- isWildcard bool, -- generateNotFoundTerm bool default false, -- addMetadata bool default false, -- termLength int) -- non wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 47 | { "$" : [ [ "abcdefghijklmonpqr" ] ], "t" : true } 47 | { "$" : [ "abcdefghijklmonpqrstuvwsyz" ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 28 | { "$" : [ [ { "$numberInt" : "1" } ] ], "t" : false } 20 | { "$" : [ { "$numberInt" : "1" } ], "t" : false } 8 | { "" : true, "t" : false } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 32 | { "$" : [ [ { "$numberLong" : "1234567891011" } ] ], "t" : true } 24 | { "$" : [ { "$numberLong" : "1234567891011" } ], "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 25 | { "$" : [ [ true ] ], "t" : false } 17 | { "$" : [ true ], "t" : false } 8 | { "" : true, "t" : false } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 33 | { "$" : [ "abcdefghijkl" ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 20 | { "$" : [ { "$numberInt" : "1" } ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 24 | { "$" : [ { "$numberLong" : "1234567891011" } ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 17 | { "$" : [ true ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) -- wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 47 | { "$" : [ [ "abcdefghijklmonpqr" ] ], "t" : true } 48 | { "$.0" : [ "abcdefghijklmonpqrstuvwsy" ], "t" : true } 43 | { "$.0.0" : "abcdefghijklmonpqrstuvwsyz", "t" : false } 47 | { "$" : [ "abcdefghijklmonpqrstuvwsyz" ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 28 | { "$" : [ [ { "$numberInt" : "1" } ] ], "t" : false } 22 | { "$.0" : [ { "$numberInt" : "1" } ], "t" : false } 16 | { "$.0.0" : { "$numberInt" : "1" }, "t" : false } 20 | { "$" : [ { "$numberInt" : "1" } ], "t" : false } 8 | { "" : true, "t" : false } 12 | { "" : [ ], "t" : false } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 32 | { "$" : [ [ { "$numberLong" : "1234567891011" } ] ], "t" : true } 26 | { "$.0" : [ { "$numberLong" : "1234567891011" } ], "t" : false } 28 | { "$.0.0" : { "$numberDecimal" : "1234567891011" }, "t" : false } 24 | { "$" : [ { "$numberLong" : "1234567891011" } ], "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 25 | { "$" : [ [ true ] ], "t" : false } 19 | { "$.0" : [ true ], "t" : false } 13 | { "$.0.0" : true, "t" : false } 17 | { "$" : [ true ], "t" : false } 8 | { "" : true, "t" : false } 12 | { "" : [ ], "t" : false } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 15 | { "$.0" : [ ], "t" : true } 35 | { "$.0.0" : "abcdefghijklmonpqr", "t" : true } 33 | { "$" : [ "abcdefghijkl" ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 15 | { "$.0" : [ ], "t" : true } 16 | { "$.0.0" : { "$numberInt" : "1" }, "t" : false } 20 | { "$" : [ { "$numberInt" : "1" } ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 15 | { "$.0" : [ ], "t" : true } 28 | { "$.0.0" : { "$numberDecimal" : "1234567891011" }, "t" : false } 24 | { "$" : [ { "$numberLong" : "1234567891011" } ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : [ [ ] ], "t" : true } 15 | { "$.0" : [ ], "t" : true } 13 | { "$.0.0" : true, "t" : false } 17 | { "$" : [ true ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (7 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 47 | { "$" : [ [ "abcdefghijklmonpqr" ] ], "t" : true } 47 | { "$" : [ "abcdefghijklmonpqrstuvwsyz" ], "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (4 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested_array", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now we have an index with truncation enabled and 50 chars. \d documentdb_data.documents_10400; Table "documentdb_data.documents_10400" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_10400" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_10401" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='50')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '10400'::bigint) -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 1, "ikey": [["abcdefghijklmonpqrstuvwsyz"]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 2, "ikey": [[1]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 3, "ikey": [[{ "$numberDecimal" : "1234567891011" }]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 4, "ikey": [[true]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 5, "ikey": [[[]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 6, "ikey": [[{}]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[1]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[false]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } (1 row) -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 7, "ikey": [[["abcdefghijklmonpqrstuvwsyz"]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 8, "ikey": [[[1]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 9, "ikey": [[[{ "$numberDecimal" : "1234567891011" }]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 10, "ikey": [[[true]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 11, "ikey": [[[[]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 12, "ikey": [[[{}]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[1]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ [ [ { "$numberDecimal" : "1234567891011" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[{ "$numberDecimal" : "1234567891011" }]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[false]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[[]]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } (2 rows) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 13, "ikey": "abcdefghijklmonpqrstuvwsyz" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 14, "ikey": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 15, "ikey": { "$numberDecimal" : "1234567891011" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 16, "ikey": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 17, "ikey": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 18, "ikey": {} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": { "$numberDecimal" : "1234567891011" } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": false } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "16" }, "ikey" : true } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ [ [ { "$numberDecimal" : "1234567891011" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$in": [1, true] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$nin": [1, true] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ [ [ { "$numberDecimal" : "1234567891011" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (16 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [1, true] } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [[[1]], [[true]]] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [[[1]], [[true]]], "$gt": [[{ "$numberDecimal" : "1234567891011" }]] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$all": [[[1]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$all": [[[[]]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$ne": { "$numberDecimal" : "1234567891011" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ [ [ { "$numberDecimal" : "1234567891011" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (17 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$in": [[[1]], [[true]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$nin": [[[1]], [[true]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "3" }, "ikey" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "9" }, "ikey" : [ [ [ { "$numberDecimal" : "1234567891011" } ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (14 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$ne": [[{ "$numberDecimal" : "1234567891011" }]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } { "_id" : { "$numberInt" : "2" }, "ikey" : [ [ { "$numberInt" : "1" } ] ] } { "_id" : { "$numberInt" : "4" }, "ikey" : [ [ true ] ] } { "_id" : { "$numberInt" : "5" }, "ikey" : [ [ [ ] ] ] } { "_id" : { "$numberInt" : "6" }, "ikey" : [ [ { } ] ] } { "_id" : { "$numberInt" : "7" }, "ikey" : [ [ [ "abcdefghijklmonpqrstuvwsyz" ] ] ] } { "_id" : { "$numberInt" : "8" }, "ikey" : [ [ [ { "$numberInt" : "1" } ] ] ] } { "_id" : { "$numberInt" : "10" }, "ikey" : [ [ [ true ] ] ] } { "_id" : { "$numberInt" : "11" }, "ikey" : [ [ [ [ ] ] ] ] } { "_id" : { "$numberInt" : "12" }, "ikey" : [ [ [ { } ] ] ] } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (16 rows) --------------------------------------------------------------------- ---- Nested Documents --------------------------------------------------------------------- -- gin_bson_get_single_path_generated_terms( -- document bson, -- path text, -- isWildcard bool, -- generateNotFoundTerm bool default false, -- addMetadata bool default false, -- termLength int) -- non wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 46 | { "$" : { "a" : [ "abcdefghijklmonpq" ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 28 | { "$" : { "a" : [ { "$numberInt" : "1" } ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 32 | { "$" : { "a" : [ { "$numberLong" : "1234567891011" } ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 25 | { "$" : { "a" : [ true ] }, "t" : false } 8 | { "" : true, "t" : false } (2 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', false, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) -- wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 46 | { "$" : { "a" : [ "abcdefghijklmonpq" ] }, "t" : true } 48 | { "$.a" : [ "abcdefghijklmonpqrstuvwsy" ], "t" : true } 43 | { "$.a.0" : "abcdefghijklmonpqrstuvwsyz", "t" : false } 41 | { "$.a" : "abcdefghijklmonpqrstuvwsyz", "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 28 | { "$" : { "a" : [ { "$numberInt" : "1" } ] }, "t" : true } 22 | { "$.a" : [ { "$numberInt" : "1" } ], "t" : false } 16 | { "$.a.0" : { "$numberInt" : "1" }, "t" : false } 14 | { "$.a" : { "$numberInt" : "1" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]]}}', 'ikey', true, true, true, 50) term; ERROR: invalid input syntax JSON for BSON: Code: '1', Message 'Got parse error at "]", position 68: "BRACKET_MISMATCH"' LINE 1: ..._helpers.gin_bson_get_single_path_generated_terms('{"_id": 3... ^ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', true, true, true, 50) term; length | term --------------------------------------------------------------------- 25 | { "$" : { "a" : [ true ] }, "t" : false } 19 | { "$.a" : [ true ], "t" : false } 13 | { "$.a.0" : true, "t" : false } 11 | { "$.a" : true, "t" : false } 8 | { "" : true, "t" : false } (5 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 15 | { "$.a" : [ ], "t" : true } 35 | { "$.a.0" : "abcdefghijklmonpqr", "t" : true } 35 | { "$.a" : "abcdefghijklmonpqrst", "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 15 | { "$.a" : [ ], "t" : true } 16 | { "$.a.0" : { "$numberInt" : "1" }, "t" : false } 14 | { "$.a" : { "$numberInt" : "1" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 15 | { "$.a" : [ ], "t" : true } 28 | { "$.a.0" : { "$numberDecimal" : "1234567891011" }, "t" : false } 26 | { "$.a" : { "$numberDecimal" : "1234567891011" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', true, true, true, 35) term; length | term --------------------------------------------------------------------- 21 | { "$" : { "a" : [ ] }, "t" : true } 15 | { "$.a" : [ ], "t" : true } 13 | { "$.a.0" : true, "t" : false } 11 | { "$.a" : true, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (6 rows) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 50) term; length | term --------------------------------------------------------------------- 46 | { "$" : { "a" : [ "abcdefghijklmonpq" ] }, "t" : true } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } (3 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested_documents", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- now we have an index with truncation enabled and 100 chars. \d documentdb_data.documents_10401; Table "documentdb_data.documents_10401" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_10401" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_10403" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='50')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '10401'::bigint) -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 1, "ikey": { "a" : ["abcdefghijklmonpqrstuvwsyz"]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 2, "ikey": { "a" : [1]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 3, "ikey": { "a" : [{ "$numberDecimal" : "1234567891011" }]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 4, "ikey": { "a" : [true]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 5, "ikey": { "a" : [[]}] }'); ERROR: invalid input syntax JSON for BSON: Code: '1', Message 'Got parse error at "}", position 31: "BRACKET_MISMATCH"' LINE 1: ...('db', 'index_truncation_tests_nested_documents', '{ "_id": ... ^ SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 6, "ikey": { "a" : [{}]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [1] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "a" : [ { "$numberDecimal" : "1234567891011" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [false] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } (1 row) -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 7, "ikey": { "a" : [["abcdefghijklmonpqrstuvwsyz"]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 8, "ikey": { "a" : [[1]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 9, "ikey": { "a" : [[{ "$numberDecimal" : "1234567891011" }]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 10, "ikey": { "a" : [[true]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 11, "ikey": { "a" : [[[]]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 12, "ikey": { "a" : [[{}]]} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[1]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "a" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[{ "$numberDecimal" : "1234567891011" }]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[false]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[[]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } (2 rows) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 13, "ikey": "abcdefghijklmonpqrstuvwsyz" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 14, "ikey": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 15, "ikey": { "$numberDecimal" : "1234567891011" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 16, "ikey": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 17, "ikey": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 18, "ikey": {} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": 1 } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "ikey" : { "a" : [ { "$numberDecimal" : "1234567891011" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": { "$numberDecimal" : "1234567891011" } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": false } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "a" : [ { "$numberDecimal" : "1234567891011" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "a" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } (11 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$in": [1, true] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$nin": [1, true] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "a" : [ { "$numberDecimal" : "1234567891011" } ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "a" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (15 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [1, true] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], [true]] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [1, "abcdefghijklmonpqrstuvwsyz"] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], ["abcdefghijklmonpqrstuvwsyz"]] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], [true]], "$gt": [{ "$numberDecimal" : "1234567891011" }] } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$all": [[1]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$all": [[[]]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$ne": { "$numberDecimal" : "1234567891011" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "a" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (16 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$in": [[1], [true]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$nin": [[1], [true]] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "a" : [ { "$numberDecimal" : "1234567891011" } ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "a" : [ [ { "$numberDecimal" : "1234567891011" } ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (13 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$ne": [{ "$numberDecimal" : "1234567891011" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "a" : [ "abcdefghijklmonpqrstuvwsyz" ] } } { "_id" : { "$numberInt" : "2" }, "ikey" : { "a" : [ { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "a" : [ true ] } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "a" : [ { } ] } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "a" : [ [ "abcdefghijklmonpqrstuvwsyz" ] ] } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "a" : [ [ { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "a" : [ [ true ] ] } } { "_id" : { "$numberInt" : "11" }, "ikey" : { "a" : [ [ [ ] ] ] } } { "_id" : { "$numberInt" : "12" }, "ikey" : { "a" : [ [ { } ] ] } } { "_id" : { "$numberInt" : "13" }, "ikey" : "abcdefghijklmonpqrstuvwsyz" } { "_id" : { "$numberInt" : "14" }, "ikey" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "15" }, "ikey" : { "$numberDecimal" : "1234567891011" } } { "_id" : { "$numberInt" : "16" }, "ikey" : true } { "_id" : { "$numberInt" : "17" }, "ikey" : [ ] } { "_id" : { "$numberInt" : "18" }, "ikey" : { } } (15 rows) -- term generation tests set documentdb.indexTermLimitOverride to 100; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 19, "ikey": [[[[[[[[[[1]]]]]]]]]] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 20, "ikey": [[[[[[[[[[true]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 21, "ikey": [[[[[[[[[[{ "$numberDecimal" : "1234567891011" }]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 22, "ikey": [[[[[[[[[[{ "$maxKey": 1 }]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 23, "ikey": [[[[[[[[[[{ "$minKey": 1 }]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 24, "ikey": [[[[[[[[[[{ "$numberDouble" : "1234567891011" }]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 25, "ikey": [[[[[[[[[[ "abcdefghijklmopqrstuvwxyz" ]]]]]]]]]] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 115) term, document-> '_id' as did from documentdb_data.documents_10402) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "19" } } | 92 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberInt" : "1" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "19" } } | 84 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberInt" : "1" } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "19" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "19" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "20" } } | 89 | { "$" : [ [ [ [ [ [ [ [ [ [ true ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "20" } } | 81 | { "$" : [ [ [ [ [ [ [ [ [ true ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "20" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "20" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "21" } } | 96 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "21" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "21" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "21" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "22" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$maxKey" : 1 } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "22" } } | 80 | { "$" : [ [ [ [ [ [ [ [ [ { "$maxKey" : 1 } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "22" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "22" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "23" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$minKey" : 1 } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "23" } } | 80 | { "$" : [ [ [ [ [ [ [ [ [ { "$minKey" : 1 } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "23" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "23" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "24" } } | 96 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "24" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "24" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "24" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "25" } } | 104 | { "$" : [ [ [ [ [ [ [ [ [ [ "abcdefghijk" ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "25" } } | 105 | { "$" : [ [ [ [ [ [ [ [ [ "abcdefghijklmopqrstu" ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "25" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "25" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (28 rows) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 120) term, document-> '_id' as did from documentdb_data.documents_10402) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "19" } } | 92 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberInt" : "1" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "19" } } | 84 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberInt" : "1" } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "19" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "19" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "20" } } | 89 | { "$" : [ [ [ [ [ [ [ [ [ [ true ] ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "20" } } | 81 | { "$" : [ [ [ [ [ [ [ [ [ true ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "20" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "21" } } | 96 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "21" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "21" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "21" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "22" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$maxKey" : 1 } ] ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "22" } } | 80 | { "$" : [ [ [ [ [ [ [ [ [ { "$maxKey" : 1 } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "22" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "23" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$minKey" : 1 } ] ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "23" } } | 80 | { "$" : [ [ [ [ [ [ [ [ [ { "$minKey" : 1 } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "23" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "24" } } | 96 | { "$" : [ [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "24" } } | 88 | { "$" : [ [ [ [ [ [ [ [ [ { "$numberLong" : "1234567891011" } ] ] ] ] ] ] ] ] ], "t" : false } { "" : { "$numberInt" : "24" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "24" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "25" } } | 109 | { "$" : [ [ [ [ [ [ [ [ [ [ "abcdefghijklmopq" ] ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "25" } } | 110 | { "$" : [ [ [ [ [ [ [ [ [ "abcdefghijklmopqrstuvwxyz" ] ] ] ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "25" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "25" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (25 rows) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 26, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": 1}}}}}}}}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 27, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": true}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 28, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$maxKey": 1 }}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 29, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$minKey": 1 }}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 30, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$numberDouble" : "1234567891011" }}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 31, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$numberDecimal" : "1234567891011" }}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 32, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": "abcdefghijklmopqrstuvwxyz"}}}}}}}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_10403) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | 76 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberInt" : "1" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "26" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "27" } } | 73 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : true } } } } } } } }, "t" : false } { "" : { "$numberInt" : "27" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "28" } } | 72 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$maxKey" : 1 } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "28" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "29" } } | 72 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$minKey" : 1 } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "29" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "30" } } | 80 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberLong" : "1234567891011" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "30" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "31" } } | 80 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberLong" : "1234567891011" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "31" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "32" } } | 97 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : "abcdefghijklmopqrstu" } } } } } } } }, "t" : true } { "" : { "$numberInt" : "32" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "32" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (15 rows) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 105) term, document-> '_id' as did from documentdb_data.documents_10403) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | 76 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberInt" : "1" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "26" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "27" } } | 73 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : true } } } } } } } }, "t" : false } { "" : { "$numberInt" : "27" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "28" } } | 72 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$maxKey" : 1 } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "28" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "29" } } | 72 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$minKey" : 1 } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "29" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "30" } } | 80 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberLong" : "1234567891011" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "30" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "31" } } | 80 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : { "$numberLong" : "1234567891011" } } } } } } } } }, "t" : false } { "" : { "$numberInt" : "31" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "32" } } | 102 | { "$" : { "a" : { "b" : { "c" : { "d" : { "e" : { "f" : { "g" : { "h" : "abcdefghijklmopqrstuvwxyz" } } } } } } } }, "t" : true } { "" : { "$numberInt" : "32" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "32" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (15 rows) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 33, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": 1}]}]}]}]}]}]}]}]}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 34, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": true}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 35, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$numberDecimal" : "1234567891011" }}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 36, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$maxKey": 1 }}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 37, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$minKey": 1 }}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 38, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$numberDouble" : "1234567891011" }}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 39, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": "abcdefghijklmopqrstuvwxyz"}]}]}]}]}]}]}]}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 165) term, document-> '_id' as did from documentdb_data.documents_10404) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } | 140 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "33" } } | 132 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "33" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "33" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "34" } } | 137 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 129 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "35" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "35" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "35" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "35" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "36" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "36" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "37" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "37" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "38" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "38" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "38" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "38" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "39" } } | 156 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmop" } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 155 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvw" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "39" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "39" } } | 12 | { "" : [ ], "t" : false } (32 rows) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 170) term, document-> '_id' as did from documentdb_data.documents_10404) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } | 140 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 132 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "33" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "34" } } | 137 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 129 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "35" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "35" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "35" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "35" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "36" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "36" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "37" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "37" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "38" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "38" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "38" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "38" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "39" } } | 161 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstu" } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 158 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "39" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "39" } } | 12 | { "" : [ ], "t" : false } (31 rows) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', true, true, true, 165) term, document-> '_id' as did from documentdb_data.documents_10404) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } | 140 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "33" } } | 134 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 128 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 122 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 116 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 110 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 104 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 98 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 120 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 114 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 132 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 126 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 120 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 114 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 118 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 112 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 104 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 98 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 28 | { "$.a.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "33" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "33" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "34" } } | 137 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 131 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 125 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 119 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 113 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 107 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 101 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 95 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.0.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 117 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 111 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.0.a.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 129 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 123 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 117 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 111 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.0.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 115 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 109 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 101 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 95 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 25 | { "$.a.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "35" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "35" } } | 138 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "35" } } | 132 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 126 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 120 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 114 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 108 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 102 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 124 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 118 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 130 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 124 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 118 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 122 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 116 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 108 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 102 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 38 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "35" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "35" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "36" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 130 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 124 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 118 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 112 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 106 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 100 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 94 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 116 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 110 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.0.a.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 122 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 116 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 110 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.0.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 114 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 108 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 100 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 94 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 24 | { "$.a.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "36" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "37" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 130 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 124 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 118 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 112 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 106 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 100 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 94 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 116 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 110 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.0.a.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 122 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 116 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 110 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.0.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 114 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 108 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 100 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 94 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 24 | { "$.a.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "37" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "38" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "38" } } | 138 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "38" } } | 132 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 126 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 120 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 114 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 108 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 102 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 124 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 118 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 130 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 124 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 118 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 122 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 116 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 108 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 102 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 32 | { "$.a.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "38" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "38" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "39" } } | 156 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmop" } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 155 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstu" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 154 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 148 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 142 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 136 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 130 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 124 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 134 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.0.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 146 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 140 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 134 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.0.a.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 155 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvw" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 152 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 146 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 140 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 134 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.0.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 144 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 138 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 130 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 124 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 54 | { "$.a.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "39" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "39" } } | 12 | { "" : [ ], "t" : false } (7165 rows) SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', true, true, true, 170) term, document-> '_id' as did from documentdb_data.documents_10404) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "33" } } | 140 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 134 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 128 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 122 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 116 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 110 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 104 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 98 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 120 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 114 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 132 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 126 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 120 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 114 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 108 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 102 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 96 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 118 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 112 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 106 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 100 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 94 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 88 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 82 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 104 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 98 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 92 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 86 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 80 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 74 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 68 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 90 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 84 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 78 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 72 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 66 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 60 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 54 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 76 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 70 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 64 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 58 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 52 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 46 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 40 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 62 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 56 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberInt" : "1" } } ] } ], "t" : false } { "" : { "$numberInt" : "33" } } | 50 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 44 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 38 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 32 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 48 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberInt" : "1" } } ] }, "t" : false } { "" : { "$numberInt" : "33" } } | 42 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberInt" : "1" } } ], "t" : false } { "" : { "$numberInt" : "33" } } | 36 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 30 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 34 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberInt" : "1" } }, "t" : false } { "" : { "$numberInt" : "33" } } | 28 | { "$.a.b.c.d.e.f.g.h" : { "$numberInt" : "1" }, "t" : false } { "" : { "$numberInt" : "33" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "33" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "34" } } | 137 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 131 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 125 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 119 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 113 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 107 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 101 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 95 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.0.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.0.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 117 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 111 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.0.a.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.0.a.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.0.a.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.0.a.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 129 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 123 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 117 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 111 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 105 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 99 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 93 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.0.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.0.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.0.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.0.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 115 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 109 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 103 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 97 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 91 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 85 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 79 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.0.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.0.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.0.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.0.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 101 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 95 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 89 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 83 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 77 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 71 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 65 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.0.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.0.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.0.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.0.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 87 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 81 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 75 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 69 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 63 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 57 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 51 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.0.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.0.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.0.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.0.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 73 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 67 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : true } ] } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 61 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 55 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 49 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 43 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 37 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.e.0.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.0.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.0.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.0.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.0.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 59 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : true } ] } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 53 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : true } ] } ], "t" : false } { "" : { "$numberInt" : "34" } } | 47 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 41 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 35 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 29 | { "$.a.b.c.d.e.f.0.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.f.0.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.f.0.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 45 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : true } ] }, "t" : false } { "" : { "$numberInt" : "34" } } | 39 | { "$.a.b.c.d.e.f.g" : [ { "h" : true } ], "t" : false } { "" : { "$numberInt" : "34" } } | 33 | { "$.a.b.c.d.e.f.g.0" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 27 | { "$.a.b.c.d.e.f.g.0.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 31 | { "$.a.b.c.d.e.f.g" : { "h" : true }, "t" : false } { "" : { "$numberInt" : "34" } } | 25 | { "$.a.b.c.d.e.f.g.h" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "34" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "35" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "35" } } | 138 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 132 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 126 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 120 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 114 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 108 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 102 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 124 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 118 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 130 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 124 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 118 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 112 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 106 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 100 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 122 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 116 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 110 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 104 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 98 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 92 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 86 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 108 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 102 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 96 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 90 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 84 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 78 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 72 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 94 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 88 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 82 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 76 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 70 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 64 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 58 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 80 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 74 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 68 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 62 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 56 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 50 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 66 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 60 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "35" } } | 54 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 48 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 44 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 52 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "35" } } | 46 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 42 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 38 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "35" } } | 40 | { "$.a.b.c.d.e.f.g.h" : { "$numberDecimal" : "1234567891011" }, "t" : false } { "" : { "$numberInt" : "35" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "35" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "35" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "36" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 130 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 124 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 118 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 112 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 106 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 100 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 94 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 116 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 110 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.0.a.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 122 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 116 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 110 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 104 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 98 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 92 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.0.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 114 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 108 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 102 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 96 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 90 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 84 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 78 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.0.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 100 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 94 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 88 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 82 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 76 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 70 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 64 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.0.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 86 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 80 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 74 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 68 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 62 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 56 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 50 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.0.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 72 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 66 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 60 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 54 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 48 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.0.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 58 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 52 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$maxKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "36" } } | 46 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 40 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 34 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 28 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.f.0.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 44 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$maxKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "36" } } | 38 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$maxKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "36" } } | 32 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 26 | { "$.a.b.c.d.e.f.g.0.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 30 | { "$.a.b.c.d.e.f.g" : { "h" : { "$maxKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "36" } } | 24 | { "$.a.b.c.d.e.f.g.h" : { "$maxKey" : 1 }, "t" : false } { "" : { "$numberInt" : "36" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "36" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "37" } } | 136 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 130 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 124 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 118 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 112 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 106 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 100 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 94 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 116 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 110 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.0.a.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 128 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 122 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 116 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 110 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 104 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 98 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 92 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.0.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 114 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 108 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 102 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 96 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 90 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 84 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 78 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.0.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 100 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 94 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 88 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 82 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 76 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 70 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 64 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.0.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 86 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 80 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 74 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 68 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 62 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 56 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 50 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.0.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 72 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 66 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 60 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 54 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 48 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.0.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 58 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 52 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$minKey" : 1 } } ] } ], "t" : false } { "" : { "$numberInt" : "37" } } | 46 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 40 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 34 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 28 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.f.0.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 44 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$minKey" : 1 } } ] }, "t" : false } { "" : { "$numberInt" : "37" } } | 38 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$minKey" : 1 } } ], "t" : false } { "" : { "$numberInt" : "37" } } | 32 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 26 | { "$.a.b.c.d.e.f.g.0.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 30 | { "$.a.b.c.d.e.f.g" : { "h" : { "$minKey" : 1 } }, "t" : false } { "" : { "$numberInt" : "37" } } | 24 | { "$.a.b.c.d.e.f.g.h" : { "$minKey" : 1 }, "t" : false } { "" : { "$numberInt" : "37" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "37" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "38" } } | 144 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "38" } } | 138 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 132 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 126 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 120 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 114 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 108 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 102 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.0.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.0.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 124 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 118 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.0.a.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.0.a.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.0.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.0.a.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 136 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 130 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 124 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 118 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 112 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 106 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 100 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.0.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.0.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.0.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.0.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 122 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 116 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 110 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 104 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 98 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 92 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 86 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.0.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.0.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.0.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.0.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 108 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 102 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 96 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 90 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 84 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 78 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 72 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.0.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.0.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.0.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.0.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 94 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 88 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 82 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 76 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 70 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 64 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 58 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.0.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.0.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.0.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.0.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 80 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 74 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 68 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 62 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 56 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 50 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 44 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.e.0.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.0.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.0.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.0.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.0.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 66 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 60 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] } ], "t" : false } { "" : { "$numberInt" : "38" } } | 54 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 48 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 42 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 36 | { "$.a.b.c.d.e.f.0.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.f.0.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.f.0.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 52 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : { "$numberLong" : "1234567891011" } } ] }, "t" : false } { "" : { "$numberInt" : "38" } } | 46 | { "$.a.b.c.d.e.f.g" : [ { "h" : { "$numberLong" : "1234567891011" } } ], "t" : false } { "" : { "$numberInt" : "38" } } | 40 | { "$.a.b.c.d.e.f.g.0" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 34 | { "$.a.b.c.d.e.f.g.0.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 38 | { "$.a.b.c.d.e.f.g" : { "h" : { "$numberLong" : "1234567891011" } }, "t" : false } { "" : { "$numberInt" : "38" } } | 32 | { "$.a.b.c.d.e.f.g.h" : { "$numberDouble" : "1234567891011.0" }, "t" : false } { "" : { "$numberInt" : "38" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "38" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "38" } } | 12 | { "" : [ ], "t" : false } { "" : { "$numberInt" : "39" } } | 161 | { "$" : [ { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstu" } ] } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 160 | { "$.0" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 154 | { "$.0.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 148 | { "$.0.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 142 | { "$.0.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 136 | { "$.0.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 130 | { "$.0.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 124 | { "$.0.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.0.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.0.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 134 | { "$.0.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.0.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.0.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.0.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.0.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.0.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.0.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.0.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.0.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.0.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.0.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.0.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.0.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 146 | { "$.0.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 140 | { "$.0.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 134 | { "$.0.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.0.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.0.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.0.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.0.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.0.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.0.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.0.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.0.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.0.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.0.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.0.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.0.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.0.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.0.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.0.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.0.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.0.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.0.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.0.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.0.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.0.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.0.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.0.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.0.a.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.0.a.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.0.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.0.a.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.0.a.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.0.a.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.0.a.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.0.a.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.0.a.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.0.a.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.0.a.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.0.a.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.0.a.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.0.a.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 158 | { "$" : { "a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 152 | { "$.a" : [ { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] } ], "t" : true } { "" : { "$numberInt" : "39" } } | 146 | { "$.a.0" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 140 | { "$.a.0.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 134 | { "$.a.0.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 128 | { "$.a.0.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 122 | { "$.a.0.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.a.0.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.a.0.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.0.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.0.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.0.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.0.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.a.0.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.a.0.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.0.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.0.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.0.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.0.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.0.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.0.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.0.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.0.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.0.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.0.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.0.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.0.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.0.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.0.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.0.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.0.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.0.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.0.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.0.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.0.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.0.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.0.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.0.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.0.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.0.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.0.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.0.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.0.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.0.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.0.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.0.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 144 | { "$.a" : { "b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ] }, "t" : true } { "" : { "$numberInt" : "39" } } | 138 | { "$.a.b" : [ { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 132 | { "$.a.b.0" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 126 | { "$.a.b.0.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 120 | { "$.a.b.0.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 114 | { "$.a.b.0.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 108 | { "$.a.b.0.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.b.0.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.b.0.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.0.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.0.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.0.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.0.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.b.0.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.b.0.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.0.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.0.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.0.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.0.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.0.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.0.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.0.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.0.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.0.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.0.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.0.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.0.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.0.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.0.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.0.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.0.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.0.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.0.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.0.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.0.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.0.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.0.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.0.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.0.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 130 | { "$.a.b" : { "c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 124 | { "$.a.b.c" : [ { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 118 | { "$.a.b.c.0" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 112 | { "$.a.b.c.0.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 106 | { "$.a.b.c.0.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 100 | { "$.a.b.c.0.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 94 | { "$.a.b.c.0.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.c.0.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.c.0.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.0.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.0.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.0.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.0.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.c.0.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.c.0.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.0.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.0.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.0.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.0.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.0.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.0.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.0.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.0.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.0.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.0.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.0.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.0.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.0.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.0.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.0.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.0.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.0.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 116 | { "$.a.b.c" : { "d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 110 | { "$.a.b.c.d" : [ { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 104 | { "$.a.b.c.d.0" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 98 | { "$.a.b.c.d.0.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 92 | { "$.a.b.c.d.0.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 86 | { "$.a.b.c.d.0.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 80 | { "$.a.b.c.d.0.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.d.0.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.d.0.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.0.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.0.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.0.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.d.0.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.d.0.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.0.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.0.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.0.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.0.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.0.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.0.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.0.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.0.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.0.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.0.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 102 | { "$.a.b.c.d" : { "e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 96 | { "$.a.b.c.d.e" : [ { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 90 | { "$.a.b.c.d.e.0" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 84 | { "$.a.b.c.d.e.0.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 78 | { "$.a.b.c.d.e.0.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 72 | { "$.a.b.c.d.e.0.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 66 | { "$.a.b.c.d.e.0.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.e.0.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.0.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.0.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.e.0.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.e.0.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.0.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.0.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.0.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.0.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 88 | { "$.a.b.c.d.e" : { "f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 82 | { "$.a.b.c.d.e.f" : [ { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] } ], "t" : false } { "" : { "$numberInt" : "39" } } | 76 | { "$.a.b.c.d.e.f.0" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 70 | { "$.a.b.c.d.e.f.0.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 64 | { "$.a.b.c.d.e.f.0.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 58 | { "$.a.b.c.d.e.f.0.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.f.0.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.f.0.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 74 | { "$.a.b.c.d.e.f" : { "g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ] }, "t" : false } { "" : { "$numberInt" : "39" } } | 68 | { "$.a.b.c.d.e.f.g" : [ { "h" : "abcdefghijklmopqrstuvwxyz" } ], "t" : false } { "" : { "$numberInt" : "39" } } | 62 | { "$.a.b.c.d.e.f.g.0" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 56 | { "$.a.b.c.d.e.f.g.0.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 60 | { "$.a.b.c.d.e.f.g" : { "h" : "abcdefghijklmopqrstuvwxyz" }, "t" : false } { "" : { "$numberInt" : "39" } } | 54 | { "$.a.b.c.d.e.f.g.h" : "abcdefghijklmopqrstuvwxyz", "t" : false } { "" : { "$numberInt" : "39" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "39" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "39" } } | 12 | { "" : [ ], "t" : false } (7164 rows) -- specific tests set documentdb.indexTermLimitOverride to 200; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex", "enableLargeIndexKeys": true } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'index_truncation_tests_nested'); drop_primary_key --------------------------------------------------------------------- (1 row) -- 1. does not fail. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested','{ "_id" : 1, "data": { "$binary": { "base64": "ewogICAgIl9pZCI6ICI2NzY5ZGI2NmExZGIyMDA4NTczOTdiNjAiLAogICAgImluZGV4IjogMCwKICAgICJndWlkIjogIjMzZjk1N2QwLWU0M2MtNDYyNi1iOGJjLTFkODE0ODE3MmZkNyIsCiAgICAiaXNBY3RpdmUiOiB0cnVlLAogICAgImJhbGFuY2UiOiAiJDMsOTMwLjI4IiwKICAgICJwaWN0dXJlIjogImh0dHA6Ly9wbGFjZWhvbGQuaXQvMzJ4MzIiLAogICAgImFnZSI6IDI3LAogICAgImV5ZUNvbG9yIjogImdyZWVuIiwKICAgICJuYW1lIjogIkxpbGEgVmFsZW56dWVsYSIsCiAgICAiZ2VuZGVyIjogImZlbWFsZSIsCiAgICAiY29tcGFueSI6ICJBUFBMSURFQyIsCiAgICAiZW1haWwiOiAibGlsYXZhbGVuenVlbGFAYXBwbGlkZWMuY29tIiwKICAgICJwaG9uZSI6ICIrMSAoODIyKSA1NDItMjQ1MCIsCiAgICAiYWRkcmVzcyI6ICI2NjcgT3hmb3JkIFdhbGssIENhc2h0b3duLCBBcmthbnNhcywgMjYyMyIsCiAgICAiYWJvdXQiOiAiSW4gYWxpcXVpcCBub24gZXN0IHNpdCBlc3QgTG9yZW0gcXVpIG9jY2FlY2F0IGZ1Z2lhdCBleC4gRG9sb3IgbGFib3JlIG1vbGxpdCBjb25zZXF1YXQgaXBzdW0uIFF1aXMgY29uc2VxdWF0IGRlc2VydW50IGVpdXNtb2QgcHJvaWRlbnQgZHVpcyBvY2NhZWNhdCBldSBlbGl0IG5vbiBhZCBleCBkZXNlcnVudCBwcm9pZGVudCBMb3JlbS4gSWQgbW9sbGl0IGNpbGx1bSBpcHN1bSB2b2x1cHRhdGUgYXV0ZSBsYWJvcmlzIGVzc2UgYW5pbS5cclxuIiwKICAgICJyZWdpc3RlcmVkIjogIjIwMjAtMDktMDRUMDM6MDA6MTggKzAzOjAwIiwKICAgICJsYXRpdHVkZSI6IDguMTI4MTI0LAogICAgImxvbmdpdHVkZSI6IC0zNy4zMjY4MDMsCiAgICAidGFncyI6IFsKICAgICAgImV0IiwKICAgICAgInN1bnQiLAogICAgICAibW9sbGl0IiwKICAgICAgImFuaW0iLAogICAgICAibW9sbGl0IiwKICAgICAgImRvIiwKICAgICAgIm5vbiIKICAgIF0sCiAgICAiZnJpZW5kcyI6IFsKICAgICAgewogICAgICAgICJpZCI6IDAsCiAgICAgICAgIm5hbWUiOiAiTGVuYSBIdWZmbWFuIgogICAgICB9LAogICAgICB7CiAgICAgICAgImlkIjogMSwKICAgICAgICAibmFtZSI6ICJWaWNreSBMdWNhcyIKICAgICAgfSwKICAgICAgewogICAgICAgICJpZCI6IDIsCiAgICAgICAgIm5hbWUiOiAiSm9zZXBoIEdhcmRuZXIiCiAgICAgIH0KICAgIF0sCiAgICAiZ3JlZXRpbmciOiAiSGVsbG8sIExpbGEgVmFsZW56dWVsYSEgWW91IGhhdmUgMTAgdW5yZWFkIG1lc3NhZ2VzLiIsCiAgICAiZmF2b3JpdGVGcnVpdCI6ICJiYW5hbmEiCiAgfQ==", "subType": "01" } }, "updatedAt": { "$date": 101010 }, "estimatedTimeOfArrival": { "$date": 101010 }, "isSomething": false, "createdAt": { "$date": 101010 }, "itemData": [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ], "employeeCode": "LBF" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 2 a. Terms generated with nested object index term truncation support SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( '{ "_id": 1, "itemData" : [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ] }' , 'itemData', true, true, true, 1000) term; length | term --------------------------------------------------------------------- 613 | { "$" : [ { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : "test", "el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first" : null, "greaterThan" : null, "shortPath" : "aas", "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } } }, { "attribute" : "xpto", "ccb" : { "$numberInt" : "34354" }, "dx" : { "$numberInt" : "0" }, "el" : null, "first" : null, "greaterThan" : null, "shortPath" : null, "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string2", "option3" : null, "option4" : { "$numberInt" : "122121" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior" : { "$numberLong" : "1111111111111111" } } } ], "t" : false } 341 | { "$.0" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : "test", "el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first" : null, "greaterThan" : null, "shortPath" : "aas", "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } } }, "t" : false } 29 | { "$.0.attribute" : "1234", "t" : false } 17 | { "$.0.cb" : { "$numberInt" : "12431" }, "t" : false } 22 | { "$.0.dx" : "test", "t" : false } 70 | { "$.0.el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "t" : false } 16 | { "$.0.first" : null, "t" : false } 7 | { "" : null, "t" : false } 22 | { "$.0.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 28 | { "$.0.shortPath" : "aas", "t" : false } 12 | { "$.0.i" : null, "t" : false } 7 | { "" : null, "t" : false } 191 | { "$.0.largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } }, "t" : false } 38 | { "$.0.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 56 | { "$.0.largePathWithObject.option2" : "small-string1", "t" : false } 38 | { "$.0.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 42 | { "$.0.largePathWithObject.option4" : { "$numberInt" : "123" }, "t" : false } 112 | { "$.0.largePathWithObject.onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "t" : false } 44 | { "$.0.largePathWithObject.prior" : { "$numberLong" : "123123213213" }, "t" : false } 339 | { "$" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : "test", "el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first" : null, "greaterThan" : null, "shortPath" : "aas", "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } } }, "t" : false } 27 | { "$.attribute" : "1234", "t" : false } 15 | { "$.cb" : { "$numberInt" : "12431" }, "t" : false } 20 | { "$.dx" : "test", "t" : false } 68 | { "$.el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "t" : false } 14 | { "$.first" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 26 | { "$.shortPath" : "aas", "t" : false } 10 | { "$.i" : null, "t" : false } 7 | { "" : null, "t" : false } 189 | { "$.largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } }, "t" : false } 36 | { "$.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 54 | { "$.largePathWithObject.option2" : "small-string1", "t" : false } 36 | { "$.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 40 | { "$.largePathWithObject.option4" : { "$numberInt" : "123" }, "t" : false } 110 | { "$.largePathWithObject.onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "t" : false } 42 | { "$.largePathWithObject.prior" : { "$numberLong" : "123123213213" }, "t" : false } 273 | { "$.1" : { "attribute" : "xpto", "ccb" : { "$numberInt" : "34354" }, "dx" : { "$numberInt" : "0" }, "el" : null, "first" : null, "greaterThan" : null, "shortPath" : null, "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string2", "option3" : null, "option4" : { "$numberInt" : "122121" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior" : { "$numberLong" : "1111111111111111" } } }, "t" : false } 29 | { "$.1.attribute" : "xpto", "t" : false } 18 | { "$.1.ccb" : { "$numberInt" : "34354" }, "t" : false } 17 | { "$.1.dx" : { "$numberInt" : "0" }, "t" : false } 13 | { "$.1.el" : null, "t" : false } 7 | { "" : null, "t" : false } 16 | { "$.1.first" : null, "t" : false } 7 | { "" : null, "t" : false } 22 | { "$.1.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.1.shortPath" : null, "t" : false } 7 | { "" : null, "t" : false } 12 | { "$.1.i" : null, "t" : false } 7 | { "" : null, "t" : false } 192 | { "$.1.largePathWithObject" : { "option1" : null, "option2" : "small-string2", "option3" : null, "option4" : { "$numberInt" : "122121" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior" : { "$numberLong" : "1111111111111111" } }, "t" : false } 38 | { "$.1.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 56 | { "$.1.largePathWithObject.option2" : "small-string2", "t" : false } 38 | { "$.1.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 42 | { "$.1.largePathWithObject.option4" : { "$numberInt" : "122121" }, "t" : false } 113 | { "$.1.largePathWithObject.onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "t" : false } 44 | { "$.1.largePathWithObject.prior" : { "$numberLong" : "1111111111111111" }, "t" : false } 271 | { "$" : { "attribute" : "xpto", "ccb" : { "$numberInt" : "34354" }, "dx" : { "$numberInt" : "0" }, "el" : null, "first" : null, "greaterThan" : null, "shortPath" : null, "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string2", "option3" : null, "option4" : { "$numberInt" : "122121" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior" : { "$numberLong" : "1111111111111111" } } }, "t" : false } 27 | { "$.attribute" : "xpto", "t" : false } 16 | { "$.ccb" : { "$numberInt" : "34354" }, "t" : false } 15 | { "$.dx" : { "$numberInt" : "0" }, "t" : false } 11 | { "$.el" : null, "t" : false } 7 | { "" : null, "t" : false } 14 | { "$.first" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 18 | { "$.shortPath" : null, "t" : false } 7 | { "" : null, "t" : false } 10 | { "$.i" : null, "t" : false } 7 | { "" : null, "t" : false } 190 | { "$.largePathWithObject" : { "option1" : null, "option2" : "small-string2", "option3" : null, "option4" : { "$numberInt" : "122121" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior" : { "$numberLong" : "1111111111111111" } }, "t" : false } 36 | { "$.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 54 | { "$.largePathWithObject.option2" : "small-string2", "t" : false } 36 | { "$.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 40 | { "$.largePathWithObject.option4" : { "$numberInt" : "122121" }, "t" : false } 111 | { "$.largePathWithObject.onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "t" : false } 42 | { "$.largePathWithObject.prior" : { "$numberLong" : "1111111111111111" }, "t" : false } 8 | { "" : true, "t" : false } 12 | { "" : [ ], "t" : false } (91 rows) -- 2 b. Terms generated with nested object index term truncation support SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( '{ "_id": 1, "itemData" : [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ] }' , 'itemData', true, true, true, 60) term; length | term --------------------------------------------------------------------- 45 | { "$" : [ { "attribute" : "1234", "cb" : { "$maxKey" : 1 } } ], "t" : true } 47 | { "$.0" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : { "$maxKey" : 1 } }, "t" : true } 29 | { "$.0.attribute" : "1234", "t" : false } 17 | { "$.0.cb" : { "$numberInt" : "12431" }, "t" : false } 22 | { "$.0.dx" : "test", "t" : false } 60 | { "$.0.el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2" }, "t" : true } 16 | { "$.0.first" : null, "t" : false } 7 | { "" : null, "t" : false } 22 | { "$.0.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 28 | { "$.0.shortPath" : "aas", "t" : false } 12 | { "$.0.i" : null, "t" : false } 7 | { "" : null, "t" : false } 44 | { "$.0.largePathWithObject" : { "option1" : { "$maxKey" : 1 } }, "t" : true } 38 | { "$.0.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 56 | { "$.0.largePathWithObject.option2" : "small-string1", "t" : false } 38 | { "$.0.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 42 | { "$.0.largePathWithObject.option4" : { "$numberInt" : "123" }, "t" : false } 60 | { "$.0.largePathWithObject.onlyPathWithLargeString" : "a", "t" : true } 44 | { "$.0.largePathWithObject.prior" : { "$numberLong" : "123123213213" }, "t" : false } 45 | { "$" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : { "$maxKey" : 1 } }, "t" : true } 27 | { "$.attribute" : "1234", "t" : false } 15 | { "$.cb" : { "$numberInt" : "12431" }, "t" : false } 20 | { "$.dx" : "test", "t" : false } 60 | { "$.el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2Jv" }, "t" : true } 14 | { "$.first" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 26 | { "$.shortPath" : "aas", "t" : false } 10 | { "$.i" : null, "t" : false } 7 | { "" : null, "t" : false } 51 | { "$.largePathWithObject" : { "option1" : null, "option2" : { "$maxKey" : 1 } }, "t" : true } 36 | { "$.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 54 | { "$.largePathWithObject.option2" : "small-string1", "t" : false } 36 | { "$.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 40 | { "$.largePathWithObject.option4" : { "$numberInt" : "123" }, "t" : false } 60 | { "$.largePathWithObject.onlyPathWithLargeString" : "aas", "t" : true } 42 | { "$.largePathWithObject.prior" : { "$numberLong" : "123123213213" }, "t" : false } 44 | { "$.1" : { "attribute" : "xpto", "ccb" : { "$numberInt" : "34354" } }, "t" : true } 29 | { "$.1.attribute" : "xpto", "t" : false } 18 | { "$.1.ccb" : { "$numberInt" : "34354" }, "t" : false } 17 | { "$.1.dx" : { "$numberInt" : "0" }, "t" : false } 13 | { "$.1.el" : null, "t" : false } 7 | { "" : null, "t" : false } 16 | { "$.1.first" : null, "t" : false } 7 | { "" : null, "t" : false } 22 | { "$.1.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.1.shortPath" : null, "t" : false } 7 | { "" : null, "t" : false } 12 | { "$.1.i" : null, "t" : false } 7 | { "" : null, "t" : false } 44 | { "$.1.largePathWithObject" : { "option1" : { "$maxKey" : 1 } }, "t" : true } 38 | { "$.1.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 56 | { "$.1.largePathWithObject.option2" : "small-string2", "t" : false } 38 | { "$.1.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 42 | { "$.1.largePathWithObject.option4" : { "$numberInt" : "122121" }, "t" : false } 60 | { "$.1.largePathWithObject.onlyPathWithLargeString" : "a", "t" : true } 44 | { "$.1.largePathWithObject.prior" : { "$numberLong" : "1111111111111111" }, "t" : false } 46 | { "$" : { "attribute" : "xpto", "ccb" : { "$numberInt" : "34354" }, "dx" : { "$maxKey" : 1 } }, "t" : true } 27 | { "$.attribute" : "xpto", "t" : false } 16 | { "$.ccb" : { "$numberInt" : "34354" }, "t" : false } 15 | { "$.dx" : { "$numberInt" : "0" }, "t" : false } 11 | { "$.el" : null, "t" : false } 7 | { "" : null, "t" : false } 14 | { "$.first" : null, "t" : false } 7 | { "" : null, "t" : false } 20 | { "$.greaterThan" : null, "t" : false } 7 | { "" : null, "t" : false } 18 | { "$.shortPath" : null, "t" : false } 7 | { "" : null, "t" : false } 10 | { "$.i" : null, "t" : false } 7 | { "" : null, "t" : false } 51 | { "$.largePathWithObject" : { "option1" : null, "option2" : { "$maxKey" : 1 } }, "t" : true } 36 | { "$.largePathWithObject.option1" : null, "t" : false } 7 | { "" : null, "t" : false } 54 | { "$.largePathWithObject.option2" : "small-string2", "t" : false } 36 | { "$.largePathWithObject.option3" : null, "t" : false } 7 | { "" : null, "t" : false } 40 | { "$.largePathWithObject.option4" : { "$numberInt" : "122121" }, "t" : false } 60 | { "$.largePathWithObject.onlyPathWithLargeString" : "aas", "t" : true } 42 | { "$.largePathWithObject.prior" : { "$numberLong" : "1111111111111111" }, "t" : false } 8 | { "" : true, "t" : false } 7 | { "" : { "$maxKey" : 1 }, "t" : true } 12 | { "" : [ ], "t" : false } (92 rows) -- 3. Now insert the document with nested object index term truncation support SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested', ' { "_id" : 2, "data": { "$binary": { "base64": "ewogICAgIl9pZCI6ICI2NzY5ZGI2NmExZGIyMDA4NTczOTdiNjAiLAogICAgImluZGV4IjogMCwKICAgICJndWlkIjogIjMzZjk1N2QwLWU0M2MtNDYyNi1iOGJjLTFkODE0ODE3MmZkNyIsCiAgICAiaXNBY3RpdmUiOiB0cnVlLAogICAgImJhbGFuY2UiOiAiJDMsOTMwLjI4IiwKICAgICJwaWN0dXJlIjogImh0dHA6Ly9wbGFjZWhvbGQuaXQvMzJ4MzIiLAogICAgImFnZSI6IDI3LAogICAgImV5ZUNvbG9yIjogImdyZWVuIiwKICAgICJuYW1lIjogIkxpbGEgVmFsZW56dWVsYSIsCiAgICAiZ2VuZGVyIjogImZlbWFsZSIsCiAgICAiY29tcGFueSI6ICJBUFBMSURFQyIsCiAgICAiZW1haWwiOiAibGlsYXZhbGVuenVlbGFAYXBwbGlkZWMuY29tIiwKICAgICJwaG9uZSI6ICIrMSAoODIyKSA1NDItMjQ1MCIsCiAgICAiYWRkcmVzcyI6ICI2NjcgT3hmb3JkIFdhbGssIENhc2h0b3duLCBBcmthbnNhcywgMjYyMyIsCiAgICAiYWJvdXQiOiAiSW4gYWxpcXVpcCBub24gZXN0IHNpdCBlc3QgTG9yZW0gcXVpIG9jY2FlY2F0IGZ1Z2lhdCBleC4gRG9sb3IgbGFib3JlIG1vbGxpdCBjb25zZXF1YXQgaXBzdW0uIFF1aXMgY29uc2VxdWF0IGRlc2VydW50IGVpdXNtb2QgcHJvaWRlbnQgZHVpcyBvY2NhZWNhdCBldSBlbGl0IG5vbiBhZCBleCBkZXNlcnVudCBwcm9pZGVudCBMb3JlbS4gSWQgbW9sbGl0IGNpbGx1bSBpcHN1bSB2b2x1cHRhdGUgYXV0ZSBsYWJvcmlzIGVzc2UgYW5pbS5cclxuIiwKICAgICJyZWdpc3RlcmVkIjogIjIwMjAtMDktMDRUMDM6MDA6MTggKzAzOjAwIiwKICAgICJsYXRpdHVkZSI6IDguMTI4MTI0LAogICAgImxvbmdpdHVkZSI6IC0zNy4zMjY4MDMsCiAgICAidGFncyI6IFsKICAgICAgImV0IiwKICAgICAgInN1bnQiLAogICAgICAibW9sbGl0IiwKICAgICAgImFuaW0iLAogICAgICAibW9sbGl0IiwKICAgICAgImRvIiwKICAgICAgIm5vbiIKICAgIF0sCiAgICAiZnJpZW5kcyI6IFsKICAgICAgewogICAgICAgICJpZCI6IDAsCiAgICAgICAgIm5hbWUiOiAiTGVuYSBIdWZmbWFuIgogICAgICB9LAogICAgICB7CiAgICAgICAgImlkIjogMSwKICAgICAgICAibmFtZSI6ICJWaWNreSBMdWNhcyIKICAgICAgfSwKICAgICAgewogICAgICAgICJpZCI6IDIsCiAgICAgICAgIm5hbWUiOiAiSm9zZXBoIEdhcmRuZXIiCiAgICAgIH0KICAgIF0sCiAgICAiZ3JlZXRpbmciOiAiSGVsbG8sIExpbGEgVmFsZW56dWVsYSEgWW91IGhhdmUgMTAgdW5yZWFkIG1lc3NhZ2VzLiIsCiAgICAiZmF2b3JpdGVGcnVpdCI6ICJiYW5hbmEiCiAgfQ==", "subType": "01" } }, "updatedAt": { "$date": 101010 }, "estimatedTimeOfArrival": { "$date": 101010 }, "isSomething": false, "createdAt": { "$date": 101010 }, "itemData": [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ], "employeeCode": "LBF" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 4. Now issue a find query SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData": { "$eq": { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } } } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } (2 rows) -- 5. Index usage explain EXPLAIN(ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData": { "$eq": { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } } } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 28 bytes Tasks Shown: All -> Task Tuple data received from node: 28 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=2 loops=1) -> Sort (actual rows=2 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_10405_1040081 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "itemData" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : "test", "el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first" : null, "greaterThan" : null, "shortPath" : "aas", "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on "wildcardIndex" (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "itemData" : { "attribute" : "1234", "cb" : { "$numberInt" : "12431" }, "dx" : "test", "el" : { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first" : null, "greaterThan" : null, "shortPath" : "aas", "i" : null, "largePathWithObject" : { "option1" : null, "option2" : "small-string1", "option3" : null, "option4" : { "$numberInt" : "123" }, "onlyPathWithLargeString" : "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior" : { "$numberLong" : "123123213213" } } } }'::documentdb_core.bson) (16 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData.largePathWithObject.option2": { "$eq": "small-string1" } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } (2 rows) EXPLAIN(ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData.largePathWithObject.option2": { "$eq": "small-string1" } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 28 bytes Tasks Shown: All -> Task Tuple data received from node: 28 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=2 loops=1) -> Sort (actual rows=2 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_10405_1040081 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "itemData.largePathWithObject.option2" : "small-string1" }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on "wildcardIndex" (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "itemData.largePathWithObject.option2" : "small-string1" }'::documentdb_core.bson) (16 rows) bson_index_truncation_symbol_tests.out000066400000000000000000002771051507310017400377450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1170000; SET documentdb.next_collection_id TO 11700; SET documentdb.next_collection_index_id TO 11700; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_symbol_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11700 Table "documentdb_data.documents_11700" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11700" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11701" documentdb_rum (document bson_rum_single_path_ops (path=ikey, tl='20')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11700'::bigint) -- Insert symbol BSON data SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 1, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 2, "ikey": { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 3, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 4, "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 5, "ikey": { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 6, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "F", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 7, "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G", "customKey": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 8, "ikey": { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 9, "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "H", "customKey": 8 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 10, "ikey": { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item": "H", "customKey": 9 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11700) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 20 | { "$" : { "$symbol" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 20 | { "$" : { "$symbol" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 20 | { "$" : { "$symbol" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 20 | { "$" : { "$symbol" : "YWJvYm9" }, "t" : true } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "5" } } | 20 | { "$" : { "$symbol" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 20 | { "$" : { "$symbol" : "eyAiZXh" }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 20 | { "$" : { "$symbol" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 20 | { "$" : { "$symbol" : "dGhpcyB" }, "t" : true } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "8" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "9" } } | 20 | { "$" : { "$symbol" : "eyAiYSI" }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 20 | { "$" : { "$symbol" : "dGhpcyB" }, "t" : true } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "10" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (30 rows) /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11700) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 40 | { "$" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 37 | { "$" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" }, "t" : false } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 40 | { "$" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "3" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "4" } } | 25 | { "$" : { "$symbol" : "YWJvYm9yYQ==" }, "t" : false } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 37 | { "$" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" }, "t" : false } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 40 | { "$" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZ" }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 40 | { "$" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjo" }, "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "8" } } | 40 | { "$" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5" }, "t" : true } { "" : { "$numberInt" : "8" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "8" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "9" } } | 40 | { "$" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjo" }, "t" : true } { "" : { "$numberInt" : "9" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "9" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "10" } } | 40 | { "$" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5" }, "t" : true } { "" : { "$numberInt" : "10" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "10" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (27 rows) /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiYSI6IDEsICJiIjogMyB9" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "G" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "G" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiYSI6IDEsICJiIjogMyB9" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$maxKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#<=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) /* $in/$nin/$ne/$all (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (10 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "YWJvYm9yYQ==" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "G", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "9" }, "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item" : "H", "customKey" : { "$numberInt" : "8" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "A" } { "_id" : { "$numberInt" : "2" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "3" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } { "_id" : { "$numberInt" : "4" }, "ikey" : { "$symbol" : "YWJvYm9yYQ==" } } { "_id" : { "$numberInt" : "5" }, "ikey" : { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } } { "_id" : { "$numberInt" : "6" }, "ikey" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item" : "F", "customKey" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "8" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } } { "_id" : { "$numberInt" : "10" }, "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item" : "H", "customKey" : { "$numberInt" : "9" } } (8 rows) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; document --------------------------------------------------------------------- (0 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE (documentdb_api_catalog.bson_dollar_in(document, '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_internal.##=) ANY (ARRAY['{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_api_internal.bsonindexbounds, '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_api_internal.bsonindexbounds])) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@*=) '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE (documentdb_api_catalog.bson_dollar_nin(document, '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!*=) '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!*=) '{ "ikey" : [ { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "YWJvYm9yYQ==" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "YWJvYm9yYQ==" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE (documentdb_api_catalog.bson_dollar_ne(document, '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@!=) '{ "ikey" : { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11700_1170005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11700_1170005 collection Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson)) -> Bitmap Index Scan on ikey_1 Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey" : { "$symbol" : "MTIzNDUxMjM0NQ==" } }'::documentdb_core.bson)) (12 rows) -- insert $symbol BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_symbol_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_11701 Table "documentdb_data.documents_11701" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11701" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11703" documentdb_rum (document bson_rum_single_path_ops (path=ikey2, tl='100')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11701'::bigint) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11701) docs; did | length | term --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjo" } } } } }, "t" : true } { "" : { "$numberInt" : "1" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "1" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "2" } } | 93 | { "$" : [ [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVl" } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 94 | { "$" : [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib" } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "2" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "2" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "3" } } | 30 | { "$" : [ [ "a" ] ], "t" : false } { "" : { "$numberInt" : "3" } } | 22 | { "$" : [ "a" ], "t" : false } { "" : { "$numberInt" : "3" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 97 | { "$" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasad" } } } } } }, "t" : true } { "" : { "$numberInt" : "4" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "4" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "5" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "5" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "5" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "6" } } | 84 | { "$" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "$maxKey" : 1 } } } } } }, "t" : true } { "" : { "$numberInt" : "6" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "6" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } { "" : { "$numberInt" : "7" } } | 80 | { "$" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$maxKey" : 1 } } } } ] ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 94 | { "$" : [ [ [ [ [ { "a" : { "b" : { "c" : { "$symbol" : "eyAiZXhhbXBsZSI6I" } } } } ] ] ] ] ], "t" : true } { "" : { "$numberInt" : "7" } } | 8 | { "" : true, "t" : false } { "" : { "$numberInt" : "7" } } | 7 | { "" : { "$maxKey" : 1 }, "t" : true } (23 rows) /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "test" : "a", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "test" : "b", "ikey2" : [ [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] ] ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "test" : "c", "ikey2" : [ [ "a" ] ], "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "test" : "d", "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "test" : "e", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "test" : "f", "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] } } } } } }, "item" : "A" } (1 row) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "test" : "g", "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ], "item" : "A" } (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ "a" ] ] }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdefg" : { "bcdef" : { "cdefg" : { "dhig" : { "f" : { "d" : "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "csssss" : { "$numberInt" : "2" } } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] } } } } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] } } } } } } }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : { "abcdeasasfg" : { "bcassasdef" : { "cdefsssg" : { "dhsssig" : { "ssssb" : { "c" : [ [ [ { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } ] ] ] } } } } } } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_11701_1170022 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "item" : "A" }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '11701'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_11701_1170022 collection Output: document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bson) Filter: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "item" : "A" }'::documentdb_core.bson) -> Bitmap Index Scan on ikey_2 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "ikey2" : [ [ [ [ [ [ { "a" : { "b" : { "c" : { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ] ] ] ] ] ] }'::documentdb_core.bson) (13 rows) bson_insert_basic_types.out000066400000000000000000000545021507310017400354440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 300000; SET documentdb.next_collection_id TO 3000; SET documentdb.next_collection_index_id TO 3000; -- insert int32 SELECT documentdb_api.insert_one('db','collection','{"_id":"1", "value": { "$numberInt" : "11" }, "valueMax": { "$numberInt" : "2147483647" }, "valueMin": { "$numberInt" : "-2147483648" }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert int64 SELECT documentdb_api.insert_one('db','collection','{"_id":"2", "value":{"$numberLong" : "134311"}, "valueMax": { "$numberLong" : "9223372036854775807" }, "valueMin": { "$numberLong" : "-9223372036854775808" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert double SELECT documentdb_api.insert_one('db','collection','{"_id":"3", "value":{"$numberDouble" : "0"}, "valueMax": { "$numberDouble" : "1.7976931348623157E+308" }, "valueMin": { "$numberDouble" : "-1.7976931348623157E+308" }, "valueEpsilon": { "$numberDouble": "4.94065645841247E-324"}, "valueinfinity": {"$numberDouble":"Infinity"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert string SELECT documentdb_api.insert_one('db','collection','{"_id":"4", "value": "Today is a very good day and I am happy."}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert binary SELECT documentdb_api.insert_one('db','collection','{"_id":"5", "value": {"$binary": { "base64": "SSBsb3ZlIE1pY3Jvc29mdA==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- minKey/maxKey SELECT documentdb_api.insert_one('db','collection','{"_id":"6", "valueMin": { "$minKey": 1 }, "valueMax": { "$maxKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- oid, date, time SELECT documentdb_api.insert_one('db','collection','{"_id":"7", "tsField": {"$timestamp":{"t":1565545664,"i":1}}, "dateBefore1970": {"$date":{"$numberLong":"-1577923200000"}}, "dateField": {"$date":{"$numberLong":"1565546054692"}}, "oidField": {"$oid":"5d505646cf6d4fe581014ab2"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- array & nested object SELECT documentdb_api.insert_one('db','collection','{"_id":"8","arrayOfObject":[{"bonjour":"bonjour"},{"ça va ?":"ça va !"},{"Qu''est-ce que tu as fait cette semaine ?":"rien"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'collection') ORDER BY 1,2,3; shard_key_value | object_id | document --------------------------------------------------------------------- 3000 | { "" : "1" } | { "_id" : "1", "value" : { "$numberInt" : "11" }, "valueMax" : { "$numberInt" : "2147483647" }, "valueMin" : { "$numberInt" : "-2147483648" } } 3000 | { "" : "2" } | { "_id" : "2", "value" : { "$numberLong" : "134311" }, "valueMax" : { "$numberLong" : "9223372036854775807" }, "valueMin" : { "$numberLong" : "-9223372036854775808" } } 3000 | { "" : "3" } | { "_id" : "3", "value" : { "$numberDouble" : "0.0" }, "valueMax" : { "$numberDouble" : "1.7976931348623157081e+308" }, "valueMin" : { "$numberDouble" : "-1.7976931348623157081e+308" }, "valueEpsilon" : { "$numberDouble" : "4.9406564584124654418e-324" }, "valueinfinity" : { "$numberDouble" : "Infinity" } } 3000 | { "" : "4" } | { "_id" : "4", "value" : "Today is a very good day and I am happy." } 3000 | { "" : "5" } | { "_id" : "5", "value" : { "$binary" : { "base64" : "SSBsb3ZlIE1pY3Jvc29mdA==", "subType" : "02" } } } 3000 | { "" : "6" } | { "_id" : "6", "valueMin" : { "$minKey" : 1 }, "valueMax" : { "$maxKey" : 1 } } 3000 | { "" : "7" } | { "_id" : "7", "tsField" : { "$timestamp" : { "t" : 1565545664, "i" : 1 } }, "dateBefore1970" : { "$date" : { "$numberLong" : "-1577923200000" } }, "dateField" : { "$date" : { "$numberLong" : "1565546054692" } }, "oidField" : { "$oid" : "5d505646cf6d4fe581014ab2" } } 3000 | { "" : "8" } | { "_id" : "8", "arrayOfObject" : [ { "bonjour" : "bonjour" }, { "ça va ?" : "ça va !" }, { "Qu'est-ce que tu as fait cette semaine ?" : "rien" } ] } (8 rows) -- project two fields out. SELECT document->'_id', document->'value' FROM documentdb_api.collection('db', 'collection') ORDER BY object_id; ?column? | ?column? --------------------------------------------------------------------- { "" : "1" } | { "" : { "$numberInt" : "11" } } { "" : "2" } | { "" : { "$numberLong" : "134311" } } { "" : "3" } | { "" : { "$numberDouble" : "0.0" } } { "" : "4" } | { "" : "Today is a very good day and I am happy." } { "" : "5" } | { "" : { "$binary" : { "base64" : "SSBsb3ZlIE1pY3Jvc29mdA==", "subType" : "02" } } } { "" : "6" } | { "" : "7" } | { "" : "8" } | (8 rows) -- insert document with $ or . in the field path SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 9, "$field": 1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 10, "field": { "$subField": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 11, "field": [ { "$subField": 1 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 12, ".field": 1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 13, "fie.ld": 1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 14, "field": { ".subField": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 15, "field": { "sub.Field": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 16, "field": [ { "sub.Field": 1 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Test to validate that _id field cannot have regex as it's value */ select documentdb_api.insert_one('db', 'bsontypetests', '{"_id": {"$regex": "^A", "$options": ""}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "The '_id' field value must not be a type of regex" } ] } (1 row) /* Test _id cannot have nested paths with $ */ SELECT documentdb_api.insert_one('db', 'bsontypetests', '{ "_id": { "a": 2, "$c": 3 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "385875997" }, "errmsg" : "_id fields may not contain '$'-prefixed fields: $c is not valid for storage." } ] } (1 row) /* Test to validate that _id field cannot have array as it's value */ select documentdb_api.insert_one('db', 'bsontypetests', '{"_id": [1]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "The '_id' field value must not be a type of array" } ] } (1 row) -- assert object_id matches the '_id' from the content - should be numRows. SELECT COUNT(*) FROM documentdb_api.collection('db', 'collection') where object_id::bson = bson_get_value(document, '_id'); count --------------------------------------------------------------------- 16 (1 row) \copy documentdb_data.documents_3000 to 'test.bin' with (format 'binary') CREATE TABLE tmp_documentdb_data_documents_3000 (LIKE documentdb_data.documents_3000); \copy tmp_documentdb_data_documents_3000 from 'test.bin' with (format 'binary') -- verify that all records are same after serialization/deserialization SELECT COUNT(*)=0 FROM ( (TABLE documentdb_data.documents_3000 EXCEPT TABLE tmp_documentdb_data_documents_3000) UNION (TABLE tmp_documentdb_data_documents_3000 EXCEPT TABLE documentdb_data.documents_3000) ) q; ?column? --------------------------------------------------------------------- t (1 row) -- verify output via hex strings and json BEGIN; set local documentdb_core.bsonUseEJson TO true; SELECT document FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "$field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "field" : { "$subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "11" }, "field" : [ { "$subField" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "12" }, ".field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "13" }, "fie.ld" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "14" }, "field" : { ".subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "15" }, "field" : { "sub.Field" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "16" }, "field" : [ { "sub.Field" : { "$numberInt" : "1" } } ] } { "_id" : "1", "value" : { "$numberInt" : "11" }, "valueMax" : { "$numberInt" : "2147483647" }, "valueMin" : { "$numberInt" : "-2147483648" } } { "_id" : "2", "value" : { "$numberLong" : "134311" }, "valueMax" : { "$numberLong" : "9223372036854775807" }, "valueMin" : { "$numberLong" : "-9223372036854775808" } } { "_id" : "3", "value" : { "$numberDouble" : "0.0" }, "valueMax" : { "$numberDouble" : "1.7976931348623157081e+308" }, "valueMin" : { "$numberDouble" : "-1.7976931348623157081e+308" }, "valueEpsilon" : { "$numberDouble" : "4.9406564584124654418e-324" }, "valueinfinity" : { "$numberDouble" : "Infinity" } } { "_id" : "4", "value" : "Today is a very good day and I am happy." } { "_id" : "5", "value" : { "$binary" : { "base64" : "SSBsb3ZlIE1pY3Jvc29mdA==", "subType" : "02" } } } { "_id" : "6", "valueMin" : { "$minKey" : 1 }, "valueMax" : { "$maxKey" : 1 } } { "_id" : "7", "tsField" : { "$timestamp" : { "t" : 1565545664, "i" : 1 } }, "dateBefore1970" : { "$date" : { "$numberLong" : "-1577923200000" } }, "dateField" : { "$date" : { "$numberLong" : "1565546054692" } }, "oidField" : { "$oid" : "5d505646cf6d4fe581014ab2" } } { "_id" : "8", "arrayOfObject" : [ { "bonjour" : "bonjour" }, { "ça va ?" : "ça va !" }, { "Qu'est-ce que tu as fait cette semaine ?" : "rien" } ] } (16 rows) ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO false; SELECT document FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; document --------------------------------------------------------------------- BSONHEX1a000000105f6964000900000010246669656c64000100000000 BSONHEX29000000105f6964000a000000036669656c64001400000010247375624669656c6400010000000000 BSONHEX31000000105f6964000b000000046669656c64001c0000000330001400000010247375624669656c640001000000000000 BSONHEX1a000000105f6964000c000000102e6669656c64000100000000 BSONHEX1a000000105f6964000d000000106669652e6c64000100000000 BSONHEX29000000105f6964000e000000036669656c640014000000102e7375624669656c6400010000000000 BSONHEX29000000105f6964000f000000036669656c640014000000107375622e4669656c6400010000000000 BSONHEX31000000105f69640010000000046669656c64001c00000003300014000000107375622e4669656c640001000000000000 BSONHEX37000000025f6964000200000031001076616c7565000b0000001076616c75654d617800ffffff7f1076616c75654d696e000000008000 BSONHEX43000000025f6964000200000032001276616c756500a70c0200000000001276616c75654d617800ffffffffffffff7f1276616c75654d696e00000000000000008000 BSONHEX70000000025f6964000200000033000176616c75650000000000000000000176616c75654d617800ffffffffffffef7f0176616c75654d696e00ffffffffffffefff0176616c7565457073696c6f6e0001000000000000000176616c7565696e66696e69747900000000000000f07f00 BSONHEX44000000025f6964000200000034000276616c75650029000000546f6461792069732061207665727920676f6f642064617920616e64204920616d2068617070792e0000 BSONHEX30000000025f6964000200000035000576616c75650014000000021000000049206c6f7665204d6963726f736f667400 BSONHEX24000000025f696400020000003600ff76616c75654d696e007f76616c75654d61780000 BSONHEX62000000025f6964000200000037001174734669656c640001000000c054505d09646174654265666f7265313937300000bc729c90feffff09646174654669656c64002404d1816c010000076f69644669656c64005d505646cf6d4fe581014ab200 BSONHEX9b000000025f6964000200000038000461727261794f664f626a656374007c0000000330001a00000002626f6e6a6f75720008000000626f6e6a6f757200000331001c00000002c3a761207661203f0009000000c3a7612076612021000003320038000000025175276573742d63652071756520747520617320666169742063657474652073656d61696e65203f00050000007269656e00000000 (16 rows) ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO true; SELECT bson_hex_to_bson(bson_to_bson_hex(document)) FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; bson_hex_to_bson --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "$field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "field" : { "$subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "11" }, "field" : [ { "$subField" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "12" }, ".field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "13" }, "fie.ld" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "14" }, "field" : { ".subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "15" }, "field" : { "sub.Field" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "16" }, "field" : [ { "sub.Field" : { "$numberInt" : "1" } } ] } { "_id" : "1", "value" : { "$numberInt" : "11" }, "valueMax" : { "$numberInt" : "2147483647" }, "valueMin" : { "$numberInt" : "-2147483648" } } { "_id" : "2", "value" : { "$numberLong" : "134311" }, "valueMax" : { "$numberLong" : "9223372036854775807" }, "valueMin" : { "$numberLong" : "-9223372036854775808" } } { "_id" : "3", "value" : { "$numberDouble" : "0.0" }, "valueMax" : { "$numberDouble" : "1.7976931348623157081e+308" }, "valueMin" : { "$numberDouble" : "-1.7976931348623157081e+308" }, "valueEpsilon" : { "$numberDouble" : "4.9406564584124654418e-324" }, "valueinfinity" : { "$numberDouble" : "Infinity" } } { "_id" : "4", "value" : "Today is a very good day and I am happy." } { "_id" : "5", "value" : { "$binary" : { "base64" : "SSBsb3ZlIE1pY3Jvc29mdA==", "subType" : "02" } } } { "_id" : "6", "valueMin" : { "$minKey" : 1 }, "valueMax" : { "$maxKey" : 1 } } { "_id" : "7", "tsField" : { "$timestamp" : { "t" : 1565545664, "i" : 1 } }, "dateBefore1970" : { "$date" : { "$numberLong" : "-1577923200000" } }, "dateField" : { "$date" : { "$numberLong" : "1565546054692" } }, "oidField" : { "$oid" : "5d505646cf6d4fe581014ab2" } } { "_id" : "8", "arrayOfObject" : [ { "bonjour" : "bonjour" }, { "ça va ?" : "ça va !" }, { "Qu'est-ce que tu as fait cette semaine ?" : "rien" } ] } (16 rows) ROLLBACK; BEGIN; -- test that hex strings can be coerced to bson (bson_in accepts both) set local documentdb_core.bsonUseEJson TO true; SELECT bson_to_bson_hex(document)::text::bson FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; bson_to_bson_hex --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "$field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "field" : { "$subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "11" }, "field" : [ { "$subField" : { "$numberInt" : "1" } } ] } { "_id" : { "$numberInt" : "12" }, ".field" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "13" }, "fie.ld" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "14" }, "field" : { ".subField" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "15" }, "field" : { "sub.Field" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "16" }, "field" : [ { "sub.Field" : { "$numberInt" : "1" } } ] } { "_id" : "1", "value" : { "$numberInt" : "11" }, "valueMax" : { "$numberInt" : "2147483647" }, "valueMin" : { "$numberInt" : "-2147483648" } } { "_id" : "2", "value" : { "$numberLong" : "134311" }, "valueMax" : { "$numberLong" : "9223372036854775807" }, "valueMin" : { "$numberLong" : "-9223372036854775808" } } { "_id" : "3", "value" : { "$numberDouble" : "0.0" }, "valueMax" : { "$numberDouble" : "1.7976931348623157081e+308" }, "valueMin" : { "$numberDouble" : "-1.7976931348623157081e+308" }, "valueEpsilon" : { "$numberDouble" : "4.9406564584124654418e-324" }, "valueinfinity" : { "$numberDouble" : "Infinity" } } { "_id" : "4", "value" : "Today is a very good day and I am happy." } { "_id" : "5", "value" : { "$binary" : { "base64" : "SSBsb3ZlIE1pY3Jvc29mdA==", "subType" : "02" } } } { "_id" : "6", "valueMin" : { "$minKey" : 1 }, "valueMax" : { "$maxKey" : 1 } } { "_id" : "7", "tsField" : { "$timestamp" : { "t" : 1565545664, "i" : 1 } }, "dateBefore1970" : { "$date" : { "$numberLong" : "-1577923200000" } }, "dateField" : { "$date" : { "$numberLong" : "1565546054692" } }, "oidField" : { "$oid" : "5d505646cf6d4fe581014ab2" } } { "_id" : "8", "arrayOfObject" : [ { "bonjour" : "bonjour" }, { "ça va ?" : "ça va !" }, { "Qu'est-ce que tu as fait cette semaine ?" : "rien" } ] } (16 rows) ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO false; SELECT COUNT(1) FROM documentdb_api.collection('db', 'collection') WHERE bson_hex_to_bson(bson_out(document)) != document; count --------------------------------------------------------------------- 0 (1 row) ROLLBACK; bson_order_aggregates_tests.out000066400000000000000000004645101507310017400363050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 71000; SET documentdb.next_collection_id TO 7100; SET documentdb.next_collection_index_id TO 7100; -- Insert an a.b, a.c matrix SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 1, "a" : { "b" : 1, "c" : 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 2, "a" : { "b" : 1, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 3, "a" : { "b" : 1, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 4, "a" : { "b" : 2, "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 5, "a" : { "b" : 2, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 6, "a" : { "b" : 2, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 7, "a" : { "b" : 3, "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 8, "a" : { "b" : 3, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 9, "a" : { "b" : 3, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonlastonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (3 rows) SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTONSORTED(bson_expression_get(document, '{ "": "$a.f" }'))) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "firstonsorted" : null } { "firstonsorted" : null } { "firstonsorted" : null } (3 rows) SELECT bson_repath_and_build('last'::text, BSONLAST(bson_expression_get(document, '{ "": "$a.f" }'), ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "last" : null } { "last" : null } { "last" : null } (3 rows) -- Test the different order combinations SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) -- Test with null results from the sort spec SELECT BSONFIRST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) -- Test null ordering SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 11, "a" : { "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (1 row) SELECT BSONLAST(document, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLAST(document, ARRAY['{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_7100_71000 collection Recheck Cond: (shard_key_value = '7100'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '7100'::bigint) (10 rows) END; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bsonorderaggregates", "indexes": [{"key": {"a.b": 1}, "name": "a_dot_b"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLAST(document, ARRAY['{"a.b":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Index Scan using _id_ on documents_7100_71000 collection Index Cond: (shard_key_value = '7100'::bigint) (8 rows) END; -- Shard the collection SELECT documentdb_api.shard_collection('db','bsonorderaggregates', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT BSONLAST(document, ARRAY['{ "a.b":1}'::bson,'{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (4 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (4 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (4 rows) SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } (4 rows) SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (3 rows) SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } (4 rows) SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonlastonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } (4 rows) SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstonsorted --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } (4 rows) -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTONSORTED(bson_expression_get(document, '{ "": "$a.f" }'))) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "firstonsorted" : null } { "firstonsorted" : null } { "firstonsorted" : null } (3 rows) SELECT bson_repath_and_build('last'::text, BSONLAST(bson_expression_get(document, '{ "": "$a.f" }'), ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "last" : null } { "last" : null } { "last" : null } (3 rows) SELECT bson_repath_and_build( 'lastNull'::text, bson_expression_get(BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.f" }', true), 'first'::text, bson_expression_get(BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.b" }', true), 'firstNull'::text, bson_expression_get(BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.x" }', true) ) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "lastNull" : null, "first" : { "$numberInt" : "3" }, "firstNull" : null } { "lastNull" : null, "first" : { "$numberInt" : "3" }, "firstNull" : null } { "lastNull" : null, "first" : { "$numberInt" : "3" }, "firstNull" : null } (3 rows) -- regression test for crash in BSONFIRST/BSONLAST when the first documents are small and we need to choose a larger document in byte size SELECT documentdb_api.insert_one('db', 'bsonFirstLastCrash', '{"_id": 1, "a": "z", "b": "z", "c": "z"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bsonFirstLastCrash', FORMAT('{"_id": 2, "a": "%s", "b": "%s", "c": "%s"}', repeat('aaa', 10), repeat('bbb', 10), repeat('dd', 10))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONFIRST(document, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstLastCrash'); bsonfirst --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" } (1 row) SELECT BSONLAST(document, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstLastCrash'); bsonlast --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" } (1 row) -- -- BEGIN FIRSTN/LASTN Testing -- -- Insert an a.b, a.c matrix SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 1, "a" : { "b" : 1, "c" : 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 2, "a" : { "b" : 1, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 3, "a" : { "b" : 1, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 4, "a" : { "b" : 2, "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 5, "a" : { "b" : 2, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 6, "a" : { "b" : 2, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 7, "a" : { "b" : 3, "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 8, "a" : { "b" : 3, "c" : 2 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 9, "a" : { "b" : 3, "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONLASTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } (3 rows) SELECT BSONLASTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonlastnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) SELECT BSONFIRSTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (3 rows) -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTNONSORTED(bson_expression_get(document, '{ "": "$a.f" }'), 1)) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "firstonsorted" : [ { } ] } { "firstonsorted" : [ { } ] } { "firstonsorted" : [ { } ] } (3 rows) SELECT bson_repath_and_build('last'::text, BSONLASTN(bson_expression_get(document, '{ "": "$a.f" }'), 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "last" : [ { } ] } { "last" : [ { } ] } { "last" : [ { } ] } (3 rows) -- Test the different order combinations SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) -- Test with null results from the sort spec SELECT BSONFIRSTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) -- Test null ordering SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 11, "a" : { "c" : 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLASTN(document, 1, ARRAY['{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_7102_71044 collection Recheck Cond: (shard_key_value = '7102'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '7102'::bigint) (10 rows) END; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bsonordernaggregates", "indexes": [{"key": {"a.b": 1}, "name": "a_dot_b"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLASTN(document, 1, ARRAY['{"a.b":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Index Scan using _id_ on documents_7102_71044 collection Index Cond: (shard_key_value = '7102'::bigint) (8 rows) END; -- Shard the collection SELECT documentdb_api.shard_collection('db','bsonordernaggregates', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONLASTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bsonlastnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) SELECT BSONFIRSTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } } ] } (4 rows) SELECT BSONLASTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonlastnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (4 rows) SELECT BSONFIRSTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); bsonfirstnonsorted --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ] } { "" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } } ] } { "" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ] } (4 rows) -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTNONSORTED(bson_expression_get(document, '{ "": "$a.f" }'), 1)) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "firstonsorted" : [ { } ] } { "firstonsorted" : [ { } ] } { "firstonsorted" : [ { } ] } (3 rows) SELECT bson_repath_and_build('last'::text, BSONLASTN(bson_expression_get(document, '{ "": "$a.f" }'), 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "last" : [ { } ] } { "last" : [ { } ] } { "last" : [ { } ] } (3 rows) SELECT bson_repath_and_build( 'lastNull'::text, BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), 'first'::text, BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), 'firstNull'::text, BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) ) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); bson_repath_and_build --------------------------------------------------------------------- { "lastNull" : [ { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "11" }, "a" : { "c" : { "$numberInt" : "3" } } } ], "first" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ], "firstNull" : [ { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } }, { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } } ] } { "lastNull" : [ { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } ], "first" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ], "firstNull" : [ { "_id" : { "$numberInt" : "8" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "2" } } }, { "_id" : { "$numberInt" : "5" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } ] } { "lastNull" : [ { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } } ], "first" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ], "firstNull" : [ { "_id" : { "$numberInt" : "7" }, "a" : { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "1" } } }, { "_id" : { "$numberInt" : "4" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "1" } } } ] } (3 rows) -- regression test for crash in BSONFIRSTN/BSONLASTN when the first documents are small and we need to choose a larger document in byte size SELECT documentdb_api.insert_one('db', 'bsonFirstNLastNCrash', '{"_id": 1, "a": "z", "b": "z", "c": "z"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'bsonFirstNLastNCrash', FORMAT('{"_id": 2, "a": "%s", "b": "%s", "c": "%s"}', repeat('aaa', 10), repeat('bbb', 10), repeat('dd', 10))::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT BSONFIRSTN(document, 1, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" } ] } (1 row) SELECT BSONLASTN(document, 1, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" } ] } (1 row) -- regression test for allocating too much memory SELECT BSONFIRSTN(document, 9999999999999, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonfirstn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" }, { "_id" : { "$numberInt" : "1" }, "a" : "z", "b" : "z", "c" : "z" } ] } (1 row) SELECT BSONLASTN(document, 9999999999999, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonlastn --------------------------------------------------------------------- { "" : [ { "_id" : { "$numberInt" : "1" }, "a" : "z", "b" : "z", "c" : "z" }, { "_id" : { "$numberInt" : "2" }, "a" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "b" : "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "c" : "dddddddddddddddddddd" } ] } (1 row) -- regression test for NULL pointer SELECT BSONFIRSTN(NULL, 1, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]); bsonfirstn --------------------------------------------------------------------- { "" : [ null ] } (1 row) SELECT BSONFIRSTNONSORTED(NULL, 1); bsonfirstnonsorted --------------------------------------------------------------------- { "" : [ null ] } (1 row) SELECT BSONLASTN(NULL, 3, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonlastn --------------------------------------------------------------------- { "" : [ null, null ] } (1 row) SELECT BSONLASTNONSORTED(NULL, 3) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bsonlastnonsorted --------------------------------------------------------------------- { "" : [ null, null ] } (1 row) bson_projection_operator_dollar_slice_test.out000066400000000000000000001466451507310017400414270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 290000; SET documentdb.next_collection_id TO 2900; SET documentdb.next_collection_index_id TO 2900; --Input type positive number select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 0} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 2} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 8} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberLong" : "2"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "2.1234"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "2.1234"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : []}', '{"a" : { "$slice" : 1} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1]}', '{"a" : { "$slice" : 1} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [{"x":[1,2,3]}, {"x":[4,5,6]}]}', '{"a.x" : { "$slice" : 2} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "x" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } ] } (1 row) --Input type is Negative number select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -0} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -1} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -2} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : -4} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5,6,7,8,9,10,11] }', '{"a" : { "$slice" : -13} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -8} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberLong" : "-2"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "-2.1234"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "-2.1234"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) --Input type is array with postive number fields select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0,0]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0,2]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [2,3]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [3,1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "4" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [3,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [4,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [5,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberLong" : "1"}, { "$numberLong" : "3"} ] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDouble" : "2.1234"}, { "$numberDouble" : "3.1234"} ] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "1.1234"}, { "$numberDecimal" : "3.1234"}] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) --Input type is array with negative number fields select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-0,0]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-1,2]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-2,3]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-3,1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-3,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-4,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-5,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-10,10]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberLong" : "-1"}, { "$numberLong" : "3"} ] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDouble" : "-2.1234"}, { "$numberDouble" : "3.1234"} ] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "-1.1234"}, { "$numberDecimal" : "3.1234"}] }}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "5" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) --Input is NaN or Infinity select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "NaN"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "Infinity"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "NaN"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "Infinity"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, { "$numberDecimal" : "NaN"}]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value, but is of type: decimal select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, { "$numberDecimal" : "Infinity"}]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, { "$numberDecimal" : "NaN"}]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value, but is of type: decimal select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, { "$numberDecimal" : "Infinity"}]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0, { "$numberDecimal" : "Infinity"}]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, 1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0, { "$numberDecimal" : "NaN"}]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value, but is of type: decimal select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, 1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : { "$numberDecimal" : "-Infinity"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$numberDecimal" : "-Infinity"}, 1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1, { "$numberDecimal" : "-Infinity"}]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value, but is of type: decimal --large values $slice select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "999999999999999999999999999999"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "999999999999999999999999999999"}, { "$numberDecimal" : "999999999999999999999999999999"}] } }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "0"}, { "$numberDecimal" : "999999999999999999999999999999"}] } }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : {"$numberDecimal" : "123123123123123121231"}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : [ {"$numberDecimal" : "123123123123123121231"}, {"$numberDecimal" : "123123123123123121231"} ]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ ], "b" : { "$numberInt" : "22" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : [1,{"$numberDecimal" : "123123123123123121231"}]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : { "$numberInt" : "22" } } (1 row) --inclusion Exclusion check select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b" :0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b" :1 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b":0, "c":0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c": 1, "d" : 0 }',NULL); ERROR: exclusion cannot be applied to field d within the inclusion projection. --Nested array inside document & array select bson_dollar_project_find('{"_id":"1", "a" : {"x": [1,2,3], "y":5 }, "b":10}', '{"a.x" : { "$slice" : 1}, "b" :0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : { "x" : [ { "$numberInt" : "1" } ], "y" : { "$numberInt" : "5" } } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : {"x": [1,2,3], "y":5 }, "b":10}', '{"a.x" : { "$slice" : 1}, "b" :1 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : { "x" : [ { "$numberInt" : "1" } ] }, "b" : { "$numberInt" : "10" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3]], "b":10}', '{"a.0" : { "$slice" : 1}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ], "b" : { "$numberInt" : "10" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3], {"y": 5}], "b":10}', '{"a.0" : { "$slice" : 1}, "b" :1 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ ], { } ], "b" : { "$numberInt" : "10" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3],4,5]}', '{"a.0" : { "$slice" : 1}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3], {"y": 5}], "b":10}', '{"a.0" : { "$slice" : 1}, "b" :0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], { "y" : { "$numberInt" : "5" } } ] } (1 row) --multiple Slice select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1}, "b" :0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "c" : [ { "$numberInt" : "1" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1}, "b" :1 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" } ] } (1 row) --$slice with other operators select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "2" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}}, "b" : 1 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "2" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}, "b" :0}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" } ], "c" : [ { "$numberInt" : "1" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}}, "b" : 0 }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "c" : [ { "$numberInt" : "2" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}, "b" :1}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" } ], "a" : [ { "$numberInt" : "2" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"b" : 0 , "a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "1" } ], "c" : [ { "$numberInt" : "2" } ], "d" : { "$numberInt" : "4" } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"b" : 1 , "a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "b" : { "$numberInt" : "22" }, "c" : [ { "$numberInt" : "1" } ], "a" : [ { "$numberInt" : "2" } ] } (1 row) select bson_dollar_project_find('{"a": [ {"b" : [10]}, { "b" : [20]}]}', '{ "a.b": {"$slice":1}, "a.b": {"$add":[1,5]} }','{}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "b" : { "$numberInt" : "6" } }, { "b" : { "$numberInt" : "6" } } ] } (1 row) select bson_dollar_project_find('{"a": [ {"b" : [10]}, { "b" : [20]}]}', '{ "a.b": {"$add":[1,10]}, "a.b": {"$slice":1} }','{}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "b" : [ { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "20" } ] } ] } (1 row) select bson_dollar_project_find('{"b": [[1,2,3,4]], "a": [10,20,30,40]}', '{ "a.$": 1, "b" : {"$slice" : 1} }','{"a" : {"$gt" :1}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ], "a" : [ { "$numberInt" : "10" } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : {"b": {"c":[1,2,3], "d":10},"f":10 } }', '{"a.b.c" : {"$slice": 1}, "a.b.d": {"field":"$a.f"} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : [ { "$numberInt" : "1" } ], "d" : { "field" : { "$numberInt" : "10" } } } } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : {"b": {"c":[1,2,3], "d":10},"f":10 } }', '{"a.b.c" : {"$slice": 1}, "a.b.d": {"$isArray":"$a.c"} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : { "b" : { "c" : [ { "$numberInt" : "1" } ], "d" : false } } } (1 row) --Path Collision select bson_dollar_project_find('{"_id":"1", "a" : [{"x":1, "y":2}]}', '{"a" : { "$slice" : 1}, "a.x":0 }',NULL); ERROR: Collision detected in specified path a.x remaining portion x select bson_dollar_project_find('{"_id":"1", "a" : [{"x":1, "y":2}]}', '{"a" : { "$slice" : 1}, "a.x":1 }',NULL); ERROR: Collision detected in specified path a.x remaining portion x --array of array select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3]}]]}', '{"a.b" : { "$slice" : 2}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3]}], { "b": [1,2,3]}]}', '{"a.b" : { "$slice" : 2}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3], "c":{ "d": [1,2,3] } }], { "e": [1,2,3] , "f": [[{"g": [1,2,3]}]] }]}', '{"a.b" : { "$slice" : 2}, "a.c.d" : { "$slice" : 2}, "a.e" : { "$slice" : 2},"a.f.g" : { "$slice" : 2}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ [ { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } ], { "e" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "f" : [ [ { "g" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] } ] } (1 row) --Null and undefined input select bson_dollar_project_find('{"_id":"1", "a" : null}', '{"a" : { "$slice" : [1,2]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,null]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [null,1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [null,null]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : { "$undefined" : true }}', '{"a" : { "$slice" : [1,2]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : { "$undefined" : true } } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,{ "$undefined" : true }]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$undefined" : true },1]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$undefined" : true },{ "$undefined" : true }]} }',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : null } (1 row) --Invalid Input Negative cases find slice projection select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : "str"} }',NULL); ERROR: Expected numeric value for first parameter of $slice but found 'string' type select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : ["str"]} }',NULL); ERROR: $slice takes 2 arguments, but 1 were passed in. select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,2,3]} }',NULL); ERROR: $slice takes 2 arguments, but 3 were passed in. select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,"str"]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value, but is of type: string select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,-1]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,0]} }',NULL); ERROR: The second parameter provided to the $slice operator must always be a positive numeric value select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1]} }',NULL); ERROR: $slice takes 2 arguments, but 1 were passed in. select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : null} }',NULL); ERROR: Expected numeric value for first parameter of $slice but found 'null' type select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : { "$undefined" : true }} }',NULL); ERROR: Expected numeric value for first parameter of $slice but found 'undefined' type bson_projection_operator_elemmatch_tests_core.out000066400000000000000000000275371507310017400421230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- Test $elemMatch projection operator SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 280000; SET documentdb.next_collection_id TO 2800; SET documentdb.next_collection_index_id TO 2800; SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": [ 11, 21, 31, 41 ], "z": "World" }', '{ "a":{ "$elemMatch":{ "$gt":25 }} }', '{}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "31" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 2, "a": [ 11, 21, 31, 41 ], "f": [ { "g": [ 14, 24, 34, 44 ], "h": "Hello" }, { "g": [ 15, 25, 35, 45 ], "h": "world" }], "z": "World" }', '{ "f": {"$elemMatch": {"g": {"$elemMatch": {"$gt":25 }}}} }', '{}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "f" : [ { "g" : [ { "$numberInt" : "14" }, { "$numberInt" : "24" }, { "$numberInt" : "34" }, { "$numberInt" : "44" } ], "h" : "Hello" } ] } (1 row) -- Empty $elemMatch Predicate should match the first array or object value SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, {"b": 51}, 61 ] }', '{ "a": {"$elemMatch": {} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "b" : { "$numberInt" : "51" } } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ [ { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" } ] ] } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$or": [{}, {}]} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ [ { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" } ] ] } (1 row) -- this is negation so won't match any SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$nor": [{}, {}]} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ [ { "$numberInt" : "51" }, { "$numberInt" : "52" }, { "$numberInt" : "53" } ] ] } (1 row) -- $elemMatch on non array fields are skipped SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ], "b": {"c": 2}, "d": 71 }', '{ "b": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" } } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ], "b": {"c": 2}, "d": 71 }', '{ "d": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" } } (1 row) -- Testing order of $elemMatch projection for inclusion and exclusion projections -- Inclusion projection - elemMatch is projected at the end & multiple elemMatch projections are projected based on projection spec order SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "e": 1, "d": 1 }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "71" }, "e" : { "f" : "good" }, "b" : [ { "$numberInt" : "51" } ], "a" : [ { "$numberInt" : "11" } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "d": 1, "e": {"$add": [2,3]} }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "d" : { "$numberInt" : "71" }, "e" : { "$numberInt" : "5" }, "b" : [ { "$numberInt" : "51" } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}', '{"z": {"$elemMatch": {"$eq": 8} }, "x": {"$elemMatch": {"$eq": 3} }, "y": {"$elemMatch": {"$eq": 4} }}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "z" : [ { "$numberInt" : "8" } ], "x" : [ { "$numberInt" : "3" } ], "y" : [ { "$numberInt" : "4" } ] } (1 row) -- Exclusions projection - elemMatch follows document order SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "e": 0, "d": 0 }', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "11" } ], "b" : [ { "$numberInt" : "51" } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "e": 0}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "11" }, { "$numberInt" : "21" }, { "$numberInt" : "31" } ], "b" : [ { "$numberInt" : "51" } ], "d" : { "$numberInt" : "71" } } (1 row) -- should error SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "e": 1, "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "d": 0 }', '{}' ); ERROR: exclusion cannot be applied to field d within the inclusion projection. -- various predicates SELECT * FROM bson_dollar_project_find( '{"x": [{"a": 1}, {"a": 180}, {"a": 4}]}', '{"x": {"$elemMatch": {"$or": [{"a": {"$eq": 4}}, {"$and": [{"a": {"$mod": [12, 0]}}, {"a": {"$mod": [15, 0]}}]}]}}}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "x" : [ { "a" : { "$numberInt" : "180" } } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{"x": [{"a": 1, "b": 2}, {"a": 2, "c": 3}, {"a": 1, "d": 5}], "y": [{"aa": 1, "bb": 2}, {"aa": 2, "cc": 3}, {"aa": 1, "dd": 5}]}', '{"x": {"$elemMatch": {"d": {"$exists": true}}}}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "x" : [ { "a" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "5" } } ] } (1 row) SELECT * FROM bson_dollar_project_find( '{"x": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}', '{"x": {"$elemMatch": {"$elemMatch": {"$gt": 5, "$lt": 7}}}}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "x" : [ [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] ] } (1 row) -- Multiple elemMatch projections SELECT * FROM bson_dollar_project_find( '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}', '{"z": {"$elemMatch": {"$eq": 8} }, "x": {"$elemMatch": {"$eq": 3} }, "y": {"$elemMatch": {"$eq": 4} }}', '{}' ); bson_dollar_project_find --------------------------------------------------------------------- { "z" : [ { "$numberInt" : "8" } ], "x" : [ { "$numberInt" : "3" } ], "y" : [ { "$numberInt" : "4" } ] } (1 row) -- -- Error Cases -- $elemMatch on nested fields SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": {"b" : [ 11, 21, 31, 41 ], "z": "World" }}', '{"a.b": {"$elemMatch": {"$gt":25} } }', '{}'); ERROR: Cannot use $elemMatch projection on a nested field. SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": {"b" : [ 11, 21, 31, 41 ], "z": "World" }}', '{"a": {"b": {"$elemMatch": {"$gt":25} } } }', '{}'); ERROR: Cannot use $elemMatch projection on a nested field. -- When positional and elemMatch projection are given together SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"$gt": 15} }, "b.$": 1 }', '{ "a": {"$elemMatch": {"$gt": 15} } }' ); ERROR: Positional operator cannot be used together with $elemMatch. SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b.$": 1, "a": {"$elemMatch": {"$gt": 15} } }', '{ "a": {"$elemMatch": {"$gt": 15} } }' ); ERROR: Positional operator cannot be used together with $elemMatch. -- $jsonSchema doesn't work with projection $elemMatch SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"$jsonSchema": {}} } }', '{ }' ); ERROR: $jsonSchema usage is not permitted in this specific context -- This is a bad place for jsonSchema spec, because $jsonSchema comes at top level field SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"b" : {"$jsonSchema": {}} } } }', '{ }' ); ERROR: Unrecognized operator specified: $jsonSchema --unresolved fields select bson_dollar_project_find('{"_id":"1", "a" :[[1],[2],[3],[4]]}', '{"c" : { "$elemMatch" : {}}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1" } (1 row) select bson_dollar_project_find('{"_id":"1", "a" :[1,2,3,4]}', '{"a" : { "$elemMatch" : {"$gt" : 1}}, "c" : { "$elemMatch" : {}}}',NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : "1", "a" : [ { "$numberInt" : "2" } ] } (1 row) bson_projection_operator_positional_tests_core.out000066400000000000000000000515761507310017400423450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 270000; SET documentdb.next_collection_id TO 2700; SET documentdb.next_collection_index_id TO 2700; -- Invalid scenarios SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 1, "b.$": 1}', '{}'); ERROR: More than one positional projection cannot be specified within a single query. SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a..$": 1}', '{}'); ERROR: The FieldPath cannot terminate with a '.' character. SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$slice": 1}}', '{}'); ERROR: Positional projection is not allowed when applied to an expression or sub object SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 0}', '{}'); ERROR: Exclusion is not compatible with positional projection usage SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": [1,2,3]}', '{}'); ERROR: Positional projection is not applicable when working with a literal value SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": "Hello"}', '{}'); ERROR: Positional projection is not applicable when working with a literal value SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "0"}}', '{}'); ERROR: Exclusion is not compatible with positional projection usage SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a": 1, "a.$": 1 }', '{}'); ERROR: Collision detected in specified path a SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b": 1, "a.b.$": 1 }', '{}'); ERROR: Collision detected in specified path a.b SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a": 1, "a.b.$": 1 }', '{}'); ERROR: Collision detected in specified path a.b remaining portion b SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 1, "a": 1 }', '{}'); ERROR: Collision detected in specified path a SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b.$": 1, "a.b": 1 }', '{}'); ERROR: Collision detected in specified path a.b SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b": 1, "a.$": 1 }', '{}'); ERROR: Collision detected in specified path a -- some basic positional projection test SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "Infinity"}}', '{"a": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "NaN"}}', '{"a": 2}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 2}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 3}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "3" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [6,5,4] }', '{ "a.$": 1}', '{"b": 6}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": 1, "c": 8, "b": 5}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : [ { "$numberInt" : "5" } ] } (1 row) -- with $and SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$and": [{"a": 1}, {"c": 8}, {"b": 5}]}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "5" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$and": [{"a": 2}, {"a": 3}, {"a": 1}]}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "6" } ] } (1 row) -- with $nor and $not and complex $or - Error SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$nor": [{"a": 1}, {"c": 8}, {"b": 5}]}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$not": {"$eq": 3}}}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": 3}, {"b": 6}]}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": {"$gte": 1}}, {"a": {"$lt": 3}}]}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array -- with $in SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$in": [1,2,3]}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "6" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$in": [4,5,3]}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "4" } ] } (1 row) -- $or with simple expressions converted to $in SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": 2}, {"a": 3}, {"a": 1}]}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "6" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": {"$in": [3]}}, {"a": {"$in": [2]}}, {"a": {"$in": [1]}}]}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "6" } ] } (1 row) -- positional with various conditions SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$eq": 2}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "5" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[[1],[2],[3]], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$elemMatch": {"$eq": 3}}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[[1,2], [3,4]], "b": [[5,6], [7,8]], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$elemMatch": {"$eq": 3}}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ [ { "$numberInt" : "7" }, { "$numberInt" : "8" } ] ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[{"b": [1,2,3]}, {"b": [4,5,6]}, {"b": [7,8,9]}], "c": [10, 11, 12] }', '{ "c.$": 1}', '{"a": {"$elemMatch": {"b": {"$elemMatch": {"$eq": 6}}}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "c" : [ { "$numberInt" : "11" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "x": [{"y": 1}, {"y": 2}, {"y": 3}] }', '{ "x.$": 1}', '{"x": {"$elemMatch": {"y": {"$gt": 1}}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "x" : [ { "y" : { "$numberInt" : "2" } } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1, {"b": [4,5,6]}, {"b": [7,8,9]}], "c": [10, 11, 12] }', '{ "c.$": 1}', '{"a": {"$elemMatch": {}}}'); bson_dollar_project_find --------------------------------------------------------------------- { "c" : [ { "$numberInt" : "11" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$type": "int"}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "6" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,"string"], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$type": "string"}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "4" } ] } (1 row) SELECT * FROM bson_dollar_project_find('{ "a" :[{"c": 1}, {"c": 2}, {"b": 3}], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a.b": {"$exists": true}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : [ { "$numberInt" : "4" } ] } (1 row) -- non existent fields SELECT * FROM bson_dollar_project_find('{"x": [{"a": 1, "b": 2}, {"a": 2, "c": 3}, {"a": 1, "d": 5}], "y": [{"aa": 1, "bb": 2}, {"aa": 2, "cc": 3}, {"aa": 1, "dd": 5}]}', '{"g.$": 1}', '{}'); bson_dollar_project_find --------------------------------------------------------------------- { } (1 row) -- positional on non array fields SELECT * FROM bson_dollar_project_find('{ "a" :[{"c": 1}, {"c": 2}, {"b": 3}], "b": 25, "c": [7,8,9] }', '{ "b.$": 1}', '{"a.b": {"$exists": true}}'); bson_dollar_project_find --------------------------------------------------------------------- { "b" : { "$numberInt" : "25" } } (1 row) -- on nested path SELECT * FROM bson_dollar_project_find('{"x": [-1, 1, 2], "a": {"b": {"d": [1,2,3]}, "f": 456}, "e": 123}', '{"a.b.c.$": 1}', '{"x": {"$gt": 0}}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : { "b" : { } } } (1 row) SELECT * FROM bson_dollar_project_find('{"x": {"y": [{"a": 1, "b": 1}, {"a": 1, "b": 2}]}}', '{"x.y.$": 1}', '{"x.y.a": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "x" : { "y" : [ { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } ] } } (1 row) SELECT * FROM bson_dollar_project_find('{"x": [1], "a": [{"b":[[[{"c": 1, "d": 2}]]]}]}', '{"a.b.c.$": 1}', '{"x": 1}'); -- Only relevant path is included bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "b" : [ [ [ { "c" : { "$numberInt" : "1" } } ] ] ] } ] } (1 row) -- in a nested path match the query on the first array and include only the fields requested in positional SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": [{"b": {"c": [1,2,3]}}, {"b": {"c": [4,5,6]}}, {"b": {"c": [7,8,9]}}]}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : [ { "b" : { "c" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } ] } (1 row) SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": {"b": [{"c": [1,2,3]}, {"c": [4,5,6]}, {"c": [7,8,9]}]}}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : { "b" : [ { "c" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } ] } } (1 row) SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": {"b": {"c": [1,2,3]}}}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); bson_dollar_project_find --------------------------------------------------------------------- { "a" : { "b" : { "c" : [ { "$numberInt" : "2" } ] } } } (1 row) -- errors if no match found or matched index is greater than size of array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [4,5,6,7] }', '{ "a.$": 1}', '{"b": 2}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [4,5,6,7] }', '{ "a.$": 1}', '{"b": 7}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' element mismatch -- Test with multiple docs BEGIN; SELECT documentdb_api.insert_one('db','positionalProjection', '{"_id": 1, "a" : { "b" : [{"c": 1, "d": 1}, {"c": 2, "d": 2}]}, "x": [1,2]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','positionalProjection', '{"_id": 2, "a" : { "b" : {"c": [11, 12], "d": [13, 14]} }, "x": [1,2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_project_find(document, '{"a.b.c.$": 1}', '{"x": 2}') FROM documentdb_api.collection('db', 'positionalProjection') WHERE document @@ '{ "x": 2}' ORDER BY object_id; bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "c" : { "$numberInt" : "2" } } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "c" : [ { "$numberInt" : "12" } ] } } } (2 rows) ROLLBACK; -- Empty or null query Spec SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "a.$": 1}', NULL); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "a.$": 1}', '{}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.c.d.$": 1}', NULL); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.c.d.$": 1}', '{}'); ERROR: Executor error during find command :: caused by :: positional operator '.$' couldn't find a matching element in the array -- Empty or null with non array spec field works SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.$": 1}', NULL); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "c" : [ { "d" : { "$numberInt" : "1" }, "e" : { "$numberInt" : "2" } } ] } } (1 row) SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": {"d": 1, "e": 2}} }', '{ "b.c.d.$": 1}', '{}'); bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "c" : { "d" : { "$numberInt" : "1" } } } } (1 row) -- $project and $addFields doesn't support positional, TODO throw native mongo error for $project SELECT * FROM bson_dollar_project('{ "_id": 1, "a" :[{ "b": {"c": [1,3,2]}, "d": {"e": [4,5,6]}}]} ', '{"a.b.c.$": 1 }'); ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT bson_dollar_add_fields('{"a": {"b": [1,2,3]}}', '{ "a.b.$" : "1", "a.y": ["p", "q"]}'); ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. --sharded collection tests BEGIN; -- Insert data into a new collection to be sharded SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 0, "key": {"a": "b"}, "a" : [{"b": 1, "c": 1}, {"b": 1, "c": 2}], "x":[11,12,13] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 1, "key": {"a": "b"}, "a" : [{"b": {"c": 1}}, {"b": {"c": 2}}], "x":[11,12,13] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 2, "key": {"b": "c"}, "a" : { "b": [{"c": 1, "d": 1}, {"c": 2, "d": 2}] }, "x":[11,12,13] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 3, "key": {"c": "d"}, "a" : { "b": {"c": [{"d": 1, "d": 2}], "e": [1,2,3]} }, "x":[11,12,13] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Shard orders collection on key SELECT documentdb_api.shard_collection('db','positional_sharded', '{"key":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT bson_dollar_project_find(document, '{"a.b.c.$": 1}', '{"x": 11}') FROM documentdb_api.collection('db', 'positional_sharded') WHERE document @@ '{ "x": 11}' ORDER BY object_id; bson_dollar_project_find --------------------------------------------------------------------- { "_id" : { "$numberInt" : "0" }, "a" : [ { } ] } { "_id" : { "$numberInt" : "1" }, "a" : [ { "b" : { "c" : { "$numberInt" : "1" } } } ] } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "c" : { "$numberInt" : "1" } } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "c" : [ { "d" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" } } ] } } } (4 rows) ROLLBACK; bson_query_disable_seqscan_tests.out000066400000000000000000000111021507310017400373270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 730000; SET documentdb.next_collection_id TO 7300; SET documentdb.next_collection_index_id TO 7300; SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 1, "a": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 2, "a": -500 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 3, "a": { "$numberLong": "1000" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 4, "a": true }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 5, "a": "some string" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 6, "a": { "b": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 7, "a": { "$date": {"$numberLong": "123456"} } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) set documentdb.forceDisableSeqScan to on; -- should fail SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "a": { "$eq": 1 } } }'); ERROR: Could not find any valid index to push down for query SELECT documentdb_api_internal.create_indexes_non_concurrently('seqscandb', '{ "createIndexes": "seqscandistest", "indexes": [ { "key": { "a": 1 }, "name": "idx_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- fail to push down SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "b": { "$eq": 1 } } }'); ERROR: Could not find any valid index to push down for query SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest" }'); ERROR: Could not find any valid index to push down for query -- passes SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "a": { "$eq": 1 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "_id": { "$gt": 4 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : "some string" } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "7" }, "a" : { "$date" : { "$numberLong" : "123456" } } } (3 rows) bson_query_index_selection_sharded_tests.out000066400000000000000000000270501507310017400410660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3610000; SET documentdb.next_collection_id TO 3610; SET documentdb.next_collection_index_id TO 3610; -- insert 10K documents SELECT COUNT (*) FROM ( SELECT documentdb_api.insert_one('db', 'test_index_selection_sharded', FORMAT('{ "a": { "b": %s, "c": %s } }', i, i)::bson) FROM generate_series(1, 10000) i) r1; NOTICE: creating collection count --------------------------------------------------------------------- 10000 (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'test_index_selection_sharded'); drop_primary_key --------------------------------------------------------------------- (1 row) -- create indexes on a.b, and a.c SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_index_selection_sharded", "indexes": [ { "name": "a_b_1", "key": { "a.b": 1 } }, { "name": "a_c_1", "key": { "a.c": 1 }}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Now, do an explain with an OR query that each uses 1 of the indexes. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_3610_3610002 collection WHERE (((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '3610'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_3610_3610002 collection Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on a_b_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_c_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) (15 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$and": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_3610_3610002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '3610'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_3610_3610002 collection Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson)) -> BitmapAnd -> Bitmap Index Scan on a_c_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_b_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) (15 rows) BEGIN; set local citus.enable_local_execution to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_3610_3610002 collection WHERE (((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '3610'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_3610_3610002 collection Output: document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on a_b_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_c_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) (15 rows) ROLLBACK; -- Now shard the collection SELECT documentdb_api.shard_collection('db', 'test_index_selection_sharded', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- rerun the query BEGIN; set local enable_seqscan to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_3610_3610016 documents_3610 WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_3610_3610016 documents_3610 Output: document Recheck Cond: ((documents_3610.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) OR (documents_3610.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on a_b_1 Index Cond: (documents_3610.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_c_1 Index Cond: (documents_3610.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) (15 rows) SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$and": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_3610_3610016 documents_3610 WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_3610_3610016 documents_3610 Output: document Recheck Cond: (documents_3610.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) Filter: (documents_3610.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "500" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_c_1 Index Cond: (documents_3610.document OPERATOR(documentdb_api_catalog.@<) '{ "a.c" : { "$numberInt" : "10" } }'::documentdb_core.bson) (13 rows) ROLLBACK; bson_query_modifier_orderby_tests_explain_index.out000066400000000000000000000361261507310017400424570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_api_catalog; SET citus.next_shard_id TO 3400000; SET documentdb.next_collection_id TO 3400; SET documentdb.next_collection_index_id TO 3400; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsoexplainnorderby'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.create_collection('db', 'bsoexplainnorderby'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsoexplainnorderby'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsoexplainnorderby', 'index_2', '{"a.b": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsoexplainnorderby', 'index_3', '{"a.b.1": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; set local citus.enable_local_execution TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_modifier_orderby_tests_explain_core.sql set search_path to documentdb_api_catalog, documentdb_core, documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Seq Scan on documents_3400_3400001 collection (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Index Scan using index_2 on documents_3400_3400001 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Index Scan using index_2 on documents_3400_3400001 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a": { "$gte": { "b": 0 } } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Seq Scan on documents_3400_3400001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "0" } } }'::documentdb_core.bson) (9 rows) ROLLBACK; bson_query_modifier_orderby_tests_explain_runtime.out000066400000000000000000000372601507310017400430330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedset search_path to documentdb_api_catalog; SET citus.next_shard_id TO 3400000; SET documentdb.next_collection_id TO 3400; SET documentdb.next_collection_index_id TO 3400; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsoexplainnorderby'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.create_collection('db', 'bsoexplainnorderby'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) BEGIN; set enable_seqscan to on; set local citus.enable_local_execution TO OFF; \i sql/bson_query_modifier_orderby_tests_explain_core.sql set search_path to documentdb_api_catalog, documentdb_core, documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": -1 }') DESC; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "-1" } }'::documentdb_core.bson)) DESC -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (11 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.0" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b.0" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)), (documentdb_api_catalog.bson_orderby(document, '{ "a.b.1" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "0" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a": { "$gte": { "b": 0 } } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Heap Scan on documents_3400_3400001 collection Recheck Cond: (shard_key_value = '3400'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "0" } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '3400'::bigint) (12 rows) ROLLBACK; bson_query_modifier_orderby_tests_index.out000066400000000000000000001275571507310017400407500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3500000; SET documentdb.next_collection_id TO 3500; SET documentdb.next_collection_index_id TO 3500; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsonorderby'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.create_collection('db', 'bsonorderby'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsonorderby'); drop_primary_key --------------------------------------------------------------------- (1 row) \set prevEcho :ECHO \set ECHO none BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_modifier_orderby_tests_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$in": [ 0, 1, 2, 3 ] } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) PREPARE q1(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1); PREPARE q1desc(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1) DESC; EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) -- now insert items that are sorted "After" arrays (e.g. boolean) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 14, "a" : [ { "b": [ true, false ] }, { "b": [ true ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 15, "a" : { "b": [ [ true, false], [ false, true ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 16, "a" : { "b": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- doesn't consider the array itself but considers nested arrays. SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "b" : [ [ true, false ], [ false, true ] ] } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : [ { "b" : [ true, false ] }, { "b" : [ true ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "b" : true } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : [ { "b" : [ true, false ] }, { "b" : [ true ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "b" : true } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "b" : [ [ true, false ], [ false, true ] ] } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (8 rows) -- sort order across types (see sorta.js). SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 0, "a": { "$minKey": 1 } }'); psql:sql/bson_query_modifier_orderby_tests_core.sql:61: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 3, "a": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 1, "a": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 7, "a": [ 2 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 5, "a": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 2, "a": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 6, "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 8, "a": { "$maxKey": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'sortordertests') ORDER BY bson_orderby(document, '{ "a": 1 }'), object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } | { "_id" : { "$numberInt" : "0" }, "a" : { "$minKey" : 1 } } { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ ] } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : [ ] } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : null } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$maxKey" : 1 } } (9 rows) SELECT bson_orderby('{ "b": 1 }', '{ "b": -1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": 1 }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": -1 }') = '{ "b": { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": 1 }') = '{ "b": { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 2 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": -1 }') = '{ "b": 3 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": -1 }') = '{ "b": true }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": 1 }') = '{ "b": false }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": -1 }') = '{ "b": [3] }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": 1 }') = '{ "b": [1] }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": -1 }') = '{ "b": true }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, { "c": 2 }, "someString" ] }', '{ "b.c": -1 }') = '{ "b.c": 2 }'; ?column? --------------------------------------------------------------------- t (1 row) ROLLBACK; bson_query_modifier_orderby_tests_runtime.out000066400000000000000000001273551507310017400413200ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3500000; SET documentdb.next_collection_id TO 3500; SET documentdb.next_collection_index_id TO 3500; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsonorderby'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.create_collection('db', 'bsonorderby'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsonorderby'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set enable_seqscan to off; \i sql/bson_query_modifier_orderby_tests_core.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": 1 }') ASC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$in": [ 0, 1, 2, 3 ] } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (4 rows) PREPARE q1(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1); PREPARE q1desc(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1) DESC; EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) EXECUTE q1desc('{ "a.b.0": -1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (5 rows) EXECUTE q1('{ "a.b.0": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } (5 rows) -- now insert items that are sorted "After" arrays (e.g. boolean) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 14, "a" : [ { "b": [ true, false ] }, { "b": [ true ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 15, "a" : { "b": [ [ true, false], [ false, true ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 16, "a" : { "b": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- doesn't consider the array itself but considers nested arrays. SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "b" : [ [ true, false ], [ false, true ] ] } } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : [ { "b" : [ true, false ] }, { "b" : [ true ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "b" : true } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : [ { "b" : [ true, false ] }, { "b" : [ true ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : { "b" : true } } { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "a" : { "b" : [ [ true, false ], [ false, true ] ] } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "b" : { "$numberInt" : "1" } } } (8 rows) -- sort order across types (see sorta.js). SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 0, "a": { "$minKey": 1 } }'); psql:sql/bson_query_modifier_orderby_tests_core.sql:61: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 3, "a": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 1, "a": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 7, "a": [ 2 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 5, "a": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 2, "a": [] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 6, "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 8, "a": { "$maxKey": 1 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'sortordertests') ORDER BY bson_orderby(document, '{ "a": 1 }'), object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "0" } } | { "_id" : { "$numberInt" : "0" }, "a" : { "$minKey" : 1 } } { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ ] } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : [ ] } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : null } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : { "$maxKey" : 1 } } (9 rows) SELECT bson_orderby('{ "b": 1 }', '{ "b": -1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": 1 }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": -1 }') = '{ "b": { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": 1 }') = '{ "b": { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 2 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": -1 }') = '{ "b": 3 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": -1 }') = '{ "b": true }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": 1 }') = '{ "b": false }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": -1 }') = '{ "b": [3] }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": 1 }') = '{ "b": [1] }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": -1 }') = '{ "b": true }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": 1 }') = '{ "b": 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_orderby('{ "b": [ 1, { "c": 2 }, "someString" ] }', '{ "b.c": -1 }') = '{ "b.c": 2 }'; ?column? --------------------------------------------------------------------- t (1 row) ROLLBACK; bson_query_operator_array_tests_index_composite.out000066400000000000000000000562611507310017400425300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 380000; SET documentdb.next_collection_id TO 3800; SET documentdb.next_collection_index_id TO 3800; set enable_seqscan TO off; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to on; SELECT documentdb_api.drop_collection('array_query_db', 'array_operator_tests') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('array_query_db', '{ "createIndexes": "array_operator_tests", "indexes": [ { "key": { "value": 1 }, "enableCompositeTerm": true, "name": "queryoperator_value" }, { "key": { "value.subfield": 1 }, "enableCompositeTerm": true, "name": "queryoperator_value_subfield" }] }', true) IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) \i sql/bson_query_operator_array_tests_core.sql -- some documents with mixed types SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 1, "value": 42 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 2, "value": -999 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 3, "value": { "longNum": "2048" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 4, "value": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 5, "value": "alpha beta" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 6, "value": { "subfield": 7 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 7, "value": { "dateField": { "longNum": "654321" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some documents with arrays with those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 100, "value": [ 42, "bravo charlie", false ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 101, "value": [ false, -999, { "subfield": 7 }, 8, 9, 10 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 102, "value": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some documents with arrays of arrays of those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 200, "value": [ 42, [ false, "alpha beta" ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 201, "value": [ false, -999, { "subfield": 7 }, [ 42, "bravo charlie", false ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 202, "value": [ [ false, -999, { "subfield": 7 }, 8, 9, 10 ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert empty arrays SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 300, "value": [ ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 301, "value": [ [], "zuluValue" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (6 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (7 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lt": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (8 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lte": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (8 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ 42, [ false, "alpha beta" ] ] ]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ ] ]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (4 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 3 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 2 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 0 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "value" : [ ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42, false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42 ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "value" : { "$numberInt" : "42" } } { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } (4 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 0 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 8, "$lt": 10 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "$gt": 8, "$lt": 10 } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "subfield": { "$gt": 0 } } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) bson_query_operator_array_tests_runtime.out000066400000000000000000000556571507310017400410320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 661000; SET documentdb.next_collection_id TO 6610; SET documentdb.next_collection_index_id TO 6610; set enable_seqscan TO on; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to off; SELECT documentdb_api.drop_collection('array_query_db', 'array_operator_tests') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('array_query_db', 'array_operator_tests') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) \i sql/bson_query_operator_array_tests_core.sql -- some documents with mixed types SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 1, "value": 42 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 2, "value": -999 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 3, "value": { "longNum": "2048" } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 4, "value": false }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 5, "value": "alpha beta" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 6, "value": { "subfield": 7 } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 7, "value": { "dateField": { "longNum": "654321" } } }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some documents with arrays with those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 100, "value": [ 42, "bravo charlie", false ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 101, "value": [ false, -999, { "subfield": 7 }, 8, 9, 10 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 102, "value": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now insert some documents with arrays of arrays of those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 200, "value": [ 42, [ false, "alpha beta" ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 201, "value": [ false, -999, { "subfield": 7 }, [ 42, "bravo charlie", false ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 202, "value": [ [ false, -999, { "subfield": 7 }, 8, 9, 10 ] ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert empty arrays SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 300, "value": [ ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 301, "value": [ [], "zuluValue" ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (6 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ 42, "bravo charlie", false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (7 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lt": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (8 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lte": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "202" }, "value" : [ [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (8 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ 42, [ false, "alpha beta" ] ] ]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ ] ]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } { "_id" : { "$numberInt" : "300" }, "value" : [ ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (4 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 3 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 2 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } { "_id" : { "$numberInt" : "301" }, "value" : [ [ ], "zuluValue" ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 0 } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "value" : [ ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42, false ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42 ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "value" : { "$numberInt" : "42" } } { "_id" : { "$numberInt" : "100" }, "value" : [ { "$numberInt" : "42" }, "bravo charlie", false ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "200" }, "value" : [ { "$numberInt" : "42" }, [ false, "alpha beta" ] ] } (4 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 0 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } (2 rows) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 8, "$lt": 10 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "$gt": 8, "$lt": 10 } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "subfield": { "$gt": 0 } } } } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } { "_id" : { "$numberInt" : "102" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, { "$numberInt" : "42" }, { "$numberInt" : "99" }, { "dateField" : { "longNum" : "654321" } } ] } { "_id" : { "$numberInt" : "201" }, "value" : [ false, { "$numberInt" : "-999" }, { "subfield" : { "$numberInt" : "7" } }, [ { "$numberInt" : "42" }, "bravo charlie", false ] ] } (3 rows) bson_query_operator_elemmatch_explain_composite.out000066400000000000000000000460421507310017400424540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1064000; SET documentdb.next_collection_id TO 10640; SET documentdb.next_collection_index_id TO 10640; set enable_seqscan TO on; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to off; SELECT documentdb_api.drop_collection('comp_elmdb', 'cmp_elemmatch_ops') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('comp_elmdb', 'cmp_elemmatch_ops') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_elmdb', '{ "createIndexes": "cmp_elemmatch_ops", "indexes": [ { "key": { "price": 1 }, "name": "price_1", "enableCompositeTerm": true }, { "key": { "brands": 1 }, "name": "brands_1", "enableCompositeTerm": true } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_elmdb', '{ "createIndexes": "cmp_elemmatch_ops", "indexes": [ { "key": { "brands.name": 1 }, "name": "brands.name_1", "enableCompositeTerm": true }, { "key": { "brands.rating": 1 }, "name": "brands.rating_1", "enableCompositeTerm": true } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 1, "price": [ 120, 150, 100 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 2, "price": [ 110, 140, 160 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- pushes to the price index set documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$gt": 120, "$lt": 150 } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: price_1 isMultiKey: true indexBounds: ["price": (120, 150)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Filter: (document @#? '{ "price" : { "$gt" : { "$numberInt" : "120" }, "$lt" : { "$numberInt" : "150" } } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on price_1 (actual rows=1 loops=1) Index Cond: (document @<> '{ "price" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "2" }, "value" : { "$numberInt" : "120" }, "isTopLevel" : true }, { "op" : { "$numberInt" : "4" }, "value" : { "$numberInt" : "150" }, "isTopLevel" : true } ] } }'::bson) (12 rows) -- without the GUC becomes a disjoint index filter set documentdb.useNewElemMatchIndexOperatorOnPushdown to off; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$gt": 120, "$lt": 150 } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: price_1 isMultiKey: true indexBounds: ["price": (120, Infinity]], ["price": [-Infinity, 150)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 3), (isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Filter: (document @#? '{ "price" : { "$gt" : { "$numberInt" : "120" }, "$lt" : { "$numberInt" : "150" } } }'::bson) Rows Removed by Filter: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on price_1 (actual rows=2 loops=1) Index Cond: ((document @> '{ "price" : { "$numberInt" : "120" } }'::bson) AND (document @< '{ "price" : { "$numberInt" : "150" } }'::bson)) (13 rows) reset documentdb.useNewElemMatchIndexOperatorOnPushdown; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$in": [ 120, 140 ], "$gt": 121 } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: price_1 isMultiKey: true indexBounds: ["price": (121, 120]], ["price": [140, 140]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Filter: (document @#? '{ "price" : { "$in" : [ { "$numberInt" : "120" }, { "$numberInt" : "140" } ], "$gt" : { "$numberInt" : "121" } } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on price_1 (actual rows=1 loops=1) Index Cond: (document @<> '{ "price" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "6" }, "value" : [ { "$numberInt" : "120" }, { "$numberInt" : "140" } ], "isTopLevel" : true }, { "op" : { "$numberInt" : "2" }, "value" : { "$numberInt" : "121" }, "isTopLevel" : true } ] } }'::bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$type": "number" } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: price_1 isMultiKey: true indexBounds: ["price": [-Infinity, Infinity]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=2 loops=1) Filter: (document @#? '{ "price" : { "$type" : "number" } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on price_1 (actual rows=2 loops=1) Index Cond: (document @<> '{ "price" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "12" }, "value" : "number", "isTopLevel" : true } ] } }'::bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$ne": 160 } } } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '10641'::bigint) Filter: (document @#? '{ "price" : { "$ne" : { "$numberInt" : "160" } } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=2 loops=1) Index Cond: (shard_key_value = '10641'::bigint) (6 rows) EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$nin": [ 160, 110, 140] } } } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '10641'::bigint) Filter: (document @#? '{ "price" : { "$nin" : [ { "$numberInt" : "160" }, { "$numberInt" : "110" }, { "$numberInt" : "140" } ] } }'::bson) Rows Removed by Filter: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=2 loops=1) Index Cond: (shard_key_value = '10641'::bigint) (7 rows) -- now test some with nested objects SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 3, "brands": [ { "name" : "alpha", "rating" : 5 }, { "name" : "beta", "rating" : 3 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 4, "brands": [ { "name" : "alpha", "rating" : 4 }, { "name" : "beta", "rating" : 2 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 5, "brands": [ { "name" : "alpha", "rating" : 2 }, { "name" : "beta", "rating" : 4 } ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": "alpha", "rating": 2 } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: brands.rating_1 isMultiKey: true indexBounds: ["brands.rating": [2, 2]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Filter: (document @#? '{ "brands" : { "name" : "alpha", "rating" : { "$numberInt" : "2" } } }'::bson) Rows Removed by Filter: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on "brands.rating_1" (actual rows=2 loops=1) Index Cond: (document @<> '{ "brands.rating" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : { "$numberInt" : "2" }, "isTopLevel" : false } ] } }'::bson) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": "alpha" } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: brands.name_1 isMultiKey: true indexBounds: ["brands.name": ["alpha", "alpha"]] innerScanLoops: 3 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 3)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=3 loops=1) Filter: (document @#? '{ "brands" : { "name" : "alpha" } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on "brands.name_1" (actual rows=3 loops=1) Index Cond: (document @<> '{ "brands.name" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "alpha", "isTopLevel" : false } ] } }'::bson) (12 rows) -- test elemMatch behavior when confronted with multiple arrays SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 6, "brands": [ { "name": [ "gurci", "dolte" ], "rating": 5 } ]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this technically matches the doc 6 above and the elemMatches don't get joined. EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": { "$gt": "gabba", "$lt": "ergo" } } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: brands.name_1 isMultiKey: true indexBounds: ["brands.name": ("gabba", { })], ["brands.name": ["", "ergo")] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Filter: (document @#? '{ "brands" : { "name" : { "$gt" : "gabba", "$lt" : "ergo" } } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on "brands.name_1" (actual rows=1 loops=1) Index Cond: (document @<> '{ "brands.name" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "2" }, "value" : "gabba", "isTopLevel" : false }, { "op" : { "$numberInt" : "4" }, "value" : "ergo", "isTopLevel" : false } ] } }'::bson) (12 rows) -- this can now join the elemMatch filters EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands.name": { "$elemMatch": { "$gt": "gabba", "$lt": "ergo" } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: brands.name_1 isMultiKey: true indexBounds: ["brands.name": ("gabba", "ergo")] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=0 loops=1) Filter: (document @#? '{ "brands.name" : { "$gt" : "gabba", "$lt" : "ergo" } }'::bson) -> Bitmap Index Scan on "brands.name_1" (actual rows=0 loops=1) Index Cond: (document @<> '{ "brands.name" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "2" }, "value" : "gabba", "isTopLevel" : true }, { "op" : { "$numberInt" : "4" }, "value" : "ergo", "isTopLevel" : true } ] } }'::bson) (11 rows) -- disjoint filter handling for elemMatch and non elemMatch: this matches a document since these are matching different elements of the array. EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$eq": 110, "$elemMatch": { "$gt": 155, "$lt": 165 } } } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: price_1 isMultiKey: true indexBounds: ["price": [110, 110]], ["price": (155, 165)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 1), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_10641_1064002 collection (actual rows=1 loops=1) Recheck Cond: (document @= '{ "price" : { "$numberInt" : "110" } }'::bson) Filter: (document @#? '{ "price" : { "$gt" : { "$numberInt" : "155" }, "$lt" : { "$numberInt" : "165" } } }'::bson) Heap Blocks: exact=1 -> Bitmap Index Scan on price_1 (actual rows=1 loops=1) Index Cond: ((document @= '{ "price" : { "$numberInt" : "110" } }'::bson) AND (document @<> '{ "price" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "2" }, "value" : { "$numberInt" : "155" }, "isTopLevel" : true }, { "op" : { "$numberInt" : "4" }, "value" : { "$numberInt" : "165" }, "isTopLevel" : true } ] } }'::bson)) (13 rows) bson_query_operator_elemmatch_tests_explain_index.out000066400000000000000000001101231507310017400427730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 720000; SET documentdb.next_collection_id TO 7200; SET documentdb.next_collection_index_id TO 7200; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('elemmatchtest', 'index_2', '{"$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_elemmatch_tests_explain_core.sql /* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 10, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 12, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 13, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- run an explain analyze EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 155 bytes Tasks Shown: All -> Task Tuple data received from node: 155 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 63 bytes Tasks Shown: All -> Task Tuple data received from node: 63 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$in" : [ { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$in" : [ { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 453 bytes Tasks Shown: All -> Task Tuple data received from node: 453 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$nin" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$nin" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 70 bytes Tasks Shown: All -> Task Tuple data received from node: 70 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$eq" : { "b" : [ { "$numberInt" : "18" } ] } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$eq" : { "b" : [ { "$numberInt" : "18" } ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 190 bytes Tasks Shown: All -> Task Tuple data received from node: 190 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$exists" : false } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$exists" : false } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 77 bytes Tasks Shown: All -> Task Tuple data received from node: 77 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=7 loops=1) Task Count: 1 Tuple data received from nodes: 522 bytes Tasks Shown: All -> Task Tuple data received from node: 522 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=7 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 140 bytes Tasks Shown: All -> Task Tuple data received from node: 140 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$and" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$and" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 190 bytes Tasks Shown: All -> Task Tuple data received from node: 190 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$nor" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$nor" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 387 bytes Tasks Shown: All -> Task Tuple data received from node: 387 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$not" : { "$gt" : { "$numberInt" : "18" }, "$lte" : { "$numberInt" : "19" } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$not" : { "$gt" : { "$numberInt" : "18" }, "$lte" : { "$numberInt" : "19" } } } }'::documentdb_core.bson) (12 rows) -- elemMatch with Logical ops and non-logical op EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 63 bytes Tasks Shown: All -> Task Tuple data received from node: 63 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ], "b" : { "$numberInt" : "3" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 8 Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ], "b" : { "$numberInt" : "3" } } }'::documentdb_core.bson) (13 rows) /* Nested elemMatch */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 93 bytes Tasks Shown: All -> Task Tuple data received from node: 93 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "15" } } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "15" } } } } }'::documentdb_core.bson) (12 rows) -- NOTE: The explain plan can be confusin while printing for alias name for two adjacent elemMatch. In SubPlan 2, you will see it has alias elemmatchd2_1 created but using elemmatchd2 in filters. As per the query plan, filter qual is using attNumber=1 which is expected to refer its immediate RTE that will have :colnames ("elemmatchd2"). I have also tested using query: it is not possible that alias defined inside one EXISTS() be used outside of it and inside any other EXISTS(). EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 93 bytes Tasks Shown: All -> Task Tuple data received from node: 93 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" }, "$lte" : { "$numberInt" : "2" } } } }, "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "55" } } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" }, "$lte" : { "$numberInt" : "2" } } } }, "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "55" } } } } }'::documentdb_core.bson) (12 rows) /* Non $elemMatch expression and a nested $elemMatch. */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 100 bytes Tasks Shown: All -> Task Tuple data received from node: 100 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" } } } } } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" } } } } } }'::documentdb_core.bson)) (12 rows) /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ 100 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": { "0" : 100 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": { "0" : [ 100 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": [ { "0" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": [ { "0" : [ 100 ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "-1" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- below queries will use $type:array internally as first filter EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 62 bytes Tasks Shown: All -> Task Tuple data received from node: 62 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$elemMatch" : { "$in" : [ { "$numberInt" : "100" } ] } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$elemMatch" : { "$in" : [ { "$numberInt" : "100" } ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 166 bytes Tasks Shown: All -> Task Tuple data received from node: 166 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$numberInt" : "100" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$numberInt" : "100" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 166 bytes Tasks Shown: All -> Task Tuple data received from node: 166 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) (12 rows) -- below query will not use $type internally EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 49 bytes Tasks Shown: All -> Task Tuple data received from node: 49 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720001 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "-1" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on index_2 (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "-1" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) (12 rows) ROLLBACK; -- Shard the collection and run an explain analyze SELECT documentdb_api.shard_collection('db','elemmatchtest', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720016 documents_7200 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) (9 rows) SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7200_720016 documents_7200 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) -> Bitmap Index Scan on index_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) (9 rows) ROLLBACK; bson_query_operator_elemmatch_tests_explain_runtime.out000066400000000000000000000723141507310017400433600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 720000; SET documentdb.next_collection_id TO 7200; SET documentdb.next_collection_index_id TO 7200; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO on; set local citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; \i sql/bson_query_operator_elemmatch_tests_explain_core.sql /* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 10, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 12, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 13, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- run an explain analyze EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 155 bytes Tasks Shown: All -> Task Tuple data received from node: 155 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=2 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) Rows Removed by Filter: 10 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 63 bytes Tasks Shown: All -> Task Tuple data received from node: 63 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$in" : [ { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 453 bytes Tasks Shown: All -> Task Tuple data received from node: 453 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=6 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$nin" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) Rows Removed by Filter: 6 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 70 bytes Tasks Shown: All -> Task Tuple data received from node: 70 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$eq" : { "b" : [ { "$numberInt" : "18" } ] } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 190 bytes Tasks Shown: All -> Task Tuple data received from node: 190 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=3 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$exists" : false } } }'::documentdb_core.bson) Rows Removed by Filter: 9 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 77 bytes Tasks Shown: All -> Task Tuple data received from node: 77 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=7 loops=1) Task Count: 1 Tuple data received from nodes: 522 bytes Tasks Shown: All -> Task Tuple data received from node: 522 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=7 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Rows Removed by Filter: 5 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 140 bytes Tasks Shown: All -> Task Tuple data received from node: 140 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=2 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$and" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Rows Removed by Filter: 10 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 190 bytes Tasks Shown: All -> Task Tuple data received from node: 190 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=3 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$nor" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) Rows Removed by Filter: 9 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 387 bytes Tasks Shown: All -> Task Tuple data received from node: 387 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=5 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$not" : { "$gt" : { "$numberInt" : "18" }, "$lte" : { "$numberInt" : "19" } } } }'::documentdb_core.bson) Rows Removed by Filter: 7 (10 rows) -- elemMatch with Logical ops and non-logical op EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 63 bytes Tasks Shown: All -> Task Tuple data received from node: 63 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ], "b" : { "$numberInt" : "3" } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) /* Nested elemMatch */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 93 bytes Tasks Shown: All -> Task Tuple data received from node: 93 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "15" } } } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) -- NOTE: The explain plan can be confusin while printing for alias name for two adjacent elemMatch. In SubPlan 2, you will see it has alias elemmatchd2_1 created but using elemmatchd2 in filters. As per the query plan, filter qual is using attNumber=1 which is expected to refer its immediate RTE that will have :colnames ("elemmatchd2"). I have also tested using query: it is not possible that alias defined inside one EXISTS() be used outside of it and inside any other EXISTS(). EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 93 bytes Tasks Shown: All -> Task Tuple data received from node: 93 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" }, "$lte" : { "$numberInt" : "2" } } } }, "b" : { "$elemMatch" : { "$gte" : { "$numberInt" : "10" }, "$lt" : { "$numberInt" : "55" } } } } }'::documentdb_core.bson) Rows Removed by Filter: 11 (10 rows) /* Non $elemMatch expression and a nested $elemMatch. */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 100 bytes Tasks Shown: All -> Task Tuple data received from node: 100 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "d" : { "$elemMatch" : { "e" : { "$gte" : { "$numberInt" : "2" } } } } } }'::documentdb_core.bson)) Rows Removed by Filter: 11 (10 rows) /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ 100 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": { "0" : 100 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": { "0" : [ 100 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": [ { "0" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": [ { "0" : [ 100 ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "-1" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- below queries will use $type:array internally as first filter EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 62 bytes Tasks Shown: All -> Task Tuple data received from node: 62 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$elemMatch" : { "$in" : [ { "$numberInt" : "100" } ] } } }'::documentdb_core.bson) Rows Removed by Filter: 18 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 166 bytes Tasks Shown: All -> Task Tuple data received from node: 166 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=3 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$numberInt" : "100" } } }'::documentdb_core.bson) Rows Removed by Filter: 16 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 166 bytes Tasks Shown: All -> Task Tuple data received from node: 166 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=3 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "0" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) Rows Removed by Filter: 16 (10 rows) -- below query will not use $type internally EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 49 bytes Tasks Shown: All -> Task Tuple data received from node: 49 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720001 collection (actual rows=1 loops=1) Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "-1" : { "$gte" : { "$numberInt" : "100" } } } }'::documentdb_core.bson) Rows Removed by Filter: 18 (10 rows) ROLLBACK; -- Shard the collection and run an explain analyze SELECT documentdb_api.shard_collection('db','elemmatchtest', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO on; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720016 documents_7200 Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a.b" : { "$gte" : { "$numberInt" : "10" }, "$lte" : { "$numberInt" : "15" } } }'::documentdb_core.bson) (7 rows) SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7200_720016 documents_7200 Filter: (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "$or" : [ { "b" : { "$gte" : { "$numberInt" : "1" } } }, { "b" : { "$lt" : { "$numberInt" : "2" } } } ] } }'::documentdb_core.bson) (7 rows) ROLLBACK; bson_query_operator_elemmatch_tests_index.out000066400000000000000000001100441507310017400412550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 260000; SET documentdb.next_collection_id TO 2600; SET documentdb.next_collection_index_id TO 2600; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) \set prevEcho :ECHO \set ECHO none -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_elemmatch_tests_core.sql -- Test $elemMatch query operator /* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Simple comparison */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (6 rows) /* Comparison operator in elemMatch */ -- Comparison ops on same paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gte" : 1, "$lt" : 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gt" : 1, "$lte" : 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": null} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : [18]} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : 18} } }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : 18} } } }'; object_id | document --------------------------------------------------------------------- (0 rows) -- Comparison ops on different paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 1}, "c": 3} } }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$gte": 1, "$lte": 1 }, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$not": {"$elemMatch": {"b": 1, "c": 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 2}, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) /* Logical operator in elemMatch */ -- Logical ops on same path inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$or": [{"b": "1"}, {"c": 2}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$and" : [ { "a" : { "$elemMatch" : { "$gt" : 1, "$not" : { "$gt" : 2 } } } }]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$or" : [ {"a.b": {"$elemMatch": {"$eq": 10}}}, {"a.b": {"$elemMatch": {"$eq": 7}}}]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } (2 rows) -- elemMatch with Logical ops and non-logical op SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } (1 row) /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 21, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 22, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 23, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Nested elemMatch */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ], "d" : [ { "e" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ], "d" : [ { "e" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$in": [3] } } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ], "d" : [ { "e" : { "$numberInt" : "3" } } ], "f" : { "$numberInt" : "1" } } ] } (1 row) -- d.e being the path in nested elemMatch SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d.e": { "$elemMatch": { "$gte": 2, "$lte": 2 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : [ { "d" : [ { "e" : [ { "$numberInt" : "2" } ] } ] } ] } (1 row) /* Non $elemMatch expression and a nested $elemMatch. */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ], "d" : [ { "e" : { "$numberInt" : "3" } } ], "f" : { "$numberInt" : "1" } } ] } (1 row) /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ [ { "b" : 1 } ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": [ [ { "b" : [1] } ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": [ 100 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": { "0" : 100 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": { "0" : [ 100 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "0" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 38, "a": [ { "0" : [ 100 ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 39, "a": [ { "-1" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 40, "a": { "b" : [ [ 100, 200, 300 ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 41, "a": { "b" : [ { "c" : [100] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 42, "a": { "b" : [ { "c" : [[100]] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "40" } } | { "_id" : { "$numberInt" : "40" }, "a" : { "b" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "b" : { "$eq" : 1 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "32" } } | { "_id" : { "$numberInt" : "32" }, "a" : [ [ { "b" : { "$numberInt" : "1" } } ] ] } { "" : { "$numberInt" : "33" } } | { "_id" : { "$numberInt" : "33" }, "a" : [ [ { "b" : [ { "$numberInt" : "1" } ] } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } { "" : { "$numberInt" : "37" } } | { "_id" : { "$numberInt" : "37" }, "a" : [ { "0" : { "$numberInt" : "100" } } ] } { "" : { "$numberInt" : "38" } } | { "_id" : { "$numberInt" : "38" }, "a" : [ { "0" : [ { "$numberInt" : "100" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } { "" : { "$numberInt" : "37" } } | { "_id" : { "$numberInt" : "37" }, "a" : [ { "0" : { "$numberInt" : "100" } } ] } { "" : { "$numberInt" : "38" } } | { "_id" : { "$numberInt" : "38" }, "a" : [ { "0" : [ { "$numberInt" : "100" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "39" } } | { "_id" : { "$numberInt" : "39" }, "a" : [ { "-1" : { "$numberInt" : "100" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "40" } } | { "_id" : { "$numberInt" : "40" }, "a" : { "b" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } | { "_id" : { "$numberInt" : "41" }, "a" : { "b" : [ { "c" : [ { "$numberInt" : "100" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c.0" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "42" } } | { "_id" : { "$numberInt" : "42" }, "a" : { "b" : [ { "c" : [ [ { "$numberInt" : "100" } ] ] } ] } } (1 row) ROLLBACK; -- Invalid Arguments SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": [] }}'; ERROR: $elemMatch needs an Object bson_query_operator_elemmatch_tests_runtime.out000066400000000000000000001077131507310017400416420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 260000; SET documentdb.next_collection_id TO 2600; SET documentdb.next_collection_index_id TO 2600; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_elemmatch_tests_core.sql -- Test $elemMatch query operator /* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Simple comparison */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (6 rows) /* Comparison operator in elemMatch */ -- Comparison ops on same paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gte" : 1, "$lt" : 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gt" : 1, "$lte" : 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": null} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : [18]} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : 18} } }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : 18} } } }'; object_id | document --------------------------------------------------------------------- (0 rows) -- Comparison ops on different paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 1}, "c": 3} } }'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$gte": 1, "$lte": 1 }, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$not": {"$elemMatch": {"b": 1, "c": 2} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 2}, "c": 2} } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) /* Logical operator in elemMatch */ -- Logical ops on same path inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : [ { }, { "b" : { "$numberInt" : "2" } } ] } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, [ { "$numberInt" : "18" } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "15" }, { "b" : [ { "$numberInt" : "18" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$or": [{"b": "1"}, {"c": 2}] } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$and" : [ { "a" : { "$elemMatch" : { "$gt" : 1, "$not" : { "$gt" : 2 } } } }]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$or" : [ {"a.b": {"$elemMatch": {"$eq": 10}}}, {"a.b": {"$elemMatch": {"$eq": 7}}}]}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ] } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ] } } (2 rows) -- elemMatch with Logical ops and non-logical op SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : [ { "b" : { "$numberInt" : "3" } }, { "b" : { "$numberInt" : "2" } } ] } (1 row) /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 21, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 22, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 23, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Nested elemMatch */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ], "d" : [ { "e" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "15" }, { "$numberInt" : "18" } ], "d" : [ { "e" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$in": [3] } } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ], "d" : [ { "e" : { "$numberInt" : "3" } } ], "f" : { "$numberInt" : "1" } } ] } (1 row) -- d.e being the path in nested elemMatch SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d.e": { "$elemMatch": { "$gte": 2, "$lte": 2 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : [ { "d" : [ { "e" : [ { "$numberInt" : "2" } ] } ] } ] } (1 row) /* Non $elemMatch expression and a nested $elemMatch. */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "18" }, { "$numberInt" : "19" } ], "d" : [ { "e" : { "$numberInt" : "3" } } ], "f" : { "$numberInt" : "1" } } ] } (1 row) /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ [ { "b" : 1 } ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": [ [ { "b" : [1] } ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": [ 100 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": { "0" : 100 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": { "0" : [ 100 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "0" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 38, "a": [ { "0" : [ 100 ] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 39, "a": [ { "-1" : 100 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 40, "a": { "b" : [ [ 100, 200, 300 ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 41, "a": { "b" : [ { "c" : [100] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 42, "a": { "b" : [ { "c" : [[100]] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "40" } } | { "_id" : { "$numberInt" : "40" }, "a" : { "b" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "b" : { "$eq" : 1 } } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "32" } } | { "_id" : { "$numberInt" : "32" }, "a" : [ [ { "b" : { "$numberInt" : "1" } } ] ] } { "" : { "$numberInt" : "33" } } | { "_id" : { "$numberInt" : "33" }, "a" : [ [ { "b" : [ { "$numberInt" : "1" } ] } ] ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } { "" : { "$numberInt" : "37" } } | { "_id" : { "$numberInt" : "37" }, "a" : [ { "0" : { "$numberInt" : "100" } } ] } { "" : { "$numberInt" : "38" } } | { "_id" : { "$numberInt" : "38" }, "a" : [ { "0" : [ { "$numberInt" : "100" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "31" } } | { "_id" : { "$numberInt" : "31" }, "a" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } { "" : { "$numberInt" : "37" } } | { "_id" : { "$numberInt" : "37" }, "a" : [ { "0" : { "$numberInt" : "100" } } ] } { "" : { "$numberInt" : "38" } } | { "_id" : { "$numberInt" : "38" }, "a" : [ { "0" : [ { "$numberInt" : "100" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "39" } } | { "_id" : { "$numberInt" : "39" }, "a" : [ { "-1" : { "$numberInt" : "100" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "40" } } | { "_id" : { "$numberInt" : "40" }, "a" : { "b" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "300" } ] ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "41" } } | { "_id" : { "$numberInt" : "41" }, "a" : { "b" : [ { "c" : [ { "$numberInt" : "100" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c.0" : { "$elemMatch": {"$eq": 100 } } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "42" } } | { "_id" : { "$numberInt" : "42" }, "a" : { "b" : [ { "c" : [ [ { "$numberInt" : "100" } ] ] } ] } } (1 row) ROLLBACK; -- Invalid Arguments SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": [] }}'; ERROR: $elemMatch needs an Object bson_query_operator_error_tests.out000066400000000000000000001102471507310017400372650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 30000; SET documentdb.next_collection_id TO 300; SET documentdb.next_collection_index_id TO 300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- these queries are negative tests for $size operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : -3 }}' ORDER BY object_id; ERROR: Parsing of operator $size failed. A non-negative value was expected in operator $size: -3 SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.1 }}' ORDER BY object_id; ERROR: Failed to parse $size. Expected an integer in: $size: 3.1 SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : -3.4 }}' ORDER BY object_id; ERROR: Failed to parse $size. Expected an integer in: $size: -3.4 -- These can't be tested since the extended json syntax treats $type as an extended json operator and not a call to actual $type function. -- SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : 123.56 }}' ORDER BY object_id; -- SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : [] }}' ORDER BY object_id; -- these queries are negative tests for $all operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, 1 ] } }' ORDER BY object_id; ERROR: $all/$elemMatch has to be consistent SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ 1, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, {"$all" : [0]} ] } }' ORDER BY object_id; ERROR: $all/$elemMatch has to be consistent SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$all" : [0]}, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, {} ] } }' ORDER BY object_id; ERROR: $all/$elemMatch has to be consistent SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {}, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, { "b" : 1 } ] } }' ORDER BY object_id; ERROR: $all/$elemMatch has to be consistent SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ { "b" : 1 }, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, { "$or" : [ {"b":1} ] } ] } }' ORDER BY object_id; ERROR: $all/$elemMatch has to be consistent SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ { "$or" : [ {"b":1} ] }, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$all" : [1] } ] } }' ORDER BY object_id; ERROR: no $ expressions in $all -- negative tests for $not operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$not" : {} } }'; ERROR: Operator $not must not be left empty -- negative tests for comp operators with regex SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$ne" : {"$regex" : "hello", "$options" : ""} } }'; ERROR: Can't have regex as arg to $ne. SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$gt" : {"$regex" : "hello", "$options" : ""} } }'; ERROR: Can't have RegEx as arg to predicate over field 'a'. SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$gte" : {"$regex" : "hello", "$options" : ""} } }'; ERROR: Can't have RegEx as arg to predicate over field 'a'. SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$lt" : {"$regex" : "hello", "$options" : ""} } }'; ERROR: Can't have RegEx as arg to predicate over field 'a'. SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$lte" : {"$regex" : "hello", "$options" : ""} } }'; ERROR: Can't have RegEx as arg to predicate over field 'a'. -- type undefined, no-operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$undefined" : true } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : 1, "b" : { "$undefined" : true } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : { "$undefined" : true } }'; ERROR: Comparison with undefined value is not allowed -- type undefined, comparison query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$gt" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$gte" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$lt" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$lte" : { "$undefined" : true } } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in" : [ { "$undefined" : true } ] } }'; ERROR: InMatchExpression equality cannot be undefined SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in" : [ { "$undefined" : true }, 2, 3, 4 ] } }'; ERROR: InMatchExpression equality cannot be undefined SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin" : [ { "$undefined" : true } ] } }'; ERROR: InMatchExpression equality cannot be undefined SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin" : [ { "$undefined" : true }, 6, 7, 8] } }'; ERROR: InMatchExpression equality cannot be undefined -- type undefined, array query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$all" : [ { "$undefined" : true } ] } }'; ERROR: Comparison with undefined value is not allowed SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$all" : [ { "$undefined" : true }, 2 ] } }'; ERROR: Comparison with undefined value is not allowed --type undefined, bitwise query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllClear": {"$undefined": true}}}'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllClear: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllClear": [1, {"$undefined": true}]}}'; ERROR: bit positions must be an integer but got: 1: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllSet": {"$undefined": true}}}'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAllSet: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllSet":[1, {"$undefined": true}]}}'; ERROR: bit positions must be an integer but got: 1: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnyClear": {"$undefined": true}}}'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnyClear: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnyClear": [1, {"$undefined": true}]}}'; ERROR: bit positions must be an integer but got: 1: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnySet": {"$undefined": true}}}'; ERROR: a takes an Array, a number, or a BinData but received: $bitsAnySet: \{ "$undefined" : true }\ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnySet": [1, {"$undefined": true}]}}'; ERROR: bit positions must be an integer but got: 1: \{ "$undefined" : true }\ bson_query_operator_geospatial_multi_tests.out000066400000000000000000002114701507310017400414760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 567100; SET documentdb.next_collection_id TO 56710; SET documentdb.next_collection_index_id TO 56710; SELECT documentdb_api.drop_collection('db', 'geo_multi') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'geo_multi') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- Insert multiple items SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 1, "name": "PointA", "geo": { "type": "Point", "coordinates": [100, 0] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 2, "name": "PointB", "geo": { "type": "Point", "coordinates": [102, 2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 3, "name": "MultiPointAB", "geo": { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 4, "name": "LineStringA", "geo": { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 5, "name": "LineStringB", "geo": { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 6, "name": "MultiLineStringAB", "geo": { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 7, "name": "PolygonA", "geo": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 8, "name": "PolygonB", "geo": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- commenting out the polygon with holes for now -- SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 9, "name": "PolygonA_WithHole", "geo": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 10, "name": "MultiPolygonAB", "geo": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 11, "name": "GeometryCollectionAll_Withouthole", "geo": { "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [100, 0] }, { "type": "Point", "coordinates": [102, 2] }, { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] }, { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] }, { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] }, { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] }, { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] }, { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]}] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- commenting out the polygon with holes for now -- SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 12, "name": "GeometryCollectionAll_Withhole", "geo": { "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [100, 0] }, { "type": "Point", "coordinates": [102, 2] }, { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] }, { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] }, { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] }, { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] }, { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] }, { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]}] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 13, "name": "Polygon_Exterior", "geo": { "type": "Polygon", "coordinates": [ [ [0, 0], [1, 0], [1, 1], [0, 1], [0, 0] ] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Big enough single polygon to match all the documents except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [103, 0], [103, 3], [100, 3], [100, 0] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "3" }, "name" : "MultiPointAB", "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "6" }, "name" : "MultiLineStringAB", "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } { "_id" : { "$numberInt" : "10" }, "name" : "MultiPolygonAB", "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } { "_id" : { "$numberInt" : "11" }, "name" : "GeometryCollectionAll_Withouthole", "geo" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] }, { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] }, { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] }, { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } ] } } (10 rows) -- PolygonA matches PointA, LineStringA, PolygonA, LineStringA SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } (3 rows) -- PolygonB matches PointB, LineStringB, PolygonB, SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } (3 rows) -- MultiPolygonAB creates a covered region that matches all except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "3" }, "name" : "MultiPointAB", "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "6" }, "name" : "MultiLineStringAB", "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } { "_id" : { "$numberInt" : "10" }, "name" : "MultiPolygonAB", "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } { "_id" : { "$numberInt" : "11" }, "name" : "GeometryCollectionAll_Withouthole", "geo" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] }, { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] }, { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] }, { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } ] } } (10 rows) -- PolygonA_WithHole matches PointA and PolygonA (Bug) and doesn't match itself -- Limitation1: Matching itself is different behavior in mongo and postgis doesn't behave same out of the box for 2 identical polygons with holes. -- Limitation2: PolygonA is matched because of this limitation that the outer ring of polygon with hole covers the polygonB and in this case the hole is not considered SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] } } }}'; ERROR: $geoWithin currently doesn't support polygons with holes EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_56710_567101 collection WHERE (documentdb_api_catalog.bson_dollar_geowithin(documentdb_api_catalog.bson_validate_geography(document, 'geo'::text), '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '56710'::bigint)) Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documentdb_data.documents_56710_567101 collection Output: document Recheck Cond: (collection.shard_key_value = '56710'::bigint) Filter: (documentdb_api_catalog.bson_validate_geography(collection.document, 'geo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '56710'::bigint) (13 rows) -- Create Index and should get the same result SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geo_multi", "indexes": [{"key": {"geo": "2dsphere"}, "name": "my_geo_indx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; -- Big enough single polygon to match all the documents except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [103, 0], [103, 3], [100, 3], [100, 0] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "3" }, "name" : "MultiPointAB", "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "6" }, "name" : "MultiLineStringAB", "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } { "_id" : { "$numberInt" : "10" }, "name" : "MultiPolygonAB", "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } { "_id" : { "$numberInt" : "11" }, "name" : "GeometryCollectionAll_Withouthole", "geo" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] }, { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] }, { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] }, { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } ] } } (10 rows) -- PolygonA matches PointA, LineStringA, PolygonA, LineStringA SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } (3 rows) -- PolygonB matches PointB, LineStringB, PolygonB, SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } (3 rows) -- MultiPolygonAB creates a covered region that matches all except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "3" }, "name" : "MultiPointAB", "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "6" }, "name" : "MultiLineStringAB", "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } { "_id" : { "$numberInt" : "10" }, "name" : "MultiPolygonAB", "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } { "_id" : { "$numberInt" : "11" }, "name" : "GeometryCollectionAll_Withouthole", "geo" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] }, { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] }, { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] }, { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } ] } } (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_56710_567101 collection WHERE (documentdb_api_catalog.bson_dollar_geowithin(documentdb_api_catalog.bson_validate_geography(document, 'geo'::text), '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '56710'::bigint)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_geo_indx on documentdb_data.documents_56710_567101 collection Output: document Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'geo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) (10 rows) ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'geo_multi', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; set local citus.enable_local_execution TO OFF; set local documentdb.forceUseIndexIfAvailable to on; SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "name" : "PointA", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "name" : "PointB", "geo" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "3" }, "name" : "MultiPointAB", "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "4" }, "name" : "LineStringA", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] } } { "_id" : { "$numberInt" : "5" }, "name" : "LineStringB", "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] } } { "_id" : { "$numberInt" : "6" }, "name" : "MultiLineStringAB", "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] } } { "_id" : { "$numberInt" : "7" }, "name" : "PolygonA", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] } } { "_id" : { "$numberInt" : "8" }, "name" : "PolygonB", "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] } } { "_id" : { "$numberInt" : "10" }, "name" : "MultiPolygonAB", "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } { "_id" : { "$numberInt" : "11" }, "name" : "GeometryCollectionAll_Withouthole", "geo" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] }, { "type" : "Point", "coordinates" : [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] }, { "type" : "MultiPoint", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] }, { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberDouble" : "100.5" }, { "$numberDouble" : "0.5" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ] ], [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberDouble" : "102.5" }, { "$numberDouble" : "2.5" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ] }, { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } ] } } (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document FROM documentdb_data.documents_56710_567116 documents_56710 WHERE documentdb_api_catalog.bson_dollar_geowithin(documentdb_api_catalog.bson_validate_geography(document, 'geo'::text), '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_geo_indx on documentdb_data.documents_56710_567116 documents_56710 Output: document Index Cond: (documentdb_api_catalog.bson_validate_geography(documents_56710.document, 'geo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "103" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "102" }, { "$numberInt" : "2" } ] ] ], [ [ [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "101" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "0" } ] ] ] ] } } }'::documentdb_core.bson) (10 rows) ROLLBACK; bson_query_operator_geospatial_runtime_validation.out000066400000000000000000002464041507310017400430240ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1605000; SET documentdb.next_collection_id TO 160500; SET documentdb.next_collection_index_id TO 160500; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); drop_primary_key --------------------------------------------------------------------- (1 row) -- Top level validations -- Insert so that validations kick in SELECT documentdb_api.insert_one('db','geoquerytest','{ "z" : { "y": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": 1 }}'; ERROR: Expected 'document' type for Geometry but found 'int' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberInt": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'int' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberLong": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'long' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberDouble": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'double' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberDecimal": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'decimal' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": [10, 10] }}'; ERROR: Expected 'document' type for Geometry but found 'array' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": true }}'; ERROR: Expected 'document' type for Geometry but found 'bool' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": false }}'; ERROR: Expected 'document' type for Geometry but found 'bool' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$undefined": true } }}'; ERROR: Expected 'document' type for Geometry but found 'undefined' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": "Geometry" }}'; ERROR: Expected 'document' type for Geometry but found 'string' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"a": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: a: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"box": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: box: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"center": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: center: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"polygon": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: polygon: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": 1 }}'; ERROR: Expected 'document' type for Geometry but found 'int' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberInt": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'int' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberLong": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'long' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberDouble": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'double' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberDecimal": "1" } }}'; ERROR: Expected 'document' type for Geometry but found 'decimal' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": [10, 10] }}'; ERROR: Expected 'document' type for Geometry but found 'array' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": true }}'; ERROR: Expected 'document' type for Geometry but found 'bool' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": false }}'; ERROR: Expected 'document' type for Geometry but found 'bool' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$undefined": true } }}'; ERROR: Expected 'document' type for Geometry but found 'undefined' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": "Geometry" }}'; ERROR: Expected 'document' type for Geometry but found 'string' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"a": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: a: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"box": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: box: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"center": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: center: [ 10, 20 ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"polygon": [10, 20]}}}'; ERROR: Unrecognized geographic specifier encountered: polygon: [ 10, 20 ] -- Valid Shape operator validations -- $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": "Points" }}}'; ERROR: Unknown geographical specifier detected: "Points" with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { }}}'; ERROR: Geo query is missing the required geometry data SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": 1 }}}'; ERROR: Unknown geographical specifier detected: 1 with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": true }}}'; ERROR: Unknown geographical specifier detected: true with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"w": 10, "x": 10, "y": 11, "z": 12}}}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeftX": 10, "bottomLeftY": 10, "topRightX": 11, "topRightY": 12}}}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": [10], "y": 10 }, "topRight": { "x": 11, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": "10" }, "topRight": { "x": 11, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": true, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": 11, "y": {"y": 10}}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [10, 11, 12, 13] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[[10], 10], [11, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, "10"], [11, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10], [true, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10], [11, {"y": 11}]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10]] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": "Points" }}}'; ERROR: Unknown geographical specifier detected: "Points" with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { }}}'; ERROR: Geo query is missing the required geometry data SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": 1 }}}'; ERROR: Unknown geographical specifier detected: 1 with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": true }}}'; ERROR: Unknown geographical specifier detected: true with operator $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"w": 10, "x": 10, "y": 11, "z": 12}}}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeftX": 10, "bottomLeftY": 10, "topRightX": 11, "topRightY": 12}}}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": [10], "y": 10 }, "topRight": { "x": 11, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": "10" }, "topRight": { "x": 11, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": true, "y": 11}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": 11, "y": {"y": 10}}}}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [10, 11, 12, 13] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[[10], 10], [11, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, "10"], [11, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10], [true, 11]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10], [11, {"y": 11}]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10]] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers -- $center SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": "Points" }}}'; ERROR: Unrecognized geographical specifier in operator $center: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": 1 }}}'; ERROR: Unrecognized geographical specifier in operator $center: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": true }}}'; ERROR: Unrecognized geographical specifier in operator $center: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": [10], "y": 10 }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": "10" } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": -10 } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": true } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [ [10], 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, "10"], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [ {"x": 10 } , 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], "10" ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], -10 ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], true ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], 10, 10 ] }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }}}}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10] ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": {} }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": "Points" }}}'; ERROR: Unrecognized geographical specifier in operator $center: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": 1 }}}'; ERROR: Unrecognized geographical specifier in operator $center: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": true }}}'; ERROR: Unrecognized geographical specifier in operator $center: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": [10], "y": 10 }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": "10" } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": -10 } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": true } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [ [10], 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, "10"], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [ {"x": 10 } , 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], "10" ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], -10 ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], true ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], 10, 10 ] }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }}}}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10] ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "NaN" }] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "-NaN" }] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "-Infinity" }] }}}'; ERROR: radius value must be zero or greater -- $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": "Points" }}}'; ERROR: Invalid specifier $centerSphere: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": 1 }}}'; ERROR: Invalid specifier $centerSphere: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": true }}}'; ERROR: Invalid specifier $centerSphere: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": [10], "y": 10 }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": "10" } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": -10 } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": true } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [ [10], 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, "10"], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [ {"x": 10 } , 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], "10" ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], -10 ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], true ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], 10, 10 ] }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }}}}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10] ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [] }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": {} }}}'; ERROR: The specified point should either be structured as an array or defined as an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": "Points" }}}'; ERROR: Invalid specifier $centerSphere: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": 1 }}}'; ERROR: Invalid specifier $centerSphere: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": true }}}'; ERROR: Invalid specifier $centerSphere: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": [10], "y": 10 }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": "10" } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": -10 } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": true } }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [ [10], 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, "10"], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [ {"x": 10 } , 10], 10 ] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], "10" ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], -10 ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], true ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], 10, 10 ] }}}'; ERROR: A maximum of two fields can be defined for the circular region. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }}}}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10] ] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "NaN" }] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "-NaN" }] }}}'; ERROR: radius value must be zero or greater SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "-Infinity" }] }}}'; ERROR: radius value must be zero or greater -- $polygon SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": "Points" }}}'; ERROR: Invalid specifier $polygon: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": 1 }}}'; ERROR: Invalid specifier $polygon: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": true }}}'; ERROR: Invalid specifier $polygon: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10} } }}}'; ERROR: A polygon shape requires a minimum of three points SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": [10], "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": "10"}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": { "xx" : 10 }, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": true, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": false} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11]] }}}'; ERROR: A polygon shape requires a minimum of three points SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[[10], 10], [11, 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, {"y": 10}], [11, 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], ["11", 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11], [true, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11], [12, false]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": "Points" }}}'; ERROR: Invalid specifier $polygon: "Points" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": 1 }}}'; ERROR: Invalid specifier $polygon: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": true }}}'; ERROR: Invalid specifier $polygon: true SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10} } }}}'; ERROR: A polygon shape requires a minimum of three points SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": [10], "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": "10"}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": { "xx" : 10 }, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": true, "y": 10} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": false} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11]] }}}'; ERROR: A polygon shape requires a minimum of three points SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[[10], 10], [11, 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, {"y": 10}], [11, 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], ["11", 11], [12, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11], [true, 12]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11], [12, false]] }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDouble": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDouble": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "-inf" }]] }}}'; ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf ERROR: Point coordinate values must always be finite numbers -- $geoIntersects operator validations SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": 1 }}'; ERROR: Expected 'document' type for Geometry but found 'int' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { } }}'; ERROR: Geo query is missing the required geometry data SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": [{ "$geometry": {} }] }}'; ERROR: Expected 'document' type for Geometry but found 'array' instead SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$box": [[10, 20], [30, 40]] }}}'; ERROR: $geoIntersect is not supported with the given geometry input: { "$box" : [ [ 10, 20 ], [ 30, 40 ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$polygon": [[10, 20], [30, 40]] }}}'; ERROR: $geoIntersect is not supported with the given geometry input: { "$polygon" : [ [ 10, 20 ], [ 30, 40 ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$centerSphere": [[10, 20], [30, 40]] }}}'; ERROR: $geoIntersect is not supported with the given geometry input: { "$centerSphere" : [ [ 10, 20 ], [ 30, 40 ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": 1 }}}'; ERROR: unknown geo specifier: $geometry: 1 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": {} }}}'; ERROR: Unknown GeoJSON data type: { } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "point" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "point" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "linestring" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "linestring" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "polygon" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "polygon" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multipoint" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "multipoint" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multilinestring" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "multilinestring" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multipolygon" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "multipolygon" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "geometrycollection" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "geometrycollection" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "invalidGeoJsonType" } }}}'; ERROR: Unknown GeoJSON data type: { "type" : "invalidGeoJsonType" } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point" } }}}'; ERROR: Point must be either an array or an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString" } }}}'; ERROR: GeoJSON coordinates should always be provided as an array format containing coordinate values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon" } }}}'; ERROR: Coordinates for Polygon must be provided as an array SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint" } }}}'; ERROR: GeoJSON coordinates should always be provided as an array format containing coordinate values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiLineString" } }}}'; ERROR: Coordinates for MultiLineString must be provided as an array SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon" } }}}'; ERROR: Coordinates for MultiPolygon must be provided as an array SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection" } }}}'; ERROR: GeometryCollection requires geometries in an array format SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "Coordinates": [10, 10] } }}}'; ERROR: Point must be either an array or an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": {"x": 10, "y": "Text"} } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [[1, 2], [3, 4]] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [1, "text"] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [{"x": 10, "y": 10}] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [1, 2] } }}}'; ERROR: GeoJSON coordinates need to be provided in an array format SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2]] } }}}'; ERROR: GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2], [3, "text"]] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2], {"x": 10, "y": 10}] } }}}'; ERROR: GeoJSON coordinates need to be provided in an array format -- Polygon extra validations SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [1, 2] } }}}'; ERROR: GeoJSON coordinates should always be provided as an array format containing coordinate values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[1, 2], [3, 4]] }}}}'; ERROR: GeoJSON coordinates need to be provided in an array format SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[]] }}}}'; ERROR: Loop contains no vertices: [] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4]]] }}}}'; ERROR: Loop structure remains unclosed: [ [ 1, 2 ], [ 3, 4 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [1, 3]]] }}}}'; ERROR: Loop structure remains unclosed: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 1, 3 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [2, 1]]] }}}}'; ERROR: Loop structure remains unclosed: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 2, 1 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [1, 2]]] }}}}'; ERROR: A Loop must contain no fewer than three distinct vertices: [ [ 1, 2 ], [ 3, 4 ], [ 1, 2 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]] }}}}'; ERROR: Loop is not valid: [ [1.000000, 1.000000], [1.000000, 5.000000], [3.000000, 4.000000], [0.000000, 3.000000], [1.000000, 1.000000] ] - Edges cross SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] }}}}'; -- Edges of polygon intersect, 2d area is 0 ERROR: Loop is not valid: [ [0.000000, 0.000000], [-2.000000, -1.000000], [1.000000, 1.000000], [0.000000, 1.000000], [0.000000, 0.000000] ] - Edges cross SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]]}}}}'; -- Edges of polygon intersect, 2d area is not 0 ERROR: Loop is not valid: [ [1.000000, 0.000000], [0.000000, 10.000000], [10.000000, 10.000000], [0.000000, 0.000000], [1.000000, 0.000000] ] - Edges cross SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]]}}}}'; -- Polygon with hole edge part of (overlapping) outer ring ERROR: Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 10.000000], [75.000000, 25.000000], [75.000000, 75.000000], [0.000000, 70.000000], [0.000000, 10.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 80.000000], [80.000000, 80.000000], [80.000000, 0.000000], [0.000000, 0.000000] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]]}}}}'; -- Polygon with hole having 1 edge common with outer ring ERROR: Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 0.000000], [75.000000, 25.000000], [75.000000, 75.000000], [0.000000, 80.000000], [0.000000, 0.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 80.000000], [80.000000, 80.000000], [80.000000, 0.000000], [0.000000, 0.000000] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 2], [2, 0], [2, 2], [0, 0], [1, 2], [3, 2], [4, 2], [0, 2]]]}}}}'; -- Combination polygon - both intersection and overlap ERROR: Loop is not valid: [ [0.000000, 2.000000], [4.000000, 2.000000], [3.000000, 2.000000], [1.000000, 2.000000], [0.000000, 0.000000], [2.000000, 2.000000], [2.000000, 0.000000], [0.000000, 2.000000] ] - Edges cross SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], []] }}}}'; ERROR: Loop contains no vertices: [] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]] }}}}'; ERROR: Secondary loops are outside the first exterior loop and must instead represent holes SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] }}}}'; --Holes covering the polygon ERROR: Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 0.000000], [1.000000, 0.000000], [1.000000, 1.000000], [0.000000, 1.000000], [0.000000, 0.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 1.000000], [1.000000, 1.000000], [1.000000, 0.000000], [0.000000, 0.000000] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [ [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0, 0], [0, 0.5], [1, 0.5], [1, 0], [0, 0]], [[0, 0.5], [0, 1], [1, 1], [1, 0.5], [0, 0.5]] ] }}}}'; -- Multi holes covering the polygon ERROR: Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 0.000000], [1.000000, 0.000000], [1.000000, 0.500000], [0.000000, 0.500000], [0.000000, 0.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 1.000000], [1.000000, 1.000000], [1.000000, 0.000000], [0.000000, 0.000000] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]] }}}}'; -- Duplicate non adjacent vertices ERROR: Loop is not valid: [ [ 1, 2 ], [ 2, 3 ], [ 1, 2 ], [ 3, 4 ], [ 1, 2 ] ] Duplicate vertices: 0 and 2 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [1, 2] } }}}'; ERROR: GeoJSON coordinates need to be provided in an array format SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": {} } }}}'; ERROR: GeoJSON coordinates should always be provided as an array format containing coordinate values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [[1, 2], [3, "text"]] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [[[1, 2], [3, 4]]] } }}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 2], [3,4]]], [] ] } }}}'; ERROR: Loop structure remains unclosed: [ [ 1, 2 ], [ 3, 4 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [], [] ] } }}}'; ERROR: Polygon does not contain any loops. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 2], [3, 4], [1, 2]]], [] ] } }}}'; ERROR: A Loop must contain no fewer than three distinct vertices: [ [ 1, 2 ], [ 3, 4 ], [ 1, 2 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], []], []] } }}}'; ERROR: Loop contains no vertices: [] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]]], [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]]] } }}}'; ERROR: Secondary loops are outside the first exterior loop and must instead represent holes SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiLineString", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]], [[1, 2]]] }}}}'; ERROR: GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ] ] -- Geometry Collections SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": {} }}}}'; ERROR: GeometryCollection requires geometries in an array format SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [] }}}}'; ERROR: GeometryCollection must contain a minimum of one geometry element SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coords": [10, 10] }] }}}}'; ERROR: Point must be either an array or an object SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "unknownPoint", "coords": [10, 10] }] }}}}'; ERROR: Unknown GeoJSON data type: { "type" : "unknownPoint", "coords" : [ 10, 10 ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coordinates": [10, "text"] }] }}}}'; ERROR: Point parameter should contain only numeric values SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coordinates": [10, 10] }, {"type": "LineString", "coordinates": [[1, 2], [2, 3]]}, {"type": "Polygon", "coordinates": [[[1, 1], [5, 5], [2, 6], [1, 1]]]}, {"type": "LineString", "coordinates": [[10, 10]]}] }}}}'; ERROR: GeoJSON LineString requires a minimum of two vertices: [ [ 10, 10 ] ] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [10, 10]}]}] }}}}'; ERROR: GeometryCollections nesting is not allowed: [ { "type" : "Point", "coordinates" : [ 10, 10 ] } ] --CRS checks SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": [], "coordinates": [1, 2] } }}}'; ERROR: The GeoJSON CRS value must be provided as an object. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {}, "coordinates": [1, 2] } }}}'; ERROR: GeoJSON CRS must have field "type": "name" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": 1, "name": 1}, "coordinates": [1, 2] } }}}'; ERROR: GeoJSON CRS must have field "type": "name" SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name"}, "coordinates": [1, 2] } }}}'; ERROR: CRS must include a field named "properties", and this field needs to be an object. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {}}, "coordinates": [1, 2] } }}}'; ERROR: In CRS, the field "properties.name" is required to be of string type SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": { "name": 2 }}, "coordinates": [1, 2] } }}}'; ERROR: In CRS, the field "properties.name" is required to be of string type SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {"name": "UnknownCRS"}}, "coordinates": [1, 2] } }}}'; ERROR: Unrecognized CRS name provided: UnknownCRS SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {"name": "urn:x-mongodb:crs:STRICTWINDING:EPSG:4326" } }, "coordinates": [1, 2] } }}}'; ERROR: Unrecognized CRS name provided: urn:x-mongodb:crs:STRICTWINDING:EPSG:4326 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"properties": {}, "type": "name"}, "coordinates": [1, 2] } }}}'; ERROR: In CRS, the field "properties.name" is required to be of string type SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": { "type": "name", "properties": { "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" } }, "coordinates": [1, 2] } }}}'; ERROR: Polygon supports strict winding order exclusively. SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [5, 5], [2, 6], [1, 1]]], "crs": { "type": "name", "properties": { "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" } }} }}}'; ERROR: Custom CRS for big polygon is not supported yet. -- $geoWithin with non polygon GeoJSON don't work SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "Point", "coordinates": [10, 10] } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "type" : "Point", "coordinates" : [ 10, 10 ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "MultiPoint", "coordinates": [[10, 10], [20, 20]] } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "type" : "MultiPoint", "coordinates" : [ [ 10, 10 ], [ 20, 20 ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "type" : "LineString", "coordinates" : [ [ 7.0999999999999996447, 7.2000000000000001776 ], [ 4.0999999999999996447, 4.2000000000000001776 ], [ 7.2999999999999998224, 7.4000000000000003553 ], [ 2.1000000000000000888, 2.2000000000000001776 ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "MultiLineString", "coordinates": [[[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]]] } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "type" : "MultiLineString", "coordinates" : [ [ [ 7.0999999999999996447, 7.2000000000000001776 ], [ 4.0999999999999996447, 4.2000000000000001776 ], [ 7.2999999999999998224, 7.4000000000000003553 ], [ 2.1000000000000000888, 2.2000000000000001776 ] ] ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ -25, -25 ], [ 25, 25 ] ] }, { "type" : "Point", "coordinates" : [ 2.1000000000000000888, 2.2000000000000001776 ] } ] } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": { "lon": 50, "lat": 50 } }}}'; ERROR: $geoWithin is not supported for the specified geometry: { "lon" : 50, "lat" : 50 } SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": [51, 51] }}}'; ERROR: $geoWithin is not supported for the specified geometry: [ 51, 51 ] -- Out of bounds checks for GeoJSON SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "Point", "coordinates": [200, 200]} }}}'; ERROR: longitude/latitude is out of bounds, lng: 200 lat: 200 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "LineString", "coordinates": [[-200, -200], [50, 50]]} }}}'; ERROR: longitude/latitude is out of bounds, lng: -200 lat: -200 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "Polygon", "coordinates": [[[-200, -200], [50, 50], [30, 30], [-200, -200]]] } }}}'; ERROR: longitude/latitude is out of bounds, lng: -200 lat: -200 -- Also check some cases which are specific to runtime -- e.g. GeoJson point type is matched only during runtime if there is no 2d index on the field -- If the index is created then it would simply error out as this is not a proper point format for the index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 100, "a" : { "b": { "type": "Point", "coordinates": [60, 60] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "a" : [{ "b": { "type": "Point", "coordinates": [65, 65] } }, { "b": { "type": "Point", "coordinates": [70, 70] } }, { "b": { "type": "Point", "coordinates": [75, 75] } }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- This is Geojson Polygon which should not match for 2d planar calculations using $box, $polygon, $center in $geowithin SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "a" : { "b": {"type": "Polygon", "coordinates": [[ [10, 10], [10, 10], [10, 10], [10, 10] ]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [100, 100]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "60" }, { "$numberInt" : "60" } ] } } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "65" }, { "$numberInt" : "65" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "70" }, { "$numberInt" : "70" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "75" }, { "$numberInt" : "75" } ] } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[10, 10], 100]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "60" }, { "$numberInt" : "60" } ] } } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "65" }, { "$numberInt" : "65" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "70" }, { "$numberInt" : "70" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "75" }, { "$numberInt" : "75" } ] } } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 100], [100, 100], [100, 10]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "a" : { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "60" }, { "$numberInt" : "60" } ] } } } { "_id" : { "$numberInt" : "101" }, "a" : [ { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "65" }, { "$numberInt" : "65" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "70" }, { "$numberInt" : "70" } ] } }, { "b" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "75" }, { "$numberInt" : "75" } ] } } ] } (2 rows) -- insert some invalid polygons - don't error out on runtime as polygon validation during inserting happens only in index case SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 501, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] } } }', NULL); -- self intersecting polygon with 0 geometrical area insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 502, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]] } } }', NULL); -- self intersecting polygon with non-zero geometrical area insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 503, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]] } } }', NULL); -- hole edge lies on outer ring edge insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 504, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]] } } }', NULL); -- hole shares an edge with outer ring insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 505, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[10, 10], [10, 70], [75, 75], [75, 25], [10, 10]],[[10,20], [10,30], [50, 50], [10, 20]]] } } }', NULL); -- 3rd ring edge lies on 2nd ring edge insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) bson_query_operator_geospatial_tests_explain_index.out000066400000000000000000005551531507310017400432040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167400; SET documentdb.next_collection_id TO 16740; SET documentdb.next_collection_index_id TO 16740; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); drop_primary_key --------------------------------------------------------------------- (1 row) -- 2d and 2d with pfe SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"d": "2d"}, "name": "my_2d_idx_pfe", "partialFilterExpression" : {"e": { "$gte": 5} } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- 2dsphere and 2dsphere with pfe SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": "2dsphere"}, "name": "my_2ds_geoloc_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"largeGeo": "2dsphere"}, "name": "my_2ds_largegeo_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"d": "2dsphere"}, "name": "my_2ds_idx_pfe", "partialFilterExpression" : {"e": { "$gte": 5} } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geoA": "2dsphere", "geoB": "2dsphere"}, "name": "my_2dsgeo_a_or_b_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo1": "2dsphere", "geo2": "2dsphere"}, "name": "my_2ds_geo1_2_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } }]}', true); -- Multi 2dsphere index with pfe create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Also create a regular index on the same path, to validate that geo operators are never pushed to regular index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": 1}, "name": "my_regular_a_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": 1}, "name": "my_regular_geo.loc_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql -- Insert multiple items - 2d index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert multiple items - 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 103, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 104, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 105, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 106, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 107, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 108, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 109, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 110, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 111, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 112, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 113, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 114, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for testing index usage with partial filter expression SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "d" : [15, 15], "e": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "d" : [16, 16], "e": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "d" : [17, 17], "e": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "d" : [18, 18], "e": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "d" : [19, 19], "e": 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "d" : [20, 20], "e": 6 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "d" : [21, 21], "e": 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "d" : [22, 22], "e": 8 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "d" : [23, 23], "e": 9 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "d" : [24, 24], "e": 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 500, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 501, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 2d index explain -- $geoWithin / $within => $box shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (9 rows) -- $geoWithin / $within => Hashes of $center/$centerSphere may vary so skipping those here to avoid flakiness -- $geoWithin / $within => $polygon shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (9 rows) -- Explain plan with partial filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16740_167402 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on my_regular_a_idx Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (9 rows) -- 2dSphere index explains -- $geoIntersects explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- With pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16740_167402 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$eq": [2.1, 2.2]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on "my_regular_geo.loc_idx" Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) (9 rows) -- $geoWithin explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- $geometry with legacy formats EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) (9 rows) -- Testing composite 2dsphere index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2dsgeo_a_or_b_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2dsgeo_a_or_b_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2dsgeo_a_or_b_idx on documents_16740_167402 collection Index Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Testing composite 2dsphere with pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "region" : "USA" }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geo1_2_pfe_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Bitmap Heap Scan on documents_16740_167402 collection Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "region" : "USA" }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geo1_2_pfe_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Index Scan using my_2ds_geo1_2_pfe_idx on documents_16740_167402 collection Index Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index but should return same values QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Seq Scan on documents_16740_167402 collection Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) COMMIT; -- few items for $center recheck condition SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "a" : { "b": [70, 70] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 402, "a" : { "b": [80, 80] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 403, "a" : { "b": [90, 90] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; BEGIN; set local enable_seqscan TO off; -- Testing $center and $centerSphere with infinite radius - gives no recheck condition EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=7 loops=1) Task Count: 1 Tuple data received from nodes: 464 bytes Tasks Shown: All -> Task Tuple data received from node: 464 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documents_16740_167402 collection (actual rows=7 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=12 loops=1) Task Count: 1 Tuple data received from nodes: 1765 bytes Tasks Shown: All -> Task Tuple data received from node: 1765 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_geoloc_idx on documents_16740_167402 collection (actual rows=12 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (9 rows) -- Testing $center and $centerSphere with non-infinite radius - gives rows removed by recheck EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 376 bytes Tasks Shown: All -> Task Tuple data received from node: 376 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documents_16740_167402 collection (actual rows=5 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "100" } ] } }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 1603 bytes Tasks Shown: All -> Task Tuple data received from node: 1603 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_geoloc_idx on documents_16740_167402 collection (actual rows=9 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "1" } ] } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using my_2ds_largegeo_idx on documents_16740_167402 collection (actual rows=0 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-59.802468529298138833" }, { "$numberDouble" : "-2.3633072488322852678" } ], { "$numberDouble" : "2.7684032724649791923" } ] } }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 128 bytes Tasks Shown: All -> Task Tuple data received from node: 128 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=1 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using my_2ds_largegeo_idx on documents_16740_167402 collection (actual rows=1 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "2.9592242752161572739" } ] } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 351 bytes Tasks Shown: All -> Task Tuple data received from node: 351 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using my_2ds_largegeo_idx on documents_16740_167402 collection (actual rows=2 loops=1) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "3.1499999999999999112" } ] } }'::documentdb_core.bson) (12 rows) ROLLBACK; SELECT documentdb_api.delete('db', '{"delete":"geoquerytest", "deletes":[{"q":{}, "limit": 0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""39"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql -- Insert multiple items - 2d index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert multiple items - 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 103, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 104, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 105, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 106, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 107, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 108, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 109, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 110, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 111, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 112, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 113, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 114, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for testing index usage with partial filter expression SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "d" : [15, 15], "e": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "d" : [16, 16], "e": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "d" : [17, 17], "e": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "d" : [18, 18], "e": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "d" : [19, 19], "e": 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "d" : [20, 20], "e": 6 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "d" : [21, 21], "e": 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "d" : [22, 22], "e": 8 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "d" : [23, 23], "e": 9 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "d" : [24, 24], "e": 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 500, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 501, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 2d index explain -- $geoWithin / $within => $box shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (9 rows) -- $geoWithin / $within => Hashes of $center/$centerSphere may vary so skipping those here to avoid flakiness -- $geoWithin / $within => $polygon shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_ab_idx Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (9 rows) -- Explain plan with partial filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2d_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16740_167416 documents_16740 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on my_regular_a_idx Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (9 rows) -- 2dSphere index explains -- $geoIntersects explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- With pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_idx_pfe Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16740_167416 documents_16740 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$eq": [2.1, 2.2]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on "my_regular_geo.loc_idx" Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) (9 rows) -- $geoWithin explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) -- $geometry with legacy formats EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geoloc_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) (9 rows) -- Testing composite 2dsphere index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2dsgeo_a_or_b_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2dsgeo_a_or_b_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2dsgeo_a_or_b_idx on documents_16740_167416 documents_16740 Index Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Testing composite 2dsphere with pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "region" : "USA" }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geo1_2_pfe_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_16740_167416 documents_16740 Recheck Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "region" : "USA" }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds_geo1_2_pfe_idx Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_geo1_2_pfe_idx on documents_16740_167416 documents_16740 Index Cond: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index but should return same values QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16740_167416 documents_16740 Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) COMMIT; -- few items for $center recheck condition SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "a" : { "b": [70, 70] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 402, "a" : { "b": [80, 80] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 403, "a" : { "b": [90, 90] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; BEGIN; set local enable_seqscan TO off; -- Not running analyze on sharded collections as EXPLAIN returns task from only 1 of the 8 shards so the result can be flaky -- Testing $center and $centerSphere with infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_geoloc_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (7 rows) -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "100" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_geoloc_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "1" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_largegeo_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-59.802468529298138833" }, { "$numberDouble" : "-2.3633072488322852678" } ], { "$numberDouble" : "2.7684032724649791923" } ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_largegeo_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "2.9592242752161572739" } ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_largegeo_idx on documents_16740_167416 documents_16740 Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "3.1499999999999999112" } ] } }'::documentdb_core.bson) (9 rows) ROLLBACK; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) bson_query_operator_geospatial_tests_explain_runtime.out000066400000000000000000004421321507310017400435500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167500; SET documentdb.next_collection_id TO 16750; SET documentdb.next_collection_index_id TO 16750; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql -- Insert multiple items - 2d index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert multiple items - 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 103, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 104, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 105, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 106, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 107, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 108, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 109, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 110, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 111, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 112, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 113, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 114, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for testing index usage with partial filter expression SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "d" : [15, 15], "e": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "d" : [16, 16], "e": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "d" : [17, 17], "e": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "d" : [18, 18], "e": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "d" : [19, 19], "e": 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "d" : [20, 20], "e": 6 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "d" : [21, 21], "e": 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "d" : [22, 22], "e": 8 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "d" : [23, 23], "e": 9 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "d" : [24, 24], "e": 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 500, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 501, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 2d index explain -- $geoWithin / $within => $box shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (7 rows) -- $geoWithin / $within => Hashes of $center/$centerSphere may vary so skipping those here to avoid flakiness -- $geoWithin / $within => $polygon shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (7 rows) -- Explain plan with partial filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (7 rows) -- 2dSphere index explains -- $geoIntersects explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- With pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$eq": [2.1, 2.2]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) (7 rows) -- $geoWithin explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- $geometry with legacy formats EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) (7 rows) -- Testing composite 2dsphere index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Testing composite 2dsphere with pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Seq Scan on documents_16750_167503 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index but should return same values QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: object_id -> Seq Scan on documents_16750_167503 collection Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) COMMIT; ANALYZE; BEGIN; set local enable_seqscan TO off; -- Testing $center and $centerSphere with infinite radius EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection (actual rows=4 loops=1) Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 32 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=12 loops=1) Task Count: 1 Tuple data received from nodes: 1765 bytes Tasks Shown: All -> Task Tuple data received from node: 1765 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection (actual rows=12 loops=1) Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 24 (10 rows) -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection (actual rows=4 loops=1) Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "100" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 32 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 1603 bytes Tasks Shown: All -> Task Tuple data received from node: 1603 bytes Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167503 collection (actual rows=9 loops=1) Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "1" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 27 (10 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Seq Scan on documents_16750_167503 collection (actual rows=0 loops=1) Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-59.802468529298138833" }, { "$numberDouble" : "-2.3633072488322852678" } ], { "$numberDouble" : "2.7684032724649791923" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 36 (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 128 bytes Tasks Shown: All -> Task Tuple data received from node: 128 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=1 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Seq Scan on documents_16750_167503 collection (actual rows=1 loops=1) Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "2.9592242752161572739" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 35 (13 rows) EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 351 bytes Tasks Shown: All -> Task Tuple data received from node: 351 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Seq Scan on documents_16750_167503 collection (actual rows=2 loops=1) Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "3.1499999999999999112" } ] } }'::documentdb_core.bson) Rows Removed by Filter: 34 (13 rows) ROLLBACK; SELECT documentdb_api.delete('db', '{"delete":"geoquerytest", "deletes":[{"q":{}, "limit": 0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""36"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql -- Insert multiple items - 2d index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert multiple items - 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 103, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 104, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 105, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 106, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 107, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 108, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 109, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 110, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 111, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 112, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 113, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 114, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for testing index usage with partial filter expression SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "d" : [15, 15], "e": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "d" : [16, 16], "e": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "d" : [17, 17], "e": 3 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "d" : [18, 18], "e": 4 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "d" : [19, 19], "e": 5 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "d" : [20, 20], "e": 6 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "d" : [21, 21], "e": 7 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "d" : [22, 22], "e": 8 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "d" : [23, 23], "e": 9 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "d" : [24, 24], "e": 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert couple of items for composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 500, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 501, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 2d index explain -- $geoWithin / $within => $box shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } }'::documentdb_core.bson) (7 rows) -- $geoWithin / $within => Hashes of $center/$centerSphere may vary so skipping those here to avoid flakiness -- $geoWithin / $within => $polygon shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$polygon" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ], [ { "$numberInt" : "12" }, { "$numberInt" : "5" } ] ] } }'::documentdb_core.bson) (7 rows) -- Explain plan with partial filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geometry(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "d" : { "$box" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ] ] } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (7 rows) -- 2dSphere index explains -- $geoIntersects explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1999999999999999556" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ], [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Point", "coordinates" : { "lon" : { "$numberDouble" : "3.1000000000000000888" }, "lat" : { "$numberDouble" : "3.2000000000000001776" } } } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ], [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ], [ [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "7" } ], [ { "$numberInt" : "7" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "4" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ], [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "LineString", "coordinates" : [ [ { "$numberInt" : "-25" }, { "$numberInt" : "-25" } ], [ { "$numberInt" : "25" }, { "$numberInt" : "25" } ] ] }, { "type" : "Point", "coordinates" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- With pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$gte": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 5}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 3}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'd'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "d" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "30" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$eq": [2.1, 2.2]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "geo.loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] }'::documentdb_core.bson) (7 rows) -- $geoWithin explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "120.0" }, { "$numberDouble" : "89.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "89.0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) -- $geometry with legacy formats EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : { "lon" : { "$numberInt" : "50" }, "lat" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo.loc" : { "$geometry" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" } ] } }'::documentdb_core.bson) (7 rows) -- Testing composite 2dsphere index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geoA'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoA" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geoB'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geoB" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (7 rows) -- Testing composite 2dsphere with pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "region" : "USA" }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index but should return same values QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: ((documentdb_api_catalog.bson_validate_geography(document, 'geo1'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo1" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson) AND (documentdb_api_catalog.bson_validate_geography(document, 'geo2'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "geo2" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } }'::documentdb_core.bson)) (9 rows) COMMIT; ANALYZE; BEGIN; set local enable_seqscan TO off; -- Not running analyze on sharded collections as EXPLAIN returns task from only 1 of the 8 shards so the result can be flaky -- Testing $center and $centerSphere with infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "5" }, { "$numberInt" : "10" } ], { "$numberDecimal" : "Infinity" } ] } }'::documentdb_core.bson) (7 rows) -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "a.b" : { "$center" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "100" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'geo.loc'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "geo.loc" : { "$centerSphere" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], { "$numberInt" : "1" } ] } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-59.802468529298138833" }, { "$numberDouble" : "-2.3633072488322852678" } ], { "$numberDouble" : "2.7684032724649791923" } ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "2.9592242752161572739" } ] } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_16750_167516 documents_16750 Filter: (documentdb_api_catalog.bson_validate_geography(document, 'largeGeo'::text) OPERATOR(documentdb_api_catalog.@|-|) '{ "largeGeo" : { "$centerSphere" : [ [ { "$numberDouble" : "-61.522660944103108704" }, { "$numberDouble" : "17.799379814518658804" } ], { "$numberDouble" : "3.1499999999999999112" } ] } }'::documentdb_core.bson) (9 rows) ROLLBACK; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) bson_query_operator_geospatial_tests_index.out000066400000000000000000011163551507310017400414620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 168300; SET documentdb.next_collection_id TO 16830; SET documentdb.next_collection_index_id TO 16830; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection -- Tests without sharding -- Geometries BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_core.sql -- Insert multiple items SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert items for $center corner case test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geo" : { "loc": [ 2, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geo" : { "loc": [ 5, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geo" : { "loc": [ 5, 8 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 204, "geo" : { "loc": [ 4, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 205, "geo" : { "loc": [ 5, 4 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 206, "geo" : { "loc": [ 5, 6 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 207, "geo" : { "loc": [ 6, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 208, "geo" : { "loc": [ 0, 0 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 209, "geo" : { "loc": [ 0, 10 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- $geoWithin / $within => $box shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- $geoWithin / $within => $center shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[0,0], { "$numberDecimal" : "Infinity" }]}}}' ORDER BY object_id; -- infinite radius document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 3]}}}' ORDER BY object_id; -- _id 201,202,203 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "202" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "203" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "8" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 1]}}}' ORDER BY object_id; -- _id 204,205,206 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[0, 5], 5]}}}' ORDER BY object_id; -- _id 208,209 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "208" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "209" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ] } } (4 rows) -- $geoWithin / $within => $polygon shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Validate non-geo query operator are not pushed to geo indexes but regular indexes and works fine SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Test valid polygons in query SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]]}}}}'; -- Polygon with points on a great circle of earth document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]]}}}}'; -- Polygon with points on the same longitude document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]]}}}}'; -- Polygon with points on a single latitude, appear as straight line in 2d document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89], [-60, 89], [0, 89], [120, 89], [-120.0, 89]]]}}}}'; -- Polygon with points on a single latitude close to north pole document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]]}}}}'; -- Polygon with points on a single latitude, points going around the earth with similar hole document --------------------------------------------------------------------- (0 rows) -- Special case for array of legacy pairs SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "c" : { "d": [ [10, 10], [100, 100] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "c" : { "d": [ [100, 100], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "c" : [{ "d": [100, 100]}, { "d": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "c" : [{ "d": [10, 10]}, { "d": [100, 100]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[0, 0], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[90, 90], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql -- Insert multiple items -- Old format legacy points are valid for geography SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 15, "geo" : { "loc": [ -46.67527188, -23.60076866 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 16, "geo" : { "loc": [ -46.67354611, -23.60337759 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 50, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 51, "a" : { "b": [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 52, "a" : { "b": [ ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 53, "a" : { "b": { } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 54, "a" : { "b": [ [], [] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 55, "a" : { "b": [ [10, 10], [120, 80] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 56, "a" : { "b": [ [120, 80], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 57, "a" : [{ "b": [120, 80]}, { "b": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 58, "a" : [{ "b": [10, 10]}, { "b": [120, 80]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- for $centerSphere edge test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 17, "geo" : { "loc": [4.9757, 2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 18, "geo" : { "loc": [-4.9757, -2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 19, "geoPrec" : { "loc": [1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 20, "geoPrec" : { "loc": [-1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 21, "geoPrec" : { "loc": [0, 1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 22, "geoPrec" : { "loc": [0, -1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for testing composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 400, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid polygon inserts SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 601, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } } }', NULL); -- all points on equator insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 602, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } } }', NULL); -- all points on same latitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 603, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } } }', NULL); -- all points on same longitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --$geoIntersects operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}' ORDER BY object_id; -- Validate legacy format works document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}' ORDER BY object_id; -- this weird GeoJson mongo native syntax is also supported document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (13 rows) -- with holes, should not include document with _id 4 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (11 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (7 rows) -- Legacy formats with $geometry works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } (1 row) -- Check if a north pole region geography finds a point with _id 12, this is invalid polygon in 2d but valid as a spherical geometry SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } (2 rows) -- $geoWithin operator works with spherical queries with $geometry (Polygon and Multipolygons only) and $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (8 rows) -- SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } (1 row) -- $centerSphere operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 1] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (15 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 4] }}}' ORDER BY object_id; -- still returns results with bigger buffer document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.0984] }}}' ORDER BY object_id; -- edge test for $centerSphere document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.21] }}}' ORDER BY object_id; -- 0.21 is enough to include Point(5 5) and not Point(10 10) so shouldn't include some docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], { "$numberDecimal" : "Infinity" }] }}}' ORDER BY object_id; -- infinite radius should include all docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } { "_id" : { "$numberInt" : "401" }, "largeGeo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ] ] ] } } (2 rows) -- Testing composite 2dsphere index SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "201" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "202" }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) -- Testing composite 2dsphere with pfe SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "301" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "302" }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "region": { "$eq": "USA" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index because pfe doesn't match but should return same values document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) -- Make sure a really big query that requires buffer reallocs don't mess up geometry/geography and return the result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoIntersects" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoWithin" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) -- $centerSphere precision test SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoPrec.loc": {"$geoWithin": {"$centerSphere": [[0,0], {"$numberDouble": "0.017453292519943295"}] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "geoPrec" : { "loc" : [ { "$numberInt" : "1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "20" }, "geoPrec" : { "loc" : [ { "$numberInt" : "-1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "21" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "22" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "-1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } (4 rows) -- $centerSphere test with array of legacy coordinates in document SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0,0], 2] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[90, 90], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (5 rows) ROLLBACK; -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- Geometries BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_core.sql -- Insert multiple items SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert items for $center corner case test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geo" : { "loc": [ 2, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geo" : { "loc": [ 5, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geo" : { "loc": [ 5, 8 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 204, "geo" : { "loc": [ 4, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 205, "geo" : { "loc": [ 5, 4 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 206, "geo" : { "loc": [ 5, 6 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 207, "geo" : { "loc": [ 6, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 208, "geo" : { "loc": [ 0, 0 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 209, "geo" : { "loc": [ 0, 10 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- $geoWithin / $within => $box shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- $geoWithin / $within => $center shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[0,0], { "$numberDecimal" : "Infinity" }]}}}' ORDER BY object_id; -- infinite radius document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 3]}}}' ORDER BY object_id; -- _id 201,202,203 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "202" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "203" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "8" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 1]}}}' ORDER BY object_id; -- _id 204,205,206 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[0, 5], 5]}}}' ORDER BY object_id; -- _id 208,209 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "208" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "209" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ] } } (4 rows) -- $geoWithin / $within => $polygon shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Validate non-geo query operator are not pushed to geo indexes but regular indexes and works fine SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Test valid polygons in query SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]]}}}}'; -- Polygon with points on a great circle of earth document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]]}}}}'; -- Polygon with points on the same longitude document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]]}}}}'; -- Polygon with points on a single latitude, appear as straight line in 2d document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89], [-60, 89], [0, 89], [120, 89], [-120.0, 89]]]}}}}'; -- Polygon with points on a single latitude close to north pole document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]]}}}}'; -- Polygon with points on a single latitude, points going around the earth with similar hole document --------------------------------------------------------------------- (0 rows) -- Special case for array of legacy pairs SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "c" : { "d": [ [10, 10], [100, 100] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "c" : { "d": [ [100, 100], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "c" : [{ "d": [100, 100]}, { "d": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "c" : [{ "d": [10, 10]}, { "d": [100, 100]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[0, 0], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[90, 90], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql -- Insert multiple items -- Old format legacy points are valid for geography SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 15, "geo" : { "loc": [ -46.67527188, -23.60076866 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 16, "geo" : { "loc": [ -46.67354611, -23.60337759 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 50, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 51, "a" : { "b": [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 52, "a" : { "b": [ ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 53, "a" : { "b": { } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 54, "a" : { "b": [ [], [] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 55, "a" : { "b": [ [10, 10], [120, 80] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 56, "a" : { "b": [ [120, 80], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 57, "a" : [{ "b": [120, 80]}, { "b": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 58, "a" : [{ "b": [10, 10]}, { "b": [120, 80]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- for $centerSphere edge test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 17, "geo" : { "loc": [4.9757, 2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 18, "geo" : { "loc": [-4.9757, -2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 19, "geoPrec" : { "loc": [1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 20, "geoPrec" : { "loc": [-1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 21, "geoPrec" : { "loc": [0, 1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 22, "geoPrec" : { "loc": [0, -1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for testing composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 400, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid polygon inserts SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 601, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } } }', NULL); -- all points on equator insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 602, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } } }', NULL); -- all points on same latitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 603, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } } }', NULL); -- all points on same longitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --$geoIntersects operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}' ORDER BY object_id; -- Validate legacy format works document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}' ORDER BY object_id; -- this weird GeoJson mongo native syntax is also supported document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (13 rows) -- with holes, should not include document with _id 4 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (11 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (7 rows) -- Legacy formats with $geometry works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } (1 row) -- Check if a north pole region geography finds a point with _id 12, this is invalid polygon in 2d but valid as a spherical geometry SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } (2 rows) -- $geoWithin operator works with spherical queries with $geometry (Polygon and Multipolygons only) and $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (8 rows) -- SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } (1 row) -- $centerSphere operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 1] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (15 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 4] }}}' ORDER BY object_id; -- still returns results with bigger buffer document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.0984] }}}' ORDER BY object_id; -- edge test for $centerSphere document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.21] }}}' ORDER BY object_id; -- 0.21 is enough to include Point(5 5) and not Point(10 10) so shouldn't include some docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], { "$numberDecimal" : "Infinity" }] }}}' ORDER BY object_id; -- infinite radius should include all docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } { "_id" : { "$numberInt" : "401" }, "largeGeo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ] ] ] } } (2 rows) -- Testing composite 2dsphere index SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "201" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "202" }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) -- Testing composite 2dsphere with pfe SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "301" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "302" }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "region": { "$eq": "USA" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index because pfe doesn't match but should return same values document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) -- Make sure a really big query that requires buffer reallocs don't mess up geometry/geography and return the result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoIntersects" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoWithin" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) -- $centerSphere precision test SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoPrec.loc": {"$geoWithin": {"$centerSphere": [[0,0], {"$numberDouble": "0.017453292519943295"}] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "geoPrec" : { "loc" : [ { "$numberInt" : "1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "20" }, "geoPrec" : { "loc" : [ { "$numberInt" : "-1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "21" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "22" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "-1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } (4 rows) -- $centerSphere test with array of legacy coordinates in document SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0,0], 2] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[90, 90], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (5 rows) ROLLBACK; bson_query_operator_geospatial_tests_runtime.out000066400000000000000000011163531507310017400420340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 168300; SET documentdb.next_collection_id TO 16830; SET documentdb.next_collection_index_id TO 16830; \set prevEcho :ECHO \set ECHO none NOTICE: creating collection -- Tests without sharding -- Geometries BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_core.sql -- Insert multiple items SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert items for $center corner case test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geo" : { "loc": [ 2, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geo" : { "loc": [ 5, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geo" : { "loc": [ 5, 8 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 204, "geo" : { "loc": [ 4, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 205, "geo" : { "loc": [ 5, 4 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 206, "geo" : { "loc": [ 5, 6 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 207, "geo" : { "loc": [ 6, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 208, "geo" : { "loc": [ 0, 0 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 209, "geo" : { "loc": [ 0, 10 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- $geoWithin / $within => $box shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- $geoWithin / $within => $center shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[0,0], { "$numberDecimal" : "Infinity" }]}}}' ORDER BY object_id; -- infinite radius document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 3]}}}' ORDER BY object_id; -- _id 201,202,203 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "202" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "203" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "8" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 1]}}}' ORDER BY object_id; -- _id 204,205,206 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[0, 5], 5]}}}' ORDER BY object_id; -- _id 208,209 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "208" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "209" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ] } } (4 rows) -- $geoWithin / $within => $polygon shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Validate non-geo query operator are not pushed to geo indexes but regular indexes and works fine SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Test valid polygons in query SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]]}}}}'; -- Polygon with points on a great circle of earth document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]]}}}}'; -- Polygon with points on the same longitude document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]]}}}}'; -- Polygon with points on a single latitude, appear as straight line in 2d document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89], [-60, 89], [0, 89], [120, 89], [-120.0, 89]]]}}}}'; -- Polygon with points on a single latitude close to north pole document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]]}}}}'; -- Polygon with points on a single latitude, points going around the earth with similar hole document --------------------------------------------------------------------- (0 rows) -- Special case for array of legacy pairs SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "c" : { "d": [ [10, 10], [100, 100] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "c" : { "d": [ [100, 100], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "c" : [{ "d": [100, 100]}, { "d": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "c" : [{ "d": [10, 10]}, { "d": [100, 100]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[0, 0], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[90, 90], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql -- Insert multiple items -- Old format legacy points are valid for geography SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 15, "geo" : { "loc": [ -46.67527188, -23.60076866 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 16, "geo" : { "loc": [ -46.67354611, -23.60337759 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 50, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 51, "a" : { "b": [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 52, "a" : { "b": [ ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 53, "a" : { "b": { } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 54, "a" : { "b": [ [], [] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 55, "a" : { "b": [ [10, 10], [120, 80] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 56, "a" : { "b": [ [120, 80], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 57, "a" : [{ "b": [120, 80]}, { "b": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 58, "a" : [{ "b": [10, 10]}, { "b": [120, 80]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- for $centerSphere edge test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 17, "geo" : { "loc": [4.9757, 2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 18, "geo" : { "loc": [-4.9757, -2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 19, "geoPrec" : { "loc": [1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 20, "geoPrec" : { "loc": [-1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 21, "geoPrec" : { "loc": [0, 1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 22, "geoPrec" : { "loc": [0, -1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for testing composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 400, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid polygon inserts SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 601, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } } }', NULL); -- all points on equator insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 602, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } } }', NULL); -- all points on same latitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 603, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } } }', NULL); -- all points on same longitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --$geoIntersects operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}' ORDER BY object_id; -- Validate legacy format works document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}' ORDER BY object_id; -- this weird GeoJson mongo native syntax is also supported document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (13 rows) -- with holes, should not include document with _id 4 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (11 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (7 rows) -- Legacy formats with $geometry works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } (1 row) -- Check if a north pole region geography finds a point with _id 12, this is invalid polygon in 2d but valid as a spherical geometry SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } (2 rows) -- $geoWithin operator works with spherical queries with $geometry (Polygon and Multipolygons only) and $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (8 rows) -- SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } (1 row) -- $centerSphere operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 1] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (15 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 4] }}}' ORDER BY object_id; -- still returns results with bigger buffer document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.0984] }}}' ORDER BY object_id; -- edge test for $centerSphere document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.21] }}}' ORDER BY object_id; -- 0.21 is enough to include Point(5 5) and not Point(10 10) so shouldn't include some docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], { "$numberDecimal" : "Infinity" }] }}}' ORDER BY object_id; -- infinite radius should include all docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } { "_id" : { "$numberInt" : "401" }, "largeGeo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ] ] ] } } (2 rows) -- Testing composite 2dsphere index SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "201" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "202" }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) -- Testing composite 2dsphere with pfe SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "301" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "302" }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "region": { "$eq": "USA" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index because pfe doesn't match but should return same values document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) -- Make sure a really big query that requires buffer reallocs don't mess up geometry/geography and return the result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoIntersects" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoWithin" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) -- $centerSphere precision test SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoPrec.loc": {"$geoWithin": {"$centerSphere": [[0,0], {"$numberDouble": "0.017453292519943295"}] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "geoPrec" : { "loc" : [ { "$numberInt" : "1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "20" }, "geoPrec" : { "loc" : [ { "$numberInt" : "-1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "21" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "22" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "-1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } (4 rows) -- $centerSphere test with array of legacy coordinates in document SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0,0], 2] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[90, 90], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (5 rows) ROLLBACK; -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- Geometries BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_core.sql -- Insert multiple items SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert items for $center corner case test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geo" : { "loc": [ 2, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geo" : { "loc": [ 5, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geo" : { "loc": [ 5, 8 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 204, "geo" : { "loc": [ 4, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 205, "geo" : { "loc": [ 5, 4 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 206, "geo" : { "loc": [ 5, 6 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 207, "geo" : { "loc": [ 6, 5 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 208, "geo" : { "loc": [ 0, 0 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 209, "geo" : { "loc": [ 0, 10 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- $geoWithin / $within => $box shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- $geoWithin / $within => $center shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[0,0], { "$numberDecimal" : "Infinity" }]}}}' ORDER BY object_id; -- infinite radius document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 3]}}}' ORDER BY object_id; -- _id 201,202,203 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "202" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "203" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "8" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 1]}}}' ORDER BY object_id; -- _id 204,205,206 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "205" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "206" }, "geo" : { "loc" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } } { "_id" : { "$numberInt" : "207" }, "geo" : { "loc" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[0, 5], 5]}}}' ORDER BY object_id; -- _id 208,209 on boundary document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "201" }, "geo" : { "loc" : [ { "$numberInt" : "2" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "204" }, "geo" : { "loc" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } { "_id" : { "$numberInt" : "208" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "209" }, "geo" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "10" } ] } } (4 rows) -- $geoWithin / $within => $polygon shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "long" : { "$numberLong" : "20" }, "lat" : { "$numberInt" : "20" } } } } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "long" : { "$numberInt" : "25" }, "lat" : { "$numberInt" : "25" } } }, [ { "$numberDouble" : "30.0" }, { "$numberDecimal" : "30" } ], [ { "$numberInt" : "35" }, { "$numberInt" : "35" } ] ] } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Validate non-geo query operator are not pushed to geo indexes but regular indexes and works fine SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) -- Test valid polygons in query SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]]}}}}'; -- Polygon with points on a great circle of earth document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]]}}}}'; -- Polygon with points on the same longitude document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]]}}}}'; -- Polygon with points on a single latitude, appear as straight line in 2d document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89], [-60, 89], [0, 89], [120, 89], [-120.0, 89]]]}}}}'; -- Polygon with points on a single latitude close to north pole document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]]}}}}'; -- Polygon with points on a single latitude, points going around the earth with similar hole document --------------------------------------------------------------------- (0 rows) -- Special case for array of legacy pairs SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "c" : { "d": [ [10, 10], [100, 100] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "c" : { "d": [ [100, 100], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "c" : [{ "d": [100, 100]}, { "d": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "c" : [{ "d": [10, 10]}, { "d": [100, 100]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[0, 0], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[90, 90], 20]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "c" : { "d" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] ] } } { "_id" : { "$numberInt" : "6" }, "c" : { "d" : [ [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "7" }, "c" : [ { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] }, { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "8" }, "c" : [ { "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "d" : [ { "$numberInt" : "100" }, { "$numberInt" : "100" } ] } ] } (4 rows) ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql -- Insert multiple items -- Old format legacy points are valid for geography SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "geo" : { "loc": [2.1, 2.2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "geo" : { "loc": [120, 89.1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 15, "geo" : { "loc": [ -46.67527188, -23.60076866 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 16, "geo" : { "loc": [ -46.67354611, -23.60337759 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 50, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 51, "a" : { "b": [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 52, "a" : { "b": [ ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 53, "a" : { "b": { } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 54, "a" : { "b": [ [], [] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 55, "a" : { "b": [ [10, 10], [120, 80] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 56, "a" : { "b": [ [120, 80], [10, 10] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 57, "a" : [{ "b": [120, 80]}, { "b": [10, 10]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 58, "a" : [{ "b": [10, 10]}, { "b": [120, 80]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- for $centerSphere edge test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 17, "geo" : { "loc": [4.9757, 2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 18, "geo" : { "loc": [-4.9757, -2.66966] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 19, "geoPrec" : { "loc": [1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 20, "geoPrec" : { "loc": [-1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 21, "geoPrec" : { "loc": [0, 1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 22, "geoPrec" : { "loc": [0, -1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for testing composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 400, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid polygon inserts SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 601, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } } }', NULL); -- all points on equator insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 602, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } } }', NULL); -- all points on same latitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 603, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } } }', NULL); -- all points on same longitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) --$geoIntersects operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}' ORDER BY object_id; -- Validate legacy format works document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}' ORDER BY object_id; -- this weird GeoJson mongo native syntax is also supported document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } (7 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (13 rows) -- with holes, should not include document with _id 4 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (11 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (7 rows) -- Legacy formats with $geometry works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } (1 row) -- Check if a north pole region geography finds a point with _id 12, this is invalid polygon in 2d but valid as a spherical geometry SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } (2 rows) -- $geoWithin operator works with spherical queries with $geometry (Polygon and Multipolygons only) and $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (8 rows) -- SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } (1 row) -- $centerSphere operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 1] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (15 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 4] }}}' ORDER BY object_id; -- still returns results with bigger buffer document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.0984] }}}' ORDER BY object_id; -- edge test for $centerSphere document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.21] }}}' ORDER BY object_id; -- 0.21 is enough to include Point(5 5) and not Point(10 10) so shouldn't include some docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], { "$numberDecimal" : "Infinity" }] }}}' ORDER BY object_id; -- infinite radius should include all docs document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "geo" : { "loc" : [ { "$numberDouble" : "2.1000000000000000888" }, { "$numberDouble" : "2.2000000000000001776" } ] } } { "_id" : { "$numberInt" : "2" }, "geo" : [ { "loc" : [ { "$numberDouble" : "3.1000000000000000888" }, { "$numberDouble" : "3.2000000000000001776" } ] }, { "loc" : [ { "$numberDouble" : "4.0999999999999996447" }, { "$numberDouble" : "4.2000000000000001776" } ] } ] } { "_id" : { "$numberInt" : "3" }, "geo" : { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "5.0999999999999996447" }, { "$numberDouble" : "5.2000000000000001776" } ] } } } { "_id" : { "$numberInt" : "4" }, "geo" : [ { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.0999999999999996447" }, { "$numberDouble" : "6.2000000000000001776" } ] } }, { "loc" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "6.2999999999999998224" }, { "$numberDouble" : "6.4000000000000003553" } ] } } ] } { "_id" : { "$numberInt" : "5" }, "geo" : { "loc" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "7.0999999999999996447" }, { "$numberDouble" : "7.2000000000000001776" } ], [ { "$numberDouble" : "7.2999999999999998224" }, { "$numberDouble" : "7.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "6" }, "geo" : { "loc" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "8.0999999999999996447" }, { "$numberDouble" : "8.1999999999999992895" } ], [ { "$numberDouble" : "8.3000000000000007105" }, { "$numberDouble" : "8.4000000000000003553" } ] ] } } } { "_id" : { "$numberInt" : "7" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] ] } } } { "_id" : { "$numberInt" : "9" }, "geo" : { "loc" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "geo" : { "loc" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "-10" } ], [ { "$numberInt" : "-10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ], [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] ] } } } { "_id" : { "$numberInt" : "11" }, "geo" : { "loc" : { "type" : "GeometryCollection", "geometries" : [ { "type" : "Point", "coordinates" : [ { "$numberDouble" : "11.099999999999999645" }, { "$numberDouble" : "11.199999999999999289" } ] }, { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "11.300000000000000711" }, { "$numberDouble" : "11.400000000000000355" } ], [ { "$numberDouble" : "11.5" }, { "$numberDouble" : "11.599999999999999645" } ] ] }, { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "-5" } ], [ { "$numberInt" : "-5" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "5" }, { "$numberInt" : "5" } ] ] ] } ] } } } { "_id" : { "$numberInt" : "12" }, "geo" : { "loc" : [ { "$numberInt" : "120" }, { "$numberDouble" : "89.099999999999994316" } ] } } { "_id" : { "$numberInt" : "13" }, "geo" : { "loc" : { "x" : { "$numberInt" : "50" }, "y" : { "$numberInt" : "50" }, "z" : { "$numberInt" : "51" } } } } { "_id" : { "$numberInt" : "14" }, "geo" : { "loc" : [ { "$numberInt" : "51" }, { "$numberInt" : "51" }, { "$numberInt" : "52" } ] } } { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } { "_id" : { "$numberInt" : "17" }, "geo" : { "loc" : [ { "$numberDouble" : "4.9756999999999997897" }, { "$numberDouble" : "2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "18" }, "geo" : { "loc" : [ { "$numberDouble" : "-4.9756999999999997897" }, { "$numberDouble" : "-2.669659999999999922" } ] } } { "_id" : { "$numberInt" : "601" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "0.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "0.0" } ] ] ] } } } { "_id" : { "$numberInt" : "602" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-120" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "60.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "90.0" }, { "$numberDouble" : "60.0" } ], [ { "$numberDouble" : "-120.0" }, { "$numberDouble" : "60.0" } ] ] ] } } } { "_id" : { "$numberInt" : "603" }, "geo" : { "loc" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "4" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "6" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "8" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] ] ] } } } (20 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "400" }, "largeGeo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "96.328125" }, { "$numberDouble" : "5.6159858191553402307" } ], [ { "$numberDouble" : "153.984375" }, { "$numberDouble" : "-6.3152985383300332956" } ] ] } } { "_id" : { "$numberInt" : "401" }, "largeGeo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "-11.350796722383671877" } ], [ { "$numberDouble" : "135.35156249999997158" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "0.87887178283242761712" } ], [ { "$numberDouble" : "98.96484375" }, { "$numberDouble" : "-11.350796722383671877" } ] ] ] } } (2 rows) -- Testing composite 2dsphere index SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "201" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : { "$numberInt" : "202" }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "200" }, "geoA" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geoB" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) -- Testing composite 2dsphere with pfe SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "301" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } { "_id" : { "$numberInt" : "302" }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "21" }, { "$numberInt" : "21" } ] }, "region" : "USA" } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "region": { "$eq": "USA" } }' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index because pfe doesn't match but should return same values document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "300" }, "geo1" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, "geo2" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] }, "region" : "USA" } (1 row) -- Make sure a really big query that requires buffer reallocs don't mess up geometry/geography and return the result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoIntersects" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoWithin" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.675271879999996827" }, { "$numberDouble" : "-23.600768659999999954" } ] } } { "_id" : { "$numberInt" : "16" }, "geo" : { "loc" : [ { "$numberDouble" : "-46.673546109999996645" }, { "$numberDouble" : "-23.603377590000000907" } ] } } (2 rows) -- $centerSphere precision test SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoPrec.loc": {"$geoWithin": {"$centerSphere": [[0,0], {"$numberDouble": "0.017453292519943295"}] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "19" }, "geoPrec" : { "loc" : [ { "$numberInt" : "1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "20" }, "geoPrec" : { "loc" : [ { "$numberInt" : "-1" }, { "$numberInt" : "0" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "21" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } { "_id" : { "$numberInt" : "22" }, "geoPrec" : { "loc" : [ { "$numberInt" : "0" }, { "$numberInt" : "-1" } ], "d" : { "$numberDouble" : "0.017453292519943295474" } } } (4 rows) -- $centerSphere test with array of legacy coordinates in document SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0,0], 2] }}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "51" }, "a" : { "b" : [ { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } }, { "x" : { "$numberInt" : "2" }, "y" : { "$numberInt" : "2" } }, { "x" : { "$numberInt" : "3" }, "y" : { "$numberInt" : "3" } } ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (6 rows) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[90, 90], 1]}}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "50" }, "a" : { "b" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "40" } ], [ { "$numberInt" : "45" }, { "$numberInt" : "45" } ], [ { "$numberInt" : "50" }, { "$numberInt" : "50" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "55" } ] ] } } { "_id" : { "$numberInt" : "55" }, "a" : { "b" : [ [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ], [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] ] } } { "_id" : { "$numberInt" : "56" }, "a" : { "b" : [ [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ], [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] ] } } { "_id" : { "$numberInt" : "57" }, "a" : [ { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] }, { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } ] } { "_id" : { "$numberInt" : "58" }, "a" : [ { "b" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] }, { "b" : [ { "$numberInt" : "120" }, { "$numberInt" : "80" } ] } ] } (5 rows) ROLLBACK; bson_query_operator_in_opt.out000066400000000000000000002201571507310017400362040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 330000; SET documentdb.next_collection_id TO 33000; SET documentdb.next_collection_index_id TO 33000; DO $$ BEGIN FOR i IN 1..10000 LOOP PERFORM documentdb_api.insert_one('db', 'in_opt_tests', '{ "accid": 1, "vid": 3, "val": [1, 2] }'); END LOOP; END; $$ LANGUAGE plpgsql; NOTICE: creating collection SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":1, "accid": 1, "vid": 1, "val": [1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":2, "accid": 1, "vid": 2, "val": [3, 4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":3, "_id":1, "accid": 1, "vid": 1, "val": [3, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":4, "accid": 1, "vid": 2, "val": {"test": 5}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":5, "accid": 1, "vid": 1, "val": [{"test": 7}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":6, "accid": 1, "vid": 2, "val": [true, false]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":7, "accid": 1, "vid": 1, "val": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":8, "accid": 1, "vid": 2, "val": 3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":9, "accid": 1, "vid": 1, "val": 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":10, "accid": 1, "vid": 2, "val": [2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":11, "accid": 1, "vid": 1, "val": [3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":12, "accid": 1, "vid": 2, "val": [4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":13, "accid": 1, "vid": 1, "val": [1, true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":14, "accid": 1, "vid": 2, "val": [true, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":15, "accid": 1, "vid": 1, "val": [1, 4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":16, "accid": 1, "vid": 2, "val": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":17, "accid": 1, "vid": 1, "val": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":18, "accid": 1, "vid": 2, "val": { "$minKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":19, "accid": 1, "vid": 1, "val": [{ "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":20, "accid": 1, "vid": 2, "val": [{ "$minKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":21, "accid": 1, "vid": 1, "val": [3, { "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":22, "accid": 1, "vid": 2, "val": { "$maxKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":23, "accid": 1, "vid": 1, "val": [{ "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":24, "accid": 1, "vid": 2, "val": [{ "$maxKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":25, "accid": 1, "vid": 1, "val": [3, { "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":26, "accid": 1, "vid": 2, "val": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":27, "accid": 1, "vid": 1, "a": {"val": [1, 2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":28, "accid": 1, "vid": 2, "a": {"val": [3, 4]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":29, "accid": 1, "vid": 1, "a": {"val": [3, 1]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":30, "accid": 1, "vid": 2, "a": {"val": {"test": 5}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":31, "accid": 1, "vid": 1, "a": {"val": [{"test": 7}]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":32, "accid": 1, "vid": 2, "a": {"val": [true, false]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":33, "accid": 1, "vid": 1, "a": {"val": 2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":34, "accid": 1, "vid": 2, "a": {"val": 3}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":35, "accid": 1, "vid": 1, "a": {"val": 4}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":36, "accid": 1, "vid": 2, "a": {"val": [2]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":37, "accid": 1, "vid": 1, "a": {"val": [3]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":38, "accid": 1, "vid": 2, "a": {"val": [4]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":39, "accid": 1, "vid": 1, "a": {"val": [1, true]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":40, "accid": 1, "vid": 2, "a": {"val": [true, 1]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":41, "accid": 1, "vid": 1, "a": {"val": [1, 4]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":42, "accid": 1, "vid": 2, "a": {"val": [null]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":43, "accid": 1, "vid": 1, "a": {"val": null}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":44, "accid": 1, "vid": 2, "a": {"val": { "$minKey": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":45, "accid": 1, "vid": 1, "a": {"val": [{ "$minKey": 1 }]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":46, "accid": 1, "vid": 2, "a": {"val": [{ "$minKey": 1 }, 3]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":47, "accid": 1, "vid": 1, "a": {"val": [3, { "$minKey": 1 }]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":48, "accid": 1, "vid": 2, "a": {"val": { "$maxKey": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":49, "accid": 1, "vid": 1, "a": {"val": [{ "$maxKey": 1 }]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":50, "accid": 1, "vid": 2, "a": {"val": [{ "$maxKey": 1 }, 3]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":51, "accid": 1, "vid": 1, "a": {"val": [3, { "$maxKey": 1 }]}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":52, "accid": 1, "vid": 2, "a": {"val": []}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 2, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "7" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (8 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "in_opt_tests", "indexes": [ {"key": {"val": 1, "accid": 1, "vid": 1}, "name": "val_accid_vid"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "in_opt_tests", "indexes": [ {"key": {"a.val": 1, "accid": 1, "vid": 1}, "name": "a_val_accid_vid"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) -- no optimization EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Result One-Time Filter: false (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on val_accid_vid Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on a_val_accid_vid Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330005 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "27" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "39" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, true ] } } { "_id" : { "$numberInt" : "41" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (7 rows) -- no optimization SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "8" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "12" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "20" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "24" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (11 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "34" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "35" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "38" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "41" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "46" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "50" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (11 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (4 rows) END; SELECT documentdb_api.shard_collection('db','in_opt_tests', '{"accid":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (shard_key_value = '4322365043291501017'::bigint) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: ((shard_key_value = '4322365043291501017'::bigint) AND ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (shard_key_value = '4322365043291501017'::bigint) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (shard_key_value = '4322365043291501017'::bigint) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) -- no optimization EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Result One-Time Filter: (false AND false) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330016 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on val_accid_vid Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330016 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on a_val_accid_vid Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.val" : [ { "$numberInt" : "4" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (shard_key_value = '4322365043291501017'::bigint) -> Bitmap Index Scan on val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_33000_330023 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (shard_key_value = '4322365043291501017'::bigint) -> Bitmap Index Scan on a_val_accid_vid Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.val" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (10 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "13" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, true ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (7 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "27" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "39" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, true ] } } { "_id" : { "$numberInt" : "41" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (7 rows) -- no optimization SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "8" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "9" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "12" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "15" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "20" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "24" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (11 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "34" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : { "$numberInt" : "3" } } } { "_id" : { "$numberInt" : "35" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : { "$numberInt" : "4" } } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "38" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "41" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } } { "_id" : { "$numberInt" : "46" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "50" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "2" }, "a" : { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (11 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "_id" : { "$numberInt" : "1" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "_id" : { "$numberInt" : "11" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "21" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "_id" : { "$numberInt" : "25" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "29" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } } { "_id" : { "$numberInt" : "37" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" } ] } } { "_id" : { "$numberInt" : "47" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } } { "_id" : { "$numberInt" : "51" }, "accid" : { "$numberInt" : "1" }, "vid" : { "$numberInt" : "1" }, "a" : { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } } (4 rows) END; bson_query_operator_near_nearsphere.out000066400000000000000000006710411507310017400400570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 523000; SET documentdb.next_collection_id TO 5230; SET documentdb.next_collection_index_id TO 5230; SET search_path to documentdb_api_catalog; SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 1, "a": { "b": [ 0, 0]} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 2, "a": { "b": [ 1.1, 1.1]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 3, "a": { "b": [ 2.29, 2.29]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 4, "a": { "b": [ 3.31, 3.31]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 5, "a": { "b": [ 4.42, 4.42]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 6, "a": { "b": [ 5.5, 5.5]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 7, "a": { "b": [ 6.66, 6.66]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 8, "a": { "b": [ 7.74, 7.74]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 9, "a": { "b": [ 8.81, 8.81]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 10, "a": { "geo": {"type": "Point", "coordinates": [35.3, 35.4]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 11, "a": { "geo": {"type": "LineString", "coordinates": [[35.36, 35.42], [32.3, 30]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 12, "a": { "geo": {"type": "Polygon", "coordinates": [[[35.73, 35.74], [38.6, 35.3], [38.7, 39.2], [35.73, 35.74]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 13, "a": { "geo": {"type": "MultiPoint", "coordinates": [[35.43, 35.44], [32.3, 30.3]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 14, "a": { "geo": {"type": "MultiLineString", "coordinates": [[[35.83, 35.84], [32.3, 30.6]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 15, "a": { "geo": {"type": "MultiPolygon", "coordinates": [[[[35.312, 35.441], [38.644, 35.3231], [38.71, 39.32], [35.312, 35.441]]]]}} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test near and nearsphere with index and runtime flags -- Should fail SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); ERROR: unable to find index for $geoNear query SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); ERROR: unable to find index for $geoNear query BEGIN; -- Should pass SET LOCAL documentdb.enable_force_push_geonear_index to off; SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) ROLLBACK; -- $near and $nearSphere enforce index usage SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }, {"key": {"a.geo": "2dsphere"}, "name": "my_2ds_ageo_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','near_sphere'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'near_sphere') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5230 | 5231 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : "2d" }, "name" : "my_2d_ab_idx" } | t 5230 | 5232 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : "2dsphere" }, "name" : "my_2ds_ab_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t 5230 | 5233 | { "v" : { "$numberInt" : "2" }, "key" : { "a.geo" : "2dsphere" }, "name" : "my_2ds_ageo_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t (3 rows) -- validations -- $near/$nearSphere tests SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0] } }}'); ERROR: Invalid parameter detected in geo near query: 0 SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0]}}}}}'); ERROR: Invalid parameter detected in geo near query: coordinates SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$hello": 1}}}}'); ERROR: Invalid parameter detected in geo near query: $hello SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point"}}}}}'); ERROR: The parameter $near expects a GeoJSON point, but received { "type" : "Point" } instead SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"tide": "Point", "coordintes": [1,1]}}}}}'); ERROR: The parameter $near expects a GeoJSON point, but received { "tide" : "Point", "coordintes" : [ 1, 1 ] } instead SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {}}}}'); ERROR: A geo near query requires the $geometry to be specified. SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": []}}}'); ERROR: A geo near query requires the $geometry to be specified. SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"tide": "Point", "coordintes": [1,1]}}}}'); ERROR: Invalid parameter detected in geo near query: tide SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 1, "coordinates": [1,1]}}}}'); ERROR: Invalid parameter detected in geo near query: x SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": "a", "y": 1}}}}'); ERROR: Invalid parameter detected in geo near query: x SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0] } }}'); ERROR: Invalid parameter detected in geo near query: 0 SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0]}}}}}'); ERROR: Invalid parameter detected in geo near query: coordinates SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$hello": 1}}}}'); ERROR: Invalid parameter detected in geo near query: $hello SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point"}}}}}'); ERROR: The parameter $near expects a GeoJSON point, but received { "type" : "Point" } instead SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"tide": "Point", "coordintes": [1,1]}}}}}'); ERROR: The parameter $near expects a GeoJSON point, but received { "tide" : "Point", "coordintes" : [ 1, 1 ] } instead SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {}}}}'); ERROR: A geo near query requires the $geometry to be specified. SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": []}}}'); ERROR: A geo near query requires the $geometry to be specified. SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"tide": "Point", "coordintes": [1,1]}}}}'); ERROR: Invalid parameter detected in geo near query: tide SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 1, "coordinates": [1,1]}}}}'); ERROR: Invalid parameter detected in geo near query: x SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": "a", "y": 1}}}}'); ERROR: Invalid parameter detected in geo near query: x SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [1,1]}}, "b": { "$nearSphere": {"coordinates": [1,1]}}}}'); ERROR: Excessive number of geoNear query expressions SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [1,1]}}, "b": { "$nearSphere": {"coordinates": [1,1]}}}}'); ERROR: Excessive number of geoNear query expressions SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [1,1]}}, "b": { "$near": {"coordinates": [1,1]}}}}'); ERROR: Excessive number of geoNear query expressions SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "near_sphere", "pipeline": [ { "$sort": { "a.b": 1 }}, { "$match": { "a.b": { "$near": {"coordinates": [1,1]}}}} ], "cursor": {} }'); ERROR: Operators $geoNear, $near, and $nearSphere cannot be used in this particular context -- $near/$nearSphere with invalid distance argument SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$minDistance": -1}}}'); ERROR: minDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$minDistance": {"$numberDouble": "NaN"}}}}'); ERROR: minDistance must be positive or zero SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"coordinates": [1, 1]}, "$minDistance": {"$numberDouble": "Infinity"}}}}}'); ERROR: The value of minDistance must always be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"coordinates": [1, 1]}, "$maxDistance": {"$numberDouble": "Infinity"}}}}}'); ERROR: maxDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$maxDistance": {"$numberDouble": "-Infinity"}}}}'); ERROR: maxDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$maxDistance": {"$numberDouble": "-NaN"}}}}'); ERROR: maxDistance must be positive or zero SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$minDistance": -1}}}'); ERROR: minDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$minDistance": {"$numberDouble": "NaN"}}}}'); ERROR: minDistance must be positive or zero SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"coordinates": [1, 1]}, "$minDistance": {"$numberDouble": "Infinity"}}}}}'); ERROR: The value of minDistance must always be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"coordinates": [1, 1]}, "$maxDistance": {"$numberDouble": "Infinity"}}}}}'); ERROR: maxDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$maxDistance": {"$numberDouble": "-Infinity"}}}}'); ERROR: maxDistance value must be zero or greater SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$maxDistance": {"$numberDouble": "-NaN"}}}}'); ERROR: maxDistance must be positive or zero -- invalid places to call $near/$nearSphere SELECT document FROM documentdb_api.collection('db','near_sphere') WHERE document @@ '{ "a.b": { "$elemMatch" : {"$near": [1,1] }}}'; ERROR: $near, $nearSphere and $geoNear cannot be used here. Use $geoWithin instead. SELECT document FROM documentdb_api.collection('db','near_sphere') WHERE document @@ '{ "$or": [{"a.b": {"$near": [1,1] }},{"t": 1}]}'; ERROR: $geoNear must appear at the top level of the expression SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": {}, "projection": { "p" : {"$elemMatch": {"geo": {"$near": [1,1]}}}}}'); ERROR: $near, $nearSphere and $geoNear cannot be used here. Use $geoWithin instead. SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{},"u":{"$set": {"a.$[elem].b": 1}},"multi":false,"upsert":true, "arrayFilters": [{"elem.geo": {"$near": [1, 1]}}]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""21757981"" }, ""errmsg"" : ""$near, $nearSphere and $geoNear cannot be used here. Use $geoWithin instead."" } ] }",f) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere", "indexes": [{"key": {"t": 1}, "name": "my_invalid_idx", "partialFilterExpression": {"geo": {"$near": [1,1]}} }]}', true); ERROR: Error in specification { "key" : { "t" : 1 }, "name" : "my_invalid_idx", "partialFilterExpression" : { "geo" : { "$near" : [ 1, 1 ] } } }:Operators $geoNear, $near, and $nearSphere cannot be used in this particular context BEGIN; -- $near operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 6}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$maxDistance": 6}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0, "z": 6}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } (4 rows) -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [5, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) -- $nearSphere operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.1}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$maxDistance": 0.15}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.16, "$maxDistance": 0.2}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0, 0.15]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0, "z": 0.15}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [5, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) -- Test with GeoJson objects in documents -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": { "type": "Point", "coordinates": [5, 6] }}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) -- Verify that @@ operator handles the near / nearSphere operators SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.b": { "$near": [5, 6]}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.b": { "$near": [5, 6]}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.geo": { "$nearSphere": [5, 6]}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) -- Explain tests to ensure index pushdown EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist" }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist" }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE (((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" } }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" }'::documentdb_core.bson) (11 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE (((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (11 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE (((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (11 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.geo", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ageo_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.geo", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.geo", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (10 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_5230_523006 collection WHERE (((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '5230'::bigint)) ORDER BY (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523006 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) Order By: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (11 rows) ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) -- check update BEGIN; SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""21757981"" }, ""errmsg"" : ""Operators $geoNear, $near, and $nearSphere cannot be used in this particular context"" } ] }",f) (1 row) SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1.1,1.1]}} ,"u":{"$set": {"t": 1}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""21757981"" }, ""errmsg"" : ""Operators $geoNear, $near, and $nearSphere cannot be used in this particular context"" } ] }",f) (1 row) SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""21757981"" }, ""errmsg"" : ""Operators $geoNear, $near, and $nearSphere cannot be used in this particular context"" } ] }",f) (1 row) ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'near_sphere', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL enable_seqscan to off; set local citus.enable_local_execution TO OFF; SET LOCAL seq_page_cost TO 9999999; -- $near operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 6}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$maxDistance": 6}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0, "z": 6}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } (4 rows) -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [5, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) -- $nearSphere operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.1}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$maxDistance": 0.15}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.16, "$maxDistance": 0.2}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0, "z": 0.15}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } (6 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [5, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "b" : [ { "$numberDouble" : "5.5" }, { "$numberDouble" : "5.5" } ] } } { "_id" : { "$numberInt" : "5" }, "a" : { "b" : [ { "$numberDouble" : "4.4199999999999999289" }, { "$numberDouble" : "4.4199999999999999289" } ] } } { "_id" : { "$numberInt" : "7" }, "a" : { "b" : [ { "$numberDouble" : "6.6600000000000001421" }, { "$numberDouble" : "6.6600000000000001421" } ] } } { "_id" : { "$numberInt" : "4" }, "a" : { "b" : [ { "$numberDouble" : "3.3100000000000000533" }, { "$numberDouble" : "3.3100000000000000533" } ] } } { "_id" : { "$numberInt" : "8" }, "a" : { "b" : [ { "$numberDouble" : "7.7400000000000002132" }, { "$numberDouble" : "7.7400000000000002132" } ] } } { "_id" : { "$numberInt" : "3" }, "a" : { "b" : [ { "$numberDouble" : "2.2900000000000000355" }, { "$numberDouble" : "2.2900000000000000355" } ] } } { "_id" : { "$numberInt" : "9" }, "a" : { "b" : [ { "$numberDouble" : "8.8100000000000004974" }, { "$numberDouble" : "8.8100000000000004974" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "b" : [ { "$numberDouble" : "1.1000000000000000888" }, { "$numberDouble" : "1.1000000000000000888" } ] } } { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } } (9 rows) -- Test with GeoJson objects in documents -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$minDistance": 0.8}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$maxDistance": 0.8}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } (3 rows) -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [5, 6]}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}}'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" }, "a" : { "geo" : { "type" : "LineString", "coordinates" : [ [ { "$numberDouble" : "35.359999999999999432" }, { "$numberDouble" : "35.420000000000001705" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberInt" : "30" } ] ] } } } { "_id" : { "$numberInt" : "13" }, "a" : { "geo" : { "type" : "MultiPoint", "coordinates" : [ [ { "$numberDouble" : "35.429999999999999716" }, { "$numberDouble" : "35.439999999999997726" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.300000000000000711" } ] ] } } } { "_id" : { "$numberInt" : "14" }, "a" : { "geo" : { "type" : "MultiLineString", "coordinates" : [ [ [ { "$numberDouble" : "35.829999999999998295" }, { "$numberDouble" : "35.840000000000003411" } ], [ { "$numberDouble" : "32.299999999999997158" }, { "$numberDouble" : "30.600000000000001421" } ] ] ] } } } { "_id" : { "$numberInt" : "10" }, "a" : { "geo" : { "type" : "Point", "coordinates" : [ { "$numberDouble" : "35.299999999999997158" }, { "$numberDouble" : "35.399999999999998579" } ] } } } { "_id" : { "$numberInt" : "15" }, "a" : { "geo" : { "type" : "MultiPolygon", "coordinates" : [ [ [ [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ], [ { "$numberDouble" : "38.643999999999998352" }, { "$numberDouble" : "35.323099999999996612" } ], [ { "$numberDouble" : "38.710000000000000853" }, { "$numberDouble" : "39.320000000000000284" } ], [ { "$numberDouble" : "35.311999999999997613" }, { "$numberDouble" : "35.441000000000002501" } ] ] ] ] } } } { "_id" : { "$numberInt" : "12" }, "a" : { "geo" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ], [ { "$numberDouble" : "38.600000000000001421" }, { "$numberDouble" : "35.299999999999997158" } ], [ { "$numberDouble" : "38.700000000000002842" }, { "$numberDouble" : "39.200000000000002842" } ], [ { "$numberDouble" : "35.729999999999996874" }, { "$numberDouble" : "35.74000000000000199" } ] ] ] } } } (6 rows) -- Explain tests to ensure index pushdown EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist" }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberInt" : "5" }, "maxDistance" : { "$numberInt" : "8" }, "distanceField" : "dist" } }'::documentdb_core.bson) (13 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) (13 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE ((documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2d_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geometry(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geometry(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ], "minDistance" : { "$numberDouble" : "0.80000000000000004441" }, "maxDistance" : { "$numberInt" : "1" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) (13 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.geo", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) IS NOT NULL) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ageo_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.geo'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.geo", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) (12 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); QUERY PLAN --------------------------------------------------------------------- Sort Output: remote_scan.document, remote_scan.distance Sort Key: remote_scan.distance -> Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.distance Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) AS distance FROM documentdb_data.documents_5230_523016 collection WHERE ((documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) IS NOT NULL) AND (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson)) Node: host=localhost port=58070 dbname=regression -> Index Scan using my_2ds_ab_idx on documentdb_data.documents_5230_523016 collection Output: document, (documentdb_api_catalog.bson_validate_geography(document, 'a.b'::text) OPERATOR(documentdb_api_catalog.<|-|>) '{ "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true }'::documentdb_core.bson) Index Cond: (documentdb_api_catalog.bson_validate_geography(collection.document, 'a.b'::text) OPERATOR(documentdb_api_internal.@|><|) '{ "a.b" : { "key" : "a.b", "near" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] }, "minDistance" : { "$numberInt" : "500000" }, "maxDistance" : { "$numberInt" : "1500000" }, "distanceField" : "dist", "spherical" : true } }'::documentdb_core.bson) (13 rows) ROLLBACK; -- update with sharded BEGIN; SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""21757981"" }, ""errmsg"" : ""Operators $geoNear, $near, and $nearSphere cannot be used in this particular context"" } ] }",f) (1 row) ROLLBACK; -- Test near and nearsphere with different sorting features. SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 1, "zone": 1, "loc": { "type": "Point", "coordinates": [-20, -20]} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 2, "zone": 2, "loc": { "type": "Point", "coordinates": [-10, -10]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 3, "zone": 3, "loc": { "type": "Point", "coordinates": [0, 0]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 4, "zone": 4, "loc": { "type": "Point", "coordinates": [10, 10]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 5, "zone": 5, "loc": { "type": "Point", "coordinates": [20, 20]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 6, "zone": 1, "loc": { "type": "Point", "coordinates": [-20, -20]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 7, "zone": 2, "loc": { "type": "Point", "coordinates": [-10, -10]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 8, "zone": 3, "loc": { "type": "Point", "coordinates": [0, 0]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 9, "zone": 4, "loc": { "type": "Point", "coordinates": [10, 10]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 10, "zone": 5, "loc": { "type": "Point", "coordinates": [20, 20]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 11, "zone": 6, "loc": { "type": "Point", "coordinates": [30, 30]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere_distinct", "indexes": [{"key": {"loc.coordinates": "2d"}, "name": "my_2d_loccoord_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "near_sphere_distinct", "key": "zone", "query": {"loc.coordinates": { "$near": [0, 0], "$maxDistance": 1}} }'); document --------------------------------------------------------------------- { "values" : [ { "$numberInt" : "3" } ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- find and modify fails with geonear -- With sort on findAndModify with near, sort takes precedence SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "near_sphere_distinct", "query": { "loc.coordinates": { "$near": [0, 0], "$maxDistance": 1} }, "sort": {"_id": -1}, "update": {"a": 10}, "fields": {"_id": 1}}'); ERROR: Operators $geoNear, $near, and $nearSphere cannot be used in this particular context CONTEXT: SQL statement "SELECT ctid, object_id, document FROM documentdb_data.documents_5231_523025 WHERE documentdb_api_internal.bson_query_match(document, $1::documentdb_core.bson, $2::documentdb_core.bson, $3::text) ORDER BY documentdb_api_catalog.bson_orderby(document, $4::documentdb_core.bson) DESC LIMIT 1 FOR UPDATE" SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_5231 WHERE shard_key_value = 5231" -- If no sort clause then near decides the ordering SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "near_sphere_distinct", "query": { "loc.coordinates": { "$near": [30, 30]} }, "update": {"a": 10}, "fields": {"_id": 1}}'); ERROR: Operators $geoNear, $near, and $nearSphere cannot be used in this particular context CONTEXT: SQL statement "SELECT ctid, object_id, document FROM documentdb_data.documents_5231_523025 WHERE documentdb_api_internal.bson_query_match(document, $1::documentdb_core.bson, $2::documentdb_core.bson, $3::text) LIMIT 1 FOR UPDATE" SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_5231 WHERE shard_key_value = 5231" bson_query_operator_object_id_tests.out000066400000000000000000000434541507310017400400630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 251000; SET documentdb.next_collection_id TO 2510; SET documentdb.next_collection_index_id TO 2510; SELECT COUNT(*) FROM (SELECT documentdb_api.insert_one('db', 'test_object_id_index', FORMAT('{ "_id": %s, "a": %s, "otherField": "aaaa" }', g, g)::bson) FROM generate_series(1, 10000) g) i; NOTICE: creating collection count --------------------------------------------------------------------- 10000 (1 row) EXPLAIN (COSTS ON) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection (cost=0.00..0.00 rows=1 width=32) Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "15" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS ON) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 55, 90 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection (cost=0.00..0.00 rows=1 width=32) Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"15\" } }","{ \"\" : { \"$numberInt\" : \"55\" } }","{ \"\" : { \"$numberInt\" : \"90\" } }"}'::documentdb_core.bson[]))) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gt": 50 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "50" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "50" } }'::documentdb_core.bson) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gt": 50, "$lt": 60 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "60" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "60" } }'::documentdb_core.bson)) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gte": 50, "$lte": 60 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "60" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "60" } }'::documentdb_core.bson)) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": 15 }, { "_id": 16 } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "15" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "16" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "15" } }'::documentdb_core.bson) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": { "$in": [ 15, 16, 17] }}, { "_id": { "$in": [ 16, 17, 18 ] } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"15\" } }","{ \"\" : { \"$numberInt\" : \"16\" } }","{ \"\" : { \"$numberInt\" : \"17\" } }"}'::documentdb_core.bson[])) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"16\" } }","{ \"\" : { \"$numberInt\" : \"17\" } }","{ \"\" : { \"$numberInt\" : \"18\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "16" }, { "$numberInt" : "17" }, { "$numberInt" : "18" } ] }'::documentdb_core.bson) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": { "$gt": 50 } }, { "_id": { "$lt": 60 } } ] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "60" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "50" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "60" } }'::documentdb_core.bson)) (8 rows) -- create a scenario where there's an alternate filter and that can be matched in the RUM index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_object_id_index", "indexes": [ { "key": { "otherField": 1 }, "name": "idx_1" } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 20 ] }, "otherField": "aaaa" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"15\" } }","{ \"\" : { \"$numberInt\" : \"20\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "otherField" : "aaaa" }'::documentdb_core.bson) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15 ] }, "otherField": "aaaa" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251007 collection Index Cond: ((shard_key_value = '2510'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "15" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "otherField" : "aaaa" }'::documentdb_core.bson) (8 rows) -- now shard the collection SELECT documentdb_api.shard_collection('db', 'test_object_id_index', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- we shouldn't have object_id filters unless we also have shard key filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_2510_251016 documents_2510 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "15" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "15" } }'::documentdb_core.bson) (9 rows) BEGIN; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 55, 90 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_2510_251016 documents_2510 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "15" }, { "$numberInt" : "55" }, { "$numberInt" : "90" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "15" }, { "$numberInt" : "55" }, { "$numberInt" : "90" } ] }'::documentdb_core.bson) (9 rows) ROLLBACK; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15, "a": 15 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_2510_251023 collection Index Cond: ((shard_key_value = '8792588867541173546'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "15" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "15" } }'::documentdb_core.bson) (8 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15, "a": { "$gt": 15 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_2510_251016 documents_2510 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "15" } }'::documentdb_core.bson) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "15" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "15" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 20 ] }, "otherField": "aaaa" }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_2510_251016 documents_2510 Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "otherField" : "aaaa" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" } ] }'::documentdb_core.bson)) -> BitmapAnd -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "otherField" : "aaaa" }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "15" }, { "$numberInt" : "20" } ] }'::documentdb_core.bson) (12 rows) bson_query_operator_pfe_index_pushdown.out000066400000000000000000001270231507310017400406020ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path to documentdb_api_catalog; SET citus.next_shard_id TO 10980000; SET documentdb.next_collection_id TO 10980; SET documentdb.next_collection_index_id TO 10980; SELECT documentdb_api.create_collection('db', 'bsonquery'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- insert documents with different compositions of keys and types SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 1, "a" : { "c" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 2, "a" : { "d" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 3, "a" : { "b" : 1 }, "b": "xyz" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 4, "a" : { "b" : { "$undefined": true } }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 5, "a" : { "b" : "xxx" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 6, "a" : { "c" : "xxx" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 7, "a" : { "e" : 1, "f": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create indexes with partial filter expressions SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "bsonquery", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$exists": true } } }, { "key": {"a.c": 1}, "name": "my_idx_2", "partialFilterExpression": { "a.c": {"$gte": "abc" } } }, { "key": {"a.e": 1, "a.f": 1}, "name": "my_idx_3", "partialFilterExpression": { "a.e": 1, "a.f": 1 } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT collection_id AS collid FROM documentdb_api_catalog.collections WHERE collection_name = 'bsonquery' AND database_name = 'db' \gset \d documentdb_data.documents_:collid Table "documentdb_data.documents_10980" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_10980" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_10981" documentdb_rum (document bson_rum_single_path_ops (path='a.b', tl='2699')) WHERE document #>= '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery "documents_rum_index_10982" documentdb_rum (document bson_rum_single_path_ops (path='a.c', tl='2699')) WHERE document #>= '{ "a.c" : "abc" }'::documentdb_core.bsonquery "documents_rum_index_10983" documentdb_rum (document bson_rum_single_path_ops (path='a.e', tl='2691'), document bson_rum_single_path_ops (path='a.f', tl='2691')) WHERE document #= '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery AND document #= '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery Check constraints: "shard_key_value_check" CHECK (shard_key_value = '10980'::bigint) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "bsonquery" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bsonquery", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bsonquery", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "my_idx_1", "partialFilterExpression" : { "a.b" : { "$exists" : true } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bsonquery", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a.c" : { "$numberInt" : "1" } }, "name" : "my_idx_2", "partialFilterExpression" : { "a.c" : { "$gte" : "abc" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.bsonquery", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a.e" : { "$numberInt" : "1" }, "a.f" : { "$numberInt" : "1" } }, "name" : "my_idx_3", "partialFilterExpression" : { "a.e" : { "$numberInt" : "1" }, "a.f" : { "$numberInt" : "1" } } } }, "ok" : { "$numberDouble" : "1.0" } } (4 rows) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','bsonquery');; drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- should push down to pfe index since types match EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : "c" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.c" : "abc" }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : "c" }'::documentdb_core.bson) (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "c" : "xxx" } } (1 row) -- should not push to pfe index due to type mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; document --------------------------------------------------------------------- (0 rows) -- should push to $exists pfe index using minkey EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : "a" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : "a" }'::documentdb_core.bson) (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : "xxx" } } (1 row) -- should not push to $exists pfe index due to key mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.d" : "a" }'::documentdb_core.bson) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; document --------------------------------------------------------------------- (0 rows) -- should push to pfe index when $ne is present EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery)) Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on my_idx_3 (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } } } (1 row) -- should not push to pfe index due to missing key EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } } } (1 row) -- should not push to pfe index since $eq: null cannot match $exists: true EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": null }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$ne": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gt": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lt": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gte": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lte": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) -- test PFE pushdown for $in -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$in" : [ 1, 2, 3 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) -- cannot push down (fails PFE) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "aaa", "aa1" ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "aaa", "aa1" ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "aaa", "bbb" ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "aaa", "bbb" ] }'::documentdb_core.bson) (7 rows) -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "ccc", "bbb" ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "ccc", "bbb" ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.c" : "abc" }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "ccc", "bbb" ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "abc", "bbb" ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "abc", "bbb" ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.c" : "abc" }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.c" : [ "abc", "bbb" ] }'::documentdb_core.bson) (9 rows) -- cannot push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.f": { "$in": [ 3, 4 ]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.f" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.g": { "$in": [ 3, 4 ]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.g" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.f": { "$in": [ 3, 1 ]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980001 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.f" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson)) (7 rows) -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 1, 1 ] }, "a.f": { "$in": [ 1, 1 ]} }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980001 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.f" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_3 Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a.e" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a.f" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] }'::documentdb_core.bson)) (9 rows) ROLLBACK; -- shard the collection SELECT documentdb_api.shard_collection('db', 'bsonquery', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- rerun the queries BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- should push down to pfe index since types match EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980016 documents_10980 Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : "c" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.c" : "abc" }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_2 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : "c" }'::documentdb_core.bson) (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "c" : "xxx" } } (1 row) -- should not push to pfe index due to type mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.c" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; document --------------------------------------------------------------------- (0 rows) -- should push to $exists pfe index using minkey EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980016 documents_10980 Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : "a" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "a.b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : "a" }'::documentdb_core.bson) (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "b" : "xxx" } } (1 row) -- should not push to $exists pfe index due to key mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.d" : "a" }'::documentdb_core.bson) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; document --------------------------------------------------------------------- (0 rows) -- should push to pfe index when $ne is present EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10980_10980016 documents_10980 Recheck Cond: ((document OPERATOR(documentdb_api_catalog.#=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bsonquery)) Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.f" : { "$numberInt" : "1" } }'::documentdb_core.bson)) -> Bitmap Index Scan on my_idx_3 (9 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } } } (1 row) -- should not push to pfe index due to missing key EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.e" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (7 rows) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } } } (1 row) -- should not push to pfe index since $eq: null cannot match $exists: true EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": null }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$ne": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gt": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lt": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gte": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lte": null } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_10980_10980016 documents_10980 Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : null }'::documentdb_core.bson)) (7 rows) ROLLBACK; bson_query_operator_range.out000066400000000000000000001621371507310017400360130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 492000; SET documentdb.next_collection_id TO 49200; SET documentdb.next_collection_index_id TO 49200; SET search_path TO documentdb_api_catalog; DO $$ BEGIN FOR i IN 1..10000 LOOP PERFORM documentdb_api.insert_one('db', 'range_query', '{ "a": 1 }'); END LOOP; END; $$ LANGUAGE plpgsql; NOTICE: creating collection SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 1, "a": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 2, "a": [1, 2, 3] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 3, "a": [{ "b" : 1}, 2, [4, 5]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging -- if there is no index we don't optimize the a > 1 & a < 5 to a <> {1, 5} (aka the range operator) SET local documentdb_core.enableCollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "$numberInt" : "2" }, [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] ] } (2 rows) EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_49200_492007 collection Recheck Cond: (shard_key_value = '49200'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "5" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '49200'::bigint) (10 rows) END; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_query", "indexes": [ {"key": {"a": 1}, "name": "a_range"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "$numberInt" : "2" }, [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] ] } (2 rows) -- when collation is present $push down of $range query is not done, and we use the unoptimized version (workitem=3423305) SET local documentdb_core.enableCollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "$numberInt" : "2" }, [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] ] } (2 rows) ROLLBACK; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_49200_492007 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on a_range Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (9 rows) SET local documentdb_core.enableCollation TO on; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } ,"collation" : {"locale" : "en", "strength" : 1} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_49200_492007 collection Recheck Cond: (shard_key_value = '49200'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "1" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "$numberInt" : "5" }, "collation" : "en-u-ks-level1" }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '49200'::bigint) (10 rows) END; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$in": [ 5, 6, 7] }, "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_49200_492007 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson)) -> Bitmap Index Scan on a_range Index Cond: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson)) (9 rows) END; -- Shard orders collection on item SELECT documentdb_api.shard_collection('db','range_query', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "_id" : { "$numberInt" : "3" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "$numberInt" : "2" }, [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] ] } (2 rows) END; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_49200_492016 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on a_range Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (9 rows) END; SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, 2]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, 4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": {"test": 5}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{"test": 7}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [true, false]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 2}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 4}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, true]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [true, 1]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, 4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [null]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": { "$minKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$minKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, { "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": { "$maxKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$maxKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, { "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "val" : { "$numberInt" : "2" } } { "val" : [ { "$numberInt" : "2" } ] } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "val" : { "$numberInt" : "2" } } { "val" : [ { "$numberInt" : "2" } ] } (5 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_js_tests", "indexes": [ {"key": {"val": 1}, "name": "a_range"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "val" : { "$numberInt" : "2" } } { "val" : [ { "$numberInt" : "2" } ] } (5 rows) BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "val" : { "$numberInt" : "2" } } { "val" : [ { "$numberInt" : "2" } ] } (5 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "val" : [ { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } { "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "4" } ] } { "val" : { "$numberInt" : "2" } } { "val" : [ { "$numberInt" : "2" } ] } (5 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "val" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49201_492025 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "val" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "3" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on a_range Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "val" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "3" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (11 rows) EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "val" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49201_492025 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "val" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "3" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) -> Bitmap Index Scan on a_range Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "val" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "3" }, "minInclusive" : false, "maxInclusive" : false } }'::documentdb_core.bson) (11 rows) END; -- tests For Minkey() and MaxKey() along with numbers SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": { "$maxKey": 1 }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": { "$minKey": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$minKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3, { "$minKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$maxKey": 1 }, 3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3, { "$maxKey": 1 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": 3}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Runtime tests SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : { "$minKey" : 1 } } { "val" : [ { "$minKey" : 1 } ] } { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : { "$minKey" : 1 } } { "val" : [ { "$minKey" : 1 } ] } { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : { "$numberInt" : "3" } } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : [ { "$maxKey" : 1 } ] } { "val" : { "$maxKey" : 1 } } (10 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lt": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": 100} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lt": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lte": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gt": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) -- Index tests SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_js_tests2", "indexes": [ {"key": {"val": 1}, "name": "a_range"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : { "$minKey" : 1 } } { "val" : [ { "$minKey" : 1 } ] } { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : { "$minKey" : 1 } } { "val" : [ { "$minKey" : 1 } ] } { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : { "$numberInt" : "3" } } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : [ { "$maxKey" : 1 } ] } { "val" : { "$maxKey" : 1 } } (10 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lt": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": 100} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lt": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lte": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gt": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); document --------------------------------------------------------------------- { "val" : [ { "$minKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$minKey" : 1 } ] } { "val" : [ { "$maxKey" : 1 }, { "$numberInt" : "3" } ] } { "val" : [ { "$numberInt" : "3" }, { "$maxKey" : 1 } ] } { "val" : [ { "$numberInt" : "3" } ] } { "val" : { "$numberInt" : "3" } } (6 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "val" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49202_492043 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "val" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "val" : { "$maxKey" : 1 } }'::documentdb_core.bson)) -> Bitmap Index Scan on a_range Index Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "val" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "val" : { "$maxKey" : 1 } }'::documentdb_core.bson)) (11 rows) END; SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899731608" }} }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899831608" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899931608" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657991031608" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); document --------------------------------------------------------------------- { "createdAt" : { "$date" : { "$numberLong" : "2657899731608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657899831608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657899931608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657991031608" } } } (4 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "daterangecoll", "indexes": [{"key": {"createdAt": 1}, "name": "created_at_index"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); document --------------------------------------------------------------------- { "createdAt" : { "$date" : { "$numberLong" : "2657899731608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657899831608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657899931608" } } } { "createdAt" : { "$date" : { "$numberLong" : "2657991031608" } } } (4 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "createdAt" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49203_492063 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "createdAt" : { "min" : { "$date" : { "$numberLong" : "2657899731608" } }, "max" : { "$date" : { "$numberLong" : "2657991031608" } }, "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) -> Bitmap Index Scan on created_at_index Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "createdAt" : { "min" : { "$date" : { "$numberLong" : "2657899731608" } }, "max" : { "$date" : { "$numberLong" : "2657991031608" } }, "minInclusive" : true, "maxInclusive" : true } }'::documentdb_core.bson) (11 rows) END; -- do not convert $gte/$lte null BEGIN; SET LOCAL enable_seqscan TO OFF; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": null, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "createdAt" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49203_492063 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "createdAt" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "createdAt" : { "$date" : { "$numberLong" : "2657991031608" } } }'::documentdb_core.bson)) -> Bitmap Index Scan on created_at_index Index Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "createdAt" : null }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "createdAt" : { "$date" : { "$numberLong" : "2657991031608" } } }'::documentdb_core.bson)) (11 rows) EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": null } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "createdAt" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST -> Bitmap Heap Scan on documents_49203_492063 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "createdAt" : { "$date" : { "$numberLong" : "2657899731608" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "createdAt" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on created_at_index Index Cond: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "createdAt" : { "$date" : { "$numberLong" : "2657899731608" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "createdAt" : null }'::documentdb_core.bson)) (11 rows) END; -- A local repro that had run into segfault SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"idLinea": 1}, "name": "idLinea_1"} ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"f_insercion": 1}, "name": "f_insercion_1"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"idLinea": 1, "f_insercion": 1}, "name": "idLinea_1_f_insercion_1", "unique": true} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) DO $$ BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('db', 'range_and_aggregation', FORMAT('{ "f_insercion": { "$date" : { "$numberLong" : "%s" } }, "idLinea": 1, "n_18_velocidad": %s }', i, i)::documentdb_core.bson); END LOOP; END; $$ LANGUAGE plpgsql; BEGIN; ALTER FUNCTION documentdb_api_catalog.bson_dollar_project COST 20000; ANALYZE; -- full query 500K SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "range_and_aggregation", "pipeline": [ { "$match" : { "$and" : [ { "f_insercion" : { "$gte" : { "$date" : { "$numberLong" : "0" } }}, "f_insercion" : { "$lt" : { "$date" : { "$numberLong" : "500000" } }} } ] }}, {"$project" : { "f_insercion" : 1, "n_18_velocidad": 1, "_id": 0, "date" : { "$dateToParts" : { "date" : "$f_insercion" } }} }, { "$group" : { "_id" : { "year" : "$date.year", "month" : "$date.month", "day" : "$date.day", "hour" : "$date.hour" }, "speed_avg" : { "$avg" : "$n_18_velocidad" } , "speed_max" : { "$max" : "$n_18_velocidad" } , "speed_min" : { "$min" : "$n_18_velocidad" }} }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "year" : { "$numberInt" : "1970" }, "month" : { "$numberInt" : "1" }, "day" : { "$numberInt" : "1" }, "hour" : { "$numberInt" : "0" } }, "speed_avg" : { "$numberDouble" : "500.5" }, "speed_max" : { "$numberInt" : "1000" }, "speed_min" : { "$numberInt" : "1" } } (1 row) -- full query 500K ( "idLinea": 1 filter ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "range_and_aggregation", "pipeline": [ { "$match" : { "idLinea": 1, "$and" : [ { "f_insercion" : { "$gte" : { "$date" : { "$numberLong" : "0" } }}, "f_insercion" : { "$lt" : { "$date" : { "$numberLong" : "500000" } }} } ] }}, {"$project" : { "f_insercion" : 1, "n_18_velocidad": 1, "_id": 0, "date" : { "$dateToParts" : { "date" : "$f_insercion" } }} }, { "$group" : { "_id" : { "year" : "$date.year", "month" : "$date.month", "day" : "$date.day", "hour" : "$date.hour" }, "speed_avg" : { "$avg" : "$n_18_velocidad" } , "speed_max" : { "$max" : "$n_18_velocidad" } , "speed_min" : { "$min" : "$n_18_velocidad" }} }], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "year" : { "$numberInt" : "1970" }, "month" : { "$numberInt" : "1" }, "day" : { "$numberInt" : "1" }, "hour" : { "$numberInt" : "0" } }, "speed_avg" : { "$numberDouble" : "500.5" }, "speed_max" : { "$numberInt" : "1000" }, "speed_min" : { "$numberInt" : "1" } } (1 row) ROLLBACK; bson_query_operator_tests_explain_index.out000066400000000000000000003567721507310017400410020ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('nullfield', 'nullfield_wildcard', '{"$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2691'), document bson_rum_single_path_ops (path=c, tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_single_path_ops (path='a.b', tl='2691'), document bson_rum_single_path_ops (path=_id, tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_single_path_ops (path=b, tl='2691'), document bson_rum_single_path_ops (path=a, tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=23 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (12 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=4 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) Filter: ((object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) (16 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_ab (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) (15 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (14 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (19 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson)) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson)) (23 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (11 rows) COMMIT; bson_query_operator_tests_explain_index_comp_desc.out000066400000000000000000004325511507310017400430040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": -1, "c": -1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": -1, "a": -1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "a" : -1 }, { "c" : -1 } ]', tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "a.b" : -1 }, { "_id" : -1 } ]', tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "b" : -1 }, { "a" : -1 } ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[1, 1], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[MinKey, MaxKey], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC(1, Infinity], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[1, Infinity], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[-Infinity, 1), "_id": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[-Infinity, 1], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC[-Infinity, 1]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC[MinKey, MaxKey]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC(MinKey, null]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC({ "b" : 1 }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC({ "b" : [ true, false ] }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : 1 }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ true, false ] }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : 1 }), "c": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : [ true, false ] }), "c": DESC(MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : 1 }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : [ true, false ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : 1 }, { "b" : 1 }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": DESC(MinKey, MaxKey)], ["a": DESC[{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC["M", "M"], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC[4, 4], "a": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[4, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[5, 5], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[5, 5], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC(3, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC(3, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using queryoperator_b_a on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (24 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC[MinKey, MaxKey], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[1, 1], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[1, 1], "c": DESC(MinKey, MaxKey)], ["a": DESC[2, 2], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)], ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[4, 4], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[NaN, NaN]], ["a": DESC[1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[Infinity, Infinity]], ["a": DESC[1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[1.01, 1.01]], ["a": DESC[10, 10]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_explain_index_comp_unique.out000066400000000000000000004364511507310017400433770ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "c", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) "documents_rum_index_1205" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a.b", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a.b" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) "documents_rum_index_1206" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "b", "a", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "b" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": (1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : 1 }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, { "b" : 1 }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": ["M", "M"], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [4, 4], "a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [4, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (26 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [MinKey, MaxKey], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [2, 2], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [4, 4], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [NaN, NaN], "_id": (MinKey, MaxKey)], ["a": [1000, 1000], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [Infinity, Infinity], "_id": (MinKey, MaxKey)], ["a": [1000, 1000], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [1.01, 1.01], "_id": (MinKey, MaxKey)], ["a": [10, 10], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_explain_index_composite.out000066400000000000000000004315551507310017400430550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "c" ]', tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a.b", "_id" ]', tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "b", "a" ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": (1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [-Infinity, 1]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [MinKey, MaxKey]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": (MinKey, null]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : 1 }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }), "c": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }), "c": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, { "b" : 1 }], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey)], ["a": [{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": ["M", "M"], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [4, 4], "a": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [4, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using queryoperator_b_a on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (24 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [MinKey, MaxKey], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey)], ["a": [2, 2], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 28kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)], ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [4, 4], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [NaN, NaN]], ["a": [1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [Infinity, Infinity]], ["a": [1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [1.01, 1.01]], ["a": [10, 10]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_explain_runtime.out000066400000000000000000003313701507310017400413410ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1300000; SET documentdb.next_collection_id TO 1300; SET documentdb.next_collection_index_id TO 1300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); psql:sql/bson_query_operator_tests_insert.sql:30: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 23 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=23 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 23 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=6 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 21 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Rows Removed by Filter: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=15 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 12 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 26 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=3 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 24 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=16 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 11 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 26 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=3 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 24 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=18 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 9 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=9 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 18 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=6 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 21 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=18 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 9 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=9 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 18 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Rows Removed by Filter: 37 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Rows Removed by Filter: 37 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) Rows Removed by Filter: 39 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) bson_query_operator_tests_index.out000066400000000000000000006152141507310017400372470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_operator_tests_index_backcompat.out000066400000000000000000006153501507310017400414340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; \set prevEcho :ECHO \set ECHO none BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_operator_tests_index_comp_desc.out000066400000000000000000006152141507310017400412630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 940000; SET documentdb.next_collection_id TO 9400; SET documentdb.next_collection_index_id TO 9400; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_operator_tests_index_comp_unique.out000066400000000000000000006152141507310017400416530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 915000; SET documentdb.next_collection_id TO 9150; SET documentdb.next_collection_index_id TO 9150; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_operator_tests_index_composite.out000066400000000000000000006152141507310017400413310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_operator_tests_parameterized.out000066400000000000000000000717401507310017400407740ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 66400; SET documentdb.next_collection_id TO 6640; SET documentdb.next_collection_index_id TO 6640; /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 1, "a" : { "b" : 0 }}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SET client_min_messages TO WARNING; DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'queryOperatorParameterized'; EXECUTE format('SELECT undistribute_table(''documentdb_data.documents_%s'')', v_collection_id); END $$; SET client_min_messages TO DEFAULT; PREPARE q1 (text, text, bson) AS SELECT object_id, document FROM documentdb_api.collection($1, $2) WHERE document @@ $3; -- valid queries EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$lte" : [true, false] }}'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.b": 2 } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.b": 2 } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.c": { "$exists": 1 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.c": { "$exists": 0 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": { "$gte": 1 } }, { "a.c": { "$exists": 0 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) -- invalid queries. EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a": { "$invalid": 1 } }'); ERROR: Unrecognized operator specified: $invalid EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a": { "$invalid": 2 } } ] }'); ERROR: Unrecognized operator specified: $invalid EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ ] }'); ERROR: $or/$and/$nor arrays must have at least one entry -- repeat the queries with remote execution on. BEGIN; set local citus.enable_local_execution to off; EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$lte" : [true, false] }}'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.b": 2 } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.b": 2 } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.c": { "$exists": 1 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.c": { "$exists": 0 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": { "$gte": 1 } }, { "a.c": { "$exists": 0 } } ] }'); object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) -- invalid queries. EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a": { "$invalid": 1 } }'); ERROR: Unrecognized operator specified: $invalid EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a": { "$invalid": 2 } } ] }'); ERROR: current transaction is aborted, commands ignored until end of transaction block EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ ] }'); ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- repeat the queries with remote execution on and hex output. BEGIN; set local citus.enable_local_execution to off; set local documentdb_core.bsonUseEJson to off; EXECUTE q1( 'db', 'queryOperatorParameterized', bson_json_to_bson('{ "a.b": { "$eq" : 1 }}')); object_id | document --------------------------------------------------------------------- BSONHEX0b00000010000200000000 | BSONHEX1d000000105f696400020000000361000c000000106200010000000000 BSONHEX0b00000010000a00000000 | BSONHEX33000000105f6964000a000000036100220000000462001a000000103000000000001031000100000010320002000000000000 BSONHEX0b00000010000b00000000 | BSONHEX47000000105f6964000b000000046100360000000330000c00000010620000000000000331000c0000001062000100000000033200100000000162000000000000000840000000 BSONHEX0b00000010000c00000000 | BSONHEX85000000105f6964000c00000004610074000000033000220000000462001a000000103000ffffffff10310001000000103200020000000000033100220000000462001a0000001030000000000010310001000000103200020000000000033200220000000462001a00000010300000000000103100010000001032000700000000000000 (4 rows) EXPLAIN (COSTS OFF) EXECUTE q1( 'db', 'queryOperatorParameterized', bson_json_to_bson('{ "a.b": { "$eq" : 1 }}')); QUERY PLAN --------------------------------------------------------------------- Seq Scan on documents_6640 Filter: ((document #= 'BSONHEX0e00000010612e62000100000000'::bsonquery) AND (shard_key_value = '6640'::bigint)) (2 rows) ROLLBACK; -- run an explain analyze EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); QUERY PLAN --------------------------------------------------------------------- Seq Scan on documents_6640 (actual rows=4 loops=1) Filter: ((document #= '{ "a.b" : { "$numberInt" : "1" } }'::bsonquery) AND (shard_key_value = '6640'::bigint)) Rows Removed by Filter: 10 (3 rows) PREPARE q2(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE document OPERATOR(documentdb_api_catalog.@@) $3 ORDER BY documentdb_api_catalog.bson_orderby(document, $4) DESC; EXPLAIN (COSTS OFF) EXECUTE q2( 'db', 'queryOperatorParameterized', '{ "a.b" : { "$gt": 0 } }', '{ "a.b": -1 }'); QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: (bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::bson)) DESC -> Seq Scan on documents_6640 Filter: ((document #> '{ "a.b" : { "$numberInt" : "0" } }'::bsonquery) AND (shard_key_value = '6640'::bigint)) (4 rows) BEGIN; set local citus.enable_local_execution to off; EXPLAIN (COSTS OFF) EXECUTE q2( 'db', 'queryOperatorParameterized', '{ "a.b" : { "$gt": 0 } }', '{ "a.b": -1 }'); QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: (bson_orderby(document, '{ "a.b" : { "$numberInt" : "-1" } }'::bson)) DESC -> Seq Scan on documents_6640 Filter: ((document #> '{ "a.b" : { "$numberInt" : "0" } }'::bsonquery) AND (shard_key_value = '6640'::bigint)) (4 rows) ROLLBACK; bson_query_operator_tests_pg17_explain_index.out000066400000000000000000003577361507310017400416410ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('nullfield', 'nullfield_wildcard', '{"$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2691'), document bson_rum_single_path_ops (path=c, tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_single_path_ops (path='a.b', tl='2691'), document bson_rum_single_path_ops (path=_id, tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_single_path_ops (path=b, tl='2691'), document bson_rum_single_path_ops (path=a, tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=23 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (12 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=3 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=9 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=4 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) Filter: ((object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) (16 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "_id" : { "min" : { "$numberInt" : "1" }, "max" : { "$numberInt" : "5" }, "minInclusive" : false, "maxInclusive" : true } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_ab (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) (15 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (14 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (19 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson)) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson)) (23 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_b_a (actual rows=25 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (11 rows) COMMIT; bson_query_operator_tests_pg17_explain_index_comp_desc.out000066400000000000000000004350461507310017400436440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedNOTICE: identifier "pg_regress/bson_query_operator_tests_pg17_explain_index_comp_desc" will be truncated to "pg_regress/bson_query_operator_tests_pg17_explain_index_comp_de" SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_comp_desc.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); psql:sql/bson_query_operator_tests_explain_index_comp_desc.sql:9: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); psql:sql/bson_query_operator_tests_explain_index_comp_desc.sql:12: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); psql:sql/bson_query_operator_tests_explain_index_comp_desc.sql:15: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); psql:sql/bson_query_operator_tests_explain_index_comp_desc.sql:18: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": -1, "c": -1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": -1, "a": -1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "a" : -1 }, { "c" : -1 } ]', tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "a.b" : -1 }, { "_id" : -1 } ]', tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ { "b" : -1 }, { "a" : -1 } ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[1, 1], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[MinKey, MaxKey], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC(1, Infinity], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[1, Infinity], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[-Infinity, 1), "_id": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC[-Infinity, 1], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC[-Infinity, 1]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC[MinKey, MaxKey]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": DESC(MinKey, null]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC({ "b" : 1 }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC({ "b" : [ true, false ] }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : 1 }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ true, false ] }, [ ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : 1 }), "c": DESC(MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : [ true, false ] }), "c": DESC(MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : 1 }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ }, { "b" : [ true, false ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : 1 }, { "b" : 1 }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": DESC(MinKey, MaxKey)], ["a": DESC[{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": DESC["M", "M"], "_id": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC[4, 4], "a": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[4, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[5, 5], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[5, 5], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC(3, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC(3, Infinity], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using queryoperator_b_a on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (24 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC[MinKey, MaxKey], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": DESC(MinKey, null], "a": DESC[3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[1, 1], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[1, 1], "c": DESC(MinKey, MaxKey)], ["a": DESC[2, 2], "c": DESC(MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)], ["a": DESC[MinKey, MaxKey], "c": DESC(MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": DESC[3, 3], "c": DESC(MinKey, MaxKey)], ["a": DESC[4, 4], "c": DESC(MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[NaN, NaN]], ["a": DESC[1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[Infinity, Infinity]], ["a": DESC[1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": DESC[1.01, 1.01]], ["a": DESC[10, 10]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_pg17_explain_index_comp_unique.out000066400000000000000000004407621507310017400442350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedNOTICE: identifier "pg_regress/bson_query_operator_tests_pg17_explain_index_comp_unique" will be truncated to "pg_regress/bson_query_operator_tests_pg17_explain_index_comp_un" SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_comp_unique.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); psql:sql/bson_query_operator_tests_explain_index_comp_unique.sql:9: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); psql:sql/bson_query_operator_tests_explain_index_comp_unique.sql:12: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); psql:sql/bson_query_operator_tests_explain_index_comp_unique.sql:15: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); psql:sql/bson_query_operator_tests_explain_index_comp_unique.sql:18: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "c", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) "documents_rum_index_1205" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a.b", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a.b" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) "documents_rum_index_1206" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "b", "a", "_id" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "b" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "_id" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": (1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : 1 }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, { "b" : 1 }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": ["M", "M"], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [4, 4], "a": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [4, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (26 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [MinKey, MaxKey], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [2, 2], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)], ["a": [4, 4], "c": (MinKey, MaxKey), "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [NaN, NaN], "_id": (MinKey, MaxKey)], ["a": [1000, 1000], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [Infinity, Infinity], "_id": (MinKey, MaxKey)], ["a": [1000, 1000], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [1.01, 1.01], "_id": (MinKey, MaxKey)], ["a": [10, 10], "_id": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_pg17_explain_index_composite.out000066400000000000000000004340521507310017400437060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedNOTICE: identifier "pg_regress/bson_query_operator_tests_pg17_explain_index_composite" will be truncated to "pg_regress/bson_query_operator_tests_pg17_explain_index_composi" SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_composite.sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); psql:sql/bson_query_operator_tests_explain_index_composite.sql:9: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); psql:sql/bson_query_operator_tests_explain_index_composite.sql:12: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); psql:sql/bson_query_operator_tests_explain_index_composite.sql:15: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); psql:sql/bson_query_operator_tests_explain_index_composite.sql:18: NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show the indexes \d documentdb_data.documents_1200 Table "documentdb_data.documents_1200" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_1200" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_1204" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "c" ]', tl='2691')) "documents_rum_index_1205" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a.b", "_id" ]', tl='2691')) "documents_rum_index_1206" documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "b", "a" ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '1200'::bigint) BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=23 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [MinKey, MaxKey], "_id": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=23 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": (1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [1, Infinity], "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 9)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1), "_id": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 6)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": [-Infinity, 1], "_id": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 10)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [-Infinity, 1]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=4 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": [MinKey, MaxKey]] innerScanLoops: 4 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 4)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=4 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=4 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: a_index isMultiKey: false indexBounds: ["a": (MinKey, null]] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1203_1200055 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on a_index (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) (19 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=15 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : 1 }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 15 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 23)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=15 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=15 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": ({ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=16 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 16 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 25)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=16 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=16 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=1 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, [ ]), "c": (MinKey, MaxKey)] innerScanLoops: 1 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=1 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=1 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=3 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ 2, 3, 4 ] }, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 8)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=3 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 3 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=5 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }), "c": (MinKey, MaxKey)] innerScanLoops: 5 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 5)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=5 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }), "c": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]), "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=6 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : 1 }], "c": (MinKey, MaxKey)] innerScanLoops: 6 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 7)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=6 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=6 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=18 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey)] innerScanLoops: 18 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 29)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=18 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=18 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=9 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=9 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 17 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : 1 }, { "b" : 1 }], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [{ "b" : [ true, false ] }, { "b" : [ true, false ] }], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [[ { "b" : [ 2, 3, 4 ] } ], [ { "b" : [ 2, 3, 4 ] } ]], "c": (MinKey, MaxKey)], ["a": [{ "b" : [ 2, 3, 4 ] }, { "b" : [ 2, 3, 4 ] }], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) (18 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (20 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=27 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 41)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1200_1200005 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1200'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_ab isMultiKey: true indexBounds: ["a.b": ["M", "M"], "_id": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_ab (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@<>) '{ "a.b" : { "elemMatchIndexOp" : [ { "op" : { "$numberInt" : "1" }, "value" : "M", "isTopLevel" : false } ] } }'::documentdb_core.bson) (22 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [4, 4], "a": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson) (30 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [4, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (31 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [5, 5], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) (21 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) Output: object_id, document indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": (3, Infinity], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) (27 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Index Scan using queryoperator_b_a on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) (24 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": [MinKey, MaxKey], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (35 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1200_1200005 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1200'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) Output: object_id, document indexName: queryoperator_b_a isMultiKey: true indexBounds: ["b": (MinKey, null], "a": [3, 3]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, null]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documentdb_data.documents_1200_1200005 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) OR ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on queryoperator_b_a (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: ((collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson)) (43 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [1, 1], "c": (MinKey, MaxKey)], ["a": [2, 2], "c": (MinKey, MaxKey)] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 2), (isInequality: true, estimatedEntryCount: 1)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (22 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 26 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Index Recheck: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=26 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1200'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1200'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=25 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)], ["a": [MinKey, MaxKey], "c": (MinKey, MaxKey)] innerScanLoops: 27 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 39), (isInequality: true, estimatedEntryCount: 40)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=25 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Index Recheck: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperator_a_c (actual rows=27 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (23 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperator_a_c isMultiKey: true indexBounds: ["a": [3, 3], "c": (MinKey, MaxKey)], ["a": [4, 4], "c": (MinKey, MaxKey)] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 0), (isInequality: true, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1200_1200005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperator_a_c (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [NaN, NaN]], ["a": [1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=2 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [Infinity, Infinity]], ["a": [1000, 1000]] innerScanLoops: 2 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 2), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=2 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on queryoperatorin_a (actual rows=2 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) (19 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=0 loops=1) indexName: queryoperatorin_a isMultiKey: true indexBounds: ["a": [1.01, 1.01]], ["a": [10, 10]] innerScanLoops: 0 loops scanType: regular scanKeyDetails: key 1: [(isInequality: false, estimatedEntryCount: 0), (isInequality: false, estimatedEntryCount: 0)] -> Bitmap Heap Scan on documents_1201_1200017 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on queryoperatorin_a (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) (18 rows) COMMIT; bson_query_operator_tests_pg17_explain_runtime.out000066400000000000000000003323341507310017400422000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1300000; SET documentdb.next_collection_id TO 1300; SET documentdb.next_collection_index_id TO 1300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'queryoperator'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'nullfield'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'nullfield'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); drop_collection --------------------------------------------------------------------- f (1 row) SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \i sql/bson_query_operator_tests_explain_core.sql \i sql/bson_query_operator_tests_insert.sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); psql:sql/bson_query_operator_tests_insert.sql:30: NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 328 bytes Tasks Shown: All -> Task Tuple data received from node: 328 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 23 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=23 loops=1) Task Count: 1 Tuple data received from nodes: 1526 bytes Tasks Shown: All -> Task Tuple data received from node: 1526 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=23 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 332 bytes Tasks Shown: All -> Task Tuple data received from node: 332 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 23 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 372 bytes Tasks Shown: All -> Task Tuple data received from node: 372 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 392 bytes Tasks Shown: All -> Task Tuple data received from node: 392 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 432 bytes Tasks Shown: All -> Task Tuple data received from node: 432 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=6 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 21 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 32 bytes Tasks Shown: All -> Task Tuple data received from node: 32 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 157 bytes Tasks Shown: All -> Task Tuple data received from node: 157 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=4 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$minKey" : 1 } }'::documentdb_core.bson) Rows Removed by Filter: 1 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 36 bytes Tasks Shown: All -> Task Tuple data received from node: 36 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1302_1300036 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1302'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@?) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bson) Rows Removed by Filter: 4 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=5 loops=1) Index Cond: (shard_key_value = '1302'::bigint) (14 rows) /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=15 loops=1) Task Count: 1 Tuple data received from nodes: 1349 bytes Tasks Shown: All -> Task Tuple data received from node: 1349 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=15 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 12 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 26 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=3 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 24 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=16 loops=1) Task Count: 1 Tuple data received from nodes: 1389 bytes Tasks Shown: All -> Task Tuple data received from node: 1389 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=16 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 11 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 37 bytes Tasks Shown: All -> Task Tuple data received from node: 37 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=1 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 26 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=3 loops=1) Task Count: 1 Tuple data received from nodes: 417 bytes Tasks Shown: All -> Task Tuple data received from node: 417 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=3 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 24 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 300 bytes Tasks Shown: All -> Task Tuple data received from node: 300 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=18 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 9 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=9 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 18 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=6 loops=1) Task Count: 1 Tuple data received from nodes: 340 bytes Tasks Shown: All -> Task Tuple data received from node: 340 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=6 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 21 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=18 loops=1) Task Count: 1 Tuple data received from nodes: 1506 bytes Tasks Shown: All -> Task Tuple data received from node: 1506 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=18 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 9 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=9 loops=1) Task Count: 1 Tuple data received from nodes: 762 bytes Tasks Shown: All -> Task Tuple data received from node: 762 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=9 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@<=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 18 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 122 bytes Tasks Shown: All -> Task Tuple data received from node: 122 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1732 bytes Tasks Shown: All -> Task Tuple data received from node: 1732 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "b" : [ true, false ] } }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : [ { "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] }'::documentdb_core.bson) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (13 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : null }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<) '{ "" : { "$numberInt" : "40" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "20" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "_id" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "_id" : { "$numberInt" : "40" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=4 loops=1) Task Count: 1 Tuple data received from nodes: 172 bytes Tasks Shown: All -> Task Tuple data received from node: 172 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=4 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=0 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 80 bytes Tasks Shown: All -> Task Tuple data received from node: 80 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=2 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) ANY ('{"{ \"\" : { \"$numberInt\" : \"1\" } }","{ \"\" : { \"$numberInt\" : \"2\" } }"}'::documentdb_core.bson[]))) (9 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=5 loops=1) Task Count: 1 Tuple data received from nodes: 212 bytes Tasks Shown: All -> Task Tuple data received from node: 212 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=5 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=5 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (((document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) Rows Removed by Filter: 22 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=1 loops=1) Task Count: 1 Tuple data received from nodes: 40 bytes Tasks Shown: All -> Task Tuple data received from node: 40 bytes Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1300_1300002 collection (actual rows=1 loops=1) Index Cond: ((shard_key_value = '1300'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.<=) '{ "" : { "$numberInt" : "5" } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@>=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@<=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bson)) (10 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 198 bytes Tasks Shown: All -> Task Tuple data received from node: 198 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "b" : "M", "c" : { "$gt" : { "$numberInt" : "50" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#?) '{ "a" : { "c" : { "$numberInt" : "100" }, "d" : "Y" } }'::documentdb_core.bson)) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@>=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 91 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 91 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=2 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson)) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$minKey" : 1 } }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Output: remote_scan.object_id, remote_scan.document Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Query: SELECT object_id, document FROM documentdb_data.documents_1300_1300002 collection WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bsonquery) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "b" : null }'::documentdb_core.bsonquery) OR (document OPERATOR(documentdb_api_catalog.#=) '{ "c" : null }'::documentdb_core.bsonquery) OR documentdb_api_catalog.bson_dollar_exists(document, '{ "c" : false }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '1300'::bigint)) ORDER BY object_id Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Output: object_id, document Sort Key: collection.object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documentdb_data.documents_1300_1300002 collection (actual rows=0 loops=1) Output: object_id, document Recheck Cond: (collection.shard_key_value = '1300'::bigint) Filter: ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND ((collection.document OPERATOR(documentdb_api_catalog.@=) '{ "b" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@=) '{ "c" : null }'::documentdb_core.bson) OR (collection.document OPERATOR(documentdb_api_catalog.@?) '{ "c" : false }'::documentdb_core.bson))) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (collection.shard_key_value = '1300'::bigint) (21 rows) -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Result (actual rows=0 loops=1) One-Time Filter: false (12 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=2 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Filter: 25 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=27 loops=1) Task Count: 1 Tuple data received from nodes: 1854 bytes Tasks Shown: All -> Task Tuple data received from node: 1854 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=27 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=27 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (15 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=25 loops=1) Task Count: 1 Tuple data received from nodes: 1768 bytes Tasks Shown: All -> Task Tuple data received from node: 1768 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=25 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 27kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=25 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@!*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }'::documentdb_core.bson) Rows Removed by Filter: 2 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Sort (actual rows=0 loops=1) Sort Key: object_id Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_1300_1300002 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1300'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }'::documentdb_core.bson) Rows Removed by Filter: 27 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=27 loops=1) Index Cond: (shard_key_value = '1300'::bigint) (17 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "NaN" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Rows Removed by Filter: 37 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=2 loops=1) Task Count: 1 Tuple data received from nodes: 86 bytes Tasks Shown: All -> Task Tuple data received from node: 86 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=2 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "Infinity" }, { "$numberInt" : "1000" } ] }'::documentdb_core.bson) Rows Removed by Filter: 37 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=0 loops=1) Task Count: 1 Tuple data received from nodes: 0 bytes Tasks Shown: All -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1303_1300052 collection (actual rows=0 loops=1) Recheck Cond: (shard_key_value = '1303'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberDouble" : "1.0100000000000000089" }, { "$numberInt" : "10" } ] }'::documentdb_core.bson) Rows Removed by Filter: 39 Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=39 loops=1) Index Cond: (shard_key_value = '1303'::bigint) (14 rows) bson_query_operator_tests_runtime.out000066400000000000000000006150661507310017400376300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; \i sql/bson_query_operator_tests_core.sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (23 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (27 rows) /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (24 rows) /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (26 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (25 rows) /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (7 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (8 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "1" } } { "" : { "$numberInt" : "7" } } | { "_id" : { "$numberInt" : "7" }, "a" : true } { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "a" : { "c" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "24" } } | { "_id" : { "$numberInt" : "24" }, "a" : { "$numberDouble" : "Infinity" } } { "" : { "$numberInt" : "25" } } | { "_id" : { "$numberInt" : "25" }, "a" : { "$numberDouble" : "-Infinity" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (9 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } { "" : { "$numberInt" : "14" } } | { "_id" : { "$numberInt" : "14" }, "a" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } { "" : "ab_null" } | { "_id" : "ab_null", "a" : { "b" : null } } { "" : "ab_undefined" } | { "_id" : "ab_undefined", "a" : { "b" : { "$undefined" : true } } } (18 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (6 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "19" } } | { "_id" : { "$numberInt" : "19" }, "a" : [ { "b" : "1", "c" : { "$numberInt" : "100" }, "d" : "Y" }, { "b" : "2", "c" : { "$numberInt" : "50" }, "d" : "X" }, { "b" : "3", "c" : { "$numberInt" : "100" }, "d" : "Z" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (3 rows) /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : "b" } | { "_id" : "b", "b" : { "$numberInt" : "1" } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "0" } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : "a" } | { "_id" : "a", "a" : { "$undefined" : true } } { "" : "a_null" } | { "_id" : "a_null", "a" : null } (4 rows) SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (4 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "1" } } } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "a" : { "b" : "someString" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "b" : true } } (5 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "10" } } | { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (3 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "17" } } | { "_id" : { "$numberInt" : "17" }, "a" : [ ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "" : { "$numberInt" : "13" } } | { "_id" : { "$numberInt" : "13" }, "a" : [ { "b" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "b" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (2 rows) -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (1 row) -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "16" } } | { "_id" : { "$numberInt" : "16" }, "a" : [ { "b" : { } }, { "b" : { "$numberInt" : "0" } } ] } (3 rows) -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "11" } } | { "_id" : { "$numberInt" : "11" }, "a" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberDouble" : "3.0" } } ] } { "" : { "$numberInt" : "12" } } | { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "18" } } | { "_id" : { "$numberInt" : "18" }, "a" : [ { "b" : "S", "c" : { "$numberInt" : "10" }, "d" : "X" }, { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "X" }, { "b" : "L", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } { "" : { "$numberInt" : "20" } } | { "_id" : { "$numberInt" : "20" }, "a" : [ { "b" : "M", "c" : { "$numberInt" : "100" }, "d" : "Y" } ] } (2 rows) -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } { "" : { "$numberInt" : "22" } } | { "_id" : { "$numberInt" : "22" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "11" } } ], "d" : [ { "e" : { "$numberInt" : "20" } }, { "e" : { "$numberInt" : "25" } } ] } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "21" } } | { "_id" : { "$numberInt" : "21" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } }, { "c" : { "$numberInt" : "15" } }, { "c" : { "$numberInt" : "18" } } ], "d" : [ { "e" : { "$numberInt" : "10" } }, { "e" : { "$numberInt" : "15" } }, { "e" : { "$numberInt" : "18" } } ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" }, "b" : null } { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "20" }, "b" : null } { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "30" } } (4 rows) -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (10 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (12 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } (2 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } (4 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (1 row) -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (29 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (37 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } { "_id" : { "$numberInt" : "41" }, "a" : [ "abc", "xyz1" ] } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "26" }, "a" : "Lets Optimize dollar In" } { "_id" : { "$numberInt" : "27" }, "a" : "Lets Optimize dollar In again" } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (38 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberLong" : "1" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberDecimal" : "1.0" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberDouble" : "1.0" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "24" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } { "_id" : { "$numberInt" : "25" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "29" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "NaN" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "31" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "Infinity" }, { "$numberInt" : "4" } ] } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (36 rows) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "a" : { "$numberDecimal" : "1.000000000000000000000000000000001" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberDouble" : "1.0000000000000011102" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "01" } } } { "_id" : { "$numberInt" : "10" }, "a" : { "$binary" : { "base64" : "ww==", "subType" : "02" } } } { "_id" : { "$numberInt" : "11" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "01" } } } { "_id" : { "$numberInt" : "12" }, "a" : { "$binary" : { "base64" : "zg==", "subType" : "02" } } } { "_id" : { "$numberInt" : "13" }, "a" : { "$timestamp" : { "t" : 1670981326, "i" : 1 } } } { "_id" : { "$numberInt" : "14" }, "a" : { "$date" : { "$numberLong" : "1548833410136" } } } { "_id" : { "$numberInt" : "15" }, "a" : { "$oid" : "639926cee6bda3127f153bf1" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$maxKey" : 1 } } { "_id" : { "$numberInt" : "19" }, "a" : { "$minKey" : 1 } } { "_id" : { "$numberInt" : "20" }, "a" : { "$undefined" : true } } { "_id" : { "$numberInt" : "21" }, "a" : null } { "_id" : { "$numberInt" : "22" }, "a" : { "b" : { "$numberInt" : "1" } } } { "_id" : { "$numberInt" : "23" }, "a" : { "b" : { "$numberInt" : "2" } } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberDouble" : "NaN" } } { "_id" : { "$numberInt" : "30" }, "a" : { "$numberDouble" : "Infinity" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberDouble" : "0.0" } } { "_id" : { "$numberInt" : "33" }, "a" : { "$numberDecimal" : "0.0" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberLong" : "0" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "36" }, "a" : { "$numberLong" : "9223372036854775807" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberLong" : "9223372036854775806" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "2147483647" } } { "_id" : { "$numberInt" : "39" }, "a" : { "$numberInt" : "2147483646" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "2147483645" } } (26 rows) -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (1 row) -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "_id" : { "$numberInt" : "12" }, "a" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } (2 rows) -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "23" } } | { "_id" : { "$numberInt" : "23" }, "a" : { "$numberDouble" : "NaN" } } { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (2 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "26" } } | { "_id" : { "$numberInt" : "26" }, "a" : [ { "$numberDouble" : "NaN" }, { "$numberDouble" : "Infinity" } ] } (1 row) ROLLBACK; bson_query_projection_operator_expressions_map_tests.out000066400000000000000000001515251507310017400436130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 245000; SET documentdb.next_collection_id TO 2450; SET documentdb.next_collection_index_id TO 2450; SELECT documentdb_api.insert_one('db','mapprojectexprs','{"array": [{"_id":"1", "a" : { "b" : 1 } },{"_id":"2", "a" : { "b" : [ 0, 1, 2]} },{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] },{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] },{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } },{"_id":"6", "a" : [ { "c" : 0 }, 2 ] },{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] },{"_id":"8", "a" : { "c" : 1 } },{"_id":"9", "c" : { "d" : 1 } }]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- field path expressions SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "b" : { "$numberInt" : "1" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ], [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], { "c" : { "$numberInt" : "1" } } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$numberInt" : "1" }, [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ], [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], [ ], [ { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ [ ], [ ], [ { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], { "$numberInt" : "1" } ] } (1 row) -- field path expressions on bson_expression_get() with nullOnEmpty = true SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "b" : { "$numberInt" : "1" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ], [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], { "c" : { "$numberInt" : "1" } }, null ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$numberInt" : "1" }, [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ], [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], [ ], [ { "$numberInt" : "2" } ], null, null ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ null, null, [ ], [ ], null, [ { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], { "$numberInt" : "1" }, null ] } (1 row) -- field path expressions on bson_expression_get() with nullOnEmpty = false SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "b" : { "$numberInt" : "1" } }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ], [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], { "c" : { "$numberInt" : "1" } } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$numberInt" : "1" }, [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ], [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], [ ], [ { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ [ ], [ ], [ { "$numberInt" : "0" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], { "$numberInt" : "1" } ] } (1 row) -- const value expressions SELECT bson_expression_map(document, 'array', '{ "field" : "someString" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ "someString", "someString", "someString", "someString", "someString", "someString", "someString", "someString", "someString" ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : [ "1.0" ] }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ], [ "1.0" ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$minKey": 1 } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 }, { "$minKey" : 1 } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "nestedField": "fieldValue" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" }, { "nestedField" : "fieldValue" } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "nestedField": "fieldValue", "nestedField2": "fieldValue2" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" }, { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } ] } (1 row) -- literal expressions SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "1.0" } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": [1, 2, 3] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ "some literal", "some literal", "some literal", "some literal", "some literal", "some literal", "some literal", "some literal", "some literal" ] } (1 row) -- isArray expressions: top level expression SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$literal": [ 1, 2, 3 ] } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ true, true, true, true, true, true, true, true, true ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$literal": "someLiteral" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "nestedObj": "someValue" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) -- project $a.b along with isArray to validate the values easily. SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": "$a.b" } }'), bson_expression_map(document, 'array', '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map | bson_expression_map --------------------------------------------------------------------- { "field" : [ false, true, true, true, true, true, true, false, false ] } | { "field" : [ { "$numberInt" : "1" }, [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ], [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ], [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ], [ ], [ { "$numberInt" : "2" } ] ] } (1 row) -- test nested operator expansion (this should all be false since the inner operator returns true/false and is never an array) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$isArray": "$a.b" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) -- isArray expressions: array declaration. SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "some literal" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "$literal": [ 1, 2, 3 ] } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ true, true, true, true, true, true, true, true, true ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "$literal": "someLiteral" } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "nestedObj": "someValue" } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, false, false, false, false, false, false, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ false, true, true, true, true, true, true, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ [1, 2, 3 ] ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; bson_expression_map --------------------------------------------------------------------- { "field" : [ true, true, true, true, true, true, true, true, true ] } (1 row) -- isArray expressions: array declaration invalid SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; ERROR: The expression $isArray requires exactly 1 arguments, but 0 arguments were actually provided. SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ 1, 2 ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; ERROR: The expression $isArray requires exactly 1 arguments, but 2 arguments were actually provided. -- unsupported operators SELECT bson_expression_map(document, 'array', '{ "field" : { "$unknownop": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; ERROR: Unrecognized expression format: $unknownop -- Array Expression and Nested Expression evaluation tests SELECT bson_expression_map(document, 'array', '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ [ "1" ], [ "2" ], [ "3" ], [ "4" ], [ "5" ], [ "6" ], [ "7" ], [ "8" ], [ "9" ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ [ { "b" : { "$numberInt" : "1" } } ], [ { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ], [ [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] ], [ [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] ], [ { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } ], [ [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] ], [ [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] ], [ { "c" : { "$numberInt" : "1" } } ], [ null ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ [ { "$numberInt" : "1" } ], [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ], [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ], [ [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ], [ [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ], [ [ ] ], [ [ { "$numberInt" : "2" } ] ], [ null ], [ null ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ { "val" : [ { "$numberInt" : "1" } ] }, { "val" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "val" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ] }, { "val" : [ [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ] }, { "val" : [ [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] }, { "val" : [ [ ] ] }, { "val" : [ [ { "$numberInt" : "2" } ] ] }, { "val" : [ null ] }, { "val" : [ null ] } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", "$a.b"]}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ { "val" : [ "1", "2", { "$numberInt" : "1" } ] }, { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ] }, { "val" : [ "1", "2", [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ] }, { "val" : [ "1", "2", [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] }, { "val" : [ "1", "2", [ ] ] }, { "val" : [ "1", "2", [ { "$numberInt" : "2" } ] ] }, { "val" : [ "1", "2", null ] }, { "val" : [ "1", "2", null ] } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", "$a.b"], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "new" : [ { "val" : [ "1", "2", { "$numberInt" : "1" } ], "val2" : "1" }, { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ], "val2" : "2" }, { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ], "val2" : "3" }, { "val" : [ "1", "2", [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ], "val2" : "4" }, { "val" : [ "1", "2", [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ], "val2" : "5" }, { "val" : [ "1", "2", [ ] ], "val2" : "6" }, { "val" : [ "1", "2", [ { "$numberInt" : "2" } ] ], "val2" : "7" }, { "val" : [ "1", "2", null ], "val2" : "8" }, { "val" : [ "1", "2", null ], "val2" : "9" } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "field" : [ false, true, true, true, true, true, true, false, false ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] , "a": 1.0} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: Expected a single field in an expression operator specification. Found: '$isArray' and 'a'. SELECT bson_expression_map(document, 'array', '{ "field" : { "first": 1.0, "$isArray": [ "$a.b" ]} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT bson_expression_map(document, 'array', '{ "field" : ["$_id", ["$a", "$b"], { "arrayobj" : [{},"$_id"]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ "1", [ { "b" : { "$numberInt" : "1" } }, null ], { "arrayobj" : [ { }, "1" ] } ], [ "2", [ { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, null ], { "arrayobj" : [ { }, "2" ] } ], [ "3", [ [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], null ], { "arrayobj" : [ { }, "3" ] } ], [ "4", [ [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], null ], { "arrayobj" : [ { }, "4" ] } ], [ "5", [ { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, null ], { "arrayobj" : [ { }, "5" ] } ], [ "6", [ [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ], null ], { "arrayobj" : [ { }, "6" ] } ], [ "7", [ [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], null ], { "arrayobj" : [ { }, "7" ] } ], [ "8", [ { "c" : { "$numberInt" : "1" } }, null ], { "arrayobj" : [ { }, "8" ] } ], [ "9", [ null, null ], { "arrayobj" : [ { }, "9" ] } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : [{"$literal" : 3.12}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ], [ { "$numberDouble" : "3.1200000000000001066" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : [{"$isArray" : [1,2]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: The expression $isArray requires exactly 1 arguments, but 2 arguments were actually provided. SELECT bson_expression_map(document, 'array', '{ "field" : {"$literal" : 3.12} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "field" : [ { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" }, { "$numberDouble" : "3.1200000000000001066" } ] } (1 row) SELECT bson_expression_map(document, 'array', '{ "field" : {"$isArray" : "$a.b"} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); bson_expression_map --------------------------------------------------------------------- { "field" : [ false, true, true, true, true, true, true, false, false ] } (1 row) -- Expressions with undefined paths. SELECT documentdb_api.insert_one('db', 'mapprojectexprwithundefined','{"array": [{"_id":"1", "a": [ 1, 2 ] },{"_id":"2", "a": { "b": 1 } },{"_id":"3", "a" : [ { "b": 1 }, 2, 3 ] },{"_id":"4", "a" : { "b": [ 1, 2 ] } } ] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_expression_map(document, 'array', '{"field": "$z"}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": "$a.b.c"}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ ], [ ], [ ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": ["$z", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": ["$a.b.c", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ [ ], { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ [ ], { "$numberInt" : "2" } ], [ [ ], { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": ["$a.x.y", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ [ ], { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ [ ], { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": ["$z.x.y", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ], [ null, { "$numberInt" : "2" } ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, ["$z"]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ], [ [ null ], { "$numberInt" : "2" }, [ null ] ], [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ], [ [ null ], { "$numberInt" : "2" }, [ null ] ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 2]}]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ], [ [ null ], { "$numberInt" : "2" }, [ null ] ], [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ], [ [ null ], { "$numberInt" : "2" }, [ null ] ] ] } (1 row) SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 0]}]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); bson_expression_map --------------------------------------------------------------------- { "field" : [ [ [ [ ] ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ], [ [ null ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ], [ [ [ ] ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ], [ [ null ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ] ] } (1 row) -- Error cases when a field is an empty string SELECT bson_expression_map(document, 'array', '{ "field" : {"" : "$a.b"} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", {"": "hello"}], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. SELECT bson_expression_map(document, 'array', '{ "field" : [{"literal" : [2, {"" : "empty"}]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. -- Field not present or null, NullOnEmpty = false SELECT bson_expression_map('{"array": [{}]}', 'array', '{ "": "$a" }', false), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": "$a" }', false), bson_expression_map('{"array": [{}]}', 'array', '{ "": { "a" : "$a" }}', false), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', false); bson_expression_map | bson_expression_map | bson_expression_map | bson_expression_map --------------------------------------------------------------------- { "" : [ ] } | { "" : [ null ] } | { "" : [ { } ] } | { "" : [ { "a" : null } ] } (1 row) -- Field not present or null, NullOnEmpty = true SELECT bson_expression_map('{"array": [{}]}', 'array', '{ "": "$a" }', true), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": "$a" }', true), bson_expression_map('{"array": [{}]}', 'array', '{ "": { "a" : "$a" }}', true), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', true); bson_expression_map | bson_expression_map | bson_expression_map | bson_expression_map --------------------------------------------------------------------- { "" : [ null ] } | { "" : [ null ] } | { "" : [ { "a" : null } ] } | { "" : [ { "a" : null } ] } (1 row) -- Array not present or null or not an array SELECT bson_expression_map('{"array": {}}', 'array', '{ "": "$a" }', true); ERROR: Input Array for bson_express_map of wrong type Name: 'array' Type: 'object' SELECT bson_expression_map('{"array": null}', 'array', '{ "": "$a" }', true); ERROR: Input Array for bson_express_map of wrong type Name: 'array' Type: 'null' SELECT bson_expression_map('{"array": []}', 'array', '{ "": { "a" : "$a" }}', true); bson_expression_map --------------------------------------------------------------------- { "" : [ ] } (1 row) SELECT bson_expression_map('{"notarray": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', true); ERROR: Missing Input Array for bson_expression_map: 'array' -- Document and array expressions with nested expressions that should be converted to a constant at the tree parse stage SET client_min_messages TO DEBUG3; SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": {"a": [ { "$literal" : "foo" } ] }}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_map --------------------------------------------------------------------- { "result" : [ { "a" : [ "foo" ] } ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$literal" : "foo" } ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_map --------------------------------------------------------------------- { "result" : [ [ "foo" ] ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$undefined" : true } ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_map --------------------------------------------------------------------- { "result" : [ [ null ] ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$literal" : "foo" }, {"$substr": ["wehello world", 2, -1]} ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_map --------------------------------------------------------------------- { "result" : [ [ "foo", "hello world" ] ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": {"a": [ { "$literal" : "foo" } ], "a": {"$const": "foo2"} }}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_map --------------------------------------------------------------------- { "result" : [ { "a" : "foo2" } ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); DEBUG: Converting document expression into a fixed constant. bson_expression_map --------------------------------------------------------------------- { "document" : [ { "a" : { "a" : "$$REMOVE" }, "b" : "b is 2" } ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": { "b" : {"a": "foo", "d": {"$substr": ["hello world", 6, -1]}} }, "c": {"$const": "c is 2"} }}'); DEBUG: Converting document expression into a fixed constant. bson_expression_map --------------------------------------------------------------------- { "document" : [ { "a" : { "b" : { "a" : "foo", "d" : "world" } }, "c" : "c is 2" } ] } (1 row) SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": {"d": { "$literal" : {"a": "$$REMOVE" } }, "c": [{"$literal": "$$REMOVE"}, true, false]}, "b": {"$const": "b is 2"}}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_map --------------------------------------------------------------------- { "document" : [ { "a" : { "d" : { "a" : "$$REMOVE" }, "c" : [ "$$REMOVE", true, false ] }, "b" : "b is 2" } ] } (1 row) SET client_min_messages TO DEFAULT; bson_query_projection_operator_expressions_tests.out000066400000000000000000001425231507310017400427540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 240000; SET documentdb.next_collection_id TO 2400; SET documentdb.next_collection_index_id TO 2400; SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"1", "a" : { "b" : 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"2", "a" : { "b" : [ 0, 1, 2]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"6", "a" : [ { "c" : 0 }, 2 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"8", "a" : { "c" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"9", "c" : { "d" : 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- field path expressions SELECT bson_expression_get(document, '{ "field" : "$a" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "b" : { "$numberInt" : "1" } } } { "field" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "field" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "field" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "field" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "field" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "$numberInt" : "1" } } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } { "field" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "field" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "field" : [ ] } { "field" : [ { "$numberInt" : "2" } ] } { } { } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.c" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { } { } { "field" : [ ] } { "field" : [ ] } { } { "field" : [ { "$numberInt" : "0" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] } { "field" : { "$numberInt" : "1" } } { } (9 rows) -- field path expressions on bson_expression_get() with nullOnEmpty = true SELECT bson_expression_get(document, '{ "field" : "$a" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "b" : { "$numberInt" : "1" } } } { "field" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "field" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "field" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "field" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "field" : { "c" : { "$numberInt" : "1" } } } { "field" : null } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.b" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "$numberInt" : "1" } } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } { "field" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "field" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "field" : [ ] } { "field" : [ { "$numberInt" : "2" } ] } { "field" : null } { "field" : null } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.c" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : null } { "field" : null } { "field" : [ ] } { "field" : [ ] } { "field" : null } { "field" : [ { "$numberInt" : "0" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] } { "field" : { "$numberInt" : "1" } } { "field" : null } (9 rows) -- field path expressions on bson_expression_get() with nullOnEmpty = false SELECT bson_expression_get(document, '{ "field" : "$a" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "b" : { "$numberInt" : "1" } } } { "field" : { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } } { "field" : [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] } { "field" : [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] } { "field" : { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] } { "field" : [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] } { "field" : { "c" : { "$numberInt" : "1" } } } { } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.b" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "$numberInt" : "1" } } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } { "field" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "field" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "field" : [ ] } { "field" : [ { "$numberInt" : "2" } ] } { } { } (9 rows) SELECT bson_expression_get(document, '{ "field" : "$a.c" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { } { } { "field" : [ ] } { "field" : [ ] } { } { "field" : [ { "$numberInt" : "0" } ] } { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ] } { "field" : { "$numberInt" : "1" } } { } (9 rows) -- const value expressions SELECT bson_expression_get(document, '{ "field" : "someString" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } { "field" : "someString" } (9 rows) SELECT bson_expression_get(document, '{ "field" : [ "1.0" ] }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } { "field" : [ "1.0" ] } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$minKey": 1 } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } { "field" : { "$minKey" : 1 } } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "nestedField": "fieldValue" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } { "field" : { "nestedField" : "fieldValue" } } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "nestedField": "fieldValue", "nestedField2": "fieldValue2" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } { "field" : { "nestedField" : "fieldValue", "nestedField2" : "fieldValue2" } } (9 rows) -- literal expressions SELECT bson_expression_get(document, '{ "field" : { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } { "field" : { "$numberDouble" : "1.0" } } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$literal": [1, 2, 3] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "field" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$literal": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } { "field" : "some literal" } (9 rows) -- isArray expressions: top level expression SELECT bson_expression_get(document, '{ "field" : { "$isArray": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$literal": [ 1, 2, 3 ] } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$literal": "someLiteral" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "nestedObj": "someValue" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) -- project $a.b along with isArray to validate the values easily. SELECT bson_expression_get(document, '{ "field" : { "$isArray": "$a.b" } }'), bson_expression_get(document, '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get | bson_expression_get --------------------------------------------------------------------- { "field" : false } | { "field" : { "$numberInt" : "1" } } { "field" : true } | { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "field" : true } | { "field" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } { "field" : true } | { "field" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } { "field" : true } | { "field" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } { "field" : true } | { "field" : [ ] } { "field" : true } | { "field" : [ { "$numberInt" : "2" } ] } { "field" : false } | { } { "field" : false } | { } (9 rows) -- test nested operator expansion (this should all be false since the inner operator returns true/false and is never an array) SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$isArray": "$a.b" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) -- isArray expressions: array declaration. SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "some literal" ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "$literal": [ 1, 2, 3 ] } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "$literal": "someLiteral" } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "nestedObj": "someValue" } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ [1, 2, 3 ] ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; bson_expression_get --------------------------------------------------------------------- { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } (9 rows) -- isArray expressions: array declaration invalid SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; ERROR: The expression $isArray requires exactly 1 arguments, but 0 arguments were actually provided. SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ 1, 2 ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; ERROR: The expression $isArray requires exactly 1 arguments, but 2 arguments were actually provided. -- unsupported operators SELECT bson_expression_get(document, '{ "field" : { "$unknownop": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; ERROR: Unrecognized expression format: $unknownop -- Array Expression and Nested Expression evaluation tests SELECT bson_expression_get(document, '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : [ "1" ] } { "new" : [ "2" ] } { "new" : [ "3" ] } { "new" : [ "4" ] } { "new" : [ "5" ] } { "new" : [ "6" ] } { "new" : [ "7" ] } { "new" : [ "8" ] } { "new" : [ "9" ] } (9 rows) SELECT bson_expression_get(document, '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : [ { "b" : { "$numberInt" : "1" } } ] } { "new" : [ { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } { "new" : [ [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ] ] } { "new" : [ [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ] ] } { "new" : [ { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] } ] } { "new" : [ [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ] ] } { "new" : [ [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ] ] } { "new" : [ { "c" : { "$numberInt" : "1" } } ] } { "new" : [ null ] } (9 rows) SELECT bson_expression_get(document, '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : [ { "$numberInt" : "1" } ] } { "new" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "new" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ] } { "new" : [ [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ] } { "new" : [ [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] } { "new" : [ [ ] ] } { "new" : [ [ { "$numberInt" : "2" } ] ] } { "new" : [ null ] } { "new" : [ null ] } (9 rows) SELECT bson_expression_get(document, '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : { "val" : [ { "$numberInt" : "1" } ] } } { "new" : { "val" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "new" : { "val" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ] } } { "new" : { "val" : [ [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ] } } { "new" : { "val" : [ [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] } } { "new" : { "val" : [ [ ] ] } } { "new" : { "val" : [ [ { "$numberInt" : "2" } ] ] } } { "new" : { "val" : [ null ] } } { "new" : { "val" : [ null ] } } (9 rows) SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", "$a.b"]}}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : { "val" : [ "1", "2", { "$numberInt" : "1" } ] } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ] } } { "new" : { "val" : [ "1", "2", [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ] } } { "new" : { "val" : [ "1", "2", [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ] } } { "new" : { "val" : [ "1", "2", [ ] ] } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "2" } ] ] } } { "new" : { "val" : [ "1", "2", null ] } } { "new" : { "val" : [ "1", "2", null ] } } (9 rows) SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", "$a.b"], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "new" : { "val" : [ "1", "2", { "$numberInt" : "1" } ], "val2" : "1" } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ], "val2" : "2" } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] ], "val2" : "3" } } { "new" : { "val" : [ "1", "2", [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] ], "val2" : "4" } } { "new" : { "val" : [ "1", "2", [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] ], "val2" : "5" } } { "new" : { "val" : [ "1", "2", [ ] ], "val2" : "6" } } { "new" : { "val" : [ "1", "2", [ { "$numberInt" : "2" } ] ], "val2" : "7" } } { "new" : { "val" : [ "1", "2", null ], "val2" : "8" } } { "new" : { "val" : [ "1", "2", null ], "val2" : "9" } } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : false } { "field" : false } (9 rows) SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] , "a": 1.0} }') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: Expected a single field in an expression operator specification. Found: '$isArray' and 'a'. SELECT bson_expression_get(document, '{ "field" : { "first": 1.0, "$isArray": [ "$a.b" ]} }') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. SELECT bson_expression_get(document, '{ "field" : ["$_id", ["$a", "$b"], { "arrayobj" : [{},"$_id"]}] }') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "field" : [ "1", [ { "b" : { "$numberInt" : "1" } }, null ], { "arrayobj" : [ { }, "1" ] } ] } { "field" : [ "2", [ { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, null ], { "arrayobj" : [ { }, "2" ] } ] } { "field" : [ "3", [ [ { "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" } } ], null ], { "arrayobj" : [ { }, "3" ] } ] } { "field" : [ "4", [ [ { "b" : [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "b" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] } ], null ], { "arrayobj" : [ { }, "4" ] } ] } { "field" : [ "5", [ { "b" : [ { "1" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } ] }, null ], { "arrayobj" : [ { }, "5" ] } ] } { "field" : [ "6", [ [ { "c" : { "$numberInt" : "0" } }, { "$numberInt" : "2" } ], null ], { "arrayobj" : [ { }, "6" ] } ] } { "field" : [ "7", [ [ { "c" : { "$numberInt" : "0" } }, { "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" } } ], null ], { "arrayobj" : [ { }, "7" ] } ] } { "field" : [ "8", [ { "c" : { "$numberInt" : "1" } }, null ], { "arrayobj" : [ { }, "8" ] } ] } { "field" : [ "9", [ null, null ], { "arrayobj" : [ { }, "9" ] } ] } (9 rows) SELECT bson_expression_get(document, '{ "field" : [{"$literal" : 3.12}] }') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } { "field" : [ { "$numberDouble" : "3.1200000000000001066" } ] } (9 rows) SELECT bson_expression_get(document, '{ "field" : [{"$isArray" : [1,2]}] }') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: The expression $isArray requires exactly 1 arguments, but 2 arguments were actually provided. SELECT bson_expression_get(document, '{ "field" : {"$literal" : 3.12} }') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } { "field" : { "$numberDouble" : "3.1200000000000001066" } } (9 rows) SELECT bson_expression_get(document, '{ "field" : {"$isArray" : "$a.b"} }') FROM documentdb_api.collection('db', 'projectexprs'); bson_expression_get --------------------------------------------------------------------- { "field" : false } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : true } { "field" : false } { "field" : false } (9 rows) -- Expressions with undefined paths. SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"1", "a": [ 1, 2 ] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"2", "a": { "b": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"3", "a" : [ { "b": 1 }, 2, 3 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"4", "a" : { "b": [ 1, 2 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_expression_get(document, '{"field": "$z"}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { } { } { } { } (4 rows) SELECT bson_expression_get(document, '{"field": "$a.b.c"}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ ] } { } { "field" : [ ] } { "field" : [ ] } (4 rows) SELECT bson_expression_get(document, '{"field": ["$z", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } (4 rows) SELECT bson_expression_get(document, '{"field": ["$a.b.c", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ [ ], { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ [ ], { "$numberInt" : "2" } ] } { "field" : [ [ ], { "$numberInt" : "2" } ] } (4 rows) SELECT bson_expression_get(document, '{"field": ["$a.x.y", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ [ ], { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ [ ], { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } (4 rows) SELECT bson_expression_get(document, '{"field": ["$z.x.y", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } { "field" : [ null, { "$numberInt" : "2" } ] } (4 rows) SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, ["$z"]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ null ] ] } (4 rows) SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 2]}]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ null ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ null ] ] } (4 rows) SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 0]}]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); bson_expression_get --------------------------------------------------------------------- { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ] } { "field" : [ [ [ ] ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ] } { "field" : [ [ null ], { "$numberInt" : "2" }, [ { "$numberInt" : "1" } ] ] } (4 rows) -- Error cases when a field is an empty string SELECT bson_expression_get(document, '{ "field" : {"" : "$a.b"} }') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", {"": "hello"}], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. SELECT bson_expression_get(document, '{ "field" : [{"literal" : [2, {"" : "empty"}]}] }') FROM documentdb_api.collection('db', 'projectexprs'); ERROR: A FieldPath object cannot be created when the provided string is empty. -- Field not present or null, NullOnEmpty = false SELECT bson_expression_get('{}', '{ "": "$a" }', false), bson_expression_get('{"a" : null}', '{ "": "$a" }', false), bson_expression_get('{}', '{ "": { "a" : "$a" }}', false), bson_expression_get('{"a" : null}', '{ "": { "a" : "$a" }}', false); bson_expression_get | bson_expression_get | bson_expression_get | bson_expression_get --------------------------------------------------------------------- { } | { "" : null } | { "" : { } } | { "" : { "a" : null } } (1 row) -- Field not present or null, NullOnEmpty = true SELECT bson_expression_get('{}', '{ "": "$a" }', true), bson_expression_get('{"a" : null}', '{ "": "$a" }', true), bson_expression_get('{}', '{ "": { "a" : "$a" }}', true), bson_expression_get('{"a" : null}', '{ "": { "a" : "$a" }}', true); bson_expression_get | bson_expression_get | bson_expression_get | bson_expression_get --------------------------------------------------------------------- { "" : null } | { "" : null } | { "" : { "a" : null } } | { "" : { "a" : null } } (1 row) -- Document and array expressions with nested expressions that should be converted to a constant at the tree parse stage SET client_min_messages TO DEBUG3; SELECT bson_expression_get('{}', '{"result": {"a": [ { "$literal" : "foo" } ] }}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_get --------------------------------------------------------------------- { "result" : { "a" : [ "foo" ] } } (1 row) SELECT bson_expression_get('{}', '{"result": [ { "$literal" : "foo" } ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_get --------------------------------------------------------------------- { "result" : [ "foo" ] } (1 row) SELECT bson_expression_get('{}', '{"result": [ { "$undefined" : true } ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_get --------------------------------------------------------------------- { "result" : [ null ] } (1 row) SELECT bson_expression_get('{}', '{"result": [ { "$literal" : "foo" }, {"$substr": ["wehello world", 2, -1]} ] }'); DEBUG: Transforming array expression into fixed constant. bson_expression_get --------------------------------------------------------------------- { "result" : [ "foo", "hello world" ] } (1 row) SELECT bson_expression_get('{}', '{"result": {"a": [ { "$literal" : "foo" } ], "a": {"$const": "foo2"} }}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_get --------------------------------------------------------------------- { "result" : { "a" : "foo2" } } (1 row) SELECT bson_expression_get('{}', '{"document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); DEBUG: Converting document expression into a fixed constant. bson_expression_get --------------------------------------------------------------------- { "document" : { "a" : { "a" : "$$REMOVE" }, "b" : "b is 2" } } (1 row) SELECT bson_expression_get('{}', '{"document": {"a": { "b" : {"a": "foo", "d": {"$substr": ["hello world", 6, -1]}} }, "c": {"$const": "c is 2"} }}'); DEBUG: Converting document expression into a fixed constant. bson_expression_get --------------------------------------------------------------------- { "document" : { "a" : { "b" : { "a" : "foo", "d" : "world" } }, "c" : "c is 2" } } (1 row) SELECT bson_expression_get('{}', '{"document": {"a": {"d": { "$literal" : {"a": "$$REMOVE" } }, "c": [{"$literal": "$$REMOVE"}, true, false]}, "b": {"$const": "b is 2"}}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Converting document expression into a fixed constant. bson_expression_get --------------------------------------------------------------------- { "document" : { "a" : { "d" : { "a" : "$$REMOVE" }, "c" : [ "$$REMOVE", true, false ] }, "b" : "b is 2" } } (1 row) SELECT bson_dollar_project('{}', '{"array": [{"$substr": ["hello world", 0, -1]}, "1", 2, true, false, {"$literal": [{ "$add":[1, 2] }]}], "document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "array" : [ "hello world", "1", { "$numberInt" : "2" }, true, false, [ { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] ], "document" : { "a" : { "a" : "$$REMOVE" }, "b" : "b is 2" } } (1 row) SELECT bson_dollar_project('{}', '{"array": [{"$substr": ["hello world", 0, -1]}, "1", 2, true, false, {"$literal": [{ "$add":[1, 2] }]}], "document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"}}, "array2": [{"$literal": "$$ROOT"}, {"$literal": "$$NOW"}, true], "document2": {"result": {"$substr": ["result is: blah", 11, -1]}}}'); DEBUG: Transforming array expression into fixed constant. DEBUG: Transforming array expression into fixed constant. bson_dollar_project --------------------------------------------------------------------- { "array" : [ "hello world", "1", { "$numberInt" : "2" }, true, false, [ { "$add" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] ], "document" : { "a" : { "a" : "$$REMOVE" }, "b" : "b is 2" }, "array2" : [ "$$ROOT", "$$NOW", true ], "document2" : { "result" : "blah" } } (1 row) SET client_min_messages TO DEFAULT; bson_query_shard_key_optimization_tests.out000066400000000000000000000352151507310017400410010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 170000; SET documentdb.next_collection_id TO 1700; SET documentdb.next_collection_index_id TO 1700; SELECT documentdb_api.drop_collection('db', 'shardkeyopt') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', 'shardkeyopt'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create an index on a.b SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('shardkeyopt', 'a_b_1', '{"a.b": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170000 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1700_170000 collection Index Cond: ((shard_key_value = '1700'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$minKey" : 1 } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson)) (8 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1700_170000 collection Index Cond: ((shard_key_value = '1700'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$minKey" : 1 } }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson) (8 rows) ROLLBACK; -- shard the collection SELECT documentdb_api.shard_collection('db', 'shardkeyopt', '{ "c": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170016 documents_1700 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170016 documents_1700 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170016 documents_1700 Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson)) -> BitmapAnd -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson) (12 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170016 documents_1700 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }, "c": 2 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170017 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (shard_key_value = '-1389566185330078543'::bigint)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> BitmapAnd -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '-1389566185330078543'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "c": 2 }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170017 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (shard_key_value = '-1389566185330078543'::bigint)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "2" } }'::documentdb_core.bson) -> BitmapAnd -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '-1389566185330078543'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "c": 2, "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_1700_170017 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (shard_key_value = '-1389566185330078543'::bigint)) -> BitmapAnd -> Bitmap Index Scan on a_b_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@!=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson) (13 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "c": 2, "_id": { "$gt": { "$minKey": 1 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_1700_170017 collection Index Cond: ((shard_key_value = '-1389566185330078543'::bigint) AND (object_id OPERATOR(documentdb_core.>) '{ "" : { "$minKey" : 1 } }'::documentdb_core.bson)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : { "$minKey" : 1 } }'::documentdb_core.bson)) (8 rows) ROLLBACK; bson_selectivity_index_tests.out000066400000000000000000000453731507310017400365360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1014000; SET documentdb.next_collection_id TO 10140; SET documentdb.next_collection_index_id TO 10140; -- Test Scenarios that cover the Bitmap Or selectivity - more selecitivity tests will be added here with r1 AS (SELECT FORMAT('{ "a": 1, "b": 2, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(1, 25000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""25000"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) with r1 AS (SELECT FORMAT('{ "a": 1, "b": 3, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(25001, 50000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""25000"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) with r1 AS (SELECT FORMAT('{ "a": 1, "b": 3, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(50001, 75000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""25000"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "selectivity_index_tests", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "name": "idx_1" } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_10140; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'selectivity_index_tests') WHERE document @@ '{ "a": 1, "b": { "$in": [ 2, 3, 4, 5 ] }, "a": { "$in": [ 1, 5, 6, 7 ] }, "$or": [ { "c": 3, "d": { "$gt": 500 } }, { "c": { "$gt": 4 } }] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10140_1014007 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson)) Filter: (((document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "d" : { "$numberInt" : "500" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@>) '{ "c" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> Bitmap Index Scan on idx_1 Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson)) (10 rows) BEGIN; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'selectivity_index_tests') WHERE document @@ '{ "a": 1, "b": { "$in": [ 2, 3, 4, 5 ] }, "a": { "$in": [ 1, 5, 6, 7 ] }, "$or": [ { "c": 3, "d": { "$gt": 500 } }, { "c": { "$gt": 4 } }] }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_10140_1014007 collection Recheck Cond: (((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "d" : { "$numberInt" : "500" } }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "c" : { "$numberInt" : "4" } }'::documentdb_core.bson))) -> BitmapOr -> Bitmap Index Scan on idx_1 Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "d" : { "$numberInt" : "500" } }'::documentdb_core.bson)) -> Bitmap Index Scan on idx_1 Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "c" : { "$numberInt" : "4" } }'::documentdb_core.bson)) (12 rows) ROLLBACK; -- test bitmap or pushdown SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A380", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 40); NOTICE: creating collection count --------------------------------------------------------------------- 40 (1 row) SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A350", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 50); count --------------------------------------------------------------------- 50 (1 row) SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A330", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 30); count --------------------------------------------------------------------- 30 (1 row) SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A340", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 30); count --------------------------------------------------------------------- 30 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "productionDate": 1, "plane": 1 }, "name": "plane_productionDate_index" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "stoppingDate": 1, "plane": 1 }, "name": "plane_stoppingDate_index" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "noticeDate": 1, "plane": 1 }, "name": "plane_noticeDate_index" } ] }', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_10142; set documentdb.enableNewSelectivityMode to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=0 loops=1) -> Bitmap Heap Scan on documents_10142_1014018 collection (actual rows=0 loops=1) Recheck Cond: (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson) Filter: ((document @? '{ "productionDate" : false }'::bson) OR (document @? '{ "stoppingDate" : false }'::bson) OR (document @? '{ "noticeDate" : false }'::bson)) Rows Removed by Filter: 150 Heap Blocks: exact=4 -> Bitmap Index Scan on "plane_noticeDate_index" (actual rows=150 loops=1) Index Cond: (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson) (8 rows) set documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=0 loops=1) -> Bitmap Heap Scan on documents_10142_1014018 collection (actual rows=0 loops=1) Recheck Cond: (((document @? '{ "productionDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson)) OR ((document @? '{ "stoppingDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson)) OR ((document @? '{ "noticeDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson))) -> BitmapOr (actual rows=0 loops=1) -> Bitmap Index Scan on "plane_productionDate_index" (actual rows=0 loops=1) Index Cond: ((document @? '{ "productionDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson)) -> Bitmap Index Scan on "plane_stoppingDate_index" (actual rows=0 loops=1) Index Cond: ((document @? '{ "stoppingDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson)) -> Bitmap Index Scan on "plane_noticeDate_index" (actual rows=0 loops=1) Index Cond: ((document @? '{ "noticeDate" : false }'::bson) AND (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson)) (10 rows) set documentdb.enableNewSelectivityMode to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=0 loops=1) -> Bitmap Heap Scan on documents_10142_1014018 collection (actual rows=0 loops=1) Recheck Cond: (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson) Filter: ((document @? '{ "productionDate" : false }'::bson) OR (document @? '{ "stoppingDate" : false }'::bson) OR (document @? '{ "noticeDate" : false }'::bson)) Rows Removed by Filter: 150 Heap Blocks: exact=4 -> Bitmap Index Scan on "plane_noticeDate_index" (actual rows=150 loops=1) Index Cond: (document @~ '{ "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } } }'::bson) (8 rows) bson_sequence_tests.out000066400000000000000000000040541507310017400346020ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 230000; SET documentdb.next_collection_id TO 2300; SET documentdb.next_collection_index_id TO 2300; SELECT '{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence; bsonsequence --------------------------------------------------------------------- SEQHEX0c00000010610001000000000c0000001061000200000000 (1 row) SELECT bsonsequence_get_bson('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence); bsonsequence_get_bson --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "2" } } (2 rows) SELECT bsonsequence_get_bson(bsonsequence_in(bsonsequence_out('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence))); bsonsequence_get_bson --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "2" } } (2 rows) PREPARE q1(bytea) AS SELECT bsonsequence_get_bson($1); EXECUTE q1('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence::bytea); bsonsequence_get_bson --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "2" } } (2 rows) SELECT '{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence::bytea::bsonsequence; bsonsequence --------------------------------------------------------------------- SEQHEX0c00000010610001000000000c0000001061000200000000 (1 row) SELECT bsonsequence_get_bson('{ "a": 1 }'::bson::bsonsequence); bsonsequence_get_bson --------------------------------------------------------------------- { "a" : { "$numberInt" : "1" } } (1 row) -- generate a long string and ensure we have the docs. SELECT COUNT(*) FROM bsonsequence_get_bson(('{ "": [ ' || rtrim(REPEAT('{ "a": 1, "b": 2 },', 100), ',') || ' ] }')::bsonsequence); count --------------------------------------------------------------------- 100 (1 row) bson_sort_index_pushdown.out000066400000000000000000001107041507310017400356550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- tests specific to pushing down to the right index the $sort -- at the moment $sort is not pushed down to index unless it is a $sort on the _id field -- on an unsharded collection or we have a shard key filter and all the filters can be pushed to the _id index. -- once we support sort pushdown to the index we need to revisit the strategy to push down sort on _id. SET search_path TO documentdb_api,documentdb_api_internal,documentdb_api_catalog,documentdb_core; SET citus.next_shard_id TO 9640000; SET documentdb.next_collection_id TO 964000; SET documentdb.next_collection_index_id TO 964000; SET documentdb.enableIndexOrderbyPushdown = 'on'; DO $$ DECLARE i int; DECLARE a int; DECLARE modres int; BEGIN FOR i IN 1..10000 LOOP SELECT MOD(i, 3) into modres; CASE WHEN modres = 0 THEN a:=12; WHEN modres = 1 THEN a:=14; ELSE a:=22; END CASE; PERFORM documentdb_api.insert_one('sort_pushdown', 'coll', FORMAT('{ "_id": %s, "a": %s}', i, a)::documentdb_core.bson); END LOOP; END; $$; NOTICE: creating collection SELECT 1 FROM documentdb_distributed_test_helpers.get_feature_counter_pretty(true); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT count(*) from documentdb_api.collection('sort_pushdown', 'coll'); count --------------------------------------------------------------------- 10000 (1 row) -- force the analyzer to kick in to have real statistics after we did the insertion. ANALYZE documentdb_data.documents_964001; -- sort by id with no filters uses the _id_ index and returns the right results set enable_seqscan to off; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "11" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "12" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "15" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "16" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "17" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "19" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$numberInt" : "22" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1} }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documents_964001_9640002 collection (actual rows=10000 loops=1) Index Cond: (shard_key_value = '964001'::bigint) (2 rows) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": -1}, "limit": 20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10000" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9999" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9998" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9997" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9996" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9995" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9994" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9993" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9992" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9991" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9990" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9989" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9988" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9987" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9986" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9985" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9984" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9983" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9982" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9981" }, "a" : { "$numberInt" : "12" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": -1} }'); QUERY PLAN --------------------------------------------------------------------- Index Scan Backward using _id_ on documents_964001_9640002 collection (actual rows=10000 loops=1) Index Cond: (shard_key_value = '964001'::bigint) (2 rows) reset enable_seqscan; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"limit" : 2}, {"match" : 4}, {"sort" : 4}, {"sort_by_id" : 4}]} (1 row) -- filter on _id_ SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": 1}, "limit":20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "11" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "12" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "15" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "16" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "17" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "18" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "19" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "21" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "22" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "23" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "24" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "25" }, "a" : { "$numberInt" : "14" } } (20 rows) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": -1}, "limit":20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10000" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9999" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9998" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9997" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9996" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9995" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9994" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9993" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9992" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9991" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9990" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9989" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9988" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9987" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9986" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9985" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9984" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "9983" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "9982" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "9981" }, "a" : { "$numberInt" : "12" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": 1} }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=9995 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: quicksort Memory: 1087kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=9995 loops=1) Recheck Cond: ((shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "5" } }'::bson)) Filter: (document @> '{ "_id" : { "$numberInt" : "5" } }'::bson) Heap Blocks: exact=94 -> Bitmap Index Scan on _id_ (actual rows=9995 loops=1) Index Cond: ((shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "5" } }'::bson)) (9 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": -1} }'); QUERY PLAN --------------------------------------------------------------------- Sort (actual rows=9995 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "-1" } }'::bson)) USING >>> NULLS LAST Sort Method: quicksort Memory: 1087kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=9995 loops=1) Recheck Cond: ((shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "5" } }'::bson)) Filter: (document @> '{ "_id" : { "$numberInt" : "5" } }'::bson) Heap Blocks: exact=94 -> Bitmap Index Scan on _id_ (actual rows=9995 loops=1) Index Cond: ((shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "5" } }'::bson)) (9 rows) -- filter on a with no index SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 22}}, "sort": {"_id": 1}, "limit": 20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "8" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "11" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "14" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "17" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "20" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "23" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "26" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "29" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "32" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "35" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "38" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "41" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "44" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "47" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "50" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "53" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "56" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "59" }, "a" : { "$numberInt" : "22" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 22}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Index Scan using _id_ on documents_964001_9640002 collection (actual rows=20 loops=1) Index Cond: (shard_key_value = '964001'::bigint) Filter: (document @= '{ "a" : { "$numberInt" : "22" } }'::bson) Rows Removed by Filter: 39 (5 rows) -- create compound index on a and _id and filter on a and on _id SELECT documentdb_api_internal.create_indexes_non_concurrently('sort_pushdown', '{ "createIndexes": "coll", "indexes": [ { "key": { "a": 1, "_id": 1 }, "name": "a_id" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE documentdb_data.documents_964001; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "13" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "16" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "19" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "22" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "25" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "28" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "31" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "34" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "37" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "40" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "43" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "46" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "49" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "52" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "58" }, "a" : { "$numberInt" : "14" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=3334 loops=1) Recheck Cond: (document @= '{ "a" : { "$numberInt" : "14" } }'::bson) Heap Blocks: exact=94 -> Bitmap Index Scan on a_id (actual rows=3334 loops=1) Index Cond: (document @= '{ "a" : { "$numberInt" : "14" } }'::bson) (9 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$in": [12, 14]}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=6667 loops=1) Recheck Cond: (document @*= '{ "a" : [ { "$numberInt" : "12" }, { "$numberInt" : "14" } ] }'::bson) Heap Blocks: exact=94 -> Bitmap Index Scan on a_id (actual rows=6667 loops=1) Index Cond: (document @*= '{ "a" : [ { "$numberInt" : "12" }, { "$numberInt" : "14" } ] }'::bson) (9 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"query_operator_eq" : 4}, {"query_operator_gt" : 4}, {"query_operator_in" : 1}, {"limit" : 7}, {"match" : 9}, {"sort" : 9}, {"sort_by_id" : 9}]} (1 row) BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown = 'false'; ---- should not use Index Scan using _id_ EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 1 Tuple data received from nodes: 420 bytes Tasks Shown: All -> Task Tuple data received from node: 420 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=3334 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) Heap Blocks: exact=94 -> Bitmap Index Scan on a_id (actual rows=3334 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) (16 rows) ---- should not use Index Scan using _id_ with $in EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$in": [12, 14]}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 1 Tuple data received from nodes: 420 bytes Tasks Shown: All -> Task Tuple data received from node: 420 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=6667 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "12" }, { "$numberInt" : "14" } ] }'::documentdb_core.bson) Heap Blocks: exact=94 -> Bitmap Index Scan on a_id (actual rows=6667 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "12" }, { "$numberInt" : "14" } ] }'::documentdb_core.bson) (16 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"query_operator_eq" : 1}, {"query_operator_in" : 1}, {"limit" : 2}, {"match" : 2}, {"sort" : 2}, {"sort_by_id" : 2}]} (1 row) END; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 100}}, "sort": {"_id": 1}, "limit": 20 }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "101" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "102" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "103" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "104" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "105" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "106" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "107" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "108" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "109" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "110" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "111" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "112" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "113" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "114" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "115" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "116" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "117" }, "a" : { "$numberInt" : "12" } } { "_id" : { "$numberInt" : "118" }, "a" : { "$numberInt" : "14" } } { "_id" : { "$numberInt" : "119" }, "a" : { "$numberInt" : "22" } } { "_id" : { "$numberInt" : "120" }, "a" : { "$numberInt" : "12" } } (20 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 100}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640002 collection (actual rows=9900 loops=1) Recheck Cond: ((document @> '{ "_id" : { "$numberInt" : "100" } }'::bson) AND (shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "100" } }'::bson)) Heap Blocks: exact=94 -> BitmapAnd (actual rows=0 loops=1) -> Bitmap Index Scan on a_id (actual rows=9900 loops=1) Index Cond: (document @> '{ "_id" : { "$numberInt" : "100" } }'::bson) -> Bitmap Index Scan on _id_ (actual rows=9900 loops=1) Index Cond: ((shard_key_value = '964001'::bigint) AND (object_id > '{ "" : { "$numberInt" : "100" } }'::bson)) (12 rows) -- no filter should still prefer the _id index EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Index Scan using _id_ on documents_964001_9640002 collection (actual rows=20 loops=1) Index Cond: (shard_key_value = '964001'::bigint) (3 rows) -- shard the collection on a, should sort on object_id only when there is a shard filter. SELECT documentdb_api.shard_collection('{ "shardCollection": "sort_pushdown.coll", "key": { "a": "hashed" }, "numInitialChunks": 2 }'); shard_collection --------------------------------------------------------------------- (1 row) SET citus.explain_all_tasks to on; SET citus.max_adaptive_executor_pool_size to 1; EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 1 Tuple data received from nodes: 420 bytes Tasks Shown: All -> Task Tuple data received from node: 420 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640004 collection (actual rows=3334 loops=1) Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) AND (shard_key_value = '3904677705083871083'::bigint)) Heap Blocks: exact=94 -> BitmapAnd (actual rows=0 loops=1) -> Bitmap Index Scan on a_id (actual rows=3334 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ (actual rows=3334 loops=1) Index Cond: (shard_key_value = '3904677705083871083'::bigint) (19 rows) EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$gt": 14}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: remote_scan."?sort?" NULLS FIRST Sort Method: quicksort Memory: 26kB -> Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 2 Tuple data received from nodes: 700 bytes Tasks Shown: All -> Task Tuple data received from node: 700 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Bitmap Heap Scan on documents_964001_9640004 collection (actual rows=3333 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) Heap Blocks: exact=94 -> Bitmap Index Scan on a_id (actual rows=3333 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=0 loops=1) -> Sort (actual rows=0 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on documents_964001_9640005 collection (actual rows=0 loops=1) Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) -> Bitmap Index Scan on a_id (actual rows=0 loops=1) Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) (31 rows) -- no filter on sharded collection should not sort on object_id EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: remote_scan."?sort?" NULLS FIRST Sort Method: quicksort Memory: 26kB -> Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 2 Tuple data received from nodes: 700 bytes Tasks Shown: All -> Task Tuple data received from node: 700 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Seq Scan on documents_964001_9640004 collection (actual rows=10000 loops=1) -> Task Tuple data received from node: 0 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=0 loops=1) -> Sort (actual rows=0 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: quicksort Memory: 25kB -> Seq Scan on documents_964001_9640005 collection (actual rows=0 loops=1) (24 rows) -- drop compound index, should use the _id index CALL documentdb_api.drop_indexes('sort_pushdown', '{ "dropIndexes": "coll", "index": "a_id"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) ANALYZE documentdb_data.documents_964001; BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown = 'true'; EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 1 Tuple data received from nodes: 420 bytes Tasks Shown: All -> Task Tuple data received from node: 420 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Index Scan using _id_ on documents_964001_9640004 collection (actual rows=20 loops=1) Index Cond: (shard_key_value = '3904677705083871083'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "14" } }'::documentdb_core.bson) (11 rows) -- or should push down to the shards and use object_id EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"$or": [{"a": {"$eq": 14}}, {"a": {"$eq": 22}}]}, "sort": {"_id": 1}, "limit": 20 }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=20 loops=1) Task Count: 1 Tuple data received from nodes: 420 bytes Tasks Shown: All -> Task Tuple data received from node: 420 bytes Node: host=localhost port=58070 dbname=regression -> Limit (actual rows=20 loops=1) -> Sort (actual rows=20 loops=1) Sort Key: (documentdb_api_catalog.bson_orderby(document, '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson)) NULLS FIRST Sort Method: top-N heapsort Memory: 26kB -> Seq Scan on documents_964001_9640004 collection (actual rows=6667 loops=1) Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "14" }, { "$numberInt" : "22" } ] }'::documentdb_core.bson) AND ((shard_key_value = '3904677705083871083'::bigint) OR (shard_key_value = '-8641956760761651950'::bigint))) Rows Removed by Filter: 3333 (14 rows) ROLLBACK; RESET citus.explain_all_tasks; RESET citus.max_adaptive_executor_pool_size; bson_type_comparison_tests.out000066400000000000000000000354701507310017400362130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 66100; SET documentdb.next_collection_id TO 6610; SET documentdb.next_collection_index_id TO 6610; -- insert double SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : 3.0 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : 5.0 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : -1.0 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- string SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "Hell" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "hell" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "hello world" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "Actual string" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- object SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "a": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "b": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "ba": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "c": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- array SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : [ 1, 2, 3 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : [ true, "string", 2.0 ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- binary SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$binary": { "base64": "VGhpcyBpcyBhIHN0cmluZw==", "subType": "00" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$binary": { "base64": "QSBxdWljayBicm93biBmb3g=", "subType": "00" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- object_id SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$oid": "000102030405060708090A0B" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$oid": "0102030405060708090A0B0C" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- bool SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : false }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- date SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "123" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "5192" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "-200" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "1647277893736" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- null SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- regex SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "^foo$", "options": "gi" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "^foo$", "options": "" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "bar$", "options": "g" }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- int32 SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "25" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "13486" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "-25" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- int64 SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "25" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "13486" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "-25" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- timestamp SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 256, "i": 1 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 256, "i": 25 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 200, "i": 10 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 200, "i": 80 }} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- minkey, maxkey SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$minKey": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$maxKey": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- These type comparison don't work. -- Decimal128 -- these types don't have an extended json representation -- Javascript -- Javascript with scope -- Symbol -- DBPointer SELECT document -> 'a' FROM documentdb_api.collection('db', 'bsontypetests') ORDER BY document -> 'a', object_id; ?column? --------------------------------------------------------------------- { "" : { "$minKey" : 1 } } { "" : null } { "" : { "$numberInt" : "-25" } } { "" : { "$numberLong" : "-25" } } { "" : { "$numberDouble" : "-1.0" } } { "" : { "$numberDouble" : "3.0" } } { "" : { "$numberDouble" : "5.0" } } { "" : { "$numberInt" : "25" } } { "" : { "$numberLong" : "25" } } { "" : { "$numberInt" : "13486" } } { "" : { "$numberLong" : "13486" } } { "" : "Actual string" } { "" : "Hell" } { "" : "hell" } { "" : "hello world" } { "" : { "a" : { "$numberInt" : "1" } } } { "" : { "b" : { "$numberInt" : "1" } } } { "" : { "ba" : { "$numberInt" : "1" } } } { "" : { "c" : { "$numberInt" : "1" } } } { "" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } { "" : [ true, "string", { "$numberDouble" : "2.0" } ] } { "" : { "$binary" : { "base64" : "VGhpcyBpcyBhIHN0cmluZw==", "subType" : "00" } } } { "" : { "$binary" : { "base64" : "QSBxdWljayBicm93biBmb3g=", "subType" : "00" } } } { "" : { "$oid" : "000102030405060708090a0b" } } { "" : { "$oid" : "0102030405060708090a0b0c" } } { "" : false } { "" : true } { "" : { "$date" : { "$numberLong" : "-200" } } } { "" : { "$date" : { "$numberLong" : "123" } } } { "" : { "$date" : { "$numberLong" : "5192" } } } { "" : { "$date" : { "$numberLong" : "1647277893736" } } } { "" : { "$timestamp" : { "t" : 200, "i" : 10 } } } { "" : { "$timestamp" : { "t" : 200, "i" : 80 } } } { "" : { "$timestamp" : { "t" : 256, "i" : 1 } } } { "" : { "$timestamp" : { "t" : 256, "i" : 25 } } } { "" : { "$regularExpression" : { "pattern" : "^foo$", "options" : "" } } } { "" : { "$regularExpression" : { "pattern" : "^foo$", "options" : "i" } } } { "" : { "$regularExpression" : { "pattern" : "bar$", "options" : "" } } } { "" : { "$maxKey" : 1 } } (39 rows) bson_unique_index.out000066400000000000000000003065411507310017400342530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 560000; SET documentdb.next_collection_id TO 5600; SET documentdb.next_collection_index_id TO 5600; SET documentdb.enable_large_unique_index_keys TO false; -- insert a document SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"1", "a": { "b": 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5600 | 5600 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5600 | 5601 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "unique" : true } | t (2 rows) -- insert a value that doesn't collide with the unique index. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"2", "a": [ { "b": 2 }, { "b" : 3 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert a value that has duplicate values that do not collide with other values. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"3", "a": [ { "b": 4 }, { "b" : 4 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert a value that has duplicate values that collide wtih other values. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"4", "a": [ { "b": 5 }, { "b" : 3 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"5", "a": { "b": [ 5, 3 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"6", "a": { "b": 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- valid scenarios again. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"4", "a": [ { "b": 5 }, { "b" : 6 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"5", "a": { "b": [ 7, 9 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"6", "a": { "b": 8 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"7", "a": { "b": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"8", "a": { "b": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- we can use the unique index for queries BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueindex') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using "rumConstraint1" on documents_5600_560002 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (7 rows) ROLLBACK; -- insert a document that does not have an a.b (should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "c": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that does not have an a.b (should fail) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "d": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- insert another document that has a.b = null (Should fail) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "b": null } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- insert a document that has constraint failure on _id SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id": "8", "a": { "b": 2055 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) -- drop the unique index. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniqueindex", "index": ["rumConstraint1"]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5600 | 5600 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t (1 row) -- now we can violate the unique constraint SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"9", "a": { "b": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"10", "a": { "b": [ 2, 1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create an index when the collection violates unique. Should fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 }] }', true); ERROR: could not create exclusion constraint "documents_rum_index_5602_560002" DETAIL: Key (document, (ROW(shard_key_value, document)::shard_key_and_document))=({ "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } }, (5600,"{ ""_id"" : ""1"", ""a"" : { ""b"" : { ""$numberInt"" : ""1"" } } }")) conflicts with key (document, (ROW(shard_key_value, document)::shard_key_and_document))=({ "_id" : "9", "a" : { "b" : { "$numberInt" : "1" } } }, (5600,"{ ""_id"" : ""9"", ""a"" : { ""b"" : { ""$numberInt"" : ""1"" } } }")). CONTEXT: SQL statement "ALTER TABLE documentdb_data.documents_5600 ADD CONSTRAINT documents_rum_index_5602 EXCLUDE USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='a.b') WITH OPERATOR(documentdb_api_catalog.=?=), ((shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) documentdb_api_catalog.bson_rum_exclusion_ops(path='a.b') WITH OPERATOR(documentdb_api_catalog.=)) " -- create a unique index with the same name ( should be fine since we dropped it ) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "c": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5600 | 5600 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5600 | 5603 | { "v" : { "$numberInt" : "2" }, "key" : { "c" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "sparse" : true, "unique" : true } | t (2 rows) -- since this is sparse, we can create several documents without "c" on it. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"11", "d": "someValue" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that does not have an c (should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"12", "e" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that has a.b = null (Should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"13", "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- however, inserting 'c' again should fail. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"14", "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- drop the unique index by key. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniqueindex", "index": {"c": 1} }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5600 | 5600 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t (1 row) -- create unique index fails for wildcard. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"f.$**": 1}, "name": "my_idx3", "unique": 1.0}]}', true); ERROR: Error in specification { "key" : { "f.$**" : 1 }, "name" : "my_idx3", "unique" : 1.0 }:Index type 'wildcard' does not support the unique option SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"$**": 1}, "wildcardProjection": { "f.g": 0 }, "name": "my_idx3", "unique": 1.0}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "wildcardProjection" : { "f.g" : 0 }, "name" : "my_idx3", "unique" : 1.0 }:Index type 'wildcard' does not support the unique option -- test for sharded SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"1", "a": { "b": 1 }, "d": 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db', 'queryuniqueindexsharded', '{ "d": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindexsharded", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindexsharded') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5601 | 5605 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5601 | 5606 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "unique" : true } | t (2 rows) -- valid scenarios: SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"2", "a": { "b": [ 2, 2] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"3", "a": { "b": [ 3, 4 ] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"4", "a": { "b": 5 }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"5", "a": { "c": 5 }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now violate unique in shard key "d": 1 SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"6", "a": { "b": [ 3, 6 ] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"7", "a": { "b": null }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- now insert something in a different shard - should not violate unique SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"8", "a": { "b": [ 3, 6 ] }, "d": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"9", "a": { "b": null }, "d": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- still can be used for query. BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueindexsharded') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5601_560032 documents_5601 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on "rumConstraint1" Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (9 rows) ROLLBACK; -- create unique index with truncation SELECT string_agg(md5(random()::text), '_') AS longstring1 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring2 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring3 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring4 FROM generate_series(1, 100) \gset SELECT length(:'longstring1'); length --------------------------------------------------------------------- 3299 (1 row) -- create with truncation allowed and the new op-class enabled set documentdb.enable_large_unique_index_keys to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "e": 1 }, "name": "rumConstraint1", "unique": 1, "unique": 1, "sparse": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "e": 1, "f": 1 }, "name": "rumConstraint2", "unique": 1, "unique": 1, "sparse": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5607" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "e" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=e, tl='2691', generatenotfoundterm='true') WITH =?=) "documents_rum_index_5608" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=e, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=f, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- succeeds SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 1, "e": "%s", "f": 1 }', :'longstring1')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- unique conflict SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 2, "e": [ "%s", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- create with suffix post truncation - succeeds SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 3, "e": [ "%s-withsuffix", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this should also fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 4, "e": "%s-withsuffix", "f": 1 }', :'longstring1')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- this will work. SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 5, "e": "%s-withsuffix", "f": 1 }', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this will fail (suffix match of array and string). SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 6, "e": [ "%s", "%s-withsuffix" ], "f": 1 }', :'longstring3', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- test truncated elements with numeric types of the same/different equivalent value. SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 7, "e": { "path1": "%s", "path2": 1.0 }, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 8, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.0" }}, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 9, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.01" }}, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test composite sparse unique indexes: Should succeed since none of the documents have this path (sparse unique ignore) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "g": 1, "h": 1 }, "name": "rumConstraint3", "unique": 1, "sparse": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5, "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique cosntraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5, "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- reset test data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "rumConstraint1", "rumConstraint2", "rumConstraint3" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "4" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- test unique sparse composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": 1, "sparse": 1 }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5610" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=key1, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=key2, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- should succeed and generate terms for all combinations on both arrays SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail due to terms permutation on both arrays SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- now test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3, 4, 5] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should succeed with null permutations on missing key (sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed due to new combinations SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should work because doesn't fall in unique constraint SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key3": [1, 2] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key3": [1, 2] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5611" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=key1, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=key2, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3, 4, 5] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should fail with null permutations on missing key (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5612" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=a, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=b, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=c, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- should work SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "b": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- repeated documents won't matter because they don't fall in the index (sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5613" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=a, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=b, tl='2691', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=c, tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- should work SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "b": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- repeated documents will matter because they fall in the index (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5614" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=a, tl='60', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=b, tl='60', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- insert data in a way that bson_rum_single_path_ops will match truncated and bson_rum_unique_shard_path_ops recheck won't set documentdb.defaultUniqueIndexKeyhashOverride to 1; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset log level RESET client_min_messages; -- should fail even with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5600 Table "documentdb_data.documents_5600" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5600" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5615" EXCLUDE USING documentdb_rum (generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=, document bson_rum_single_path_ops (path=a, tl='60', generatenotfoundterm='true') WITH =?=, document bson_rum_single_path_ops (path=b, tl='60', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5600'::bigint) -- insert data in a way that bson_rum_single_path_ops will match truncated but unique shard uuid won't match set documentdb.defaultUniqueIndexKeyhashOverride to 0; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works - SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed without recheck logs SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset log level RESET client_min_messages; -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- test new op class (generate_unique_shard_document) for composite sparse indexes SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key2": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "2" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ { "$numberInt" : "1" } ], "key2" : [ "b" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "1" }, "$numPaths" : { "$numberInt" : "1" }, "key1" : [ { "$numberInt" : "1" } ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "6" }, "$numPaths" : { "$numberInt" : "1" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": 3 }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "7" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "key2" : [ { "$numberInt" : "3" } ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": ["a"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "8" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "key2" : [ [ "a" ], "a" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": "abobora", "key2": ["jabuticaba"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "3" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ "abobora" ], "key2" : [ [ "jabuticaba" ], "jabuticaba" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "0" }, "$numPaths" : { "$numberInt" : "0" } } (1 row) -- test new op class (generate_unique_shard_document) for composite not sparse indexes SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key2": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "2" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ { "$numberInt" : "1" } ], "key2" : [ "b" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "2" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ { "$numberInt" : "1" } ], "key2" : [ null ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "7" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "key2" : [ null ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": 3 }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "7" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "key2" : [ { "$numberInt" : "3" } ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": ["a"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "8" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "key2" : [ [ "a" ], "a" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": "abobora", "key2": ["jabuticaba"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "3" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ "abobora" ], "key2" : [ [ "jabuticaba" ], "jabuticaba" ] } (1 row) SELECT documentdb_api_internal.generate_unique_shard_document('{ "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); generate_unique_shard_document --------------------------------------------------------------------- { "$shard_key_value" : { "$numberLong" : "1" }, "$numTerms" : { "$numberInt" : "2" }, "$numPaths" : { "$numberInt" : "2" }, "key1" : [ null ], "key2" : [ null ] } (1 row) bson_unique_index_composite.out000066400000000000000000002640571507310017400363420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 562000; SET documentdb.next_collection_id TO 5620; SET documentdb.next_collection_index_id TO 5620; SET documentdb.enable_large_unique_index_keys TO false; -- insert a document SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"1", "a": { "b": 1 } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5620 | 5620 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5620 | 5621 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "unique" : true, "enableOrderedIndex" : { "$numberInt" : "1" } } | t (2 rows) -- insert a value that doesn't collide with the unique index. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"2", "a": [ { "b": 2 }, { "b" : 3 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert a value that has duplicate values that do not collide with other values. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"3", "a": [ { "b": 4 }, { "b" : 4 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert a value that has duplicate values that collide wtih other values. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"4", "a": [ { "b": 5 }, { "b" : 3 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"5", "a": { "b": [ 5, 3 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"6", "a": { "b": 3 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- valid scenarios again. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"4", "a": [ { "b": 5 }, { "b" : 6 }]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"5", "a": { "b": [ 7, 9 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"6", "a": { "b": 8 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"7", "a": { "b": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"8", "a": { "b": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- we can use the unique index for queries BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniquecomposite') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using "rumConstraint1" on documents_5620_562002 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (7 rows) ROLLBACK; -- insert a document that does not have an a.b (should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "c": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that does not have an a.b (should fail) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "d": "someValue" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- insert another document that has a.b = null (Should fail) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "b": null } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- insert a document that has constraint failure on _id SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id": "8", "a": { "b": 2055 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) -- drop the unique index. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniquecomposite", "index": ["rumConstraint1"]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5620 | 5620 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t (1 row) -- now we can violate the unique constraint SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"9", "a": { "b": 1 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"10", "a": { "b": [ 2, 1 ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create an index when the collection violates unique. Should fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); ERROR: could not create exclusion constraint "documents_rum_index_5622_562002" DETAIL: Key (document, documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, true))=({ "_id" : "1", "a" : { "b" : { "$numberInt" : "1" } } }, { "$shard_key_value" : { "$numberLong" : "5620" }, "$numTerms" : { "$numberInt" : "1" }, "$numPaths" : { "$numberInt" : "1" }, "a.b" : [ { "$numberInt" : "1" } ] }) conflicts with key (document, documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson, true))=({ "_id" : "9", "a" : { "b" : { "$numberInt" : "1" } } }, { "$shard_key_value" : { "$numberLong" : "5620" }, "$numTerms" : { "$numberInt" : "1" }, "$numPaths" : { "$numberInt" : "1" }, "a.b" : [ { "$numberInt" : "1" } ] }). CONTEXT: SQL statement "ALTER TABLE documentdb_data.documents_5620 ADD CONSTRAINT documents_rum_index_5622 EXCLUDE USING documentdb_rum ( document documentdb_api_internal.bson_rum_composite_path_ops(pathspec='[ "a.b" ]',tl=2691) WITH OPERATOR(documentdb_api_catalog.=?=),documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, 'BSONHEX0e00000010612e62000100000000'::documentdb_core.bson, true) documentdb_api_internal.bson_rum_unique_shard_path_ops WITH OPERATOR(documentdb_api_internal.=#=)) " -- create a unique index with the same name ( should be fine since we dropped it ) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "c": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 , "enableCompositeTerm": true}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5620 | 5620 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5620 | 5623 | { "v" : { "$numberInt" : "2" }, "key" : { "c" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "sparse" : true, "unique" : true, "enableOrderedIndex" : { "$numberInt" : "1" } } | t (2 rows) -- since this is sparse, we can create several documents without "c" on it. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"11", "d": "someValue" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that does not have an c (should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"12", "e" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- insert another document that has a.b = null (Should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"13", "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- however, inserting 'c' again should fail. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"14", "c": null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- drop the unique index by key. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniquecomposite", "index": {"c": 1} }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5620 | 5620 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t (1 row) -- create unique index fails for wildcard. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"f.$**": 1}, "name": "my_idx3", "unique": 1.0 }]}', true); ERROR: Error in specification { "key" : { "f.$**" : 1 }, "name" : "my_idx3", "unique" : 1.0 }:Index type 'wildcard' does not support the unique option SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"$**": 1}, "wildcardProjection": { "f.g": 0 }, "name": "my_idx3", "unique": 1.0}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "wildcardProjection" : { "f.g" : 0 }, "name" : "my_idx3", "unique" : 1.0 }:Index type 'wildcard' does not support the unique option -- test for sharded SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"1", "a": { "b": 1 }, "d": 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('db', 'queryuniqueshardedcomposite', '{ "d": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueshardedcomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueshardedcomposite') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 5621 | 5625 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 5621 | 5626 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b" : { "$numberInt" : "1" } }, "name" : "rumConstraint1", "unique" : true, "enableOrderedIndex" : { "$numberInt" : "1" } } | t (2 rows) -- valid scenarios: SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"2", "a": { "b": [ 2, 2] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"3", "a": { "b": [ 3, 4 ] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"4", "a": { "b": 5 }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"5", "a": { "c": 5 }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now violate unique in shard key "d": 1 SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"6", "a": { "b": [ 3, 6 ] }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"7", "a": { "b": null }, "d": 1 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- now insert something in a different shard - should not violate unique SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"8", "a": { "b": [ 3, 6 ] }, "d": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"9", "a": { "b": null }, "d": 2 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- still can be used for query. BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueshardedcomposite') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_5621_562032 documents_5621 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on "rumConstraint1" Index Cond: (document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "5" } }'::documentdb_core.bson) (9 rows) ROLLBACK; -- create unique index with truncation SELECT string_agg(md5(random()::text), '_') AS longstring1 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring2 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring3 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring4 FROM generate_series(1, 100) \gset SELECT length(:'longstring1'); length --------------------------------------------------------------------- 3299 (1 row) -- create with truncation allowed and the new op-class enabled set documentdb.enable_large_unique_index_keys to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "e": 1 }, "name": "rumConstraint1", "unique": 1, "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "e": 1, "f": 1 }, "name": "rumConstraint2", "unique": 1, "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5627" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "e" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "e" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=) "documents_rum_index_5628" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "e", "f" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "e" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- succeeds SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 1, "e": "%s", "f": 1 }', :'longstring1')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- unique conflict SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 2, "e": [ "%s", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- create with suffix post truncation - succeeds SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 3, "e": [ "%s-withsuffix", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this should also fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 4, "e": "%s-withsuffix", "f": 1 }', :'longstring1')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- this will work. SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 5, "e": "%s-withsuffix", "f": 1 }', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- this will fail (suffix match of array and string). SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 6, "e": [ "%s", "%s-withsuffix" ], "f": 1 }', :'longstring3', :'longstring2')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) -- test truncated elements with numeric types of the same/different equivalent value. SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 7, "e": { "path1": "%s", "path2": 1.0 }, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 8, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.0" }}, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 9, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.01" }}, "f": 1 }', :'longstring3')::bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test composite sparse unique indexes: Should succeed since none of the documents have this path (sparse unique ignore) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "g": 1, "h": 1 }, "name": "rumConstraint3", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5, "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique cosntraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5, "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "h": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'rumConstraint3'" } ] } (1 row) -- reset test data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "rumConstraint1", "rumConstraint2", "rumConstraint3" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "4" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- test unique sparse composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5630" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "key1", "key2" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- should succeed and generate terms for all combinations on both arrays SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail due to terms permutation on both arrays SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- now test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3, 4, 5] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should succeed with null permutations on missing key (sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed due to new combinations SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should work because doesn't fall in unique constraint SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key3": [1, 2] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key3": [1, 2] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d+ documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------------------------------------------------------------------- shard_key_value | bigint | | not null | | plain | | object_id | bson | | not null | | extended | | document | bson | | not null | | extended | | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5631" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "key1", "key2" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) \d+ documentdb_data.documents_rum_index_5631 Index "documentdb_data.documents_rum_index_5631" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | generate_unique_shard_document | uuid | yes | generate_unique_shard_document(document, shard_key_value, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false) | plain | 0 documentdb_rum, for table "documentdb_data.documents_5620" -- test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3, 4, 5] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should fail with null permutations on missing key (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5, "key2": null }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": true, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5632" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "b", "c" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }'::bson, true) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- should work SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "b": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- repeated documents won't matter because they don't fall in the index (sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5633" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "b", "c" ]', tl='2691') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- should work SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "b": 1, "c": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- repeated documents will matter because they fall in the index (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5634" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "b" ]', tl='60') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- insert data in a way that bson_rum_single_path_ops will match truncated and bson_rum_unique_shard_path_ops recheck won't set documentdb.defaultUniqueIndexKeyhashOverride to 1; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. DEBUG: Executing unique index runtime recheck. insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset log level RESET client_min_messages; -- should fail even with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_5620 Table "documentdb_data.documents_5620" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_5620" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_5635" EXCLUDE USING documentdb_rum (document bson_rum_composite_path_ops (pathspec='[ "a", "b" ]', tl='60') WITH =?=, generate_unique_shard_document(document, shard_key_value, '{ "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } }'::bson, false) bson_rum_unique_shard_path_ops WITH =#=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '5620'::bigint) -- insert data in a way that bson_rum_single_path_ops will match truncated but unique shard uuid won't match set documentdb.defaultUniqueIndexKeyhashOverride to 0; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works - SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should succeed without recheck logs SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset log level RESET client_min_messages; -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'constraint1'" } ] } (1 row) bson_update_document_tests.out000066400000000000000000007305171507310017400361640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 210000; SET documentdb.next_collection_id TO 2100; SET documentdb.next_collection_index_id TO 2100; -- replace document scenarios SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 1, "b": 2 } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- allow updating ID if it's type compatible SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 1.0, "b": 2 } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- ID mismatch not allowed: error SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 2.0, "b": 2 } }', '{}'); ERROR: Cannot modify '_id' field as part of the operation -- ID not specified - pick the ID from the source document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "b": 2 } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- upsert case: Creates a new document. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 2.0, "b": 2 } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "2.0" }, "b" : { "$numberInt" : "2" } } (1 row) -- upsert case: no id specified creates a new ID SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{}')).newDocument @? '{ "_id" : 1 }'; ?column? --------------------------------------------------------------------- t (1 row) -- upsert case: no id specified creates from filter SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": 2.0 }]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "2.0" }, "b" : { "$numberInt" : "2" } } (1 row) -- upsert case: no id specified autogenerates when _id filter is not $eq. SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": { "$gt": 2.0 } }]}')).newDocument @? '{ "_id" : 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": { "$lt": 2.0 } }]}')).newDocument @? '{ "_id" : 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1, "_id": 2.0 } ]}')).newDocument @? '{ "_id" : 1 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1 }, { "_id": 3 } ] }')).newDocument @? '{ "_id" : 1 }'; ?column? --------------------------------------------------------------------- t (1 row) -- would be nice to use the $type function. SELECT bson_get_value((documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1, "_id": 2.0 } ]}')).newDocument, '_id') @= '{ "" : 2.0 }'; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_get_value((documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1 }, { "_id": 3 } ] }')).newDocument, '_id') @!= '{ "" : 3 }'; ?column? --------------------------------------------------------------------- t (1 row) -- upsert case: _id collision between query and replace; errors out SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 3, "b": 2 } }', '{"$and": [ { "a": 1, "_id": 2.0 }]}'); ERROR: Cannot modify '_id' field as part of the operation SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$setOnInsert": {"_id.b": 1}, "$set":{ "_id": 1 } } }', '{"_id.a": 4}'); ERROR: Modifying the path '_id.b' will result in a conflict occurring at '_id' -- _id specified twice, failure for update. SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 3, "b": 2 } }', '{"$and": [ { "a": 1 }, {"_id": 2.0 }, { "_id": 3.0 }]}'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice -- update scenario tests: $set SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$set": { "a": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": "somePath" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, "somePath", { "$numberInt" : "3" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : "somePath" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, null, null, null, null, { "$numberInt" : "9" }, null, null, { "$numberInt" : "13" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 }, "$unset": { "a.b.6": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, null, null, null, null, { "$numberInt" : "9" }, null, null, { "$numberInt" : "13" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.1": { "sub": "1234" }, "a.b.5": [1, 2, 3 ] } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "sub" : "1234" }, { "$numberInt" : "3" }, null, null, [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$set": { "b.c.d": { "sub": "1234" } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" }, "b" : { "c" : { "d" : { "sub" : "1234" } } } } (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath", "a.b.c": false } } }', '{}'); ERROR: Modifying the path 'a.b.c' will result in a conflict occurring at 'a.b.c' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [] }', '{ "": { "$set": { "a.2.b": 1, "a.2.c": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ null, null, { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [] }', '{ "": { "$set": { "a.1500001": 1 } } }', '{}'); ERROR: Backfilling is not possible for more than 1500000 elements. -- update scenario tests: $inc SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$inc": { "a.b": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "4" } } } (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath", "a.b.c": 10 }, "$inc": { "a.b.c": 2 } } }', '{}'); ERROR: Modifying the path 'a.b.c' will result in a conflict occurring at 'a.b.c' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$set": { "b.c": 10 }, "$inc": { "b.c": 2 } } }', '{}'); ERROR: Modifying the path 'b.c' will result in a conflict occurring at 'b.c' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$inc": { "b.c": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" }, "b" : { "c" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ 1, 2, 3 ] }', '{ "": { "$inc": { "a.2": 2, "a.6": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" }, null, null, null, { "$numberInt" : "1" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); ERROR: Unable to perform $inc operators on the existing value ((NumberLong)9223372036854775807) in the document with identifier {_id: 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong": "-9223372036854775808"} }', '{ "": { "$inc": { "a": -1 } } }', '{}'); ERROR: Unable to perform $inc operators on the existing value ((NumberLong)-9223372036854775808) in the document with identifier {_id: 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":{"$oid":"5d505646cf6d4fe581014ab2"}, "a": {"$numberLong": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); ERROR: Unable to perform $inc operators on the existing value ((NumberLong)9223372036854775807) in the document with identifier {_id: { "$oid" : "5d505646cf6d4fe581014ab2" }} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDouble": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberDouble" : "9223372036854775808.0" } } (1 row) -- update scenario tests: $min SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "1" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": true } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": null } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : null } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": [1, 2, 3 ] } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.c": [1, 2, 3 ] } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$min": { "a.1": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" }, { "$numberInt" : "3" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$min": { "a.1": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": -1 }, "$min": { "a.1": 1 } } }', '{}'); ERROR: Modifying the path 'a.1' will result in a conflict occurring at 'a.1' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": {"$numberDecimal": "9.99e-100"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "9.99E-100" } } } (1 row) -- update scenario tests: $max SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "3" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": true } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : true } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": null } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": [1, 2, 3 ] } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.c": [1, 2, 3 ] } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$max": { "a.1": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$max": { "a.1": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "3" } ] } (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": 3 }, "$max": { "a.1": 1 } } }', '{}'); ERROR: Modifying the path 'a.1' will result in a conflict occurring at 'a.1' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": {"$numberDecimal": "9.99e100"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "9.99E+100" } } } (1 row) -- update scenario tests: $bit SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "and" : 10 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :3}', '{ "": { "$bit": { "expdata" : { "or" : 5 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "7" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :1}', '{ "": { "$bit": { "expdata" : { "xor" : 5 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "4" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :[13,3,1]}', '{ "": { "$bit": { "expdata.0" : { "and" :10 } } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : [ { "$numberInt" : "8" }, { "$numberInt" : "3" }, { "$numberInt" : "1" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "and" : 0, "or" : 10 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "10" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "or" : 10, "xor" : 10 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "5" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1}', '{ "": { "$bit": { "expdata" : { "or" : 10 }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "expdata" : { "$numberInt" : "10" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": [ 100, 200 ]}}, "f": 12 }', '{ "": { "$bit": {"key.x.y.0": {"and": 10}, "f": {"and": 10 }}}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : [ { "$numberInt" : "0" }, { "$numberInt" : "200" } ] } }, "f" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": 10 }}, "f": 1}', '{ "": { "$bit": { "key.x.y": { "xor": 10 } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : { "$numberInt" : "0" } } }, "f" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200 ] } }, "f": 1 } ', '{ "": { "$bit": { "key.x.y.0": { "and": 10 } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : [ { "$numberInt" : "0" }, { "$numberInt" : "200" } ] } }, "f" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "x": 1 , "f": 1 } ', '{ "": { "$bit": { "x": { "and": { "$numberLong": "1" } } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : { "$numberLong" : "1" }, "f" : { "$numberInt" : "1" } } (1 row) -- update scenario negative tests: $bit SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :"abc"}', '{ "": { "$bit": { "expdata" : { "or" :10 } } }}', '{}'); ERROR: $bit cannot be used on a value that is not of an integral type. The document with _id = 1 contains the field expdata, which has a non-integer type string. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "or" :10.0 } } }}', '{}'); ERROR: The $bit modifier field must be an Integer(32/64 bit); a 'double' is not supported here: { "or" : 10 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "ors" :10 } } }}', '{}'); ERROR: The $bit modifier only supports 'and', 'or', and 'xor', not 'ors' which is an unknown operator: { "ors" : 10 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :[1,2,3]}', '{ "": { "$bit": { "expdata" : { "or" :10 } } }}', '{}'); ERROR: $bit cannot be used on a value that is not of an integral type. The document with _id = 1 contains the field expdata, which has a non-integer type array. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { }} }}', '{}'); ERROR: You must pass in at least one bitwise operation. The format is: {$bit: {field: {and/or/xor: #}} /* TODO: Make the error compatible with mongo: "errmsg" : "Cannot create field 'y' in element {x: [ { y: 10 } ]}" */ SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [ { "y": 10 } ] }}', '{ "": { "$bit": { "key.x.y": { "and": 0 }}}}', '{}'); ERROR: Invalid array index path y -- update scenario tests: $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1 }', '{ "": {"$addToSet": { "letters": "a" } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1 }', '{ "": {"$addToSet": { "letters": {"a":"b", "c":"d"} } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ { "a" : "b", "c" : "d" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1 }', '{ "": {"$addToSet": { "letters": {"$each" : ["a", "b","c"]} } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", "c" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": {"c":"d", "e":"f", "g":"h" }} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", { "c" : "d", "e" : "f", "g" : "h" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": "c" } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", "c" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": ["c", "d"] } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", [ "c", "d" ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": "a" } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": ["a", "b"] } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", [ "a", "b" ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "c":123456} }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b" ], "c" : [ { "$numberInt" : "123456" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": "blue, green, red" }', '{ "": { "$addToSet": { "newColors": "mauve" } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "colors" : "blue, green, red", "newColors" : [ "mauve" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": ["blue, green, red"] }', '{ "": { "$addToSet": { "colors": {} } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "colors" : [ "blue, green, red", { } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": ["blue, green, red", { }] }', '{ "": { "$addToSet": { "colors": {} } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": ["c", "d"]}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", "c", "d" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": [ { } ]}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", { } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "numbers": [44,78,80,80,80] }', '{ "": { "$addToSet": { "numbers": 80 }} }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each" : ["c","d","c","d","c","e","d","e"] }}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", "c", "d", "e" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b","e"] }', '{ "": { "$addToSet": { "letters": { "$each" : ["a","b","c","d","e"] }}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ "a", "b", "e", "c", "d" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "numbers": [1,2,5] }', '{ "": { "$addToSet": { "numbers": { "$each" : [1,2,3,4,5,5,4,3,2,1] }}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "numbers" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "5" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200 ] } }, "f": 1 } ', '{ "": { "$addToSet": { "key.x.y": { "$each": [3, 5, 6] } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } }, "f" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200, "a" ] } }, "f": 1 } ', '{ "": { "$addToSet": { "key.x.y": { "$each": [3, 5, 6, 7,8,9,"a","b","a",7,8] } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : [ { "$numberInt" : "100" }, { "$numberInt" : "200" }, "a", { "$numberInt" : "3" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, "b" ] } }, "f" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": [ 100,3,6 ]}}, "f": [1,3] }', '{ "": { "$addToSet": {"key.x.y": {"$each": [1, 3, 6, 9,"b","a"]}, "f": {"$each": [1,2,4] }}}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "x" : { "y" : [ { "$numberInt" : "100" }, { "$numberInt" : "3" }, { "$numberInt" : "6" }, { "$numberInt" : "1" }, { "$numberInt" : "9" }, "b", "a" ] } }, "f" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "4" } ] } (1 row) -- Update scenario for some complex items: $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters": { "$each": [1,3,4] } } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "2" } } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters": { "$each": [[1,3,4]] } } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "2" } } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] }, [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters.0": { "$each": [1,3,4] } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "2" } }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": {"$addToSet": { "letters.0": { "$each": [1,3,4, { "a":2}, {"a":3} ] } }}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "2" } }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "a" : { "$numberInt" : "3" } } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": {"$addToSet": { "letters.0": { "$each": [4,{"a":3} ] }, "letters.1.a": { "$each": [4, {"a":2}] } } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "$numberInt" : "1" }, { "a" : { "$numberInt" : "2" } }, { "$numberInt" : "4" }, { "a" : { "$numberInt" : "3" } } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "a" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$addToSet" : {"a.3": 4 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, [ { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$addToSet" : {"a.7": 7 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, null, null, null, null, [ { "$numberInt" : "7" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$addToSet" : {"a.0.5": 7 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, null, null, null, null, [ { "$numberInt" : "7" } ] ], [ { "$numberInt" : "2" } ], [ { "$numberInt" : "3" } ] ] } (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],3]}', '{ "": { "$addToSet" : {"a.2.5": 7 } } }', '{}'); ERROR: Failed to create the field '2' within the element specified by {2 : 3} -- update scenario negative tests: $inc SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": [1,2] }', '{ "": { "$inc": { "a": 30 } } }', '{}'); ERROR: Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type array. SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": {"x":1} }', '{ "": { "$inc": { "a": 30 } } }', '{}'); ERROR: Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type object. SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": "b" }', '{ "": { "$inc": { "a": 30 } } }', '{}'); ERROR: Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string. SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": 5 }', '{ "": { "$inc": { "a": "strings" } } }', '{}'); ERROR: Increment should be numeric -- update scenario negative tests: $addToSet SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "colors": "blue, green, red" }', '{ "": { "$addToSet": { "colors": "mauve" } }}', '{}'); ERROR: Expected 'array' type for $addToSet but field 'colors' has 'string' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": "c"}}} }', '{}'); ERROR: Expected 'array' type for $each but found 'string' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each" : {} }}} }', '{}'); ERROR: Expected 'array' type for $each but found 'object' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$ach": ["c"]}}} }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""letters"" : [ ""a"", ""b"", { ""$ach"" : [ ""c"" ] } ] }",) (1 row) -- update scenario tests: $unset SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$unset": { "a.b": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2, "c": 3 }, "d": 1 }', '{ "": { "$unset": { "a.b": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "c" : { "$numberInt" : "3" } }, "d" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [ 1, 2, 3 ] } }', '{ "": { "$unset": { "a.b.1": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "1" }, null, { "$numberInt" : "3" } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [ 1, 2, 3 ] } }', '{ "": { "$unset": { "a.b.5": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$unset": { "a": 1, "b.c": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } (1 row) -- update scenario tests: $rename SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a.b": "c.d" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { }, "c" : { "d" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a.b": "a.c" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "c" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a": "c" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "b" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1 }', '{ "" : { "$rename": { "b": "c" } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "c": 4}', '{ "": { "$rename": { "b": "c.d" } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- $rename when rename source node doesn't exist but target node exist, this should be a no-op SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "c": 4}', '{ "": { "$rename": { "b": "a" } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": {"b": 1, "d": 2}}', '{ "": { "$rename": { "a.b": "c" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "d" : { "$numberInt" : "2" } }, "c" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": {"b": 1}}', '{ "": { "$rename": { "a.b": "d" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { }, "d" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "$rename": { "b": "a" }, "$set": {"x" : 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "x": 1}', '{ "": { "$rename": { "b": "a" }, "$inc": {"x" : 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "b": 1, "x": 1}', '{ "": { "$rename": { "a": "b", "x": "y" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "1" } } (1 row) -- update scenario tests: $mul SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble" : "2.0"} } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "0.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt" : "2" } } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "2" } } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "9223372036854775807" } } }', '{ "": { "$mul": { "a.b": {"$numberLong": "0"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble" : "0.0"} } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt" : "0" } } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "0" } } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": -10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "-20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "+1.0"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "2.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": 1.1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "2.2000000000000001776" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": -1.1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "-2.2000000000000001776" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberInt": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberLong": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberLong" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberDouble": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberDouble" : "0.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberDecimal" : "0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "100"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "500"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "50000" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2147483647"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "4611686014132420609" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2147483647"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "4611686014132420609" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "4294967294.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "-2147483647"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "-4611686014132420609" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "-2147483647"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberLong" : "-4611686014132420609" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "18446744073709551616.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "20.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "20.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "20.0" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": NaN } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }','{ "": { "$mul": { "a.b": NaN } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDouble" : "NaN" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20.00000000000000" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberDecimal" : "20.0000000000000" } } } (1 row) -- int64 overflow should coerce to double: $mul SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); ERROR: Unable to perform $mul on the existing ((NumberLong)9223372036854775807) value for the document with _id: 1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "-9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); ERROR: Unable to perform $mul on the existing ((NumberLong)-9223372036854775807) value for the document with _id: 1 -- update scenario error tests: $mul SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }','{ "": { "$mul": { "a.b": "Hello" } } }', '{}'); ERROR: Multiplication operation failed due to a non-numeric argument: { a.b : "Hello" } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": "Text" } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field 'b', which has a non-numeric type string. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1,2,3] } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field 'b', which has a non-numeric type array. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {} } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field 'b', which has a non-numeric type object. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": null } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field 'b', which has a non-numeric type null. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": true } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field 'b', which has a non-numeric type bool. -- $pullAll operator- positive testcases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "scores": [0,5] } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "scores" : [ { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters": [1,3,4] } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters.0": [1,3,4] } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "letters" : [ [ { "a" : { "$numberInt" : "2" } } ], { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "score": [0,5] } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "a.b": [0,5] } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : {} }', '{ "": { "$pullAll": { "scores.top": [0,5] } }}', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : {"top": [0,5,10,11]} }', '{ "": { "$pullAll": { "scores.top": [0,5] } }}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "scores" : { "top" : [ { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } (1 row) -- $pullAll operator- negative testcases SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "scores": 0 } }}', '{}'); ERROR: Parameter $pullAll needs an array input, but received a int instead SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : "a" }', '{ "": { "$pullAll": { "scores": [0] } }}', '{}'); ERROR: Unable to use $pullAll on a value that is not an array SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters.1": [1,3,4] } }}', '{}'); ERROR: Unable to use $pullAll on a value that is not an array -- rename overwrites. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2, "c": 1 } }', '{ "": { "$rename": { "a.b": "a.c" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "c" : { "$numberInt" : "2" } } } (1 row) -- update scenario tests: $setOnInsert (non-upsert) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$setOnInsert": { "a.b": 1, "c": 2, "d": 4 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "double", "v": 42.13}', '{ "": { "$setOnInsert": {"v.foo": 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "double", "v": 42.13}', '{ "": { "$setOnInsert": {"v.-1.foo": 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "array", "v": [42]}', '{ "": { "$setOnInsert": {"v.array.0": 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "array", "v": [42]}', '{ "": { "$setOnInsert": {"v.0.foo": 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- upsert: SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "_id": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2 } } }', '{ "_id": 1 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2 } } }', '{ "_id": { "$eq": 1 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "f": 3, "g": 4, "h": 5 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "3" }, "g" : { "$numberInt" : "4" }, "h" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "$and": [ { "_id": { "$eq": 1 }}, {"f": 3 }, { "g": 4 }, { "h": 5 } ] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "f" : { "$numberInt" : "3" }, "g" : { "$numberInt" : "4" }, "h" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "$or": [ { "_id": { "$eq": 1 }}, {"f": 3 }, { "g": 4 }, { "h": 5 } ] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "2" }, "h" : { "$numberInt" : "6" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "$or": [ { "g": 4 } ] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "g" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "2" }, "h" : { "$numberInt" : "6" } } (1 row) --upsert querySpec has document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 5, "_id": 1 } } }', '{"a.x.y":10}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "5" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.y": 5, "_id": 1 } } }', '{"a.x":{"c":"d"}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "c" : "d" }, "y" : { "$numberInt" : "5" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.y": 10, "_id": 1 } } }', '{"a": {"x":5}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "$numberInt" : "5" }, "y" : { "$numberInt" : "10" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"b":5}, "_id": 1 } } }', '{"a.c":8}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "5" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"x":{"z":10}}, "_id": 1} }}', '{"a":{"x":{"y":5}}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "z" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.x.z": 10, "_id": 1 } } }', '{"a":{"x":{"y":5}}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "y" : { "$numberInt" : "5" }, "z" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"x":{"z":10}}, "_id": 1 } } }', '{"a.x.y":10}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "z" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.x.z":10, "_id": 1 } } }', '{"a.x.y":10}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "x" : { "y" : { "$numberInt" : "10" }, "z" : { "$numberInt" : "10" } } } } (1 row) --upsert querySpec has array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.11":11, "_id": 1 } } }', '{"a":[0,1,2,3,4,5,6,7,8,9,10]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0":0, "a.6":6, "_id": 1 } } }', '{"a":[8,1,2,3]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, null, null, { "$numberInt" : "6" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0":1, "a.1":2, "_id": 1 } } }', '{"a":[{"x":1},{"x":2},{"x":3}]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "x" : { "$numberInt" : "3" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0.1": 5 , "_id": 1} } }', '{"a":[[1,2],[3,4]]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0.x": 10 , "_id": 1} } }', '{"a":[{"x":1},{"x":2}]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "x" : { "$numberInt" : "10" } }, { "x" : { "$numberInt" : "2" } } ] } (1 row) --upsert $rename cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "b"}, "$set":{ "_id": 1 } } }', '{"b":1}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "b": "a"}, "$set":{ "_id": 1 } } }', '{"b":1}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.b": "a.c"}, "$set":{ "_id": 1 } } }', '{"a.b":10}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "c" : { "$numberInt" : "10" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.b": "a.c"}, "$set":{ "_id": 1 } } }', '{"a":{"b":10}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "c" : { "$numberInt" : "10" } } } (1 row) --upsert querySpec with $gt, $lt, $gte, $lte SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.1":{"$gt": 100},"a.2":{"x":10}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "2" : { "x" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$lt": 100},"a.y":{"x":10}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "y" : { "x" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$gte": 100},"a.y":{"x":10}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "y" : { "x" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$lte": 100},"a.y":{"x":10}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "y" : { "x" : { "$numberInt" : "10" } } } } (1 row) -- upsert querySpec with implicit AND - valid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$in": [ 1, 2 ] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$gt": 20, "$lt": 40 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2 ], "$in": [ 1, 2 ] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2 ], "$ne": 40 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) -- upsert querySpec with implicit AND - Invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$all": [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path 'b' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$all": [ 2 ], "$in" : [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path 'b' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2, 1 ], "$in": [ 1, 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path 'b' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2, 1 ], "$in": [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path 'b' has been matched twice -- upsert querySpec with implicit AND on "_id" - valid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$in": [ 1, 2 ] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$gt": 20, "$lt": 40 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2 ], "$in": [ 1, 2 ] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2 ], "$ne": 40 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } (1 row) -- upsert querySpec with implicit AND on "_id" - Invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$all": [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$all": [ 2 ], "$in" : [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2, 1 ], "$in": [ 1, 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2, 1 ], "$in": [ 2 ] } }'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice -- cannot modify id cases SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "_id": 2 } } }', '{ "_id": 1 }'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$set": { "_id": 2 } } }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$inc": { "_id": 2 } } }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$max": { "_id": 2 } } }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' -- Multiple operators: no-op SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {}, "x": 0 }', '{ "": { "$pullAll": { "a.b": [0] }, "$unset": { "d": 1 }, "$mul": { "x": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {}, "x": 0 }', '{ "": { "$pullAll": { "a.b": [0] }, "$unset": { "d": 1 }, "$bit": { "x": { "and": 0 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- Multiple operators at least one update SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [0,0,0,0,4], "x": 0 }', '{ "": { "$pullAll": { "a": [0] }, "$unset": { "d": 1 }, "$mul": { "x": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "4" } ], "x" : { "$numberInt" : "0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [0,0,0,0,4], "x": 10 }', '{ "": { "$pullAll": { "b": [0] }, "$unset": { "a": 1 }, "$mul": { "x": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : { "$numberInt" : "100" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": [0,0,0,0,0,1,1,1,2]}, "x": 10 }', '{ "": { "$pullAll": { "a.b": [0,1] }, "$set": { "d": 1 }, "$mul": { "x": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "$numberInt" : "2" } ] }, "x" : { "$numberInt" : "10" }, "d" : { "$numberInt" : "1" } } (1 row) -- aggregation pipeline: project & unset -- -- simple case for project SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberDouble" : "2.0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "b": 0 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "x": 1, "y": [{ "z": 1, "foo": 1 }] }', '{ "": [ { "$unset": ["x", "y.z"] } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "y" : [ { "foo" : { "$numberInt" : "1" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": [ { "$unset": "copies" } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "title" : "Bees Babble", "isbn" : "999999999333", "author" : { "last" : "Bumble", "first" : "Bee" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": [ { "$unset": ["isbn", "author.first", "copies.warehouse"] } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "title" : "Bees Babble", "author" : { "last" : "Bumble" }, "copies" : [ { "qty" : { "$numberInt" : "2" } }, { "qty" : { "$numberInt" : "5" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$project": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } (1 row) -- -- project with upsert uses fields from query SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$project": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "2.0" }, "d" : { "$numberInt" : "1" }, "b" : { "$numberDouble" : "2.0" } } (1 row) -- -- project and unset (shoudl just project _id ) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$project": { "b": 1 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } (1 row) -- project and unset silently ignore removing the _id field. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "_id" }] }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "_id": 0 } } ] }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- -- simple case for addFields SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$addFields": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "c" : { "$numberDouble" : "2.0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$addFields": { "b": 0 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 10, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 30.5, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": false, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": "someString", "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$addFields": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "2.0" }, "d" : { "$numberInt" : "1" }, "b" : { "$numberDouble" : "2.0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$addFields": { "b": 1 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- -- simple case for set SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$set": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" }, "c" : { "$numberDouble" : "2.0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$set": { "b": 0 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 10, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 30.5, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": false, "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": "someString", "name": 1 } }, { "$unset": "name" } ] }', '{}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$set": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberDouble" : "2.0" }, "d" : { "$numberInt" : "1" }, "b" : { "$numberDouble" : "2.0" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$set": { "b": 1 } }] }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- simple case for replaceRoot SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_key" : "$a" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a_key" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_b_key" : "$a.b" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a_b_key" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_b_key" : "$a.b", "a_key" : "$a", "a_b_arr_key" : "$a.b.arr" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a_b_key" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } }, "a_key" : { "b" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } }, "a_b_arr_key" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": "$a.b" }}]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": {"$mergeObjects": [ { "dogs": 0, "cats": 0, "birds": 0, "fish": 0 }, "$a.b" ] } }}]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "dogs" : { "$numberInt" : "0" }, "cats" : { "$numberInt" : "0" }, "birds" : { "$numberInt" : "0" }, "fish" : { "$numberInt" : "0" }, "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } (1 row) -- simple case for replaceWith SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_key" : "$a" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "newRoot" : { "a_key" : { "$numberInt" : "1" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b" : 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_b_key" : "$a.b" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "newRoot" : { "a_b_key" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_b_key" : "$a.b", "a_key" : "$a", "a_b_arr_key" : "$a.b.arr" }} }]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "newRoot" : { "a_b_key" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } }, "a_key" : { "b" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } }, "a_b_arr_key" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": "$a.b" }}]}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "newRoot" : { "arr" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { } ], "a" : { "b" : { "$numberInt" : "1" } }, "int" : { "$numberInt" : "1" } } } (1 row) -- update: Error cases: SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 }, "$unset": { "a.b.7": 1 } } }', '{}'); ERROR: Modifying the path 'a.b.7' will result in a conflict occurring at 'a.b.7' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ { "b": 2 } ] }', '{ "": { "$rename": { "a.0": "b" } } }', '{}'); ERROR: The source field of a rename cannot be an array element SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ { "b": 2 } ] }', '{ "": { "$rename": { "a.0.b": "a.1.c" } } }', '{}'); ERROR: The source field of a rename cannot be an array element SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "c": 3, "$and": [ { "c": 4 } ] }'); ERROR: Unable to determine which query fields to set, as the path 'c' has been matched twice SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"d.e"}} }', '{}'); ERROR: Invalid array index path e SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"d.e"}} }', '{}'); ERROR: Invalid array index path e SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"d.e":"d.c"}} }', '{}'); ERROR: Invalid array index path e SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"a.0"}} }', '{}'); ERROR: The target field of a rename cannot be an array element -- $push top level input validation with all modifiers SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberInt" : "2"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type int in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong" : "2"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type long in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDouble" : "2.0"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type double in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b" : [1,2,3]}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type object in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": false}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type bool in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": NaN}', '{ "": { "$push" :{"a":"0"}} }', '{}'); ERROR: The field 'a' is required to be an array, however it is currently of type double in document { _id: 1 } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": "6" }}} }', '{}'); ERROR: Expected 'array' type for $each in $push but found 'string' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": 6 }}} }', '{}'); ERROR: Expected 'array' type for $each in $push but found 'int' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": {"a": 6} }}} }', '{}'); ERROR: Expected 'array' type for $each in $push but found 'object' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": 1.1 }}} }', '{}'); ERROR: Expected 'array' type for $slice in $push but found 'double' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": "2" }}} }', '{}'); ERROR: Expected 'array' type for $slice in $push but found 'string' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": true }}} }', '{}'); ERROR: Expected 'array' type for $slice in $push but found 'bool' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": [1,2,3] }}} }', '{}'); ERROR: Expected 'array' type for $slice in $push but found 'array' type SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 0 }}} }', '{}'); ERROR: The $sort element value must be either 1 or -1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": -2 }}} }', '{}'); ERROR: The $sort element value must be either 1 or -1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 2 }}} }', '{}'); ERROR: The $sort element value must be either 1 or -1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 1.1 }}} }', '{}'); ERROR: The $sort element value must be either 1 or -1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"a.b": -2} }}} }', '{}'); ERROR: The $sort element value must be either 1 or -1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"a.": -2} }}} }', '{}'); ERROR: The $sort field is a dotted field but has an empty part: a. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {".b.c": -2} }}} }', '{}'); ERROR: The $sort field is a dotted field but has an empty part: .b.c SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"": 1} }}} }', '{}'); ERROR: The $sort field should not be left empty SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {} }}} }', '{}'); ERROR: The $sort pattern is empty when it should be a set of fields. -- TODO: Make the error compatible with mongo: "errmsg" : "Cannot create field 'y' in element {x: [ { y: 1 } ]}" SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{"key.x.y": 1 }}}', '{}'); ERROR: Invalid array index path y SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{ "key.x": { "$each": [], "badplugin": 1} }}}', '{}'); ERROR: Unrecognized clause in $push: badplugin SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": -0.1 }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: double SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": 1.1 }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: double SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": "start" }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: string SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": false }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: bool SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": {"a.b": -2} }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: object SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": [1,2,3] }}} }', '{}'); ERROR: The value for $position must be an integer value, not of type: array -- $push valid cases when modifiers are not persent SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" : {"a": 6} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" : {"a": {"another": 6}} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "another" : { "$numberInt" : "6" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": false} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, false ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": [5,6,7]} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": 1.21} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberDouble" : "1.2099999999999999645" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": 1, "scores": [44,78,38,80], "a": {"scores": [1,2]}}', '{ "": { "$push" : {"scores": 1, "a.scores": 10} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "scores" : [ { "$numberInt" : "44" }, { "$numberInt" : "78" }, { "$numberInt" : "38" }, { "$numberInt" : "80" }, { "$numberInt" : "1" } ], "a" : { "scores" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "10" } ] } } (1 row) -- $push with $each modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": { "$each" : [1,2,"3", {"four": 4}] }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, "3", { "four" : { "$numberInt" : "4" } } ] } (1 row) -- $push with array indices as dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a.3": 4 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, [ { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a.7": 7 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, null, null, null, null, [ { "$numberInt" : "7" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$push" : {"a.0.5": 7 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, null, null, null, null, [ { "$numberInt" : "7" } ] ], [ { "$numberInt" : "2" } ], [ { "$numberInt" : "3" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$push" : {"a.0.5": { "$each": [10,9,8], "$sort" : 1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, null, null, null, null, [ { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ], [ { "$numberInt" : "2" } ], [ { "$numberInt" : "3" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],3]}', '{ "": { "$push" : {"a.2.5": 7 } } }', '{}'); ERROR: Failed to create the field '2' within the element specified by {2 : 3} -- $push with $each & $slice modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": 5 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": -6 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": 20 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": -11 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) -- $push with $each & $position modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": 20 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "-1" }, { "$numberInt" : "0" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": -20 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "-1" }, { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": 6 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "-1" }, { "$numberInt" : "0" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": -8 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "-1" }, { "$numberInt" : "0" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) -- $push with $sort modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": { "$each" : [1,2,"3", {"four": 4}, false, [3,1,2]], "$sort": -1 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ false, [ { "$numberInt" : "3" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ], { "four" : { "$numberInt" : "4" } }, "3", { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "2" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"wk": 1, "scores": 85}, {"wk": 3, "scores": 30}, {"wk": 2, "scores": 75}, {"wk": 5, "scores": 99}]}', '{ "": { "$push" : {"a": { "$each" : [{"wk": 2, "scores": 70}], "$sort": 1 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "wk" : { "$numberInt" : "1" }, "scores" : { "$numberInt" : "85" } }, { "wk" : { "$numberInt" : "2" }, "scores" : { "$numberInt" : "70" } }, { "wk" : { "$numberInt" : "2" }, "scores" : { "$numberInt" : "75" } }, { "wk" : { "$numberInt" : "3" }, "scores" : { "$numberInt" : "30" } }, { "wk" : { "$numberInt" : "5" }, "scores" : { "$numberInt" : "99" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"wk": 1, "scores": 85}, {"wk": 3, "scores": 30}, {"wk": 2, "scores": 75}, {"wk": 5, "scores": 99}]}', '{ "": { "$push" : {"a": { "$each" : [{"wk": 2, "scores": 70}], "$sort": { "scores" : -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "wk" : { "$numberInt" : "5" }, "scores" : { "$numberInt" : "99" } }, { "wk" : { "$numberInt" : "1" }, "scores" : { "$numberInt" : "85" } }, { "wk" : { "$numberInt" : "2" }, "scores" : { "$numberInt" : "75" } }, { "wk" : { "$numberInt" : "2" }, "scores" : { "$numberInt" : "70" } }, { "wk" : { "$numberInt" : "3" }, "scores" : { "$numberInt" : "30" } } ] } (1 row) -- Sort spec dotted path contains intermediate array, sort spec path not found so same sort order SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.c" : 1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "5" } } ] }, { "b" : [ { "c" : { "$numberInt" : "10" } } ] }, { "b" : [ { "c" : { "$numberInt" : "3" } } ] }, { "b" : [ { "c" : { "$numberInt" : "2" } } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.c" : -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "5" } } ] }, { "b" : [ { "c" : { "$numberInt" : "10" } } ] }, { "b" : [ { "c" : { "$numberInt" : "3" } } ] }, { "b" : [ { "c" : { "$numberInt" : "2" } } ] } ] } (1 row) -- Sort spec dotted path doesn't exist, same sort order SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "c" : -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "5" } } ] }, { "b" : [ { "c" : { "$numberInt" : "10" } } ] }, { "b" : [ { "c" : { "$numberInt" : "3" } } ] }, { "b" : [ { "c" : { "$numberInt" : "2" } } ] } ] } (1 row) -- Sort spec with array and valid index element SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.0" : -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "b" : [ { "c" : { "$numberInt" : "10" } } ] }, { "b" : [ { "c" : { "$numberInt" : "5" } } ] }, { "b" : [ { "c" : { "$numberInt" : "3" } } ] }, { "b" : [ { "c" : { "$numberInt" : "2" } } ] } ] } (1 row) -- Multiple Sort spec with existing or non exisiting paths SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1, "b": -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "5" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "10" } }, { "a" : { "$numberInt" : "8" }, "b" : { "$numberInt" : "3" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1, "b": -1, "c": 1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "5" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "10" } }, { "a" : { "$numberInt" : "8" }, "b" : { "$numberInt" : "3" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "d" : 1, "e": -1, "f": 1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "10" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } }, { "a" : { "$numberInt" : "8" }, "b" : { "$numberInt" : "3" } }, { "a" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "1" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "5" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "1" } } ] } (1 row) -- Sort spec with only some elements having sort path, other elements treat missing path as NULL SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": 1}, {"a": 10, "b": 0}, {"b": 5}, {"b": 3}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "5" } }, { "b" : { "$numberInt" : "3" } }, { "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "0" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": 1}, {"a": 10, "b": 0}, {"b": 5}, {"b": 3}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : -1 } }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : { "$numberInt" : "1" }, "a" : [ { "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "0" } }, { "b" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "5" } }, { "b" : { "$numberInt" : "3" } } ] } (1 row) -- $push with combinations of other modifiers e.g $slice, $sort SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [{"a": 1, "b": 10}, {"a": 2, "b": 8}, {"a": 3, "b": 5}, {"a": 4, "b": 6}]}', '{ "": { "$push" : {"arr": { "$each" : [{"a": 5, "b": 8}, {"a": 6, "b": 7}, {"a": 7, "b": 6}], "$sort": { "b" : -1 }, "$slice": 3 }} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "arr" : [ { "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "10" } }, { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "8" } }, { "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "8" } } ] } (1 row) -- $push & modifiers with dotted paths SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": {"c": [1,2,3,4,5,6,7,8,9,10]}}}', '{"" : {"$push": {"a.b.c": 11}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" }, { "$numberInt" : "11" } ] } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": {"c": [1,2,3,4,5,6,7,8,9,10]}}}', '{"" : {"$push": {"a.b.c": {"$each": [11,12], "$slice": -6, "$sort": -1, "$position": 4}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : [ { "$numberInt" : "6" }, { "$numberInt" : "5" }, { "$numberInt" : "4" }, { "$numberInt" : "3" }, { "$numberInt" : "2" }, { "$numberInt" : "1" } ] } } } (1 row) -- $push with absent fields SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.c": {"x": [{"z": 1}]}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "scores" : { "a" : { "b" : [ { "$numberInt" : "1" } ], "c" : [ { "x" : [ { "z" : { "$numberInt" : "1" } } ] } ] } }, "key" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.c": {"$each": [5,4,3,2,1], "$slice": 3, "$sort": 1}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "scores" : { "a" : { "b" : [ { "$numberInt" : "1" } ], "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } }, "key" : { "$numberInt" : "1" } } (1 row) -- $push with key having dots SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.b": {"x": [{"z.a": 1}]}}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "scores" : { "a" : { "b" : [ { "$numberInt" : "1" }, { "x" : [ { "z.a" : { "$numberInt" : "1" } } ] } ] } }, "key" : { "$numberInt" : "1" } } (1 row) -- $push with NaN and Infinity values SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "100"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "2"}, {"$numberDecimal": "NaN"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : 1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""$numberDouble"" : ""NaN"" }, { ""$numberDecimal"" : ""NaN"" }, { ""$numberDecimal"" : ""2"" }, { ""$numberDecimal"" : ""23"" }, { ""$numberDecimal"" : ""100"" } ] }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "Infinity"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "332"}, {"$numberDecimal": "NaN"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : -1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""$numberDecimal"" : ""Infinity"" }, { ""$numberDecimal"" : ""332"" }, { ""$numberDecimal"" : ""23"" }, { ""$numberDouble"" : ""NaN"" }, { ""$numberDecimal"" : ""NaN"" } ] }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "NaN"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "Infinity"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : 1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""$numberDecimal"" : ""NaN"" }, { ""$numberDouble"" : ""NaN"" }, { ""$numberDecimal"" : ""23"" }, { ""$numberDecimal"" : ""Infinity"" } ] }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "NaN"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "Infinity"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : -1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""$numberDecimal"" : ""Infinity"" }, { ""$numberDecimal"" : ""23"" }, { ""$numberDecimal"" : ""NaN"" }, { ""$numberDouble"" : ""NaN"" } ] }",) (1 row) -- $push without $each but with other modifiers works on mongo5.0, $ is now supported in key names. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{ "key.x": { "$eachh": [], "$position": 1, "$sort" : 1} }}}', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""key"" : { ""x"" : [ { ""y"" : [ { ""$numberInt"" : ""1"" } ] }, { ""y"" : [ { ""$numberInt"" : ""2"" } ] }, { ""$eachh"" : [ ], ""$position"" : { ""$numberInt"" : ""1"" }, ""$sort"" : { ""$numberInt"" : ""1"" } } ] } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$position": 5, "$slice": 3, "$sort": -1 }}} }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""$numberInt"" : ""1"" }, { ""$numberInt"" : ""2"" }, { ""$numberInt"" : ""3"" }, { ""$numberInt"" : ""4"" }, { ""$numberInt"" : ""5"" }, { ""$position"" : { ""$numberInt"" : ""5"" }, ""$slice"" : { ""$numberInt"" : ""3"" }, ""$sort"" : { ""$numberInt"" : ""-1"" } } ] }",) (1 row) -- test conflicting update operator paths SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": 1 } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b": 1 } } }', '{}'); ERROR: Modifying the path 'a.b' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a": 1 } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b": 1 } } }', '{}'); ERROR: Modifying the path 'a.b' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b.c": 1 } } }', '{}'); ERROR: Modifying the path 'a.b.c' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b.c.d.e": 1 } } }', '{}'); ERROR: Modifying the path 'a.b.c.d.e' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c.d.e": 1 } } }', '{}'); ERROR: Modifying the path 'a.b.c.d.e' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c": 1} } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b": 1} } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": 1} } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.k.d": 1} } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d.e": 1} } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e": 1 } } } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e.f": 1 } } } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "k.f": 1 } } } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "f.k": 1 } } } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e.f": {"g": 1} } } } } }', '{}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c.d": { "e": 1 } } } }', '{}'); ERROR: Modifying the path 'a.b.c.d' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c": { "d.e": 1 } } } }', '{}'); ERROR: Modifying the path 'a.b.c' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b": { "c.d.e": 1 } } } }', '{}'); ERROR: Modifying the path 'a.b' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$unset": {"a.b": 1 } } }', '{}'); ERROR: Modifying the path 'a.b' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$unset": {"a.b.c.d.e.f": 1 } } }', '{}'); ERROR: Modifying the path 'a.b.c.d.e.f' will result in a conflict occurring at 'a.b.c.d.e' SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$inc": {"a.b": 1 } } }', '{}'); ERROR: Modifying the path 'a.b' will result in a conflict occurring at 'a.b' -- update scenario tests: $currentDate -- -- Function that extracts date / timestamp value of a given key in a json obj, and returns the equivalent epoch in ms CREATE OR REPLACE FUNCTION get_epochms_from_key(obj json, qkey text, is_date bool) RETURNS bigint AS $$ DECLARE k text; qarr text[]; epoch_seconds bigint; nanoseconds_in_second bigint; epoch_milliseconds bigint; tmp bool; BEGIN SELECT string_to_array(qkey, '.') into qarr; -- convert the nested keys in keys array (e.g. "a.b.c" to [a,b,c] ) FOREACH k IN ARRAY qarr LOOP IF obj->k IS NULL THEN RETURN 0; END IF; SELECT obj->k into obj; END LOOP; IF is_date THEN IF (obj->'$date' IS NULL) OR (obj->'$date'->'$numberLong' IS NULL) THEN RETURN 0; END IF; SELECT obj->'$date'->>'$numberLong' into epoch_milliseconds; ELSE IF (obj->'$timestamp' IS NULL) OR (obj ->'$timestamp'->'t' IS NULL) OR (obj->'$timestamp'->'i' IS NULL) THEN RETURN 0; END IF; SELECT obj->'$timestamp'->>'t' into epoch_seconds; SELECT obj->'$timestamp'->>'i' into nanoseconds_in_second; epoch_milliseconds := (epoch_seconds * 1000) + ROUND(nanoseconds_in_second::float8 / (1000 * 1000)); END IF; RETURN epoch_milliseconds; END $$ LANGUAGE plpgsql; -- -- Function to test that on updating a doc with $currentDate, the date/timestamp value lies between the timestamp values of just before & after calling the update api CREATE OR REPLACE FUNCTION test_update_currentDate(doc bson, updateSpec bson, querySpec bson, qDates text[] DEFAULT '{}'::text[], qTimestamps text[] DEFAULT '{}'::text[]) RETURNS text AS $$ DECLARE obj json; bgn_epoch numeric; end_epoch numeric; qKey text; epoch_msec bigint; bgn_epoch_msec bigint; end_epoch_msec bigint; BEGIN SELECT extract(epoch from clock_timestamp()) into bgn_epoch; -- get time just before the $currentDate execution. (e.g 1709721220.205436) SELECT newDocument FROM documentdb_api_internal.bson_update_document(doc, updateSpec, querySpec) into obj; SELECT extract(epoch from clock_timestamp()) into end_epoch; -- get time just after the $currentDate execution. -- convert the epoch to milliseconds (e.g. 1709721220.205436 -> 1709721220205) -- Also adjust begin and end epochs by 1 ms to eliminate any rounding error and reduce flakyness. bgn_epoch_msec := FLOOR(bgn_epoch * 1000) - 1; end_epoch_msec := CEIL(end_epoch * 1000) + 1; IF array_length(qDates, 1) != 0 THEN FOREACH qKey IN ARRAY qDates LOOP SELECT get_epochms_from_key(obj, qKey, true) into epoch_msec; IF epoch_msec NOT BETWEEN bgn_epoch_msec AND end_epoch_msec THEN RETURN 'TEST FAILED : Updated date "' || qkey || '" : ' || epoch_msec || ' should be between ' || bgn_epoch_msec || ' and ' || end_epoch_msec; END IF; END LOOP; END IF; IF array_length(qTimestamps, 1) != 0 THEN FOREACH qKey IN ARRAY qTimestamps LOOP SELECT get_epochms_from_key(obj, qKey, false) into epoch_msec; IF epoch_msec NOT BETWEEN bgn_epoch_msec AND end_epoch_msec THEN RETURN 'TEST FAILED : Updated timestamp "' || qkey || '" : ' || epoch_msec || ' should be between ' || bgn_epoch_msec || ' and ' || end_epoch_msec; END IF; END LOOP; END IF; RETURN 'TEST PASSED'; END; $$ LANGUAGE plpgsql; -- -- tests to update existing field to current timestamp using { "$type" : "timestamp" } SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) -- -- tests to update existing field to current date using { true } SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) -- -- tests to update existing field to current date using { false } SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) -- -- tests to update existing field to current date using { "$$type" : "date" } -- -- Note: Due to a bug in libbson, parsing of { "$type" : "date" } fails. So temporarily the $currentDate impl also supports {"$$type" : "date" } -- -- Once the bug is fixed, these tests need to be updated from "$$type" to "$type" SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) -- -- tests to update existing field to timestamp, and add new fields with current date / timestamp SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : { "$type" : "timestamp"} } } } ', '{}', ARRAY[]::text[], ARRAY['a','b.c']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : { "$$type" : "date"} } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : true } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : false } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); test_update_currentdate --------------------------------------------------------------------- TEST PASSED (1 row) -- -- these tests should give error messages SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberInt" : "1"} } } }', '{}'); ERROR: int is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberLong" : "1"} } } }', '{}'); ERROR: long is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberDouble" : "1.0"} } } }', '{}'); ERROR: double is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": "Hello" } } }', '{}'); ERROR: string is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": NaN } } }', '{}'); ERROR: double is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$type" : "Hello" } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : true } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : 2 } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberInt" : "1"} } } }', '{}'); ERROR: int is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberLong" : "1"} } } }', '{}'); ERROR: long is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberDouble" : "1.0"} } } }', '{}'); ERROR: double is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": "Hello" } } }', '{}'); ERROR: string is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": NaN } } }', '{}'); ERROR: double is not valid type for $currentDate. Please use a boolean ('true') or a $type expression ({$type: 'timestamp/date'}) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "Hello" } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : true } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : 2 } } } }', '{}'); ERROR: The '$type' string field is required to be 'date' or 'timestamp': {$currentDate: {field : {$type: 'date'}}} -- -- Note : This test intenionally provides { "$type" : "date" } instead of { "$$type" : "date" } -- -- The API call returns Error due to a Bug in libbson library that fails to parse { "$type" : "date" } -- -- If this test starts failing (i.e. api call does't return error), it may mean that the libbson bug has been fixed. -- -- In that case $currentDate implementation needs a fix as well (i.e. remove support for "$$type" since "$type" will work OK) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "date" } } } }', '{}'); ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Missing "$binary" after "$type" reading type "binary"' LINE 1: ... "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "... ^ -- --Empty UpdateSpec check SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "": 11} } }', '{}'); ERROR: The update path cannot be empty and is therefore invalid SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.": 11} } }', '{}'); ERROR: Empty field name detected at path 'a.' -- update scenario tests: $pop -- -- $pop from begin of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1]}', '{ "": { "$pop" :{"a": -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" :{"a": -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [1,2,3,4,5] }} }', '{ "": { "$pop" :{"a.b.c": -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": -1, "b": -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": -1, "b": -1, "c" : -1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : [ { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" } ] } (1 row) -- -- $pop from end of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [5]}', '{ "": { "$pop" :{"a": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" :{"a": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [1,2,3,4,5] }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : { "c" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": 1, "b": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": 1, "b": 1, "c" : 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) -- -- $pop from begin and end of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9]}', '{ "": { "$pop" :{"a": -1, "b": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9]}', '{ "": { "$pop" :{"z": 1, "a": -1, "b": 1}} }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) -- For below test, the spec parsing func (ParseDotPathAndGetTreeNode) throws error, but mongoDB 5.0 doesn't. TODO : Fix ParseDotPathAndGetTreeNode -- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": -1, "a": 1}} }', '{}'); -- -- Empty $pop document. Should not pop anything SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {}} }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" : {}} }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- -- Error Cases : $pop on Non-Array Fields SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberInt" : "2"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'int' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberLong" : "2"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'long' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberDouble" : "2.0"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'double' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'string' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : false }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'bool' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : NaN }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); ERROR: The specified path 'a.b.c' within $pop includes an element that is not of an array data type 'double' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1, "a.b.d": -1 }} }', '{}'); ERROR: The specified path 'a.b.d' within $pop includes an element that is not of an array data type 'string' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a" : {"b" : { "c": 1 , "d": -1} }} } }', '{}'); ERROR: Expected numeric value in: a: { "b" : { "c" : 1, "d" : -1 } } -- -- Error Cases : $pop's key's value is neither -1 nor 1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": "Hello"}} }', '{}'); ERROR: Expected numeric value in: a: "Hello" SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": true}} }', '{}'); ERROR: Expected numeric value in: a: true SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": NaN}} }', '{}'); ERROR: Expected numeric value: a: NaN SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": []}} }', '{}'); ERROR: Expected numeric value in: a: [ ] SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {}}} }', '{}'); ERROR: Expected numeric value in: a: { } SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {"$numberInt" : "2"}}} }', '{}'); ERROR: $pop operator requires either 1 or -1, but received: 2 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {"$numberDouble" : "-1.5"}}} }', '{}'); ERROR: Expected numeric value: a: -1.5 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8]}} }', '{ "": { "$pop" : {"a.b.c": 2 }} }', '{}'); ERROR: $pop operator requires either 1 or -1, but received: 2 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 25, "a.b.d": -1 }} }', '{}'); ERROR: $pop operator requires either 1 or -1, but received: 25 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1, "a.b.d": -25 }} }', '{}'); ERROR: $pop operator requires either 1 or -1, but received: -25 -- -- Error Cases : $pop is not a document SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : []} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type array. Expected format: {$mod: {: ...}}, but received: {$pop: [ ]}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : [{"a" : 1}]} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type array. Expected format: {$mod: {: ...}}, but received: {$pop: [ { "a" : 1 } ]}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : "Hello"} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type string. Expected format: {$mod: {: ...}}, but received: {$pop: "Hello"}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : false} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type bool. Expected format: {$mod: {: ...}}, but received: {$pop: false}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : NaN} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type double. Expected format: {$mod: {: ...}}, but received: {$pop: NaN}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberInt" : "1"}} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type int. Expected format: {$mod: {: ...}}, but received: {$pop: 1}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberLong" : "-1"}} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type long. Expected format: {$mod: {: ...}}, but received: {$pop: -1}. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberDouble" : "2.5"}} }', '{}'); ERROR: Modifiers work only with fields, but the provided value is of type double. Expected format: {$mod: {: ...}}, but received: {$pop: 2.5}. -- --Update the Field with Periods (.) and Dollar Signs ($) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$b": 2 } }', '{ "": { "$inc": { "a.$b": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$b" : { "$numberInt" : "4" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "b": 2 } }', '{ "": { "$inc": { "$a.c": 2 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "$b": { "c" : 2 } } }', '{ "": { "$inc": { "$a.$b.c": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "$b" : { "c" : { "$numberInt" : "3" } } } } (1 row) -- --Negative scenarios for field names with Dollar Signs ($) SELECT documentdb_api_internal.bson_update_document('{"_id" : 1}', '{ "": { "$set": { "$a": 2 } } }', '{}'); ERROR: The dollar ($) prefixed field '$a' in '$a' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith. SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id" : 1, "$set": { "$a": 2 } } }', '{}'); ERROR: Field '$set' in path '$set' is not allowed when doing a replace operation. Use $replaceWith aggregation stage instead SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "a" : 1 }', '{ "": { "_id" : 1, "$b" : 2} }', '{}'); ERROR: Field '$b' in path '$b' is not allowed when doing a replace operation. Use $replaceWith aggregation stage instead SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "$b": { "c" : 2 } } }', '{ "": { "$set": { "$a": { "$b" : { "$d": 1 } } } } } ', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""$a"" : { ""$b"" : { ""$d"" : { ""$numberInt"" : ""1"" } } } }",) (1 row) -- more scenarios for update field names with $ signs -- $ paths not allowed when it's not an upsert SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": "1" }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); ERROR: The dollar ($) prefixed field '$secret' in '$secret.agent.x' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$secret": { "agent": 1 } }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); ERROR: Failed to create the field 'agent' within the element specified by {agent : 1} SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$secret": { "agent": { "y": 1 } } }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""$secret"" : { ""agent"" : { ""y"" : { ""$numberInt"" : ""1"" }, ""x"" : { ""$numberInt"" : ""1"" } } } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{ "_id": 5 }', '{ "": { "$set": { "$inc": 5 } } }', '{}'); ERROR: The dollar ($) prefixed field '$inc' in '$inc' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith. -- allowed on upsert. SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1, "_id": 6 } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""6"" }, ""$secret"" : { ""agent"" : { ""x"" : { ""$numberInt"" : ""1"" } } } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{"_id": 2 }'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""2"" }, ""$secret"" : { ""agent"" : { ""x"" : { ""$numberInt"" : ""1"" } } } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{"a": 3, "_id": 4 }'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""4"" }, ""a"" : { ""$numberInt"" : ""3"" }, ""$secret"" : { ""agent"" : { ""x"" : { ""$numberInt"" : ""1"" } } } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$inc": 5 } } }', '{"_id": 5 }'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""5"" }, ""$inc"" : { ""$numberInt"" : ""5"" } }",) (1 row) -- $pull invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": "text"}', '{ "": { "$pull": { "a": 1 } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{ "": { "$pull": { "a": 1 } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": true}', '{ "": { "$pull": { "a": 1 } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDecimal": "1.23"}}', '{ "": { "$pull": { "a": 1 } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": 2}}', '{ "": { "$pull": { "a": 1 } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a.0": {"b": 2, "c":2} } } }', '{}'); ERROR: $pull cannot be used on values that are not arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": [1], "c": [1]}, {"b": [2], "c": [2]}, {"b": [3], "c": [3]}]}', '{ "": { "$pull": { "a.b": 1 } } }', '{}'); ERROR: Invalid array index path b SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$lte": 2, "b": 2} } } }', '{}'); ERROR: Unrecognized operator specified: b SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"b": 2, "$lte": 2} } } }', '{}'); ERROR: unknown top level operator: $lte. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. -- valid $pull without expressions in arrays and array of arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a": {"b": 2, "c":2} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2,3,4,5], [6,7,8,9,10]]}', '{ "": { "$pull": { "a.0": 4 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "5" } ], [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}], [{"b": 4, "c": 4}, {"b": 5, "c": 5}, {"b": 6, "c": 6}]]}', '{ "": { "$pull": { "a.1": {"b": 4, "c": 4} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" } }, { "b" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "2" } }, { "b" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "3" } } ], [ { "b" : { "$numberInt" : "5" }, "c" : { "$numberInt" : "5" } }, { "b" : { "$numberInt" : "6" }, "c" : { "$numberInt" : "6" } } ] ] } (1 row) -- valid $pull with expressions in arrays and array of arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$gte": 2, "$lte": 5} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": {"$gte": 5} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" } ], [ { "$numberInt" : "2" } ], [ { "$numberInt" : "3" } ], [ { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$gte": 5, "$ne": 8} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "8" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$in": [3,6,9]} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$nin": [3,6,9]} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "6" }, { "$numberInt" : "9" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": { "$not": {"$gt": 5 } } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" }, { "$numberInt" : "9" }, { "$numberInt" : "10" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"fruits":[ "apples", "pears", "oranges", "grapes", "bananas" ],"vegetables":[ "carrots", "celery", "squash", "carrots" ]}', '{"":{"$pull":{"fruits":{"$in":["apples","oranges"]},"vegetables":"carrots"}}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "fruits" : [ "pears", "grapes", "bananas" ], "vegetables" : [ "celery", "squash" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":2,"fruits":[ "plums", "kiwis", "oranges", "bananas", "apples" ],"vegetables":[ "broccoli", "zucchini", "carrots", "onions" ]}', '{"":{"$pull":{"fruits":{"$in":["apples","oranges"]},"vegetables":"carrots"}}}', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "fruits" : [ "plums", "kiwis", "bananas" ], "vegetables" : [ "broccoli", "zucchini", "onions" ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "item": "A", "score": 5 }, { "item": "B", "score": 8 }, { "item": "C", "score": 8 }, { "item": "B", "score": 4 }]}', '{ "": { "$pull": { "a": { "score": 8 , "item": "B" } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "item" : "A", "score" : { "$numberInt" : "5" } }, { "item" : "C", "score" : { "$numberInt" : "8" } }, { "item" : "B", "score" : { "$numberInt" : "4" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "results": [{ "item": "A", "score": 5, "answers": [ { "q": 1, "a": 4 }, { "q": 2, "a": 6 } ] }, { "item": "B", "score": 8, "answers": [ { "q": 1, "a": 8 }, { "q": 2, "a": 9 } ]}, { "item": "C", "score": 8, "answers": [ { "q": 1, "a": 8 }, { "q": 2, "a": 7 } ] }, { "item": "B", "score": 4, "answers": [ { "q": 1, "a": 0 }, { "q": 2, "a": 8 } ] }]}', '{ "": { "$pull": { "results": { "answers": {"$elemMatch": { "q": 2, "a": { "$gte": 8 } } } } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "results" : [ { "item" : "A", "score" : { "$numberInt" : "5" }, "answers" : [ { "q" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "4" } }, { "q" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "6" } } ] }, { "item" : "C", "score" : { "$numberInt" : "8" }, "answers" : [ { "q" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "8" } }, { "q" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "7" } } ] } ] } (1 row) -- First level of nested array is supported in native mongo only when pull spec value is expression SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": {"$gte": 5} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" } ], [ { "$numberInt" : "2" } ], [ { "$numberInt" : "3" } ], [ { "$numberInt" : "4" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[{"a": 1, "b" : 1}], [{"a": 2, "b": 2}], [{"a": 3, "b": 3}]]}', '{ "": { "$pull": { "arr": {"$eq": {"a": 1, "b": 1} } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "arr" : [ [ { "a" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "2" } } ], [ { "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "3" } } ] ] } (1 row) -- First level of nested array is not recursed if $pull spec value is plain value SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": 5 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[{"a": 1, "b" : 1}], [{"a": 2, "b": 2}], [{"a": 3, "b": 3}]]}', '{ "": { "$pull": { "arr": {"a": 1, "b": 1} } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- Second and more are not supported SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[[1,2]], [[3,4]]]}', '{ "": { "$pull": { "a": {"$gte": 3} } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- $pull no ops for no match SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a": {"b": 2, "c":3} } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "c": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$gt": 5} } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "item": "A", "score": 5 }, { "item": "B", "score": 8 }, { "item": "C", "score": 8 }, { "item": "B", "score": 4 }]}', '{ "": { "$pull": { "a": { "$elemMatch": { "score": 8 , "item": "B" } } } } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) -- validate _id SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": {"$b": 2, "c":3} } } }', '{}'); ERROR: _id fields may not contain '$'-prefixed fields: $b is not valid for storage. -- replaceRoot/replaceWith with dotted paths. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$replaceWith": { "_id": 1, "a.b.c": 3 } } ] }', '{}'); ERROR: FieldPath field names may not contain '.'. Consider using $getField or $setField --upsert when querySpec has $all SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }', '{"_id": 10, "x": { "$all" : {}}}'); ERROR: $all needs an array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }', '{"_id": 11, "x": { "$all" : [1]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "11" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":12}}}','{"x": { "$all" : [2]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "12" }, "x" : { "$numberInt" : "2" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":13}}}' ,'{"x": { "$all" : [[3]]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "13" }, "x" : [ { "$numberInt" : "3" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":14}}}','{"x": { "$all" : [{"x":11}]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "14" }, "x" : { "x" : { "$numberInt" : "11" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":15}}}','{"_id": { "$all" : [15]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "15" }, "x" : { "$numberInt" : "15" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":16}}}','{"_id": { "$all" : [{"x": 16}]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "x" : { "$numberInt" : "16" } }, "x" : { "$numberInt" : "16" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":17}}}','{"_id": { "$all" : [[13]]}}'); ERROR: The '_id' field value must not be a type of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":18}}}','{"x": { "$all" : [1,2,3]}}'); ERROR: Unable to determine which query fields to set, as the path 'x' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":19}}}','{"_id": { "$all" : [15,16,17]}}'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {}}','{"_id": { "$all" : [[15]]}}'); ERROR: Cannot modify '_id' field to an array or array descendent as part of the operation. --upsert when querySpec has $in SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": 21, "x": { "$in" : {}}}'); ERROR: Expected 'array' type for $in but found 'object' type SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": 22, "x": { "$in" : [1]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "22" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":23}}}','{"x": { "$in" : [3423]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "23" }, "x" : { "$numberInt" : "3423" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":24}}}','{"x": { "$in" : [[2]]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "24" }, "x" : [ { "$numberInt" : "2" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":25}}}','{"x": { "$in" : [{"y":2}]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "x" : { "y" : { "$numberInt" : "2" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":26}}}','{"x": { "$in" : [10,20,30]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "26" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":27}}}','{"_id": { "$in" : [25]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "25" }, "x" : { "$numberInt" : "27" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":28}}}','{"_id": { "$in" : [{"y":26}]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "y" : { "$numberInt" : "26" } }, "x" : { "$numberInt" : "28" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":29}}}','{"_id": { "$in" : [[26]]}}'); ERROR: The '_id' field value must not be a type of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":30}}}','{"_id": { "$in" : [27]}}'); ERROR: Updating the path '_id' is not allowed because it would change the immutable field '_id' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":31}}}','{"_id": { "$in" : [27,28,29]}}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "31" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": { "$in" : [[27]]}}'); ERROR: Cannot modify '_id' field to an array or array descendent as part of the operation. SELECT bson_dollar_project(newDocument, '{ "_id": 0 }') as newDocument from documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"y":31}}}','{"_id": { "$in" : [27,28,29]}}'); newdocument --------------------------------------------------------------------- { "y" : { "$numberInt" : "31" } } (1 row) -- $nor operator in query spec SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"_id": 1, "b": 3} }', '{"$nor": [ { "_id": { "$eq" : 2}}]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "3" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"_id": 1, "b": 3} }', '{"$nor": [ { "a": { "$eq" : 2}}]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "3" } } (1 row) --miscellaneous tests with multiple fields in queySpec SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"$and": [{"_id": 1}, {"_id": 1}]}'); ERROR: Unable to determine which query fields to set, as the path '_id' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"_id.x": 1 , "_id.y": 2}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "x" : { "$numberInt" : "1" }, "y" : { "$numberInt" : "2" } }, "a" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"$and": [{"x": 1}, {"x": 1}]}'); ERROR: Unable to determine which query fields to set, as the path 'x' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"x": 1, "x.x": 1}'); ERROR: Unable to determine which query fields to set, as the path 'x.x' has been matched twice SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"x.x": 1, "x": 1}'); ERROR: Unable to determine which query fields to set, as the path 'x' has been matched twice -- show that we never crash due to passing one of the arguments as NULL SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', null); ERROR: sourceDocument / updateSpec / querySpec cannot be NULL SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', null, '{"b": 1}'); ERROR: sourceDocument / updateSpec / querySpec cannot be NULL SELECT documentdb_api_internal.bson_update_document(null, '{"": {"a": 1}}', '{"c": 1}'); ERROR: sourceDocument / updateSpec / querySpec cannot be NULL SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', '{"b": 1}', null, true); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""2"" } }",) (1 row) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', '{"b": 1}', '{"a": 1}', true); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""2"" } }",) (1 row) -- $rename Negative/No-Op cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.": "b"} } }', '{}'); ERROR: Empty field name detected at path 'a.' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "$.": "b"} } }', '{}'); ERROR: Empty field name detected at path '$.' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "$[].0": "b"} } }', '{}'); ERROR: Array filter identifier usage (e.g., '$[]') is not permitted at the starting position of the specified path '$[].0' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "b."} } }', '{}'); ERROR: Empty field name detected at path 'b.' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "$"} } }', '{}'); ERROR: Positional element (i.e. '$') cannot appear at the beginning of the path '$'. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "$[]"} } }', '{}'); ERROR: Array filter identifier usage (e.g., '$[]') is not permitted at the starting position of the specified path '$[]' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "a": "f.g"} } }', '{}'); ERROR: Failed to create the field 'f' within the element specified by {f : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "f.g": "a"} } }', '{}'); ERROR: Failed to create the field 'f' within the element specified by {f : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "f": 1}', '{ "": { "$rename": { "x": "f.g"} } }', '{}'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a" : 1, "f" : 1, "b" : { "c" : { "d" : 1 } }}', '{ "": { "$rename": { "b.c.d.f": "t.k"} } }', '{}'); ERROR: Failed to create the field 'd' within the element specified by {d : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"key": 1,"key2": 2,"f": {"g": 1, "h": 1},"j": 1,"k": 1}', '{ "": { "$rename": { "f.g": "k.m","f.h":"j.m"} } }', '{}'); ERROR: Failed to create the field 'j' within the element specified by {j : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"key": 1,"key2": 2,"f": {"g": 1, "h": 1},"j": {},"k": 1}', '{ "": { "$rename": { "f.g": "k.m","f.h":"j.m"} } }', '{}'); ERROR: Failed to create the field 'k' within the element specified by {k : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "f.g": "a"}, "$setOnInsert": { "b": "f.g" } } }', '{}'); -- $rename with $setOnInsert ERROR: Failed to create the field 'f' within the element specified by {f : 1} SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$setOnInsert": { "f.g": "a" }, "$rename": { "f.g": "a"} } }', '{}'); ERROR: Failed to create the field 'f' within the element specified by {f : 1} --$rename working complex cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": 1,"key2": 2,"f": {"g": 1, "h": 1},"h":1}', '{ "": { "$rename": { "key": "f.g"} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "2" }, "f" : { "g" : { "$numberInt" : "1" }, "h" : { "$numberInt" : "1" } }, "h" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "key": 2,"x": {"y": 1, "z": 2}}', '{ "": { "$rename": { "key": "newName","x.y":"z","x.z":"k"} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "x" : { }, "newName" : { "$numberInt" : "2" }, "z" : { "$numberInt" : "1" }, "k" : { "$numberInt" : "2" } } (1 row) bson_update_positional_all.out000066400000000000000000000741061507310017400361300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2300000; SET documentdb.next_collection_id TO 23000; SET documentdb.next_collection_index_id TO 23000; --Test Set1 : array of document Tests SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, { "c" : 5, "d" : 6 } ], "H" : { "c" : 10 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "c" : { "$numberInt" : "11" }, "d" : { "$numberInt" : "2" } }, { "c" : { "$numberInt" : "11" }, "d" : { "$numberInt" : "6" } } ], "H" : { "c" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"c":5}] }', '{ "": { "$set": { "a.$[].c": 30 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "c" : { "$numberInt" : "30" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "y": [1,2,3,4] } ] }}','{ "": { "$inc": { "a.b.0.x.$[]": 100 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "x" : [ { "$numberInt" : "101" }, { "$numberInt" : "102" }, { "$numberInt" : "103" }, { "$numberInt" : "104" } ] }, { "y" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "x": [1,2,3,4] } ] }}','{ "": { "$inc": { "a.b.$[].x.0": 100 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "x" : [ { "$numberInt" : "101" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "x" : [ { "$numberInt" : "101" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] } } (1 row) -- Test Set2 : Elements in updatespec is not present in Document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, { "d" : 6 } ], "H" : { "c" : 10 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "c" : { "$numberInt" : "11" }, "d" : { "$numberInt" : "2" } }, { "d" : { "$numberInt" : "6" }, "c" : { "$numberInt" : "11" } } ], "H" : { "c" : { "$numberInt" : "10" } } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "d" : 2 }, { "d" : 6 } ] }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "d" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "11" } }, { "d" : { "$numberInt" : "6" }, "c" : { "$numberInt" : "11" } } ] } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "y": [1,2,3,4] } ] }}','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "x" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "c" : { "$numberInt" : "11" } }, { "y" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "c" : { "$numberInt" : "11" } } ] } } (1 row) --Test Set3 : $set Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$[]": 30 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "30" }, { "$numberInt" : "30" }, { "$numberInt" : "30" }, { "$numberInt" : "30" } ] } (1 row) --Test Set4 : $inc Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 30 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "31" }, { "$numberInt" : "32" }, { "$numberInt" : "33" }, { "$numberInt" : "34" } ] } (1 row) --Test Set5 : $min Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$[]": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "3" } ] } (1 row) --Test Set6 : $max Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$max": { "a.$[]": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "3" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } (1 row) --Test Set7 : $mul Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[]": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "3" }, { "$numberInt" : "6" }, { "$numberInt" : "9" }, { "$numberInt" : "12" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1.0,2.2,3.2,4.3] }', '{ "": { "$mul": { "a.$[]": 3 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "6.6000000000000005329" }, { "$numberDouble" : "9.6000000000000014211" }, { "$numberDouble" : "12.899999999999998579" } ] } (1 row) --Test Set8 : $bit Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [14,6] }', '{ "": { "$bit": { "a.$[]": {"or" : 1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "15" }, { "$numberInt" : "7" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [14,6] }', '{ "": { "$bit": { "a.$[]": {"and" : 1 } } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "0" }, { "$numberInt" : "0" } ] } (1 row) --Test Set9 : $unset Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$unset": { "a.$[]": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ null, null, null, null ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4],[5,6]] }', '{ "": { "$unset": { "a.$[].$[]": 10} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ null, null ], [ null, null ], [ null, null ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"c":5}] }', '{ "": { "$unset": { "a.$[].c": 1 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { } ] } (1 row) --Test Set10 $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[14],[6]] }', '{ "": { "$addToSet": { "a.$[]": "new" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "14" }, "new" ], [ { "$numberInt" : "6" }, "new" ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "x": {"myArray": [{"a": [[1],[1]],"b": [[1],[2]]},{"a": [[1],[2]],"b": [[1],[2]]}]} }', '{ "": { "$addToSet": {"x.myArray.$[].a.$[]": "new","x.myArray.$[].b.$[]": "new2" } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "x" : { "myArray" : [ { "a" : [ [ { "$numberInt" : "1" }, "new" ], [ { "$numberInt" : "1" }, "new" ] ], "b" : [ [ { "$numberInt" : "1" }, "new2" ], [ { "$numberInt" : "2" }, "new2" ] ] }, { "a" : [ [ { "$numberInt" : "1" }, "new" ], [ { "$numberInt" : "2" }, "new" ] ], "b" : [ [ { "$numberInt" : "1" }, "new2" ], [ { "$numberInt" : "2" }, "new2" ] ] } ] } } (1 row) --Test Set11 $push SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4]] }', '{ "": { "$push": { "a.$[]": 30 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "2" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "3" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "4" }, { "$numberInt" : "30" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[40,8,5],[42,7,15],[55,42,0],[41,0]] }', '{ "": { "$push": { "a.$[]": { "$sort":-1, "$each" : [10,20,30], "$position":2, "$slice":2} } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "40" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "42" }, { "$numberInt" : "30" } ], [ { "$numberInt" : "55" }, { "$numberInt" : "42" } ], [ { "$numberInt" : "41" }, { "$numberInt" : "30" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[]abc.c": 11 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "c" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "2" } } ], "$[]abc" : { "c" : { "$numberInt" : "11" } } } } (1 row) --Test Set12 : Update path not exist or cannot be created SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ 1 , 2 ], "H" : { "c" : 11 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); ERROR: Failed to create the field '0' within the element specified by {0 : 1} SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, 2 ], "H" : { "c" : 11 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); ERROR: Failed to create the field '1' within the element specified by {1 : 2} --Test Set 13 : Positional all operator on non array element SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[].c": 11 } } }', '{}'); ERROR: Array updates cannot be applied to an element that is not an array a: { b: [ { "c" : 1, "d" : 2 } ] } --Test Set 14 : Try with $ and $[] and Typo with $[] SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$.c": 11 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[element].c": 11 } } }', '{}'); ERROR: array filter identifier element must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1.0,2.2,3.2,4.3] }', '{ "": { "$mul": { "a.$[x]": 3 } } }', '{}'); ERROR: array filter identifier x must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[]abc": 3 } } }', '{}'); ERROR: Invalid array index path $[]abc SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$[]":10} } }', '{}'); ERROR: Array filter identifier usage (e.g., '$[]') is not permitted at the starting position of the specified path '$[]' --Test Set 15 : Complex One SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4],[5,6]] }', '{ "": { "$inc": { "a.$[].$[]": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "11" }, { "$numberInt" : "12" } ], [ { "$numberInt" : "13" }, { "$numberInt" : "14" } ], [ { "$numberInt" : "15" }, { "$numberInt" : "16" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "x": [100,2,3,4] } ] }}','{ "": { "$inc": { "a.b.$[].x.0": 100 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "b" : [ { "x" : [ { "$numberInt" : "101" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] }, { "x" : [ { "$numberInt" : "200" }, { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" } ] } ] } } (1 row) --Test set 16: Large field SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":5},{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":6}] }', '{ "": { "$set": { "a.$[].aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 10 } } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$numberInt" : "10" } }, { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" : { "$numberInt" : "10" } } ] } (1 row) --Test set 17: Multiple Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4], "b":10 }', '{ "": { "$set": { "a.$[]": 30 }, "$inc": {"b" : 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "30" }, { "$numberInt" : "30" }, { "$numberInt" : "30" }, { "$numberInt" : "30" } ], "b" : { "$numberInt" : "11" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4], "b":{"x":10} }', '{ "": { "$set": { "b.x": 30 }, "$inc": {"a.$[]" : 1} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" }, { "$numberInt" : "4" }, { "$numberInt" : "5" } ], "b" : { "x" : { "$numberInt" : "30" } } } (1 row) --Test Set 18 : Path Conflicts SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].$[]": 10, "a.0": 11 } } }', '{}'); ERROR: Modifying the path 'a.0' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0": 10, "a.$[].$[]": 11 } } }', '{}'); ERROR: Modifying the path 'a.$[].$[]' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0.1": 10, "a.$[].$[]": 11 } } }', '{}'); ERROR: Modifying the path 'a.$[].$[]' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].$[]": 11, "a.1.0": 10 } } }', '{}'); ERROR: Modifying the path 'a.1.0' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.b.$[]": 10, "a.b.0": 11 } } }', '{}'); ERROR: Modifying the path 'a.b.0' will result in a conflict occurring at 'a.b' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 11, "a.0": 10 } } }', '{}'); ERROR: Modifying the path 'a.0' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.0": 11, "a.$[]": 10 } } }', '{}'); ERROR: Modifying the path 'a.$[]' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.0": 11 }, "$set":{"a.$[]": 11} } }', '{}'); ERROR: Modifying the path 'a.$[]' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 11 }, "$set":{"a.0": 11} } }', '{}'); ERROR: Modifying the path 'a.0' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "x": 10 }, {"x": 11}] }', '{ "": { "$inc": { "a.$[].x": 11 }, "$set":{"a.0": 11} } }', '{}'); ERROR: Modifying the path 'a.0' will result in a conflict occurring at 'a' SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x":10},{"y":11}] }', '{ "": { "$set": { "a.$[]": 30 }, "$inc": {"a.1.y" : 1} } }', '{}'); ERROR: Modifying the path 'a.1.y' will result in a conflict occurring at 'a' --Test Set 19 : Multiple Spec One Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].0": 30 , "a.$[].1" : 10} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ [ { "$numberInt" : "31" }, { "$numberInt" : "12" } ], [ { "$numberInt" : "33" }, { "$numberInt" : "14" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b":1,"c":2,"x":{"y":3}}] }', '{ "": { "$inc": { "a.$[].b": 10 , "a.$[].c" : 20, "a.$[].x.y":30} } }', '{}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "b" : { "$numberInt" : "11" }, "c" : { "$numberInt" : "22" }, "x" : { "y" : { "$numberInt" : "33" } } } ] } (1 row) ---Test Set 20 : $ Operator--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0.$": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x": 5},{"y":10}] }', '{ "": { "$inc": { "a.$.c": 30 } } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$":10} } }', '{}'); ERROR: Positional element (i.e. '$') cannot appear at the beginning of the path '$'. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"x":5},{"y":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$.y": 12 } } }', '{}'); bson_update_document --------------------------------------------------------------------- ("{ ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : [ { ""x"" : { ""$numberInt"" : ""15"" } }, { ""y"" : { ""$numberInt"" : ""10"" }, ""x"" : { ""$numberInt"" : ""10"" } } ] }",) (1 row) ---Test Set 21 : $[] Operator--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$[ele]": 30 } } }', '{}'); ERROR: array filter identifier ele must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[ele]": 30 } } }', '{}'); ERROR: array filter identifier ele must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[ele]": 30 } } }', '{}'); ERROR: array filter identifier ele must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$[ele]": 30 } } }', '{}'); ERROR: array filter identifier ele must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x": 5,"c" :11},{"y":10},{"x":10}] }', '{ "": { "$inc": { "a.$[ele].c": 30 } } }', '{}'); ERROR: array filter identifier ele must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$[]":10} } }', '{}'); ERROR: Array filter identifier usage (e.g., '$[]') is not permitted at the starting position of the specified path '$[]' ---Test Set 22 : Multiple positional operator on same level--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"a":[1,2,3],"b":[4,5,6]}] }', '{ "": { "$inc": {"a.$[].a.$[]": 10,"a.$[].b.$[x]": 11 } } }', '{}'); ERROR: array filter identifier x must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"x":5},{"y":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$[x].y": 12 } } }', '{}'); ERROR: array filter identifier x must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"y":5},{"x":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$[x].y": 12 } } }', '{}'); ERROR: array filter identifier x must match an entry in arrayFilters (no match found) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2,3],[4,5,6]] }', '{ "": { "$inc": { "a.$.$[]": 10} } }', '{}'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ {"a":[ {"x":1},{"y":2} ] ,"b": [ {"x":5},{"y":10} ] } ] }', '{ "": { "$inc": { "a.$[].b.$[].x": 10, "a.$[].b.$[x].y":12} } }', '{}'); ERROR: array filter identifier x must match an entry in arrayFilters (no match found) -- Test Set 23: Rename with positional should not work. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": {"a.$[]": "b.$[]" } } }', '{}'); ERROR: The source field for $rename may not be dynamic: a.$[] SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": {"a.0": "b.$[]" } } }', '{}'); ERROR: The destination field for $rename may not be dynamic: b.$[] -- Test Set 24: $positional with adding new fields SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"a.c.$[]": 1 } } }', '{}'); ERROR: The specified path 'c' does not exist within the document. Cannot apply array update operations. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"c.$[]": 1 } } }', '{}'); ERROR: The specified path 'c' does not exist within the document. Cannot apply array update operations. bson_update_positional_arrayFilters.out000066400000000000000000000557711507310017400400360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 220000; SET documentdb.next_collection_id TO 2200; SET documentdb.next_collection_index_id TO 2200; -- arrayFilters with aggregation pipeline SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', '{ "": []}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "fieldA" : { "fieldB" : { "$numberInt" : "10" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', NULL); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "fieldA" : { "fieldB" : { "$numberInt" : "10" } } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', '{ "": [ { "filterX": 30 }]}'); ERROR: Specifying arrayFilters is not allowed when performing pipeline-style updates -- arrayFilters ignored on replace SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "fieldC": 40 } }', '{}', '{ "": [ { "filterX": 50 }]}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "fieldC" : { "$numberInt" : "40" } } (1 row) -- arrayFilters with update fails - missing array filter SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 60 }}}', '{}', '{ "": [] }'); ERROR: array filter identifier itemA must match an entry in arrayFilters (no match found) -- arrayFilters with update fails - invalid array filters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ 2 ] }'); ERROR: BSONField updates.update.arrayFilters.0 is the wrong type int. expected type object SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ {} ] }'); ERROR: Cannot use an expression without a top-level field name in arrayFilters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "": 3} ] }'); ERROR: The top level field name must be alphanumeric string. Found '' SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "itemA": 4, "itemB.itemC": 5 } ] }'); ERROR: Error parsing array filter :: caused by :: Expected a single top-level field name, found itemA and itemB SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "itemA": 6 }, { "itemA": 7 } ] }'); ERROR: Multiple array filters detected using identical top-level field name itemA -- simple array update on equality SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1, "numbers": [ 100, 200 ] }','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{}', '{ "": [{ "numElem": 100 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "numbers" : [ { "$numberInt" : "300" }, { "$numberInt" : "200" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{}','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{"_id": 1, "numbers": [ 100, 200 ] }', '{ "": [{ "numElem": 100 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "numbers" : [ { "$numberInt" : "300" }, { "$numberInt" : "200" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{}', '{ "": [{ "numElem": 100 }] }'); ERROR: The specified path 'numbers' does not exist within the document. Cannot apply array update operations. -- updates on $gte condition SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "scores" : [ 150, 120, 110 ], "age": 15 }','{ "": { "$set": { "scores.$[scoreElem]": 200 }}}', '{}', '{ "": [{ "scoreElem": { "$gte": 200 } }] }'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "scores" : [ 150, 210, 200, 180, 202 ], "age": 16 }','{ "": { "$set": { "scores.$[scoreElem]": 200 }}}', '{}', '{ "": [{ "scoreElem": { "$gte": 200 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "scores" : [ { "$numberInt" : "150" }, { "$numberInt" : "200" }, { "$numberInt" : "200" }, { "$numberInt" : "180" }, { "$numberInt" : "200" } ], "age" : { "$numberInt" : "16" } } (1 row) -- nested arrayFilters. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75}, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$set": { "metrics.$[metricElem].avg": 100 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "metrics" : [ { "value" : { "$numberInt" : "58" }, "max" : { "$numberInt" : "136" }, "avg" : { "$numberInt" : "66" }, "dev" : { "$numberInt" : "88" } }, { "value" : { "$numberInt" : "96" }, "max" : { "$numberInt" : "176" }, "avg" : { "$numberInt" : "100" }, "dev" : { "$numberInt" : "75" } }, { "value" : { "$numberInt" : "68" }, "max" : { "$numberInt" : "168" }, "avg" : { "$numberInt" : "100" }, "dev" : { "$numberInt" : "83" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75 }, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$inc": { "metrics.$[metricElem].dev": -50 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 }, "metricElem.dev": { "$gte": 80 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "metrics" : [ { "value" : { "$numberInt" : "58" }, "max" : { "$numberInt" : "136" }, "avg" : { "$numberInt" : "66" }, "dev" : { "$numberInt" : "88" } }, { "value" : { "$numberInt" : "96" }, "max" : { "$numberInt" : "176" }, "avg" : { "$numberInt" : "99" }, "dev" : { "$numberInt" : "75" } }, { "value" : { "$numberInt" : "68" }, "max" : { "$numberInt" : "168" }, "avg" : { "$numberInt" : "86" }, "dev" : { "$numberInt" : "33" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75 }, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$inc": { "metrics.$[metricElem].dev": -50 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 }, "metricElem.dev": { "$gte": 75 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "metrics" : [ { "value" : { "$numberInt" : "58" }, "max" : { "$numberInt" : "136" }, "avg" : { "$numberInt" : "66" }, "dev" : { "$numberInt" : "88" } }, { "value" : { "$numberInt" : "96" }, "max" : { "$numberInt" : "176" }, "avg" : { "$numberInt" : "99" }, "dev" : { "$numberInt" : "25" } }, { "value" : { "$numberInt" : "68" }, "max" : { "$numberInt" : "168" }, "avg" : { "$numberInt" : "86" }, "dev" : { "$numberInt" : "33" } } ] } (1 row) -- negation operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "degreesList" : [ { "level": "PhD", "age": 28}, { "level": "Bachelor", "age": 22} ] }', '{ "": { "$set" : { "degreesList.$[deg].gradYear" : 2020 }} }', '{}', '{ "": [{ "deg.level": { "$ne": "Bachelor" } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "degreesList" : [ { "level" : "PhD", "age" : { "$numberInt" : "28" }, "gradYear" : { "$numberInt" : "2020" } }, { "level" : "Bachelor", "age" : { "$numberInt" : "22" } } ] } (1 row) -- multiple positional operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[typeElem].answers.$[ansScore]": 190 }} }', '{}', '{ "": [{ "typeElem.type": "quiz" }, { "ansScore": { "$gte": 18 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "results" : [ { "type" : "quiz", "answers" : [ { "$numberInt" : "210" }, { "$numberInt" : "208" }, { "$numberInt" : "15" } ] }, { "type" : "quiz", "answers" : [ { "$numberInt" : "208" }, { "$numberInt" : "209" }, { "$numberInt" : "16" } ] }, { "type" : "hw", "answers" : [ { "$numberInt" : "15" }, { "$numberInt" : "14" }, { "$numberInt" : "13" } ] }, { "type" : "exam", "answers" : [ { "$numberInt" : "35" }, { "$numberInt" : "20" }, { "$numberInt" : "33" }, { "$numberInt" : "10" } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[].answers.$[ansScore]": 190 }} }', '{}', '{ "": [{ "ansScore": { "$gte": 18 } }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "results" : [ { "type" : "quiz", "answers" : [ { "$numberInt" : "210" }, { "$numberInt" : "208" }, { "$numberInt" : "15" } ] }, { "type" : "quiz", "answers" : [ { "$numberInt" : "208" }, { "$numberInt" : "209" }, { "$numberInt" : "16" } ] }, { "type" : "hw", "answers" : [ { "$numberInt" : "15" }, { "$numberInt" : "14" }, { "$numberInt" : "13" } ] }, { "type" : "exam", "answers" : [ { "$numberInt" : "225" }, { "$numberInt" : "210" }, { "$numberInt" : "223" }, { "$numberInt" : "10" } ] } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[typeElem].answers.$[]": 190 }} }', '{}', '{ "": [{ "typeElem.type": "quiz" }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "results" : [ { "type" : "quiz", "answers" : [ { "$numberInt" : "210" }, { "$numberInt" : "208" }, { "$numberInt" : "205" } ] }, { "type" : "quiz", "answers" : [ { "$numberInt" : "208" }, { "$numberInt" : "209" }, { "$numberInt" : "206" } ] }, { "type" : "hw", "answers" : [ { "$numberInt" : "15" }, { "$numberInt" : "14" }, { "$numberInt" : "13" } ] }, { "type" : "exam", "answers" : [ { "$numberInt" : "35" }, { "$numberInt" : "20" }, { "$numberInt" : "33" }, { "$numberInt" : "10" } ] } ] } (1 row) -- arrayFilters for all Update operators should recurse if for a single level nested array -- array update operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$addToSet": { "matrix.$[row]": 2 }} }', '{}', '{ "": [{ "row": 0 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "2" } ], [ { "$numberInt" : "1" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pop": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 0 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "0" } ], [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pull": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 2 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "2" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pull": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 2 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "2" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [2, 3] ] }', '{ "": { "$push": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 1 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "1" } ], [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] ] } (1 row) -- field update operators, should be able to match but apply update based on the type requirement SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$inc": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); ERROR: Operation $inc cannot be performed because the target value is not numeric. Document { _id: 1 } contains the field '0' which is of non-numeric type array. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$min": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ { "$numberInt" : "10" }, [ { "$numberInt" : "1" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$max": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); bson_update_document --------------------------------------------------------------------- (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$mul": { "matrix.$[row]": 2 }} }', '{}', '{ "": [{ "row": 0 }] }'); ERROR: Unable to use the $mul operator on values that are not numeric. The document { _id: 1 } contains the field '0', which has a non-numeric type array. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$rename": { "matrix.$[row]": "arrayA.3" }} }', '{}', '{ "": [{ "row": 0 }] }'); ERROR: The source field for $rename may not be dynamic: matrix.$[row] SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$set": { "matrix.$[row]": "updatedValue" }} }', '{}', '{ "": [{ "row": 0 }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ "updatedValue", [ { "$numberInt" : "1" } ] ] } (1 row) -- bit operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$bit": { "matrix.$[row]": {"or": 5} }} }', '{}', '{ "": [{ "row": 0 }] }'); ERROR: $bit cannot be used on a value that is not of an integral type. The document with _id = 1 contains the field 0, which has a non-integer type array. -- Check array value should also match in arrayFilters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [11,12,13], [14,15,16] ] }', '{ "": { "$set": { "matrix.$[row]": [21,22,23] }} }', '{}', '{ "": [{ "row": [11,12,13] }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ [ { "$numberInt" : "21" }, { "$numberInt" : "22" }, { "$numberInt" : "23" } ], [ { "$numberInt" : "14" }, { "$numberInt" : "15" }, { "$numberInt" : "16" } ] ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [11,12,13], [14,15,16] ] }', '{ "": { "$set": { "matrix.$[row]": 33 }} }', '{}', '{ "": [{ "row": {"$size": 3} }] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "matrix" : [ { "$numberInt" : "33" }, { "$numberInt" : "33" } ] } (1 row) bson_update_positional_queryFilters.out000066400000000000000000000535261507310017400400610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 200000; SET documentdb.next_collection_id TO 2000; SET documentdb.next_collection_index_id TO 2000; -- simple array update on equality SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "grades" : [ 85, 80, 80 ] }','{ "": { "$set": { "grades.$" : 82 } } }', '{ "_id": 1, "grades": 80 }', NULL); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "grades" : [ { "$numberInt" : "85" }, { "$numberInt" : "82" }, { "$numberInt" : "80" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 2, "grades" : [ 88, 90, 92 ] }','{ "": { "$set": { "grades.$" : 82 } } }', '{ "_id": 1, "grades": 80 }', NULL); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 4, "grades": [ { "grade": 80, "mean": 75, "std": 8 }, { "grade": 85, "mean": 90, "std": 5 }, { "grade": 85, "mean": 85, "std": 8 } ] }', '{ "": { "$set": { "grades.$.std" : 6 } } }', '{ "_id": 4, "grades.grade": 85 }', NULL); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "grades" : [ { "grade" : { "$numberInt" : "80" }, "mean" : { "$numberInt" : "75" }, "std" : { "$numberInt" : "8" } }, { "grade" : { "$numberInt" : "85" }, "mean" : { "$numberInt" : "90" }, "std" : { "$numberInt" : "6" } }, { "grade" : { "$numberInt" : "85" }, "mean" : { "$numberInt" : "85" }, "std" : { "$numberInt" : "8" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 4, "grades": [ { "grade": 80, "mean": 75, "std": 8 }, { "grade": 85, "mean": 90, "std": 5 }, { "grade": 85, "mean": 85, "std": 8 } ] }', '{ "": { "$set": { "grades.$.std" : 6 } } }', '{ "_id": 5, "grades": { "$elemMatch": { "grade": { "$lte": 90 }, "mean": { "$gt": 80 } } } }', NULL); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "grades" : [ { "grade" : { "$numberInt" : "80" }, "mean" : { "$numberInt" : "75" }, "std" : { "$numberInt" : "8" } }, { "grade" : { "$numberInt" : "85" }, "mean" : { "$numberInt" : "90" }, "std" : { "$numberInt" : "6" } }, { "grade" : { "$numberInt" : "85" }, "mean" : { "$numberInt" : "85" }, "std" : { "$numberInt" : "8" } } ] } (1 row) -- positional on match that doesn't work SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "c": 8 }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$or": [ { "b": 5 }, { "c": 8 } ] }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$nor": [ { "b": 5 }, { "c": 8 } ] }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$not": { "$eq": 8 } } }'); ERROR: The positional operator failed to locate the required match within the provided query. -- positional on alternate array (pick first match) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$in": [ 5, 6 ]} }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) -- test $or with simple filters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$or": [ { "b": 5 }, { "b": 6 } ] }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) -- test various filter operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": 5 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$ne": 5 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$nin": [ 4, 5] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "100" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$gte": 5 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$lte": 5 } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$regularExpression": { "pattern": "^ba[rz]", "options": "" } } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ "bat", "bar", "baz" ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$exists": true } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "100" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ], "b" : [ "bat", "bar", "baz" ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$type": "number" } }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ true, "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$type": "string" } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ true, "bar", "baz" ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b.c": { "$elemMatch": { "$eq": 2 }} }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b.c": { "$elemMatch": { "$eq": 2 }} }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ 5, 6 ] } }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$bitsAnySet": [ 0, 1 ]} }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) -- $elemMatch with empty document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, { "c": 5 }, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$elemMatch": {} }}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "$numberInt" : "4" }, { "c" : { "$numberInt" : "5" } }, { "$numberInt" : "6" } ], "c" : { "$numberInt" : "8" } } (1 row) -- $all with $elemmatch SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ { "$elemMatch": { "c": 2 } } ]} }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "100" }, { "$numberInt" : "3" } ], "b" : [ { "c" : { "$numberInt" : "1" } }, { "c" : { "$numberInt" : "2" } }, { "c" : { "$numberInt" : "3" } } ], "c" : { "$numberInt" : "8" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ { "$elemMatch": { "c": 2 } } , { "$elemMatch": { "c": 3 } } ]} }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "100" } ], "b" : [ { "c" : { "$numberInt" : "1" } }, { "c" : { "$numberInt" : "2" } }, { "c" : { "$numberInt" : "3" } } ], "c" : { "$numberInt" : "8" } } (1 row) -- upsert cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{}', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": [ 1, 2, 3 ], "a": [ 4, 5, 6 ] }'); ERROR: The positional operator failed to locate the required match within the provided query. -- simple example for non-array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 3, "a": { "b": [ { "c": 1, "d": 2 } ] } }', '{ "": { "$set": { "a.$.c": 11 } }}', '{ "_id": 1 }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 3, "a": { "b": [ { "c": 1, "d": 2 } ] } }', '{ "": { "$set": { "a.$.c": 11 } }}', '{ "a.b.c": 1 }'); ERROR: Array updates cannot be applied to an element that is not an array a: { b: [ { "c" : 1, "d" : 2 } ] } -- miscellenous cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8] }', '{ "": { "$set": { "a.$": "new" } }}', '{ "b": 6 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, "new", { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : [ { "$numberInt" : "5" }, { "$numberInt" : "6" }, { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8] }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"a" : 3 ,"b": 6 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, "new", { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : [ { "$numberInt" : "5" }, "new", { "$numberInt" : "7" }, { "$numberInt" : "8" } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "key":[{"id":1,"a":1},{"id":2,"a":1}],"key2":[{"id":1,"a":1}]}', '{ "": { "$set": { "key.$.a": 5 } }}', '{"key.id": 2, "key2.id" : 3}'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "key" : [ { "id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } }, { "id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "5" } } ], "key2" : [ { "id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } ] } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8], "c" : 1 }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"a" : 3 ,"b": 6, "c" : 1 }'); bson_update_document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : [ { "$numberInt" : "1" }, "new", { "$numberInt" : "3" }, { "$numberInt" : "4" } ], "b" : [ { "$numberInt" : "5" }, "new", { "$numberInt" : "7" }, { "$numberInt" : "8" } ], "c" : { "$numberInt" : "1" } } (1 row) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8], "c" : 1 }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"c" : 1 }'); ERROR: The positional operator failed to locate the required match within the provided query. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : 1, "c" : 1 }', '{ "": { "$set": { "a.$": "new"} }}', '{"a" : 1}'); ERROR: Failed to create the field 'a' within the element specified by {a : 1} bson_wildcard_reduced_term_tests.out000066400000000000000000001040761507310017400373120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5600000; SET documentdb.next_collection_id TO 56000; SET documentdb.next_collection_index_id TO 56000; -- test term generation SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "d" : { "$numberInt" : "1" } } { "" : true } (6 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": [ 1, 2 ], "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberInt" : "2" } } } { "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "a.c" : { "$numberInt" : "2" } } { "d" : { "$numberInt" : "1" } } { "" : true } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": 1, "c": 2 }, { "d": 1 } ] }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : [ { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } }, { "d" : { "$numberInt" : "1" } } ] } { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "2" } } } { "a.b" : { "$numberInt" : "1" } } { "a.c" : { "$numberInt" : "2" } } { "a" : { "d" : { "$numberInt" : "1" } } } { "a.d" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (9 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ 1, 2 ], "c": 2 }, { "d": 1 }, 3 ] }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : [ { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberInt" : "2" } }, { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "3" } ] } { "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberInt" : "2" } } } { "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "a.c" : { "$numberInt" : "2" } } { "a" : { "d" : { "$numberInt" : "1" } } } { "a.d" : { "$numberInt" : "1" } } { "a" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (12 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ 1, 2 ], "c": 2 }, [ { "d": 1 }, 5 ], 3 ] }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : [ { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberInt" : "2" } }, [ { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "5" } ], { "$numberInt" : "3" } ] } { "a" : { "b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ], "c" : { "$numberInt" : "2" } } } { "a.b" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.b" : { "$numberInt" : "1" } } { "a.b" : { "$numberInt" : "2" } } { "a.c" : { "$numberInt" : "2" } } { "a.1" : [ { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "5" } ] } { "a.1.0" : { "d" : { "$numberInt" : "1" } } } { "a.1.0.d" : { "$numberInt" : "1" } } { "a.1.d" : { "$numberInt" : "1" } } { "a.1.1" : { "$numberInt" : "5" } } { "a" : [ { "d" : { "$numberInt" : "1" } }, { "$numberInt" : "5" } ] } { "a" : { "$numberInt" : "3" } } { "" : true } { "" : [ ] } (16 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ [ 1, 2 ] ] }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : [ [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } { "a.0" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "a.0.0" : { "$numberInt" : "1" } } { "a.0.1" : { "$numberInt" : "2" } } { "a" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" } ] } { "" : true } { "" : [ ] } (8 rows) SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ [ { "b": 1 } ] ] }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "a" : [ [ { "b" : { "$numberInt" : "1" } } ] ] } { "a.0" : [ { "b" : { "$numberInt" : "1" } } ] } { "a.0.0" : { "b" : { "$numberInt" : "1" } } } { "a.0.0.b" : { "$numberInt" : "1" } } { "a.0.b" : { "$numberInt" : "1" } } { "a" : [ { "b" : { "$numberInt" : "1" } } ] } { "" : true } { "" : [ ] } (9 rows) -- objects with fields with numeric paths don't get skipped SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "0" : { "b": { "1": { "f": true }, "2": 2 }, "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" } } { "0" : { "b" : { "1" : { "f" : true }, "2" : { "$numberInt" : "2" } }, "c" : { "$numberInt" : "2" } } } { "0.b" : { "1" : { "f" : true }, "2" : { "$numberInt" : "2" } } } { "0.b.1" : { "f" : true } } { "0.b.1.f" : true } { "0.b.2" : { "$numberInt" : "2" } } { "0.c" : { "$numberInt" : "2" } } { "d" : { "$numberInt" : "1" } } { "" : true } (9 rows) -- array paths *before* matches are fully considered SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ { "c": 1 }]}] }', 'a.0.b', true, enableReducedWildcardTerms => true); gin_bson_get_single_path_generated_terms --------------------------------------------------------------------- { "a.0.b" : [ { "c" : { "$numberInt" : "1" } } ] } { "a.0.b" : { "c" : { "$numberInt" : "1" } } } { "a.0.b.c" : { "$numberInt" : "1" } } { "" : true } { "" : [ ] } (5 rows) -- create a root wildcard index with reduced terms SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcardreducedterms", "indexes": [ { "key": { "$**": 1 }, "name": "my_idx", "enableReducedWildcardTerm": true }] }'); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d documentdb_data.documents_56000 Table "documentdb_data.documents_56000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_56000" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_56001" documentdb_rum (document bson_rum_single_path_ops (path='', iswildcard='true', tl='2699', wkl='200', rwt='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '56000'::bigint) -- now insert some convoluted document SELECT documentdb_api.insert_one('db','wildcardreducedterms', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- these return the above document SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- { "" : { "$numberInt" : "15" } } | { "_id" : { "$numberInt" : "15" }, "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] } (1 row) -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}'; object_id | document --------------------------------------------------------------------- (0 rows) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}'; object_id | document --------------------------------------------------------------------- (0 rows) -- EXPLAIN to show the plan with the paths EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_56000_5600001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) (9 rows) -- having numbers in fields is okay as long as it also has letters EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c01" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_56000_5600001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c01" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c01" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d0af.e" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_56000_5600001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c.d0af.e" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "c.d0af.e" : [ { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }, { "d" : [ [ { "$numberInt" : "0" }, { "$numberInt" : "1" }, { "$numberInt" : "7" } ] ] } ] }'::documentdb_core.bson) (9 rows) -- these won't be pushed EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_56000_5600001 collection Recheck Cond: (shard_key_value = '56000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "c.0.d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '56000'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_56000_5600001 collection Recheck Cond: (shard_key_value = '56000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "c.0" : { "d" : [ [ { "$numberInt" : "-1" }, { "$numberInt" : "1" }, { "$numberInt" : "2" } ] ] } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '56000'::bigint) (10 rows) collection_management.out000066400000000000000000000257151507310017400350650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_core; SET citus.next_shard_id TO 190000; SET documentdb.next_collection_id TO 1900; SET documentdb.next_collection_index_id TO 1900; -- create a collection and insert a document SELECT documentdb_api.create_collection('collection_management','originalname'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); count --------------------------------------------------------------------- 0 (1 row) SELECT documentdb_api.insert_one('collection_management','originalname','{"_id":"1", "a":1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- query an existing collection SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); count --------------------------------------------------------------------- 1 (1 row) -- query a non-existing collection SELECT count(*) FROM documentdb_api.collection('collection_management','nonexistent'); count --------------------------------------------------------------------- 0 (1 row) -- SELECT * from a non-existing collection SELECT * FROM documentdb_api.collection('collection_management','nonexistent'); shard_key_value | object_id | document --------------------------------------------------------------------- (0 rows) -- EXPLAIN of querying a non-existing collection EXPLAIN SELECT * FROM documentdb_api.collection('collection_management','nonexistent'); QUERY PLAN --------------------------------------------------------------------- Function Scan on empty_data_table collection (cost=0.25..10.25 rows=1000 width=72) (1 row) -- try to rename to an already existing name SELECT documentdb_api.create_collection('collection_management','newname'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.rename_collection('collection_management','originalname', 'newname'); ERROR: The collection collection_management.newname is already present in the system -- Disallow system.views, system.profile etc as the target collection names SELECT documentdb_api.rename_collection('collection_management','originalname', 'system.views'); ERROR: Unable to write data to specified location collection_management.system.views CONTEXT: SQL statement "UPDATE documentdb_api_catalog.collections SET collection_name = $1 WHERE database_name = $2 AND collection_name = $3" SELECT documentdb_api.rename_collection('collection_management','originalname', 'system.profile'); ERROR: Unable to write data to specified location collection_management.system.profile CONTEXT: SQL statement "UPDATE documentdb_api_catalog.collections SET collection_name = $1 WHERE database_name = $2 AND collection_name = $3" -- validate duplicate collections are not allowed SELECT documentdb_api.create_collection('collection_management','collection1'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('collection_management','collection1'); create_collection --------------------------------------------------------------------- f (1 row) -- try to rename to an already existing name, after dropping the old one SELECT documentdb_api.rename_collection('collection_management','originalname', 'newname', true); rename_collection --------------------------------------------------------------------- (1 row) -- try to query the original name SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); count --------------------------------------------------------------------- 0 (1 row) -- try to query the new name SELECT count(*) FROM documentdb_api.collection('collection_management','newname'); count --------------------------------------------------------------------- 1 (1 row) -- drop the collection SELECT documentdb_api.drop_collection('collection_management','newname'); drop_collection --------------------------------------------------------------------- t (1 row) -- try to drop a non-existent collection SELECT documentdb_api.drop_collection('collection_management','originalname'); drop_collection --------------------------------------------------------------------- f (1 row) -- recreate a table that previously existed SELECT documentdb_api.create_collection('collection_management','originalname'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); count --------------------------------------------------------------------- 0 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('collection_management', '{"createIndexes": "drop_collection_test", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- store id of drop_collection_test before dropping it SELECT collection_id AS drop_collection_test_id FROM documentdb_api_catalog.collections WHERE collection_name = 'drop_collection_test' AND database_name = 'collection_management' \gset -- Insert a record into index metadata that indicates an invalid collection index -- to show that we delete records for invalid indexes too when dropping database. INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:drop_collection_test_id, 2020, ('invalid_index_2', '{"a": 1}', null, null, null, null, 2, null, null, null), false); -- drop the database SELECT documentdb_api.drop_database('collection_management'); drop_database --------------------------------------------------------------------- (1 row) SELECT count(*) FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management'; count --------------------------------------------------------------------- 0 (1 row) SELECT COUNT(*)=0 FROM documentdb_api_catalog.collection_indexes WHERE collection_id = :drop_collection_test_id; ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('collection_management','testDropViaUuid'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('collection_management','testDropViaUuid2'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT collection_uuid::text AS drop_collection_uuid2 FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management' AND collection_name = 'testDropViaUuid2' \gset SELECT collection_uuid::text AS drop_collection_uuid FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management' AND collection_name = 'testDropViaUuid' \gset SELECT documentdb_api.drop_collection('collection_management', 'testDropViaUuid', NULL, :'drop_collection_uuid2'::uuid); ERROR: drop collection collection_management.testDropViaUuid UUID mismatch SELECT documentdb_api.drop_collection('collection_management', 'testDropViaUuid', NULL, :'drop_collection_uuid'::uuid); drop_collection --------------------------------------------------------------------- t (1 row) -- try to target a collection via a prepared statement. SELECT documentdb_api.create_collection('collection_management','testPrepared'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) PREPARE collectionQuery1(text, text) AS SELECT document FROM documentdb_api.collection($1, $2); EXECUTE collectionQuery1('collection_management', 'testPrepared'); document --------------------------------------------------------------------- (0 rows) -- try to run the prepared statement many times against a non-existent collection PREPARE qcountNoneExistent(text, text, bson, text) AS WITH "stage0" as ( SELECT document FROM documentdb_api.collection($1, $2) WHERE document OPERATOR(documentdb_api_catalog.@@) $3 ) , "stage1" as ( SELECT documentdb_core.bson_repath_and_build($4, BSONSUM('{ "": 1 }'::bson)) as document FROM "stage0" ) SELECT * FROM "stage1"; EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); document --------------------------------------------------------------------- { "count" : { "$numberInt" : "0" } } (1 row) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/command_compact.out000066400000000000000000000162721507310017400337370ustar00rootroot00000000000000SET citus.next_shard_id TO 2432000; SET documentdb.next_collection_id TO 24320; SET documentdb.next_collection_index_id TO 24320; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api.compact(NULL); compact --------------------------------------------------------------------- (1 row) SELECT documentdb_api.compact('{}'); ERROR: Invalid command compact specification, missing database or collection name SELECT documentdb_api.compact('{"noIdea": "collection1"}'); ERROR: The BSON field compact.noIdea is not recognized as a known field SELECT documentdb_api.compact('{"compact": "non_existing_collection"}'); ERROR: Invalid command compact specification, missing database or collection name SELECT documentdb_api.compact('{"compact": 1 }'); ERROR: The BSON field 'compact' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.compact('{"compact": true }'); ERROR: The BSON field 'compact' has an incorrect type 'bool'; it should be of type 'string'. SELECT documentdb_api.compact('{"compact": ["coll"]}'); ERROR: The BSON field 'compact' has an incorrect type 'array'; it should be of type 'string'. SELECT documentdb_api.create_collection('commands_compact_db','compact_test'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.compact('{"compact": "compact_test", "dryRun": "invalid"}'); ERROR: The BSON field 'dryRun' has an incorrect type 'string'; it should be of type 'bool'. SELECT documentdb_api.compact('{"compact": "compact_test", "comment": "test comment"}'); ERROR: Invalid command compact specification, missing database or collection name SELECT documentdb_api.compact('{"compact": "compact_test", "force": false}'); ERROR: command compact option force:false is not supported -- Insert a single document SELECT documentdb_api.insert_one('commands_compact_db', 'compact_test', FORMAT('{ "_id": 1, "a": "%s", "c": [ %s "d" ] }', repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Bloat the table DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..45 LOOP UPDATE documentdb_data.documents_24321 SET document = document::bytea::bson WHERE document @@ '{ "_id": 1 }'; COMMIT; END LOOP; END; $$; -- VALID, first need to analyze the table so that stats are up to date ANALYZE VERBOSE documentdb_data.documents_24321; INFO: analyzing "documentdb_data.documents_24321" INFO: "documents_24321": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows SELECT documentdb_api.coll_stats('commands_compact_db','compact_test')->>'storageSize'; ?column? --------------------------------------------------------------------- 4243456 (1 row) -- TODO: even after analyze it seems like pg_class stats for toast tables are not updated for test run. -- Need to investigate this further for test, for live servers this should be okay because the analyze thereshold is set to 0. SELECT documentdb_api.compact('{"compact": "compact_test", "$db": "commands_compact_db", "dryRun": true}'); compact --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "estimatedBytesFreed" : { "$numberLong" : "0" } } (1 row) SELECT documentdb_api.compact('{"compact": "compact_test", "$db": "commands_compact_db", "dryRun": false}'); compact --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "bytesFreed" : { "$numberLong" : "0" } } (1 row) SELECT documentdb_api.coll_stats('commands_compact_db','compact_test')->>'storageSize'; ?column? --------------------------------------------------------------------- 114688 (1 row) SELECT documentdb_api.drop_collection('commands_compact_db','compact_test'); drop_collection --------------------------------------------------------------------- t (1 row) -- sharded test SELECT documentdb_api.create_collection('commands_compact_db', 'compact_test_sharded'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.shard_collection('commands_compact_db', 'compact_test_sharded', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..51 LOOP PERFORM documentdb_api.insert_one('commands_compact_db', 'compact_test_sharded', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }',i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); COMMIT; END LOOP; END; $$; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..45 LOOP UPDATE documentdb_data.documents_24322 SET document = document::bytea::bson WHERE document @@ '{ "_id": 1 }'; COMMIT; END LOOP; END; $$; -- VALID, first need to analyze the table so that stats are up to date ANALYZE VERBOSE documentdb_data.documents_24322; INFO: analyzing "documentdb_data.documents_24322" INFO: "documents_24322": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows SELECT documentdb_api.coll_stats('commands_compact_db','compact_test_sharded')->>'storageSize'; ?column? --------------------------------------------------------------------- 9117696 (1 row) -- TODO: even after analyze it seems like pg_class stats for toast tables are not updated for test run. -- Need to investigate this further for test, for live servers this should be okay because the analyze thereshold is set to 0. SELECT documentdb_api.compact('{"compact": "compact_test_sharded", "$db": "commands_compact_db", "dryRun": true}'); compact --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "estimatedBytesFreed" : { "$numberLong" : "0" } } (1 row) SELECT documentdb_api.compact('{"compact": "compact_test_sharded", "$db": "commands_compact_db", "dryRun": false}'); compact --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "bytesFreed" : { "$numberLong" : "0" } } (1 row) SELECT documentdb_api.coll_stats('commands_compact_db','compact_test_sharded')->>'storageSize'; ?column? --------------------------------------------------------------------- 4808704 (1 row) SELECT documentdb_api.drop_collection('commands_compact_db','compact_test_sharded'); drop_collection --------------------------------------------------------------------- t (1 row) command_insert_procedure.out000066400000000000000000000645061507310017400356110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 129000; SET documentdb.next_collection_id TO 1290; SET documentdb.next_collection_index_id TO 1290; -- Run inside transaction BEGIN; CALL documentdb_api.insert_bulk('db', '{"insert":"salaries", "documents":[{ "_id" : 1 }]}'); ERROR: the insert procedure cannot be used in transactions. Please use the insert function instead END; -- exercise invalid insert syntax errors CALL documentdb_api.insert_bulk('db', NULL); ERROR: insert document cannot be NULL CALL documentdb_api.insert_bulk(NULL, '{"insert":"collection", "documents":[{"a":1}]}'); ERROR: Database name must not be NULL value CALL documentdb_api.insert_bulk('db', '{"documents":[{"a":1}]}'); ERROR: The BSON field 'insert.insert' is required but not provided CALL documentdb_api.insert_bulk('db', '{"insert":"collection"}'); ERROR: BSON field 'insert.documents' is missing but a required field CALL documentdb_api.insert_bulk('db', '{"insert":["collection"], "documents":[{"a":1}]}'); ERROR: Collection name contains an invalid data type array CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":{"a":1}}'); ERROR: The BSON field 'insert.documents' has an incorrect type 'object'; it should be of type 'array'. CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[{"a":1}], "extra":1}'); ERROR: The BSON field 'insert.extra' is not recognized as a valid field. CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[4]}'); ERROR: The BSON field 'insert.documents.0' has an incorrect type 'int'; it should be of type 'object'. CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[{"a":1}],"ordered":1}'); ERROR: The BSON field 'insert.ordered' has an incorrect type 'int'; it should be of type 'bool'. -- Disallow system.views, system.profile writes CALL documentdb_api.insert_bulk('db', '{"insert":"system.views", "documents":[{"a":1}],"ordered":true}'); ERROR: Unable to write data to specified location db.system.views CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" CALL documentdb_api.insert_bulk('db', '{"insert":"system.profile", "documents":[{"a":1}],"ordered":true}'); ERROR: Unable to write data to specified location db.system.profile CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- regular single-row insert CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":99,"a":99}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection0') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } (1 row) -- batch scenario set documentdb.batchWriteSubTransactionCount TO 5; -- when single batch has no issue CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl0", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "5" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('batchDB','batchColl0') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" } } (5 rows) -- when multiple batches have no issue CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl1", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":7}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "7" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('batchDB','batchColl1') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "7" } } (7 rows) -- when single batch has issue _id 2 is duplicated CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl2", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "2" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select document from documentdb_api.collection('batchDB','batchColl2') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } (2 rows) -- when multiple batches have no _id 2 is duplicated and _id 6 is duplicated CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl3", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":6}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "2" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select document from documentdb_api.collection('batchDB','batchColl3') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } (2 rows) -- when single batch has issue _id 2 is duplicated and ordered false CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl4", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}], "ordered":false}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "4" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "2" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select document from documentdb_api.collection('batchDB','batchColl4') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" } } (4 rows) -- when multiple batches have no _id 2 is duplicated and _id 6 is duplicated and ordered false CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl5", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":6}], "ordered":false}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "5" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "2" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" }, { "index" : { "$numberInt" : "6" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select document from documentdb_api.collection('batchDB','batchColl5') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "6" } } (5 rows) -- end batch test rest GUC set documentdb.batchWriteSubTransactionCount TO 512; -- Insert collection a db with same name and different case and collection being same. Expect to error CALL documentdb_api.insert_bulk('dB', '{"insert":"collection0", "documents":[{"_id":99,"a":99}]}'); ERROR: Database already exists but with a different case; existing entry: [db], attempted creation: [dB] CONTEXT: SQL statement "SELECT documentdb_api_internal.validate_dbname(NEW.database_name)" PL/pgSQL function trigger_validate_dbname() line 3 at PERFORM SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- Insert collection a db with same name and different case and collection being different. Expect to error CALL documentdb_api.insert_bulk('dB', '{"insert":"collection9", "documents":[{"_id":99,"a":99}]}'); ERROR: Database already exists but with a different case; existing entry: [db], attempted creation: [dB] CONTEXT: SQL statement "SELECT documentdb_api_internal.validate_dbname(NEW.database_name)" PL/pgSQL function trigger_validate_dbname() line 3 at PERFORM SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- Insert collection same db and new collection. CALL documentdb_api.insert_bulk('db', '{"insert":"collection8", "documents":[{"_id":99,"a":99}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection0') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (2 rows) CALL documentdb_api.insert_bulk('db', '{"insert":"collection1", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection1') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) CALL documentdb_api.insert_bulk('db', '{"insert":"collection2", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection2') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) CALL documentdb_api.insert_bulk('db', '{"insert":"collection3", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}],"ordered":false}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection3') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) -- shard the collection by _id select documentdb_api.shard_collection('db', 'collection4', '{"_id":"hashed"}', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection4", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection4", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection4') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) -- single-row insert with retry and auto-generated _id CALL documentdb_api.insert_bulk('db', '{"insert":"collection5", "documents":[{"a":1}]}',NULL,'insert-2'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection5", "documents":[{"a":1}]}',NULL,'insert-2'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select count(*) from documentdb_api.collection('db','collection5') where document @@ '{}'; count --------------------------------------------------------------------- 1 (1 row) -- multi-row insert collection different shards CALL documentdb_api.insert_bulk('db', '{"insert":"collection6", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection6') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) select document from documentdb_api.collection('db','collection6') where document @@ '{"a":1}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) select document from documentdb_api.collection('db','collection6') where document @@ '{"a":2}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (1 row) -- insert with documents in special section CALL documentdb_api.insert_bulk('db', '{"insert":"collection7"}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "2" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) select document from documentdb_api.collection('db','collection7') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) -- insert with both docs specified. CALL documentdb_api.insert_bulk('db', '{"insert":"collection9", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); ERROR: Both 'documents' and 'insert.documents' cannot be specified. -- insert with id undefined skips CALL documentdb_api.insert_bulk('db', '{"insert":"collection9", "documents":[{"_id":{ "$undefined": true } }]}'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) CALL documentdb_api.insert_bulk('db', '{"insert":"collection9"}', '{ "": [ {"_id":{ "$undefined": true } } ]}'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) -- insert with invalid database CALL documentdb_api.insert_bulk('Invalid Database Name', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); ERROR: Database Invalid Database Name has an invalid character CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" CALL documentdb_api.insert_bulk('db', '{"insert":"system.othercoll", "documents":[{"_id":1,"a":1}]}'); ERROR: System namespace provided is invalid: db.system.othercoll CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" CALL documentdb_api.insert_bulk('db', '{"insert":"random$name", "documents":[{"_id":1,"a":1}]}'); ERROR: Collection name provided is invalid: random$name CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" CALL documentdb_api.insert_bulk('db', '{"insert":".randomname", "documents":[{"_id":1,"a":1}]}'); ERROR: Collection names must not begin with the '.' character: .randomname CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" CALL documentdb_api.insert_bulk('verylongdatabasenameformeasuringthelimitsofdatabasenamesinmongodb', '{"insert":"coll", "documents":[{"_id":1,"a":1}]}'); ERROR: The provided database name exceeds the permitted length CALL documentdb_api.insert_bulk('verylongdatabasenameformeasuringlimitsofdatabasenamesinmongoda', '{"insert":"verylongcollectionnameformeasuringthelimitsofcollectionnamesinmongodb", "documents":[{"_id":1,"a":1}]}'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) -- when multiple batches and after multiple intermidate commits also things are fine SET documentdb.batchWriteSubTransactionCount TO 2; SELECT documentdb_api.create_collection('commitDb', 'commitColl'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- insert 10 documents CALL documentdb_api.insert_bulk('commitDb', '{"insert":"commitColl", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":7}, {"_id":8}, {"_id":9}, {"_id":10}]}'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "10" }, "ok" : { "$numberDouble" : "1.0" } } | t (1 row) -- first one is duplicate and rest 9 are inserted CALL documentdb_api.insert_bulk('commitDb', '{"insert":"commitColl", "documents":[{"_id":1}, {"_id":12}, {"_id":13}, {"_id":14}, {"_id":15}, {"_id":16}, {"_id":17}, {"_id":18}, {"_id":19}, {"_id":20}], "ordered":false}'); p_result | p_success --------------------------------------------------------------------- { "n" : { "$numberInt" : "9" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) -- total doc count should be 10+9 SELECT count(document) FROM documentdb_api.collection('commitDb','commitColl'); count --------------------------------------------------------------------- 19 (1 row) -- clean the collections SELECT documentdb_api.drop_collection('db', 'collection0'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection1'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection2'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection3'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection4'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection5'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection6'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection7'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db', 'collection8'); drop_collection --------------------------------------------------------------------- t (1 row) command_shard_commands.out000066400000000000000000000526661507310017400352230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 756000; SET documentdb.next_collection_id TO 7560; SET documentdb.next_collection_index_id TO 7560; ALTER SEQUENCE pg_dist_colocationid_seq RESTART WITH 7560; set documentdb.recreate_retry_table_on_shard to on; CREATE FUNCTION command_sharding_get_collectionInfo(dbname text DEFAULT 'comm_sh_coll', filterValue text DEFAULT '') RETURNS SETOF documentdb_core.bson AS $$ BEGIN RETURN QUERY WITH base AS (SELECT bson_dollar_project(bson_dollar_unwind(cursorpage, '$cursor.firstBatch'), '{ "cursor.firstBatch.idIndex": 0, "cursor.firstBatch.info.uuid": 0, "cursor.firstBatch.options": 0 }')::documentdb_core.bson AS doc FROM list_collections_cursor_first_page(dbname, FORMAT('{ "listCollections": 1, "filter": { %s }, "addDistributedMetadata": true }', filterValue)::documentdb_core.bson)) SELECT doc FROM base ORDER BY bson_orderby(doc, '{ "cursor.firstBatch.name": 1 }'); END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('comm_sh_coll', 'single_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('comm_sh_coll', 'comp_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- test new shard collection API - invalid inputs SELECT documentdb_api.shard_collection('{ }'); ERROR: shardCollection is a required field. SELECT documentdb_api.shard_collection('{ "key": { "_id": "hashed" } }'); ERROR: shardCollection is a required field. SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": 1 } }'); ERROR: only shard keys that use hashed are supported SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": 1 }'); ERROR: hashed shard keys cannot be declared unique. SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": -1 }'); ERROR: numInitialChunks must be a positive number SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": 5678 }'); ERROR: numInitialChunks must be less than 128. SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "collation": { "a": "b" } }'); ERROR: Collation for sharded collections is currently unsupported SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "timeseries": { "a": "b" } }'); ERROR: timeseries on shard collection is not supported yet SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.shard_collection('{ "shardCollection": ".single_shard", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.shard_collection('{ "shardCollection": ".", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.shard_collection('{ "shardCollection": "admin.system.collections", "key": { "_id": "hashed" } }'); ERROR: System namespace provided is invalid: admin.system.collections -- valid shard collection SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false }'); shard_collection --------------------------------------------------------------------- (1 row) -- cannot shard a sharded collection SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false }'); ERROR: Sharding already enabled for collection comm_sh_coll.single_shard with options { "_id": "comm_sh_coll.single_shard", "dropped" : false, "key" : { "a" : "hashed" }, "unique": false }. -- shard collection creates a new collection. SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.new_coll", "key": { "_id": "hashed" }, "unique": false }'); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) -- call listCollections and validate state. SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7561" }, "shardCount" : { "$numberInt" : "8" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT * FROM public.citus_tables tbls JOIN (SELECT 'documentdb_data.documents_' || collection_id AS mongo_table_name FROM documentdb_api_catalog.collections WHERE database_name = 'comm_sh_coll' UNION ALL SELECT 'documentdb_data.retry_' || collection_id AS mongo_table_name FROM documentdb_api_catalog.collections WHERE database_name = 'comm_sh_coll') colls ON tbls.table_name::text = colls.mongo_table_name ORDER BY colocation_id ASC; table_name | citus_table_type | distribution_column | colocation_id | table_size | shard_count | table_owner | access_method | mongo_table_name --------------------------------------------------------------------- documentdb_data.documents_7560 | distributed | | 7560 | 16 kB | 1 | documentdb_admin_role | heap | documentdb_data.documents_7560 documentdb_data.documents_7562 | distributed | | 7560 | 32 kB | 1 | documentdb_admin_role | heap | documentdb_data.documents_7562 documentdb_data.retry_7560 | distributed | | 7560 | 24 kB | 1 | documentdb_admin_role | heap | documentdb_data.retry_7560 documentdb_data.retry_7562 | distributed | | 7560 | 24 kB | 1 | documentdb_admin_role | heap | documentdb_data.retry_7562 documentdb_data.documents_7561 | distributed | shard_key_value | 7561 | 272 kB | 8 | documentdb_admin_role | heap | documentdb_data.documents_7561 documentdb_data.retry_7561 | distributed | shard_key_value | 7561 | 192 kB | 8 | documentdb_admin_role | heap | documentdb_data.retry_7561 documentdb_data.retry_7563 | distributed | shard_key_value | 7562 | 192 kB | 8 | documentdb_admin_role | heap | documentdb_data.retry_7563 documentdb_data.documents_7563 | distributed | shard_key_value | 7562 | 256 kB | 8 | documentdb_admin_role | heap | documentdb_data.documents_7563 (8 rows) -- shard with different shard count SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.comp_shard", "key": { "_id": "hashed" }, "unique": false, "numInitialChunks": 3 }'); shard_collection --------------------------------------------------------------------- (1 row) SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7563" }, "shardCount" : { "$numberInt" : "3" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7561" }, "shardCount" : { "$numberInt" : "8" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- unshard - should return to the original colocationGroup. SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.comp_shard" }'); unshard_collection --------------------------------------------------------------------- (1 row) -- unsupported option SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.new_coll", "toShard": "shard2" }'); ERROR: unshardCollection with toShard not supported yet SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7561" }, "shardCount" : { "$numberInt" : "8" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- cannot unshard an unsharded collection. SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.comp_shard" }'); ERROR: Collection comm_sh_coll.comp_shard is not sharded -- reshardCollection invalid apis SELECT documentdb_api.reshard_collection('{ }'); ERROR: reshardCollection is a required field. SELECT documentdb_api.reshard_collection('{ "key": { "_id": "hashed" } }'); ERROR: reshardCollection is a required field. SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": 1 } }'); ERROR: only shard keys that use hashed are supported SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": 1 }'); ERROR: hashed shard keys cannot be declared unique. SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": 5678 }'); ERROR: numInitialChunks must be less than 128. SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "collation": { "a": "b" } }'); ERROR: Collation for sharded collections is currently unsupported SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": -1 }'); ERROR: numInitialChunks must be a positive number SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.reshard_collection('{ "reshardCollection": ".single_shard", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.reshard_collection('{ "reshardCollection": ".", "key": { "_id": "hashed" } }'); ERROR: name needs to be fully qualified . SELECT documentdb_api.reshard_collection('{ "reshardCollection": "admin.system.collections", "key": { "_id": "hashed" } }'); ERROR: System namespace provided is invalid: admin.system.collections -- cannot reshard unsharded collection SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.comp_shard", "key": { "_id": "hashed" }, "unique": false }'); ERROR: Collection comm_sh_coll.comp_shard is not sharded -- should noop since options are the same SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false }'); NOTICE: Skipping Sharding for collection comm_sh_coll.single_shard as the same options were passed in. reshard_collection --------------------------------------------------------------------- (1 row) SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7561" }, "shardCount" : { "$numberInt" : "8" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- with force, should redo SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false, "forceRedistribution": true }'); reshard_collection --------------------------------------------------------------------- (1 row) SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7564" }, "shardCount" : { "$numberInt" : "8" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- reshard with new key allowed SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false, "numInitialChunks": 5 }'); reshard_collection --------------------------------------------------------------------- (1 row) SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7565" }, "shardCount" : { "$numberInt" : "5" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "a" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- reshard with same key and change chunks allowed SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false, "numInitialChunks": 2, "forceRedistribution": true }'); reshard_collection --------------------------------------------------------------------- (1 row) SELECT command_sharding_get_collectionInfo(); command_sharding_get_collectioninfo --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7560" }, "shardCount" : { "$numberInt" : "1" }, "name" : "comp_shard", "type" : "collection", "info" : { "readOnly" : false } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7562" }, "shardCount" : { "$numberInt" : "8" }, "name" : "new_coll", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "comm_sh_coll.$cmd.ListCollections", "firstBatch" : { "colocationId" : { "$numberInt" : "7566" }, "shardCount" : { "$numberInt" : "2" }, "name" : "single_shard", "type" : "collection", "info" : { "readOnly" : false, "shardKey" : { "a" : "hashed" } } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) commands_coll_mod.out000066400000000000000000000337771507310017400342160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 2500000; SET documentdb.next_collection_id TO 25000; SET documentdb.next_collection_index_id TO 25000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Create a collection SELECT documentdb_api.create_collection('commands','collModTest'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('commands','collModTest','{"_id":"1", "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Creating a regular and ttl index SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', documentdb_distributed_test_helpers.generate_create_index_arg('collModTest', 'a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', '{"createIndexes": "collModTest", "indexes": [{"key": {"b": 1}, "name": "b_ttl", "v" : 2, "expireAfterSeconds": 10000}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', '{"createIndexes": "collModTest", "indexes": [{"key": {"z": 1}, "name": "z_ttl_should_be_dropped_parallely", "v" : 2, "expireAfterSeconds": 1000}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Top level validations for collMod index options SELECT documentdb_api.coll_mod(NULL, 'collModTest', '{"collMod": "collModTest", "index": {}}'); ERROR: Database name must not be NULL SELECT documentdb_api.coll_mod('commands', NULL, '{"collMod": "collModTest", "index": {}}'); ERROR: collection name cannot be NULL SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "hello": 1}'); -- Unknown field ERROR: The BSON field 'collMod.hello' is not recognized as a valid field. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": 1}'); -- Type mismatch ERROR: The BSON field 'collMod.index' has an incorrect type 'int'; it should be of type 'object'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {}}'); ERROR: Must specify either index name or key pattern. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": []}'); ERROR: The BSON field 'collMod.index' has an incorrect type 'array'; it should be of type 'object'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "c_1"}}'); ERROR: no expireAfterSeconds or hidden field SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1}}'); ERROR: The BSON field 'collMod.index.name' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": 1}}'); ERROR: The BSON field 'collMod.index.keyPattern' has an incorrect type 'int'; it should be of type 'object'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "name": 1}}'); ERROR: The BSON field 'collMod.index.name' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": 1, "name": "c_1"}}'); ERROR: The BSON field 'collMod.index.keyPattern' has an incorrect type 'int'; it should be of type 'object'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "name": "c_1"}}'); ERROR: Both name and key pattern cannot be present SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}}}'); ERROR: no expireAfterSeconds or hidden field SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": true}}'); ERROR: The BSON field 'collMod.index.name' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": {}}}'); ERROR: The BSON field 'collMod.index.name' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": "expire"}}'); ERROR: The BSON field 'collMod.index.name' has an incorrect type 'int'; it should be of type 'string'. -- Inserting some documents SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 0, "b": { "$date": { "$numberLong": "-1000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 1, "b": { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 2, "b": { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 3, "b": { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 4, "b": { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 5, "b": [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 6, "b": [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 7, "b": [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 8, "b": true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 9, "b": "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert a doc with current time when the test is running -- Function to insert a doc in collection with current time and given id CREATE OR REPLACE FUNCTION insert_doc_with_current_time(id numeric) RETURNS void AS $fn$ DECLARE epoch_bgn text; bgn_epoch_sec numeric; bgn_usec numeric; bgn_epoch_msec numeric; BEGIN SELECT extract(epoch from clock_timestamp()) into epoch_bgn; SELECT split_part(epoch_bgn, '.', 1)::numeric into bgn_epoch_sec; SELECT split_part(epoch_bgn, '.', 2)::numeric into bgn_usec; bgn_epoch_msec := bgn_epoch_sec * 1000 + ROUND(bgn_usec / 1000); EXECUTE format($$ SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id": %s, "b": { "$date": { "$numberLong": "%s" } } }', NULL)$$, id, bgn_epoch_msec); END $fn$ LANGUAGE plpgsql; SELECT insert_doc_with_current_time(100); insert_doc_with_current_time --------------------------------------------------------------------- (1 row) -- Test TTL deletion with current setting it should not delete the current timestamp doc with _id: 100 CALL documentdb_api_internal.delete_expired_rows(); SELECT object_id from documentdb_api.collection('commands', 'collModTest'); object_id --------------------------------------------------------------------- { "" : "1" } { "" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } { "" : { "$numberInt" : "100" } } (5 rows) -- Updating ttl expiration time to 2 secs SELECT * FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'b_ttl' AND (index_spec).index_expire_after_seconds = 2; -- Before update collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- (0 rows) SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "b_ttl", "expireAfterSeconds": 2}}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "expireAfterSeconds_old" : { "$numberLong" : "10000" }, "expireAfterSeconds_new" : { "$numberDouble" : "2.0" } } (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'b_ttl' AND (index_spec).index_expire_after_seconds = 2; -- After update collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 25001 | 25003 | (b_ttl,"{ ""b"" : { ""$numberInt"" : ""1"" } }",,,,,2,2,,) | t (1 row) SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) -- Now even _id: 100 should get deleted CALL documentdb_api_internal.delete_expired_rows(); SELECT object_id from documentdb_api.collection('commands', 'collModTest'); object_id --------------------------------------------------------------------- { "" : "1" } { "" : { "$numberInt" : "4" } } { "" : { "$numberInt" : "8" } } { "" : { "$numberInt" : "9" } } (4 rows) -- Errors SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "a_1", "expireAfterSeconds": 2000}}'); -- Not a TTL index to be modified ERROR: no expireAfterSeconds field to update SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "a_1", "hidden": true}}'); -- Hidden is not supported yet coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : false, "hidden_new" : true } (1 row) SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "c_1", "expireAfterSeconds": 1000}}'); -- index not found ERROR: cannot find index c_1 for ns commands.collModTest SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "expireAfterSeconds": 1000}}'); -- index not found ERROR: cannot find index { "c" : 1 } for ns commands.collModTest commands_collmod_tests_hidden.out000066400000000000000000000703421507310017400366010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 920000; SET documentdb.next_collection_id TO 9200; SET documentdb.next_collection_index_id TO 9200; SELECT documentdb_api.create_collection('collmod','coll_mod_test_hidden'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT COUNT(documentdb_api.insert_one('collmod','coll_mod_test_hidden', FORMAT('{"_id":"%s", "a": %s }', i, i )::documentdb_core.bson)) FROM generate_series(1, 100) i; count --------------------------------------------------------------------- 100 (1 row) -- cannot create an index as hidden SELECT documentdb_api_internal.create_indexes_non_concurrently('collmod', '{"createIndexes": "coll_mod_test_hidden", "indexes": [{"key": {"a": 1}, "name": "my_idx_1", "hidden": true }]}'); ERROR: hidden indexes are not supported yet. SELECT documentdb_api_internal.create_indexes_non_concurrently('collmod', '{"createIndexes": "coll_mod_test_hidden", "indexes": [{"key": {"a": 1}, "name": "my_idx_1" }]}', TRUE); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) set citus.show_shards_for_app_name_prefixes to '*'; \d documentdb_data.documents_9201 Table "documentdb_data.documents_9201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '9201'::bigint) \d documentdb_data.documents_9201_920002 Table "documentdb_data.documents_9201_920002" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920002" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202_920002" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check_920002" CHECK (shard_key_value = '9201'::bigint) ANALYZE documentdb_data.documents_9201; -- get list index output SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "my_idx_1" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) -- the index is used for queries set enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_9201_920002 collection Recheck Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (4 rows) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { "$numberInt" : "1" } } (1 row) -- now hide the index SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": true } }'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : false, "hidden_new" : true } (1 row) -- print the status \d documentdb_data.documents_9201 Table "documentdb_data.documents_9201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) INVALID Check constraints: "shard_key_value_check" CHECK (shard_key_value = '9201'::bigint) \d documentdb_data.documents_9201_920002 Table "documentdb_data.documents_9201_920002" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920002" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202_920002" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) INVALID Check constraints: "shard_key_value_check_920002" CHECK (shard_key_value = '9201'::bigint) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "my_idx_1", "hidden" : true } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) -- the index is not used for queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Index Scan using _id_ on documents_9201_920002 collection Index Cond: (shard_key_value = '9201'::bigint) Filter: (document @= '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (3 rows) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); document --------------------------------------------------------------------- { "_id" : "1", "a" : { "$numberInt" : "1" } } (1 row) -- cannot hide the primary key index (since it's unique) SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "_id_", "hidden": true } }'); ERROR: cannot modify hidden field of the _id_ index -- now inserts done while the index is hidden do get factored into the final results. SELECT documentdb_api.insert_one('collmod','coll_mod_test_hidden', '{"_id":"101", "a": 101 }'::documentdb_core.bson); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 101 } }'); document --------------------------------------------------------------------- { "_id" : "101", "a" : { "$numberInt" : "101" } } (1 row) -- unhide the index SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": false } }'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : true, "hidden_new" : false } (1 row) -- print the status: index is no longer invalid \d documentdb_data.documents_9201 Table "documentdb_data.documents_9201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '9201'::bigint) \d documentdb_data.documents_9201_920002 Table "documentdb_data.documents_9201_920002" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920002" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9202_920002" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check_920002" CHECK (shard_key_value = '9201'::bigint) -- hidden is no longer in the options SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "my_idx_1" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) -- can use the index again EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on documents_9201_920002 collection Recheck Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document @= '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (4 rows) -- the row shows up from the index SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 101 } }'); document --------------------------------------------------------------------- { "_id" : "101", "a" : { "$numberInt" : "101" } } (1 row) -- shard the collection. SELECT documentdb_api.shard_collection('{ "shardCollection": "collmod.coll_mod_test_hidden", "key": { "_id": "hashed" }, "numInitialChunks": 3 }'); shard_collection --------------------------------------------------------------------- (1 row) set citus.explain_all_tasks to on; BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 3 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920004 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920005 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (21 rows) ROLLBACK; -- now hide the index again (with debug logs) set client_min_messages to debug1; SET citus.multi_shard_modify_mode TO 'sequential'; SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": true } }'); DEBUG: executing "SELECT index_id, index_spec, index_is_valid FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $2 AND (index_spec).index_name = $1;" via SPI DEBUG: executing "WITH r1 AS (SELECT MIN($1 || '_' || sh.shardid) AS shardName FROM pg_dist_shard sh JOIN pg_dist_placement pl on pl.shardid = sh.shardid WHERE logicalrelid = $1::regclass GROUP by groupid) SELECT ARRAY_AGG(r1.shardName) FROM r1" via SPI DEBUG: Executing command_node_worker on table documentdb_data.documents_9201_920004 DEBUG: executing "SELECT array_agg(shardid) FROM pg_dist_shard WHERE logicalrelid = $1" via SPI DEBUG: executing "UPDATE pg_catalog.pg_index SET indisvalid = $1 WHERE indexrelid = $2 RETURNING indexrelid" via SPI DEBUG: executing "UPDATE pg_catalog.pg_index SET indisvalid = $1 WHERE indexrelid = $2 RETURNING indexrelid" via SPI DEBUG: executing "UPDATE pg_catalog.pg_index SET indisvalid = $1 WHERE indexrelid = $2 RETURNING indexrelid" via SPI DEBUG: executing "UPDATE pg_catalog.pg_index SET indisvalid = $1 WHERE indexrelid = $2 RETURNING indexrelid" via SPI DEBUG: Skipping command_node_worker on table documentdb_data.documents_9201_920005 since not in chosen shards DEBUG: Skipping command_node_worker on table documentdb_data.documents_9201_920006 since not in chosen shards DEBUG: executing "UPDATE documentdb_api_catalog.collection_indexes SET index_spec = $1 WHERE index_id = $2;" via SPI coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : false, "hidden_new" : true } (1 row) reset client_min_messages; reset citus.multi_shard_modify_mode; \d documentdb_data.documents_9201 Table "documentdb_data.documents_9201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) INVALID Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) \d documentdb_data.documents_9201_920003 \d documentdb_data.documents_9201_920004 Table "documentdb_data.documents_9201_920004" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920004" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203_920004" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204_920004" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) INVALID Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) \d documentdb_data.documents_9201_920005 Table "documentdb_data.documents_9201_920005" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920005" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203_920005" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204_920005" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) INVALID Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "my_idx_1", "hidden" : true } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 3 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9201_920004 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9201_920005 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_9201_920006 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (15 rows) ROLLBACK; -- unhide the index again SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": false } }'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" }, "hidden_old" : true, "hidden_new" : false } (1 row) \d documentdb_data.documents_9201 Table "documentdb_data.documents_9201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) \d documentdb_data.documents_9201_920003 \d documentdb_data.documents_9201_920004 Table "documentdb_data.documents_9201_920004" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920004" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203_920004" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204_920004" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) \d documentdb_data.documents_9201_920005 Table "documentdb_data.documents_9201_920005" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "collection_pk_9201_920005" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_9203_920005" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_9204_920005" documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = documentdb_api_internal.get_shard_key_value('{ "_id" : "hashed" }'::documentdb_core.bson, 9201::bigint, document)) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "collmod.coll_mod_test_hidden", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "my_idx_1" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 3 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920004 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920005 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_9201_920006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (21 rows) ROLLBACK; commands_create_drop_indexes_a.out000066400000000000000000000335771507310017400367320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 130000; SET documentdb.next_collection_id TO 13000; SET documentdb.next_collection_index_id TO 13000; set search_path to documentdb_core,documentdb_api,documentdb_api_catalog; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["*"]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- t | 1 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Whatever rest of the arguments are, having "*" as the first one would drop -- all indexes. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["*", "_id_", "index_dne"]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- t | 1 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Given that "*" is not the first item of the array, we should interpret it -- as a plain index name and throw an error complaining that index doesn't exist. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["my_idx_1", "*"]}'); ERROR: index not found with name [*] SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- f | 2 t | 1 (2 rows) -- cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": "_id_"}'); ERROR: cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["_id_", "*"]}'); ERROR: cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": "*"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- t | 1 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_by_key", "indexes": [ {"key": {"a": 1, "c.e": 1}, "name": "idx_1"}, {"key": {"b.$**": 1}, "name": "idx_2"} ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- no such index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"c.d": 1}}'); ERROR: Unable to locate index using the provided key: { "c.d" : 1 } -- cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"_id": 1}}'); ERROR: cannot drop _id index -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 13001 | 13007 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 13001 | 13008 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "c.e" : { "$numberInt" : "1" } }, "name" : "idx_1" } | t 13001 | 13009 | { "v" : { "$numberInt" : "2" }, "key" : { "b.$**" : { "$numberInt" : "1" } }, "name" : "idx_2" } | t (3 rows) -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'drop_by_key') ORDER BY indexrelid; indexrelid | indisvalid | indisready --------------------------------------------------------------------- documentdb_data.collection_pk_13001 | t | t documentdb_data.documents_rum_index_13008 | t | t documentdb_data.documents_rum_index_13009 | t | t (3 rows) -- invalid key spec document but would just complain "no such index" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"$**.c.d": 1}}'); ERROR: Unable to locate index using the provided key: { "$**.c.d" : 1 } -- only drops "idx_2" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": "*", "index": {"a": 1, "c.e": 1}, "index": {"b.$**": 1}}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 13001 | 13007 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 13001 | 13008 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "c.e" : { "$numberInt" : "1" } }, "name" : "idx_1" } | t (2 rows) -- incorrect ordering of the (compound) keys, so cannot match "idx_1" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"c.e": 1, "a": 1}}'); ERROR: Unable to locate index using the provided key: { "c.e" : 1, "a" : 1 } -- now drop "idx_1" too, but specify collection name using "deleteIndexes" CALL documentdb_api.drop_indexes('db', '{"deleteIndexes": "drop_by_key", "index": {"a": 1, "c.e": 1}}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 13001 | 13007 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t (1 row) -- Show that having a record indicating an invalid collection index with the -- same index name wouldn't cause any problems when creating the index. SELECT documentdb_api.create_collection('db', 'collection_1000'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) SELECT collection_id, 1000, ('idx_1', '{}', null, null, null, null, 2, null, null, null)::documentdb_api_catalog.index_spec_type, false FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1000'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1000", "indexes": [{"key": {"a": 1}, "name": "idx_1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- delete the fake invalid entry that we inserted above DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'idx_1' AND index_id = 1000 AND (index_spec).index_key operator(documentdb_core.=) '{}' AND index_is_valid = false AND collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1000'); -- Show that having a record indicating an invalid collection index with the -- same index key wouldn't cause any problems when creating the index. SELECT documentdb_api.create_collection('db', 'collection_1001'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) SELECT collection_id, 1000, ('idx_1', '{"a": 1}', null, null, null, null, 2, null, null, null)::documentdb_api_catalog.index_spec_type, false FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1001'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1001", "indexes": [{"key": {"a": 1}, "name": "idx_2"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- delete the fake invalid entry that we inserted above DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'idx_1' AND index_id = 1000 AND (index_spec).index_key operator(documentdb_core.=) '{"a": 1}' AND index_is_valid = false AND collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1001'); commands_create_drop_indexes_b.out000066400000000000000000000327451507310017400367270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 140000; SET documentdb.next_collection_id TO 14000; SET documentdb.next_collection_index_id TO 14000; ---- some other tests using createIndexes & dropIndexes ---- -- test 1 SELECT documentdb_api.create_collection('mydb', 'collection_2'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"} ] }' ,true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', 'my_idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_14002 ON documentdb_data.documents_14001 USING documentdb_rum (document bson_rum_single_path_ops (path=a, iswildcard='true', tl='2699')) (1 row) CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": "my_idx_1" }' ); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT count(*)=0 AS index_does_not_exist FROM documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', 'my_idx_1'); index_does_not_exist --------------------------------------------------------------------- t (1 row) -- test 2 SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.b.$**": 1}, "name": "my_idx_1"}, {"key": {"$**": 1}, "name": "my_idx_2"}, {"key": {"c.d": 1}, "name": "my_idx_3"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_indexes.index_name, documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', documentdb_indexes.index_name) FROM (VALUES ('my_idx_1'), ('my_idx_2'), ('my_idx_3')) documentdb_indexes(index_name) ORDER BY documentdb_indexes.index_name; index_name | documentdb_index_get_pg_def --------------------------------------------------------------------- my_idx_1 | CREATE INDEX documents_rum_index_14003 ON documentdb_data.documents_14001 USING documentdb_rum (document bson_rum_single_path_ops (path='a.b', iswildcard='true', tl='2699')) my_idx_2 | CREATE INDEX documents_rum_index_14004 ON documentdb_data.documents_14001 USING documentdb_rum (document bson_rum_single_path_ops (path='', iswildcard='true', tl='2699', wkl='200')) my_idx_3 | CREATE INDEX documents_rum_index_14005 ON documentdb_data.documents_14001 USING documentdb_rum (document bson_rum_single_path_ops (path='c.d', tl='2699')) (3 rows) -- not the same index since this specifies wildcardProjection SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"$**": 1}, "name": "my_idx_4", "wildcardProjection": {"a": 0}} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": ["my_idx_1"] }' ); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "5" } } (1 row) CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": ["my_idx_2", "my_idx_3"] }' ); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "4" } } (1 row) SELECT count(*)=0 AS index_does_not_exist FROM ( SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', documentdb_indexes.index_name) FROM (VALUES ('my_idx_1'), ('my_idx_2'), ('my_idx_3')) documentdb_indexes(index_name) ) q; index_does_not_exist --------------------------------------------------------------------- t (1 row) -- Cannot SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if collection -- was created before and if we're really creating an index. BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"}, {"key": {"c.d": 1}, "name": "new_idx_2"} ] }', false ); ERROR: Creation of new indexes on the specified existing collection mydb.collection_2 is not permitted within a multi-document transaction. ROLLBACK; -- would only create idx_2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_200", "indexes": [{"key": {"$**": 1}, "name": "idx_1"}], "indexes": [{"key": {"$**": 1}, "name": "idx_2"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT (index_spec).index_name FROM documentdb_api_catalog.collection_indexes WHERE collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'collection_200' AND database_name = 'db') ORDER BY 1; index_name --------------------------------------------------------------------- _id_ idx_2 (2 rows) -- Can SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if we're not -- creating any indexes, even if we're in a xact block. BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"$**": 1}, "name": "my_idx_4", "wildcardProjection": {"a": 0}} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ROLLBACK; -- Can SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if collection -- wasn't created before. -- i) using create_collection() BEGIN; SELECT documentdb_api.create_collection('mydb', 'collection_new'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ROLLBACK; -- ii) using a command that implicitly creates the collection -- if it doesn't exist, e.g.: insert() BEGIN; SELECT documentdb_api.insert_one('mydb','collection_new',' {"_id" : 1, "item" : "bread"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ROLLBACK; -- iii) implicitly creating via create_indexes() BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ROLLBACK; BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"c.d": 1}, "name": "new_idx_2"} ] }' ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ROLLBACK; commands_create_index_geospatial.out000066400000000000000000003421201507310017400372510ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167200; SET documentdb.next_collection_id TO 16720; SET documentdb.next_collection_index_id TO 16720; SELECT documentdb_api.create_collection('db', '2dindextest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db', '2dsphereindextest') IS NOT NULL; NOTICE: creating collection ?column? --------------------------------------------------------------------- t (1 row) -- Test invalid 2d index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "unique": true }]}', true); -- 2d with unique ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "unique" : true }:Index type '2d' does not support the unique option SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": "2d"}, "name": "my_2d_a_idx" }]}', true); -- Multi 2d ERROR: Error in specification { "key" : { "a" : "2d", "b" : "2d" }, "name" : "my_2d_a_idx" }:Cannot contain more than one geo fields SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": 1}, "name": "my_2d_a_idx" } ]}', true); -- Multi 2d ERROR: Compound 2d indexes are not supported yet SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"b": 1, "a": "2d"}, "name": "my_2d_a_idx" }]}', true); -- Multi 2d and 2d index is not the first one ERROR: Error in specification { "key" : { "b" : 1, "a" : "2d" }, "name" : "my_2d_a_idx" }:The 2d field must be the first in the index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a.$**": "2d"}, "name": "my_2d_a_idx" }]}', true); -- 2d with wildcard ERROR: Error in specification { "key" : { "a.$**" : "2d" }, "name" : "my_2d_a_idx" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "max": -190 } ]}', true); -- 2d with max -170 and min -180 (default) ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "max" : -190 }:The specified region for hash must be valid with a positive area, but the provided coordinates [-180, -190] are invalid. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "min": 190 } ]}', true); -- 2d with min 190 and max 180 (default) ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "min" : 190 }:The specified region for hash must be valid with a positive area, but the provided coordinates [190, 180] are invalid. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "max": 180, "min": 180} ]}', true); -- 2d with min and max equal to 180 ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "max" : 180, "min" : 180 }:The specified region for hash must be valid with a positive area, but the provided coordinates [180, 180] are invalid. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "expireAfterSeconds": 20 } ]}', true); -- With TTL ERROR: Creating a 2d index as ttl index is not supported. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": "text"}, "name": "my_2d_a_idx" } ]}', true); -- 2d with text ERROR: Error in specification { "key" : { "a" : "2d", "b" : "text" }, "name" : "my_2d_a_idx" }:It is not allowed to enable more than one index plugin for the same index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b.$**": 1}, "name": "my_2d_a_idx" } ]}', true); -- 2d followed by wildcard ERROR: Error in specification { "key" : { "a" : "2d", "b.$**" : 1 }, "name" : "my_2d_a_idx" }:wildcard indexes do not allow compounding SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "bits": 0 } ]}', true); -- bits 0 ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "bits" : 0 }:The number of bits for the hash must be greater than 0 and no more than 32, but 0 bits were provided instead. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "bits": 33 } ]}', true); -- bits more than 32 ERROR: Error in specification { "key" : { "a" : "2d" }, "name" : "my_2d_a_idx", "bits" : 33 }:The number of bits for the hash must be greater than 0 and no more than 32, but 33 bits were provided instead. -- Test invalid 2dsphere index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "unique": true }]}', true); -- 2dsphere with unique ERROR: Error in specification { "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "unique" : true }:Index type '2dsphere' does not support the unique option SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b": 1}, "name": "my_2ds_a_idx" } ]}', true); -- Compound 2dsphere ERROR: Error in specification { "key" : { "a" : "2dsphere", "b" : 1 }, "name" : "my_2ds_a_idx" }:Compound Regular & 2dsphere indexes are not supported yet SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"b": 1, "a": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); -- Compound 2dsphere with 1 being regular index ERROR: Error in specification { "key" : { "b" : 1, "a" : "2dsphere" }, "name" : "my_2ds_a_idx" }:Compound Regular & 2dsphere indexes are not supported yet SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a.$**": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); -- 2dsphere with wildcard ERROR: Error in specification { "key" : { "a.$**" : "2dsphere" }, "name" : "my_2ds_a_idx" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "coarsestIndexedLevel": -1 } ]}', true); -- 2dsphere with coarestIndexedLevel invalid value ERROR: Error in specification { "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "coarsestIndexedLevel" : -1 }:coarsestIndexedLevel must be greater than or equal to 0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "finestIndexedLevel": 31 } ]}', true); -- 2dsphere with finestIndexedLevel invalid value ERROR: Error in specification { "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "finestIndexedLevel" : 31 }:finestIndexedLevel must not exceed 30 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "coarsestIndexedLevel": 32, "finestIndexedLevel": 30 } ]}', true); -- 2dsphere with finestIndexedLevel invalid value ERROR: Error in specification { "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "coarsestIndexedLevel" : 32, "finestIndexedLevel" : 30 }:finestIndexedLevel must be greater than or equal to coarsestIndexedLevel SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "expireAfterSeconds": 20 } ]}', true); -- With TTL ERROR: Creating a 2dsphere index as ttl index is not supported. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b": "text"}, "name": "my_2ds_a_idx" } ]}', true); -- 2dsphere with different ERROR: Error in specification { "key" : { "a" : "2dsphere", "b" : "text" }, "name" : "my_2ds_a_idx" }:It is not allowed to enable more than one index plugin for the same index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b.$**": 1}, "name": "my_2ds_a_idx" } ]}', true); -- 2dsphere followed by wildcard ERROR: Error in specification { "key" : { "a" : "2dsphere", "b.$**" : 1 }, "name" : "my_2ds_a_idx" }:wildcard indexes do not allow compounding -- Test valid 2d & 2dsphere index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"b.c": "2d"}, "name": "my_2d_b_c_idx" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"d": "2d"}, "name": "my_2d_d_idx", "min": -100, "max": 100 }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"e": "2d"}, "name": "my_2d_e_idx", "bits": 32 } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"pfe": "2d"}, "name": "my_2d_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere" }, "name": "my_2ds_a_idx" } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"b.c": "2dsphere" }, "name": "my_2ds_bc_idx", "coarsestIndexedLevel": 20 } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"c": "2dsphere" }, "name": "my_2ds_c_idx", "coarsestIndexedLevel": 5, "finestIndexedLevel": 25 } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"d": "2dsphere" }, "name": "my_2ds_d_idx", "finestIndexedLevel": 25 } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"e": "2dsphere", "f": "2dsphere" }, "name": "my_2ds_ef_idx" } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"g": "2dsphere", "h": "2dsphere" }, "name": "my_2ds_gh_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', '2dindextest') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 16720 | 16720 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 16720 | 16722 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "2d" }, "name" : "my_2d_a_idx" } | t 16720 | 16723 | { "v" : { "$numberInt" : "2" }, "key" : { "b.c" : "2d" }, "name" : "my_2d_b_c_idx" } | t 16720 | 16724 | { "v" : { "$numberInt" : "2" }, "key" : { "d" : "2d" }, "name" : "my_2d_d_idx", "min" : { "$numberDouble" : "-100.0" }, "max" : { "$numberDouble" : "100.0" } } | t 16720 | 16725 | { "v" : { "$numberInt" : "2" }, "key" : { "e" : "2d" }, "name" : "my_2d_e_idx", "bits" : { "$numberDouble" : "32.0" } } | t 16720 | 16726 | { "v" : { "$numberInt" : "2" }, "key" : { "pfe" : "2d" }, "name" : "my_2d_pfe_idx", "partialFilterExpression" : { "region" : { "$eq" : "USA" } } } | t (6 rows) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', '2dsphereindextest') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 16721 | 16721 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 16721 | 16727 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "2dsphere" }, "name" : "my_2ds_a_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t 16721 | 16728 | { "v" : { "$numberInt" : "2" }, "key" : { "b.c" : "2dsphere" }, "name" : "my_2ds_bc_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" }, "coarsestIndexedLevel" : { "$numberInt" : "20" } } | t 16721 | 16729 | { "v" : { "$numberInt" : "2" }, "key" : { "c" : "2dsphere" }, "name" : "my_2ds_c_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" }, "finestIndexedLevel" : { "$numberInt" : "25" }, "coarsestIndexedLevel" : { "$numberInt" : "5" } } | t 16721 | 16730 | { "v" : { "$numberInt" : "2" }, "key" : { "d" : "2dsphere" }, "name" : "my_2ds_d_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" }, "finestIndexedLevel" : { "$numberInt" : "25" } } | t 16721 | 16731 | { "v" : { "$numberInt" : "2" }, "key" : { "e" : "2dsphere", "f" : "2dsphere" }, "name" : "my_2ds_ef_idx", "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t 16721 | 16732 | { "v" : { "$numberInt" : "2" }, "key" : { "g" : "2dsphere", "h" : "2dsphere" }, "name" : "my_2ds_gh_pfe_idx", "partialFilterExpression" : { "region" : { "$eq" : "USA" } }, "2dsphereIndexVersion" : { "$numberInt" : "3" } } | t (7 rows) -- 2d index strict mode insert restrictions SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": "Hello" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "location object expected, location array not in correct format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "location object expected, location array not in correct format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": false } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "location object expected, location array not in correct format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": null } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "location object expected, location array not in correct format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$undefined" : true } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "location object expected, location array not in correct format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386138141" }, "errmsg" : "Geo field contains only one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberLong": "1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386138141" }, "errmsg" : "Geo field contains only one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberDouble": "1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386138141" }, "errmsg" : "Geo field contains only one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberDecimal": "1" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386138141" }, "errmsg" : "Geo field contains only one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": "Invalid" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": false } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": null } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": { "$undefined": true } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": "Invalid", "z": 10 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) -- 2dsphere index strict mode insert restriction SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : "Hello" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : \"Hello\"" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : true" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : false }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : false" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberInt": "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : 1" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberLong": "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : 1" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberDouble": "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : 1" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberDecimal": "1" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "The Failed to retrieve geo keys { _id: 1 } geo element should be provided as either an array or an object: a : 1" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "x": 1 } }', NULL); -- Legacy object invalid format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"x\" : 1 }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "x": 1, "y": "Text" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"x\" : 1, \"y\" : \"Text\" }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [1] }', NULL); -- Legacy array invalid format insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [1, "text"] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "point"} }', NULL); -- Wrong type case-sensitive insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"point\" }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point"} }', NULL); -- coordinates missing insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point must be either an array or an object" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coords": [1, 2]} }', NULL); -- Invalid 'coords' insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point must be either an array or an object" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [1, "hello"]} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point must be either an array or an object" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [[1 , 2], [3, 4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multipoint", "coordinates": [[1 , 2], [3, 4]] } }', NULL); -- Wrong case sensitive type insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"Multipoint\", \"coordinates\" : [ [ 1, 2 ], [ 3, 4 ] ] }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [3, 4] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates need to be provided in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [[1 , "Hello"], [3, 4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates should always be provided as an array format containing coordinate values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } MultiPoint coordinates require a minimum of one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Linestring", "coordinates": [[1,2], [3,4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"Linestring\", \"coordinates\" : [ [ 1, 2 ], [ 3, 4 ] ] }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates should always be provided as an array format containing coordinate values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": [[1, 2], [1, 2]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": [[1, 2], [1, 2]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multilinestring", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"Multilinestring\", \"coordinates\" : [ ] }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[1,2], [3,4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates need to be provided in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Coordinates for Failed to retrieve geo keys { _id: 1 } MultiLineString must be provided as an array" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[[1, 2], [1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[[1, 2], [1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON LineString requires a minimum of two vertices: [ [ 1, 2 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } MultiLineString coordinates require a minimum of one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "polygon", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"polygon\", \"coordinates\" : [ ] }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Polygon Failed to retrieve geo keys { _id: 1 } does not contain any loops." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Coordinates for Failed to retrieve geo keys { _id: 1 } Polygon must be provided as an array" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [1, 2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates should always be provided as an array format containing coordinate values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[1, 2]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates need to be provided in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "A Failed to retrieve geo keys { _id: 1 } Loop must contain no fewer than three distinct vertices: [ [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop structure remains unclosed: [ [ 1, 2 ], [ 1, 2 ], [ 1, 3 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3], [1,2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "A Failed to retrieve geo keys { _id: 1 } Loop must contain no fewer than three distinct vertices: [ [ 1, 2 ], [ 1, 2 ], [ 1, 3 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [1.000000, 1.000000], [1.000000, 5.000000], [3.000000, 4.000000], [0.000000, 3.000000], [1.000000, 1.000000] ] - Edges cross" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] } }', NULL); -- self intersecting polygon with 0 geometrical area insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [0.000000, 0.000000], [-2.000000, -1.000000], [1.000000, 1.000000], [0.000000, 1.000000], [0.000000, 0.000000] ] - Edges cross" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]] } }', NULL); -- self intersecting polygon with non-zero geometrical area insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [1.000000, 0.000000], [0.000000, 10.000000], [10.000000, 10.000000], [0.000000, 0.000000], [1.000000, 0.000000] ] - Edges cross" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]] } }', NULL); -- hole edge lies on outer ring edge insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 10.000000], [75.000000, 25.000000], [75.000000, 75.000000], [0.000000, 70.000000], [0.000000, 10.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 80.000000], [80.000000, 80.000000], [80.000000, 0.000000], [0.000000, 0.000000] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]] } }', NULL); -- hole shares an edge with outer ring insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [0.000000, 0.000000], [75.000000, 25.000000], [75.000000, 75.000000], [0.000000, 80.000000], [0.000000, 0.000000] ] first loop: [ [0.000000, 0.000000], [0.000000, 80.000000], [80.000000, 80.000000], [80.000000, 0.000000], [0.000000, 0.000000] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[10, 10], [10, 70], [75, 75], [75, 25], [10, 10]],[[10,20], [10,30], [50, 50], [10, 20]]] } }', NULL); -- 3rd ring edge lies on 2nd ring edge insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Secondary loops are outside the boundaries of the primary exterior loop - all secondary loops are required to be holes: [ [10.000000, 20.000000], [50.000000, 50.000000], [10.000000, 30.000000], [10.000000, 20.000000] ] first loop: [ [10.000000, 10.000000], [75.000000, 25.000000], [75.000000, 75.000000], [10.000000, 70.000000], [10.000000, 10.000000] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Secondary loops are outside the first exterior loop and must instead represent holes" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [ 1, 2 ], [ 2, 3 ], [ 1, 2 ], [ 3, 4 ], [ 1, 2 ] ] Duplicate vertices: 0 and 2" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multipolygon", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Unknown GeoJSON data type: { \"type\" : \"Multipolygon\", \"coordinates\" : [ ] }" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } MultiPolygon coordinates require a minimum of one element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": "non-array" } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Coordinates for Failed to retrieve geo keys { _id: 1 } MultiPolygon must be provided as an array" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [1, 2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Coordinates for Failed to retrieve geo keys { _id: 1 } Polygon must be provided as an array" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[1, 2]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates should always be provided as an array format containing coordinate values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeoJSON coordinates need to be provided in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop structure remains unclosed: [ [ 1, 2 ], [ 1, 2 ], [ 1, 3 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3], [1,2]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "A Failed to retrieve geo keys { _id: 1 } Loop must contain no fewer than three distinct vertices: [ [ 1, 2 ], [ 1, 2 ], [ 1, 3 ], [ 1, 2 ] ]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [1.000000, 1.000000], [1.000000, 5.000000], [3.000000, 4.000000], [0.000000, 3.000000], [1.000000, 1.000000] ] - Edges cross" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Secondary loops are outside the first exterior loop and must instead represent holes" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Loop is not valid: [ [ 1, 2 ], [ 2, 3 ], [ 1, 2 ], [ 3, 4 ], [ 1, 2 ] ] Duplicate vertices: 0 and 2" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": {} } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeometryCollection requires geometries in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeometryCollection must contain a minimum of one geometry element" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "coordinates": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } GeometryCollection requires geometries in an array format" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [1, 2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Element 0 of \"geometries\" is not an object" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [1, 2]}, 2] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Element 1 of \"geometries\" is not an object" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": ["Hello", 2]}] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) -- Multi key failure cases SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], "Invalid point" ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "386400285" }, "errmsg" : "Expected 'array' or 'document' type but found 'string' type" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, true] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, false] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, null] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, "point"] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, { "$undefined": true }] ] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{"b" : [ { "c": [10, 20] }, { "c": { "long": "100", "lat": "100" } }, [ 30, "text"] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "352583709" }, "errmsg" : "Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes." } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [{"type": "Point", "coordinates": [10, 20]}, {"type": "Point", "coordinates": [10, 20]}] }', NULL); -- This is not supported as multi key insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [[10, 20], [20, 20]] }', NULL); -- This is not supported as multi key legacy insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] }', NULL); -- This is not supported as multi key legacy insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "b" : [ {"c" : {"type": "Point", "coordinates": [10, 20]} }, {"c" : {"type": "Point", "coordinates": ["Text", 20]} } ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "302514205" }, "errmsg" : "Failed to retrieve geo keys { _id: 1 } Point parameter should contain only numeric values" } ] } (1 row) -- Some case which are valid where the field is either empty object/document or not of type object/document -- These cases generate NULL geometries and are not indexed SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 1, "a" : "Hello" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 2, "a" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 3, "a" : false }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 4, "a" : 10 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 5, "a" : [] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 6, "a" : { } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 7, "a" : { "$undefined": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 8, "a" : [ { }, [ ] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 9, "a" : { "field": [] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 10, "a" : { "field": { } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 101, "a" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', '2dindextest','{ "_id": 102, "b": [{"c": null}, {"c": {"$undefined": true}}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid insertions where 2d geometery index terms are generated SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 11, "a" : [11, 11] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 12, "a" : { "long": 12, "lat": 12 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 13, "a" : [13, 13, 11] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 14, "a" : { "long": 14, "lat": 14, "extra": 1414 } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 15, "a" : [ [ 15.1, 15.1 ], [15.2, 15.2] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 16, "a" : [ [ 16.1, 16.1 ], [16.2, 16.2], { }, [16.3, 16.3], [16.4, 16.4] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 18, "a" : [ [ { "$numberLong": "18" }, { "$numberInt": "18" } ], [ { "$numberDouble": "18.1" }, { "$numberDecimal": "18.2" }] ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Out of boundary check- errors SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [-120, 10] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [10, 120] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "-100.000001" }, 80] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "80" }, { "$numberDecimal": "100.000001" }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "-inf" }, { "$numberDecimal": "20" }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "20" }, { "$numberDecimal": "inf" }] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ [10, 20], [-200, 200]] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "369360925" }, "errmsg" : "Point lies outside the specified interval range [-100, 100]" } ] } (1 row) -- NULL values for 2dsphere index SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : null }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "$undefined": true } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"b": [{"c": null}, {"c": {"$undefined": true}}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"z" : "Text" }', NULL); -- index field missing insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid GeoJson inserts for 2dsphere indexes SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : [ 5, 10] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "x": 5 , "y": 10} }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Point", "coordinates": [5, 10] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Point", "coordinates": { "x": 5, "y": 10 } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiPoint", "coordinates": [[1 , 2], [3, 4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "LineString", "coordinates": [[1,2], [3,4]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiLineString", "coordinates": [[[1,2], [3,4]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3], [2, 3], [2, 2], [1, 2]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3], [2, 3], [2, 2], [1, 2]]]] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [1, 2]}] } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid polygon inserts for 2dsphere index SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } }', NULL); -- all points on equator insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } }', NULL); -- all points on the same longitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } }', NULL); -- all points on same latitude insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]] } }', NULL); -- points on a single latitude, polygon going around the earth with similar hole insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Test whether invalid document after valid documents are correctly errored out without OOM BEGIN; set local enable_seqscan TO on; -- Valid and then invalid doc for `a` 2dsphere field SELECT documentdb_api.insert_one('db','2dsOOMTest','{ "_id" : 1, "a": [2.1, 2.2] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','2dsOOMTest','{ "_id" : 2, "a": "Text" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- error while building the index and should not OOM SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsOOMTest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_oom_idx" }]}', true); ERROR: The Failed to retrieve geo keys { _id: 2 } geo element should be provided as either an array or an object: a : "Text" CONTEXT: SQL statement "CREATE INDEX documents_rum_index_16734 ON documentdb_data.documents_16722 USING GIST(documentdb_api_catalog.bson_validate_geography(document, 'a'::text) documentdb_api_catalog.bson_gist_geography_ops_2d( path='a' ) ) WHERE ( documentdb_api_catalog.bson_validate_geography(document, 'a'::text) IS NOT NULL ) " ROLLBACK; commands_create_indexes.out000066400000000000000000002775251507310017400354110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 110000; SET documentdb.next_collection_id TO 11000; SET documentdb.next_collection_index_id TO 11000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; ---- createIndexes - top level - parse error ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', NULL, true); ERROR: arg cannot be NULL SELECT documentdb_api_internal.create_indexes_non_concurrently(NULL, '{}', true); ERROR: dbName cannot be NULL SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "unknown_field": []}', true); ERROR: BSON field 'createIndexes.unknown_field' is an unknown field SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": null, "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}', true); ERROR: Collection name contains an invalid data type null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": null}', true); ERROR: The BSON field 'createIndexes.indexes' has an incorrect type 'null'; it should be of type 'array'. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": 5}', true); ERROR: The BSON field 'createIndexes.indexes' has an incorrect type 'int'; it should be of type 'array'. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": []}', true); ERROR: You must provide at least one index in order to proceed with creation SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1"}', true); ERROR: The BSON field 'createIndexes.indexes' is required but was not provided SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{}', true); ERROR: The BSON field 'createIndexes.indexes' is required but was not provided SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": 1}', true); ERROR: Collection name contains an invalid data type int SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": 1}', true); ERROR: The BSON field 'createIndexes.indexes' has an incorrect type 'int'; it should be of type 'array'. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [1,2]}', true); ERROR: The BSON field 'createIndexes.indexes.0' has an incorrect type 'int'; it should be of type 'object'. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": 1}]}', true); ERROR: Error in specification { "key" : 1 }:The field 'key' is required to be an object type, however, it received a int instead. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": 1}]}', true); ERROR: Error in specification { "name" : 1 }:The field 'name' is required to be an string type, however, it received a int instead. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"unique": "1"}]}', true); ERROR: Error in specification { "unique" : "1" }:The field 'unique' has value unique: "1", which is not convertible to bool SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}}]}', true); ERROR: Error in specification { "key" : { "a" : 1 } }:The 'name' field is mandatory and must be included as part of an index specification SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "my_idx"}]}', true); ERROR: Error in specification { "name" : "my_idx" }:The 'key' field is mandatory and must be included as part of an index specification SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"unknown_field": "111"}]}', true); ERROR: Error in specification { "unknown_field" : "111" }:The field 'unknown_field' cannot be used in an index specification. Provided specification: { "unknown_field" : "111" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "_name_", "unknown_field": "111"}]}', true); ERROR: Error in specification { "name" : "_name_", "unknown_field" : "111" }:The field 'unknown_field' cannot be used in an index specification. Provided specification: { "name" : "_name_", "unknown_field" : "111" } ---- createIndexes - indexes.key - parse error ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"": 1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "" : 1 }, "name" : "my_idx" }:Index keys are not allowed to be completely empty fields. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a" : 1, "" : -1 }, "name" : "my_idx" }:Index keys are not allowed to be completely empty fields. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": 1, "b": -1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**" : 1, "b" : -1 }, "name" : "my_idx" }:wildcard indexes do not allow compounding SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {".$**": 1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { ".$**" : 1 }, "name" : "my_idx" }:Index keys are not allowed to include any fields that are empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": "bad"}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**" : "bad" }, "name" : "my_idx" }:Unknown plugin index specified: "bad" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": 0}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**" : 0 }, "name" : "my_idx" }:Index key pattern values are not allowed to be zero. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": ""}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**" : "" }, "name" : "my_idx" }:Index key pattern values must not contain empty strings SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": {"a": 1}}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**" : { "a" : 1 } }, "name" : "my_idx" }:Values in v:2 index key pattern must not be of type object; acceptable types include numbers greater than zero, numbers less than zero, and strings. -- note that those are valid .. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_1"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": 1}, "name": "my_idx_3"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- valid sparse index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse_num": 1}, "name": "my_sparse_num_idx1", "sparse": 1}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse_num": 1}, "name": "my_non_sparse_num_idx1", "sparse": 0}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.double": 1}, "name": "my_sparse_double_idx1", "sparse": 0.2}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": null, "createIndexes": "collection_1", "indexes": [{"key": 0, "key": {"bsparse": 1}, "name": "my_non_sparse_idx1", "sparse": false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"cs.$**": 1}, "name": "my_wildcard_non_sparse_idx1", "sparse": false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- invalid sparse indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": true}]}', true); ERROR: Error in specification { "key" : { "bs.$**" : 1 }, "name" : "my_wildcard_sparse_idx1", "sparse" : true }:Index type 'wildcard' does not support the sparse option SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": "true"}]}', true); ERROR: Error in specification { "key" : { "bs.$**" : 1 }, "name" : "my_wildcard_sparse_idx1", "sparse" : "true" }:The field 'sparse' has value sparse: "true", which is not convertible to bool SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.a": 1}, "name": "my_sparse_with_pfe_idx", "sparse": true, "partialFilterExpression": { "rating": { "$gt": 5 } }}]}', true); ERROR: Error in specification { "key" : { "bs.a" : 1 }, "name" : "my_sparse_with_pfe_idx", "sparse" : true, "partialFilterExpression" : { "rating" : { "$gt" : 5 } } }:cannot mix "partialFilterExpression" and "sparse" options -- sparse can create index for same key with different sparse options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_sparse_a_b_idx", "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx", "sparse": false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "10" }, "numIndexesAfter" : { "$numberInt" : "11" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- valid hash indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": "hashed"}, "name": "my_idx_hashed"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "11" }, "numIndexesAfter" : { "$numberInt" : "12" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": "hashed", "b": 1 }, "name": "my_idx_hashed_compound"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "12" }, "numIndexesAfter" : { "$numberInt" : "13" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1, "b": "hashed" }, "name": "my_idx_hashed_compound_hash"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "13" }, "numIndexesAfter" : { "$numberInt" : "14" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "hashed"}, "name": "my_idx_dollar_name_1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "14" }, "numIndexesAfter" : { "$numberInt" : "15" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.c$": "hashed"}, "name": "my_idx_dollar_name_2"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "15" }, "numIndexesAfter" : { "$numberInt" : "16" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- invalid hash indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed" }, "unique": 1, "name": "invalid_hashed"}]}', true); ERROR: Error in specification { "key" : { "b" : "hashed" }, "unique" : 1, "name" : "invalid_hashed" }:Index type 'hashed' does not support the unique option. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed", "c": "hashed" }, "name": "invalid_hashed"}]}', true); ERROR: Error in specification { "key" : { "b" : "hashed", "c" : "hashed" }, "name" : "invalid_hashed" }:A maximum of one index field is allowed to be hashed but found 2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed", "c": 1, "d": "hashed" }, "name": "invalid_hashed"}]}', true); ERROR: Error in specification { "key" : { "b" : "hashed", "c" : 1, "d" : "hashed" }, "name" : "invalid_hashed" }:A maximum of one index field is allowed to be hashed but found 2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b.$**": "hashed" }, "name": "invalid_hashed"}]}', true); ERROR: Error in specification { "key" : { "b.$**" : "hashed" }, "name" : "invalid_hashed" }:Index key has an invalid field name because it begins with an operators symbol. -- can't create index on same key with same sparse options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx1"}]}', true); ERROR: Index already exists with a different name: my_non_sparse_a_b_idx SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx2", "sparse": false}]}', true); ERROR: Index already exists with a different name: my_non_sparse_a_b_idx SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx3", "sparse": true}]}', true); ERROR: Index already exists with a different name: my_sparse_a_b_idx -- passing named args is also ok SELECT documentdb_api_internal.create_indexes_non_concurrently(p_database_name=>'db', p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"c.a$**": 1}, "name": "my_idx_4"}]}', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "16" }, "numIndexesAfter" : { "$numberInt" : "17" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"d.a$**": 1}, "name": "my_idx_5"}]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "17" }, "numIndexesAfter" : { "$numberInt" : "18" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- invalid index names SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1 }, "name": "*"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "*" }:The index name '*' is not valid SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1 }, "name": "name\u0000field"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "name\u0000field" }:The index name must not include any embedded null characters -- For the next test, show the commands that we internally execute to build -- & clean-up the collection indexes. SET client_min_messages TO DEBUG1; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5"}, {"key": {"x.y": 1}, "name": "valid_index_2"} ] }', p_skip_check_collection_create=>true ); DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id) FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND (index_spec).index_name = $2 AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id)FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND documentdb_api_internal.index_spec_options_are_equivalent(index_spec, $2) AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id) FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND (index_spec).index_name = $2 AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c.d.e" : 1 }, "name" : "my_idx_5" }, existing index: { "v" : 2, "key" : { "d.a$**" : 1 }, "name" : "my_idx_5" } RESET client_min_messages; -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11000 | 11000 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 11000 | 11001 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**foo" : { "$numberInt" : "1" } }, "name" : "my_idx_1" } | t 11000 | 11002 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_3" } | t 11000 | 11003 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse" : { "$numberInt" : "1" } }, "name" : "my_sparse_idx1", "sparse" : true } | t 11000 | 11004 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse_num" : { "$numberInt" : "1" } }, "name" : "my_sparse_num_idx1", "sparse" : true } | t 11000 | 11005 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse_num" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_num_idx1", "sparse" : false } | t 11000 | 11006 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.double" : { "$numberInt" : "1" } }, "name" : "my_sparse_double_idx1", "sparse" : true } | t 11000 | 11007 | { "v" : { "$numberInt" : "2" }, "key" : { "bsparse" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_idx1", "sparse" : false } | t 11000 | 11008 | { "v" : { "$numberInt" : "2" }, "key" : { "cs.$**" : { "$numberInt" : "1" } }, "name" : "my_wildcard_non_sparse_idx1", "sparse" : false } | t 11000 | 11009 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.b" : { "$numberInt" : "1" } }, "name" : "my_sparse_a_b_idx", "sparse" : true } | t 11000 | 11010 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.b" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_a_b_idx", "sparse" : false } | t 11000 | 11011 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "hashed" }, "name" : "my_idx_hashed" } | t 11000 | 11012 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "hashed", "b" : { "$numberInt" : "1" } }, "name" : "my_idx_hashed_compound" } | t 11000 | 11013 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : "hashed" }, "name" : "my_idx_hashed_compound_hash" } | t 11000 | 11014 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**" : "hashed" }, "name" : "my_idx_dollar_name_1" } | t 11000 | 11015 | { "v" : { "$numberInt" : "2" }, "key" : { "a.c$" : "hashed" }, "name" : "my_idx_dollar_name_2" } | t 11000 | 11016 | { "v" : { "$numberInt" : "2" }, "key" : { "c.a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_4" } | t 11000 | 11017 | { "v" : { "$numberInt" : "2" }, "key" : { "d.a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_5" } | t (18 rows) -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'collection_1') ORDER BY indexrelid; indexrelid | indisvalid | indisready --------------------------------------------------------------------- documentdb_data.collection_pk_11000 | t | t documentdb_data.documents_rum_index_11001 | t | t documentdb_data.documents_rum_index_11002 | t | t documentdb_data.documents_rum_index_11003 | t | t documentdb_data.documents_rum_index_11004 | t | t documentdb_data.documents_rum_index_11005 | t | t documentdb_data.documents_rum_index_11006 | t | t documentdb_data.documents_rum_index_11007 | t | t documentdb_data.documents_rum_index_11008 | t | t documentdb_data.documents_rum_index_11009 | t | t documentdb_data.documents_rum_index_11010 | t | t documentdb_data.documents_rum_index_11011 | t | t documentdb_data.documents_rum_index_11012 | t | t documentdb_data.documents_rum_index_11013 | t | t documentdb_data.documents_rum_index_11014 | t | t documentdb_data.documents_rum_index_11015 | t | t documentdb_data.documents_rum_index_11016 | t | t documentdb_data.documents_rum_index_11017 | t | t (18 rows) -- .., but those are not SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**foo": 1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**foo" : 1 }, "name" : "my_idx" }:Index key includes an invalid or prohibited field name SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**.foo": 1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "a.$**.foo" : 1 }, "name" : "my_idx" }:Index key includes an invalid or prohibited field name SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": -1, "a.$**": 1}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { "b" : -1, "a.$**" : 1 }, "name" : "my_idx" }:wildcard indexes do not allow compounding SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {}, "name": "my_idx"}]}', true); ERROR: Error in specification { "key" : { }, "name" : "my_idx" }:Index keys are not allowed to be completely empty fields. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "my_idx"}]}', true); ERROR: Error in specification { "name" : "my_idx" }:The 'key' field is mandatory and must be included as part of an index specification SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**foo": 1}, "name": "my_idx_13"}]}', true); ERROR: Error in specification { "key" : { "$**foo" : 1 }, "name" : "my_idx_13" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"..": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { ".." : 1 }, "name" : "my_idx_12" }:Index keys are not allowed to include any fields that are empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a..b.$**": 1}, "name": "my_idx_10"}]}', true); ERROR: Error in specification { "key" : { "a..b.$**" : 1 }, "name" : "my_idx_10" }:Index keys are not allowed to include any fields that are empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a..b.foo": 1}, "name": "my_idx_11"}]}', true); ERROR: Error in specification { "key" : { "a..b.foo" : 1 }, "name" : "my_idx_11" }:Index keys are not allowed to include any fields that are empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"$a": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { "$a" : 1 }, "name" : "my_idx_12" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {".": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { "." : 1 }, "name" : "my_idx_12" }:Index keys are not allowed to include any fields that are empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$b": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { "a.$b" : 1 }, "name" : "my_idx_12" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$b.$**": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { "a.$b.$**" : 1 }, "name" : "my_idx_12" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.": 1}, "name": "my_idx_12"}]}', true); ERROR: Error in specification { "key" : { "a." : 1 }, "name" : "my_idx_12" }:Index keys are not allowed to include any fields that are empty. -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11000 | 11000 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 11000 | 11001 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**foo" : { "$numberInt" : "1" } }, "name" : "my_idx_1" } | t 11000 | 11002 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_3" } | t 11000 | 11003 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse" : { "$numberInt" : "1" } }, "name" : "my_sparse_idx1", "sparse" : true } | t 11000 | 11004 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse_num" : { "$numberInt" : "1" } }, "name" : "my_sparse_num_idx1", "sparse" : true } | t 11000 | 11005 | { "v" : { "$numberInt" : "2" }, "key" : { "asparse_num" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_num_idx1", "sparse" : false } | t 11000 | 11006 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.double" : { "$numberInt" : "1" } }, "name" : "my_sparse_double_idx1", "sparse" : true } | t 11000 | 11007 | { "v" : { "$numberInt" : "2" }, "key" : { "bsparse" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_idx1", "sparse" : false } | t 11000 | 11008 | { "v" : { "$numberInt" : "2" }, "key" : { "cs.$**" : { "$numberInt" : "1" } }, "name" : "my_wildcard_non_sparse_idx1", "sparse" : false } | t 11000 | 11009 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.b" : { "$numberInt" : "1" } }, "name" : "my_sparse_a_b_idx", "sparse" : true } | t 11000 | 11010 | { "v" : { "$numberInt" : "2" }, "key" : { "a.sparse.b" : { "$numberInt" : "1" } }, "name" : "my_non_sparse_a_b_idx", "sparse" : false } | t 11000 | 11011 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "hashed" }, "name" : "my_idx_hashed" } | t 11000 | 11012 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : "hashed", "b" : { "$numberInt" : "1" } }, "name" : "my_idx_hashed_compound" } | t 11000 | 11013 | { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" }, "b" : "hashed" }, "name" : "my_idx_hashed_compound_hash" } | t 11000 | 11014 | { "v" : { "$numberInt" : "2" }, "key" : { "a$**" : "hashed" }, "name" : "my_idx_dollar_name_1" } | t 11000 | 11015 | { "v" : { "$numberInt" : "2" }, "key" : { "a.c$" : "hashed" }, "name" : "my_idx_dollar_name_2" } | t 11000 | 11016 | { "v" : { "$numberInt" : "2" }, "key" : { "c.a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_4" } | t 11000 | 11017 | { "v" : { "$numberInt" : "2" }, "key" : { "d.a$**" : { "$numberInt" : "1" } }, "name" : "my_idx_5" } | t (18 rows) -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'collection_1') ORDER BY indexrelid; indexrelid | indisvalid | indisready --------------------------------------------------------------------- documentdb_data.collection_pk_11000 | t | t documentdb_data.documents_rum_index_11001 | t | t documentdb_data.documents_rum_index_11002 | t | t documentdb_data.documents_rum_index_11003 | t | t documentdb_data.documents_rum_index_11004 | t | t documentdb_data.documents_rum_index_11005 | t | t documentdb_data.documents_rum_index_11006 | t | t documentdb_data.documents_rum_index_11007 | t | t documentdb_data.documents_rum_index_11008 | t | t documentdb_data.documents_rum_index_11009 | t | t documentdb_data.documents_rum_index_11010 | t | t documentdb_data.documents_rum_index_11011 | t | t documentdb_data.documents_rum_index_11012 | t | t documentdb_data.documents_rum_index_11013 | t | t documentdb_data.documents_rum_index_11014 | t | t documentdb_data.documents_rum_index_11015 | t | t documentdb_data.documents_rum_index_11016 | t | t documentdb_data.documents_rum_index_11017 | t | t (18 rows) -- create a valid index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "18" }, "numIndexesAfter" : { "$numberInt" : "19" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') WHERE index_spec_as_bson OPERATOR(documentdb_api_catalog.@@) '{"name": "my_idx_14"}' ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11000 | 11018 | { "v" : { "$numberInt" : "2" }, "key" : { "start_path" : { "$numberInt" : "1" } }, "name" : "my_idx_14" } | t (1 row) -- creating the same index should noop SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "19" }, "numIndexesAfter" : { "$numberInt" : "19" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') WHERE index_spec_as_bson OPERATOR(documentdb_api_catalog.@@) '{"name": "my_idx_14"}' ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11000 | 11018 | { "v" : { "$numberInt" : "2" }, "key" : { "start_path" : { "$numberInt" : "1" } }, "name" : "my_idx_14" } | t (1 row) -- not the same index since this specifies partialFilterExpression SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14", "partialFilterExpression": {"a": 1}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "start_path" : 1 }, "name" : "my_idx_14", "partialFilterExpression" : { "a" : 1 } }, existing index: { "v" : 2, "key" : { "start_path" : 1 }, "name" : "my_idx_14" } -- valid index type in the reference implementation, which are not supported yet SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "2d"}, "name": "my_idx_2d"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "19" }, "numIndexesAfter" : { "$numberInt" : "20" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "2dsphere"}, "name": "my_idx_2dsphere"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "20" }, "numIndexesAfter" : { "$numberInt" : "21" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "text"}, "name": "my_idx_text"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "21" }, "numIndexesAfter" : { "$numberInt" : "22" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- test "v" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2.1234, "name": "invalid_v"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "v" : 2.1234000000000001762, "name" : "invalid_v" }:Index version must be representable as a 32-bit integer, but got 2.123400 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 10000000000000000, "name": "invalid_v"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "v" : 10000000000000000, "name" : "invalid_v" }:Index version must be representable as a 32-bit integer, but got 10000000000000000.000000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": -10000000000000000, "name": "invalid_v"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "v" : -10000000000000000, "name" : "invalid_v" }:Index version must be representable as a 32-bit integer, but got -10000000000000000.000000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 100, "name": "invalid_v"}]}', true); ERROR: Error in specification { "key" : { "a" : 1 }, "v" : 100, "name" : "invalid_v" }:Invalid index specification { "key" : { "a" : 1 }, "v" : 100, "name" : "invalid_v" }; unable to create an index using v=100 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2.0, "name": "valid_v"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "22" }, "numIndexesAfter" : { "$numberInt" : "23" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- same index since 2.0 == 2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2, "name": "valid_v"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "23" }, "numIndexesAfter" : { "$numberInt" : "23" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- following are assumed to be identical to built-in _id index even if their names are different than "_id_" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1}, "name" : "_id_1"}, {"key": {"_id": 1.0}, "name" : "_id_2"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "23" }, "numIndexesAfter" : { "$numberInt" : "23" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- but this is not identical to built-in _id index, so we will create it SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1.2}, "name" : "_id_3"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "23" }, "numIndexesAfter" : { "$numberInt" : "24" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- and this conflicts with _id_3 since key != {"_id": 1}, so we will throw an error SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1.2}, "name" : "_id_4"}]}', true); ERROR: Index already exists with a different name: _id_3 -- background is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.a": 1}, "name": "my_idx_6", "background": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "24" }, "numIndexesAfter" : { "$numberInt" : "25" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- hidden false is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.b": 1}, "name": "my_idx_7", "hidden": false }]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "25" }, "numIndexesAfter" : { "$numberInt" : "26" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- hidden true fails. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.c": 1}, "name": "my_idx_8", "hidden": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); ERROR: hidden indexes are not supported yet. -- ns is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.f": 1}, "name": "my_idx_9", "ns": "foo.bar" }]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "26" }, "numIndexesAfter" : { "$numberInt" : "27" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- readPreference is ignored SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.g": 1}, "name": "my_idx_10" }], "$readPreference": { "mode": "secondary" }}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "27" }, "numIndexesAfter" : { "$numberInt" : "28" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); NOTICE: creating collection ERROR: add index fails, too many indexes for db.too_many_indexes key:{ "a63" : 1 } BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); NOTICE: creating collection ERROR: add index fails, too many indexes for db.too_many_indexes key:{ "a63" : 1 } ROLLBACK; SELECT documentdb_api.create_collection('db', 'too_many_indexes'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); ERROR: add index fails, too many indexes for db.too_many_indexes key:{ "a63" : 1 } SET documentdb.enable_large_unique_index_keys TO false; -- dropDups is ignored. SELECT documentdb_api.insert_one('db','dropdups_ignore','{"_id": "1", "a": "dup" }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','dropdups_ignore','{"_id": "2", "a": "dup" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "dropdups_ignore", "indexes": [{"key": {"a": 1}, "name": "dropdups_ignore_idx_1", "dropDups": true, "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); ERROR: could not create exclusion constraint "documents_rum_index_11032_110068" DETAIL: Key (document, (ROW(shard_key_value, document)::shard_key_and_document))=({ "_id" : "1", "a" : "dup" }, (11004,"{ ""_id"" : ""1"", ""a"" : ""dup"" }")) conflicts with key (document, (ROW(shard_key_value, document)::shard_key_and_document))=({ "_id" : "2", "a" : "dup" }, (11004,"{ ""_id"" : ""2"", ""a"" : ""dup"" }")). CONTEXT: SQL statement "ALTER TABLE documentdb_data.documents_11004 ADD CONSTRAINT documents_rum_index_11032 EXCLUDE USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='a',generateNotFoundTerm=true) WITH OPERATOR(documentdb_api_catalog.=?=), ((shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) documentdb_api_catalog.bson_rum_exclusion_ops(path='a') WITH OPERATOR(documentdb_api_catalog.=)) " select documentdb_api.delete('db', '{"delete":"dropdups_ignore", "deletes":[{"q":{"_id": "2"}, "limit": 0 } ] }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "dropdups_ignore", "indexes": [{"key": {"a": 1}, "name": "dropdups_ignore_idx_1", "dropDups": true, "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SET documentdb.enable_large_unique_index_keys TO true; -- tests with ignoreUnknownIndexOptions -- -- invalid values of ignoreUnknownIndexOptions SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "ignoreUnknownIndexOptions": "hello" }', true); ERROR: The BSON field 'createIndexes.ignoreUnknownIndexOptions' has an incorrect type 'string'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "ignoreUnknownIndexOptions": {"b":1} }', true); ERROR: The BSON field 'createIndexes.ignoreUnknownIndexOptions' has an incorrect type 'object'; it should be one of the following valid types: [bool, long, int, decimal, double] -- -- ignoreUnknownIndexOptions of false (default value) will trigger error if there is any unknown field in index options. (unknown field is "dog" in these examples) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}] }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" }:The field 'dog' cannot be used in an index specification. Provided specification: { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": false }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" }:The field 'dog' cannot be used in an index specification. Provided specification: { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 0.0 }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" }:The field 'dog' cannot be used in an index specification. Provided specification: { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": null }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" }:The field 'dog' cannot be used in an index specification. Provided specification: { "key" : { "a" : 1 }, "name" : "a_1", "dog" : "pazu" } -- -- ignoreUnknownIndexOptions of true will ignore any unknown field in index options. (unknown field is "dog" in these examples) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": true }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"b": 1}, "name": "b_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 0.1 }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"c": 1}, "name": "c_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": -5.6 }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"d": 1}, "name": "d_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 1 }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- index term options -- we flow index term size option to the indexes that should truncate only SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "a": 1 }, "name": "indexa"}] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "$**": 1 }, "name": "indexwildcard"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "indexcompound"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "$**": 1 }, "wildcardProjection": {"a": 0}, "name": "index_wildcard_projection"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) WITH c1 AS (SELECT collection_id from documentdb_api_catalog.collections where collection_name = 'indexTermSizeLimit' and database_name = 'db') SELECT indexdef FROM pg_indexes, c1 where tablename = 'documents' || '_' || c1.collection_id and schemaname = 'documentdb_data' ORDER BY indexname ASC; indexdef --------------------------------------------------------------------- CREATE UNIQUE INDEX collection_pk_11006 ON documentdb_data.documents_11006 USING btree (shard_key_value, object_id) CREATE INDEX documents_rum_index_11040 ON documentdb_data.documents_11006 USING documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2699')) CREATE INDEX documents_rum_index_11041 ON documentdb_data.documents_11006 USING documentdb_rum (document bson_rum_single_path_ops (path='', iswildcard='true', tl='2699', wkl='200')) CREATE INDEX documents_rum_index_11042 ON documentdb_data.documents_11006 USING documentdb_rum (document bson_rum_single_path_ops (path=a, tl='2691'), document bson_rum_single_path_ops (path=b, tl='2691')) CREATE INDEX documents_rum_index_11043 ON documentdb_data.documents_11006 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a" ]', isexclusion='true')) (5 rows) SET documentdb.enable_large_unique_index_keys TO false; -- for hashed, unique and text indexes we should not see the limit as those shouldn't be truncated SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": "hashed" }, "name": "a_hashed" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": 1 }, "name": "a_unique", "unique": true } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SET documentdb.enable_large_unique_index_keys TO true; WITH c1 AS (SELECT collection_id from documentdb_api_catalog.collections where collection_name = 'noIndexTermSizeLimit' and database_name = 'db') SELECT indexdef FROM pg_indexes, c1 where tablename = 'documents' || '_' || c1.collection_id and schemaname = 'documentdb_data' ORDER BY indexname ASC; indexdef --------------------------------------------------------------------- CREATE UNIQUE INDEX collection_pk_11007 ON documentdb_data.documents_11007 USING btree (shard_key_value, object_id) CREATE INDEX documents_rum_index_11045 ON documentdb_data.documents_11007 USING documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }')) CREATE INDEX documents_rum_index_11046 ON documentdb_data.documents_11007 USING documentdb_rum (document documentdb_rum_hashed_ops (path=a)) CREATE INDEX documents_rum_index_11047 ON documentdb_data.documents_11007 USING documentdb_rum (document bson_rum_single_path_ops (path=a, generatenotfoundterm='true'), (ROW(shard_key_value, document)::shard_key_and_document) bson_rum_exclusion_ops (path=a)) (4 rows) SELECT ('{ "createIndexes": "indexColl_1", "indexes": [{ "key": { "description1": 1, "description2": 1, "description3": 1, "description4": 1, "description5": 1, "description6": 1, "description7": 1, "description8": 1, ' || ' "description9": 1, "description10": 1, "description11": 1, "description12": 1, "description13": 1, "description14": 1, "description15": 1, "description16": 1, "description17": 1, ' || ' "description18": 1, "description19": 1, "description20": 1 } ' || ', "name": "description1_1_description2_1_description3_1_description4_1_description5_1_description6_1_description7_1_description8_1_description9_1_description10_1' || '_description11_1_description12_1_description13_1_description14_1_description15_1_description16_1_description17_1_description18_1_description19_1_description20_1" } ]}')::bson; bson --------------------------------------------------------------------- { "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "description1" : { "$numberInt" : "1" }, "description2" : { "$numberInt" : "1" }, "description3" : { "$numberInt" : "1" }, "description4" : { "$numberInt" : "1" }, "description5" : { "$numberInt" : "1" }, "description6" : { "$numberInt" : "1" }, "description7" : { "$numberInt" : "1" }, "description8" : { "$numberInt" : "1" }, "description9" : { "$numberInt" : "1" }, "description10" : { "$numberInt" : "1" }, "description11" : { "$numberInt" : "1" }, "description12" : { "$numberInt" : "1" }, "description13" : { "$numberInt" : "1" }, "description14" : { "$numberInt" : "1" }, "description15" : { "$numberInt" : "1" }, "description16" : { "$numberInt" : "1" }, "description17" : { "$numberInt" : "1" }, "description18" : { "$numberInt" : "1" }, "description19" : { "$numberInt" : "1" }, "description20" : { "$numberInt" : "1" } }, "name" : "description1_1_description2_1_description3_1_description4_1_description5_1_description6_1_description7_1_description8_1_description9_1_description10_1_description11_1_description12_1_description13_1_description14_1_description15_1_description16_1_description17_1_description18_1_description19_1_description20_1" } ] } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "description1" : 1, "description2" : 1, "description3" : 1, "description4" : 1, "description5" : 1, "description6" : 1, "description7" : 1, "description8" : 1, "description9" : 1, "description10" : 1, "description11" : 1, "description12" : 1, "description13" : 1, "description14" : 1, "description15" : 1, "description16" : 1, "description17" : 1, "description18" : 1, "description19" : 1, "description20" : 1 }, "name" : "description1_1_description2_1_description3_1_description4_1_description5_1_description6_1_description7_1_description8_1_description9_1_description10_1_description11_1_description12_1_description13_1_description14_1_description15_1_description16_1_description17_1_description18_1_description19_1_description20_1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "%s" : 1 }, "name" : "%s_1" } ] }', repeat('a', 1200), repeat('a', 1200))::bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- try 2 columns (super long) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "%s" : 1, "b_%s": 1 }, "name" : "%s_1_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- 4/5 super long columns SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1, "c_%s": 1, "d_%s": 1 }, "name" : "a_b_c_d_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- 10 super long columns SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1, "c_%s": 1, "d_%s": 1, "e_%s": 1, "f_%s": 1, "g_%s": 1, "h_%s": 1, "i_%s": 1, "j_%s": 1 }, "name" : "a_b_c_d_e_f_g_h_i_j_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- but 1 super long name fails SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1 }, "name" : "a_%s_1" } ] }', repeat('a', 1500), repeat('a', 1200))::bson, true); ERROR: The index path or expression is too long. Try a shorter path or reducing paths by 76 characters. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1500), repeat('a', 1500), repeat('a', 1200))::bson, true); ERROR: The index path or expression is too long. Try a shorter path or reducing paths by 76 characters. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1500), repeat('a', 1200))::bson, true); ERROR: The index path or expression is too long. Try a shorter path or reducing paths by 77 characters. -- however the name can be however long we want SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 9000))::bson, true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "10" }, "numIndexesAfter" : { "$numberInt" : "11" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- tests with blocking -- -- invalid values of blocking SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "blocking": "hello" }', true); ERROR: The BSON field 'blocking' has an incorrect type 'string'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"b": 1}, "name": "b_1"}], "blocking": {"b":1} }', true); ERROR: The BSON field 'blocking' has an incorrect type 'object'; it should be one of the following valid types: [bool, long, int, decimal, double] -- -- blocking of false (default value) will trigger create index concurrently. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"c": 1}, "name": "c_1"}] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"d": 1}, "name": "d_1"}], "blocking": false }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"e": 1}, "name": "e_1"}], "blocking": 0.0 }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"f": 1}, "name": "f_1"}], "blocking": null }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- -- blocking of true will trigger create index non-concurrently. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"g": 1}, "name": "g_1"}], "blocking": true }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"h": 1}, "name": "h_1"}], "blocking": 1.0 }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Collection is not created in the same call ---- when blocking:true, we will let create index execute even if collection is not created in the call SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"i": 1}, "name": "i_1"}], "blocking": true }'); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"j": 1}, "name": "j_1"}], "blocking": false }'); ERROR: Creation of new indexes on the specified existing collection db.blocking_index is not permitted within a multi-document transaction. SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'blocking_index') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11008 | 11057 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 11008 | 11058 | { "v" : { "$numberInt" : "2" }, "key" : { "c" : { "$numberInt" : "1" } }, "name" : "c_1" } | t 11008 | 11059 | { "v" : { "$numberInt" : "2" }, "key" : { "d" : { "$numberInt" : "1" } }, "name" : "d_1" } | t 11008 | 11060 | { "v" : { "$numberInt" : "2" }, "key" : { "e" : { "$numberInt" : "1" } }, "name" : "e_1" } | t 11008 | 11061 | { "v" : { "$numberInt" : "2" }, "key" : { "f" : { "$numberInt" : "1" } }, "name" : "f_1" } | t 11008 | 11062 | { "v" : { "$numberInt" : "2" }, "key" : { "g" : { "$numberInt" : "1" } }, "name" : "g_1" } | t 11008 | 11063 | { "v" : { "$numberInt" : "2" }, "key" : { "h" : { "$numberInt" : "1" } }, "name" : "h_1" } | t 11008 | 11064 | { "v" : { "$numberInt" : "2" }, "key" : { "i" : { "$numberInt" : "1" } }, "name" : "i_1" } | t (8 rows) commands_create_indexes_background.out000066400000000000000000002764141507310017400376040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 320000; SET documentdb.next_collection_id TO 32000; SET documentdb.next_collection_index_id TO 32000; CREATE SCHEMA change_index_jobs_schema; CREATE OR REPLACE FUNCTION change_index_jobs_schema.change_index_jobs_status(active_status boolean) RETURNS void AS $$ DECLARE job_id integer; BEGIN FOR job_id IN (SELECT jobid FROM cron.job WHERE jobname LIKE 'documentdb_index_%' order by jobid) LOOP UPDATE cron.job SET active = active_status WHERE jobid = job_id; RAISE NOTICE 'Processing job_id: %', job_id; END LOOP; END; $$ LANGUAGE plpgsql; SET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,change_index_jobs_schema; -- Delete all old create index requests from other tests DELETE from documentdb_api_catalog.documentdb_index_queue; ---- createIndexes - top level - parse error ---- SELECT * FROM documentdb_api.create_indexes_background('db', NULL); ERROR: Argument value must not be NULL SELECT * FROM documentdb_api.create_indexes_background(NULL, '{}'); ERROR: dbName cannot be NULL SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "unknown_field": []}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "BSON field 'createIndexes.unknown_field' is an unknown field", "code" : { "$numberInt" : "136314909" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": null, "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Collection name contains an invalid data type null", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": null}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes' has an incorrect type 'null'; it should be of type 'array'.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": 5}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes' has an incorrect type 'int'; it should be of type 'array'.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": []}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "You must provide at least one index in order to proceed with creation", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6"}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes' is required but was not provided", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes' is required but was not provided", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": 1}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Collection name contains an invalid data type int", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": 1}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes' has an incorrect type 'int'; it should be of type 'array'.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [1,2]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "The BSON field 'createIndexes.indexes.0' has an incorrect type 'int'; it should be of type 'object'.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": 1}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : 1 }:The field 'key' is required to be an object type, however, it received a int instead.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": 1}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : 1 }:The field 'name' is required to be an string type, however, it received a int instead.", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"unique": "1"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"unique\" : \"1\" }:The field 'unique' has value unique: \"1\", which is not convertible to bool", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1}}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a\" : 1 } }:The 'name' field is mandatory and must be included as part of an index specification", "code" : { "$numberInt" : "50331677" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : \"my_idx\" }:The 'key' field is mandatory and must be included as part of an index specification", "code" : { "$numberInt" : "50331677" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"unknown_field": "111"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"unknown_field\" : \"111\" }:The field 'unknown_field' cannot be used in an index specification. Provided specification: { \"unknown_field\" : \"111\" }", "code" : { "$numberInt" : "33816605" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "_name_", "unknown_field": "111"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : \"_name_\", \"unknown_field\" : \"111\" }:The field 'unknown_field' cannot be used in an index specification. Provided specification: { \"name\" : \"_name_\", \"unknown_field\" : \"111\" }", "code" : { "$numberInt" : "33816605" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) ---- createIndexes - indexes.key - parse error ---- SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"": 1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"\" : 1 }, \"name\" : \"my_idx\" }:Index keys are not allowed to be completely empty fields.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a\" : 1, \"\" : -1 }, \"name\" : \"my_idx\" }:Index keys are not allowed to be completely empty fields.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": 1, "b": -1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**\" : 1, \"b\" : -1 }, \"name\" : \"my_idx\" }:wildcard indexes do not allow compounding", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {".$**": 1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \".$**\" : 1 }, \"name\" : \"my_idx\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": "bad"}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**\" : \"bad\" }, \"name\" : \"my_idx\" }:Unknown plugin index specified: \"bad\"", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": 0}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**\" : 0 }, \"name\" : \"my_idx\" }:Index key pattern values are not allowed to be zero.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": ""}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**\" : \"\" }, \"name\" : \"my_idx\" }:Index key pattern values must not contain empty strings", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": {"a": 1}}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**\" : { \"a\" : 1 } }, \"name\" : \"my_idx\" }:Values in v:2 index key pattern must not be of type object; acceptable types include numbers greater than zero, numbers less than zero, and strings.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt, user_oid FROM documentdb_api_catalog.documentdb_index_queue ORDER BY index_id; index_cmd | cmd_type | index_id | index_cmd_status | collection_id | attempt | user_oid --------------------------------------------------------------------- (0 rows) -- note that those are valid .. SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_1"}]}'); NOTICE: creating collection retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": 1}, "name": "my_idx_3"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32002" } ] } } (1 row) -- valid sparse index SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32003" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse_num": 1}, "name": "my_sparse_num_idx1", "sparse": 1}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32004" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse_num": 1}, "name": "my_non_sparse_num_idx1", "sparse": 0}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32005" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.double": 1}, "name": "my_sparse_double_idx1", "sparse": 0.2}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32006" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": null, "createIndexes": "collection_6", "indexes": [{"key": 0, "key": {"bsparse": 1}, "name": "my_non_sparse_idx1", "sparse": false}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32007" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"cs.$**": 1}, "name": "my_wildcard_non_sparse_idx1", "sparse": false}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32008" } ] } } (1 row) -- invalid sparse indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": true}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"bs.$**\" : 1 }, \"name\" : \"my_wildcard_sparse_idx1\", \"sparse\" : true }:Index type 'wildcard' does not support the sparse option", "code" : { "$numberInt" : "33816605" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": "true"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"bs.$**\" : 1 }, \"name\" : \"my_wildcard_sparse_idx1\", \"sparse\" : \"true\" }:The field 'sparse' has value sparse: \"true\", which is not convertible to bool", "code" : { "$numberInt" : "67108893" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.a": 1}, "name": "my_sparse_with_pfe_idx", "sparse": true, "partialFilterExpression": { "rating": { "$gt": 5 } }}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"bs.a\" : 1 }, \"name\" : \"my_sparse_with_pfe_idx\", \"sparse\" : true, \"partialFilterExpression\" : { \"rating\" : { \"$gt\" : 5 } } }:cannot mix \"partialFilterExpression\" and \"sparse\" options", "code" : { "$numberInt" : "33816605" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) -- sparse can create index for same key with different sparse options SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_sparse_a_b_idx", "sparse": true}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32009" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx", "sparse": false}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "10" }, "numIndexesAfter" : { "$numberInt" : "11" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32010" } ] } } (1 row) -- valid hash indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": "hashed"}, "name": "my_idx_hashed"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "11" }, "numIndexesAfter" : { "$numberInt" : "12" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32011" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": "hashed", "b": 1 }, "name": "my_idx_hashed_compound"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "12" }, "numIndexesAfter" : { "$numberInt" : "13" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32012" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1, "b": "hashed" }, "name": "my_idx_hashed_compound_hash"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "13" }, "numIndexesAfter" : { "$numberInt" : "14" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32013" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "hashed"}, "name": "my_idx_dollar_name_1"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "14" }, "numIndexesAfter" : { "$numberInt" : "15" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32014" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.c$": "hashed"}, "name": "my_idx_dollar_name_2"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "15" }, "numIndexesAfter" : { "$numberInt" : "16" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32015" } ] } } (1 row) -- invalid hash indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed" }, "unique": 1, "name": "invalid_hashed"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"b\" : \"hashed\" }, \"unique\" : 1, \"name\" : \"invalid_hashed\" }:Index type 'hashed' does not support the unique option.", "code" : { "$numberInt" : "319291421" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed", "c": "hashed" }, "name": "invalid_hashed"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"b\" : \"hashed\", \"c\" : \"hashed\" }, \"name\" : \"invalid_hashed\" }:A maximum of one index field is allowed to be hashed but found 2", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed", "c": 1, "d": "hashed" }, "name": "invalid_hashed"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"b\" : \"hashed\", \"c\" : 1, \"d\" : \"hashed\" }, \"name\" : \"invalid_hashed\" }:A maximum of one index field is allowed to be hashed but found 2", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b.$**": "hashed" }, "name": "invalid_hashed"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"b.$**\" : \"hashed\" }, \"name\" : \"invalid_hashed\" }:Index key has an invalid field name because it begins with an operators symbol.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) -- can't create index on same key with same sparse options SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx1"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Index already exists with a different name: my_non_sparse_a_b_idx", "code" : { "$numberInt" : "570425373" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx2", "sparse": false}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Index already exists with a different name: my_non_sparse_a_b_idx", "code" : { "$numberInt" : "570425373" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx3", "sparse": true}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Index already exists with a different name: my_sparse_a_b_idx", "code" : { "$numberInt" : "570425373" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) -- passing named args is also ok SELECT * FROM documentdb_api.create_indexes_background(p_database_name=>'db', p_index_spec=>'{"createIndexes": "collection_6", "indexes": [{"key": {"c.a$**": 1}, "name": "my_idx_4"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "16" }, "numIndexesAfter" : { "$numberInt" : "17" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32016" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background(p_index_spec=>'{"createIndexes": "collection_6", "indexes": [{"key": {"d.a$**": 1}, "name": "my_idx_5"}]}', p_database_name=>'db'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "17" }, "numIndexesAfter" : { "$numberInt" : "18" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32017" } ] } } (1 row) -- invalid index names SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1 }, "name": "*"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a\" : 1 }, \"name\" : \"*\" }:The index name '*' is not valid", "code" : { "$numberInt" : "16777245" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1 }, "name": "name\u0000field"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a\" : 1 }, \"name\" : \"name\\u0000field\" }:The index name must not include any embedded null characters", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) -- For the next test, show the commands that we internally execute to build -- & clean-up the collection indexes. SET client_min_messages TO DEBUG1; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT * FROM documentdb_api.create_indexes_background( p_database_name=>'db', p_index_spec=>'{ "createIndexes": "collection_6", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5"}, {"key": {"x.y": 1}, "name": "valid_index_2"} ] }'); DEBUG: executing "SELECT citus_is_coordinator()" via SPI DEBUG: executing "SELECT documentdb_api_internal.create_indexes_background_internal('db','BSONHEXcb00000002637265617465496e6465786573000d000000636f6c6c656374696f6e5f360004696e6465786573009d00000003300032000000036b6579001000000010782e792e7a000100000000026e616d65000e00000076616c69645f696e6465785f3100000331002d000000036b6579001000000010632e642e65000100000000026e616d6500090000006d795f6964785f35000003320030000000036b6579000e00000010782e79000100000000026e616d65000e00000076616c69645f696e6465785f3200000000')" via SPI DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id) FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND (index_spec).index_name = $2 AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id)FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND documentdb_api_internal.index_spec_options_are_equivalent(index_spec, $2) AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI DEBUG: executing "SELECT index_id, index_spec, documentdb_api_internal.index_build_is_in_progress(index_id) FROM documentdb_api_catalog.collection_indexes WHERE collection_id = $1 AND (index_spec).index_name = $2 AND (index_is_valid OR documentdb_api_internal.index_build_is_in_progress(index_id))" via SPI retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { \"v\" : 2, \"key\" : { \"c.d.e\" : 1 }, \"name\" : \"my_idx_5\" }, existing index: { \"v\" : 2, \"key\" : { \"d.a$**\" : 1 }, \"name\" : \"my_idx_5\" }", "code" : { "$numberInt" : "587202589" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) RESET client_min_messages; -- SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**foo": 1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**foo\" : 1 }, \"name\" : \"my_idx\" }:Index key includes an invalid or prohibited field name", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**.foo": 1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$**.foo\" : 1 }, \"name\" : \"my_idx\" }:Index key includes an invalid or prohibited field name", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": -1, "a.$**": 1}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"b\" : -1, \"a.$**\" : 1 }, \"name\" : \"my_idx\" }:wildcard indexes do not allow compounding", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {}, "name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { }, \"name\" : \"my_idx\" }:Index keys are not allowed to be completely empty fields.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "my_idx"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : \"my_idx\" }:The 'key' field is mandatory and must be included as part of an index specification", "code" : { "$numberInt" : "50331677" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"$**foo": 1}, "name": "my_idx_13"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"$**foo\" : 1 }, \"name\" : \"my_idx_13\" }:Index key has an invalid field name because it begins with an operators symbol.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"..": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"..\" : 1 }, \"name\" : \"my_idx_12\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a..b.$**": 1}, "name": "my_idx_10"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a..b.$**\" : 1 }, \"name\" : \"my_idx_10\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a..b.foo": 1}, "name": "my_idx_11"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a..b.foo\" : 1 }, \"name\" : \"my_idx_11\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"$a": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"$a\" : 1 }, \"name\" : \"my_idx_12\" }:Index key has an invalid field name because it begins with an operators symbol.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {".": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \".\" : 1 }, \"name\" : \"my_idx_12\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$b": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$b\" : 1 }, \"name\" : \"my_idx_12\" }:Index key has an invalid field name because it begins with an operators symbol.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$b.$**": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.$b.$**\" : 1 }, \"name\" : \"my_idx_12\" }:Index key has an invalid field name because it begins with an operators symbol.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.": 1}, "name": "my_idx_12"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"key\" : { \"a.\" : 1 }, \"name\" : \"my_idx_12\" }:Index keys are not allowed to include any fields that are empty.", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f | { } (1 row) -- valid index type in the reference implementation, which are not supported yet SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "2d"}, "name": "my_idx_2d"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "18" }, "numIndexesAfter" : { "$numberInt" : "19" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32018" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "2dsphere"}, "name": "my_idx_2dsphere"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "19" }, "numIndexesAfter" : { "$numberInt" : "20" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32019" } ] } } (1 row) SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "text"}, "name": "my_idx_text"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "20" }, "numIndexesAfter" : { "$numberInt" : "21" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32020" } ] } } (1 row) -- create a valid index. SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "21" }, "numIndexesAfter" : { "$numberInt" : "22" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32021" } ] } } (1 row) -- creating the same index should noop SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "22" }, "numIndexesAfter" : { "$numberInt" : "22" }, "createdCollectionAutomatically" : false, "note" : "all indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32021" } ] } } (1 row) -- two index spec one already exists and another is new SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}, {"key": {"another_path": 1}, "name": "my_idx_15"}]}'); retval | ok | requests --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "22" }, "numIndexesAfter" : { "$numberInt" : "23" }, "createdCollectionAutomatically" : false, "note" : "An index with this name already exists", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t | { "indexRequest" : { "cmdType" : "C", "ids" : [ { "$numberInt" : "32021" }, { "$numberInt" : "32022" } ] } } (1 row) -- Delete all old create index requests submitted so far DELETE from documentdb_api_catalog.documentdb_index_queue; -- The create_indexes_background creates a remote connection via run_command_on_coordinator. Therefore, setting sequence instead of GUC. CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a"} ] }' ); NOTICE: creating collection retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"b": 1}, "name": "my_idx_b"} ], "blocking": true }', p_log_index_queue => true ); INFO: Index Queue Commands: CREATE INDEX documents_rum_index_32025 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='b',tl=2699)) retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"block_c": 1}, "name": "my_idx_blocking_c", "storageEngine": { "blocking": true }} ] }', p_log_index_queue => true ); INFO: Index Queue Commands: CREATE INDEX documents_rum_index_32026 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='block_c',tl=2699)) retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) -- Queue should be empty SELECT index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt, user_oid FROM documentdb_api_catalog.documentdb_index_queue ORDER BY index_id; index_cmd | cmd_type | index_id | index_cmd_status | collection_id | attempt | user_oid --------------------------------------------------------------------- (0 rows) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'createIndex_background_1') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- f | 3 t | 1 (2 rows) -- Show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'createIndex_background_1') ORDER BY indexrelid; indexrelid | indisvalid | indisready --------------------------------------------------------------------- documentdb_data.collection_pk_32001 | t | t documentdb_data.documents_rum_index_32024 | t | t documentdb_data.documents_rum_index_32025 | t | t documentdb_data.documents_rum_index_32026 | t | t (4 rows) CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"c": 1}, "name": "my_idx_c"}, {"key": {"d": 1}, "name": "my_idx_d"} ] }', p_log_index_queue => true ); INFO: Index Queue Commands: CREATE INDEX CONCURRENTLY documents_rum_index_32027 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='c',tl=2699)) ,CREATE INDEX CONCURRENTLY documents_rum_index_32028 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='d',tl=2699)) retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) -- Index request submission will fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"c": 1}, "name": "my_idx_c", "unique": true} ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { \"v\" : 2, \"key\" : { \"c\" : 1 }, \"name\" : \"my_idx_c\", \"unique\" : true }, existing index: { \"v\" : 2, \"key\" : { \"c\" : 1 }, \"name\" : \"my_idx_c\" }", "code" : { "$numberInt" : "587202589" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) -- create one concurrent and one blocking. CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"block_e": 1}, "name": "my_idx_block_e"}, {"key": {"block_f": 1}, "name": "my_idx_block_f", "storageEngine": { "blocking": true } } ] }', p_log_index_queue => true ); INFO: Index Queue Commands: CREATE INDEX CONCURRENTLY documents_rum_index_32029 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='block_e',tl=2699)) ,CREATE INDEX documents_rum_index_32030 ON documentdb_data.documents_32001 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_single_path_ops(path='block_f',tl=2699)) retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'createIndex_background_1') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- f | 7 t | 1 (2 rows) -- Test unique and non-unique index creation in same request ------ check the intermediate response SELECT documentdb_api_internal.create_indexes_background_internal( 'db', '{ "createIndexes": "intermediate", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true}, {"key": {"b": 1}, "name": "my_idx_b" } ] }' ); NOTICE: creating collection create_indexes_background_internal --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) --- sleep for 2 seconds, so above request is processed by cron-job SELECT pg_sleep(2); pg_sleep --------------------------------------------------------------------- (1 row) ------ check the end-to-end success flow SELECT documentdb_api.insert_one('db','mycol', '{"_id": 1, "a" : 80, "b" : 10 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','mycol', '{"_id": 2, "a" : 90, "b" : 20 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "mycol", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true}, {"key": {"b": 1}, "name": "my_idx_b" } ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'mycol') ORDER BY 1,2; index_type_is_primary | index_type_count --------------------------------------------------------------------- f | 2 t | 1 (2 rows) -- Test constraint violation for unique index, insert duplicate docs SELECT documentdb_api.insert_one('db','constraint', '{"_id": 1, "a" : 80 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','constraint', '{"_id": 2, "a" : 80 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'my_idx_a'", "code" : { "$numberInt" : "319029277" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) -- try multiple such requests which are going to fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'my_idx_a'", "code" : { "$numberInt" : "319029277" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) -- try multiple such requests which are going to fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Duplicate key violation on the requested collection: Index 'my_idx_a'", "code" : { "$numberInt" : "319029277" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) -- test skippable error test CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "ValidateVectorSearchAsync", "indexes": [ { "name": "largeVectorIndex", "key": { "largevector": "cosmosSearch"}, "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 2001 } } ] }'); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : \"largeVectorIndex\", \"key\" : { \"largevector\" : \"cosmosSearch\" }, \"cosmosSearchOptions\" : { \"kind\" : \"vector-ivf\", \"numLists\" : 100, \"similarity\" : \"COS\", \"dimensions\" : 2001 } }:field cannot have more than 2000 dimensions for vector index", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "ValidateVectorSearchAsync", "indexes": [ { "name": "largeVectorIndex", "key": { "largevector": "cosmosSearch"}, "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 2001 } } ] }'); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Error in specification { \"name\" : \"largeVectorIndex\", \"key\" : { \"largevector\" : \"cosmosSearch\" }, \"cosmosSearchOptions\" : { \"kind\" : \"vector-hnsw\", \"similarity\" : \"COS\", \"dimensions\" : 2001 } }:field cannot have more than 2000 dimensions for vector index", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) -- test another skippable error SELECT documentdb_api.insert_one('db','LargeKeySize', '{"_id": 1, "a" : [ "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ3" ] }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "LargeKeySize", "indexes": [ { "key" : { "a": 1 }, "name": "rumConstraint1"}] }'); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "UnsupportedLanguage", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "ok" } ] }'); NOTICE: creating collection retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "unsupported language: \"ok\" for text index version 3", "code" : { "$numberInt" : "503316509" } } }, "ok" : { "$numberInt" : "0" } } | f (1 row) --Reset -- so that other tests do not get impacted SELECT change_index_jobs_schema.change_index_jobs_status(false); NOTICE: Processing job_id: 3 NOTICE: Processing job_id: 4 change_index_jobs_status --------------------------------------------------------------------- (1 row) -- test CheckForIndexCmdToFinish DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- add dummy entries INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id, comment) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32101, 3, 32000, '{"err_msg" : "deadlock detected", "err_code" : { "$numberInt" : "16908292" }}'); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, global_pid, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 10015415, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'R', 32105, 2, 32000); -- this should return finish : 1, ok : 0 and error message due to index_id 32101 SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); retval | ok | complete --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "deadlock detected. createIndexes() command might cause deadlock when there is a concurrent operation that require exclusive access on the same collection", "code" : { "$numberInt" : "16908292" } } }, "ok" : { "$numberInt" : "0" } } | f | t (1 row) DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test failure but no comment. INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32102, 3, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32103, 4, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32104, 4, 32000); -- this should return finish : 1, ok : 0 and error message due to empty comment of failed request SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); retval | ok | complete --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Failed to create index", "code" : { "$numberInt" : "29" } } }, "ok" : { "$numberInt" : "0" } } | f | t (1 row) DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test with failed global_pid, attempt is still 1 INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, global_pid, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 10015415, 32000); -- this should return finish : 0, ok : 1, it should wait for cron job to pick request again for index_id 32005 and mark attempt = 2 SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); retval | ok | complete --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } | t | f (1 row) DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test with attempt > 1 INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 32000, 4); -- this should return finish : 1, ok : 0 and error message due to one attempt is failed "Index creation attempt failed" SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); retval | ok | complete --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "ok" : { "$numberInt" : "0" }, "errmsg" : "Failed to create index", "code" : { "$numberInt" : "29" } } }, "ok" : { "$numberInt" : "0" } } | f | t (1 row) DELETE FROM documentdb_api_catalog.documentdb_index_queue; SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101]}}'); retval | ok | complete --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } | t | t (1 row) BEGIN; -- test config update, documentdb_api_internal.schedule_background_index_build_jobs reads default guc values SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); -- (1 row) SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; schedule | jobname --------------------------------------------------------------------- 1 seconds | documentdb_index_build_task_1 1 seconds | documentdb_index_build_task_2 (2 rows) -- now set guc values and verify that they take effect SET LOCAL documentdb.maxNumActiveUsersIndexBuilds TO 1; -- default value for the indexBuildScheduleInSec SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); -- (1 row) SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; schedule | jobname --------------------------------------------------------------------- 1 seconds | documentdb_index_build_task_1 (1 row) SET LOCAL documentdb.maxNumActiveUsersIndexBuilds TO 1; SET LOCAL documentdb.indexBuildScheduleInSec TO 3; SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); -- (1 row) SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; schedule | jobname --------------------------------------------------------------------- 3 seconds | documentdb_index_build_task_1 (1 row) ROLLBACK; SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; schedule | jobname --------------------------------------------------------------------- 1 seconds | documentdb_index_build_task_1 1 seconds | documentdb_index_build_task_2 (2 rows) commands_create_indexes_pfe_a.out000066400000000000000000000575251507310017400365370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 1600000; SET documentdb.next_collection_id TO 16000; SET documentdb.next_collection_index_id TO 16000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; -- supported "partialFilterExpression" operators -- SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "b": {"$gte": 10} } } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_i', 'my_idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_16001 ON documentdb_data.documents_16000 USING documentdb_rum (document bson_rum_single_path_ops (path=a, iswildcard='true', tl='2699')) WHERE (document #>= '{ "b" : { "$numberInt" : "10" } }'::bsonquery) (1 row) -- not the same index since this doesn't specify partialFilterExpression SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1" } ] }', true ); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "a.$**" : 1 }, "name" : "my_idx_1" }, existing index: { "v" : 2, "key" : { "a.$**" : 1 }, "name" : "my_idx_1", "partialFilterExpression" : { "b" : { "$gte" : 10 } } } -- but this is the same index, so should not return an error SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "b": {"$gte": 10} } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"z.$**": 1}, "name": "my_idx_3", "partialFilterExpression": { "c": {"$type": "number" } } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('mydb','{ "listIndexes": "collection_i" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""mydb.collection_i"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a.$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""my_idx_1"", ""partialFilterExpression"" : { ""b"" : { ""$gte"" : { ""$numberInt"" : ""10"" } } } }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""z.$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""my_idx_3"", ""partialFilterExpression"" : { ""c"" : { ""$type"" : ""number"" } } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) -- force using my_idx_1 when possible SELECT documentdb_distributed_test_helpers.drop_primary_key('mydb', 'collection_i'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT SUM(1) FROM documentdb_api.insert_one('mydb','collection_i', '{"a":"foo"}'), generate_series(1, 10); sum --------------------------------------------------------------------- 10 (1 row) BEGIN; set local enable_seqscan TO OFF; SET seq_page_cost TO 10000000; -- even if filter exactly matches the partialFilterExpression of my_idx_1, -- cannot use the index since the index key is "a.$**" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 10} } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_16000_1600000 collection Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bson) (8 rows) -- can use the index since it filters on the index key as well EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 10} }, { "a": 4 } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_16000_1600000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 11} }, { "a": 4 } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_16000_1600000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$numberInt" : "11" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gt": 12} }, { "a": 4 } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_16000_1600000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@>) '{ "b" : { "$numberInt" : "12" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (11 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$eq": 13} }, { "a": 4 } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_16000_1600000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "b" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "13" } }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) (11 rows) -- cannot use index (no PFE) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "c": { "$type": "string" } } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_16000_1600000 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "z" : { "$numberInt" : "13" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@#) '{ "c" : "string" }'::documentdb_core.bson)) (8 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "a": 4 } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_16000_1600000 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "z" : { "$numberInt" : "13" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) (8 rows) -- can use index EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "c": { "$type": "number" } } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_16000_1600000 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "z" : { "$numberInt" : "13" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_dollar_type(document, '{ "c" : "number" }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@#) '{ "c" : "number" }'::documentdb_core.bson) -> Bitmap Index Scan on my_idx_3 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "z" : { "$numberInt" : "13" } }'::documentdb_core.bson) (11 rows) COMMIT; -- unsupported "partialFilterExpression" operators -- CREATE FUNCTION create_index_arg_using_pfe(p_pfe documentdb_core.bson) RETURNS documentdb_core.bson AS $$ BEGIN RETURN format( '{ "createIndexes": "collection_5", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": %s } ] }', p_pfe )::documentdb_core.bson; END; $$ LANGUAGE plpgsql; SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"$or": [{"a": 1}]} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "$or" : [ { "a" : 1 } ] } ] } }:Expression not supported in partial index: $or a $eq 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$nor": [{"a": 1}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$nor" : [ { "a" : 1 } ] } }:Expression not supported in partial index: $not $or a $eq 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$nor": [{"a": 1}, {"b": 1}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$nor" : [ { "a" : 1 }, { "b" : 1 } ] } }:Expression not supported in partial index: $not $or a $eq 1 b $eq 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": 3}, {"a": {"$in": [2]}}, {"c": 4} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "b" : 3 }, { "a" : { "$in" : [ 2 ] } }, { "c" : 4 } ] } }:Expression not supported in partial index: a $in [ 2 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$ne": 1 } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$ne" : 1 } }:unknown top level operator: $ne. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$ne": 1} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$ne" : 1 } } }:Expression not supported in partial index: a $ne 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$nin": [1,2,3]} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$nin" : [ 1, 2, 3 ] } } }:Expression not supported in partial index: a $nin [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": 3}, {"a": {"$in": 2}}, {"c": 4} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "b" : 3 }, { "a" : { "$in" : 2 } }, { "c" : 4 } ] } }:Expected 'array' type for $in SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"$and": [{"a": 1}, {"b": 3}]} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "$and" : [ { "a" : 1 }, { "b" : 3 } ] } ] } }:$and only supported in partialFilterExpression at top level SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": 1, "$and": [{"c": 1}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : 1, "$and" : [ { "c" : 1 } ] } }:$and only supported in partialFilterExpression at top level SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": 1, "b": {"$and": [{"d": 1}]} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : 1, "b" : { "$and" : [ { "d" : 1 } ] } } }:Unrecognized operator specified: $and SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$not": {"$eq": [1,2,3]}} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$not" : { "$eq" : [ 1, 2, 3 ] } } } }:Expression not supported in partial index: $not a $eq [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"a": {"$not": {"$eq": [1,2,3]}}}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "a" : { "$not" : { "$eq" : [ 1, 2, 3 ] } } } ] } }:Expression not supported in partial index: $not a $eq [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"a": {"$exists": true}}, {"a": {"$size": 5}} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "a" : { "$exists" : true } }, { "a" : { "$size" : 5 } } ] } }:Expression not supported in partial index: a $size 5 SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"b": 55}, {"a": {"$exists": false}}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "b" : 55 }, { "a" : { "$exists" : false } } ] } }:Expression not supported in partial index: a $exists false SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": "b", "item": {"$exists": 1, "$text": {"$search": "coffee"}}, "c": "d" } '), true); ERROR: $text operator functionality not implemented yet SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$and": [{"a": 1}, {"b": 3}]} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$and" : [ { "a" : 1 }, { "b" : 3 } ] } } }:Unrecognized operator specified: $and SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"p": 1}, {"q": 2}], "b": [{"z": 1}, {"t": 2}], "$and": [{"p": 1}, {"q": 2}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "p" : 1 }, { "q" : 2 } ], "b" : [ { "z" : 1 }, { "t" : 2 } ] } }:$and only supported in partialFilterExpression at top level SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": {"$gte": 1, "$lte": 3}} ] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$and" : [ { "b" : { "$gte" : 1, "$lte" : 3 } } ] } }:$and only supported in partialFilterExpression at top level SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$unknown_operator": 1} } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "a" : { "$unknown_operator" : 1 } } }:Unrecognized operator specified: $unknown_operator SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$unknown_operator": [{"a": 1}] } '), true); ERROR: Error in specification { "key" : { "c.d" : 1 }, "name" : "new_idx", "partialFilterExpression" : { "$unknown_operator" : [ { "a" : 1 } ] } }:unknown top level operator: $unknown_operator. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. commands_create_indexes_pfe_b.out000066400000000000000000000635141507310017400365330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 120000; SET documentdb.next_collection_id TO 12000; SET documentdb.next_collection_index_id TO 12000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('compound_index_test', 'compound_index', '{"a.b": 1, "c.d": 1}'), true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','compound_index_test'); drop_primary_key --------------------------------------------------------------------- (1 row) BEGIN; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'compound_index_test') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_12000_120001 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on compound_index Index Cond: (document OPERATOR(documentdb_api_catalog.@>=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) ROLLBACK; -- supported "partialFilterExpression" operators -- -- note that inner $and is not an operator SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "$and": [ { "a": { "b": { "x": {"$and": [ {"$eq": 1} ] }, "y": [1]} , "c": 3} }, { "b": {"$gte": 10} } ] } } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12003 ON documentdb_data.documents_12001 USING documentdb_rum (document bson_rum_single_path_ops (path=a, iswildcard='true', tl='2699')) WHERE ((document #= '{ "a" : { "b" : { "x" : { "$and" : [ { "$eq" : { "$numberInt" : "1" } } ] }, "y" : [ { "$numberInt" : "1" } ] }, "c" : { "$numberInt" : "3" } } }'::bsonquery) AND (document #>= '{ "b" : { "$numberInt" : "10" } }'::bsonquery)) (1 row) -- note that it's not the $regex operator SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"f.$**": 1}, "name": "my_idx_2", "partialFilterExpression": { "item": {"a": {"$regex": "^p.*", "$options": "si"}} } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_2'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12004 ON documentdb_data.documents_12001 USING documentdb_rum (document bson_rum_single_path_ops (path=f, iswildcard='true', tl='2699')) WHERE (document #= '{ "item" : { "a" : { "$regularExpression" : { "pattern" : "^p.*", "options" : "is" } } } }'::bsonquery) (1 row) -- $exists: true is supported SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"r.$**": 1}, "name": "my_idx_3", "partialFilterExpression": { "$and": [ {"b": 55}, {"a": {"$exists": true}}, {"c": {"$exists": 1}}, {"d": {"$exists": -1}} ] } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_3'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12005 ON documentdb_data.documents_12001 USING documentdb_rum (document bson_rum_single_path_ops (path=r, iswildcard='true', tl='2699')) WHERE ((document #= '{ "b" : { "$numberInt" : "55" } }'::bsonquery) AND (document #>= '{ "a" : { "$minKey" : 1 } }'::bsonquery) AND (document #>= '{ "c" : { "$minKey" : 1 } }'::bsonquery) AND (document #>= '{ "d" : { "$minKey" : 1 } }'::bsonquery)) (1 row) -- While the reference implementation throws an error for the following: -- -- "partialFilterExpression" { -- "$and": [{"p": 1}, {"q": 2}], -- "b": [{"z": 1}, {"t": 2}] -- } -- -- , doesn't throw an error for below by ignoring the first $and expression. SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"p.$**": 1}, "name": "my_idx_4", "partialFilterExpression": { "$and": [{"p": 1}, {"q": 2}], "$and": [{"z": 1}, {"t": 2}] } } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_4'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12006 ON documentdb_data.documents_12001 USING documentdb_rum (document bson_rum_single_path_ops (path=p, iswildcard='true', tl='2699')) WHERE ((document #= '{ "z" : { "$numberInt" : "1" } }'::bsonquery) AND (document #= '{ "t" : { "$numberInt" : "2" } }'::bsonquery)) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb_4', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_5", "partialFilterExpression": { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} }, "c": {"$exists": 1} } } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb_4', 'collection_10', 'my_idx_5'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12009 ON documentdb_data.documents_12003 USING documentdb_rum (document bson_rum_single_path_ops (path=a, iswildcard='true', tl='2699')) WHERE ((document #= '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::bsonquery) AND (document #= '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::bsonquery) AND (document #>= '{ "c" : { "$minKey" : 1 } }'::bsonquery)) (1 row) -- force using my_idx_5 when possible SELECT documentdb_distributed_test_helpers.drop_primary_key('mydb_4', 'collection_10'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT SUM(1) FROM documentdb_api.insert_one('mydb_4','collection_10', '{"c":"foo"}'), generate_series(1, 10); sum --------------------------------------------------------------------- 10 (1 row) BEGIN; set local enable_seqscan TO OFF; SET seq_page_cost TO 10000000; -- uses my_idx_5 EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} }, "c": {"$exists": 1} } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_12003_120020 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bson)) -> Bitmap Index Scan on my_idx_5 (10 rows) -- cannot use my_idx_5 since "b.e" is missing EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]} }, "c": {"$exists": 1} } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_12003_120020 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bson)) (8 rows) -- cannot use my_idx_5 since the filter on "c" is missing EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} } } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_12003_120020 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bson)) (8 rows) -- uses my_idx_5 even if we added a filter on "another_field" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "c": { "d": [1,2,3] }, "e": { "f": 0 } } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Bitmap Heap Scan on documents_12003_120020 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bsonquery)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }, "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "another_field" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson)) -> Bitmap Index Scan on my_idx_5 (10 rows) -- cannot use my_idx_5 due to order of the fields under "b" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "e": { "f": 0 } }, "c": { "d": [1,2,3] } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_12003_120020 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "another_field" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson)) (8 rows) -- cannot use my_idx_5 due to order of the elements in array "b.c.d" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "e": { "f": 0 } }, "c": { "d": [1,3,2] } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Aggregate -> Seq Scan on documents_12003_120020 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "e" : { "f" : { "$numberInt" : "0" } } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" }, { "$numberInt" : "2" } ] } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "c" : { "$minKey" : 1 } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "another_field" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : [ { "a" : "b" }, "c", { "$numberInt" : "1" } ] }'::documentdb_core.bson)) (8 rows) COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"h.$**": 1}, "name": "my_idx_6", "partialFilterExpression": {} } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_6'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_12010 ON documentdb_data.documents_12001 USING documentdb_rum (document bson_rum_single_path_ops (path=h, iswildcard='true', tl='2699')) (1 row) -- this is normally not supported due to $or SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"z.$**": 1}, "name": "my_idx_7", "partialFilterExpression": { "$and": [ {"$or": [{"a": 1}]} ] } } ] }', true ); ERROR: Error in specification { "key" : { "z.$**" : 1 }, "name" : "my_idx_7", "partialFilterExpression" : { "$and" : [ { "$or" : [ { "a" : 1 } ] } ] } }:Expression not supported in partial index: $or a $eq 1 SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_7'); documentdb_index_get_pg_def --------------------------------------------------------------------- (0 rows) commands_create_indexes_text.out000066400000000000000000003505221507310017400364420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6770000; SET documentdb.next_collection_id TO 6770; SET documentdb.next_collection_index_id TO 6770; -- cannot create indexes for cosmos_search without the flag enabled. SELECT documentdb_api.create_collection('db', 'create_indexes_text'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- invalid scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": 1, "c": "text" } } ] }', true); ERROR: Error in specification { "key" : { "a" : "text", "b" : 1, "c" : "text" } }:All 'text' fields within the index are required to be positioned consecutively. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "hashed", "b": 1, "c": "text" } } ] }', true); ERROR: Error in specification { "key" : { "a" : "hashed", "b" : 1, "c" : "text" } }:It is not allowed to enable more than one index plugin for the same index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": "text" }, "name": "foo", "expireAfterSeconds": 10 } ] }', true); ERROR: Creating a text index as ttl index is not supported. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": "text" }, "name": "foo", "unique": true } ] }', true); ERROR: Index type 'text' does not support the unique option SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c.$**": "text" }, "name": "foo" } ] }', true); ERROR: Error in specification { "key" : { "c.$**" : "text" }, "name" : "foo" }:Index key has an invalid field name because it begins with an operators symbol. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "foo", "wildcardProjection": { "a": 1 } } ] }', true); ERROR: Error in specification { "key" : { "$**" : "text" }, "name" : "foo", "wildcardProjection" : { "a" : 1 } }:The field 'wildcardProjection' is only allowed when 'key' is {"$**": ±1} SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "ok" } ] }', true); ERROR: unsupported language: "ok" for text index version 3 CONTEXT: SQL statement "CREATE INDEX documents_rum_index_6771 ON documentdb_data.documents_6770 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_text_path_ops(weights='', iswildcard=true,defaultlanguage='ok')) " SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "weights": { "a": 2, "b": 3, "c": 4, "d": 5 } } ] }', true); ERROR: Cannot have more than 3 custom weights in the index CONTEXT: SQL statement "CREATE INDEX documents_rum_index_6772 ON documentdb_data.documents_6770 USING documentdb_rum ( document documentdb_api_catalog.bson_rum_text_path_ops(weights='{ "a" : 2.0, "b" : 3.0, "c" : 4.0, "d" : 5.0 }', iswildcard=true)) " -- create a valid indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""a_text"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6773 | (a_text,"{ ""a"" : ""text"" }",,,,,2,,,) | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6773" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "a_text" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6774" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 1.0 }'), document bson_rum_single_path_ops (path=c)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "b": "text", "c": 1 }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""b"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6775" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='{ "b" : 1.0 }'), document bson_rum_single_path_ops (path=c)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "b": "text", "c": "text" }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""b"" : { ""$numberDouble"" : ""1.0"" }, ""c"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6776" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='{ "b" : 1.0, "c" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6777" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "idx1", "default_language": "es" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""default_language"" : ""es"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6778" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', defaultlanguage=es)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1", "weights": { "b": 100, "c": 200 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""100.0"" }, ""c"" : { ""$numberDouble"" : ""200.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6779" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 100.0, "c" : 200.0 }'), document bson_rum_single_path_ops (path=c)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1", "weights": { "c": 200, "d": 10 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""1.0"" }, ""c"" : { ""$numberDouble"" : ""200.0"" }, ""d"" : { ""$numberDouble"" : ""10.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6780" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 1.0, "c" : 200.0, "d" : 10.0 }'), document bson_rum_single_path_ops (path=c)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "$**": "text" }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6781" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text", "a": 1 }, "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6782" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true'), document bson_rum_single_path_ops (path=a)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "language_override": "idioma", "name": "idx1" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""idioma"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6783" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', languageoverride=idioma)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- more tests with wildcard text indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "$**": "text", "a": "text" }, "name": "idx1" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" }, ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6784 | (idx1,"{ ""$**"" : ""text"", ""a"" : ""text"" }",,,,,2,,,) | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6784" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text", "$**": "text" }, "name": "idx1" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6785 | (idx1,"{ ""a"" : ""text"", ""$**"" : ""text"" }",,,,,2,,,) | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6785" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "$**": 1 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6786 | (idx1,"{ ""a"" : ""text"" }",,,,,2,,,"{ ""weights"" : { ""$**"" : { ""$numberInt"" : ""1"" } } }") | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6786" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "$**": 1, "b": 2 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""2.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6787 | (idx1,"{ ""a"" : ""text"" }",,,,,2,,,"{ ""weights"" : { ""$**"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""2"" } } }") | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6787" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "b": 2, "$**": 1 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""2.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6788 | (idx1,"{ ""a"" : ""text"" }",,,,,2,,,"{ ""weights"" : { ""b"" : { ""$numberInt"" : ""2"" }, ""$**"" : { ""$numberInt"" : ""1"" } } }") | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6788" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text", "$**": "text" }, "name": "idx1", "weights": { "b": 2 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""2.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6789 | (idx1,"{ ""a"" : ""text"", ""$**"" : ""text"" }",,,,,2,,,"{ ""weights"" : { ""b"" : { ""$numberInt"" : ""2"" } } }") | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6789" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "es" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""default_language"" : ""es"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6790" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true', defaultlanguage=es)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- more tests with wildcard text indexes -- this index spec corresponds to the index spec in the JS test: fts_blogwild.js SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text" }, "name": "idx1", "weights": { "$**": 1, "title": 2 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""dummy"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" }, ""title"" : { ""$numberDouble"" : ""2.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6791" documentdb_rum (document bson_rum_text_path_ops (weights='{ "dummy" : 1.0, "title" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- test variations of the index spec - with the order of the weights, and with the wildcard -- being specified in the key document SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text" }, "name": "idx1", "weights": { "title": 2, "$**": 1 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""dummy"" : { ""$numberDouble"" : ""1.0"" }, ""title"" : { ""$numberDouble"" : ""2.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6792" documentdb_rum (document bson_rum_text_path_ops (weights='{ "dummy" : 1.0, "title" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text", "$**": "text" }, "name": "idx1", "weights": { "title": 2 } }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""dummy"" : { ""$numberDouble"" : ""1.0"" }, ""$**"" : { ""$numberDouble"" : ""1.0"" }, ""title"" : { ""$numberDouble"" : ""2.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6793" documentdb_rum (document bson_rum_text_path_ops (weights='{ "dummy" : 1.0, "title" : 2.0 }', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- we now create the same indexes as above, but with the metadata term `{ _fts: 'text', _ftsx: 1 }` SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "a_text", "weights": { "a": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""a_text"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; collection_id | index_id | index_spec | index_is_valid --------------------------------------------------------------------- 6770 | 6770 | (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) | t 6770 | 6794 | (a_text,"{ ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,"{ ""weights"" : { ""a"" : { ""$numberInt"" : ""1"" } } }") | t (2 rows) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6794" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "a_text" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6795" documentdb_rum (document bson_rum_single_path_ops (path=c), document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "b": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""b"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6796" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_single_path_ops (path=c), document bson_rum_text_path_ops (weights='{ "b" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "b": 1, "c": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""b"" : { ""$numberDouble"" : ""1.0"" }, ""c"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6797" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='{ "b" : 1.0, "c" : 1.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6798" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "default_language": "es", "weights": { "a": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""default_language"" : ""es"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6799" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', defaultlanguage=es)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 100, "c": 200 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""100.0"" }, ""c"" : { ""$numberDouble"" : ""200.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6800" documentdb_rum (document bson_rum_single_path_ops (path=c), document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 100.0, "c" : 200.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 1, "c": 200, "d": 10 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""c"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" }, ""b"" : { ""$numberDouble"" : ""1.0"" }, ""c"" : { ""$numberDouble"" : ""200.0"" }, ""d"" : { ""$numberDouble"" : ""10.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6801" documentdb_rum (document bson_rum_single_path_ops (path=c), document bson_rum_text_path_ops (weights='{ "a" : 1.0, "b" : 1.0, "c" : 200.0, "d" : 10.0 }')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""a"" : { ""$numberInt"" : ""1"" }, ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6802" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "a": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6803" documentdb_rum (document bson_rum_single_path_ops (path=a), document bson_rum_text_path_ops (weights='', iswildcard='true')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "language_override": "idioma", "name": "idx1", "weights": { "a": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""weights"" : { ""a"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""idioma"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6804" documentdb_rum (document bson_rum_text_path_ops (weights='{ "a" : 1.0 }', languageoverride=idioma)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "default_language": "es", "weights": { "$**": 1 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""default_language"" : ""es"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6805" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true', defaultlanguage=es)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '6770'::bigint) -- shard and re-observe SELECT documentdb_api.shard_collection('db', 'create_indexes_text', '{ "_id" : "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""db.create_indexes_text"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_fts"" : ""text"", ""_ftsx"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx1"", ""default_language"" : ""es"", ""weights"" : { ""$**"" : { ""$numberDouble"" : ""1.0"" } }, ""textIndexVersion"" : { ""$numberInt"" : ""2"" }, ""language_override"" : ""language"" } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) \d documentdb_data.documents_6770 Table "documentdb_data.documents_6770" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6770" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6806" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_6807" documentdb_rum (document bson_rum_text_path_ops (weights='', iswildcard='true', defaultlanguage=es)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = get_shard_key_value('{ "_id" : "hashed" }'::bson, 6770::bigint, document)) CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- now create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- creating more text indexes should just fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "b": "text" }, "name": "b_text" } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "b" : "text" }, "name" : "b_text" }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "b": "text" }, "name": "c_b_text" } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "c" : 1, "b" : "text" }, "name" : "c_b_text" }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "d": 1, "b": "text" }, "name": "c_b_text" } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 1, "b" : "text" }, "name" : "c_b_text" }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "d": "text", "b": "text" }, "name": "c_b_text" } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : "text", "b" : "text" }, "name" : "c_b_text" }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "weights": { "a": 2, "b": 3, "c": 4, "d": 5 } } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "$**" : "text" }, "name" : "idx1", "weights" : { "a" : 2, "b" : 3, "c" : 4, "d" : 5 } }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "f": "text" }, "name": "idx2", "default_language": "de" } ] }', true); ERROR: Expected exactly one text index. Requested index: { "v" : 2, "key" : { "f" : "text" }, "name" : "idx2", "default_language" : "de" }, existing index: { "v" : 2, "key" : { "a" : "text" }, "name" : "a_text" } commands_create_indexes_wp.out000066400000000000000000001431201507310017400360760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1700000; SET documentdb.next_collection_id TO 17000; SET documentdb.next_collection_index_id TO 17000; -- cannot specify wildcardProjection for a non-root wildcard index SELECT documentdb_api_internal.create_indexes_non_concurrently( 'wp_test', '{ "createIndexes": "fail_test", "indexes": [ { "key": {"a.$**": 1}, "name": "idx", "wildcardProjection": {"a": 1} } ] }', true ); ERROR: Error in specification { "key" : { "a.$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1 } }:The field 'wildcardProjection' is only allowed when 'key' is {"$**": ±1} -- cannot specify wildcardProjection for a non-wildcard index SELECT documentdb_api_internal.create_indexes_non_concurrently( 'wp_test', '{ "createIndexes": "fail_test", "indexes": [ { "key": {"a": 1}, "name": "idx", "wildcardProjection": {"a": 1} } ] }', true ); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1 } }:The field 'wildcardProjection' is only allowed in an 'wildcard' index CREATE FUNCTION create_index_arg_using_wp(p_wp text) RETURNS documentdb_core.bson AS $$ BEGIN RETURN format( '{ "createIndexes": "fail_test", "indexes": [ { "key": {"$**": 1}, "name": "idx", "wildcardProjection": %s } ] }', p_wp )::documentdb_core.bson; END; $$ LANGUAGE plpgsql; -- all fields specified in wildcardProjection must be included or excluded, except _id field SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": 0}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1, "b" : 0 } }:Failed to parse: wildcardProjection :: caused by :: exclusion cannot be applied to field b within the inclusion projection. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b.c": 0}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1, "b.c" : 0 } }:Failed to parse: wildcardProjection :: caused by :: exclusion cannot be applied to field b.c within the inclusion projection. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"b.c": 1, "a": 0}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "b.c" : 1, "a" : 0 } }:Failed to parse: wildcardProjection :: caused by :: exclusion cannot be applied to field a within the inclusion projection. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"x": 1, "y.t": 0}, "b.c": 0}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : { "x" : 1, "y.t" : 0 }, "b.c" : 0 } }:Failed to parse: wildcardProjection :: caused by :: exclusion cannot be applied to field y.t within the inclusion projection. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"x": 1, "y": 1}, "b.c": 0}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : { "x" : 1, "y" : 1 }, "b.c" : 0 } }:Failed to parse: wildcardProjection :: caused by :: exclusion cannot be applied to field b.c within the inclusion projection. -- wildcardProjection cannot be empty SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { } }:The 'wildcardProjection' field must not contain an empty object -- wildcardProjection must be document SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('5'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : 5 }:The field 'wildcardProjection' must be a non-empty object, but got int -- wildcardProjection cannot contain an empty document as an inner-level specification SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": {"c": 1, "d": {}, "e": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1, "b" : { "c" : 1, "d" : { }, "e" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: An empty sub-projection is not a valid value. Found empty object at path -- and inner-level specification must be a document or a path string SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": {"c": 1, "d": [], "e": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1, "b" : { "c" : 1, "d" : [ ], "e" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Projection specification is invalid; using computed fields is not supported in kBanComputedFields parsing mode -- show that we throw an error for invalid paths used in wildcardProjection document SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a..b": 1}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a..b" : 1 } }:Failed to parse: wildcardProjection :: caused by :: FieldPath field names cannot be completely empty strings. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"a..b": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : -1, "b" : { "a..b" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: FieldPath field names cannot be completely empty strings. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"a.b.": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : -1, "b" : { "a.b." : 1 } } }:Failed to parse: wildcardProjection :: caused by :: The FieldPath cannot terminate with a '.' character. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : -1, "b" : { "" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: A FieldPath object cannot be created when the provided string is empty. SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"$aa": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : -1, "b" : { "$aa" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Projection specification is invalid; using computed fields is not supported in kBanComputedFields parsing mode SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"$a": -1, "b": {"aa": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "$a" : -1, "b" : { "aa" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: FieldPath field names cannot begin with the operators symbol '$'; you might want to use $getField or $setField instead. -- idx_1: for _id field, we will take the last inclusion specification into the account -- idx_2: not specifying inclusion for _id field would result in excluding _id field by default SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_1", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"_id": 0, "a": {"x": 10.5, "y": true}, "_id": false, "b.c": 1, "_id": -0.6} }, { "key": {"$**": -1}, "name": "idx_2", "wildcardProjection": {"a": {"x": 10.5, "y": true, "z.a.b": -100}, "b.c": 1, "k": {"z.a.b": -100}} } ] }', true ); ERROR: Error in specification { "key" : { "$**" : -1 }, "name" : "idx_2", "wildcardProjection" : { "a" : { "x" : 10.5, "y" : true, "z.a.b" : -100 }, "b.c" : 1, "k" : { "z.a.b" : -100 } } }:A numeric value in a $** index key pattern must be positive. SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_1', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- (0 rows) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_1', 'idx_2'); documentdb_index_get_pg_def --------------------------------------------------------------------- (0 rows) SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_1" }') ORDER BY 1; ERROR: Namespace does not currently exist: wp_test.ok_test_1 -- using $ in a field path is ok unless it's the first character SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_2", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": -1, "b": {"b.a$a.k$": 1}} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_2', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_17002 ON documentdb_data.documents_17001 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a", "b.b.a$a.k$" ]', isexclusion='false')) (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_2" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""wp_test.ok_test_2"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx_1"", ""wildcardProjection"" : { ""a"" : true, ""b"" : { ""b"" : { ""a$a"" : { ""k$"" : true } } }, ""_id"" : false } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_3", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 1, "b": {"c": 1, "d.e": 1}, "_id": 0} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_3'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_3" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""wp_test.ok_test_3"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx_1"", ""wildcardProjection"" : { ""a"" : true, ""b"" : { ""c"" : true, ""d"" : { ""e"" : true } }, ""_id"" : false } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.b": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17002_1700004 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17002_1700004 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": {"b": 1}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17002_1700004 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"_id": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17002_1700004 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (7 rows) -- cannot use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17002_1700004 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b": {"d": 1}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17002_1700004 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "d" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"e": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17002_1700004 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_4", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 0, "b": {"c": 0, "d.e": 0}, "f.g.h": 0} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_4'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('wp_test', '{ "listIndexes": "ok_test_4" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""wp_test.ok_test_4"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx_1"", ""wildcardProjection"" : { ""a"" : false, ""b"" : { ""c"" : false, ""d"" : { ""e"" : false } }, ""f"" : { ""g"" : { ""h"" : false } }, ""_id"" : false } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; -- cannot use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.b": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17003_1700006 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17003_1700006 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": {"b": 1}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17003_1700006 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "b" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"_id": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17003_1700006 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson)) (7 rows) -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b": {"d": 1}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "d" : { "$numberInt" : "1" } } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "d" : { "$numberInt" : "1" } } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"e": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"f.g": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "f.g" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "f.g" : { "$numberInt" : "1" } }'::documentdb_core.bson) (9 rows) COMMIT; SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 1}, "a": {"k": 1}}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 1}, "a": {"k": 2}}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 2}, "a": {"k": 2}}'); ?column? --------------------------------------------------------------------- 1 (1 row) BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1, "a.k": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.k" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.k": 1, "b.d": 1}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.k" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : { "$numberInt" : "1" } }'::documentdb_core.bson) (10 rows) SELECT COUNT(*)=1 FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1, "a.k": 1}'; ?column? --------------------------------------------------------------------- t (1 row) SELECT COUNT(*)=1 FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.k": 1, "b.d": 1}'; ?column? --------------------------------------------------------------------- t (1 row) COMMIT; BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": {"$in": [1,2,3]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "b.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "b.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) (9 rows) -- cannot use idx_1 due to filter on "a.z.r" in "$or" EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"$or": [{"b.d": {"$eq": [1,2,3]}}, {"a.z": {"r": {"$gte": 5}}}]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_17003_1700006 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a.z" : { "r" : { "$gte" : { "$numberInt" : "5" } } } }'::documentdb_core.bson)) (7 rows) -- can use idx_1 since none of the quals in "$or" are excluded EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"$or": [{"b.d": {"$eq": [1,2,3]}}, {"k": 5}]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_17003_1700006 collection Recheck Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "k" : { "$numberInt" : "5" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "b.d" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on idx_1 Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "k" : { "$numberInt" : "5" } }'::documentdb_core.bson) (12 rows) COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_5", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 0, "b": {"c": {"p": 0, "r": false}, "d._id": 0}, "_id": 1} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_5" }') ORDER BY 1; list_indexes_cursor_first_page --------------------------------------------------------------------- ("{ ""cursor"" : { ""id"" : { ""$numberLong"" : ""0"" }, ""ns"" : ""wp_test.ok_test_5"", ""firstBatch"" : [ { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""_id"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""_id_"" }, { ""v"" : { ""$numberInt"" : ""2"" }, ""key"" : { ""$**"" : { ""$numberInt"" : ""1"" } }, ""name"" : ""idx_1"", ""wildcardProjection"" : { ""a"" : false, ""b"" : { ""c"" : { ""p"" : false, ""r"" : false }, ""d"" : { ""_id"" : false } }, ""_id"" : true } } ] }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",,f,0) (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_5'); drop_primary_key --------------------------------------------------------------------- (1 row) SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_5') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"d.e.f": 1, "_id": 0}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using idx_1 on documents_17004_1700008 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@=) '{ "d.e.f" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "_id" : { "$numberInt" : "0" } }'::documentdb_core.bson)) Filter: (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "0" } }'::documentdb_core.bson) (8 rows) COMMIT; -- not the same index since this doesn't specify wildcardProjection SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_5", "indexes": [ { "key": {"$**": 1}, "name": "idx_2" } ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- test path collision SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "a.b": 1}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : 1, "a.b" : 1 } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path a.b remaining portion b SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": 1, "a": 1}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b" : 1, "a" : 1 } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path a SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a.b.c": 1}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b" : { "c.d" : 1 }, "a.b.c" : 1 } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path a.b.c SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b" : { "c.d" : 1 }, "a" : { "b.c" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path b.c SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c.d.e": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b" : { "c.d" : 1 }, "a" : { "b.c.d.e" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path b.c.d.e remaining portion c.d.e SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c": {"d.e": 1}}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b" : { "c.d" : 1 }, "a" : { "b.c" : { "d.e" : 1 } } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path d.e remaining portion e SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b.c": 1, "a.b": {"c.d": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a.b.c" : 1, "a.b" : { "c.d" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path c.d remaining portion d SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c": 1}, "a.b": {"c.d": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : { "b.c" : 1 }, "a.b" : { "c.d" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path c.d remaining portion d SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c.d.e": 1}, "a.b": {"c.d": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : { "b.c.d.e" : 1 }, "a.b" : { "c.d" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path c.d SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c": {"d.e": 1}}, "a.b": {"c.d": 1}}'), true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx", "wildcardProjection" : { "a" : { "b.c" : { "d.e" : 1 } }, "a.b" : { "c.d" : 1 } } }:Failed to parse: wildcardProjection :: caused by :: Collision detected in specified path c.d SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_1", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 1, "a": {"b": 1}} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_1', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_17011 ON documentdb_data.documents_17005 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a.b" ]', isexclusion='false')) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_2", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": {"b": 1}, "a": 1} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_2', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_17013 ON documentdb_data.documents_17006 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a" ]', isexclusion='false')) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_3", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a.b": {"c.d": 1}, "a.b": 1} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_3', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_17015 ON documentdb_data.documents_17007 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a.b" ]', isexclusion='false')) (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_4", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a.b": 1, "a.b": {"c.d": 1}} } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_4', 'idx_1'); documentdb_index_get_pg_def --------------------------------------------------------------------- CREATE INDEX documents_rum_index_17017 ON documentdb_data.documents_17008 USING documentdb_rum (document bson_rum_wildcard_project_path_ops (includeid='false', tl='2699', wkl='200', pathspec='[ "a.b.c.d" ]', isexclusion='false')) (1 row) commands_create_ttl_indexes.out000066400000000000000000002654771507310017400362770ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 2000000; SET documentdb.next_collection_id TO 20000; SET documentdb.next_collection_index_id TO 20000; SET search_path TO documentdb_api_catalog, documentdb_core, documentdb_data, public; -- make sure jobs are scheduled and disable it to avoid flakiness on the test as it could run on its schedule and delete documents before we run our commands in the test select schedule, command, active from cron.job where jobname like '%ttl_task%'; schedule | command | active --------------------------------------------------------------------- * * * * * | CALL documentdb_api_internal.delete_expired_rows(); | t (1 row) select cron.unschedule(jobid) from cron.job where jobname like '%ttl_task%'; unschedule --------------------------------------------------------------------- t (1 row) -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 8, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 1. Create TTL Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- 2. List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 20000 | 20000 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 20000 | 20001 | { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } | t (2 rows) -- 3. Call ttl purge procedure with a batch size of 10 CALL documentdb_api_internal.delete_expired_rows(10); -- 4.a. Check what documents are left after purging SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 20000 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "ttl" : { "$date" : { "$numberLong" : "2657899731608" } } } 20000 | { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "ttl" : true } 20000 | { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "ttl" : "would not expire" } (3 rows) -- 5. TTL indexes behaves like normal indexes that are used in queries BEGIN; set local enable_seqscan TO off; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT object_id FROM documentdb_data.documents_20000 WHERE bson_dollar_eq(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) LIMIT 100; $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Limit -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Bitmap Heap Scan on documents_20000_2000000 documents_20000 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ttl_index Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) (11 rows) END; -- 6. Explain of the SQL query that is used to delete documents BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) DELETE FROM documentdb_data.documents_20000_2000000 WHERE ctid IN ( SELECT ctid FROM documentdb_data.documents_20000_2000000 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) AND shard_key_value = 20000 LIMIT 100 ) $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Delete on documents_20000_2000000 -> Nested Loop -> HashAggregate Group Key: "ANY_subquery".ctid -> Subquery Scan on "ANY_subquery" -> Limit -> Bitmap Heap Scan on documents_20000_2000000 documents_20000_2000000_1 Recheck Cond: ((document @< '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) AND (shard_key_value = 20000)) -> BitmapAnd -> Bitmap Index Scan on ttl_index Index Cond: (document @< '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = 20000) -> Tid Scan on documents_20000_2000000 TID Cond: (ctid = "ANY_subquery".ctid) (15 rows) END; -- 7.a. Query to select all the shards corresponding to a ttl index that needs to be considered for purging -- ttlcoll is an unsharded collection SELECT idx.collection_id, idx.index_id, (index_spec).index_key as key, (index_spec).index_pfe as pfe, -- trunc(extract(epoch FROM now()) * 1000, 0)::int8 as currentDateTime, -- removed to reduce test flakiness (index_spec).index_expire_after_seconds as expiry, coll.shard_key, dist.shardid FROM documentdb_api_catalog.collection_indexes as idx, documentdb_api_catalog.collections as coll, pg_dist_shard as dist WHERE index_is_valid AND (index_spec).index_expire_after_seconds >= 0 AND idx.collection_id = coll.collection_id AND dist.logicalrelid = ('documentdb_data.documents_' || coll.collection_id)::regclass AND (dist.shardid = get_shard_id_for_distribution_column(logicalrelid, coll.collection_id) OR (coll.shard_key IS NOT NULL)) AND coll.collection_id >= 20000 AND coll.collection_id < 21000 -- added to reduce test flakiness ORDER BY shardid ASC; -- added to remove reduce flakiness collection_id | index_id | key | pfe | expiry | shard_key | shardid --------------------------------------------------------------------- 20000 | 20001 | { "ttl" : { "$numberInt" : "1" } } | | 5 | | 2000002 (1 row) -- 8. Shard collection SELECT documentdb_api.shard_collection('db','ttlcoll', '{"ttl":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- 9. Add more records with previous deleted as well as new ids SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 100, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 200, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 9.a. Query to select all the shards corresponding to a ttl index that needs to be considered for purging -- ttlcoll is an unsharded collection SELECT idx.collection_id, idx.index_id, (index_spec).index_key as key, (index_spec).index_pfe as pfe, -- trunc(extract(epoch FROM now()) * 1000, 0)::int8 as currentDateTime, -- removed to reduce test flakiness (index_spec).index_expire_after_seconds as expiry, coll.shard_key, dist.shardid FROM documentdb_api_catalog.collection_indexes as idx, documentdb_api_catalog.collections as coll, pg_dist_shard as dist WHERE index_is_valid AND (index_spec).index_expire_after_seconds >= 0 AND idx.collection_id = coll.collection_id AND dist.logicalrelid = ('documentdb_data.documents_' || coll.collection_id)::regclass AND (dist.shardid = get_shard_id_for_distribution_column(logicalrelid, coll.collection_id) OR (coll.shard_key IS NOT NULL)) AND coll.collection_id >= 20000 AND coll.collection_id < 21000 -- added to reduce test flakiness ORDER BY shardid ASC; -- added to reduce test flakiness collection_id | index_id | key | pfe | expiry | shard_key | shardid --------------------------------------------------------------------- 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000016 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000017 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000018 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000019 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000020 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000021 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000022 20000 | 20003 | { "ttl" : { "$numberInt" : "1" } } | | 5 | { "ttl" : "hashed" } | 2000023 (8 rows) -- Delete all other indexes from previous tests to reduce flakiness WITH deleted AS ( DELETE FROM documentdb_api_catalog.collection_indexes WHERE collection_id != 20000 RETURNING 1 ) SELECT true FROM deleted UNION ALL SELECT true LIMIT 1; ?column? --------------------------------------------------------------------- t (1 row) SELECT collection_id, (index_spec).index_key, (index_spec).index_name, (index_spec).index_expire_after_seconds as ttl_expiry, (index_spec).index_is_sparse as is_sparse, (index_spec).index_name as index_name FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_expire_after_seconds > 0; collection_id | index_key | index_name | ttl_expiry | is_sparse | index_name --------------------------------------------------------------------- 20000 | { "ttl" : { "$numberInt" : "1" } } | ttl_index | 5 | | ttl_index (1 row) -- 10.b. Call ttl task procedure with a batch size of 0 -- BEGIN; Set citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set citus.log_local_commands to on; -- Will print the local queries set local documentdb.SingleTTLTaskTimeBudget to 1; CALL documentdb_api_internal.delete_expired_rows(0); -- To test the sql query, it won't delete any data NOTICE: executing the command locally: SELECT index_id, collection_id, (index_spec).index_key AS index_key, (index_spec).index_pfe AS index_pfe, (index_spec).index_expire_after_seconds AS index_expire_after_seconds, (index_spec).index_is_sparse AS index_is_sparse, COALESCE((documentdb_core.bson_get_value_text((index_spec).index_options, 'enableCompositeTerm'::text))::boolean, (documentdb_core.bson_get_value_text((index_spec).index_options, 'enableOrderedIndex'::text))::boolean, false) AS index_is_ordered, (index_spec).index_name AS index_name FROM documentdb_api_catalog.collection_indexes_102009 collection_indexes WHERE (index_is_valid AND ((index_spec).index_expire_after_seconds OPERATOR(pg_catalog.>=) 0)) ORDER BY collection_id, index_id Set citus.log_remote_commands to off; Set citus.log_local_commands to off; END; -- 10.a. CALL documentdb_api_internal.delete_expired_rows(10); -- 11.a. Check what documents are left after purging SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- -2476384318775456034 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "ttl" : { "$date" : { "$numberLong" : "2657899731608" } } } -4856610847558204655 | { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "ttl" : true } -500866977185664605 | { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "ttl" : "would not expire" } (3 rows) -- 12. Explain of the SQL query that is used to delete documents after sharding BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) DELETE FROM documentdb_data.documents_20000_2000016 WHERE ctid IN ( SELECT ctid FROM documentdb_data.documents_20000_2000016 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) LIMIT 100 ) $Q$); mask_plan_id_from_distributed_subplan --------------------------------------------------------------------- Delete on documents_20000_2000016 -> Nested Loop -> HashAggregate Group Key: "ANY_subquery".ctid -> Subquery Scan on "ANY_subquery" -> Limit -> Bitmap Heap Scan on documents_20000_2000016 documents_20000_2000016_1 Recheck Cond: (document @< '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) -> Bitmap Index Scan on ttl_index Index Cond: (document @< '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) -> Tid Scan on documents_20000_2000016 TID Cond: (ctid = "ANY_subquery".ctid) (12 rows) END; -- 13. TTL index can be created SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl1": 1}, "name": "ttl_index1", "expireAfterSeconds": 100, "sparse" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl2": 1}, "name": "ttl_index2", "expireAfterSeconds": 100, "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl3": 1}, "name": "ttl_index3", "expireAfterSeconds": 100, "sparse" : true, "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl1" : { "$numberInt" : "1" } }, "name" : "ttl_index1", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl2" : { "$numberInt" : "1" } }, "name" : "ttl_index2", "unique" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl3" : { "$numberInt" : "1" } }, "name" : "ttl_index3", "sparse" : true, "unique" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } (5 rows) -- 14. TTL index creation restrictions SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": -1}]}', true); ERROR: Error in specification { "key" : { "ttl" : 1 }, "name" : "ttl_index2", "expireAfterSeconds" : -1 }:TTL index 'expireAfterSeconds' option cannot be less than 0. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": "stringNotAllowed"}]}', true); ERROR: Error in specification { "key" : { "ttl" : 1 }, "name" : "ttl_index2", "expireAfterSeconds" : "stringNotAllowed" }:The 'expireAfterSeconds' option for a TTL index must be a numeric value, but a different data type was provided: string. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": true}]}', true); ERROR: Error in specification { "key" : { "ttl" : 1 }, "name" : "ttl_index2", "expireAfterSeconds" : true }:The 'expireAfterSeconds' option for a TTL index must be a numeric value, but a different data type was provided: bool. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": 707992037530324174}]}', true); ERROR: Error in specification { "key" : { "ttl" : 1 }, "name" : "ttl_index2", "expireAfterSeconds" : 707992037530324174 }:TTL index 'expireAfterSeconds' option must be within an acceptable range, try a different number than 707992037530324224.000000. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": 100, "v" : 1}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 1, "key" : { "ttl" : 1 }, "name" : "ttl_index2", "expireAfterSeconds" : 100 }, existing index: { "v" : 2, "key" : { "ttl2" : 1 }, "name" : "ttl_index2", "unique" : true, "expireAfterSeconds" : 100 } SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); ERROR: Error in specification { "key" : { "_id" : 1 }, "name" : "ttl_idx", "expireAfterSeconds" : 100 }:The field 'expireAfterSeconds' is not valid for an _id index specification. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1, "_id" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); ERROR: Error in specification { "key" : { "_id" : 1 }, "name" : "ttl_idx", "expireAfterSeconds" : 100 }:The field 'expireAfterSeconds' is not valid for an _id index specification. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1, "non_id" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); ERROR: Error in specification { "key" : { "_id" : 1, "non_id" : 1 }, "name" : "ttl_idx", "expireAfterSeconds" : 100 }:TTL indexes work only on single fields, and compound indexes are incompatible with TTL functionality. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"non_id1": 1, "non_id2" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); ERROR: Error in specification { "key" : { "non_id1" : 1, "non_id2" : 1 }, "name" : "ttl_idx", "expireAfterSeconds" : 100 }:TTL indexes work only on single fields, and compound indexes are incompatible with TTL functionality. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"non_id1.$**": 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); ERROR: Error in specification { "key" : { "non_id1.$**" : 1 }, "name" : "ttl_idx", "expireAfterSeconds" : 100 }:Index type 'wildcard' cannot be a TTL index. -- 15. Unsupported ttl index scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl4": "hashed"}, "name": "ttl_index4", "expireAfterSeconds": 100}]}', true); ERROR: Creating a hash index as ttl index is not supported. -- 16. Behavioral difference with sharded reference implementation SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index1", "sparse" : true, "expireAfterSeconds" : 10}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index2", "sparse" : false, "expireAfterSeconds" : 10}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index3", "expireAfterSeconds": 100, "sparse" : true, "unique" : true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": "hashed"}, "name": "ttl_new_index4", "expireAfterSeconds": 100}]}', true); ERROR: Creating a hash index as ttl index is not supported. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew2": 5}, "name": "ttl_new_indexj", "sparse" : true, "expireAfterSeconds" : 10}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl1" : { "$numberInt" : "1" } }, "name" : "ttl_index1", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl2" : { "$numberInt" : "1" } }, "name" : "ttl_index2", "unique" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl3" : { "$numberInt" : "1" } }, "name" : "ttl_index3", "sparse" : true, "unique" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew" : { "$numberInt" : "1" } }, "name" : "ttl_new_index1", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "10" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew" : { "$numberInt" : "1" } }, "name" : "ttl_new_index2", "sparse" : false, "expireAfterSeconds" : { "$numberInt" : "10" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew" : { "$numberInt" : "1" } }, "name" : "ttl_new_index3", "sparse" : true, "unique" : true, "expireAfterSeconds" : { "$numberInt" : "100" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew2" : { "$numberInt" : "5" } }, "name" : "ttl_new_indexj", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "10" } } }, "ok" : { "$numberDouble" : "1.0" } } (9 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew3": "hashed"}, "name": "ttl_new_indexk", "unique" : true, "expireAfterSeconds" : 10}]}', true); ERROR: Error in specification { "key" : { "ttlnew3" : "hashed" }, "name" : "ttl_new_indexk", "unique" : true, "expireAfterSeconds" : 10 }:Index type 'hashed' does not support the unique option. -- 17. Partial filter expresson tests SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ttlcoll2", "indexes": [ { "key": {"ttl": 1}, "name": "ttl_pfe_index", "expireAfterSeconds" : 5, "partialFilterExpression": { "$and": [ {"b": 55}, {"a": {"$exists": true}}, {"c": {"$exists": 1}} ] } } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll2" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll2", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll2", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_pfe_index", "partialFilterExpression" : { "$and" : [ { "b" : { "$numberInt" : "55" } }, { "a" : { "$exists" : true } }, { "c" : { "$exists" : { "$numberInt" : "1" } } } ] }, "expireAfterSeconds" : { "$numberInt" : "5" } } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll2') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 20001 | 20011 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 20001 | 20012 | { "v" : { "$numberInt" : "2" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_pfe_index", "partialFilterExpression" : { "$and" : [ { "b" : { "$numberInt" : "55" } }, { "a" : { "$exists" : true } }, { "c" : { "$exists" : { "$numberInt" : "1" } } } ] }, "expireAfterSeconds" : { "$numberInt" : "5" } } | t (2 rows) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 0, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 1, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 2, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 3, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 4, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 5, "b": 55, "a" : 1, "c": 1, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 6, "b": 55, "a" : 1, "d": 1, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 7, "b": 55, "a" : 1, "c": 1, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 8, "b": 55, "a" : 1, "c": 1, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 9, "b": 55, "a" : 1, "c": 1, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_api_internal.delete_expired_rows(10); SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll2') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 20001 | { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "56" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "0" } } } 20001 | { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "56" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "100" } } } 20001 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "2657899731608" } } } 20001 | { "" : { "$numberInt" : "6" } } | { "_id" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "d" : { "$numberInt" : "1" }, "ttl" : [ { "$date" : { "$numberLong" : "100" } }, { "$date" : { "$numberLong" : "2657899731608" } } ] } 20001 | { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : true } 20001 | { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : "would not expire" } (6 rows) -- 18. Large TTL (expire after INT_MAX seconds aka 68 years) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ttlcoll3", "indexes": [ { "key": {"ttl": 1}, "name": "ttl_large_expireAfterSeconds", "expireAfterSeconds" : 2147483647 } ] }', true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll3" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll3", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll3", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_large_expireAfterSeconds", "expireAfterSeconds" : { "$numberInt" : "2147483647" } } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll3') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 20002 | 20013 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 20002 | 20014 | { "v" : { "$numberInt" : "2" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_large_expireAfterSeconds", "expireAfterSeconds" : { "$numberInt" : "2147483647" } } | t (2 rows) -- Timestamp: -623051866000 ( 4/4/1950 more than 68 years from 4/4/2024). So, with the ttl index index `ttl_large_expireAfterSeconds`, _id : [1, 6, 7] should be deleted. SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 0, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "-623051866000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 1, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 2, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1712253575000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 3, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "4867927028000" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 4, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 5, "b": 55, "a" : 1, "c": 1, "ttl" : [{ "$date": { "$numberLong": "1697900030774" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 6, "b": 55, "a" : 1, "d": 1, "ttl" : [{ "$date": { "$numberLong": "-623051866000" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 7, "b": 55, "a" : 1, "c": 1, "ttl" : [true, { "$date": { "$numberLong": "-623051866000" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 8, "b": 55, "a" : 1, "c": 1, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 9, "b": 55, "a" : 1, "c": 1, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_api_internal.delete_expired_rows(10); SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll3') order by object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 20002 | { "" : { "$numberInt" : "1" } } | { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "56" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "1657900030774" } } } 20002 | { "" : { "$numberInt" : "2" } } | { "_id" : { "$numberInt" : "2" }, "b" : { "$numberInt" : "56" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "1712253575000" } } } 20002 | { "" : { "$numberInt" : "3" } } | { "_id" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "4867927028000" } } } 20002 | { "" : { "$numberInt" : "4" } } | { "_id" : { "$numberInt" : "4" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : { "$date" : { "$numberLong" : "2657899731608" } } } 20002 | { "" : { "$numberInt" : "5" } } | { "_id" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : [ { "$date" : { "$numberLong" : "1697900030774" } } ] } 20002 | { "" : { "$numberInt" : "8" } } | { "_id" : { "$numberInt" : "8" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : true } 20002 | { "" : { "$numberInt" : "9" } } | { "_id" : { "$numberInt" : "9" }, "b" : { "$numberInt" : "55" }, "a" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "ttl" : "would not expire" } (7 rows) -- 19 Float TTL SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll1", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index5", "sparse" : true, "expireAfterSeconds" : {"$numberDouble":"12345.12345"}}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll1", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index6", "sparse" : false, "expireAfterSeconds" : {"$numberDouble":"12345.12345"}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll1" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew" : { "$numberInt" : "1" } }, "name" : "ttl_new_index5", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "12345" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlcoll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "ttlnew" : { "$numberInt" : "1" } }, "name" : "ttl_new_index6", "sparse" : false, "expireAfterSeconds" : { "$numberInt" : "12345" } } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) -- 20 Repeated TTL deletes -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 8, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'ttlRepeatedDeletes', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; count --------------------------------------------------------------------- 9991 (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'ttlRepeatedDeletes2', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; NOTICE: creating collection count --------------------------------------------------------------------- 9991 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlRepeatedDeletes", "indexes": [{"key": {"ttl": 1}, "name": "ttl_repeat_1", "sparse" : true, "expireAfterSeconds" : 5}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlRepeatedDeletes2", "indexes": [{"key": {"ttl": 1}, "name": "ttl_repeat_2", "sparse" : false, "expireAfterSeconds" : 5}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes'); count --------------------------------------------------------------------- 10001 (1 row) SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); count --------------------------------------------------------------------- 9991 (1 row) BEGIN; SET LOCAL documentdb.TTLTaskMaxRunTimeInMS to 3000; SET LOCAL documentdb.SingleTTLTaskTimeBudget to 2000; CALL documentdb_api_internal.delete_expired_rows(11); -- With repeat mode off (by default), we should delete exactly 11 documents per collections (currently has 10001 and 9991 documents) SELECT count(*) = 9990 from documentdb_api.collection('db', 'ttlRepeatedDeletes'); ?column? --------------------------------------------------------------------- t (1 row) SELECT count(*) = 9980 from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); ?column? --------------------------------------------------------------------- t (1 row) END; BEGIN; SET LOCAL documentdb.TTLTaskMaxRunTimeInMS to 3000; SET LOCAL documentdb.SingleTTLTaskTimeBudget to 2000; SET LOCAL documentdb.RepeatPurgeIndexesForTTLTask to true; SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes'); count --------------------------------------------------------------------- 9990 (1 row) SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); count --------------------------------------------------------------------- 9980 (1 row) -- With repeat mode on, we should delete more than 10 documents per collections (currently has 9990 and 9980 documents) CALL documentdb_api_internal.delete_expired_rows(10); -- 3000 ms does 70 iterations locally. So document count should be well below 9900. SELECT count(*) < 9900 from documentdb_api.collection('db', 'ttlRepeatedDeletes'); ?column? --------------------------------------------------------------------- t (1 row) SELECT count(*) < 9900 from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); ?column? --------------------------------------------------------------------- t (1 row) END; -- 21. TTL index with forced ordered scan via index hints set documentdb.enableExtendedExplainPlans to on; set documentdb_rum.preferOrderedIndexScan to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; set_config | extname --------------------------------------------------------------------- extended_rum | documentdb_extended_rum (1 row) -- Delete all other indexes from previous tests to reduce flakiness SELECT documentdb_api.drop_collection('db', 'ttlcoll'), documentdb_api.drop_collection('db', 'ttlcoll1'), documentdb_api.drop_collection('db', 'ttlcoll2'), documentdb_api.drop_collection('db', 'ttlcoll3'),documentdb_api.drop_collection('db', 'ttlRepeatedDeletes'),documentdb_api.drop_collection('db', 'ttlRepeatedDeletes2'); drop_collection | drop_collection | drop_collection | drop_collection | drop_collection | drop_collection --------------------------------------------------------------------- t | t | t | t | t | t (1 row) -- make sure jobs are scheduled and disable it to avoid flakiness on the test as it could run on its schedule and delete documents before we run our commands in the test select cron.unschedule(jobid) from cron.job where jobname like '%ttl_task%'; unschedule --------------------------------------------------------------------- (0 rows) -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 8, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT COUNT(documentdb_api.insert_one('db', 'ttlCompositeOrderedScan', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; count --------------------------------------------------------------------- 9991 (1 row) -- Create TTL Index -- SET documentdb.enableExtendedExplainPlans to on; SET documentdb.enableIndexOrderbyPushdown to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlCompositeOrderedScan", "indexes": [{"key": {"ttl": 1}, "enableCompositeTerm": true, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5, "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) select collection_id, (index_spec).index_key, (index_spec).index_name, (index_spec).index_expire_after_seconds as ttl_expiry, (index_spec).index_is_sparse as is_sparse, (index_spec).index_name as index_name from documentdb_api_catalog.collection_indexes where (index_spec).index_expire_after_seconds > 0; collection_id | index_key | index_name | ttl_expiry | is_sparse | index_name --------------------------------------------------------------------- 20006 | { "ttl" : { "$numberInt" : "1" } } | ttl_index | 5 | t | ttl_index (1 row) \d documentdb_data.documents_20006 Table "documentdb_data.documents_20006" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_20006" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_20023" documentdb_extended_rum (document documentdb_extended_rum_catalog.bson_extended_rum_composite_path_ops (pathspec='[ "ttl" ]', tl='2691')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '20006'::bigint) -- List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlCompositeOrderedScan" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlCompositeOrderedScan", "firstBatch" : { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "sparse" : true, "expireAfterSeconds" : { "$numberInt" : "5" }, "enableOrderedIndex" : { "$numberInt" : "1" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.ttlCompositeOrderedScan", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 10001 (1 row) -- Call ttl purge procedure with a batch size of 100 BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.logTTLProgressActivity to on; CALL documentdb_api_internal.delete_expired_rows(100); LOG: Number of rows deleted: 0, table = documents_20006_2000104, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000105, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000106, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000107, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000108, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000109, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000110, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000111, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=1 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms RESET client_min_messages; END; BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.useIndexHintsForTTLTask to off; SET LOCAL documentdb.logTTLProgressActivity to on; CALL documentdb_api_internal.delete_expired_rows(100); LOG: Number of rows deleted: 0, table = documents_20006_2000104, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000105, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000106, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000107, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000108, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000109, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000110, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 0, table = documents_20006_2000111, index_id=20023, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=0 LOG: TTL job elapsed time: limit: 20000ms RESET client_min_messages; END; -- Check what documents are left after purging SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 9801 (1 row) -- TTL indexes behaves like normal indexes that are used in queries (cx can provide .hint() to force) BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(costs off) SELECT object_id FROM documentdb_data.documents_20006 WHERE bson_dollar_eq(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) LIMIT 100; QUERY PLAN --------------------------------------------------------------------- Limit -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Limit -> Bitmap Heap Scan on documents_20006_2000104 documents_20006 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) -> Bitmap Index Scan on ttl_index Index Cond: (document OPERATOR(documentdb_api_catalog.@=) '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) (11 rows) END; -- Check the query to fetch the eligible TTL indexes uses IndexScan. BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(analyze on, verbose on, costs off, timing off, summary off) SELECT ctid FROM documentdb_data.documents_20006_2000105 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1754515365000" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=100 loops=1) Output: ctid -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) Output: ctid indexName: ttl_index isMultiKey: true indexBounds: ["ttl": [{ "$date" : { "$numberLong" : "-9223372036854775808" } }, { "$date" : "2025-08-06T21:22:45Z" })] innerScanLoops: 4 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 12242)] -> Index Scan using ttl_index on documentdb_data.documents_20006_2000105 (actual rows=100 loops=1) Output: ctid Index Cond: (documents_20006_2000105.document @< '{ "ttl" : { "$date" : { "$numberLong" : "1754515365000" } } }'::bson) (13 rows) END; -- Shard collection SELECT documentdb_api.shard_collection('db', 'ttlCompositeOrderedScan', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- Check TTL deletes work on sharded (should delete 800 docs, 100 for each shard) SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 9801 (1 row) CALL documentdb_api_internal.delete_expired_rows(100); SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 9001 (1 row) -- Check for Ordered Indes Scan on the ttl index BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(analyze on, verbose on, costs off, timing off, summary off) SELECT ctid FROM documentdb_data.documents_20006_2000124 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=100 loops=1) Output: ctid -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) Output: ctid indexName: ttl_index isMultiKey: false indexBounds: ["ttl": [{ "$date" : { "$numberLong" : "-9223372036854775808" } }, { "$date" : "2022-07-15T15:47:10.775Z" })] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1207)] -> Index Scan using ttl_index on documentdb_data.documents_20006_2000124 (actual rows=100 loops=1) Output: ctid Index Cond: (documents_20006_2000124.document @< '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::bson) (13 rows) END; BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; SET client_min_messages TO INFO; EXPLAIN(COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT ctid FROM documentdb_data.documents_20006_2000122 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=100 loops=1) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: ttl_index isMultiKey: false indexBounds: ["ttl": [{ "$date" : { "$numberLong" : "-9223372036854775808" } }, { "$date" : "2022-07-15T15:47:10.775Z" })] innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1216)] -> Index Scan using ttl_index on documents_20006_2000122 (actual rows=100 loops=1) Index Cond: (document @< '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::bson) (10 rows) END; SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 9001 (1 row) -- Test with descending TTL ordering BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.useIndexHintsForTTLTask to off; SET LOCAL documentdb.logTTLProgressActivity to on; SET LOCAL documentdb.enableTTLDescSort to on; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; CALL documentdb_api_internal.delete_expired_rows(100); LOG: Number of rows deleted: 100, table = documents_20006_2000120, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000121, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000122, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000123, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000124, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000125, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000126, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms LOG: Number of rows deleted: 100, table = documents_20006_2000127, index_id=20025, batch_size=100, expiry_cutoff= has_pfe=false, statement_timeout=60000, lock_timeout=10000 used_hints=0 disabled_seq_scan=0 index_is_ordered=1 use_desc_sort=1 LOG: TTL job elapsed time: limit: 20000ms RESET client_min_messages; END; SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; count --------------------------------------------------------------------- 8201 (1 row) BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; set local enable_seqscan to off; set LOCAL enable_bitmapscan to off; SET client_min_messages TO INFO; -- Check ORDER BY uses index EXPLAIN(COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT ctid FROM documentdb_data.documents_20006_2000122 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) AND documentdb_api_internal.bson_dollar_fullscan(document, '{ "ttl" : -1 }'::documentdb_core.bson) ORDER BY documentdb_api_catalog.bson_orderby(document, '{ "ttl" : -1}'::documentdb_core.bson) LIMIT 100; QUERY PLAN --------------------------------------------------------------------- Limit (actual rows=100 loops=1) -> Custom Scan (DocumentDBApiExplainQueryScan) (actual rows=100 loops=1) indexName: ttl_index isMultiKey: false indexBounds: ["ttl": [{ "$date" : { "$numberLong" : "-9223372036854775808" } }, { "$date" : "2022-07-15T15:47:10.775Z" })] isBackwardScan: true innerScanLoops: 1 loops scanType: ordered scanKeyDetails: key 1: [(isInequality: true, estimatedEntryCount: 1216)] -> Index Scan using ttl_index on documents_20006_2000122 (actual rows=100 loops=1) Index Cond: (document @< '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::bson) Order By: (document OPERATOR(documentdb_api_internal.<>-|) '{ "ttl" : { "$numberInt" : "-1" } }'::bson) (12 rows) END; commands_create_unique_index_stats.out000066400000000000000000000477221507310017400376570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 112000; SET documentdb.next_collection_id TO 11200; SET documentdb.next_collection_index_id TO 11200; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5", "partialFilterExpression": { "a": { "$exists": true }}}, {"key": {"x.y": 1}, "name": "valid_index_2", "unique": true } ] }', p_skip_check_collection_create=>true ); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('ind_db', 'collection_1') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11201 | 11201 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 11201 | 11202 | { "v" : { "$numberInt" : "2" }, "key" : { "x.y.z" : { "$numberInt" : "1" } }, "name" : "valid_index_1" } | t 11201 | 11203 | { "v" : { "$numberInt" : "2" }, "key" : { "c.d.e" : { "$numberInt" : "1" } }, "name" : "my_idx_5", "partialFilterExpression" : { "a" : { "$exists" : true } } } | t 11201 | 11204 | { "v" : { "$numberInt" : "2" }, "key" : { "x.y" : { "$numberInt" : "1" } }, "name" : "valid_index_2", "unique" : true } | t (4 rows) \d documentdb_data.documents_11201 Table "documentdb_data.documents_11201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11202" documentdb_rum (document bson_rum_single_path_ops (path='x.y.z', tl='2699')) "documents_rum_index_11203" documentdb_rum (document bson_rum_single_path_ops (path='c.d.e', tl='2699')) WHERE document #>= '{ "a" : { "$minKey" : 1 } }'::bsonquery "documents_rum_index_11204" EXCLUDE USING documentdb_rum (documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "x.y" : { "$numberInt" : "1" } }'::bson, false) documentdb_api_internal.bson_rum_unique_shard_path_ops WITH OPERATOR(documentdb_api_internal.=#=), document bson_rum_single_path_ops (path='x.y', tl='2691', generatenotfoundterm='true') WITH =?=) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11201'::bigint) \d+ documentdb_data.documents_rum_index_11202 Index "documentdb_data.documents_rum_index_11202" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201" \d+ documentdb_data.documents_rum_index_11203 Index "documentdb_data.documents_rum_index_11203" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201", predicate (document #>= '{ "a" : { "$minKey" : 1 } }'::bsonquery) -- stats target is 0 for the unique shard column \d+ documentdb_data.documents_rum_index_11204 Index "documentdb_data.documents_rum_index_11204" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- generate_unique_shard_document | uuid | yes | documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "x.y" : { "$numberInt" : "1" } }'::bson, false) | plain | 0 document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201" -- some tests disable background index job, let's enable it to test background index build codepath UPDATE cron.job SET active = true WHERE jobname LIKE 'documentdb_index_%'; -- now repeat with background indexes CALL documentdb_distributed_test_helpers.create_indexes_background( 'ind_db', '{ "createIndexes": "collection_1", "indexes": [ {"key": {"back.y.z": 1}, "name": "background_valid_index_1"}, {"key": {"back.d.e": 1}, "name": "back_my_idx_5", "partialFilterExpression": { "a": { "$exists": true }}}, {"key": {"back.y": 1}, "name": "back_valid_index_2", "unique": true } ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('ind_db', 'collection_1') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 11201 | 11201 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 11201 | 11202 | { "v" : { "$numberInt" : "2" }, "key" : { "x.y.z" : { "$numberInt" : "1" } }, "name" : "valid_index_1" } | t 11201 | 11203 | { "v" : { "$numberInt" : "2" }, "key" : { "c.d.e" : { "$numberInt" : "1" } }, "name" : "my_idx_5", "partialFilterExpression" : { "a" : { "$exists" : true } } } | t 11201 | 11204 | { "v" : { "$numberInt" : "2" }, "key" : { "x.y" : { "$numberInt" : "1" } }, "name" : "valid_index_2", "unique" : true } | t 11201 | 11205 | { "v" : { "$numberInt" : "2" }, "key" : { "back.y.z" : { "$numberInt" : "1" } }, "name" : "background_valid_index_1" } | t 11201 | 11206 | { "v" : { "$numberInt" : "2" }, "key" : { "back.d.e" : { "$numberInt" : "1" } }, "name" : "back_my_idx_5", "partialFilterExpression" : { "a" : { "$exists" : true } } } | t 11201 | 11207 | { "v" : { "$numberInt" : "2" }, "key" : { "back.y" : { "$numberInt" : "1" } }, "name" : "back_valid_index_2", "unique" : true } | t (7 rows) \d documentdb_data.documents_11201 Table "documentdb_data.documents_11201" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_11201" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_11202" documentdb_rum (document documentdb_api_catalog.bson_rum_single_path_ops (path='x.y.z', tl='2699')) "documents_rum_index_11203" documentdb_rum (document documentdb_api_catalog.bson_rum_single_path_ops (path='c.d.e', tl='2699')) WHERE document OPERATOR(documentdb_api_catalog.#>=) '{ "a" : { "$minKey" : 1 } }'::bsonquery "documents_rum_index_11204" EXCLUDE USING documentdb_rum (documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "x.y" : { "$numberInt" : "1" } }'::bson, false) documentdb_api_internal.bson_rum_unique_shard_path_ops WITH OPERATOR(documentdb_api_internal.=#=), document documentdb_api_catalog.bson_rum_single_path_ops (path='x.y', tl='2691', generatenotfoundterm='true') WITH OPERATOR(documentdb_api_catalog.=?=)) "documents_rum_index_11205" documentdb_rum (document documentdb_api_catalog.bson_rum_single_path_ops (path='back.y.z', tl='2699')) "documents_rum_index_11206" documentdb_rum (document documentdb_api_catalog.bson_rum_single_path_ops (path='back.d.e', tl='2699')) WHERE document OPERATOR(documentdb_api_catalog.#>=) '{ "a" : { "$minKey" : 1 } }'::bsonquery "documents_rum_index_11207" EXCLUDE USING documentdb_rum (documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "back.y" : { "$numberInt" : "1" } }'::bson, false) documentdb_api_internal.bson_rum_unique_shard_path_ops WITH OPERATOR(documentdb_api_internal.=#=), document documentdb_api_catalog.bson_rum_single_path_ops (path='back.y', tl='2691', generatenotfoundterm='true') WITH OPERATOR(documentdb_api_catalog.=?=)) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '11201'::bigint) \d+ documentdb_data.documents_rum_index_11205 Index "documentdb_data.documents_rum_index_11205" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201" \d+ documentdb_data.documents_rum_index_11206 Index "documentdb_data.documents_rum_index_11206" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201", predicate (document OPERATOR(documentdb_api_catalog.#>=) '{ "a" : { "$minKey" : 1 } }'::bsonquery) -- stats target is 0 for the unique shard column \d+ documentdb_data.documents_rum_index_11207 Index "documentdb_data.documents_rum_index_11207" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- generate_unique_shard_document | uuid | yes | documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "back.y" : { "$numberInt" : "1" } }'::bson, false) | plain | 0 document | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201" -- create a composite unique CALL documentdb_distributed_test_helpers.create_indexes_background( 'ind_db', '{ "createIndexes": "collection_1", "indexes": [ {"key": {"back.y": 1, "back.z": 1 }, "name": "back_valid_index_3", "unique": true } ] }' ); retval | ok --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t (1 row) \d+ documentdb_data.documents_rum_index_11208 Index "documentdb_data.documents_rum_index_11208" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- generate_unique_shard_document | uuid | yes | documentdb_api_internal.generate_unique_shard_document(document, shard_key_value, '{ "back.y" : { "$numberInt" : "1" }, "back.z" : { "$numberInt" : "1" } }'::bson, false) | plain | 0 document | bytea | yes | document | extended | document1 | bytea | yes | document | extended | documentdb_rum, for table "documentdb_data.documents_11201" -- disable background index job UPDATE cron.job SET active = false WHERE jobname LIKE 'documentdb_index_%'; -- create with the new operator class set documentdb.enable_large_unique_index_keys to off; set documentdb.forceIndexTermTruncation to on; SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.y": 1, "fore.z": 1 }, "name": "fore_valid_index_3", "unique": true } ] }', p_skip_check_collection_create=>true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "8" }, "numIndexesAfter" : { "$numberInt" : "9" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d+ documentdb_data.documents_rum_index_11209 Index "documentdb_data.documents_rum_index_11209" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | row | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 document1 | bytea | yes | document | extended | row1 | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 documentdb_rum, for table "documentdb_data.documents_11201" -- disable the flag - and stats shouldn't be set set documentdb.disable_statistics_for_unique_columns to off; ERROR: invalid configuration parameter name "documentdb.disable_statistics_for_unique_columns" DETAIL: "documentdb" is a reserved prefix. SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.yy": 1, "fore.zz": 1 }, "name": "fore_valid_index_4", "unique": true } ] }', p_skip_check_collection_create=>true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "9" }, "numIndexesAfter" : { "$numberInt" : "10" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d+ documentdb_data.documents_rum_index_11210 Index "documentdb_data.documents_rum_index_11210" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | row | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 document1 | bytea | yes | document | extended | row1 | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 documentdb_rum, for table "documentdb_data.documents_11201" set documentdb.enable_large_unique_index_keys to off; set documentdb.forceIndexTermTruncation to off; SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.abc": 1, "fore.def": 1 }, "name": "fore_valid_index_no_trunc", "unique": true } ] }', p_skip_check_collection_create=>true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "10" }, "numIndexesAfter" : { "$numberInt" : "11" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) \d+ documentdb_data.documents_rum_index_11211 Index "documentdb_data.documents_rum_index_11211" Column | Type | Key? | Definition | Storage | Stats target --------------------------------------------------------------------- document | bytea | yes | document | extended | row | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 document1 | bytea | yes | document | extended | row1 | uuid | yes | (ROW(shard_key_value, document)::documentdb_api_catalog.shard_key_and_document) | plain | 0 documentdb_rum, for table "documentdb_data.documents_11201" commands_create_view_tests.out000066400000000000000000000416451507310017400361360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 111000; SET documentdb.next_collection_id TO 11100; SET documentdb.next_collection_index_id TO 11100; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- first create a collection (invalid) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": true }'); ERROR: Capped collections not supported yet SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": 1}'); ERROR: Capped collections not supported yet SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": 2.3}'); ERROR: Capped collections not supported yet SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": "true"}'); ERROR: The BSON field 'create.capped' has an incorrect type 'string'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": "false"}'); ERROR: The BSON field 'create.capped' has an incorrect type 'string'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "timeseries": { "timeField": "a" } }'); ERROR: Time series data collections are currently not supported SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "clusteredIndex": { } }'); ERROR: clusteredIndex not supported yet SELECT documentdb_api.create_collection_view('db', '{ "create": 2 }'); ERROR: The BSON field 'create.create' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": false }'); ERROR: The BSON field 'create.create' has an incorrect type 'bool'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": null }'); ERROR: The BSON field 'create.create' has an incorrect type 'null'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": {"$undefined": true} }'); ERROR: The BSON field 'create.create' has an incorrect type 'undefined'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": "" }'); -- empty string not allowed ERROR: The specified namespace is invalid: 'db'. -- create valid collections SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_not_capped1", "capped": false}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_not_capped2", "capped": 0}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_emoji_👽" }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests" }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- noops SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Views error out if the viewOn is not a string, or empty string SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": 2 }'); ERROR: The BSON field 'create.viewOn' has an incorrect type 'int'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": false }'); ERROR: The BSON field 'create.viewOn' has an incorrect type 'bool'; it should be of type 'string'. SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": "" }'); -- empty string not allowed ERROR: The 'viewOn' field must not be empty -- viewOn can be null or undefined. It is treated as if it was not specified SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_n", "viewOn": null }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_np", "viewOn": null, "pipeline": [] }'); ERROR: 'viewOn' needs to be specified. SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_u", "viewOn": {"$undefined": true} }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_up", "viewOn": {"$undefined": true}, "pipeline": [] }'); ERROR: 'viewOn' needs to be specified. -- create a view against it (no pipeline): succeeds SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_1", "viewOn": "create_view_tests" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_emoji_👺", "viewOn": "create_view_tests_emoji_👽" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- chain the view SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_2", "viewOn": "create_view_tests_view_1", "pipeline": [ { "$match": { "a": { "$gt": 5 } } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- chain one more view SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_3", "viewOn": "create_view_tests_view_2", "pipeline": [ { "$sort": { "a": 1 } } ] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- query all 4 SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_3" }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_2" }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests" }'); document --------------------------------------------------------------------- (0 rows) -- now insert 3 docs in the table SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 1, "a": 4 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 2, "a": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 3, "a": 140 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 4, "a": 40 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_3" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_2" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } (2 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } (4 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } (4 rows) -- create views with different options SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "viewOn": "create_view_tests_view_5", "pipeline": [ { "$sort": { "a": 1 } } ] }'); ERROR: Namespace db.create_view_tests already exists but with different configuration options: {} -- Can't write to views SELECT documentdb_api.insert_one('db', 'create_view_tests_view_1', '{ "_id": 5, "a": 60 }'); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection CONTEXT: SQL statement "SELECT p_result FROM documentdb_api.insert( p_database_name, v_insert, p_document::bsonsequence, p_transaction_id)" PL/pgSQL function documentdb_api.insert_one(text,text,bson,text) line 7 at SQL statement SELECT documentdb_api.update('db', '{ "update": "create_view_tests_view_1", "updates": [ { "q": {}, "u": {} } ] }'); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection SELECT documentdb_api.delete('db', '{ "delete": "create_view_tests_view_1", "deletes": [ { "q": {}, "limit": 1 } ] }'); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection SELECT documentdb_api.shard_collection('db', 'create_view_tests_view_1', '{ "_id": "hashed" }', false); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection SELECT documentdb_api.shard_collection('db', 'create_view_tests_view_1', '{ "_id": "hashed" }', true); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection -- can drop/rename a view SELECT documentdb_api.rename_collection('db', 'create_view_tests_view_1', 'create_view_tests_view_4'); ERROR: The namespace db.create_view_tests_view_1 refers to a view object rather than a collection SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } { "_id" : { "$numberInt" : "4" }, "a" : { "$numberInt" : "40" } } (4 rows) SELECT documentdb_api.drop_collection('db', 'create_view_tests_view_3'); NOTICE: table "documents_11109" does not exist, skipping NOTICE: table "retry_11109" does not exist, skipping drop_collection --------------------------------------------------------------------- t (1 row) -- drop the collection (view still works) SELECT documentdb_api.drop_collection('db', 'create_view_tests'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); document --------------------------------------------------------------------- (0 rows) -- create a view cycle (fails) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "viewOn": "create_view_tests_view_1" }'); ERROR: Cycle detected in view: db.create_view_tests -> db.create_view_tests_view_1 -> db.create_view_tests -- recreate a collection SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 3, "a": 140 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- view works again SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "140" } } (1 row) -- do a coll_mod SELECT database_name, collection_name, view_definition FROM documentdb_api_catalog.collections WHERE collection_name = 'create_view_tests_view_1'; database_name | collection_name | view_definition --------------------------------------------------------------------- db | create_view_tests_view_1 | { "viewOn" : "create_view_tests" } (1 row) SELECT documentdb_api.coll_mod('db', 'create_view_tests_view_1', '{ "collMod": "create_view_tests_view_1", "viewOn": "create_view_tests_view_4", "pipeline": [] }'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) SELECT database_name, collection_name, view_definition FROM documentdb_api_catalog.collections WHERE collection_name = 'create_view_tests_view_1'; database_name | collection_name | view_definition --------------------------------------------------------------------- db | create_view_tests_view_1 | { "viewOn" : "create_view_tests_view_4", "pipeline" : [ ] } (1 row) -- create a much longer cycle SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_1", "viewOn": "create_view_cycle_2" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_2", "viewOn": "create_view_cycle_3" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_3", "viewOn": "create_view_cycle_4" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_4", "viewOn": "create_view_cycle_1" }'); ERROR: Cycle detected in view: db.create_view_cycle_4 -> db.create_view_cycle_1 -> db.create_view_cycle_2 -> db.create_view_cycle_3 -> db.create_view_cycle_4 -- create with long name SELECT documentdb_api.create_collection_view('db', FORMAT('{ "create": "create_view_cycle_4_%s", "viewOn": "create_view_cycle_1" }', repeat('1bc', 80))::documentdb_core.bson); ERROR: Full namespace must not exceed 235 bytes. commands_crud_ignore_common_spec_fields.out000066400000000000000000000107571507310017400406270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- These tests make sure that we ignore the common spec fields/actions that are not implemented for various commands SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 160000; SET documentdb.next_collection_id TO 1600; SET documentdb.next_collection_index_id TO 1600; -- insert tests select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":99,"a":99}], "ordered": false, "writeConcern": { "w": "majority", "wtimeout": 5000 }, "bypassDocumentValidation": true, "comment": "NoOp" }'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":21,"a":99}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp2", "apiVersion": 1 }'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- insert again select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":1,"a":"id1"}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp1", "apiVersion": 1 }'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":2,"a":"id2"}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp2"}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- create index tests SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "ignoreCommonSpec", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_ignore"}], "commitQuorum" : 100, "writeConcern": { "w": "majority", "wtimeout": 5000 }, "apiVersion": 1, "$db" : "tetsts", "db": "test2" }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- quey SELECT bson_dollar_project(document, '{ "a" : 1 }') FROM documentdb_api.collection('db', 'ignoreCommonSpec') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "id1" } { "_id" : { "$numberInt" : "2" }, "a" : "id2" } { "_id" : { "$numberInt" : "21" }, "a" : { "$numberInt" : "99" } } { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } (4 rows) -- drop index tests CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "ignoreCommonSpec", "index":[], "writeConcern": { "w": "majority", "wtimeout": 5000 }, "comment": "NoOp1", "apiVersion": 1 }'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- query SELECT bson_dollar_project(document, '{ "a" : 1 }') FROM documentdb_api.collection('db', 'ignoreCommonSpec') ORDER BY object_id; bson_dollar_project --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "id1" } { "_id" : { "$numberInt" : "2" }, "a" : "id2" } { "_id" : { "$numberInt" : "21" }, "a" : { "$numberInt" : "99" } } { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } (4 rows) commands_db_stats.out000066400000000000000000001537071507310017400342250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 630000; SET documentdb.next_collection_id TO 6300; SET documentdb.next_collection_index_id TO 6300; -- Utility function to add multiple documents to a collection. CREATE OR REPLACE FUNCTION insert_docs(p_db TEXT, p_coll TEXT, p_num INT, p_start INT default 0) RETURNS void AS $$ DECLARE num INTEGER := p_start; docText bson; BEGIN WHILE num < p_num + p_start LOOP docText := CONCAT('{ "a" : ', num, '}'); PERFORM documentdb_api.insert_one(p_db, p_coll, docText::documentdb_core.bson, NULL); num := num + 1; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.drop_database('db1'); drop_database --------------------------------------------------------------------- (1 row) -- Non existing database should return zero values SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db1', 1); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db1', 1024); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1024" }, "ok" : { "$numberInt" : "1" } } (1 row) --=============== Tests for "collections" & "objects" count ===============+=-- -- Create a Collection SELECT documentdb_api.create_collection('db1', 'col1'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- db_stats with one empty collection SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "8192.0" }, "storageSize" : { "$numberDouble" : "8192.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8192.0" }, "totalSize" : { "$numberDouble" : "16384.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db1', 1); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "8192.0" }, "storageSize" : { "$numberDouble" : "8192.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8192.0" }, "totalSize" : { "$numberDouble" : "16384.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db1', 1024); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "8.0" }, "storageSize" : { "$numberDouble" : "8.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8.0" }, "totalSize" : { "$numberDouble" : "16.0" }, "scaleFactor" : { "$numberInt" : "1024" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Add one doc SELECT documentdb_api.insert_one('db1','col1',' { "a" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- The AutoVacuum might still be napping so count in stats might still be 0, -- In this test we cannot wait till nap time is over, so we manually trigger the ANALYZE ANALYZE; -- db_stats with single collection and single document SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "30.0" }, "storageSize" : { "$numberDouble" : "16384.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "16384.0" }, "totalSize" : { "$numberDouble" : "32768.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Insert few docs in the collection SELECT insert_docs('db1', 'col1', 20, 1); insert_docs --------------------------------------------------------------------- (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" should be 21, "collections" should be 1, and fsStorageSize > fsUsedSize SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "21" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "630.0" }, "storageSize" : { "$numberDouble" : "16384.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "16384.0" }, "totalSize" : { "$numberDouble" : "32768.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Create 4 more Collections SELECT documentdb_api.create_collection('db1', 'col2'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db1', 'col3'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db1', 'col4'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('db1', 'col5'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- "collections" and "indexes" count should increase to 5 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "21" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "630.0" }, "storageSize" : { "$numberDouble" : "49152.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "49152.0" }, "totalSize" : { "$numberDouble" : "98304.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Add one doc to each new collection SELECT documentdb_api.insert_one('db1','col2',' { "a" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db1','col3',' { "a" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db1','col4',' { "a" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db1','col5',' { "a" : 100 }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should increase to 25 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "25" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "750.0" }, "storageSize" : { "$numberDouble" : "81920.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "81920.0" }, "totalSize" : { "$numberDouble" : "163840.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Insert 20 more docs in each new collection SELECT insert_docs('db1', 'col2', 20, 1); insert_docs --------------------------------------------------------------------- (1 row) SELECT insert_docs('db1', 'col3', 20, 1); insert_docs --------------------------------------------------------------------- (1 row) SELECT insert_docs('db1', 'col4', 20, 1); insert_docs --------------------------------------------------------------------- (1 row) SELECT insert_docs('db1', 'col5', 20, 1); insert_docs --------------------------------------------------------------------- (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should increase to 105 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "105" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "3150.0" }, "storageSize" : { "$numberDouble" : "81920.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "81920.0" }, "totalSize" : { "$numberDouble" : "163840.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Delete 1 document SELECT documentdb_api.delete('db1', '{"delete":"col1", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should reduce to 104 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "104" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "3120.0" }, "storageSize" : { "$numberDouble" : "81920.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "81920.0" }, "totalSize" : { "$numberDouble" : "163840.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Delete 1 document from each remaining collections SELECT documentdb_api.delete('db1', '{"delete":"col2", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db1', '{"delete":"col3", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db1', '{"delete":"col4", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db1', '{"delete":"col5", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should reduce to 100 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "3000.0" }, "storageSize" : { "$numberDouble" : "81920.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "81920.0" }, "totalSize" : { "$numberDouble" : "163840.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Now shard all collections SELECT documentdb_api.shard_collection('db1','col1', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db1','col2', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db1','col3', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db1','col4', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db1','col5', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- "objects" count should remain 100 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "1269760.0" }, "totalSize" : { "$numberDouble" : "1884160.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) --===================== Test for "indexes", "indexSize" =====================-- -- Create one more index SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col1', 'index_a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- "indexes" count should increase to 6, "indexSize" should increase SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "6" }, "indexSize" : { "$numberDouble" : "1400832.0" }, "totalSize" : { "$numberDouble" : "2015232.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Create one more index in each remaining collections SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col2', 'index_a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col3', 'index_a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col4', 'index_a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col5', 'index_a_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- "indexes" count should increase to 10, "indexSize" should increase SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "10" }, "indexSize" : { "$numberDouble" : "1925120.0" }, "totalSize" : { "$numberDouble" : "2539520.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Drop one index CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col1", "index": "index_a_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- "indexes" count should reduce to 9 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "9" }, "indexSize" : { "$numberDouble" : "1794048.0" }, "totalSize" : { "$numberDouble" : "2408448.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Drop one index from each remaining collections CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col2", "index": "index_a_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col3", "index": "index_a_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col4", "index": "index_a_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col5", "index": "index_a_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) -- "indexes" count should be back to 5 (one default _id index in each collection), "indexSize" should decrease SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "1269760.0" }, "totalSize" : { "$numberDouble" : "1884160.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) --===================== Test with Views =====================================-- -- create a view on a collection SELECT documentdb_api.create_collection_view('db1', '{ "create": "col1_view1", "viewOn": "col1" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- "views" should be 1 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "1" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "1269760.0" }, "totalSize" : { "$numberDouble" : "1884160.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- create one view on each remaining collection SELECT documentdb_api.create_collection_view('db1', '{ "create": "col2_view1", "viewOn": "col2" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db1', '{ "create": "col3_view1", "viewOn": "col3" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db1', '{ "create": "col4_view1", "viewOn": "col4" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('db1', '{ "create": "col5_view1", "viewOn": "col5" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- "views" should be 5 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "5" }, "views" : { "$numberLong" : "5" }, "objects" : { "$numberLong" : "100" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "614400.0" }, "storageSize" : { "$numberDouble" : "614400.0" }, "indexes" : { "$numberLong" : "5" }, "indexSize" : { "$numberDouble" : "1269760.0" }, "totalSize" : { "$numberDouble" : "1884160.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Drop one collection (despite a view on it) SELECT documentdb_api.drop_collection('db1', 'col5'); drop_collection --------------------------------------------------------------------- t (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "collections" should be 4, and "objects" will reduce SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "4" }, "views" : { "$numberLong" : "5" }, "objects" : { "$numberLong" : "80" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "2400.0" }, "storageSize" : { "$numberDouble" : "491520.0" }, "indexes" : { "$numberLong" : "4" }, "indexSize" : { "$numberDouble" : "1015808.0" }, "totalSize" : { "$numberDouble" : "1507328.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Drop one view SELECT documentdb_api.drop_collection('db1', 'col5_view1'); NOTICE: table "documents_6310" does not exist, skipping NOTICE: table "retry_6310" does not exist, skipping drop_collection --------------------------------------------------------------------- t (1 row) -- "views" should be 4 SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "4" }, "views" : { "$numberLong" : "4" }, "objects" : { "$numberLong" : "80" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "2400.0" }, "storageSize" : { "$numberDouble" : "491520.0" }, "indexes" : { "$numberLong" : "4" }, "indexSize" : { "$numberDouble" : "1015808.0" }, "totalSize" : { "$numberDouble" : "1507328.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Drop all remaining collections SELECT documentdb_api.drop_collection('db1', 'col1'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db1', 'col2'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db1', 'col3'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.drop_collection('db1', 'col4'); drop_collection --------------------------------------------------------------------- t (1 row) -- Only "views" and fs stats should be available, rest all should be zero values. SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "4" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) --===================== Test with another database =============================-- -- Make sure this new database does not exist SELECT documentdb_api.drop_database('db2'); drop_database --------------------------------------------------------------------- (1 row) -- Add one document SELECT documentdb_api.insert_one('db2','col1',' { "a" : 100 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- various stats should be available SELECT documentdb_api.db_stats('db2'); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "30.0" }, "storageSize" : { "$numberDouble" : "16384.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "16384.0" }, "totalSize" : { "$numberDouble" : "32768.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) --===================== Test for "scale" Values =============================-- SELECT documentdb_api.db_stats('db2', 1); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "30.0" }, "storageSize" : { "$numberDouble" : "16384.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "16384.0" }, "totalSize" : { "$numberDouble" : "32768.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 2); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "15.0" }, "storageSize" : { "$numberDouble" : "8192.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8192.0" }, "totalSize" : { "$numberDouble" : "16384.0" }, "scaleFactor" : { "$numberInt" : "2" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 2.5); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "15.0" }, "storageSize" : { "$numberDouble" : "8192.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8192.0" }, "totalSize" : { "$numberDouble" : "16384.0" }, "scaleFactor" : { "$numberInt" : "2" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 2.99); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "15.0" }, "storageSize" : { "$numberDouble" : "8192.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "8192.0" }, "totalSize" : { "$numberDouble" : "16384.0" }, "scaleFactor" : { "$numberInt" : "2" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 100); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "0.2999999999999999889" }, "storageSize" : { "$numberDouble" : "163.84000000000000341" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "163.84000000000000341" }, "totalSize" : { "$numberDouble" : "327.68000000000000682" }, "scaleFactor" : { "$numberInt" : "100" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 1024.99); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "0.029296875" }, "storageSize" : { "$numberDouble" : "16.0" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "16.0" }, "totalSize" : { "$numberDouble" : "32.0" }, "scaleFactor" : { "$numberInt" : "1024" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 2147483647); -- INT_MAX db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "1.3969838625737390769e-08" }, "storageSize" : { "$numberDouble" : "7.6293945348027136788e-06" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "7.6293945348027136788e-06" }, "totalSize" : { "$numberDouble" : "1.5258789069605427358e-05" }, "scaleFactor" : { "$numberInt" : "2147483647" }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.db_stats('db2', 2147483647000); -- More than INT_MAX db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "1" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "1" }, "avgObjSize" : { "$numberDouble" : "30.0" }, "dataSize" : { "$numberDouble" : "1.3969838625737390769e-08" }, "storageSize" : { "$numberDouble" : "7.6293945348027136788e-06" }, "indexes" : { "$numberLong" : "1" }, "indexSize" : { "$numberDouble" : "7.6293945348027136788e-06" }, "totalSize" : { "$numberDouble" : "1.5258789069605427358e-05" }, "scaleFactor" : { "$numberInt" : "2147483647" }, "ok" : { "$numberInt" : "1" } } (1 row) --===================== ERROR Cases =============================-- SELECT documentdb_api.db_stats('db2', 0); ERROR: scale has to be > 0 SELECT documentdb_api.db_stats('db2', 0.99); ERROR: scale has to be > 0 SELECT documentdb_api.db_stats('db2', -0.2); ERROR: scale has to be > 0 SELECT documentdb_api.db_stats('db2', -2); ERROR: scale has to be > 0 SELECT documentdb_api.db_stats('db2', -2147483648); -- INT_MIN ERROR: scale has to be > 0 SELECT documentdb_api.db_stats('db2', -2147483647000); -- Less than INT_MIN ERROR: scale has to be > 0 --======================== Clean Up =============================-- SET client_min_messages TO WARNING; -- Clean up SELECT documentdb_api.drop_database('db1'); drop_database --------------------------------------------------------------------- (1 row) -- Should return Zero values for non-existing collection (except of fs stats) SELECT documentdb_api.db_stats('db1'); db_stats --------------------------------------------------------------------- { "db" : "db1", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) -- Clean up SELECT documentdb_api.drop_database('db2'); drop_database --------------------------------------------------------------------- (1 row) -- Should return Zero values for non-existing collection (except of fs stats) SELECT documentdb_api.db_stats('db2'); db_stats --------------------------------------------------------------------- { "db" : "db2", "collections" : { "$numberLong" : "0" }, "views" : { "$numberLong" : "0" }, "objects" : { "$numberLong" : "0" }, "avgObjSize" : { "$numberDouble" : "0.0" }, "dataSize" : { "$numberDouble" : "0.0" }, "storageSize" : { "$numberDouble" : "0.0" }, "indexes" : { "$numberLong" : "0" }, "indexSize" : { "$numberDouble" : "0.0" }, "totalSize" : { "$numberDouble" : "0.0" }, "scaleFactor" : { "$numberInt" : "1" }, "ok" : { "$numberInt" : "1" } } (1 row) SET client_min_messages TO DEFAULT; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/commands_delete.out000066400000000000000000002065131507310017400337350ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 639000; SET documentdb.next_collection_id TO 6390; SET documentdb.next_collection_index_id TO 6390; SET documentdb.EnableVariablesSupportForWriteCommands TO on; -- Call delete for a non existent collection. -- Note that this should not report any logs related to collection catalog lookup. SET citus.log_remote_commands TO ON; SELECT documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) RESET citus.log_remote_commands; select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":1,"_id":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":2,"_id":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":3,"_id":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":4,"_id":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":5,"_id":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":6,"_id":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":7,"_id":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":8,"_id":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":9,"_id":9}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":10,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- exercise invalid delete syntax errors select documentdb_api.delete('db', NULL); ERROR: delete document cannot be NULL select documentdb_api.delete(NULL, '{"delete":"removeme", "deletes":[{"q":{},"limit":0}]}'); ERROR: Database name must not be NULL value select documentdb_api.delete('db', '{"deletes":[{"q":{},"limit":0}]}'); ERROR: The required BSON field 'delete.delete' is not present in the data. select documentdb_api.delete('db', '{"delete":"removeme"}'); ERROR: The required BSON field 'delete.deletes' is not present in the data. select documentdb_api.delete('db', '{"delete":["removeme"], "deletes":[{"q":{},"limit":0}]}'); ERROR: Collection name contains an invalid data type array select documentdb_api.delete('db', '{"delete":"removeme", "deletes":{"q":{},"limit":0}}'); ERROR: The BSON field 'delete.deletes' has an incorrect type 'object'; it should be of type 'array'. select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}], "extra":1}'); ERROR: The BSON field 'delete.extra' is not recognized as a valid field name. select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{}}]}'); ERROR: The BSON field 'delete.deletes.limit' is not present, but it is required CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6390 WHERE shard_key_value = 6390" select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"limit":0}]}'); ERROR: The BSON field 'delete.deletes.q' is not present, but it is required CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6390 WHERE shard_key_value = 6390" select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":[],"limit":0}]}'); ERROR: The BSON field 'delete.deletes.q' has an incorrect type 'array'; it should be of type 'object'. CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6390 WHERE shard_key_value = 6390" select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"extra":1}]}'); ERROR: The BSON field 'delete.deletes.extra' is not recognized as a valid field. CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6390 WHERE shard_key_value = 6390" select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}],"ordered":1}'); ERROR: The BSON field 'delete.ordered' has an incorrect type 'int'; it should be of type 'bool'. select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":5}]}'); ERROR: The limit field in delete objects must be 0 or 1. Got 5 CONTEXT: SQL statement "SELECT documentdb_api_internal.delete_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6390 WHERE shard_key_value = 6390" -- Disallow writes to system.views select documentdb_api.delete('db', '{"delete":"system.views", "deletes":[{"q":{},"limit":0}]}'); ERROR: Unable to write data to specified location db.system.views -- delete all begin; SET LOCAL search_path TO ''; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 0 (1 row) rollback; -- delete some begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 7 (1 row) rollback; -- arbitrary limit type works in Mongo begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":{"hello":"world"}}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 7 (1 row) rollback; -- delete all from non-existent collection select documentdb_api.delete('db', '{"delete":"notexists", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- query syntax errors are added the response select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$ltr":5}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""Unrecognized operator specified: $ltr"" } ] }",f) (1 row) -- when ordered, expect only first delete to be executed begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}],"ordered":true}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- when not ordered, expect first and last delete to be executed begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}],"ordered":false}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 8 (1 row) rollback; -- delete 1 without filters is supported for unsharded collections begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}', NULL, 'xact-1'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}', NULL, 'xact-1'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 is supported in the _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":6},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; count --------------------------------------------------------------------- 0 (1 row) rollback; -- delete 1 is supported in the multiple identical _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":6}]},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; count --------------------------------------------------------------------- 0 (1 row) rollback; -- delete 1 is supported in the multiple distinct _id case (but a noop) begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- validate _id extraction begin; set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":6},"limit":1}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_6390_639005 documents_6390 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6390) NOTICE: executing the command locally: WITH s AS MATERIALIZED (SELECT documents_6390.ctid FROM documentdb_data.documents_6390_639005 documents_6390 WHERE ((documents_6390.shard_key_value OPERATOR(pg_catalog.=) $1) AND ((documents_6390.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "6" } }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_true_match($2::documentdb_core.bson)) AND (documents_6390.object_id OPERATOR(documentdb_core.=) ($3)::documentdb_core.bson)) LIMIT 1 FOR UPDATE OF documents_6390) DELETE FROM documentdb_data.documents_6390_639005 d USING s WHERE ((d.ctid OPERATOR(pg_catalog.=) s.ctid) AND (d.shard_key_value OPERATOR(pg_catalog.=) $1)) RETURNING d.object_id delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_6390_639005 documents_6390 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6390) NOTICE: executing the command locally: WITH s AS MATERIALIZED (SELECT documents_6390.ctid FROM documentdb_data.documents_6390_639005 documents_6390 WHERE ((documents_6390.shard_key_value OPERATOR(pg_catalog.=) $1) AND ((documents_6390.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "6" } }'::documentdb_core.bsonquery) AND (documents_6390.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery))) LIMIT 1 FOR UPDATE OF documents_6390) DELETE FROM documentdb_data.documents_6390_639005 d USING s WHERE ((d.ctid OPERATOR(pg_catalog.=) s.ctid) AND (d.shard_key_value OPERATOR(pg_catalog.=) $1)) RETURNING d.object_id delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) reset citus.log_remote_commands; rollback; -- shard the collection select documentdb_api.shard_collection('db', 'removeme', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- make sure we get the expected results after sharding a collection begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":1}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":10}'; count --------------------------------------------------------------------- 1 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 7 (1 row) rollback; -- delete with oject_id and no shard_key works BEGIN; select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":{"$eq":5}},"limit":0}], "ordered": false }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- test pruning logic in delete begin; select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":0}]}'); NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_6390_639022 documents_6390 WHERE ((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '1786987034919379147'::bigint)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; begin; select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"limit":0}]}'); NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_6390_639022 documents_6390 WHERE (((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '1786987034919379147'::bigint)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 without filters is unsupported for sharded collections select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""delete query with limit 1 must include either _id or shard key filter"" } ] }",f) (1 row) -- delete 1 with shard key filters is supported for sharded collections begin; select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.delete_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS delete_worker FROM documentdb_data.documents_6390_639022 documents_6390 WHERE (shard_key_value OPERATOR(pg_catalog.=) '1786987034919379147'::bigint) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 with shard key filters is retryable begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}', NULL, 'xact-2'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}', NULL, 'xact-2'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 that does not match any rows is still retryable begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":15}},"limit":1}]}', NULL, 'xact-3'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":15,"_id":15}'); ?column? --------------------------------------------------------------------- 1 (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":15}},"limit":1}]}', NULL, 'xact-3'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) rollback; -- delete 1 is supported in the _id case even on sharded collections begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- delete first row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; count --------------------------------------------------------------------- 1 (1 row) -- delete second row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; count --------------------------------------------------------------------- 0 (1 row) -- no more row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- delete 1 with with _id filter on a sharded collection is retryable begin; -- add an additional _id 10 (total to 11 rows) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- delete first row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}', NULL, 'xact-4'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- second time is a noop select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}', NULL, 'xact-4'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) rollback; -- delete 1 is supported in the multiple identical _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":6}]},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; count --------------------------------------------------------------------- 0 (1 row) rollback; -- delete 1 is unsupported in the multiple distinct _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""delete query with limit 1 must include either _id or shard key filter"" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- validate _id extraction begin; set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a": 11, "_id":6},"limit":0}]}'); NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_6390_639022 documents_6390 WHERE (((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "11" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "6" } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '838241346061304183'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : { "$numberInt" : "6" } }'::documentdb_core.bson)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a": 11},{"_id":6},{"_id":5}]},"limit":0}]}'); NOTICE: executing the command locally: DELETE FROM documentdb_data.documents_6390_639022 documents_6390 WHERE (((document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "11" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "6" } }'::documentdb_core.bsonquery) AND (document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery)) AND (shard_key_value OPERATOR(pg_catalog.=) '838241346061304183'::bigint)) delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) reset citus.log_remote_commands; rollback; -- delete with spec in special section begin; select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 10 (1 row) select documentdb_api.delete('db', '{"delete":"removeme"}', '{ "":[{"q":{"a":{"$eq":5}},"limit":1}] }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'removeme'); count --------------------------------------------------------------------- 9 (1 row) rollback; -- deletes with both specs specified begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes": [{"q":{"a":{"$eq":5}},"limit":1}] }', '{ "":[{"q":{"a":{"$eq":5}},"limit":1}] }'); ERROR: Unexpected extra delete operations rollback; -- delete with index hint specified by name and by key object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "removeme", "indexes": [ { "key" : { "a": 1 }, "name": "validIndex"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"hint": "validIndex"}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""10"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"hint": { "a": 1 }}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) rollback; select documentdb_api.drop_collection('db','removeme'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 1,"a":3,"b":7}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 2,"a":2,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 3,"a":1,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- sort in ascending order and project & return deleted document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "b": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : true, "objectId" : { "" : { "$numberInt" : "2" } } } (1 row) -- sort by multiple fields (i) and return deleted document BEGIN; SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "b": -1, "a" : 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : true, "objectId" : { "" : { "$numberInt" : "1" } } } (1 row) ROLLBACK; -- sort by multiple fields (ii) and return deleted document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "a": 1, "b" : -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); delete_worker --------------------------------------------------------------------- { "isRowDeleted" : true, "objectId" : { "" : { "$numberInt" : "3" } } } (1 row) SELECT document FROM documentdb_api.collection('delete', 'test_sort_returning') ORDER BY 1; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "7" } } (1 row) -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.delete( 'delete', '{ "delete": "dne", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": true }' ); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.delete( 'delete', '{ "delete": "dne", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": false }' ); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) SELECT documentdb_api.create_collection('delete', 'no_match'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- show that we validate "query" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.delete( 'delete', '{ "delete": "no_match", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": true }' ); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.delete( 'delete', '{ "delete": "no_match", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": false }' ); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- _id test using $in opearator with explain plan select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":1,"_id":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":2,"_id":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":3,"_id":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":4,"_id":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":5,"_id":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":6,"_id":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":7,"_id":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":8,"_id":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":9,"_id":9}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":10,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "explainTest", "deletes" : [ { "q" : { "_id" : { "$in" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "6" }, { "$numberInt" : "8" }, { "$numberInt" : "10" } ] } }, "limit" : { "$numberInt" : "0" } } ], "ordered" : true }'::bson, NULL::bsonsequence, NULL::text) (2 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "explainTest", "deletes" : [ { "q" : { "_id" : { "$in" : [ { "$numberInt" : "2" }, { "$numberInt" : "4" }, { "$numberInt" : "6" }, { "$numberInt" : "8" }, { "$numberInt" : "10" } ] } }, "limit" : { "$numberInt" : "0" } } ], "ordered" : true }'::bson, NULL::bsonsequence, NULL::text) (2 rows) SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""5"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db', 'explainTest') order by 1; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" } } { "_id" : { "$numberInt" : "7" }, "a" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "9" }, "a" : { "$numberInt" : "9" } } (5 rows) -- let support SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 1, "a":"dog"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 2, "a":"cat"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 3, "a":"$$varRef"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- enableVariablesSupportForWriteCommands GUC off: ignore variableSpec SET documentdb.enableVariablesSupportForWriteCommands TO off; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "cat"} }'); ERROR: 'delete.let' is not yet supported -- enableVariablesSupportForWriteCommands GUC on: user variableSpec SET documentdb.enableVariablesSupportForWriteCommands TO on; -- variables accessed outside $expr will not evaluate to let variable value SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "$$varRef" }, "limit": 0}], "let": {"varRef": 2}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "$$varRef" }, "limit": 1}], "let": {"varRef": 2}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "$expr" : { "$eq" : [ "$_id", "$$varRef" ] } }, "limit" : { "$numberInt" : "1" } } ], "let" : { "varRef" : { "$numberInt" : "2" } } }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; --- deleteOne (1) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "$expr" : { "$eq" : [ "$_id", "$$varRef" ] } }, "limit" : { "$numberInt" : "1" } } ], "let" : { "varRef" : { "$numberInt" : "2" } } }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; --- deleteMany (2) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lte": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "zebra"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; -- deleteMany: when ordered, expect only first delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; -- deleteOne: when ordered, expect only first delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$_id", "$$varRef1"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef2"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 1}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (1 row) ROLLBACK; BEGIN; -- deleteMany: when not ordered, expect first and last delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": false, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; -- deleteOne: when not ordered, expect first and last delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$_id", "$$varRef1"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef2"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 1}], "ordered": false, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (1 row) ROLLBACK; -- sharded collection SELECT documentdb_api.shard_collection('db', 'coll_delete', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""delete query with limit 1 must include either _id or shard key filter"" } ] }",f) (1 row) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); QUERY PLAN --------------------------------------------------------------------- Result Output: delete('db'::text, '{ "delete" : "coll_delete", "deletes" : [ { "q" : { "$expr" : { "$eq" : [ "$a", "$$varRef" ] } }, "limit" : { "$numberInt" : "1" } } ], "let" : { "varRef" : { "$numberInt" : "2" } } }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": "cat"} }'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (2 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lte": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "zebra"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : "cat" } { "_id" : { "$numberInt" : "1" }, "a" : "dog" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'coll_delete'); document --------------------------------------------------------------------- (0 rows) ROLLBACK; RESET documentdb.enableVariablesSupportForWriteCommands; commands_drop_indexes.out000066400000000000000000000154471507310017400351030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 150000; SET documentdb.next_collection_id TO 15000; SET documentdb.next_collection_index_id TO 15000; ---- dropIndexes - top level - parse error ---- SELECT documentdb_api.create_collection('db', 'collection_3'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) CALL documentdb_api.drop_indexes('db', NULL); ERROR: Argument value must not be NULL CALL documentdb_api.drop_indexes(NULL, '{}'); ERROR: dbName cannot be NULL CALL documentdb_api.drop_indexes('db', '{}'); ERROR: The BSON field 'dropIndexes.dropIndexes' is required but was not provided CALL documentdb_api.drop_indexes('db', '{"dropIndexes": null, "index": ["my_idx_1", "does_not_exist"]}'); ERROR: The BSON field 'dropIndexes.dropIndexes' has an incorrect type 'null'; it should be of type 'string'. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "unknown_field": 1}'); ERROR: The BSON field 'dropIndexes.unknown_field' is not recognized as a valid field. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": null}'); ERROR: The BSON field 'dropIndexes.index' has an incorrect type 'null'; it should be of type '[string, object]'. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3"}'); ERROR: The BSON field 'dropIndexes.index' is required but was not provided -- this is ok CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index":[]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{"dropIndexes": 1, "index":[]}'); ERROR: The BSON field 'dropIndexes.dropIndexes' has an incorrect type 'int'; it should be of type 'string'. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": 1}'); ERROR: The BSON field 'dropIndexes.index' has an incorrect type 'int'; it should be of type '[string, object]'. ---- dropIndexes - top level - not implemented yet ---- CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": {}}'); ERROR: Unable to locate index using the provided key: { } CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "writeConcern": 1}'); ERROR: The BSON field 'dropIndexes.index' is required but was not provided CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "comment": 1}'); ERROR: The BSON field 'dropIndexes.index' is required but was not provided ---- dropIndexes -- collection doesn't exist ---- CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_4"}'); ERROR: The BSON field 'dropIndexes.index' is required but was not provided ---- dropIndexes -- index doesn't exist ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_3", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["my_idx_1", "does_not_exist"]}'); ERROR: index not found with name [does_not_exist] CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["does_not_exist", "my_idx_1"]}'); ERROR: index not found with name [does_not_exist] ---- dropIndexes -- unique unidex should work (unique index alters the table to remove a constraint) SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_3", "indexes": [{"key": {"a": 1}, "name": "idx_1", "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["idx_1"]}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) -- test drop_collection SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "drop_collection_test", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- store id of drop_collection_test before dropping it SELECT collection_id AS db_drop_collection_test_id FROM documentdb_api_catalog.collections WHERE collection_name = 'drop_collection_test' AND database_name = 'db' \gset -- Insert a record into index metadata that indicates an invalid collection index -- to show that we delete records for invalid indexes too when dropping collection. INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:db_drop_collection_test_id, 1010, ('invalid_index_1', '{"a": 1}', null, null, null, null, 2, null, null, null), false); SELECT documentdb_api.drop_collection('db', 'drop_collection_test'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT COUNT(*)=0 FROM documentdb_api_catalog.collection_indexes WHERE collection_id = :db_drop_collection_test_id; ?column? --------------------------------------------------------------------- t (1 row) commands_find_and_modify.out000066400000000000000000002434751507310017400355350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 540000; SET documentdb.next_collection_id TO 5400; SET documentdb.next_collection_index_id TO 5400; -- null db name SELECT documentdb_api.find_and_modify(NULL, '{}'); ERROR: The parameter p_database_name must not be NULL -- null message SELECT documentdb_api.find_and_modify('db', NULL); ERROR: p_message cannot be NULL -- missing params SELECT documentdb_api.find_and_modify('fam', '{}'); ERROR: The BSON field 'findAndModify.findAndModify' is required but was not provided SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "remove_or_update"}'); ERROR: You must specify either an update action or set remove=true for proper execution -- no such collection, upsert=false -- i) remove=true SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1000}, "remove": 0.1, "sort": {"b": -1}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- ii) remove=false SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "upsert": false}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- no such collection, upsert=true -- i) query is given SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_1", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "upsert": 1.1}'); NOTICE: creating collection find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""1"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'create_on_fam_1') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- ii) query is not given, and the upserted document is requested SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_2", "update": {"_id": 1, "b": 1}, "upsert": true, "new": -1}'); NOTICE: creating collection find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'create_on_fam_2') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- iii) enable_create_collection_on_insert is disabled BEGIN; SET LOCAL documentdb.enable_create_collection_on_insert TO OFF; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_3", "update": {"_id": 1, "b": 1}, "upsert": true}'); ERROR: The collection named 'create_on_fam_3' cannot be found ROLLBACK; -- test conflicting options SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "update": {"b": 1}}'); ERROR: It is not possible to specify both an update action and simultaneously set remove=true SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "upsert": true}'); ERROR: It is not allowed to set both upsert=true and remove=true simultaneously SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "new": true}'); ERROR: It is not allowed to set both new=true and remove=true simultaneously, as the 'remove' always returns the document that was deleted. -- field type validations SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": []}'); ERROR: Collection name contains an invalid data type array SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "query": 1}'); ERROR: The BSON field 'findAndModify.query' has an incorrect type 'int'; it should be of type 'object'. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "sort": "text"}'); ERROR: The BSON field 'findAndModify.sort' has an incorrect type 'string'; it should be of type 'object'. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "remove": {}}'); ERROR: The BSON field 'findAndModify.remove' has an incorrect type 'object'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "update": 1}'); ERROR: Update argument must be either an object or an array SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "new": []}'); ERROR: The BSON field 'findAndModify.new' has an incorrect type 'array'; it should be one of the following valid types: [bool, long, int, decimal, double] SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "fields": "text"}'); ERROR: The BSON field 'findAndModify.fields' has an incorrect type 'string'; it should be of type 'object'. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "upsert": []}'); ERROR: The BSON field 'findAndModify.upsert' has an incorrect type 'array'; it should be one of the following valid types: [bool, long, int, decimal, double] -- hard errors for unsupported options SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "not_supported", "arrayFilters": 1}'); ERROR: The BSON field 'findAndModify.arrayFields' has an incorrect type 'int'; it should be of type 'array'. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "not_supported", "hint": 1}'); ERROR: findAndModify.hint is not implemented yet -- unknown option SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "unknown_option", "unknown_option": 1}'); ERROR: The BSON field 'findAndModify.unknown_option' is not recognized as a valid field. SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":7}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- Disallow writes to system.views SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "system.views", "query": null, "remove": 0.0, "sort": {"b": -1}, "update": {"a": 10}, "fields": {"_id": 0}}'); ERROR: Unable to write data to specified location fam.system.views BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": null, "remove": 0.0, "sort": {"b": -1}, "update": {"a": 10}, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""5"" }, ""b"" : { ""$numberInt"" : ""7"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 5}, "sort": {"b": 1}, "update": 1, "update": {"a": 20}, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""5"" }, ""b"" : { ""$numberInt"" : ""5"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"a": 1}, "fields": {"_id": 0, "b": 0}, "upsert": 0, "new": false}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": "", "sort": {"b": 1}, "update": {"a": 1}, "fields": {"_id": 0, "b": 0}, "upsert": false, "new": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"_id": 40, "a": 30}, "fields": {"b": 1, "_id": 0}, "upsert": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""40"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- using update operators / aggregation pipeline -- -- multiple $inc, so only takes the last one into the account SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": { "$gte": 15 } }, "sort": {"a": 1}, "update": {"$set": {"z": 5}, "$inc": {"z": 5}, "$inc": {"a": 10}}, "upsert": false, "new": true, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""30"" }, ""z"" : { ""$numberInt"" : ""5"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- multiple $set/$inc but provided via a single document, so applies all SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 1000 }, "update": {"$set": {"_id": 1000, "p": 10, "r": 20}, "$inc": {"s": 30, "t": 40}}, "upsert": true, "new": true, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""1000"" } }, ""value"" : { ""a"" : { ""$numberInt"" : ""1000"" }, ""p"" : { ""$numberInt"" : ""10"" }, ""r"" : { ""$numberInt"" : ""20"" }, ""s"" : { ""$numberInt"" : ""30"" }, ""t"" : { ""$numberInt"" : ""40"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"z": { "$exists": false } }, "sort": {"a": 1}, "update": [{"$set": {"a": -10}}, {"$addFields": {"z": 7}}], "upsert": false, "new": true, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""-10"" }, ""b"" : { ""$numberInt"" : ""6"" }, ""z"" : { ""$numberInt"" : ""7"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 2000 }, "update": [ {"$set": {"p": 40, "_id": 2000, "r": 50}}, {"$unset": "p"}, {"$set": {"r": 70}}], "new": true, "fields": {"_id": 0}, "upsert": 1}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""2000"" } }, ""value"" : { ""a"" : { ""$numberInt"" : ""2000"" }, ""r"" : { ""$numberInt"" : ""70"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"_id": 40, "a": [ 30 ]}, "fields": {"b": 1, "_id": 0}, "upsert": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""40"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": { "$set": { "a.$[a]": 10 }}, "fields": {"b": 1, "_id": 0}, "upsert": true, "arrayFilters": [ { "a": 30 } ]}'); ERROR: Failed to create the field 'a' within the element specified by {a : 100} ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": { "$gte": 15 } }, "sort": {}, "update": {"$set": {"z": 5}, "$inc": {"z": 5}, "$inc": {"a": 10}}, "upsert": false, "new": true, "fields": {}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": null, "remove": true, "sort": {"b": -1}, "fields": {"_id": 0, "a": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""b"" : { ""$numberInt"" : ""7"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 5}, "remove": true, "sort": {"b": 1}, "fields": {"_id": 0, "b": 1}, "upsert": null}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""b"" : { ""$numberInt"" : ""5"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "remove": true, "sort": {"b": 1}, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "remove": true, "sort": {}, "fields": {}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ROLLBACK; -- test a sharded collection SELECT documentdb_api.create_collection('fam','sharded_collection'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.shard_collection('fam','sharded_collection', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a": 10,"b":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a":20,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a":30,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"b":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"b":9,"a": null}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- update the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": 10}, "update": {"$set": {"a": 1000}}, "fields": {"_id": 0}, "new": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""1000"" }, ""b"" : { ""$numberInt"" : ""7"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- update a field other than the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": 20}, "update": {"$set": {"b": -1}}, "fields": {"_id": 0}, "new": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""a"" : { ""$numberInt"" : ""20"" }, ""b"" : { ""$numberInt"" : ""-1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- test upsert SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": -1}, "update": {"$set": {"b": -2, "_id": 100}}, "new": true, "upsert": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""100"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""100"" }, ""a"" : { ""$numberInt"" : ""-1"" }, ""b"" : { ""$numberInt"" : ""-2"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- test "null" shard key: i) shard key is really equal to null SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"$set": {"b": -3}}, "fields": {"_id": 0}, "sort": {"b": -1}, "new": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""b"" : { ""$numberInt"" : ""-3"" }, ""a"" : null }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- test "null" shard key: ii) shard key is not set -- should update the document having {"b": 8} even if it doesn't specify "a" field at all BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"$set": {"b": -4}}, "fields": {"_id": 0}, "sort": {"b": -1}, "new": false}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""b"" : { ""$numberInt"" : ""8"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ROLLBACK; -- test "null" shard key: iii) shard key is not set -- should update the document having {"b": -3} SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"b": -4}, "fields": {"_id": 0}, "sort": {"b": 1}, "new": false}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""b"" : { ""$numberInt"" : ""-3"" }, ""a"" : null }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- missing shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": { "$gte": 15 } }, "update": {"$set": {"z": 5}}}'); ERROR: Query for sharded findAndModify must contain the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": null, "update": {"a": 10}}'); ERROR: Query for sharded findAndModify must contain the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -2}, "remove": true}'); ERROR: Query for sharded findAndModify must contain the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -2, "a": -1}, "remove": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""100"" }, ""a"" : { ""$numberInt"" : ""-1"" }, ""b"" : { ""$numberInt"" : ""-2"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- should match the document having {"b": -4} even if it doesn't specify "a" field at all SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -4, "a": null}, "remove": true, "fields": {"_id": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""b"" : { ""$numberInt"" : ""-4"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- show that we validate "update" document even if collection doesn't exist or if we can't match any documents SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1}, "update": { "$set": { "a": 1 }, "$unset": {"a": 1 } } }'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"$a": 1}, "update": { "$set": { "a": 1 } } }'); ERROR: unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. SELECT documentdb_api.create_collection('fam', 'no_match'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \set VERBOSITY TERSE SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "no_match", "update": { "$set": { "a": 1 }, "$unset": {"a": 1 } }}'); ERROR: Modifying the path 'a' will result in a conflict occurring at 'a' SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "no_match", "query": {"$a": 1}, "update": { "$set": { "a": 1 } } }'); ERROR: unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField. \set VERBOSITY DEFAULT -- test retryable update SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_update', '{"_id": 1, "a": 1, "b": 1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": false}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""3"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"_id": 0}}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""3"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "3" } } (1 row) SELECT documentdb_api.shard_collection('fam','retryable_update', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- test with upsert SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"a": 0}}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""2"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- Note that specifying different values for "new"/"fields" fields doesn't -- have any effect on the response message. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": false, "upsert": true, "fields": {"b": 0}}', 'xact-1'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""2"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "100" }, "b" : { "$numberInt" : "1" } } (2 rows) -- test with upsert, collection gets created automatically SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update_dne", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": false, "upsert": true}', 'xact-2'); NOTICE: creating collection find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""2"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update_dne", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true}', 'xact-2'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""2"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_update_dne') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "100" }, "b" : { "$numberInt" : "1" } } (1 row) -- test retryable delete SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete', '{"_id": 1, "a": 1, "b": 1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete', '{"_id": 2, "a": 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_delete') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true, "fields": {"b": 0}}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true, "fields": {"a": 0}}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_delete') ORDER BY document; document --------------------------------------------------------------------- (0 rows) SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete_sharded', '{"_id": 1, "a": 1, "b": 1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete_sharded', '{"_id": 2, "a": 1, "b": 1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.shard_collection('fam','retryable_delete_sharded', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true, "fields": {"b": 0}}', 'xact-14'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true, "fields": {"a": 0}}', 'xact-14'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_delete_sharded') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true}', 'xact-14'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true}', 'xact-14'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_delete_sharded') ORDER BY document; document --------------------------------------------------------------------- (0 rows) -- test with a query that doesn't match any documents SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 100}, "remove": true}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 100}, "remove": true}', 'xact-11'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- test with a collection that doesn't exist SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_dne", "query": {"a": 100}, "remove": true}', 'xact-13'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_dne", "query": {"a": 100}, "remove": true}', 'xact-13'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-20'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""4"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-20'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""b"" : { ""$numberInt"" : ""4"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "100" }, "b" : { "$numberInt" : "1" } } (2 rows) -- unknown operator expressions in fields argument SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"_id": 1}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"foo": {"$pop": ["bar"]}}}'); ERROR: Unrecognized expression format: $pop -- test with operator expression in fields argument SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"_id": 1}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"foo": {"$pow": [1, 2]}}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : false, ""upserted"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""foo"" : { ""$numberInt"" : ""1"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) DO $$ begin for r in 1..1000 loop PERFORM documentdb_api.insert_one('db', 'findAndModify', FORMAT('{"_id": %s, "a": "%s", "b": "%s", "c": "%s_1"}', r, (select string_agg( substr(md5(random()::text), 1, 280), '') FROM generate_series(1, 50)), (select string_agg( substr(md5(random()::text), 1, 280), '') FROM generate_series(1, 80)),r)::documentdb_core.bson); end loop; end; $$; NOTICE: creating collection SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "findAndModify", "remove": false, "query": {"_id": 549}, "upsert": false, "update": {"$set": {"c": "foo"}}, "new": false, "fields": { "_id": 1 }}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""549"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "findAndModify", "remove": false, "query": {"_id": 549}, "upsert": false, "update": {"$set": {"c": "foo"}}, "new": false, "fields": { "_id": 1 }}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : { ""_id"" : { ""$numberInt"" : ""549"" } }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- delete toasted document -- the document size is larger than 2000, so the tuple is toasted SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 1000)), (select string_agg('b', '') FROM generate_series(1, 1000)))::documentdb_core.bson); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true, "fields": {"_id": 0, "a": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""b"" : ""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 1000)), (select string_agg('b', '') FROM generate_series(1, 1000)))::documentdb_core.bson); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"", ""b"" : ""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- delete non-toasted document SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 100)), (select string_agg('b', '') FROM generate_series(1, 100)))::documentdb_core.bson); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true, "fields": {"_id": 0, "a": 0}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""b"" : ""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 100)), (select string_agg('b', '') FROM generate_series(1, 100)))::documentdb_core.bson); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"", ""b"" : ""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- let support SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 1, "a":"akura"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 2, "a":"adanko"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 3, "a":"odwan"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 4, "a":"okra"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 5, "a":"$$varRef"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- disable let support: turn off GUC SET documentdb.enableVariablesSupportForWriteCommands TO OFF; SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "let_support", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "let": {"x": 10}}'); ERROR: findAndModify.let is not yet supported -- enable let support: turn on GUC SET documentdb.enableVariablesSupportForWriteCommands TO ON; -- without $expr: variable won't evaluate to value SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": "$$varRef" }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "akura"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) BEGIN; -- update SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "akura"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$gt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "odwan"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""4"" }, ""a"" : ""okra"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lte": [{ "$toInt": "$$varRef" }, "$_id"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "4"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : { ""_id"" : { ""$numberInt"" : ""4"" }, ""c"" : ""camel"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$eq": ["$c", "$$varRef2"]}]}}, "sort": {"a": 1}, "update": {"c": "peacock"}, "let": {"varRef1": 4, "varRef2": "camel"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""4"" }, ""c"" : ""camel"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura" } { "_id" : { "$numberInt" : "2" }, "a" : "adanko" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "4" }, "c" : "peacock" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (5 rows) ROLLBACK; BEGIN; -- update with aggregation pipeline SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$set": {"c": "$$varRef"}}], "let": {"varRef": 1}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : ""akura"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$addFields": {"c": "$$varRef"}}], "let": {"varRef": "adanko"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : ""adanko"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura", "c" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "adanko", "c" : "adanko" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "4" }, "a" : "okra" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (5 rows) ROLLBACK; BEGIN; --- delete SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$a", "$$varRef"]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef": "akura"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : ""akura"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": 3}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : ""adanko"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$lte": ["$a", "$$varRef2"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef1": 4, "varRef2": "okra"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""4"" }, ""a"" : ""okra"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "c" : "ant" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; --- delete (2) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "remove": true, "let": {"varRef": "okra"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""5"" }, ""a"" : ""$$varRef"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$gte": [{ "$toInt": "$$varRef" }, "$_id"] } }, "sort": {"a": 1}, "remove": true, "let": {"varRef": "4"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : ""adanko"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] }}, "sort": {"a": 1}, "remove": true, "let": {"varRef": 2}}');; find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "4" }, "a" : "okra" } (3 rows) ROLLBACK; -- undefined variables SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}}'); ERROR: Attempting to use an undefined variable: varRef CONTEXT: SQL statement "SELECT ctid, object_id, document FROM documentdb_data.documents_5412_540063 WHERE documentdb_api_internal.bson_query_match(document, $1::documentdb_core.bson, $2::documentdb_core.bson, $3::text) ORDER BY documentdb_api_catalog.bson_orderby(document, $4::documentdb_core.bson) ASC LIMIT 1 FOR UPDATE" SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_5412 WHERE shard_key_value = 5412" SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef2"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef1": 3}}'); ERROR: Attempting to use an undefined variable: varRef2 CONTEXT: SQL statement "SELECT ctid, object_id, document FROM documentdb_data.documents_5412_540063 WHERE documentdb_api_internal.bson_query_match(document, $1::documentdb_core.bson, $2::documentdb_core.bson, $3::text) ORDER BY documentdb_api_catalog.bson_orderby(document, $4::documentdb_core.bson) ASC LIMIT 1 FOR UPDATE" SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_5412 WHERE shard_key_value = 5412" --- sharded collection SELECT documentdb_api.shard_collection('db', 'find_and_modify_let', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; -- update SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": "3", "$expr": {"$eq": [{"$toInt": "$$varRef"}, "$_id"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "3"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 4, "$expr": {"$lt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "odwan"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$eq": ["$c", "$$varRef2"]}]}}, "sort": {"a": 1}, "update": {"c": "peacock"}, "let": {"varRef1": 4, "varRef2": "ant"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" }, ""updatedExisting"" : false }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura" } { "_id" : { "$numberInt" : "2" }, "a" : "adanko" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "4" }, "a" : "okra" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (5 rows) ROLLBACK; BEGIN; -- update with aggregation pipeline SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$set": {"c": "$$varRef"}}], "let": {"varRef": 1}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""1"" }, ""a"" : ""akura"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$addFields": {"c": "$$varRef"}}], "let": {"varRef": "adanko"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : ""adanko"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura", "c" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : "adanko", "c" : "adanko" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "4" }, "a" : "okra" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (5 rows) ROLLBACK; BEGIN; --- delete SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 2, "$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": 3}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" }, ""updatedExisting"" : true }, ""value"" : { ""_id"" : { ""$numberInt"" : ""2"" }, ""a"" : ""adanko"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef"]}, {"$eq": ["$a", "akura"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef": "akura"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""0"" } }, ""value"" : null, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 4, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$lte": ["$a", "$$varRef2"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef1": 4, "varRef2": "okra"}}'); find_and_modify --------------------------------------------------------------------- ("{ ""lastErrorObject"" : { ""n"" : { ""$numberInt"" : ""1"" } }, ""value"" : { ""_id"" : { ""$numberInt"" : ""4"" }, ""a"" : ""okra"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "akura" } { "_id" : { "$numberInt" : "2" }, "c" : "ant" } { "_id" : { "$numberInt" : "3" }, "a" : "odwan" } { "_id" : { "$numberInt" : "5" }, "a" : "$$varRef" } (4 rows) ROLLBACK; RESET documentdb.enableVariablesSupportForWriteCommands; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/commands_insert.out000066400000000000000000000457271507310017400340070ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 659000; SET documentdb.next_collection_id TO 6590; SET documentdb.next_collection_index_id TO 6590; -- exercise invalid insert syntax errors select documentdb_api.insert('db', NULL); ERROR: insert document cannot be NULL select documentdb_api.insert(NULL, '{"insert":"into", "documents":[{"a":1}]}'); ERROR: Database name must not be NULL value select documentdb_api.insert('db', '{"documents":[{"a":1}]}'); ERROR: The BSON field 'insert.insert' is required but not provided select documentdb_api.insert('db', '{"insert":"into"}'); ERROR: BSON field 'insert.documents' is missing but a required field select documentdb_api.insert('db', '{"insert":["into"], "documents":[{"a":1}]}'); ERROR: Collection name contains an invalid data type array select documentdb_api.insert('db', '{"insert":"into", "documents":{"a":1}}'); ERROR: The BSON field 'insert.documents' has an incorrect type 'object'; it should be of type 'array'. select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}], "extra":1}'); ERROR: The BSON field 'insert.extra' is not recognized as a valid field. select documentdb_api.insert('db', '{"insert":"into", "documents":[4]}'); ERROR: The BSON field 'insert.documents.0' has an incorrect type 'int'; it should be of type 'object'. select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}],"ordered":1}'); ERROR: The BSON field 'insert.ordered' has an incorrect type 'int'; it should be of type 'bool'. -- Disallow system.views, system.profile writes select documentdb_api.insert('db', '{"insert":"system.views", "documents":[{"a":1}],"ordered":true}'); ERROR: Unable to write data to specified location db.system.views CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" select documentdb_api.insert('db', '{"insert":"system.profile", "documents":[{"a":1}],"ordered":true}'); ERROR: Unable to write data to specified location db.system.profile CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- regular single-row insert select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":99,"a":99}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "99" }, "a" : { "$numberInt" : "99" } } (1 row) -- Insert into a db with same name and different case and collection being same. Expect to error select documentdb_api.insert('dB', '{"insert":"into", "documents":[{"_id":99,"a":99}]}'); ERROR: Database already exists but with a different case; existing entry: [db], attempted creation: [dB] CONTEXT: SQL statement "SELECT documentdb_api_internal.validate_dbname(NEW.database_name)" PL/pgSQL function trigger_validate_dbname() line 3 at PERFORM SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- Insert into a db with same name and different case and collection being different. Expect to error select documentdb_api.insert('dB', '{"insert":"intonew", "documents":[{"_id":99,"a":99}]}'); ERROR: Database already exists but with a different case; existing entry: [db], attempted creation: [dB] CONTEXT: SQL statement "SELECT documentdb_api_internal.validate_dbname(NEW.database_name)" PL/pgSQL function trigger_validate_dbname() line 3 at PERFORM SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" -- Insert into same db and new collection. select documentdb_api.insert('db', '{"insert":"intonew1", "documents":[{"_id":99,"a":99}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- keep the collection, but remove the rows select documentdb_api.delete('db', '{"delete":"into", "deletes":[{"q":{},"limit":0}]}'); delete --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- single-row insert with retry begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) rollback; -- regular multi-row insert begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) rollback; -- multi-row insert with first document key starts with $ begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) rollback; -- multi-row insert with first document key starts with $ and ordered:false begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}],"ordered":false}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "$a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) rollback; -- shard the collection by _id select documentdb_api.shard_collection('db', 'into', '{"_id":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- single-row insert with retry begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) rollback; -- single-row insert with retry and auto-generated _id begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}]}',NULL,'insert-2'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}]}',NULL,'insert-2'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select count(*) from documentdb_api.collection('db','into') where document @@ '{}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- multi-row insert into different shards begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) select document from documentdb_api.collection('db','into') where document @@ '{"a":1}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } (1 row) select document from documentdb_api.collection('db','into') where document @@ '{"a":2}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (1 row) rollback; -- insert with documents in special section begin; SELECT documentdb_api.insert('db', '{"insert":"into"}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "2" } } (2 rows) rollback; -- insert with both docs specified. begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); ERROR: Both 'documents' and 'insert.documents' cannot be specified. rollback; -- insert with id undefined skips begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":{ "$undefined": true } }]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) rollback; begin; select documentdb_api.insert('db', '{"insert":"into"}', '{ "": [ {"_id":{ "$undefined": true } } ]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) rollback; -- single-row insert into non-existent collection when auto-creation is disabled begin; set local documentdb.enable_create_collection_on_insert to off; select documentdb_api.insert('db', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); ERROR: The collection named 'notexists' cannot be found rollback; -- insert with invalid database begin; select documentdb_api.insert('Invalid Database Name', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); ERROR: Database Invalid Database Name has an invalid character CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" rollback; begin; select documentdb_api.insert('db', '{"insert":"system.othercoll", "documents":[{"_id":1,"a":1}]}'); ERROR: System namespace provided is invalid: db.system.othercoll CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" rollback; begin; select documentdb_api.insert('db', '{"insert":"random$name", "documents":[{"_id":1,"a":1}]}'); ERROR: Collection name provided is invalid: random$name CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" rollback; begin; select documentdb_api.insert('db', '{"insert":".randomname", "documents":[{"_id":1,"a":1}]}'); ERROR: Collection names must not begin with the '.' character: .randomname CONTEXT: SQL statement "INSERT INTO documentdb_api_catalog.collections ( database_name, collection_name, collection_uuid ) VALUES ($1, $2, gen_random_uuid()) RETURNING collection_id" SQL statement "SELECT documentdb_api.create_collection($1, $2)" rollback; begin; select documentdb_api.insert('verylongdatabasenameformeasuringthelimitsofdatabasenamesinmongodb', '{"insert":"coll", "documents":[{"_id":1,"a":1}]}'); ERROR: The provided database name exceeds the permitted length rollback; begin; select documentdb_api.insert('verylongdatabasenameformeasuringlimitsofdatabasenamesinmongodb', '{"insert":"verylongcollectionnameformeasuringthelimitsofcollectionnamesinmongodb", "documents":[{"_id":1,"a":1}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) rollback; select documentdb_api.drop_collection('db','into'); drop_collection --------------------------------------------------------------------- t (1 row) select documentdb_api.drop_collection('db','intonew1'); drop_collection --------------------------------------------------------------------- t (1 row) -- Server contract - never attempt to deduplicate inserting documents, the clients may deduplicate them based on the handling of JSON/BSON data type. select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate1", "a": {"$numberInt": "1"}}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate2", "a": {"$numberInt": "1"}, "a": {"$numberInt": "2"}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate3", "a": {"$numberInt": "1"}, "b": {"$numberInt": "2"}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- storage size of duplicate2 and duplicate3 should be same. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "duplicatetests", "pipeline": [{"$project": { "storageSize": {"$bsonSize": "$$ROOT"} } }] }'); document --------------------------------------------------------------------- { "_id" : "duplicate1", "storageSize" : { "$numberInt" : "32" } } { "_id" : "duplicate2", "storageSize" : { "$numberInt" : "39" } } { "_id" : "duplicate3", "storageSize" : { "$numberInt" : "39" } } (3 rows) commands_shard_collection.out000066400000000000000000000763601507310017400357350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2400000; SET documentdb.next_collection_id TO 24000; SET documentdb.next_collection_index_id TO 24000; -- before reshard SELECT documentdb_api.insert_one('db','reshard','{"_id":"1", "value": { "$numberInt" : "11" }}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400006 collection Index Cond: (shard_key_value = '24000'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "11" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}'; document --------------------------------------------------------------------- { "_id" : "1", "value" : { "$numberInt" : "11" } } (1 row) ROLLBACK; -- invalid inputs SELECT documentdb_api.shard_collection('db','reshard', '{"value":1}'); ERROR: only shard keys that use hashed are supported SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hash"}'); ERROR: Shard key value provided is invalid: hash -- create two indexes before re-sharding SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "reshard", "indexes": [ {"key": {"a.b.c.$**": 1}, "name": "idx_1"}, {"key": {"z": 1}, "name": "idx_2"} ] }', true ); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT collection_id AS reshard_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'reshard' AND database_name = 'db' \gset \d documentdb_data.documents_:reshard_collection_id Table "documentdb_data.documents_24000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_24000" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_24001" documentdb_rum (document bson_rum_single_path_ops (path='a.b.c', iswildcard='true', tl='2699')) "documents_rum_index_24002" documentdb_rum (document bson_rum_single_path_ops (path=z, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '24000'::bigint) -- insert an invalid index metadata entry before re-sharding INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:reshard_collection_id, 2020, ('invalid_index', '{"c": 1}', null, null, null, null, 2, null, null, null), false); -- shard based on value key SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) \d documentdb_data.documents_:reshard_collection_id Table "documentdb_data.documents_24000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_24000" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_24003" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) "documents_rum_index_24004" documentdb_rum (document bson_rum_single_path_ops (path='a.b.c', iswildcard='true', tl='2699')) "documents_rum_index_24005" documentdb_rum (document bson_rum_single_path_ops (path=z, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = get_shard_key_value('{ "value" : "hashed" }'::bson, 24000::bigint, document)) SELECT FORMAT('documentdb_data.documents_%s', :reshard_collection_id) AS db_shard_data_table_name \gset -- make plans (more) deterministic VACUUM (ANALYZE) :db_shard_data_table_name; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'reshard') ORDER BY index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 24000 | 24003 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 24000 | 24004 | { "v" : { "$numberInt" : "2" }, "key" : { "a.b.c.$**" : { "$numberInt" : "1" } }, "name" : "idx_1" } | t 24000 | 24005 | { "v" : { "$numberInt" : "2" }, "key" : { "z" : { "$numberInt" : "1" } }, "name" : "idx_2" } | t (3 rows) SELECT documentdb_api.insert_one('db','reshard','{"value":{"$numberLong" : "134311"}, "_id":"2" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','reshard','{"_id":"3", "value": 11}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- documents without a shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"4", "novalue": 0}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$exists":false}}'; count --------------------------------------------------------------------- 1 (1 row) -- documents with an object shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"5", "value": {"hello":"world"}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"hello":"world"}}'; count --------------------------------------------------------------------- 1 (1 row) -- documents with an array shard key are not allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": ["hello","world"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "1088" }, "errmsg" : "A shard key is not permitted to include any array elements." } ] } (1 row) -- documents with regex shard key are not allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": {"$regularExpression":{"pattern":"foo","options":""}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "1088" }, "errmsg" : "A shard key is not allowed to include any regular expression pattern." } ] } (1 row) -- documents with double shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": 15.0}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- after reshard BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400022 collection Index Cond: (shard_key_value = '838241346061304183'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "11" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "1", "value" : { "$numberInt" : "11" } } { "_id" : "3", "value" : { "$numberInt" : "11" } } (2 rows) ROLLBACK; -- small longs have the same hash as ints BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberLong" : "134311"}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400020 collection Index Cond: (shard_key_value = '7547761715150210803'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberLong" : "134311" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberLong" : "134311"}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "2", "value" : { "$numberLong" : "134311" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberInt" : "134311"}}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400020 collection Index Cond: (shard_key_value = '7547761715150210803'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "134311" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberInt" : "134311"}}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "2", "value" : { "$numberLong" : "134311" } } (1 row) ROLLBACK; -- should find doubles too when looking for int BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":15}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400023 collection Index Cond: (shard_key_value = '8792588867541173546'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "15" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":15}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "6", "value" : { "$numberDouble" : "15.0" } } (1 row) ROLLBACK; -- reshard based on value and _id key SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hashed","_id":"hashed"}', true); shard_collection --------------------------------------------------------------------- (1 row) -- after reshard BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"$and":[{"value":{"$eq":11}},{"_id":{"$eq":"1"}}]}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400028 collection Index Cond: ((shard_key_value = '-2638831846010261801'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "1" }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "11" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"$and":[{"value":{"$eq":11}},{"_id":{"$eq":"1"}}]}'; document --------------------------------------------------------------------- { "_id" : "1", "value" : { "$numberInt" : "11" } } (1 row) ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11,"_id":"1"}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400028 collection Index Cond: ((shard_key_value = '-2638831846010261801'::bigint) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "1" }'::documentdb_core.bson)) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "11" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11,"_id":"1"}'; document --------------------------------------------------------------------- { "_id" : "1", "value" : { "$numberInt" : "11" } } (1 row) ROLLBACK; -- should get same hash value SELECT documentdb_api_internal.get_shard_key_value('{"value":1,"_id":1}',1,'{"_id":"1","value":11}'); get_shard_key_value --------------------------------------------------------------------- -2638831846010261801 (1 row) SELECT documentdb_api_internal.get_shard_key_value('{"value":1,"_id":1}',1,'{"value":11,"_id":"1"}'); get_shard_key_value --------------------------------------------------------------------- -2638831846010261801 (1 row) SELECT collection_id AS collection_id, shard_key::text AS shard_key FROM documentdb_api_catalog.collections WHERE collection_name = 'reshard' AND database_name = 'db' \gset DO $$ DECLARE v_collection documentdb_api_catalog.collections; v_compute_shard_key bigint; BEGIN SELECT * INTO v_collection FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshard'; SELECT documentdb_api_internal.get_shard_key_value(v_collection.shard_key, v_collection.collection_id, '{"value":11,"_id":"1"}') INTO v_compute_shard_key; RAISE INFO 'Computed shard key: %', v_compute_shard_key; END; $$; INFO: Computed shard key: -2638831846010261801 -- different order of fields SELECT documentdb_api_internal.get_shard_key_value('{"_id":1,"value":1}', 1,'{"_id":"1","value":11}'); get_shard_key_value --------------------------------------------------------------------- -1749061796927280186 (1 row) SELECT documentdb_api_internal.get_shard_key_value('{"_id":1,"value":1}', 1,'{"value":11,"_id":"1"}'); get_shard_key_value --------------------------------------------------------------------- -1749061796927280186 (1 row) -- should produce different hash values because type is taken into account SELECT documentdb_api_internal.get_shard_key_value('{"a":1,"b":1}', 1,'{"_id":"1","a":1,"b":true}'); get_shard_key_value --------------------------------------------------------------------- -5223650992195555312 (1 row) SELECT documentdb_api_internal.get_shard_key_value('{"a":1,"b":1}', 1,'{"_id":"1","a":true,"b":1}'); get_shard_key_value --------------------------------------------------------------------- -2857368848324726306 (1 row) -- only 1 part of shard key specified, goes to multiple shards BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Sort Sort Key: remote_scan.worker_column_2 -> Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_24000_2400024 documents_24000 Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "value" : { "$numberInt" : "11" } }'::documentdb_core.bson) (9 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "1", "value" : { "$numberInt" : "11" } } { "_id" : "3", "value" : { "$numberInt" : "11" } } (2 rows) ROLLBACK; -- no shard key filter specified SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE true; count --------------------------------------------------------------------- 6 (1 row) SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE false; count --------------------------------------------------------------------- 0 (1 row) SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$exists":1}}'; count --------------------------------------------------------------------- 5 (1 row) -- reshard based on nested path SELECT documentdb_api.shard_collection('db','reshard', '{"a.b":"hashed"}', true); shard_collection --------------------------------------------------------------------- (1 row) -- we should not allow arrays in the path even if the value is not an array SELECT documentdb_api.insert_one('db','reshard','{"_id":"10", "a": [{"b":22}]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "1088" }, "errmsg" : "Shard key is not allowed to include array values or any array-derived elements." } ] } (1 row) -- nested objects should be fine SELECT documentdb_api.insert_one('db','reshard','{"_id":"10", "a": {"b":22}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"a.b":22}' ORDER BY object_id; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using _id_ on documents_24000_2400032 collection Index Cond: (shard_key_value = '-8641956760761651950'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a.b" : { "$numberInt" : "22" } }'::documentdb_core.bson) (8 rows) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"a.b":22}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "b" : { "$numberInt" : "22" } } } (1 row) ROLLBACK; -- try to shard a non-existent collection SELECT documentdb_api.shard_collection('db','not_exists', '{"value":"hashed"}', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) -- shard a collection that has no user-created indexes SELECT documentdb_api.insert_one('db','shard_collection_no_indexes','{"_id":"1", "value": { "$numberInt" : "11" }}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; -- Shard it twice within a xact block to test whether we drop the temp table -- (v_saved_index_entries) before completing documentdb_api.shard_collection(). SELECT documentdb_api.shard_collection('db','shard_collection_no_indexes', '{"value":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('db','shard_collection_no_indexes', '{"value":"hashed"}', false); NOTICE: Skipping Sharding for collection db.shard_collection_no_indexes as the same options were passed in. shard_collection --------------------------------------------------------------------- (1 row) COMMIT; -- shard creates a new collection. BEGIN; SELECT documentdb_api.shard_collection('db', 'newCollectionToCreate', '{ "value": "hashed" }', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) SELECT database_name, collection_name FROM documentdb_api_catalog.collections WHERE collection_name = 'newCollectionToCreate' ORDER BY database_name, collection_name; database_name | collection_name --------------------------------------------------------------------- db | newCollectionToCreate (1 row) ROLLBACK; -- shard collection with indexes with bson text as hex binary still works. BEGIN; set local documentdb_core.bsonUseEJson to false; SELECT documentdb_api.insert_one('db','reshardwithindexes2','{"_id":"1", "value": 11, "otherValue": 15 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- BSONHEX18000000106e0001000000016f6b00000000000000f03f00 (1 row) -- create some indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('reshardwithindexes2', 'idx1', '{ "value": 1 }'), true); create_indexes_non_concurrently --------------------------------------------------------------------- BSONHEX7e00000003726177006c0000000364656661756c7453686172640059000000106e756d496e64657865734265666f72650001000000106e756d496e6465786573416674657200020000000863726561746564436f6c6c656374696f6e4175746f6d61746963616c6c790000106f6b00010000000000106f6b000100000000 (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('reshardwithindexes2', 'idx2', '{ "otherValue": 1 }'), true); create_indexes_non_concurrently --------------------------------------------------------------------- BSONHEX7e00000003726177006c0000000364656661756c7453686172640059000000106e756d496e64657865734265666f72650002000000106e756d496e6465786573416674657200030000000863726561746564436f6c6c656374696f6e4175746f6d61746963616c6c790000106f6b00010000000000106f6b000100000000 (1 row) -- now shard the collection SELECT documentdb_api.shard_collection('db', 'reshardwithindexes2', '{ "value": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT collection_id AS reshard_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'reshardwithindexes2' AND database_name = 'db' \gset set local documentdb_core.bsonUseEJson to true; SELECT index_spec from documentdb_api_catalog.collection_indexes WHERE collection_id = :reshard_collection_id order by index_id ASC; index_spec --------------------------------------------------------------------- (_id_,"{ ""_id"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) (idx1,"{ ""value"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) (idx2,"{ ""otherValue"" : { ""$numberInt"" : ""1"" } }",,,,,2,,,) (3 rows) SELECT database_name, collection_name, shard_key from documentdb_api_catalog.collections WHERE collection_id = :reshard_collection_id; database_name | collection_name | shard_key --------------------------------------------------------------------- db | reshardwithindexes2 | { "value" : "hashed" } (1 row) ROLLBACK; -- create a new sharded collection SELECT documentdb_api.create_collection('db', 'reshardoptions'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- now shard it. SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "a.b": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- shard with the same key SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "a.b": "hashed" }'); NOTICE: Skipping Sharding for collection db.reshardoptions as the same options were passed in. shard_collection --------------------------------------------------------------------- (1 row) -- shard with a new key with reshard:false (should fail) SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "c.d": "hashed" }', false); ERROR: Sharding already enabled for collection db.reshardoptions with options { "_id": "db.reshardoptions", "dropped" : false, "key" : { "c.d" : "hashed" }, "unique": false }. -- key should now be { "a.b": "hashed" } SELECT database_name, collection_name, shard_key FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshardoptions'; database_name | collection_name | shard_key --------------------------------------------------------------------- db | reshardoptions | { "a.b" : "hashed" } (1 row) -- shard with a new key with reshard:true (should work) SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "c.d": "hashed" }', true); shard_collection --------------------------------------------------------------------- (1 row) -- key should now be { "c.d": "hashed" } SELECT database_name, collection_name, shard_key FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshardoptions'; database_name | collection_name | shard_key --------------------------------------------------------------------- db | reshardoptions | { "c.d" : "hashed" } (1 row) -- reshard on non existing collections or non-sharded collections should fail SELECT documentdb_api.shard_collection('db', 'nonExistingCollection', '{ "a.b": "hashed" }', true); ERROR: Collection db.nonExistingCollection is not sharded SELECT documentdb_api.create_collection('db', 'nonShardedCollection'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.shard_collection('db', 'nonShardedCollection', '{ "a.b": "hashed" }', true); ERROR: Collection db.nonShardedCollection is not sharded documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/commands_update.out000066400000000000000000006131051507310017400337540ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 649000; SET documentdb.next_collection_id TO 6490; SET documentdb.next_collection_index_id TO 6490; SET documentdb.EnableVariablesSupportForWriteCommands TO on; select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":1,"_id":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":2,"_id":2,"b":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":3,"_id":3,"b":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":4,"_id":4,"b":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":5,"_id":5,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":6,"_id":6,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":7,"_id":7,"b":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":8,"_id":8,"b":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":9,"_id":9,"b":9}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":10,"_id":10,"b":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- exercise invalid update syntax errors select documentdb_api.update('db', NULL); ERROR: update document cannot be NULL select documentdb_api.update(NULL, '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: database name must not be NULL select documentdb_api.update('db', '{"updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: Required field 'update.update' is missing select documentdb_api.update('db', '{"update":"updateme"}'); ERROR: Required field 'update.updates' is missing select documentdb_api.update('db', '{"update":["updateme"], "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: collection name has invalid type array select documentdb_api.update('db', '{"update":"updateme", "updates":{"q":{},"u":{"$set":{"b":0}},"multi":true}}'); ERROR: The BSON field 'update.updates' has an incorrect type 'object'; it should be of type 'array'. select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}], "extra":1}'); ERROR: The BSON field 'update.extra' is not recognized as a valid field select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{}}]}'); ERROR: The required field 'update.updates.u' is missing CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"multi":true}]}'); ERROR: The required field 'update.updates.u' is missing CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"multi":true}]}'); ERROR: The required field 'update.updates.q' is missing CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"u":{"$set":{"b":0}}}]}'); ERROR: The required field 'update.updates.q' is missing CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":"text"}]}'); ERROR: BSON field 'update.updates.u' is the wrong type 'string', expected type 'object' or 'array' CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":[],"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: The BSON field 'update.updates.q' has an incorrect type 'array'; it should be of type 'object'. CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":1}]}'); ERROR: The BSON field 'update.updates.multi' has an incorrect type 'int'; it should be of type 'bool'. CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"extra":1}]}'); ERROR: The field 'update.updates.extra' specified is not recognized as a valid field CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}],"ordered":1}'); ERROR: The BSON field 'update.ordered' has an incorrect type 'int'; it should be of type 'bool'. select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$bork":{"b":0}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50331677"" }, ""errmsg"" : ""Unknown modifier: $bork. Please use a valid update modifier or pipeline-style update specified as an array"" } ] }",f) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"upsert":[]}]}'); ERROR: The BSON field 'update.updates.upsert' has an incorrect type 'array'; it should be of type 'bool'. CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6490 WHERE shard_key_value = 6490" -- Disallow writes to system.views select documentdb_api.update('db', '{"update":"system.views", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); ERROR: Unable to write data to specified location db.system.views -- update all begin; SET LOCAL search_path TO ''; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""10"" }, ""n"" : { ""$numberInt"" : ""10"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document OPERATOR(documentdb_api_catalog.@@) '{"b":0}'; count --------------------------------------------------------------------- 10 (1 row) rollback; -- update some begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"$set":{"b":0}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""3"" }, ""n"" : { ""$numberInt"" : ""3"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 3 (1 row) rollback; -- update multi with a replace is not supported begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"b":0},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50331677"" }, ""errmsg"" : ""multi=true and replace-style updates cannot be used together."" } ] }",f) (1 row) rollback; -- update multi with an aggregation pipeline is supported begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":[{"$unset":["b"]}],"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""3"" }, ""n"" : { ""$numberInt"" : ""3"" } }",t) (1 row) rollback; -- update all from non-existent collection select documentdb_api.update('db', '{"update":"notexists", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) -- query syntax errors are added the response select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$ltr":5}},"u":{"$set":{"b":0}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""Unrecognized operator specified: $ltr"" } ] }",f) (1 row) -- when ordered, expect only first update to be executed begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- when not ordered, expect first and last update to be executed begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":false}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) select count(*) from documentdb_api.collection('db', 'updateme'); count --------------------------------------------------------------------- 10 (1 row) rollback; -- update 1 without filters is supported for unsharded collections begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- update 1 with a replace that preserves the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"b":0},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (1 row) rollback; -- update 1 with a replace that tries to change the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"_id":0,"b":0},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""486539293"" }, ""errmsg"" : ""Cannot modify '_id' field as part of the operation"" } ] }",f) (1 row) rollback; -- update 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "2" } } (1 row) -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "3" } } (1 row) rollback; -- update 1 is supported in the _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":6},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "0" } } (1 row) rollback; -- update 1 is supported in the multiple identical _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "0" } } (1 row) rollback; -- update 1 is supported in the multiple distinct _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "6" } } (1 row) rollback; -- update some with range filter that excludes all rows begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":true,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- upsert 1 with range filter is supported for unsharded collections begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- upsert 1 with a replace that preserves the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":11},"u":{"b":0},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- upsert 1 with a replace that set the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33},"u":{"_id":0,"b":0},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""0"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- upsert 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 1 (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 0 (1 row) -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- upsert 1 is supported in the _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""33"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- test _id extraction from update begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""33"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":3}'; count --------------------------------------------------------------------- 1 (1 row) set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6490_649000 documents_6490 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6490) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":4}'; count --------------------------------------------------------------------- 1 (1 row) rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""33"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":0}'; count --------------------------------------------------------------------- 1 (1 row) set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":1}},"multi":true,"upsert":true}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6490_649000 documents_6490 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6490) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":1}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- shard the collection select documentdb_api.shard_collection('db', 'updateme', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- make sure we get the expected results after sharding a collection begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":5}},"u":{"$set":{"b":0}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""5"" }, ""n"" : { ""$numberInt"" : ""5"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "0" } } (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":10}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "10" } } (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 5 (1 row) rollback; -- test pruning logic in update begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_6490_649022 documents_6490 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_6490.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_6490.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE ((documents_6490.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (documents_6490.shard_key_value OPERATOR(pg_catalog.=) $6)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_6490.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"u":{"$set":{"b":0}},"multi":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_6490_649022 documents_6490 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_6490.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_6490.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE (((documents_6490.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (documents_6490.document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bsonquery)) AND (documents_6490.shard_key_value OPERATOR(pg_catalog.=) $6)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_6490.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- update 1 without filters is unsupported for sharded collections select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50856066"" }, ""errmsg"" : ""A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard"" } ] }",f) (1 row) -- update 1 with shard key filters is supported for sharded collections begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6490_649022 documents_6490 WHERE (shard_key_value OPERATOR(pg_catalog.=) '1786987034919379147'::bigint) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- update 1 with shard key filters is retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":10}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "11" } } (1 row) rollback; -- upsert 1 with shard key filters is retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 1 (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 0 (1 row) -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- update 1 that does not match any rows is still retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":15,"_id":15}'); ?column? --------------------------------------------------------------------- 1 (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) rollback; -- update 1 is supported in the _id case even on sharded collections begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- update first row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":10}'; count --------------------------------------------------------------------- 2 (1 row) -- update second row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 2 (1 row) -- no more row where _id = 10 and b != 0 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) rollback; -- update 1 with with _id filter on a sharded collection is retryable begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- update first row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- second time is a noop select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":10}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "11" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "10" } } (2 rows) rollback; -- upsert on sharded collection with multi:true begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":33},"u":{"$set":{"b":33,"_id":11}},"multi":true,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""11"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":33}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- updating shard key is disallowed when using multi:true begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) rollback; -- updating shard key is disallowed when using multi:true, even with a shard key filter begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) rollback; -- updating shard key is disallowed without a shard key filter begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50856066"" }, ""errmsg"" : ""A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard"" } ] }",f) (1 row) rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":1},"u":{"$inc":{"a":1}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""shard key value update is only supported when filtering by the full shard key and specifying multi:false"" } ] }",f) (1 row) rollback; -- updating shard key is allowed when multi:false and shard key filter is specified begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"a":2}'; count --------------------------------------------------------------------- 2 (1 row) rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":10},"u":{"$set":{"a":20}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"a":20}'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- empty shard key value is allowed (hash becomes 0) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$unset":{"a":1}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"b":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) rollback; -- update 1 is supported in the multiple identical _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "0" } } (1 row) rollback; -- update 1 is unsupported in the multiple distinct _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50856066"" }, ""errmsg"" : ""A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard"" } ] }",f) (1 row) select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "6" } } (1 row) rollback; -- test _id extraction from update begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""33"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":3 }'; count --------------------------------------------------------------------- 1 (1 row) set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6490_649023 documents_6490 WHERE (shard_key_value OPERATOR(pg_catalog.=) '5243071450131145979'::bigint) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":4 }'; count --------------------------------------------------------------------- 1 (1 row) rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""33"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":1 }'; count --------------------------------------------------------------------- 1 (1 row) set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_6490_649023 documents_6490 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_6490.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_6490.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE (((documents_6490.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "33" } }'::documentdb_core.bsonquery) AND (documents_6490.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND (documents_6490.shard_key_value OPERATOR(pg_catalog.=) $6) AND (documents_6490.object_id OPERATOR(documentdb_core.=) ($7)::documentdb_core.bson)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_6490.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":2 }'; count --------------------------------------------------------------------- 1 (1 row) rollback; -- update with docs specified on special section begin; select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""36"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":1 }'; count --------------------------------------------------------------------- 1 (1 row) select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""37"" } } ] }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":1 }'; count --------------------------------------------------------------------- 2 (1 row) select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":2}},"multi":false }, {"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":2}},"multi":false}] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":2 }'; count --------------------------------------------------------------------- 2 (1 row) rollback; -- update with docs specified on both begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}', '{ "":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}] }'); ERROR: Unexpected further updates required rollback; -- update with index hint specified by name and by key object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "updateme", "indexes": [ { "key" : { "a": 1 }, "name": "validIndex"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"hint": "validIndex"}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""10"" }, ""n"" : { ""$numberInt"" : ""10"" } }",t) (1 row) select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"hint": { "a": 1 }}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""10"" } }",t) (1 row) rollback; select documentdb_api.drop_collection('db','updateme'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":1,"a":3,"b":7}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":2,"a":2,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":3,"a":1,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- sort in ascending order and project & return old document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'update' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 3 } }, "isUpsert": false, "sort": { "b": 1 }, "returnDocument": 1, "returnFields": { "_id": 0, "b": 1 } } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); update_worker --------------------------------------------------------------------- { "isRowUpdated" : true, "updateSkipped" : false, "isRetry" : false, "resultDocument" : { "b" : { "$numberInt" : "5" } } } (1 row) -- sort by multiple fields (i) and project & return new document BEGIN; SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 4 } }, "isUpsert": false, "sort": { "b": -1, "a": 1 }, "returnDocument": 2 } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); update_worker --------------------------------------------------------------------- { "isRowUpdated" : true, "updateSkipped" : false, "isRetry" : false, "resultDocument" : { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "4" } } } (1 row) SELECT document FROM documentdb_api.collection('update', 'test_sort_returning') ORDER BY 1; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "4" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "6" } } (3 rows) ROLLBACK; SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 4 } }, "isUpsert": false, "sort": { "a": 1, "b": -1 }, "returnDocument": 2 } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); update_worker --------------------------------------------------------------------- { "isRowUpdated" : true, "updateSkipped" : false, "isRetry" : false, "resultDocument" : { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "4" } } } (1 row) SELECT document FROM documentdb_api.collection('update', 'test_sort_returning') ORDER BY 1; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "2" }, "c" : { "$numberInt" : "3" } } { "_id" : { "$numberInt" : "3" }, "c" : { "$numberInt" : "4" } } (3 rows) -- show that we validate "update" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" } ] }",f) (1 row) -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) SELECT documentdb_api.create_collection('update', 'no_match'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- show that we validate "update" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""335544349"" }, ""errmsg"" : ""Modifying the path 'p' will result in a conflict occurring at 'p'"" } ] }",f) (1 row) -- show that we validate "query" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" }, { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""16777245"" }, ""errmsg"" : ""unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField."" } ] }",f) (1 row) -- Validate multi and single updates with no-op return matched and updated as expected SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":1,"a":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":2,"a":2,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":3,"a":3,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":4,"a":100,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":5,"a":200,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":6,"a":6,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":3}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":7}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""4"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":150}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) -- no match select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 50 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) -- all updated select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":500}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""6"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) -- all match, no-op update select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":true,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""6"" } }",t) (1 row) -- single update SELECT 1 FROM documentdb_api.insert_one('update', 'single', '{"_id":1,"a":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- no-op update single select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- no match select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 50 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) --upsert with same field in querySpec select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":1234, "$and" : [{"x" : {"$eq": 1}}, {"x": 2}]},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""1234"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":2345, "x": 1, "x.x": 1},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""2345"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":3456, "x": {}, "x.x": 1},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""3456"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":4567, "x": {"x": 1}, "x.x": 1},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""4567"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":5678, "x": {"x": 1}, "x.y": 1},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""5678"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":6789, "x": [1, {"x": 1}], "x.x": 1},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""6789"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""419430429"" }, ""errmsg"" : ""Unable to determine which query fields to set, as the path '_id' has been matched twice"" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"x": 1, "x": 5},"u":{"$set" : {"x":10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""419430429"" }, ""errmsg"" : ""Unable to determine which query fields to set, as the path 'x' has been matched twice"" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""603979805"" }, ""errmsg"" : ""Invalid path '_id.b'. Please specify the full '_id' field value instead of a sub-path"" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_idab.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""3"" } } ] }",t) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id.c": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""603979805"" }, ""errmsg"" : ""Invalid path '_id.c'. Please specify the full '_id' field value instead of a sub-path"" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"_id":3},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""419430429"" }, ""errmsg"" : ""Unable to determine which query fields to set, as the path '_id' has been matched twice"" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"$set" : {"_id":3} },"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""419430429"" }, ""errmsg"" : ""Unable to determine which query fields to set, as the path '_id' has been matched twice"" } ] }",f) (1 row) -- array filters sent to final update command. BEGIN; select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "arrayFilters": [ { "a": 2 } ]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""134111"" } } ] }",t) (1 row) SELECT documentdb_api.insert_one('update', 'multi', '{ "_id": 134112, "blah": [ 5, 1, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('update', 'multi', '{ "_id": 134113, "blah": [ 6, 3, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":true,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) -- no match here. select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) -- updates one of the two. select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 99 },"u":{"$max":{"blah.$[a]":109}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 99 } ]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) ROLLBACK; -- test replace with upsert select documentdb_api.update('test@', '{ "update" : "shell_wc_a", "ordered" : true, "updates" : [ { "q" : { "_id" : 1.0 }, "u" : { "_id" : 1.0 }, "multi" : false, "upsert" : true } ] }'); NOTICE: creating collection update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberDouble"" : ""1.0"" } } ] }",t) (1 row) --upsert with $expr select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"$expr" : {"$eq": ["$a",1]}}]},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gt": ["$b",1]}}, {"x": 2}]},"u":{"$set" : {"a": 10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$expr": {"$gt" : ["$x",10]}},"u":{},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"a": 10}, {"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}, {"b":11} ]},"u":{"$set": {"a" :10}},"upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50593821"" }, ""errmsg"" : ""Use of the $expr operator is not permitted within the query predicate for an upsert operation."" } ] }",f) (1 row) -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. BEGIN; SELECT documentdb_api.insert_one('update','NonID',' { "_id" : 1, "b" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) set local citus.log_remote_commands to on; SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}, "_id" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}, "a" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$gt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$lt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": []}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2,3,4]}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$expr":{"$gt": ["$_id",1]}},"u":{"$set":{"b":0 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1},{"_id":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":2}, {"a" : 1}]},"u":{"$set":{"b":0}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"b":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT document from documentdb_api.collection('update', 'NonID'); NOTICE: executing the command locally: SELECT document FROM documentdb_data.documents_6498_649038 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '6498'::bigint) document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}},"u":{"$inc":{"b": 1 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}, {"b" : 1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_6498_649038 documents_6498 WHERE (shard_key_value OPERATOR(pg_catalog.=) 6498) update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document from documentdb_api.collection('update', 'NonID'); NOTICE: executing the command locally: SELECT document FROM documentdb_data.documents_6498_649038 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '6498'::bigint) document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "7" } } (1 row) ROLLBACK; -- regex operator and update SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 1, "Login": "robert.bean@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 2, "Login": "peter.ramesh@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 3, "Login": "picop1@test.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 4, "Login": "peter.claxton@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.update('db', '{"update":"regexColl", "updates":[{ "q" : { "Login" : { "$regularExpression" : { "pattern" : "^picop1@test\\.co\\.uk$", "options" : "i" } } },"u":{"$addToSet": { "RefreshTokens": { "RefreshToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } }}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document from documentdb_api.collection('db', 'regexColl'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "Login" : "robert.bean@networkrail.co.uk", "RefreshTokens" : [ ] } { "_id" : { "$numberInt" : "2" }, "Login" : "peter.ramesh@networkrail.co.uk", "RefreshTokens" : [ ] } { "_id" : { "$numberInt" : "3" }, "Login" : "picop1@test.co.uk", "RefreshTokens" : [ { "RefreshToken" : "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } ] } { "_id" : { "$numberInt" : "4" }, "Login" : "peter.claxton@networkrail.co.uk", "RefreshTokens" : [ ] } (4 rows) -- test update with upsert BEGIN; set documentdb.useLocalExecutionShardQueries to off; SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""8010"" } } ] }",t) (1 row) SELECT documentdb_api.shard_collection('update', 'single', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8011 }, "u": { "value": "1" }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""8011"" } } ] }",t) (1 row) ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""8010"" } } ] }",t) (1 row) -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "value": "1123" }, "u": { "_id": 8010 }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Duplicate key violation on the requested collection: Index '_id_'"" } ] }",f) (1 row) ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""8010"" } } ] }",t) (1 row) -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "value": "21020" }, "u": { "$set": { "_id": 8010 } }, "upsert": true, "multi": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Duplicate key violation on the requested collection: Index '_id_'"" } ] }",f) (1 row) ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""8010"" } } ] }",t) (1 row) -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id": 8010, "a": 5 }, "u": { "$set": { "c": 8010 } }, "upsert": true, "multi": true }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Duplicate key violation on the requested collection: Index '_id_'"" } ] }",f) (1 row) ROLLBACK; -- test updateOne with sort select documentdb_api.create_collection('update', 'test_update_one_sort'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":1,"a":3,"b":7}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":2,"a":3,"b":5}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "5" } } (2 rows) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "7" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (2 rows) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":10}},"multi":false,"upsert":false, "sort": {"_id": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } (2 rows) SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":3,"a":3,"b":3}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-1}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-1" } } (3 rows) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-1}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "10" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-1" } } (3 rows) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"b":{"$lt":5}},"u":{"$set":{"text":"smaller than 5"}},"multi":false,"upsert":false, "sort": {"b": -1}}, {"q":{"b":{"$gte":5}},"u":{"$set":{"text":"large"}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "10" }, "text" : "large" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" }, "text" : "smaller than 5" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-1" } } (3 rows) -- negative test case SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"b":{"$lt":5}},"u":{"$set":{"text":"tt"}},"multi":true,"sort": {"b": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50331677"" }, ""errmsg"" : ""sort option can not be set when multi=true"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "10" }, "text" : "large" } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" }, "text" : "smaller than 5" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-1" } } (3 rows) SELECT documentdb_api.insert('update', '{"insert":"test_update_one_sort_ex", "documents":[{"_id":-1,"a":1,"b":"string"}, {"_id":-2,"a":0,"b":1.2}, {"_id":-3,"a":1,"b":[1,2,3]}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"test_update_one_sort_ex", "updates":[{"q":{"a":{"$gte":0}},"u":{"$set":{"b":"exception"}},"multi":false,"sort": {"b": -1}},{"q":{"a":{"$gte":0}},"u":{"$set":{"b":[4,5]}},"multi":false,"sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":"exception"}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "update.test_update_one_sort_ex", "firstBatch" : [ { "a" : { "$numberInt" : "1" }, "b" : "exception" } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":[4,5]}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "update.test_update_one_sort_ex", "firstBatch" : [ { "a" : { "$numberInt" : "1" }, "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) WITH generated_data AS ( SELECT row_number() OVER () AS _id, 1 AS a, CASE (random()*6)::int WHEN 0 THEN (random()*1000)::int::text WHEN 1 THEN to_char(random()*1000, 'FM999.9999') WHEN 2 THEN 'str_' || floor(random()*10000)::int WHEN 3 THEN (ARRAY['true','false'])[floor(random()*2)+1] WHEN 4 THEN to_char( now() - (floor(random()*3650)||' days')::interval, 'YYYY-MM-DD' ) WHEN 5 THEN gen_random_uuid()::text ELSE NULL::text END AS b FROM generate_series(1, 1000) ) SELECT documentdb_api.insert( 'update'::text, ('{"insert":"test_update_one_sort_ex", "documents":[' || (SELECT string_agg(row_to_json(g)::text, ',') FROM generated_data g) || ']}')::bson ); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1000"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.update('update', '{"update":"test_update_one_sort_ex", "updates":[{"q":{"a":{"$gte":0}},"u":{"$set":{"b":"exception"}},"multi":false,"sort": {"b": -1}},{"q":{"a":{"$gte":0}},"u":{"$set":{"b":[4,5]}},"multi":false,"sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":"exception"}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "update.test_update_one_sort_ex", "firstBatch" : [ { "a" : { "$numberInt" : "1" }, "b" : "exception" }, { "a" : { "$numberInt" : "1" }, "b" : "exception" } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":[4,5]}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); cursorpage --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "update.test_update_one_sort_ex", "firstBatch" : [ { "a" : { "$numberInt" : "1" }, "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }, { "a" : { "$numberInt" : "1" }, "b" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] } ] }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- sharded collection select documentdb_api.shard_collection('update', 'test_update_one_sort', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- expect to fail as updateOne without id filter is not supported on sharded collection SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50856066"" }, ""errmsg"" : ""A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard"" } ] }",f) (1 row) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-10}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50856066"" }, ""errmsg"" : ""A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard"" } ] }",f) (1 row) -- expect to succeed as updateOne with id filter is supported on sharded collection SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":1, "a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":2, "a":3},"u":{"$set":{"b":-10}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- negative test case SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":3, "a":3},"u":{"$set":{"b":-1}},"multi":true,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""50331677"" }, ""errmsg"" : ""sort option can not be set when multi=true"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-1" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-10" }, "text" : "smaller than 5" } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" }, "text" : "large" } (3 rows) -- expect to throw error but the first one should succeed SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":3, "a":3},"u":{"$set":{"b":-10}},"multi":true,"upsert":false},{"q":{"_id":3, "a":3},"u":{"$set":{"b":-2}},"multi":true,"upsert":false, "sort": {"_id": -1}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""1"" }, ""code"" : { ""$numberInt"" : ""50331677"" }, ""errmsg"" : ""sort option can not be set when multi=true"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-10" }, "text" : "smaller than 5" } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "-10" } } { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "0" }, "text" : "large" } (3 rows) -- let support SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 1, "a":"kofi"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 2, "a":"ama"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 3, "a":"$$varRef"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- EnableVariablesSupportForWriteCommands GUC off: ignore variableSpec SET documentdb.EnableVariablesSupportForWriteCommands TO off; SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": "ama"} }'); ERROR: update.let is not yet supported -- EnableVariablesSupportForWriteCommands GUC on: user variableSpec SET documentdb.EnableVariablesSupportForWriteCommands TO on; -- variables accessed outside $expr will not evaluate to let variable value in 'q' SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": "$$varRef" }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": 2}} '); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": "$$varRef" }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2}} '); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) BEGIN; -- updateMany SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2} }'); QUERY PLAN --------------------------------------------------------------------- Result Output: update('db'::text, '{ "update" : "coll_update", "updates" : [ { "q" : { "$expr" : { "$eq" : [ "$_id", "$$varRef" ] } }, "u" : { "$set" : { "b" : "zebra" } }, "multi" : true } ], "let" : { "varRef" : { "$numberInt" : "2" } } }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; -- updateOne SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": 2} }'); QUERY PLAN --------------------------------------------------------------------- Result Output: update('db'::text, '{ "update" : "coll_update", "updates" : [ { "q" : { "$expr" : { "$eq" : [ "$_id", "$$varRef" ] } }, "u" : { "$set" : { "b" : "zebra" } }, "multi" : false } ], "let" : { "varRef" : { "$numberInt" : "2" } } }'::bson, NULL::bsonsequence, NULL::text) (2 rows) ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "kojo"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "kojo"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "b" : "kojo" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "b" : "kojo" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "kojo"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "kojo"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "b" : "kojo" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "b" : "kojo" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; -- let support: variables in 'u' BEGIN; -- variables are accessible in aggregation pipeline SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": {"$set": {"set": "$$varRef"}}, "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : "$$varRef" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : "$$varRef" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; -- updateMany: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": [{"$addFields": {"addFields": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" }, "addFields" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gte": ["$_id", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "project" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "project" : { "$numberInt" : "2" } } (3 rows) -- updateMany: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "newRoot" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "project" : { "$numberInt" : "2" } } (3 rows) -- updateMany: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "replaceWith" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "project" : { "$numberInt" : "2" } } (3 rows) ROLLBACK; BEGIN; -- updateOne: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lt": ["$a", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": [{"$addFields": {"addField": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gt": ["$a", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "project" : "ama" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "project" : "ama" } { "_id" : { "$numberInt" : "2" }, "newRoot" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "project" : "ama" } { "_id" : { "$numberInt" : "2" }, "replaceWith" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) ROLLBACK; -- let support: sharded collection SELECT documentdb_api.shard_collection('db', 'coll_update', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; -- updateMany SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"a": 1, "$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "anomaa"}}, "multi": true}], "let": {"varRef": "kofi"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; -- updateOne SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"a": 2, "$expr": {"$lt": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "ako"}}, "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "akua"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "abena"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "b" : "abena" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "b" : "akua" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; -- updateMany: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": [{"$addFields": {"addFields": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" }, "addFields" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gte": ["$_id", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" }, "addFields" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" }, "addFields" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) -- updateMany: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi", "set" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "set" : { "$numberInt" : "2" }, "addFields" : { "$numberInt" : "2" } } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef" } (3 rows) ROLLBACK; BEGIN; -- updateOne: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 3, "$expr": {"$lt": ["$a", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "u": [{"$addFields": {"addField": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 1, "$expr": {"$gt": ["$a", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""shard key value update is only supported when filtering by the full shard key and specifying multi:false"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""shard key value update is only supported when filtering by the full shard key and specifying multi:false"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) -- updateOne: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""1088"" }, ""errmsg"" : ""shard key value update is only supported when filtering by the full shard key and specifying multi:false"" } ] }",f) (1 row) SELECT document FROM documentdb_api.collection('db', 'coll_update'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : "kofi" } { "_id" : { "$numberInt" : "2" }, "a" : "ama", "addField" : "ama" } { "_id" : { "$numberInt" : "3" }, "a" : "$$varRef", "set" : "ama" } (3 rows) ROLLBACK; -- sharded collection shard on some other field and query on object_id SELECT 1 FROM documentdb_api.insert_one('db', 'upShardTest', '{"_id":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_api.shard_collection('db', 'upShardTest', '{"b": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) select documentdb_api.update('db', '{"update":"upShardTest", "updates":[{"q":{"_id":1},"u":{"b":1},"multi":false}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) commands_update_bulk.out000066400000000000000000004271341507310017400347170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 849000; SET documentdb.next_collection_id TO 8490; SET documentdb.next_collection_index_id TO 8490; SET documentdb.EnableVariablesSupportForWriteCommands TO on; select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":1,"_id":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":2,"_id":2,"b":2}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":3,"_id":3,"b":3}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":4,"_id":4,"b":4}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":5,"_id":5,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":6,"_id":6,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":7,"_id":7,"b":7}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":8,"_id":8,"b":8}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":9,"_id":9,"b":9}'); ?column? --------------------------------------------------------------------- 1 (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":10,"_id":10,"b":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- exercise invalid update syntax errors CALL documentdb_api.update_bulk('bulkdb', NULL); ERROR: update document cannot be NULL CALL documentdb_api.update_bulk(NULL, '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: database name must not be NULL CALL documentdb_api.update_bulk('bulkdb', '{"updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: Required field 'update.update' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}'); ERROR: Required field 'update.updates' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":["updateme"], "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: collection name has invalid type array CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":{"q":{},"u":{"$set":{"b":0}},"multi":true}}'); ERROR: The BSON field 'update.updates' has an incorrect type 'object'; it should be of type 'array'. CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}], "extra":1}'); ERROR: The BSON field 'update.extra' is not recognized as a valid field CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{}}]}'); ERROR: The required field 'update.updates.u' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"multi":true}]}'); ERROR: The required field 'update.updates.u' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"multi":true}]}'); ERROR: The required field 'update.updates.q' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"u":{"$set":{"b":0}}}]}'); ERROR: The required field 'update.updates.q' is missing CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":"text"}]}'); ERROR: BSON field 'update.updates.u' is the wrong type 'string', expected type 'object' or 'array' CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":[],"u":{"$set":{"b":0}},"multi":true}]}'); ERROR: The BSON field 'update.updates.q' has an incorrect type 'array'; it should be of type 'object'. CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":1}]}'); ERROR: The BSON field 'update.updates.multi' has an incorrect type 'int'; it should be of type 'bool'. CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"extra":1}]}'); ERROR: The field 'update.updates.extra' specified is not recognized as a valid field CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}],"ordered":1}'); ERROR: The BSON field 'update.ordered' has an incorrect type 'int'; it should be of type 'bool'. CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$bork":{"b":0}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50331677" }, "errmsg" : "Unknown modifier: $bork. Please use a valid update modifier or pipeline-style update specified as an array" } ] } | f (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"upsert":[]}]}'); ERROR: The BSON field 'update.updates.upsert' has an incorrect type 'array'; it should be of type 'bool'. -- Disallow writes to system.views CALL documentdb_api.update_bulk('bulkdb', '{"update":"system.views", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); ERROR: Unable to write data to specified location bulkdb.system.views -- update all set search_path TO ''; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } | t (1 row) SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document OPERATOR(documentdb_api_catalog.@@) '{"b":0}'; count --------------------------------------------------------------------- 10 (1 row) -- update some CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"$set":{"b":1}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "3" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":1}'; count --------------------------------------------------------------------- 3 (1 row) -- update multi with a replace is not supported CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"b":0},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50331677" }, "errmsg" : "multi=true and replace-style updates cannot be used together." } ] } | f (1 row) -- update multi with an aggregation pipeline is supported CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":[{"$unset":["b"]}],"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "3" } } | t (1 row) -- update all from non-existent collection CALL documentdb_api.update_bulk('bulkdb', '{"update":"notexists", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- query syntax errors are added the response CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$ltr":5}},"u":{"$set":{"b":0}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "Unrecognized operator specified: $ltr" } ] } | f (1 row) -- when ordered, expect only first update to be executed CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":2}}},{"q":{"$a":2},"u":{"$set":{"b":2}}},{"q":{"a":3},"u":{"$set":{"b":2}}}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":2}'; count --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":3}}},{"q":{"$a":2},"u":{"$set":{"b":3}}},{"q":{"a":3},"u":{"$set":{"b":3}}}],"ordered":true}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":3}'; count --------------------------------------------------------------------- 1 (1 row) -- when not ordered, expect first and last update to be executed CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":false}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "2" }, "n" : { "$numberInt" : "2" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme'); count --------------------------------------------------------------------- 10 (1 row) -- update 1 without filters is supported for unsharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":5}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":5}'; count --------------------------------------------------------------------- 1 (1 row) -- update 1 with a replace that preserves the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"b":6},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "b" : { "$numberInt" : "6" } } (1 row) -- update 1 with a replace that tries to change the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"_id":0,"b":7},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- update 1 is retryable on unsharded collection (second call is a noop) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "8" } } (1 row) -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "16" } } (1 row) -- update 1 is supported in the _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":6},"u":{"$set":{"b":9}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "9" } } (1 row) -- update 1 is supported in the multiple identical _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":10}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "10" } } (1 row) -- update 1 is supported in the multiple distinct _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":11}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "10" } } (1 row) -- update some with range filter that excludes all rows CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lt":0}},"u":{"$set":{"b":12,"_id":11}},"multi":true,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "11" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":12}'; count --------------------------------------------------------------------- 1 (1 row) -- upsert 1 with range filter is supported for unsharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 5 (1 row) -- upsert 1 with a replace that preserves the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":11},"u":{"b":13},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":13}'; count --------------------------------------------------------------------- 1 (1 row) -- upsert 1 with a replace that set the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33},"u":{"_id":0,"b":14},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "0" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":0}'; count --------------------------------------------------------------------- 1 (1 row) -- upsert 1 is retryable on unsharded collection (second call is a noop) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 0 (1 row) -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 0 (1 row) -- upsert 1 is supported in the _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "33" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33}'; count --------------------------------------------------------------------- 1 (1 row) -- test _id extraction from update CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":3}'; count --------------------------------------------------------------------- 1 (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":4}'; count --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":0}'; count --------------------------------------------------------------------- 1 (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":1}},"multi":true,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":1}'; count --------------------------------------------------------------------- 1 (1 row) -- shard the collection select documentdb_api.shard_collection('bulkdb', 'updateme', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) -- make sure we get the expected results after sharding a collection CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":5}},"u":{"$set":{"b":0}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "3" }, "n" : { "$numberInt" : "4" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "0" } } (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":10}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 8 (1 row) -- test pruning logic in update set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_8491_849010 documents_8491 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_8491.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_8491.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE ((documents_8491.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (documents_8491.shard_key_value OPERATOR(pg_catalog.=) $6)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_8491.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 8 (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"u":{"$set":{"b":0}},"multi":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_8491_849010 documents_8491 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_8491.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_8491.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE (((documents_8491.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bsonquery) AND (documents_8491.document OPERATOR(documentdb_api_catalog.#>) '{ "a" : { "$numberInt" : "0" } }'::documentdb_core.bsonquery)) AND (documents_8491.shard_key_value OPERATOR(pg_catalog.=) $6)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_8491.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 8 (1 row) -- update 1 without filters is unsupported for sharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50856066" }, "errmsg" : "A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard" } ] } | f (1 row) -- update 1 with shard key filters is supported for sharded collections set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":false}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_8491_849010 documents_8491 WHERE (shard_key_value OPERATOR(pg_catalog.=) '1786987034919379147'::bigint) p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "5" }, "a" : { "$numberInt" : "5" }, "b" : { "$numberInt" : "0" } } (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 8 (1 row) -- update 1 with shard key filters is retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":10}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "1" } } (1 row) -- upsert 1 with shard key filters is retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "11" } } ] } | t (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "11" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 1 (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 0 (1 row) -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; count --------------------------------------------------------------------- 0 (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; count --------------------------------------------------------------------- 1 (1 row) -- update 1 that does not match any rows is still retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":15,"_id":15}'); ?column? --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- update 1 is supported in the _id case even on sharded collections -- add an additional _id 10 select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- update first row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":10}'; count --------------------------------------------------------------------- 2 (1 row) -- update second row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; count --------------------------------------------------------------------- 9 (1 row) -- no more row where _id = 10 and b != 0 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- update 1 with with _id filter on a sharded collection is retryable -- add an additional _id 10 select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":11,"_id":10}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- update first row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- second time is a noop CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":10}' ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "11" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "10" }, "b" : { "$numberInt" : "0" } } (2 rows) -- upsert on sharded collection with multi:true CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":33},"u":{"$set":{"b":33,"_id":11}},"multi":true,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":33}'; count --------------------------------------------------------------------- 0 (1 row) -- updating shard key is disallowed when using multi:true CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Invalid write detected. Please validate the collection and/or shard key being written to" } ] } | f (1 row) -- updating shard key is disallowed when using multi:true, even with a shard key filter CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Invalid write detected. Please validate the collection and/or shard key being written to" } ] } | f (1 row) -- updating shard key is disallowed without a shard key filter CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50856066" }, "errmsg" : "A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard" } ] } | f (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":1},"u":{"$inc":{"a":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "1088" }, "errmsg" : "shard key value update is only supported when filtering by the full shard key and specifying multi:false" } ] } | f (1 row) -- updating shard key is allowed when multi:false and shard key filter is specified CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":2}'; count --------------------------------------------------------------------- 2 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":10},"u":{"$set":{"a":20}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":20}'; count --------------------------------------------------------------------- 1 (1 row) -- empty shard key value is allowed (hash becomes 0) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$unset":{"a":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":1}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "33" }, "b" : { "$numberInt" : "1" } } { "_id" : { "$numberInt" : "10" }, "a" : { "$numberInt" : "11" }, "b" : { "$numberInt" : "1" } } (2 rows) -- update 1 is supported in the multiple identical _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "0" } } (1 row) -- update 1 is unsupported in the multiple distinct _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50856066" }, "errmsg" : "A {multi:false} update on a sharded collection must contain an exact match on _id or target a single shard" } ] } | f (1 row) select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "6" }, "a" : { "$numberInt" : "6" }, "b" : { "$numberInt" : "0" } } (1 row) -- test _id extraction from update CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "33" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":3 }'; count --------------------------------------------------------------------- 1 (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); NOTICE: executing the command locally: SELECT documentdb_api_internal.update_worker($1, $2, $3, ($4)::documentdb_core.bson, ($5)::documentdb_core.bsonsequence, $6) AS update_worker FROM documentdb_data.documents_8491_849011 documents_8491 WHERE (shard_key_value OPERATOR(pg_catalog.=) '5243071450131145979'::bigint) p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":4 }'; count --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":1 }'; count --------------------------------------------------------------------- 2 (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}'); NOTICE: executing the command locally: WITH u AS (UPDATE documentdb_data.documents_8491_849011 documents_8491 SET document = (SELECT COALESCE(bson_update_document.newdocument, documents_8491.document) AS "coalesce" FROM documentdb_api_internal.bson_update_document(documents_8491.document, ($1)::documentdb_core.bson, $2::documentdb_core.bson, ($3)::documentdb_core.bson, false, $4::documentdb_core.bson) bson_update_document(newdocument, updatedesc) WHERE true) WHERE (((documents_8491.document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : { "$numberInt" : "33" } }'::documentdb_core.bsonquery) AND (documents_8491.document OPERATOR(documentdb_api_catalog.#=) '{ "a" : { "$numberInt" : "10" } }'::documentdb_core.bsonquery)) AND (documents_8491.shard_key_value OPERATOR(pg_catalog.=) $6) AND (documents_8491.object_id OPERATOR(documentdb_core.=) ($7)::documentdb_core.bson)) RETURNING documentdb_api_internal.bson_update_returned_value(documents_8491.shard_key_value) AS updated) SELECT count(*) AS count, sum(updated) AS sum FROM u WHERE true p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":2 }'; count --------------------------------------------------------------------- 1 (1 row) -- update with docs specified on special section CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "36" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":1 }'; count --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "37" } } ] } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":1 }'; count --------------------------------------------------------------------- 2 (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":2}},"multi":false }, {"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":2}},"multi":false}] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "2" }, "n" : { "$numberInt" : "2" } } | t (1 row) select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":2 }'; count --------------------------------------------------------------------- 2 (1 row) -- update with docs specified on both CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}', '{ "":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}] }'); ERROR: Unexpected further updates required select documentdb_api.drop_collection('bulkdb','updateme'); drop_collection --------------------------------------------------------------------- t (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":1,"a":3,"b":7}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":2,"a":2,"b":5}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":3,"a":1,"b":6}'); ?column? --------------------------------------------------------------------- 1 (1 row) -- show that we validate "update" document even if collection doesn't exist -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" } ] } | f (1 row) -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" }, { "index" : { "$numberInt" : "3" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" } ] } | f (1 row) -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." }, { "index" : { "$numberInt" : "3" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) SELECT documentdb_api.create_collection('update_bulk', 'no_match'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- show that we validate "update" document even if we can't match any documents -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" } ] } | f (1 row) -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" }, { "index" : { "$numberInt" : "3" }, "code" : { "$numberInt" : "335544349" }, "errmsg" : "Modifying the path 'p' will result in a conflict occurring at 'p'" } ] } | f (1 row) -- show that we validate "query" document even if we can't match any documents -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "1" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $b. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." }, { "index" : { "$numberInt" : "3" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $d. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- Validate multi and single updates with no-op return matched and updated as expected SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":1,"a":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":2,"a":2,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":3,"a":3,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":4,"a":100,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":5,"a":200,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":6,"a":6,"b":1}'); ?column? --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":3}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "2" }, "n" : { "$numberInt" : "6" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":7}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "4" }, "n" : { "$numberInt" : "6" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":150}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "6" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "2" }, "n" : { "$numberInt" : "6" } } | t (1 row) -- no match CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 50 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- all updated CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":500}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "6" }, "n" : { "$numberInt" : "6" } } | t (1 row) -- all match, no-op update CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":true,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "6" } } | t (1 row) -- single update SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'single', '{"_id":1,"a":1,"b":1}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":false,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- no-op update single CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- no match CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 50 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) --upsert with same field in querySpec CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":1234, "$and" : [{"x" : {"$eq": 1}}, {"x": 2}]},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "1234" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":2345, "x": 1, "x.x": 1},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "2345" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":3456, "x": {}, "x.x": 1},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "3456" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":4567, "x": {"x": 1}, "x.x": 1},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "4567" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":5678, "x": {"x": 1}, "x.y": 1},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "5678" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":6789, "x": [1, {"x": 1}], "x.x": 1},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "6789" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "419430429" }, "errmsg" : "Unable to determine which query fields to set, as the path '_id' has been matched twice" } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"x": 1, "x": 5},"u":{"$set" : {"x":10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "419430429" }, "errmsg" : "Unable to determine which query fields to set, as the path 'x' has been matched twice" } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "603979805" }, "errmsg" : "Invalid path '_id.b'. Please specify the full '_id' field value instead of a sub-path" } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_idab.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "3" } } ] } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id.c": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "603979805" }, "errmsg" : "Invalid path '_id.c'. Please specify the full '_id' field value instead of a sub-path" } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"_id":3},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "419430429" }, "errmsg" : "Unable to determine which query fields to set, as the path '_id' has been matched twice" } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"$set" : {"_id":3} },"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "419430429" }, "errmsg" : "Unable to determine which query fields to set, as the path '_id' has been matched twice" } ] } | f (1 row) -- array filters sent to final update command. CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "arrayFilters": [ { "a": 2 } ]}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "134111" } } ] } | t (1 row) SELECT documentdb_api.insert_one('update_bulk', 'multi', '{ "_id": 134112, "blah": [ 5, 1, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('update_bulk', 'multi', '{ "_id": 134113, "blah": [ 6, 3, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":true,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "2" }, "n" : { "$numberInt" : "2" } } | t (1 row) -- no match here. CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) -- updates one of the two. CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 99 },"u":{"$max":{"blah.$[a]":109}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 99 } ]}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- test replace with upsert CALL documentdb_api.update_bulk('bulktest@', '{ "update" : "shell_wc_a", "ordered" : true, "updates" : [ { "q" : { "_id" : 1.0 }, "u" : { "_id" : 1.0 }, "multi" : false, "upsert" : true } ] }'); NOTICE: creating collection p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberDouble" : "1.0" } } ] } | t (1 row) --upsert with $expr CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"$expr" : {"$eq": ["$a",1]}}]},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gt": ["$b",1]}}, {"x": 2}]},"u":{"$set" : {"a": 10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$expr": {"$gt" : ["$x",10]}},"u":{},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"a": 10}, {"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}, {"b":11} ]},"u":{"$set": {"a" :10}},"upsert":true}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50593821" }, "errmsg" : "Use of the $expr operator is not permitted within the query predicate for an upsert operation." } ] } | f (1 row) -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. SELECT documentdb_api.insert_one('update_bulk','NonID',' { "_id" : 1, "b" : 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}, "_id" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}, "a" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$gt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$lt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": []}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2,3,4]}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$expr":{"$gt": ["$_id",1]}},"u":{"$set":{"b":0 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1},{"_id":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":2}, {"a" : 1}]},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"b":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" } } | t (1 row) SELECT document from documentdb_api.collection('update_bulk', 'NonID'); NOTICE: executing the command locally: SELECT document FROM documentdb_data.documents_8499_849026 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8499'::bigint) document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "1" } } (1 row) -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}},"u":{"$inc":{"b": 1 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}, {"b" : 1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) SELECT document from documentdb_api.collection('update_bulk', 'NonID'); NOTICE: executing the command locally: SELECT document FROM documentdb_data.documents_8499_849026 collection WHERE (shard_key_value OPERATOR(pg_catalog.=) '8499'::bigint) document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "7" } } (1 row) -- regex operator and update RESET citus.log_remote_commands; RESET citus.log_local_commands; SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 1, "Login": "robert.bean@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 2, "Login": "peter.ramesh@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 3, "Login": "picop1@test.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 4, "Login": "peter.claxton@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) CALL documentdb_api.update_bulk('bulkdb', '{"update":"regexColl", "updates":[{ "q" : { "Login" : { "$regularExpression" : { "pattern" : "^picop1@test\\.co\\.uk$", "options" : "i" } } },"u":{"$addToSet": { "RefreshTokens": { "RefreshToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } }}}]}'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "1" }, "n" : { "$numberInt" : "1" } } | t (1 row) SELECT document from documentdb_api.collection('bulkdb', 'regexColl'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "Login" : "robert.bean@networkrail.co.uk", "RefreshTokens" : [ ] } { "_id" : { "$numberInt" : "2" }, "Login" : "peter.ramesh@networkrail.co.uk", "RefreshTokens" : [ ] } { "_id" : { "$numberInt" : "3" }, "Login" : "picop1@test.co.uk", "RefreshTokens" : [ { "RefreshToken" : "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } ] } { "_id" : { "$numberInt" : "4" }, "Login" : "peter.claxton@networkrail.co.uk", "RefreshTokens" : [ ] } (4 rows) -- test update with upsert set documentdb.useLocalExecutionShardQueries to off; CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "8010" } } ] } | t (1 row) SELECT documentdb_api.shard_collection('update_bulk', 'single', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8011 }, "u": { "value": "1" }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" }, "upserted" : [ { "index" : { "$numberInt" : "0" }, "_id" : { "$numberInt" : "8011" } } ] } | t (1 row) -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "value": "1123" }, "u": { "_id": 8010 }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "50856066" }, "errmsg" : "An {upsert:true} update on a sharded collection must target a single shard" } ] } | f (1 row) -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "value": "21020" }, "u": { "$set": { "_id": 8010 } }, "upsert": true, "multi": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "1" } } | t (1 row) -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id": 8010, "a": 5 }, "u": { "$set": { "c": 8010 } }, "upsert": true, "multi": true }] }'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "0" }, "n" : { "$numberInt" : "0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } | f (1 row) reset documentdb.useLocalExecutionShardQueries; -- update bulk transaction testing SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 1, "a": 1, "b": 1 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 2, "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 3, "a": 1, "b": 1 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s ]}', string_agg('{ "q": { "_id": 1 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query FROM generate_series(1, 10) \gset -- update query with an invalid query in the middle SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s, { "q": { "$a": 1 }, "u": { "$inc": { "b": 1 } } }, %s ]}', string_agg('{ "q": { "_id": 2 }, "u": { "$inc": { "b": 1 } }}', ',' ), string_agg('{ "q": { "_id": 2 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query2 FROM generate_series(1, 5) \gset SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s, { "q": { "$a": 1 }, "u": { "$inc": { "b": 1 } } }, %s ], "ordered": false }', string_agg('{ "q": { "_id": 3 }, "u": { "$inc": { "b": 1 } }}', ',' ), string_agg('{ "q": { "_id": 3 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query3 FROM generate_series(1, 5) \gset SET client_min_messages TO DEBUG1; -- this one should have no commits logged here CALL documentdb_api.update_bulk('update_bulk', :'update_query'); p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } | t (1 row) -- this should have 5 messages (1 try for the batch + rollback, and then 5 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "5" }, "n" : { "$numberInt" : "5" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- This should have 10 messages (1 try for the batch + rollback, and retry 9 more) CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- should have updated 10 times SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "6" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "11" } } (3 rows) -- reduce batch to 8 set documentdb.batchWriteSubTransactionCount to 8; -- This should have 1 commit message (1 for batchsize of 8 ) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } | t (1 row) -- this should have 5 messages (1 try for the batch + rollback, and then 5 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "5" }, "n" : { "$numberInt" : "5" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- This should have 9 messages (1 try for the batch + rollback, and retry 8 more) CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "21" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "11" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "21" } } (3 rows) -- now reduce to 3 set documentdb.batchWriteSubTransactionCount to 3; -- This should have 3 commit message (1 for each batchsize of 3) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } | t (1 row) -- this should have 4 messages (1 for success, 1 try for the batch + rollback, and then 2 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "5" }, "n" : { "$numberInt" : "5" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- this should have 7 messages (1 for success, 1 try for batch and rollback, and 5 more tries). CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: Commiting intermediate state and reacquiring collection lock p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "31" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "16" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "31" } } (3 rows) -- disable local writes set documentdb.useLocalExecutionShardQueries to off; -- These should all have 4 commit message (1 for each batchsize of 3, and 1 for the last one) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } | t (1 row) CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "5" }, "n" : { "$numberInt" : "5" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI DEBUG: Commiting intermediate state and reacquiring collection lock DEBUG: executing " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_8501 WHERE shard_key_value = 8501" via SPI p_result | p_success --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" }, "writeErrors" : [ { "index" : { "$numberInt" : "5" }, "code" : { "$numberInt" : "16777245" }, "errmsg" : "unknown top level operator: $a. If you have a field name that starts with a '$' symbol, consider using $getField or $setField." } ] } | f (1 row) -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "41" } } { "_id" : { "$numberInt" : "2" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "21" } } { "_id" : { "$numberInt" : "3" }, "a" : { "$numberInt" : "1" }, "b" : { "$numberInt" : "41" } } (3 rows) commands_validate.out000066400000000000000000000257341507310017400342110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 870000; SET documentdb.next_collection_id TO 8700; SET documentdb.next_collection_index_id TO 8700; SELECT documentdb_api.drop_collection('db', 'validatecoll'); drop_collection --------------------------------------------------------------------- f (1 row) -- Empty collection name SELECT documentdb_api.validate('db','{}'); ERROR: The specified namespace is invalid: 'db'. SELECT documentdb_api.validate('db', '{"validate" : ""}'); ERROR: The specified namespace is invalid: 'db'. -- Collection does not exist SELECT documentdb_api.validate('db', '{"validate" : "missingcoll"}'); ERROR: The collection 'db.missingcoll' cannot be validated because it does not exist. -- Create Collection SELECT documentdb_api.create_collection('db', 'validatecoll'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- Collection without docs and with only id index/no user defined indexes SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "1" }, "indexDetails" : { "_id_" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Collection with id index and an additional index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('validatecoll', 'index_1', '{"a": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Insert few docs SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 100 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 101, "b": 201 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 102, "b": 202 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) -- Collection with docs and user defined index SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Valid input options -- -- only validate SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- validate with repair: true or repair: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : false}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- validate with full: true or full: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : false}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- validate with metadata: true or metadata: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : null, "metadata" : false}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : null, "metadata" : true}'); validate --------------------------------------------------------------------- { "ns" : "db.validatecoll", "nIndexes" : { "$numberLong" : "2" }, "indexDetails" : { "_id_" : { "valid" : true }, "index_1" : { "valid" : true } }, "valid" : true, "repaired" : false, "warnings" : [ ], "errors" : [ ], "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Invalid input options -- --validate with repair: true SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "repair" : true}'); ERROR: Running the validate command with { repair: true } is not supported yet. -- validate with repair and full SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "repair" : true}'); ERROR: Running the validate command with { repair: true } is not supported yet. -- validate with repair and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "repair" : true, "metadata" : true}'); ERROR: Running the validate command with { metadata: true } is not supported with any other options -- validate with full and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "metadata" : true}'); ERROR: Running the validate command with { metadata: true } is not supported with any other options -- validate with repair, full and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "metadata" : true, "repair" : true}'); ERROR: Running the validate command with { metadata: true } is not supported with any other options -- validate field is an object SELECT documentdb_api.validate('db','{"validate":{}}'); ERROR: Collection name contains an invalid object type conflicting_indexes.out000066400000000000000000001007421507310017400345460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET citus.next_shard_id TO 1800000; SET documentdb.next_collection_id TO 18000; SET documentdb.next_collection_index_id TO 18000; SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1.0}, "name": "idx_1"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1.1}, "name": "idx_1"}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "a" : -1, "b" : 1.1000000000000000888 }, "name" : "idx_1" }, existing index: { "v" : 2, "key" : { "a" : -1, "b" : 1 }, "name" : "idx_1" } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1", "sparse": false}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1", "unique": true}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "a" : -1, "b" : 1 }, "name" : "idx_1", "unique" : true }, existing index: { "v" : 2, "key" : { "a" : -1, "b" : 1 }, "name" : "idx_1" } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": 1, "a": -1}, "name": "idx_1", "sparse": false}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "b" : 1, "a" : -1 }, "name" : "idx_1", "sparse" : false }, existing index: { "v" : 2, "key" : { "a" : -1, "b" : 1 }, "name" : "idx_1" } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_2", "sparse": false}]}', true); ERROR: Index already exists with a different name: idx_1 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "sparse": false, "wildcardProjection": {"a": 0, "b": {"c": false}}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "wildcardProjection": {"b.c": 0, "_id": 0, "a": false, "d": false}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "b" : { "c" : false }, "_id" : false, "a" : false, "d" : false } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "a" : false, "b" : { "c" : false }, "_id" : false }, "sparse" : false } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "wildcardProjection": {"b.c": 0, "_id": 0, "d": false}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "b" : { "c" : false }, "_id" : false, "d" : false } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "a" : false, "b" : { "c" : false }, "_id" : false }, "sparse" : false } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "unique": false, "wildcardProjection": {"b.c": 0, "_id": 0, "a": false}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "unique": false, "wildcardProjection": {"b.c": true, "a": 12}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "b" : { "c" : true }, "a" : true, "_id" : false }, "unique" : false }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "a" : false, "b" : { "c" : false }, "_id" : false }, "sparse" : false } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "partialFilterExpression": {}, "wildcardProjection": {"a": 0, "b": {"c": false}}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "partialFilterExpression" : { }, "wildcardProjection" : { "a" : false, "b" : { "c" : false }, "_id" : false } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_3", "wildcardProjection" : { "a" : false, "b" : { "c" : false }, "_id" : false }, "sparse" : false } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"a": true, "b": {"c": 1, "d": 1}, "b.e": 1}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"b": {"e": 1, "d": 1, "c": 1}, "a": 5}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"a": true, "b": {"d": 1}, "b.e": 1}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_5", "wildcardProjection" : { "a" : true, "b" : { "d" : true, "e" : true }, "_id" : false }, "sparse" : false }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_5", "wildcardProjection" : { "a" : true, "b" : { "c" : true, "d" : true, "e" : true }, "_id" : false }, "sparse" : false } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_6", "sparse": false, "wildcardProjection": {"b": {"e": 1, "d": 1, "c": 1}, "a": 5}}]}', true); ERROR: Index already exists with a different name: idx_5 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"$and": [{"a": 1}, {"b": {"c": 1, "d": 1}}]}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"c": 1, "d": 1}, "a": 1}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_7", "partialFilterExpression": {"b": {"c": 1, "d": 1}, "a": 1}}]}', true); ERROR: Index already exists with a different name: idx_4 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"c": 1, "d": {"$eq": 1}}, "a": {"$eq": 1}}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "b" : { "c" : 1, "d" : { "$eq" : 1 } }, "a" : { "$eq" : 1 } } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 1 } } ] } } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"d": 1, "c": 1}, "a": 1}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "b" : { "d" : 1, "c" : 1 }, "a" : 1 } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 1 } } ] } } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"d": 1}, "b": {"c": 1}, "a": 1}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "b" : { "c" : 1 }, "a" : 1 } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 1 } } ] } } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b.d": 1, "b.c": 1, "a": 1}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "b.d" : 1, "b.c" : 1, "a" : 1 } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 1 } } ] } } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"$and": [{"a": 1}, {"b": {"c": 1, "d": 2}}]}}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 2 } } ] } }, existing index: { "v" : 2, "key" : { "$**" : 1 }, "name" : "idx_4", "partialFilterExpression" : { "$and" : [ { "a" : 1 }, { "b" : { "c" : 1, "d" : 1 } } ] } } -- none of below pairs are treated as same indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_8", "partialFilterExpression": {"$or": [{"b": {"$eq": 1}}, {"b": {"$gt": 1}}]}}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx_8", "partialFilterExpression" : { "$or" : [ { "b" : { "$eq" : 1 } }, { "b" : { "$gt" : 1 } } ] } }:Expression not supported in partial index: $or b $eq 1 b $gt 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_8", "partialFilterExpression": {"b": {"$gte": 1}}}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_9", "partialFilterExpression": {"b": {"$in": [1,2,3]}, "a": 1}}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx_9", "partialFilterExpression" : { "b" : { "$in" : [ 1, 2, 3 ] }, "a" : 1 } }:Expression not supported in partial index: b $in [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_9", "partialFilterExpression": {"b": {"$in": [2,1,3]}, "a": 1}}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx_9", "partialFilterExpression" : { "b" : { "$in" : [ 2, 1, 3 ] }, "a" : 1 } }:Expression not supported in partial index: b $in [ 2, 1, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_10", "partialFilterExpression": {"b": {"$not": {"$in": [1,2,3]}}, "a": 1}}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx_10", "partialFilterExpression" : { "b" : { "$not" : { "$in" : [ 1, 2, 3 ] } }, "a" : 1 } }:Expression not supported in partial index: $not b $in [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_10", "partialFilterExpression": {"b": {"$nin": [1,2,3]}, "a": 1}}]}', true); ERROR: Error in specification { "key" : { "$**" : 1 }, "name" : "idx_10", "partialFilterExpression" : { "b" : { "$nin" : [ 1, 2, 3 ] }, "a" : 1 } }:Expression not supported in partial index: b $nin [ 1, 2, 3 ] SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true, "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": false, "sparse": true}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : false }, existing index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true, "sparse": false}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : false, "unique" : true }, existing index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "unique" : true }, existing index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "sparse": true}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true }, existing index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_11", "unique": true, "sparse": true}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "c" : 1, "d" : 2 }, "name" : "idx_11", "sparse" : true, "unique" : true }, existing index: { "v" : 2, "key" : { "c" : 1, "d" : 1 }, "name" : "idx_11", "sparse" : true, "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_1"}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_2", "unique": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_3", "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CALL documentdb_api.drop_indexes('conflict_test', '{"dropIndexes": "collection_2", "index": {"c": 1, "d": 2}}'); ERROR: 3 indexes found for key: { "c" : 1, "d" : 2 }, identify by name instead. Conflicting indexes: { "v" : 2, "key" : { "c" : 1, "d" : 2 }, "name" : "idx_1" }, { "v" : 2, "key" : { "c" : 1, "d" : 2 }, "name" : "idx_2", "unique" : true } SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}, {"key": {"a": 1}, "name": "idx_2"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "note" : "index already exists", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"b": 1}, "name": "idx_3"}, {"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "note" : "index already exists", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}, {"key": {"a": 1}, "name": "idx_4"}]}', true); ERROR: Index already exists with a different name: idx_2 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"b": 1}, "name": "idx_4"}, {"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); ERROR: Index already exists with a different name: idx_3 -- Creating identical indexes via the same command is not allowed. .. SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}, {"key": {"k": 1}, "name": "idx_1", "unique": false, "sparse": true}]}', true); NOTICE: creating collection ERROR: Identical index already exists: idx_1 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- .. However, if the index was created via a prior command; then -- Mongo skips creating the identical index, even if it's specified -- more than once. SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}, {"key": {"k": 1}, "name": "idx_1", "unique": false, "sparse": true}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_2", "unique": true}, {"key": {"k": 1}, "name": "idx_3", "unique": true}]}', true); ERROR: Index already exists with a different name: idx_2 SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_2", "unique": true}, {"key": {"k": 1}, "name": "idx_2", "unique": false}]}', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "k" : 1 }, "name" : "idx_2", "unique" : false }, existing index: { "v" : 2, "key" : { "k" : 1 }, "name" : "idx_2", "unique" : true } create_indexes_cosmos_vector.out000066400000000000000000003265621507310017400364710ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core, documentdb_api_catalog, documentdb_api, documentdb_api_internal, public; SET citus.next_shard_id TO 91000000; SET documentdb.next_collection_id TO 91000; SET documentdb.next_collection_index_id TO 91000; SELECT documentdb_api.create_collection('db', 'create_indexes_vector'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- now you get different errors SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch"}, "name": "foo_1" } ] }', true); ERROR: Error in specification { "key" : { "a" : "cosmosSearch" }, "name" : "foo_1" }:Index type 'CosmosSearch' was requested, but the 'cosmosSearch' options were not provided. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": 1 }, "name": "foo_1", "cosmosSearchOptions": { } } ] }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "foo_1", "cosmosSearchOptions" : { } }:cosmosSearch index kind must be specified SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 1 } } ] }', true); ERROR: Error in specification { "key" : { "a" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS", "dimensions" : 1 } }:vector index must specify dimensions greater than 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS" } } ] }', true); ERROR: Error in specification { "key" : { "a" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS" } }:vector index must specify dimensions greater than 1 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "dimensions": 10 } } ] }', true); ERROR: Error in specification { "key" : { "a" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "dimensions" : 10 } }:vector index must specify similarity metric -- create a valid indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "b": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "c": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 300, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; \d documentdb_data.documents_91000 Table "documentdb_data.documents_91000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_91000" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_91001" ivfflat ((bson_extract_vector(document, 'a'::text)::vector(3)) vector_cosine_ops) WITH (lists='100') WHERE bson_extract_vector(document, 'a'::text) IS NOT NULL "documents_rum_index_91002" ivfflat ((bson_extract_vector(document, 'b'::text)::vector(3)) vector_ip_ops) WITH (lists='200') WHERE bson_extract_vector(document, 'b'::text) IS NOT NULL "documents_rum_index_91003" ivfflat ((bson_extract_vector(document, 'c'::text)::vector(3))) WITH (lists='300') WHERE bson_extract_vector(document, 'c'::text) IS NOT NULL Check constraints: "shard_key_value_check" CHECK (shard_key_value = '91000'::bigint) \d documentdb_api_catalog.index_spec_type_internal Composite type "documentdb_api_catalog.index_spec_type_internal" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- index_name | text | | | index_key | bson | | | index_pfe | bson | | | index_wp | bson | | | index_is_sparse | boolean | | | index_is_unique | boolean | | | index_version | integer | | | index_expire_after_seconds | integer | | | cosmos_search_options | bson | | | index_options | bson | | | SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "create_indexes_vector" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.create_indexes_vector", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.create_indexes_vector", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "100" }, "similarity" : "COS", "dimensions" : { "$numberInt" : "3" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.create_indexes_vector", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "b" : "cosmosSearch" }, "name" : "foo_2", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "200" }, "similarity" : "IP", "dimensions" : { "$numberInt" : "3" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.create_indexes_vector", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "c" : "cosmosSearch" }, "name" : "foo_3", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "300" }, "similarity" : "L2", "dimensions" : { "$numberInt" : "3" } } } }, "ok" : { "$numberDouble" : "1.0" } } (4 rows) SELECT documentdb_api.insert_one('db', 'create_indexes_vector', '{ "a": "some sentence", "elem": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_indexes_vector', '{ "a": "some other sentence", "elem": [8.0, 5.0, 0.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; ?column? --------------------------------------------------------------------- { "" : "some other sentence" } { "" : "some sentence" } (2 rows) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; ?column? --------------------------------------------------------------------- { "" : "some other sentence" } { "" : "some sentence" } (2 rows) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[3, 5, 2]' limit 1; ?column? --------------------------------------------------------------------- { "" : "some sentence" } (1 row) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[3, 5, 2]' DESC limit 1; ?column? --------------------------------------------------------------------- { "" : "some other sentence" } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'create_indexes_vector'); drop_primary_key --------------------------------------------------------------------- (1 row) \d documentdb_data.documents_91000; Table "documentdb_data.documents_91000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "documents_rum_index_91001" ivfflat ((bson_extract_vector(document, 'a'::text)::vector(3)) vector_cosine_ops) WITH (lists='100') WHERE bson_extract_vector(document, 'a'::text) IS NOT NULL "documents_rum_index_91002" ivfflat ((bson_extract_vector(document, 'b'::text)::vector(3)) vector_ip_ops) WITH (lists='200') WHERE bson_extract_vector(document, 'b'::text) IS NOT NULL "documents_rum_index_91003" ivfflat ((bson_extract_vector(document, 'c'::text)::vector(3))) WITH (lists='300') WHERE bson_extract_vector(document, 'c'::text) IS NOT NULL Check constraints: "shard_key_value_check" CHECK (shard_key_value = '91000'::bigint) begin; set local enable_seqscan to off; EXPLAIN(COSTS OFF) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY (documentdb_api_internal.bson_extract_vector(document, 'elem'::text)::vector(3)) <=> '[10, 1, 2]'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Sort Sort Key: (((documentdb_api_internal.bson_extract_vector(document, 'elem'::text))::vector(3) <=> '[10,1,2]'::vector)) -> Seq Scan on documents_91000_91000002 collection (8 rows) ROLLBACK; -- Create an index -- Also create a geospatial index first so that we can test these are ignore for the sort clause and only vector index is considered SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "2dsphere" }, "name": "foo_1_2ds" } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence1", "myvector": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0, 1.1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 9.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 8.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- bad queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [ 8.0, 1.0 ], "limit": 1, "path": "myvector", "numCandidates": 10 } }]}'); ERROR: expected 3 dimensions, not 2 -- correct queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 2, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } { "myvector" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" } ] } (2 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 9, 1], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "5.0" }, { "$numberDouble" : "1.1000000000000000888" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); ERROR: $vectorSearch.queryVector cannot be an empty array. -- Drop the geospatial index CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "vectorIndexColl", "index": "foo_1_2ds"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "3" } } (1 row) -- direct query that does not require rewrite SELECT document -> 'myvector' FROM documentdb_api.collection('db', 'vectorIndexColl') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'myvector') <=> documentdb_api_internal.bson_extract_vector('{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10 }', 'vector') LIMIT 1; ?column? --------------------------------------------------------------------- { "" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } (1 row) -- same index with different dimensions CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "vectorIndexColl", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 4 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. ERROR: expected 4 dimensions, not 3 CONTEXT: SQL statement "CREATE INDEX documents_rum_index_91007 ON documentdb_data.documents_91001 USING ivfflat(CAST(documentdb_api_internal.bson_extract_vector(document, 'myvector'::text) AS public.vector(4)) public.vector_cosine_ops) WITH (lists = 2) WHERE documentdb_api_internal.bson_extract_vector(document, 'myvector'::text) IS NOT NULL" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- second index on a differet path SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector2": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 4 } } ] }', true); NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0], "myvector2": [3.0, 5.0, 1.1, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "130" }, "errmsg" : "expected 3 dimensions, not 2" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0, 1], "myvector2": [3.0, 5.0, 1.1] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "130" }, "errmsg" : "expected 4 dimensions, not 3" } ] } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence1", "myvector": [3.0, 5.0, 1.1 ], "myvector2": [3.0, 5.0, 1.1, 4 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 9.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector2": [8.0, 1.0, 8.0, 8 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- query should fail SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0, 2], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); ERROR: expected 3 dimensions, not 4 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); ERROR: expected 4 dimensions, not 3 -- query should work SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9, -1], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector2" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" }, { "$numberInt" : "8" } ] } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','vectorIndexColl'); drop_primary_key --------------------------------------------------------------------- (1 row) begin; set local enable_seqscan to off; EXPLAIN(COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9, -1], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 -> Limit -> Custom Scan (DocumentDBApiQueryScan) CosmosSearch Custom Params: { "nProbes" : 2 } -> Index Scan using foo_2 on documents_91001_91000016 collection Order By: (vector(documentdb_api_internal.bson_extract_vector(document, 'myvector2'::text), 4, true) <=> '[8,1,9,-1]'::vector) (11 rows) ROLLBACK; -- check other two vector indexes SET search_path TO documentdb_api_catalog, documentdb_api, public; SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector3": "cosmosSearch" }, "name": "foo_3_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector4": "cosmosSearch" }, "name": "foo_4_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 4 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "vectorIndexColl" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.vectorIndexColl", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "myvector" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "2" }, "similarity" : "COS", "dimensions" : { "$numberInt" : "3" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.vectorIndexColl", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "myvector2" : "cosmosSearch" }, "name" : "foo_2", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "2" }, "similarity" : "COS", "dimensions" : { "$numberInt" : "4" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.vectorIndexColl", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "myvector3" : "cosmosSearch" }, "name" : "foo_3_ip", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "2" }, "similarity" : "IP", "dimensions" : { "$numberInt" : "3" } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.vectorIndexColl", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "myvector4" : "cosmosSearch" }, "name" : "foo_4_l2", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : { "$numberInt" : "2" }, "similarity" : "L2", "dimensions" : { "$numberInt" : "4" } } } }, "ok" : { "$numberDouble" : "1.0" } } (4 rows) \d documentdb_data.documents_91001; Table "documentdb_data.documents_91001" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | documentdb_core.bson | | not null | document | documentdb_core.bson | | not null | Indexes: "documents_rum_index_91008" ivfflat ((documentdb_api_internal.bson_extract_vector(document, 'myvector'::text)::vector(3)) vector_cosine_ops) WITH (lists='2') WHERE documentdb_api_internal.bson_extract_vector(document, 'myvector'::text) IS NOT NULL "documents_rum_index_91009" ivfflat ((documentdb_api_internal.bson_extract_vector(document, 'myvector2'::text)::vector(4)) vector_cosine_ops) WITH (lists='2') WHERE documentdb_api_internal.bson_extract_vector(document, 'myvector2'::text) IS NOT NULL "documents_rum_index_91010" ivfflat ((documentdb_api_internal.bson_extract_vector(document, 'myvector3'::text)::vector(3)) vector_ip_ops) WITH (lists='2') WHERE documentdb_api_internal.bson_extract_vector(document, 'myvector3'::text) IS NOT NULL "documents_rum_index_91011" ivfflat ((documentdb_api_internal.bson_extract_vector(document, 'myvector4'::text)::vector(4))) WITH (lists='2') WHERE documentdb_api_internal.bson_extract_vector(document, 'myvector4'::text) IS NOT NULL Check constraints: "shard_key_value_check" CHECK (shard_key_value = '91001'::bigint) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector3": [8.0, 1.0, 9.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector4": [8.0, 1.0, 8.0, 8 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector3", "numCandidates": 10 } }, { "$project": { "myvector3": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector3" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector4" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" }, { "$numberInt" : "8" } ] } (1 row) -- Query on a non-existent collection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorCollNonExistent", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); ERROR: The $vectorSearch needs to appear as the initial stage in the processing pipeline. -- Test vector similarity score projection [COS] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_cos", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 1, "a": "some sentence", "b": 10, "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 2, "a": "some other sentence", "b": 20, "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 3, "a": "some sentence", "b": 30, "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 4, "a": "some other sentence", "b": 40, "v": [-3, -2.0, -1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "-90740.0" } } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "14286.0" } } { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "-14286.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "-42857.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "-42857.0" } } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$project": { "rank": { "$meta": "searchScore" } } } ], "cursor": {} }'); ERROR: Search score metadata is required for this query, but it is currently unavailable SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "v": 0 }}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "-90740.0" } } (4 rows) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_cos'); drop_primary_key --------------------------------------------------------------------- (1 row) begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91002_91000037 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91002'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[-1,2,-3]'::vector))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[-1,2,-3]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[-1,2,-3]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using foo_1 on documentdb_data.documents_91002_91000037 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[-1,2,-3]'::vector) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('1'::double precision OPERATOR(pg_catalog.-) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91002_91000037 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91002'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('1'::double precision - (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using foo_1 on documentdb_data.documents_91002_91000037 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <=> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- Test vector similarity score projection [L2] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_l2", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "sim_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 4, "a": "some other sentence", "v": [-3, -2.0, -1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_l2'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "290000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "405093.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "405093.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "936002.0" } } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "489898.0" } } { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "565685.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "632456.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "632456.0" } } (4 rows) begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91003_91000050 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91003'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[-1,2,-3]'::vector)), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[-1,2,-3]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[-1,2,-3]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using sim_l2 on documentdb_data.documents_91003_91000050 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[-1,2,-3]'::vector) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91003_91000050 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91003'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<->) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using sim_l2 on documentdb_data.documents_91003_91000050 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <-> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- Test vector similarity score projection [IP] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_ip", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "sim_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 4, "a": "some other sentence", "v": [-3, -2.0, -1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_ip'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "1980000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "1580000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "1580000.0" } } { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "-1980000.0" } } (4 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "4" }, "rank" : { "$numberDouble" : "200000.0" } } { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "-200000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "-600000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "-600000.0" } } (4 rows) begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91004_91000066 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91004'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "-1.0" }, { "$numberInt" : "2" }, { "$numberDouble" : "-3.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_dollar_project(documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[-1,2,-3]'::vector))), '{ "rank" : { "$round" : [ { "$multiply" : [ { "$meta" : "searchScore" }, { "$numberInt" : "100000" } ] } ] } }'::documentdb_core.bson, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[-1,2,-3]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[-1,2,-3]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using sim_ip on documentdb_data.documents_91004_91000066 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[-1,2,-3]'::vector) (17 rows) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT documentdb_api_internal.bson_document_add_score_field(document, ('-1'::double precision OPERATOR(pg_catalog.*) (public.vector(documentdb_api_internal.bson_extract_vector(document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)))) AS document FROM (SELECT collection.document FROM documentdb_data.documents_91004_91000066 collection WHERE ((collection.shard_key_value OPERATOR(pg_catalog.=) '91004'::bigint) AND (documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) ORDER BY (public.vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<#>) public.vector(documentdb_api_internal.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::documentdb_core.bson, 'vector'::text), 3, true)) LIMIT '1'::bigint) agg_stage_0 Node: host=localhost port=58070 dbname=regression -> Subquery Scan on agg_stage_0 Output: documentdb_api_internal.bson_document_add_score_field(agg_stage_0.document, ('-1'::double precision * (vector(documentdb_api_internal.bson_extract_vector(agg_stage_0.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector))) -> Limit Output: collection.document, ((vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector)) -> Custom Scan (DocumentDBApiQueryScan) Output: collection.document, (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector) CosmosSearch Custom Params: { "nProbes" : 100 } -> Index Scan using sim_ip on documentdb_data.documents_91004_91000066 collection Output: collection.document Order By: (vector(documentdb_api_internal.bson_extract_vector(collection.document, 'v'::text), 3, true) <#> '[3,4.9,1]'::vector) (17 rows) ROLLBACK; -- ivf, Create index first and shard later SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_ivf_index_first_shard_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; ANALYZE; BEGIN; SET local client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','create_ivf_index_first_shard_later', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) END; SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } (3 rows) -- nProbes = 1, will return 1 result, the vector [3, 2, 1] is only on one shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } (1 row) COMMIT; -- nProbes = 1, will return 2 results, the vector [1, 2, 3] is on both shards BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "100000.0" } } (2 rows) COMMIT; -- nProbes = 100, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 100 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "71429.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (3 rows) COMMIT; -- ivf, Shard collection first and create index later SELECT documentdb_api.shard_collection('db','shard_first_create_ivf_index_later', '{"a":"hashed"}', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "shard_first_create_ivf_index_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } (3 rows) -- nProbes = 1, will return 1 result, the vector [3, 2, 1] is only on one shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } (1 row) COMMIT; -- nProbes = 1, will return 2 results, the vector [1, 2, 3] is on both shards BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "100000.0" } } (2 rows) COMMIT; -- nProbes = 100, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 100 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "71429.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (3 rows) COMMIT; -- hnsw, Create index first and shard later SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_hnsw_index_first_shard_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) ANALYZE; BEGIN; SET local client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','create_hnsw_index_first_shard_later', '{"a":"hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) END; SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } (3 rows) -- efSearch = 1, search [3, 2, 1] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (2 rows) COMMIT; -- efSearch = 1, search [1, 2, 3] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "100000.0" } } (2 rows) COMMIT; -- efSearch = 10, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 10 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "71429.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (3 rows) COMMIT; -- hnsw, Shard collection first and create index later SELECT documentdb_api.shard_collection('db','shard_first_create_hnsw_index_later', '{"a":"hashed"}', false); NOTICE: creating collection shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "shard_first_create_hnsw_index_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "90740.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "72409.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "72409.0" } } (3 rows) -- efSearch = 1, search [3, 2, 1] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (2 rows) COMMIT; -- efSearch = 1, search [1, 2, 3] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "100000.0" } } (2 rows) COMMIT; -- efSearch = 10, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 10 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "3" }, "rank" : { "$numberDouble" : "100000.0" } } { "_id" : { "$numberInt" : "1" }, "rank" : { "$numberDouble" : "71429.0" } } { "_id" : { "$numberInt" : "2" }, "rank" : { "$numberDouble" : "71429.0" } } (3 rows) COMMIT; -- multiple cosmosSearch indexes on a same path -- create a hnsw index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- same name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- same name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 8, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 8, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } } -- different name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: Index already exists with a different name: foo_1 -- different name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: An equivalent index already exists with a different name and options. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_2", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "COS", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } } -- different name different kind ivf SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: An equivalent index already exists with a different name and options. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_3", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } } -- create a ivf index CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "multiple_indexes", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; -- same name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "note" : "All specified indexes already exist", "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- same name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: An existing index has the same name as the requested index. When index names are not specified, they are auto generated and can cause conflicts. Please refer to our documentation. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 200, "similarity" : "COS", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS", "dimensions" : 3 } } -- different name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); ERROR: Index already exists with a different name: foo_1 -- different name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: An equivalent index already exists with a different name and options. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_2", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "IP", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS", "dimensions" : 3 } } -- different name different kind hnsw SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_4", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ERROR: An equivalent index already exists with a different name and options. Requested index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_4", "cosmosSearchOptions" : { "kind" : "vector-hnsw", "m" : 4, "efConstruction" : 16, "similarity" : "IP", "dimensions" : 3 } }, existing index: { "v" : 2, "key" : { "v" : "cosmosSearch" }, "name" : "foo_1", "cosmosSearchOptions" : { "kind" : "vector-ivf", "numLists" : 100, "similarity" : "COS", "dimensions" : 3 } } CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "multiple_indexes", "index": "foo_1"}'); retval --------------------------------------------------------------------- { "ok" : true, "nIndexesWas" : { "$numberLong" : "2" } } (1 row) cursors_basic_support.out000066400000000000000000001617711507310017400351760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6700000; SET documentdb.next_collection_id TO 6700; SET documentdb.next_collection_index_id TO 6700; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_basic'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- insert 20 documents WITH r1 AS (SELECT FORMAT('{"_id": %I, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_basic', r1.formatDoc) FROM r1; insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (20 rows) -- run the default test. -- now query them with varying page sizes using cursors. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } (3 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } (6 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 10 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } { "_id" : "14", "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } } { "_id" : "13", "a" : { "b" : { "$numberInt" : "13" }, "c" : { "$numberInt" : "13" }, "d" : [ { "$numberInt" : "13" }, { "$numberInt" : "13" } ] } } (8 rows) -- try more complex queries that should work. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } (5 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 10 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } { "_id" : "14", "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } } { "_id" : "13", "a" : { "b" : { "$numberInt" : "13" }, "c" : { "$numberInt" : "13" }, "d" : [ { "$numberInt" : "13" }, { "$numberInt" : "13" } ] } } { "_id" : "12", "a" : { "b" : { "$numberInt" : "12" }, "c" : { "$numberInt" : "12" }, "d" : [ { "$numberInt" : "12" }, { "$numberInt" : "12" } ] } } { "_id" : "11", "a" : { "b" : { "$numberInt" : "11" }, "c" : { "$numberInt" : "11" }, "d" : [ { "$numberInt" : "11" }, { "$numberInt" : "11" } ] } } (10 rows) -- add projections to this. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }') FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; document | bson_dollar_project --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } | { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } | { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" } } } (6 rows) -- try on tables that do not exist SELECT document FROM documentdb_api.collection('db', 'cursors_basic_table_dne') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic_table_dne') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- (0 rows) -- try prepared queries PREPARE q1(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4; EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 1 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } (3 rows) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } { "_id" : "14", "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } } (7 rows) -- try on tables that do not exist. EXECUTE q1('db', 'cursors_basic_table_dne', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- (0 rows) EXECUTE q1('db', 'cursors_basic_table_dne', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- (0 rows) -- queries that return no rows. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 11 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; document --------------------------------------------------------------------- (0 rows) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 25 }}'); document --------------------------------------------------------------------- (0 rows) -- Explain the queries. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 1 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.shard_key_value = '6700'::bigint) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6700'::bigint) (16 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_dollar_elemmatch(document, '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 5 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.shard_key_value = '6700'::bigint) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6700'::bigint) (16 rows) EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE ((documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_true_match($3::documentdb_core.bson)) AND ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_true_match($4::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 7 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.shard_key_value = '6700'::bigint) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6700'::bigint) (16 rows) EXPLAIN (VERBOSE ON, ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (actual rows=7 loops=1) Output: remote_scan.document Task Count: 1 Tuple data received from nodes: 427 bytes Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE ((documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_true_match($3::documentdb_core.bson)) AND ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_true_match($4::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Tuple data received from node: 427 bytes Node: host=localhost port=58070 dbname=regression -> Result (actual rows=7 loops=1) Output: document One-Time Filter: (documentdb_api_catalog.bson_true_match($3) AND documentdb_api_catalog.bson_true_match($4)) -> Custom Scan (DocumentDBApiScan) (actual rows=7 loops=1) Output: document Page Row Count: 7 rows -> Result (actual rows=8 loops=1) Output: shard_key_value, object_id, document One-Time Filter: (documentdb_api_catalog.bson_true_match($3) AND documentdb_api_catalog.bson_true_match($4)) -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection (actual rows=8 loops=1) Output: shard_key_value, object_id, document Recheck Cond: (collection.shard_key_value = '6700'::bigint) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) Heap Blocks: exact=1 -> Bitmap Index Scan on _id_ (actual rows=20 loops=1) Index Cond: (collection.shard_key_value = '6700'::bigint) (25 rows) -- explain with projection (projection happens in the custom scan.) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }') FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.bson_dollar_project Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AS bson_dollar_project FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_dollar_elemmatch(document, '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) Page Row Count: 5 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.shard_key_value = '6700'::bigint) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (collection.shard_key_value = '6700'::bigint) (16 rows) -- do a primary key scan. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$gt": "10" } }'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } (5 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$gt": "10" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND ((document OPERATOR(documentdb_api_catalog.#>) '{ "_id" : "10" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.>) '{ "" : "10" }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 5 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: ((collection.shard_key_value = '6700'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "10" }'::documentdb_core.bson)) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "_id" : "10" }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: ((collection.shard_key_value = '6700'::bigint) AND (collection.object_id OPERATOR(documentdb_core.>) '{ "" : "10" }'::documentdb_core.bson)) (16 rows) -- do a primary key lookup SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$eq": "10" } }'; document --------------------------------------------------------------------- { "_id" : "10", "a" : { "b" : { "$numberInt" : "10" }, "c" : { "$numberInt" : "10" }, "d" : [ { "$numberInt" : "10" }, { "$numberInt" : "10" } ] } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$eq": "10" } }'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND ((document OPERATOR(documentdb_api_catalog.#=) '{ "_id" : "10" }'::documentdb_core.bsonquery) AND (object_id OPERATOR(documentdb_core.=) '{ "" : "10" }'::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 5 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: ((collection.shard_key_value = '6700'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "10" }'::documentdb_core.bson)) Filter: documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: ((collection.shard_key_value = '6700'::bigint) AND (collection.object_id OPERATOR(documentdb_core.=) '{ "" : "10" }'::documentdb_core.bson)) (16 rows) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_basic'); drop_primary_key --------------------------------------------------------------------- (1 row) -- validate seq scan works. EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 1 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } (3 rows) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 11 }', '{ "a.b": { "$gt": 12 }}'); document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } { "_id" : "14", "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } } { "_id" : "13", "a" : { "b" : { "$numberInt" : "13" }, "c" : { "$numberInt" : "13" }, "d" : [ { "$numberInt" : "13" }, { "$numberInt" : "13" } ] } } (8 rows) -- queries that return no rows. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; document --------------------------------------------------------------------- (0 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 11 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; document --------------------------------------------------------------------- (0 rows) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 25 }}'); document --------------------------------------------------------------------- (0 rows) -- Explain the queries. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 1 rows -> Tid Range Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (14 rows) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_dollar_elemmatch(document, '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 5 rows -> Tid Range Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@#?) '{ "a.d" : { "$gt" : { "$numberInt" : "2" } } }'::documentdb_core.bson)) (14 rows) EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE ((documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND documentdb_api_catalog.bson_true_match($3::documentdb_core.bson)) AND ((document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND documentdb_api_catalog.bson_true_match($4::documentdb_core.bson)) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 7 rows -> Tid Range Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (14 rows) -- now create an index on a.b and a.d SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('cursors_basic', 'index_1', '{"a.b": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('cursors_basic', 'index_2', '{"a.d": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) BEGIN; set local enable_seqscan TO OFF; -- now query them with varying page sizes using cursors - this will convert to a bitmap scan (as it's an index scan). SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 1 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) Filter: documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (16 rows) ROLLBACK; BEGIN; set local enable_seqscan TO OFF; set local enable_indexscan TO OFF; -- now query them with varying page sizes using cursors - this should work as a normal bitmap heap scan. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 1 rows -> Bitmap Heap Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document Recheck Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) Filter: documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) -> Bitmap Index Scan on index_1 Index Cond: (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson) (16 rows) ROLLBACK; -- ensure parallel scans don't impact this. DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'cursors_basic'; EXECUTE format('ALTER TABLE documentdb_data.documents_%s SET (parallel_workers = 1)', v_collection_id); END $$; BEGIN; set local parallel_tuple_cost TO 0; set local parallel_setup_cost TO 0; set local enable_seqscan TO ON; set local enable_indexscan TO OFF; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document Task Count: 1 Tasks Shown: All -> Task Query: SELECT document FROM documentdb_data.documents_6700_6700003 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6700'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document Page Row Count: 1 rows -> Tid Range Scan on documentdb_data.documents_6700_6700003 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "2" } }'::documentdb_core.bson)) (14 rows) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) ROLLBACK; -- invalid cursor scans PREPARE q2(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4 ORDER BY bson_orderby(document, '{ "a": 1 }'); EXECUTE q2('db', 'cursors_basic', '{}', '{}'); ERROR: Having continuations not supported for this type of query DEALLOCATE q2; -- creates projectSet - not allowed. SET client_min_messages TO ERROR; PREPARE q2(text, text, bson, bson) AS SELECT bson_dollar_unwind(document, '{ "$a": 1 }') FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4; EXECUTE q2('db', 'cursors_basic', '{}', '{}'); ERROR: Unsupported combination of query with streaming cursors RESET client_min_messages; DEALLOCATE q2; PREPARE q2(text, text, bson, bson) AS SELECT bson_dollar_project(document, '{ "a": 1 }') FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4 OFFSET 1; EXECUTE q2('db', 'cursors_basic', '{}', '{}'); ERROR: Found unsupported limit for stream cursors with offset DEALLOCATE q2; -- now create many CTEs of Project/Filter/Project PREPARE q2(text, text, bson) AS WITH r1 AS (SELECT bson_dollar_project(document, '{ "a": 1, "d": "$a.b" }') AS document, current_cursor_state(document) AS cursorState FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ '{ "_id": { "$exists": true } }'), r2 AS (SELECT bson_dollar_add_fields(document, '{ "c": 4 }') AS document, cursorState FROM r1 WHERE document @@ '{ "d": 1 }'), r3 AS (SELECT bson_dollar_project(document, '{ "_id": 0 }') AS document, cursorState FROM r2 WHERE document @@ '{ "c": 4 }'), r4 AS (SELECT bson_dollar_add_fields(document, '{ "e.f": "foo" }') AS document, cursorState FROM r3), r5 AS (SELECT document, cursorState FROM r4 WHERE document @@ '{ "e.f" : "foo" }') SELECT * FROM r5; EXECUTE q2('db', 'cursors_basic', '{}'); document | cursorstate --------------------------------------------------------------------- { "a" : { "b" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "1" }, "d" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] }, "d" : { "$numberInt" : "1" }, "c" : { "$numberInt" : "4" }, "e" : { "f" : "foo" } } | { "table_name" : "documents_6700_6700003", "value" : { "$binary" : { "base64" : "AAAAABQA", "subType" : "00" } } } (1 row) EXECUTE q2('db', 'cursors_non_existent', '{}'); document | cursorstate --------------------------------------------------------------------- (0 rows) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/cursors_seqscan.out000066400000000000000000000661551507310017400340350ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6710000; SET documentdb.next_collection_id TO 6710; SET documentdb.next_collection_index_id TO 6710; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_seqscan'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- insert 20 documents WITH r1 AS (SELECT FORMAT('{"_id": %I, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan', r1.formatDoc) FROM r1; insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (20 rows) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_seqscan'); drop_primary_key --------------------------------------------------------------------- (1 row) -- limit it by batchSize SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; ERROR: both batchSizeHint and batchSizeAttr must be set - or neither SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 100 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; ERROR: both batchSizeHint and batchSizeAttr must be set - or neither -- specify getpage_batchSizeAttr SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 1, "getpage_batchSizeAttr": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | length --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | 61 (1 row) SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 100, "getpage_batchSizeAttr": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | length --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | 61 { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | 61 (2 rows) -- run the default test. -- now query them with varying page sizes using cursors. SELECT document FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (1 row) SELECT document FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } (3 rows) -- query with page sizes and get cursor state. SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } (3 rows) SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 7 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAYA", "subType" : "00" } } } { "_id" : "14", "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAcA", "subType" : "00" } } } (7 rows) -- query with page sizes, projection and get cursor state. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | bson_dollar_project | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } | { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } (5 rows) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | bson_dollar_project | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } (3 rows) -- now test resume from continuation SELECT document, current_cursor_state(document) AS cursor1 INTO TEMPORARY d1 FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT r2 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r2 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], cursor1) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r2 \gset -- print the continuation \echo :r2 '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } ] }' -- now run the query with the continuation. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; document | bson_dollar_project | current_cursor_state --------------------------------------------------------------------- { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } | { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } | { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAYA", "subType" : "00" } } } (3 rows) EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.bson_dollar_project, remote_scan.current_cursor_state Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AS bson_dollar_project, documentdb_api_internal.current_cursor_state(document) AS current_cursor_state FROM documentdb_data.documents_6710_6710001 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6710'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson), documentdb_api_internal.current_cursor_state(document) Page Row Count: 3 rows Continuation: { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } -> Tid Range Scan on documentdb_data.documents_6710_6710001 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,3)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bson)) (15 rows) -- now try with multi-continuation with a different table SELECT r3 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r3 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], '{ "table_name": "someOtherTable" }'::bson) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r3 \gset -- print the continuation \echo :r3 '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }' -- now run the query with the continuation (Should have no continuation). SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; document | bson_dollar_project | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } (3 rows) EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.bson_dollar_project, remote_scan.current_cursor_state Task Count: 1 Tasks Shown: All -> Task Query: SELECT document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AS bson_dollar_project, documentdb_api_internal.current_cursor_state(document) AS current_cursor_state FROM documentdb_data.documents_6710_6710001 collection WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bsonquery) AND (shard_key_value OPERATOR(pg_catalog.=) '6710'::bigint)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson), documentdb_api_internal.current_cursor_state(document) Page Row Count: 3 rows -> Tid Range Scan on documentdb_data.documents_6710_6710001 collection Output: shard_key_value, object_id, document TID Cond: (collection.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(collection.document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }'::documentdb_core.bson) AND (collection.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bson)) (14 rows) -- run with remote execution set citus.enable_local_execution to off; SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; document | current_cursor_state --------------------------------------------------------------------- { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } (3 rows) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; document | bson_dollar_project | current_cursor_state --------------------------------------------------------------------- { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } } | { "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } } | { "_id" : "15", "a" : { "b" : { "$numberInt" : "15" } } } | { "table_name" : "documents_6710_6710001", "value" : { "$binary" : { "base64" : "AAAAAAYA", "subType" : "00" } } } (3 rows) cursors_seqscan_sharded.out000066400000000000000000001142221507310017400354350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6720000; SET documentdb.next_collection_id TO 6720; SET documentdb.next_collection_index_id TO 6720; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_seqscan_sharded'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.shard_collection('db', 'cursors_seqscan_sharded', '{ "sh": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- insert 20 documents in shard key 1 WITH r1 AS (SELECT FORMAT('{"_id": %I, "sh": 1, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan_sharded', r1.formatDoc) FROM r1; insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (20 rows) -- insert 20 documents in shard key 2 WITH r1 AS (SELECT FORMAT('{"_id": %I, "sh": 2, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan_sharded', r1.formatDoc) FROM r1; insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (20 rows) \d documentdb_data.documents_6720 Table "documentdb_data.documents_6720" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_6720" PRIMARY KEY, btree (shard_key_value, object_id) "documents_rum_index_6721" documentdb_rum (document bson_rum_single_path_ops (path=_id, tl='2699')) Check constraints: "shard_key_value_check" CHECK (shard_key_value = get_shard_key_value('{ "sh" : "hashed" }'::bson, 6720::bigint, document)) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_seqscan_sharded'); drop_primary_key --------------------------------------------------------------------- (1 row) -- run the default test. -- now query them with varying page sizes using cursors. SELECT * FROM execute_and_sort($$SELECT object_id, document::text FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (2 rows) SELECT * FROM execute_and_sort($$SELECT object_id, document::text FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } (6 rows) -- query with page sizes and get cursor state. SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' || current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (6 rows) SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' || current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 7 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "14", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAcA", "subType" : "00" } } } { "_id" : "14", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "14" }, "c" : { "$numberInt" : "14" }, "d" : [ { "$numberInt" : "14" }, { "$numberInt" : "14" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAcA", "subType" : "00" } } } { "_id" : "15", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAYA", "subType" : "00" } } } { "_id" : "15", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "15" }, "c" : { "$numberInt" : "15" }, "d" : [ { "$numberInt" : "15" }, { "$numberInt" : "15" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAYA", "subType" : "00" } } } { "_id" : "16", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } { "_id" : "16", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } { "_id" : "17", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "17", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (14 rows) -- query with page sizes, projection and get cursor state. SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', dollarProject:' || bson_dollar_project(document, '{ "a.b": 1 }')::text as document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "16", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } }, dollarProject:{ "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } { "_id" : "16", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "16" }, "c" : { "$numberInt" : "16" }, "d" : [ { "$numberInt" : "16" }, { "$numberInt" : "16" } ] } }, dollarProject:{ "_id" : "16", "a" : { "b" : { "$numberInt" : "16" } } } { "_id" : "17", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } }, dollarProject:{ "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } { "_id" : "17", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } }, dollarProject:{ "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, dollarProject:{ "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, dollarProject:{ "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, dollarProject:{ "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, dollarProject:{ "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, dollarProject:{ "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, dollarProject:{ "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } (10 rows) SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', dollarProject:' || bson_dollar_project(document, '{ "a.b": 1 }')::text as document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, dollarProject:{ "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, dollarProject:{ "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, dollarProject:{ "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, dollarProject:{ "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, dollarProject:{ "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, dollarProject:{ "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } (6 rows) -- now test resume from continuation SELECT document, current_cursor_state(document) AS cursor1 INTO TEMPORARY d1 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT r2 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r2 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], cursor1) AS "continuation" FROM d1 ORDER BY document -> 'sh', document-> '_id' OFFSET 2 LIMIT 1 ) rec) r2 \gset -- print the continuation \echo :r2 '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } ] }' -- now run the query with the continuation. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d2 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d2 order by document -> '_id'; document | bson_dollar_project | bson_dollar_project --------------------------------------------------------------------- { "_id" : "17", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.bson_dollar_project, remote_scan.current_cursor_state Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AS bson_dollar_project, documentdb_api_internal.current_cursor_state(document) AS current_cursor_state FROM documentdb_data.documents_6720_6720016 documents_6720 WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bsonquery)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson), documentdb_api_internal.current_cursor_state(document) Page Row Count: 3 rows -> Tid Range Scan on documentdb_data.documents_6720_6720016 documents_6720 Output: shard_key_value, object_id, document TID Cond: (documents_6720.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(documents_6720.document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } ] }'::documentdb_core.bson) AND (documents_6720.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bson)) (14 rows) -- now try with multi-continuation with a different table SELECT r3 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r3 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], '{ "table_name": "someOtherTable" }'::bson) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r3 \gset -- print the continuation \echo :r3 '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }' -- now run the query with the continuation (Should have no continuation). SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d3 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d3 order by document -> '_id'; document | bson_dollar_project | bson_dollar_project --------------------------------------------------------------------- { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (6 rows) EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Output: remote_scan.document, remote_scan.bson_dollar_project, remote_scan.current_cursor_state Task Count: 8 Tasks Shown: One of 8 -> Task Query: SELECT document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson) AS bson_dollar_project, documentdb_api_internal.current_cursor_state(document) AS current_cursor_state FROM documentdb_data.documents_6720_6720016 documents_6720 WHERE (documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.#>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bsonquery)) Node: host=localhost port=58070 dbname=regression -> Custom Scan (DocumentDBApiScan) Output: document, documentdb_api_catalog.bson_dollar_project(document, '{ "a.b" : { "$numberInt" : "1" } }'::documentdb_core.bson), documentdb_api_internal.current_cursor_state(document) Page Row Count: 3 rows -> Tid Range Scan on documentdb_data.documents_6720_6720016 documents_6720 Output: shard_key_value, object_id, document TID Cond: (documents_6720.ctid >= '(0,0)'::tid) Filter: (documentdb_api_internal.cursor_state(documents_6720.document, '{ "getpage_batchCount" : { "$numberInt" : "3" }, "continuation" : [ { "table_name" : "someOtherTable" } ] }'::documentdb_core.bson) AND (documents_6720.document OPERATOR(documentdb_api_catalog.@>) '{ "a.b" : { "$numberInt" : "12" } }'::documentdb_core.bson)) (14 rows) -- run with remote execution set citus.enable_local_execution to off; SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' ||current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); document --------------------------------------------------------------------- { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720017", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } }, cursurState:{ "table_name" : "documents_6720_6720023", "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (6 rows) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d4 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d4 order by document -> '_id'; document | bson_dollar_project | bson_dollar_project --------------------------------------------------------------------- { "_id" : "17", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "17" }, "c" : { "$numberInt" : "17" }, "d" : [ { "$numberInt" : "17" }, { "$numberInt" : "17" } ] } } | { "_id" : "17", "a" : { "b" : { "$numberInt" : "17" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAQA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "18", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "18" }, "c" : { "$numberInt" : "18" }, "d" : [ { "$numberInt" : "18" }, { "$numberInt" : "18" } ] } } | { "_id" : "18", "a" : { "b" : { "$numberInt" : "18" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAMA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "19", "sh" : { "$numberInt" : "1" }, "a" : { "b" : { "$numberInt" : "19" }, "c" : { "$numberInt" : "19" }, "d" : [ { "$numberInt" : "19" }, { "$numberInt" : "19" } ] } } | { "_id" : "19", "a" : { "b" : { "$numberInt" : "19" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAIA", "subType" : "00" } } } { "_id" : "20", "sh" : { "$numberInt" : "2" }, "a" : { "b" : { "$numberInt" : "20" }, "c" : { "$numberInt" : "20" }, "d" : [ { "$numberInt" : "20" }, { "$numberInt" : "20" } ] } } | { "_id" : "20", "a" : { "b" : { "$numberInt" : "20" } } } | { "value" : { "$binary" : { "base64" : "AAAAAAEA", "subType" : "00" } } } (6 rows) documentdb_distributed_setup.out000066400000000000000000000141001507310017400364660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA IF NOT EXISTS documentdb_distributed_test_helpers; SELECT datname, datcollate, datctype, pg_encoding_to_char(encoding), datlocprovider FROM pg_database; datname | datcollate | datctype | pg_encoding_to_char | datlocprovider --------------------------------------------------------------------- postgres | en_US.UTF-8 | en_US.UTF-8 | UTF8 | c regression | en_US.UTF-8 | en_US.UTF-8 | UTF8 | c template1 | en_US.UTF-8 | en_US.UTF-8 | UTF8 | c template0 | en_US.UTF-8 | en_US.UTF-8 | UTF8 | c (4 rows) CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.latest_documentdb_distributed_version() RETURNS text LANGUAGE plpgsql AS $fn$ DECLARE v_latest_version text; BEGIN WITH cte AS (SELECT version from pg_available_extension_versions WHERE name='documentdb_distributed'), cte2 AS (SELECT r[1]::integer as r1, r[2]::integer as r2, r[3]::integer as r3, COALESCE(r[4]::integer,0) as r4, version FROM cte, regexp_matches(version,'([0-9]+)\.([0-9]+)-([0-9]+)\.?([0-9]+)?','') r ORDER BY r1 DESC, r2 DESC, r3 DESC, r4 DESC LIMIT 1) SELECT version INTO v_latest_version FROM cte2; RETURN v_latest_version; END; $fn$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.create_latest_extension(p_cascade bool default false) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE v_latest_version text; BEGIN SELECT documentdb_distributed_test_helpers.latest_documentdb_distributed_version() INTO v_latest_version; IF p_cascade THEN EXECUTE format($$CREATE EXTENSION documentdb_distributed WITH VERSION '%1$s' CASCADE$$, v_latest_version); ELSE EXECUTE format($$CREATE EXTENSION documentdb_distributed WITH VERSION '%1$s'$$, v_latest_version); END IF; CREATE TABLE IF NOT EXISTS documentdb_data.changes ( /* Catalog ID of the collection to which this change belongs to */ collection_id bigint not null, /* derived shard key field of the document that changed */ shard_key_value bigint not null, /* object ID of the document that was changed */ object_id documentdb_core.bson not null, PRIMARY KEY(shard_key_value, object_id) ); END; $fn$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.upgrade_extension(target_version text) RETURNS void AS $$ DECLARE ran_upgrade_script bool; BEGIN IF target_version IS NULL THEN SELECT documentdb_distributed_test_helpers.latest_documentdb_distributed_version() INTO target_version; END IF; SET citus.enable_ddl_propagation = off; EXECUTE format($cmd$ ALTER EXTENSION documentdb_distributed UPDATE to %L $cmd$, target_version); EXECUTE format($cmd$ ALTER EXTENSION documentdb UPDATE to %L $cmd$, target_version); EXECUTE format($cmd$ ALTER EXTENSION documentdb_core UPDATE to %L $cmd$, target_version); IF target_version = '1.0-4.1' THEN SET client_min_messages TO WARNING; PERFORM documentdb_api_distributed.complete_upgrade(); SET client_min_messages TO DEFAULT; END IF; IF target_version IS NULL OR target_version > '1.0-4.1' THEN SET client_min_messages TO WARNING; SELECT documentdb_api_distributed.complete_upgrade() INTO ran_upgrade_script; SET client_min_messages TO DEFAULT; RAISE NOTICE 'Ran Upgrade Script: %', ran_upgrade_script; END IF; END; $$ language plpgsql; -- The schema version should NOT match the binary version SELECT extversion FROM pg_extension WHERE extname = 'documentdb_distributed' \gset -- Check if recreating the extension works DROP EXTENSION IF EXISTS documentdb_distributed CASCADE; DROP EXTENSION IF EXISTS documentdb CASCADE; NOTICE: drop cascades to extension documentdb_extended_rum DROP EXTENSION IF EXISTS documentdb_core CASCADE; -- Install the latest available documentdb_distributed version SELECT documentdb_distributed_test_helpers.create_latest_extension(p_cascade => TRUE); NOTICE: installing required extension "documentdb_core" NOTICE: installing required extension "documentdb" create_latest_extension --------------------------------------------------------------------- (1 row) -- The schema version now should match the binary version SELECT extversion FROM pg_extension WHERE extname = 'documentdb_distributed' \gset SELECT documentdb_api_distributed.initialize_cluster(); NOTICE: Copying data from local table... NOTICE: copying the data has completed DETAIL: The local data in the table is no longer visible, but is still on disk. HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$documentdb_api_distributed.documentdb_cluster_data$$) NOTICE: column "view_definition" of relation "collections" already exists, skipping NOTICE: column "view_definition" of relation "collections_102008" already exists, skipping NOTICE: Invalidating cached cluster version data NOTICE: column "validator" of relation "collections" already exists, skipping NOTICE: column "validation_level" of relation "collections" already exists, skipping NOTICE: column "validation_action" of relation "collections" already exists, skipping NOTICE: column "validator" of relation "collections_102008" already exists, skipping NOTICE: column "validation_level" of relation "collections_102008" already exists, skipping NOTICE: column "validation_action" of relation "collections_102008" already exists, skipping NOTICE: column "user_oid" of relation "documentdb_index_queue" already exists, skipping NOTICE: column "user_oid" of relation "documentdb_index_queue_102019" already exists, skipping NOTICE: Invalidating cached cluster version data initialize_cluster --------------------------------------------------------------------- (1 row) -- Call initialize again (just to ensure idempotence) SELECT documentdb_api_distributed.initialize_cluster(); NOTICE: Initialize: version is up-to-date. Skipping initialize_cluster initialize_cluster --------------------------------------------------------------------- (1 row) GRANT documentdb_admin_role TO current_user; -- install documentdb_extended_rum CREATE EXTENSION documentdb_extended_rum; GRANT USAGE ON SCHEMA documentdb_extended_rum_catalog TO documentdb_admin_role; documentdb_distributed_test_helpers.out000066400000000000000000000336611507310017400400440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA IF NOT EXISTS documentdb_distributed_test_helpers; NOTICE: schema "documentdb_distributed_test_helpers" already exists, skipping SELECT citus_set_coordinator_host('localhost', current_setting('port')::integer); citus_set_coordinator_host --------------------------------------------------------------------- (1 row) SELECT citus_set_node_property('localhost', current_setting('port')::integer, 'shouldhaveshards', true); citus_set_node_property --------------------------------------------------------------------- (1 row) /* see the comment written for its definition at create_indexes.c */ CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.generate_create_index_arg( p_collection_name text, p_index_name text, p_index_key documentdb_core.bson) RETURNS documentdb_core.bson LANGUAGE C STRICT AS 'pg_documentdb', $$generate_create_index_arg$$; -- Returns the command (without "CONCURRENTLY" option) used to create given -- documentdb index on given collection. CREATE FUNCTION documentdb_distributed_test_helpers.documentdb_index_get_pg_def( p_database_name text, p_collection_name text, p_index_name text) RETURNS SETOF TEXT AS $$ BEGIN RETURN QUERY SELECT pi.indexdef FROM documentdb_api_catalog.collection_indexes mi, documentdb_api_catalog.collections mc, pg_indexes pi WHERE mc.database_name = p_database_name AND mc.collection_name = p_collection_name AND (mi.index_spec).index_name = p_index_name AND mi.collection_id = mc.collection_id AND pi.indexname = concat('documents_rum_index_', index_id::text) AND pi.schemaname = 'documentdb_data'; END; $$ LANGUAGE plpgsql; -- query documentdb_api_catalog.collection_indexes for given collection CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.get_collection_indexes( p_database_name text, p_collection_name text, OUT collection_id bigint, OUT index_id integer, OUT index_spec_as_bson documentdb_core.bson, OUT index_is_valid bool) RETURNS SETOF RECORD AS $$ BEGIN RETURN QUERY SELECT mi.collection_id, mi.index_id, documentdb_api_internal.index_spec_as_bson(mi.index_spec), mi.index_is_valid FROM documentdb_api_catalog.collection_indexes AS mi WHERE mi.collection_id = (SELECT mc.collection_id FROM documentdb_api_catalog.collections AS mc WHERE collection_name = p_collection_name AND database_name = p_database_name); END; $$ LANGUAGE plpgsql; -- query pg_index for the documents table backing given collection CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.get_data_table_indexes ( p_database_name text, p_collection_name text) RETURNS TABLE (LIKE pg_index) AS $$ DECLARE v_collection_id bigint; v_data_table_name text; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = p_collection_name AND database_name = p_database_name; v_data_table_name := format('documentdb_data.documents_%s', v_collection_id); RETURN QUERY SELECT * FROM pg_index WHERE indrelid = v_data_table_name::regclass; END; $$ LANGUAGE plpgsql; -- count collection indexes grouping by "pg_index.indisprimary" attr CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.count_collection_indexes( p_database_name text, p_collection_name text) RETURNS TABLE ( index_type_is_primary boolean, index_type_count bigint ) AS $$ BEGIN RETURN QUERY SELECT indisprimary, COUNT(*) FROM pg_index WHERE indrelid = (SELECT ('documentdb_data.documents_' || collection_id::text)::regclass FROM documentdb_api_catalog.collections WHERE database_name = p_database_name AND collection_name = p_collection_name) GROUP BY indisprimary; END; $$ LANGUAGE plpgsql; -- function to mask variable plan id from the explain output of a distributed subplan CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan(explain_command text, out query_plan text) RETURNS SETOF TEXT AS $$ BEGIN FOR query_plan IN EXECUTE explain_command LOOP IF query_plan ILIKE '%Distributed Subplan %_%' THEN RETURN QUERY SELECT REGEXP_REPLACE(query_plan,'[[:digit:]]+','X', 'g'); ELSE RETURN next; END IF; END LOOP; RETURN; END; $$ language plpgsql; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.drop_primary_key(p_database_name text, p_collection_name text) RETURNS void AS $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = p_database_name AND collection_name = p_collection_name; DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_key operator(documentdb_core.=) '{"_id": 1}' AND collection_id = v_collection_id; EXECUTE format('ALTER TABLE documentdb_data.documents_%s DROP CONSTRAINT collection_pk_%s', v_collection_id, v_collection_id); END; $$ LANGUAGE plpgsql; -- Function to avoid flakiness of a SQL query typically on a sharded multi-node collection. -- One way to fix such falkiness is to add an order by clause to inject determinism, but -- many queryies like cursors don't support order by. This test function bridges that gap -- by storing the result of such queries in a TEMP table and then ordering the entries in the -- temp table. One caveat is that the sql query in the argument is expacted to have exact two -- columns object_id, and document. This seems to be sufficient for now for our use cases. -- If the caller wants to project multiple columns, thaey can be concatenated as aliased as 'document' CREATE OR REPLACE FUNCTION execute_and_sort(p_sql TEXT) RETURNS TABLE (document text) AS $$ BEGIN EXECUTE 'CREATE TEMP TABLE temp_dynamic_results ON COMMIT DROP AS ' || p_sql; RETURN QUERY EXECUTE 'SELECT document FROM temp_dynamic_results ORDER BY object_id'; EXECUTE 'DROP TABLE temp_dynamic_results'; END; $$ LANGUAGE plpgsql; -- This method mimics how the 2d index extract the geometries from `p_document` from `p_keyPath` -- This function expects the geospatial data in form of legacy coordinate pairs (longitude, latitude). -- returns the 2d flat geometry in form of public.geometry. -- -- This function does strict validation of the values at path for geometry formats and -- checks for valid points and multipoints input format and throws -- error if not valid and only is applicable for creating the geospatial index and control -- insert behaviors for invalid geodetic data points. -- -- example scenario with the reference implementation: -- - db.coll.createIndex({loc: "2dsphere"}); -- -- - db.insert({loc: [10, 'text']}); => This throws error -- -- - db.insert({non-loc: [10, 'text']}) => This is normal insert as no 2d index CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.bson_extract_geometry( p_document documentdb_core.bson, p_keyPath text) RETURNS public.geometry LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'pg_documentdb', $function$bson_extract_geometry$function$; -- This method mimics how the runtime extract the geometries from `p_document` from `p_keyPath` -- This is similar to bson_extract_geometry function but -- it performs a `weak` validation and doesn't throw error in case where the `bson_extract_geometry` function may throw error -- e.g. scenarios with the reference implementation: -- - db.coll.insert({loc: [[10, 20], [30, 40], ["invalid"]]}); (without 2d index on 'loc') -- - db.coll.find({loc: {$geoWithin: { $box: [[30, 30], [40, 40]] }}}) -- -- The above find should match the object if any of the point (in multikey point case) matches the -- geospatial query. CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.bson_extract_geometry_runtime( p_document documentdb_core.bson, p_keyPath text) RETURNS public.geometry LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'pg_documentdb', $function$bson_extract_geometry_runtime$function$; -- This is a helper for create_indexes_background. It performs the submission of index requests in background and wait for their completion. CREATE OR REPLACE PROCEDURE documentdb_distributed_test_helpers.create_indexes_background(IN p_database_name text, IN p_index_spec documentdb_core.bson, IN p_log_index_queue boolean DEFAULT false, INOUT retVal documentdb_core.bson DEFAULT null, INOUT ok boolean DEFAULT false) AS $procedure$ DECLARE create_index_response record; check_build_index_status record; completed boolean := false; indexRequest text; index_cmd_stored text; BEGIN SET search_path TO documentdb_core,documentdb_api; SELECT * INTO create_index_response FROM documentdb_api.create_indexes_background(p_database_name, p_index_spec); IF p_log_index_queue THEN SELECT string_agg(index_cmd, ',') into index_cmd_stored FROM documentdb_api_catalog.documentdb_index_queue; RAISE INFO 'Index Queue Commands: %', index_cmd_stored; END IF; COMMIT; IF create_index_response.ok THEN SELECT create_index_response.requests->>'indexRequest' INTO indexRequest; IF indexRequest IS NOT NULL THEN LOOP SELECT * INTO check_build_index_status FROM documentdb_api_internal.check_build_index_status(create_index_response.requests); IF check_build_index_status.ok THEN completed := check_build_index_status.complete; IF completed THEN ok := create_index_response.ok; retVal := create_index_response.retval; RETURN; END IF; ELSE ok := check_build_index_status.ok; retVal := check_build_index_status.retval; RETURN; END IF; COMMIT; -- COMMIT so that CREATE INDEX CONCURRENTLY does not wait for documentdb_distributed_test_helpers.create_indexes_background PERFORM pg_sleep_for('100 ms'); END LOOP; ELSE ok := create_index_response.ok; retVal := create_index_response.retval; RETURN; END IF; ELSE ok := create_index_response.ok; retVal := create_index_response.retval; END IF; END; $procedure$ LANGUAGE plpgsql; -- This is a helper function to evaluate expressions for testing purposes. -- This is used by backend tests to validate functionality of comparisons. CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.evaluate_query_expression(expression documentdb_core.bson, value documentdb_core.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS '$libdir/pg_documentdb.so', $function$command_evaluate_query_expression$function$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.evaluate_expression_get_first_match(expression documentdb_core.bson, value documentdb_core.bson) RETURNS documentdb_core.bson LANGUAGE c IMMUTABLE STRICT AS '$libdir/pg_documentdb.so', $function$command_evaluate_expression_get_first_match$function$; -- Wait for the background worker to be launched in the `regression` database -- When the extension is loaded, this isn't created yet. CREATE OR REPLACE PROCEDURE documentdb_distributed_test_helpers.wait_for_background_worker() AS $$ DECLARE v_bg_worker_app_name text := NULL; BEGIN LOOP SELECT application_name INTO v_bg_worker_app_name FROM pg_stat_activity WHERE application_name = 'documentdb_bg_worker_leader'; IF v_bg_worker_app_name IS NOT NULL THEN RETURN; END IF; COMMIT; -- This is needed so that we grab a fresh snapshot of pg_stat_activity PERFORM pg_sleep_for('100 ms'); END LOOP; END $$ LANGUAGE plpgsql; CALL documentdb_distributed_test_helpers.wait_for_background_worker(); -- validate background worker is launched SELECT application_name FROM pg_stat_activity WHERE application_name = 'documentdb_bg_worker_leader'; application_name --------------------------------------------------------------------- documentdb_bg_worker_leader (1 row) -- create a single table in the 'db' database so that existing tests don't change behavior (yet) set documentdb.enableNativeColocation to off; SELECT documentdb_api.create_collection('db', 'firstCollection'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) set documentdb.enableNativeColocation to on; SELECT documentdb_api.create_collection('db', 'secondCollection'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( document documentdb_core.bson, path text, isWildcard bool, generateNotFoundTerm bool default false, addMetadata bool default false, indexTermSizeLimit int default -1, enableReducedWildcardTerms bool default false) RETURNS SETOF documentdb_core.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'pg_documentdb', $$gin_bson_get_single_path_generated_terms$$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms( document documentdb_core.bson, pathSpec text, isExclusion bool, includeId bool, addMetadata bool default false, indexTermSizeLimit int default -1) RETURNS SETOF documentdb_core.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'pg_documentdb', $$gin_bson_get_wildcard_project_generated_terms$$; CREATE FUNCTION documentdb_distributed_test_helpers.get_feature_counter_pretty(p_reset_counter bool) RETURNS SETOF json AS $$ BEGIN RETURN QUERY SELECT row_to_json(result) FROM ( SELECT coalesce(json_agg(json_build_object(feature_name, usage_count)), '[]'::json) AS "Feature_usage" FROM documentdb_api_internal.command_feature_counter_stats(p_reset_counter) ) result; END; $$ LANGUAGE plpgsql; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/feature_counters.out000066400000000000000000001574251507310017400341760ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_core, documentdb_api, public; SET citus.next_shard_id TO 6750000; SET documentdb.next_collection_id TO 67500; SET documentdb.next_collection_index_id TO 67500; -- Reset the counters by making a call to the counter and discarding the results select count(*)*0 as count from documentdb_api_internal.command_feature_counter_stats(true); count --------------------------------------------------------------------- 0 (1 row) -- vector index creation error SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": "cosmosSearch"}, "name": "foo_1" } ] }', true); ERROR: Error in specification { "key" : { "a" : "cosmosSearch" }, "name" : "foo_1" }:Index type 'CosmosSearch' was requested, but the 'cosmosSearch' options were not provided. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": 1 }, "name": "foo_1", "cosmosSearchOptions": { } } ] }', true); ERROR: Error in specification { "key" : { "a" : 1 }, "name" : "foo_1", "cosmosSearchOptions" : { } }:cosmosSearch index kind must be specified -- create collection SELECT documentdb_api.create_collection_view('db', '{ "create": "feature_counter_col" }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create view SELECT documentdb_api.create_collection_view('db', '{ "create": "feature_counter_col_view", "viewOn": "feature_counter_col" }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- now collMod it SELECT documentdb_api.coll_mod('db', 'feature_counter_col_view', '{ "collMod": "feature_counter_col_view", "viewOn": "feature_counter_col", "pipeline": [ { "$limit": 10 } ] }'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- create a valid indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "b": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "c": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 300, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "f": "text" }, "name": "a_text" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "uniq": 1 }, "name": "uniq_1", "unique": true } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_collmod" : 1}, {"command_create_collection" : 1}, {"command_create_view" : 1}, {"collMod_view" : 1}, {"create_index_text" : 1}, {"create_index_unique" : 1}, {"create_index_vector" : 4}, {"create_index_vector_cos" : 1}, {"create_index_vector_ip" : 1}, {"create_index_vector_l2" : 1}, {"create_index_vector_type_ivfflat" : 3}, {"limit" : 1}]} (1 row) SELECT document -> 'a' FROM documentdb_api.collection('db', 'feature_counter_col') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; ?column? --------------------------------------------------------------------- (0 rows) SELECT document -> 'a' FROM documentdb_api.collection('db', 'feature_counter_col') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; ?column? --------------------------------------------------------------------- (0 rows) -- bad queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); ERROR: Similarity index was not found for a vector similarity search query. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); ERROR: Similarity index was not found for a vector similarity search query. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); ERROR: $path, $queryVector, and $limit are all required fields for using a vector index. -- Use unwind, lookup SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$lookup": { "from": "agg_pipeline_inventory", "as": "matched_docs", "localField": "item", "foreignField": "sku" } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$lookup": { "from": "agg_pipeline_inventory", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- add $unset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$unset": "_id" }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- add skip + limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- match + project + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceRoot": { "newRoot": "$e" } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceWith": "$e" } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- sort + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- match + sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$sort": { "_id": 1 } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$sortByCount": { "$eq": [ { "$mod": [ { "$toInt": "$_id" }, 2 ] }, 0 ] } }, { "$sort": { "_id": 1 } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- $group with first/last SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- $group with firstN/lastN SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$firstN": { "input":"$_id", "n":5 } }, "e": { "$lastN": { "input":"$_id", "n":5 } } } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- $group with firstN/lastN w N>10 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$firstN": { "input":"$_id", "n":15 } }, "e": { "$lastN": { "input":"$_id", "n":15 } } } }], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) -- collation SET documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "feature_counter_col2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_find('db', '{ "find": "feature_counter_col2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 10, "collation": { "locale": "fr_CA", "strength" : 3 } }'); document --------------------------------------------------------------------- (0 rows) RESET documentdb_core.enablecollation; -- Create TTL index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "feature_counter_col2", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- Run validate command SELECT documentdb_api.validate('db', '{ "validate" : "validatecoll", "repair" : true }' ); ERROR: Running the validate command with { repair: true } is not supported yet. -- Print without resetting the counters SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(false); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"agg_operator_eq" : 1}, {"agg_operator_mod" : 5}, {"agg_operator_toint" : 5}, {"collation" : 2}, {"validate_repair" : 1}, {"create_index_ttl" : 1}, {"query_operator_eq" : 4}, {"query_operator_gt" : 4}, {"query_operator_or" : 2}, {"add_fields" : 5}, {"count" : 1}, {"group" : 5}, {"firstN_acc" : 2}, {"firstN_acc_GT10" : 1}, {"lastN_acc" : 2}, {"lastN_acc_GT10" : 1}, {"limit" : 3}, {"lookup" : 2}, {"match" : 6}, {"project" : 3}, {"replace_root" : 2}, {"replace_with" : 1}, {"skip" : 3}, {"sort" : 6}, {"sort_by_count" : 1}, {"sort_by_id" : 5}, {"unset" : 1}, {"vector_search_native" : 3}]} (1 row) -- print and reset the counters SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"agg_operator_eq" : 1}, {"agg_operator_mod" : 5}, {"agg_operator_toint" : 5}, {"collation" : 2}, {"validate_repair" : 1}, {"create_index_ttl" : 1}, {"query_operator_eq" : 4}, {"query_operator_gt" : 4}, {"query_operator_or" : 2}, {"add_fields" : 5}, {"count" : 1}, {"group" : 5}, {"firstN_acc" : 2}, {"firstN_acc_GT10" : 1}, {"lastN_acc" : 2}, {"lastN_acc_GT10" : 1}, {"limit" : 3}, {"lookup" : 2}, {"match" : 6}, {"project" : 3}, {"replace_root" : 2}, {"replace_with" : 1}, {"skip" : 3}, {"sort" : 6}, {"sort_by_count" : 1}, {"sort_by_id" : 5}, {"unset" : 1}, {"vector_search_native" : 3}]} (1 row) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[]} (1 row) -- check other two vector indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "myvector3": "cosmosSearch" }, "name": "foo_3_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "IP", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "myvector4": "cosmosSearch" }, "name": "foo_4_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 4 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "elem": "some sentence3", "myvector3": [8.0, 1.0, 9.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "elem": "some sentence3", "myvector4": [8.0, 1.0, 8.0, 8 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector3", "numCandidates": 10 } }, { "$project": { "myvector3": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector3" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ] } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); document --------------------------------------------------------------------- { "myvector4" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" }, { "$numberInt" : "8" } ] } (1 row) -- Query on a non-existent collection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorCollNonExistent", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); ERROR: The $vectorSearch needs to appear as the initial stage in the processing pipeline. SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 2}, {"command_insert_one" : 2}, {"create_index_vector" : 2}, {"create_index_vector_ip" : 1}, {"create_index_vector_l2" : 1}, {"create_index_vector_type_ivfflat" : 2}, {"project" : 2}, {"search_vector_default_nprobes" : 2}, {"search_vector_ivfflat" : 2}, {"vector_search_native" : 2}]} (1 row) -- check vector indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_ivf": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_hnsw": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 4 } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_ivf_half": "cosmosSearch" }, "name": "ivf_index_half", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "5" }, "numIndexesAfter" : { "$numberInt" : "6" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_hnsw_half": "cosmosSearch" }, "name": "hnsw_index_half", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 4, "compression": "half" } } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "elem": 1 }, "name": "elem_index" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "_id": 1, "elem": "some sentence ivf", "vector_ivf": [8.0, 1.0, 9.0 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "_id": 2, "elem": "some sentence hnsw", "vector_hnsw": [8.0, 1.0, 8.0, 8 ] }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf", "nProbes": 10} } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "elem" : "some sentence ivf", "vector_ivf" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.208329887130052072" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw", "efSearch": 5 } } } ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "elem" : "some sentence hnsw", "vector_hnsw" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" }, { "$numberInt" : "8" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.54622507455841007307" } } } (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf_half" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw_half" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SET local enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf", "nProbes": 10, "filter": { "elem": { "$gt": "some p" } } }}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "elem" : "some sentence ivf", "vector_ivf" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "9.0" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "10.208329887130052072" } } } (1 row) ROLLBACK; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SET local enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw", "efSearch": 5, "filter": { "elem": { "$gt": "some p" } } }}} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "2" }, "elem" : "some sentence hnsw", "vector_hnsw" : [ { "$numberDouble" : "8.0" }, { "$numberDouble" : "1.0" }, { "$numberDouble" : "8.0" }, { "$numberInt" : "8" } ], "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.54622507455841007307" } } } (1 row) ROLLBACK; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 2}, {"command_insert_one" : 2}, {"create_index_vector" : 4}, {"create_index_vector_cos" : 2}, {"create_index_vector_compression_half" : 2}, {"create_index_vector_l2" : 2}, {"create_index_vector_type_hnsw" : 2}, {"create_index_vector_type_ivfflat" : 2}, {"query_operator_gt" : 2}, {"match" : 2}, {"search" : 6}, {"search_vector_compression_half" : 2}, {"search_vector_default_nprobes" : 1}, {"search_vector_default_efsearch" : 1}, {"search_vector_hnsw" : 3}, {"search_vector_ivfflat" : 3}, {"search_vector_pre_filter" : 2}]} (1 row) -- aggregation operators counters SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 1}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- should only count once per query, not once per document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$add": ["$a", 1]}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } { "result" : { "$numberInt" : "3" } } { "result" : { "$numberInt" : "2" } } (3 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(false); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"agg_operator_add" : 1}, {"command_insert" : 3}, {"command_insert_one" : 3}, {"project" : 1}]} (1 row) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$add": ["$a", 1]}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "result" : { "$numberInt" : "2" } } { "result" : { "$numberInt" : "3" } } { "result" : { "$numberInt" : "2" } } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$multiply": ["$a", 1]}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "result" : { "$numberInt" : "1" } } { "result" : { "$numberInt" : "2" } } { "result" : { "$numberInt" : "1" } } (3 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"agg_operator_add" : 2}, {"agg_operator_multiply" : 1}, {"command_insert" : 3}, {"command_insert_one" : 3}, {"project" : 3}]} (1 row) -- nested should be counted SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$filter": {"input": [1, 2, 3, 4], "cond": {"$eq": ["$$this", 3]}}}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "3" } ] } { "result" : [ { "$numberInt" : "3" } ] } { "result" : [ { "$numberInt" : "3" } ] } (3 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$filter": {"input": [1, 2, 3, 4], "cond": {"$gt": ["$$this", 3]}}}}}], "cursor": {} }'); document --------------------------------------------------------------------- { "result" : [ { "$numberInt" : "4" } ] } { "result" : [ { "$numberInt" : "4" } ] } { "result" : [ { "$numberInt" : "4" } ] } (3 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"agg_operator_eq" : 1}, {"agg_operator_filter" : 2}, {"agg_operator_gt" : 1}, {"project" : 2}]} (1 row) -- should not count for non-existent operators SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"result": { "$nonExistent": {"input": [1, 2, 3, 4], "cond": {"$eq": ["$$this", 3]}}}}}], "cursor": {} }'); ERROR: Unrecognized expression format: $nonExistent SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"project" : 1}]} (1 row) -- Test feature counters for geospatial SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "2dkey": "2d"}, "name": "my_2d_idx" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "6" }, "numIndexesAfter" : { "$numberInt" : "7" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "2dspherekey": "2dsphere"}, "name": "my_2dsphere_idx" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "7" }, "numIndexesAfter" : { "$numberInt" : "8" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"create_index_2d" : 1}, {"create_index_2dsphere" : 1}]} (1 row) SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"2dkey": [1, 1]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"2dspherekey": [1, 1]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> '2dkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dkey": {"$geoWithin": {"$box": [[0, 0], [1, 1]]}}}'; ?column? --------------------------------------------------------------------- { "" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (1 row) SELECT document -> '2dkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dkey": {"$within": {"$box": [[0, 0], [1, 1]]}}}'; ?column? --------------------------------------------------------------------- { "" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (1 row) SELECT document -> '2dspherekey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dspherekey": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0,0]]] } }}}'; ?column? --------------------------------------------------------------------- { "" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (1 row) SELECT document -> '2dspherekey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dspherekey": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": [1, 1] } }}}'; ?column? --------------------------------------------------------------------- { "" : [ { "$numberInt" : "1" }, { "$numberInt" : "1" } ] } (1 row) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 2}, {"command_insert_one" : 2}, {"query_operator_geointersects" : 1}, {"query_operator_geowithin" : 3}]} (1 row) -- Test feature counter for $text SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col3", "indexes": [ { "key": { "textkey": "text" }, "name": "my_txt_idx" } ] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{ "textkey": "this is a cat" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document -> 'textkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{ "$text": { "$search": "cat" } }'; ?column? --------------------------------------------------------------------- { "" : "this is a cat" } (1 row) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 1}, {"command_insert_one" : 1}, {"create_index_text" : 1}, {"query_operator_text" : 1}]} (1 row) -- TTL index usage tests SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date way in future SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 8, "ttl" : true }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- 1. Create TTL Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "feature_usage_ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- 2. List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "feature_usage_ttlcoll" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.feature_usage_ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.feature_usage_ttlcoll", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'feature_usage_ttlcoll') ORDER BY collection_id, index_id; collection_id | index_id | index_spec_as_bson | index_is_valid --------------------------------------------------------------------- 67505 | 67520 | { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } | t 67505 | 67521 | { "v" : { "$numberInt" : "1" }, "key" : { "ttl" : { "$numberInt" : "1" } }, "name" : "ttl_index", "expireAfterSeconds" : { "$numberInt" : "5" } } | t (2 rows) -- 4. Call ttl purge procedure with a batch size of 2 CALL documentdb_api_internal.delete_expired_rows(3); CALL documentdb_api_internal.delete_expired_rows(3); CALL documentdb_api_internal.delete_expired_rows(3); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 10}, {"command_insert_one" : 10}, {"command_list_indexes_cursor_first_page" : 1}, {"create_index_ttl" : 1}, {"cursor_type_single_batch" : 1}, {"ttl_purger_calls" : 3}]} (1 row) -- Feature counter for _internalInhibitOptimization SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$_internalInhibitOptimization": 1 }, { "$replaceWith": "$e" } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$sort": { "_id": 1 } }, { "$_internalInhibitOptimization": 1 }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); document --------------------------------------------------------------------- (0 rows) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"query_operator_gt" : 1}, {"add_fields" : 3}, {"_internalInhibitOptimization" : 3}, {"match" : 1}, {"replace_root" : 1}, {"replace_with" : 1}, {"sort" : 1}, {"sort_by_id" : 1}]} (1 row) SELECT documentdb_api.insert('db', '{"insert":"writeFC", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 } ]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('db', '{"insert":"writeFC", "documents":[ { "_id" : 2, "movie": "Wolverine", "Budget": 180000000, "year": 2012 }, { "_id" : 3, "movie": "Spider Man", "Budget": 180000000, "year": 2013 } ]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.update('db', '{"update": "writeFC", "updates":[{"q": {"_id": 1},"u":{"$set":{"year": "1998" }},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('db', '{"update": "writeFC", "updates":[{"q": {"_id": 1},"u":{"$set":{"year": "2001" }},"multi":true}, {"q": {"_id": 2},"u":{"$set":{"year": "2002" }},"multi":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); get_feature_counter_pretty --------------------------------------------------------------------- {"Feature_usage":[{"command_insert" : 2}, {"command_insert_one" : 1}, {"command_insert_100" : 1}, {"command_update" : 2}, {"command_update_one" : 1}, {"command_update_100" : 1}]} (1 row) geospatial_extract_2d_geometries.out000066400000000000000000001340461507310017400372260ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_api_catalog, documentdb_distributed_test_helpers; SET citus.next_shard_id TO 6990000; SET documentdb.next_collection_id TO 699000; SET documentdb.next_collection_index_id TO 699000; -- Case 1: All the below cases are just ignored to have a geodetic type and returns NULL geometry -- This a check based on the type of the field at the given path, if it is not array or object or empty array and objects then it will return NULL SELECT bson_extract_geometry(NULL, 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : "Hello" }', NULL) IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : true }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : false }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : null }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "$undefined": true } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : {} }', 'a') IS NULL; -- empty single point ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : [] }', 'a') IS NULL; -- empty single point ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : [{}, []] }', 'a') IS NULL; -- empty multi points ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : [[], {}] }', 'a') IS NULL; -- empty multi points ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "field1": {} } }', 'a') IS NULL; -- surprise!! this doesn't throw error and only return NULL ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "field1": [] } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "field1": [], "field2": {} } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "$numberInt": "1" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "$numberLong": "1" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "$numberDouble": "1" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "a" : { "$numberDecimal": "1" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry('{ "b" : true }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) -- Case 2: Top level validation when the geodetic field is either object or array in strict mode SELECT bson_extract_geometry('{ "a" : { "field1": "Hello" } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": true } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": false } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": null } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": { "$undefined": true } } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberInt": "1" } } }', 'a'); ERROR: Geo field contains only one element SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberLong": "1" } } }', 'a'); ERROR: Geo field contains only one element SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberDouble": "1" } } }', 'a'); ERROR: Geo field contains only one element SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberDecimal": "1" } } }', 'a'); ERROR: Geo field contains only one element SELECT bson_extract_geometry('{ "a" : { "field1": [], "field2": 10 } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": [[]], "field2": 10 } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": [{}], "field2": 10 } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": {}, "field2": 10 } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": "Hello" } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": "Hello", "field3": 10 } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": true } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": false } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": null } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": { "$undefined": true } } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. -- Case 2.1: Same Top level validations are skipped for array or object in bson_extract_geometry_runtime and returns NULL SELECT bson_extract_geometry_runtime('{ "a" : { "field1": "Hello" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": true } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": false } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": null } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$undefined": true } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberInt": "1" } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberLong": "1" } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberDouble": "1" } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberDecimal": "1" } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [], "field2": 10 } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [[]], "field2": 10 } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [{}], "field2": 10 } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": {}, "field2": 10 } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": "Hello" } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": true } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": false } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": null } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": { "$undefined": true } } }', 'a') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) -- Case 3: Top level strict validation for nested paths SELECT bson_extract_geometry('{ "a" : { "b": ["Text", "Text"] } }', 'a.b'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": [], "field2": 10 } } }', 'a.b'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": "Hello" } } }', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": true } } }', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": false } } }', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": null } } }', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": { "$undefined": true } } } }', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. -- Case 3.1: Same Top level validations are skipped for nested paths in bson_extract_geometry_runtime function and returns NULL SELECT bson_extract_geometry_runtime('{ "a" : { "b": ["Text", "Text"] } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": [], "field2": 10 } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": "Hello" } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": true } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": false } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": null } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": { "$undefined": true } } } }', 'a.b') IS NULL; ?column? --------------------------------------------------------------------- t (1 row) -- Case 4: Partial valid multipoint cases, throws error in strict mode SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 33, "2": 33 }}, {"b": ["Text", "Text"]} ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 34, "2": 34 }}, {"b": { "field1": [], "field2": 10 } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 35, "2": 35 }}, {"b": { "field1": 10, "field2": "Hello" } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 36, "2": 36 }}, {"b": { "field1": 10, "field2": true } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 37, "2": 37 }}, {"b": { "field1": 10, "field2": false } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 38, "2": 38 }}, {"b": { "field1": 10, "field2": null } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 39, "2": 39 }}, {"b": { "field1": 10, "field2": { "$undefined": true } } } ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": [45,45]} ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120], "lat": 125 } ] } ]}', 'a.b.long'); ERROR: Geo field contains only one element -- With GeoJson points, errors in case of strict mode SELECT bson_extract_geometry('{"a": {"type": "Point", "coordinates": [45,45] } }', 'a'); ERROR: location object expected, location array not in correct format SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46] } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46], "last": 20 } }', 'a'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "point", "coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid type: point (should be Point) ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{"a": {"extra": 10, "Type": "point", "coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid field name: Type ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "point", "Coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid field name: Coordinates ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. SELECT bson_extract_geometry('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": {"type": "Point", "coordinates": [45,45]}} ]}', 'a.b'); ERROR: Geo values are required to be in the 'legacy coordinate pairs' format when working with 2D indexes. -- Case 4.1: Partial points are returned without any error in non strict mode -- public.ST_ASEWKT is used to convert the geometry to Extended Well known text format of postgis SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 33, "2": 33 }}, {"b": ["Text", "Text"]} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 34, "2": 34 }}, {"b": { "field1": [], "field2": 10 } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(34 34) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 35, "2": 35 }}, {"b": { "field1": 10, "field2": "Hello" } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(35 35) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 36, "2": 36 }}, {"b": { "field1": 10, "field2": true } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(36 36) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 37, "2": 37 }}, {"b": { "field1": 10, "field2": false } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(37 37) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 38, "2": 38 }}, {"b": { "field1": 10, "field2": null } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(38 38) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 39, "2": 39 }}, {"b": { "field1": 10, "field2": { "$undefined": true } } } ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(39 39) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": [45,45]} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(44 44,45 45) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120], "lat": 125 } ] } ]}', 'a.b.long')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(70 80,90 100,110 120) (1 row) -- With GeoJson points, no errors in non-strict mode SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"type": "Point", "coordinates": [45,45] } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(45 45) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46] } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(46 46) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "Point", "coordinates": [47,47], "last": 20 } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(47 47) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "point", "coordinates": [48,48], "last": 20 } }', 'a')) AS geoms; -- Invalid type: array is empty geoms --------------------------------------------------------------------- (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "Type": "point", "coordinates": [49,49], "last": 20 } }', 'a')) AS geoms; -- Invalid field name: Type, array is empty geoms --------------------------------------------------------------------- (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "point", "Coordinates": [50,50], "last": 20 } }', 'a')) AS geoms; -- Invalid field name: Coordinates, array is empty geoms --------------------------------------------------------------------- (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": {"type": "Point", "coordinates": [51,51]}} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(44 44,51 51) (1 row) -- Case 5: Valid cases SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "field1": 10, "field2": 10 } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "thisCanBeAnything": 10, "Doesn''t matter": 10 } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": 10, "lat": 10, "extra": "Ignored" } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberInt": "10" }, "lat": { "$numberInt": "10" } } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberLong": "10" }, "lat": { "$numberLong": "10" } } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDouble": "10" }, "lat": { "$numberDouble": "10" } } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDecimal": "10" }, "lat": { "$numberDecimal": "10" } } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDouble": "1.23122e-2" }, "lat": { "$numberDecimal": "1.3160e1" } } }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(0.0123122 13.16) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [10, 10] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [10, 10, 20, 30, 40, 50] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberInt": "10"}, {"$numberInt": "10"}] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberLong": "10"}, {"$numberLong": "10"}] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDouble": "10"}, {"$numberDouble": "10"}] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDecimal": "10"}, {"$numberDecimal": "10"}] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDouble": "1.23122e-2"}, {"$numberDecimal": "1.3160e1"}] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(0.0123122 13.16) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{ "1": 33, "2": 33 }, { "1": 35, "2": 35 }]}', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(33 33,35 35) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10], [15, 15], [20, 20]] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10], { "point": 15, "point2": 15 }, [20, 20]] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10, "extra"], [15, 15, "extra"], [20, 20, "extra"]] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[{"$numberInt": "10"}, {"$numberInt": "10"}], [{"$numberLong": "15"}, {"$numberLong": "15"}], [{"$numberDouble": "20"}, {"$numberDouble": "20"}], [{"$numberDecimal": "25"}, {"$numberDecimal": "25"}] ] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20,25 25) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [-180, 180] }', 'a')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(-180 180) (1 row) -- nested path valid cases SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "b" : [50, 50] } }', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(50 50) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": [30, 30] } ] }', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,20 20,30 30) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": false } ] }', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { }, [ ], { "b": [25, 25 ]} ] }', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(25 25) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { }, { "b": [30, 30 ]}, [], { "b": {"val1": 45, "val2": 45 } } ] }', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(30 30,45 45) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": "Not valid representation"} ]}', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"noBHere": [10, 10]}, {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')); st_asewkt --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80, 90], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100, 110], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120, 130], "lat": 125 } ] } ]}', 'a.b.long')); st_asewkt --------------------------------------------------------------------- SRID=4326;MULTIPOINT(70 80,80 90,90 100,100 110,110 120,120 130) (1 row) -- Case 5.1: All Valid cases work even for non strict mode SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": 10 } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "thisCanBeAnything": 10, "Doesn''t matter": 10 } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": 10, "lat": 10, "extra": "Ignored" } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberInt": "10" }, "lat": { "$numberInt": "10" } } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberLong": "10" }, "lat": { "$numberLong": "10" } } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDouble": "10" }, "lat": { "$numberDouble": "10" } } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDecimal": "10" }, "lat": { "$numberDecimal": "10" } } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDouble": "1.23122e-2" }, "lat": { "$numberDecimal": "1.3160e1" } } }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(0.0123122 13.16) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [10, 10] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [10, 10, 20, 30, 40, 50] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberInt": "10"}, {"$numberInt": "10"}] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberLong": "10"}, {"$numberLong": "10"}] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDouble": "10"}, {"$numberDouble": "10"}] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDecimal": "10"}, {"$numberDecimal": "10"}] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(10 10) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDouble": "1.23122e-2"}, {"$numberDecimal": "1.3160e1"}] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(0.0123122 13.16) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{ "1": 33, "2": 33 }, { "1": 35, "2": 35 }]}', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(33 33,35 35) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10], [15, 15], [20, 20]] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10], { "point": 15, "point2": 15 }, [20, 20]] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10, "extra"], [15, 15, "extra"], [20, 20, "extra"]] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[{"$numberInt": "10"}, {"$numberInt": "10"}], [{"$numberLong": "15"}, {"$numberLong": "15"}], [{"$numberDouble": "20"}, {"$numberDouble": "20"}], [{"$numberDecimal": "25"}, {"$numberDecimal": "25"}] ] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,15 15,20 20,25 25) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [-180, 180] }', 'a')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(-180 180) (1 row) -- nested path valid cases SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "b" : [50, 50] } }', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(50 50) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": [30, 30] } ] }', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,20 20,30 30) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": false } ] }', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(10 10,20 20) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { }, [ ], { "b": [25, 25 ]} ] }', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(25 25) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { }, { "b": [30, 30 ]}, [], { "b": {"val1": 45, "val2": 45 } } ] }', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(30 30,45 45) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": "Not valid representation"} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"noBHere": [10, 10]}, {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;POINT(33 33) (1 row) SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80, 90], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100, 110], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120, 130], "lat": 125 } ] } ]}', 'a.b.long')) AS geoms; geoms --------------------------------------------------------------------- SRID=4326;MULTIPOINT(70 80,80 90,90 100,100 110,110 120,120 130) (1 row) -- Test to check if segmentize does leave geometries invalid in few cases. The test below shows a perfectly fine geography can be made into an invalid -- or intersecting points geometry by ST_SEGMENTIZE and to fix this we should use ST_MAKEVALID. SELECT public.ST_ISVALID('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography::public.geometry); st_isvalid --------------------------------------------------------------------- t (1 row) SET client_min_messages = 'warning'; SELECT public.ST_ISVALID(public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry); -- 500km is our default segment length st_isvalid --------------------------------------------------------------------- f (1 row) RESET client_min_messages; -- This is the base segmentize query when run without ST_MAKEVALID DO $$ DECLARE errorMessage text; BEGIN SELECT public.ST_SUBDIVIDE( public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry, 8 -- 8 is the default number of max vertices a divide segment can have )::public.geography; EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%Self-intersection at%' OR errorMessage LIKE '%geometry is invalid%' THEN -- We are only showing that after segmentize the geometry is invalid, the actual error message is irrelevant -- because the next test shows ST_MAKEVALID fixes this errorMessage := 'Invalid geometry found after segmentize.'; END IF; RAISE EXCEPTION '%', errorMessage using ERRCODE = SQLSTATE; END $$; ERROR: Invalid geometry found after segmentize. CONTEXT: PL/pgSQL function inline_code_block line 16 at RAISE -- Now run this again with ST_MAKEVALID to see the difference, ST_ASTEXT is used to pretty print the output SELECT public.ST_ASTEXT( public.ST_SUBDIVIDE( public.ST_MAKEVALID(public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry), 8 -- 8 is the default number of max vertices a divide segment can have )::public.geography, 12 -- Limit output to 12 decimal digits ); st_astext --------------------------------------------------------------------- POLYGON((-157.5 40.234375,-157.5 40,-160.299914418744 40.205209224805,-157.5 40.234375)) POLYGON((-163.102123414535 40.410586622027,-160.299914418744 40.205209224805,-180 40,-174.397876585465 40.410586622027,-168.75 40.548263918365,-163.102123414535 40.410586622027)) POLYGON((-157.5 54.765625,11.25 53.0078125,11.25 41.9921875,-157.5 40.234375,-157.5 54.765625)) POLYGON((180 51.25,180 43.75,11.25 41.9921875,11.25 53.0078125,180 51.25)) POLYGON((-168.75 55.520540637748,-163.08803378529 55.389661039663,-157.5 55,-157.5 54.765625,-180 55,-174.41196621471 55.389661039663,-168.75 55.520540637748)) (5 rows) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "segmentsTest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds" }]}', true); NOTICE: creating collection create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : true, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) --Insert 2 points one out one at the boundary and one inside the original polygon SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 1, "a" : { "type": "Point", "coordinates": [ -167, 48] } }', NULL); -- inside insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 2, "a" : { "type": "Point", "coordinates": [ -180, 40] } }', NULL); -- overlap with a vertex insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 3, "a" : { "type": "Point", "coordinates": [ -142, 49] } }', NULL); -- outside insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document FROM documentdb_api.collection('db', 'segmentsTest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-180, 40], [-157.5, 40], [-157.5, 55], [-180, 55], [-180, 40]]]}}}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "a" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "-167" }, { "$numberInt" : "48" } ] } } { "_id" : { "$numberInt" : "2" }, "a" : { "type" : "Point", "coordinates" : [ { "$numberInt" : "-180" }, { "$numberInt" : "40" } ] } } (2 rows) EXPLAIN SELECT document FROM documentdb_api.collection('db', 'segmentsTest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-180, 40], [-157.5, 40], [-157.5, 55], [-180, 55], [-180, 40]]]}}}}'; -- Polygon with points on a great circle of earth QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_699000_6990005 collection (cost=8.56..12.58 rows=1 width=32) Recheck Cond: (documentdb_api_catalog.bson_validate_geography(document, 'a'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "a" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-180" }, { "$numberInt" : "40" } ], [ { "$numberDouble" : "-157.5" }, { "$numberInt" : "40" } ], [ { "$numberDouble" : "-157.5" }, { "$numberInt" : "55" } ], [ { "$numberInt" : "-180" }, { "$numberInt" : "55" } ], [ { "$numberInt" : "-180" }, { "$numberInt" : "40" } ] ] ] } } }'::documentdb_core.bson) -> Bitmap Index Scan on my_2ds (cost=0.00..4.13 rows=8 width=0) Index Cond: (documentdb_api_catalog.bson_validate_geography(document, 'a'::text) OPERATOR(documentdb_api_catalog.@|#|) '{ "a" : { "$geometry" : { "type" : "Polygon", "coordinates" : [ [ [ { "$numberInt" : "-180" }, { "$numberInt" : "40" } ], [ { "$numberDouble" : "-157.5" }, { "$numberInt" : "40" } ], [ { "$numberDouble" : "-157.5" }, { "$numberInt" : "55" } ], [ { "$numberInt" : "-180" }, { "$numberInt" : "55" } ], [ { "$numberInt" : "-180" }, { "$numberInt" : "40" } ] ] ] } } }'::documentdb_core.bson) (9 rows) RESET search_path; isolation-currentop-singlepool.out000066400000000000000000000000001507310017400367030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedlist_metadata_cursor_tests.out000066400000000000000000000343341507310017400361650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 91000; SET documentdb.next_collection_id TO 910; SET documentdb.next_collection_index_id TO 910; -- create a collection in db1 SELECT documentdb_api.create_collection('list_metadata_db1', 'list_metadata_coll1'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db1'; SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : [ { "name" : "list_metadata_coll1", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- create a sharded collection in db1 SELECT documentdb_api.create_collection('list_metadata_db1', 'list_metadata_coll2'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.shard_collection('list_metadata_db1', 'list_metadata_coll2', '{ "_id": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- create 2 collection in db2 SELECT documentdb_api.create_collection('list_metadata_db2', 'list_metadata_db2_coll1'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api.create_collection('list_metadata_db2', 'list_metadata_db2_coll2'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- create 2 views (one for db1 and one for db2) SELECT documentdb_api.create_collection_view('list_metadata_db1', '{ "create": "list_metadata_view1_1", "viewOn": "list_metadata_coll1", "pipeline": [{ "$limit": 100 }] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.create_collection_view('list_metadata_db2', '{ "create": "list_metadata_view2_1", "viewOn": "list_metadata_coll2", "pipeline": [{ "$skip": 100 }] }'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- reset collection_uuids UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db1'; UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db2'; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1 }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_coll1", "type" : "collection", "options" : { }, "info" : { "readOnly" : false }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_coll2", "type" : "collection", "options" : { }, "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_view1_1", "type" : "view", "options" : { "viewOn" : "list_metadata_coll1", "pipeline" : [ { "$limit" : { "$numberInt" : "100" } } ] }, "info" : { "readOnly" : true }, "idIndex" : null } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1, "nameOnly": true }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_db2_coll1", "type" : "collection" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_db2_coll2", "type" : "collection" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_view2_1", "type" : "view" } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1 }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_db2_coll1", "type" : "collection", "options" : { }, "info" : { "readOnly" : false }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_db2_coll2", "type" : "collection", "options" : { }, "info" : { "readOnly" : false }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db2.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_view2_1", "type" : "view", "options" : { "viewOn" : "list_metadata_coll2", "pipeline" : [ { "$skip" : { "$numberInt" : "100" } } ] }, "info" : { "readOnly" : true }, "idIndex" : null } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "filter": { "type": "view" } }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_view1_1", "type" : "view", "options" : { "viewOn" : "list_metadata_coll1", "pipeline" : [ { "$limit" : { "$numberInt" : "100" } } ] }, "info" : { "readOnly" : true }, "idIndex" : null } }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "filter": { "info.readOnly": false } }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_coll1", "type" : "collection", "options" : { }, "info" : { "readOnly" : false }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.$cmd.ListCollections", "firstBatch" : { "name" : "list_metadata_coll2", "type" : "collection", "options" : { }, "info" : { "readOnly" : false, "shardKey" : { "_id" : "hashed" } }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } }, "ok" : { "$numberDouble" : "1.0" } } (2 rows) -- create some indexes for the collections in db1 SELECT documentdb_api_internal.create_indexes_non_concurrently('list_metadata_db1', '{ "createIndexes": "list_metadata_coll1", "indexes": [ { "key": { "a": 1 }, "name": "a_1" }, { "key": { "b": 1 }, "name": "b_1", "unique": true } ]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_coll1" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.list_metadata_coll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.list_metadata_coll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "a" : { "$numberInt" : "1" } }, "name" : "a_1" } }, "ok" : { "$numberDouble" : "1.0" } } { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.list_metadata_coll1", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "b" : { "$numberInt" : "1" } }, "name" : "b_1", "unique" : true } }, "ok" : { "$numberDouble" : "1.0" } } (3 rows) SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_coll2" }') ORDER BY 1; bson_dollar_unwind --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "list_metadata_db1.list_metadata_coll2", "firstBatch" : { "v" : { "$numberInt" : "2" }, "key" : { "_id" : { "$numberInt" : "1" } }, "name" : "_id_" } }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- fails SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_view1_1" }') ORDER BY 1; ERROR: The namespace list_metadata_db1.list_metadata_view1_1 refers to a view object rather than a collection SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_non_existent" }') ORDER BY 1; ERROR: Namespace does not currently exist: list_metadata_db1.list_metadata_non_existent -- test with add distributed metadata when there's a view SELECT COUNT(*) FROM ( SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "addDistributedMetadata": true }')) i; count --------------------------------------------------------------------- 2 (1 row) SELECT COUNT(*) FROM ( SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1, "addDistributedMetadata": true }')) i; count --------------------------------------------------------------------- 2 (1 row) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/or9.out000066400000000000000000000175621507310017400313270ustar00rootroot00000000000000-- Based on or9.js CREATE SCHEMA or9; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,or9; SET citus.next_shard_id TO 10000; SET documentdb.next_collection_id TO 1000; SET documentdb.next_collection_index_id TO 1000; SELECT 1 FROM drop_collection('db','or9_test'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','or9_test', '{"field1":10,"field2":20}'); NOTICE: creating collection ?column? --------------------------------------------------------------------- 1 (1 row) SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'or9_test'); drop_primary_key --------------------------------------------------------------------- (1 row) -- Since we cannot define compound wildcard indexes, let's define two -- different wildcard indexes here. -- -- Indeed, our current implementation always creates a wildcard index, even for compound cases -- but for compatibility, let's stick to a single-field wildcard index here. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('or9_test', 'index_1', '{"field1.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "0" }, "numIndexesAfter" : { "$numberInt" : "1" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('or9_test', 'index_2', '{"field2.$**": 1}'), true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) CREATE OR REPLACE FUNCTION or9.assert_count(expected_row_count int, query bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','or9_test') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; BEGIN; set local enable_seqscan TO OFF; -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}}, {"field1": 10}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field1": {"$gt": 15, "$lte": 25}}, {"field1": 10}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}}, {"field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 20, "$lte": 25}}, {"field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gt": 25, "$lte": 35}}, {"field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 25}, {"field1": 10}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}}, {"field2": 20, "field1": 10}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 25}, {"field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 25}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 20, "$lte": 25}, "field2": 25}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 20}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 25}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 20, "$lte": 25}, "field1": 25}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 10}, {"field1": 10, "field2": 20}]}'); assert_count --------------------------------------------------------------------- (1 row) ROLLBACK; DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'or9_test'; EXECUTE format('TRUNCATE documentdb_data.documents_%s', v_collection_id); END $$; SELECT 1 FROM insert_one('db','or9_test', '{"field1": 10, "field2": 50}'); ?column? --------------------------------------------------------------------- 1 (1 row) SELECT 1 FROM insert_one('db','or9_test', '{"field1": 50, "field2": 10}'); ?column? --------------------------------------------------------------------- 1 (1 row) BEGIN; set local enable_seqscan to OFF; -- "SERVER-12594": there are two clauses in the case below, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10]}, "field2": {"$in": [10, 50]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); assert_count --------------------------------------------------------------------- (1 row) SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10]}, "field2": {"$in": [10]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); assert_count --------------------------------------------------------------------- (1 row) ROLLBACK; public_api_schema.out000066400000000000000000000045161507310017400341610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected-- show all functions exported in documentdb_api_distributed \df documentdb_api_distributed.* List of functions Schema | Name | Result data type | Argument data types | Type --------------------------------------------------------------------- documentdb_api_distributed | complete_upgrade | boolean | | func documentdb_api_distributed | initialize_cluster | void | | func documentdb_api_distributed | rebalancer_start | documentdb_core.bson | p_spec documentdb_core.bson | func documentdb_api_distributed | rebalancer_status | documentdb_core.bson | p_spec documentdb_core.bson | func documentdb_api_distributed | rebalancer_stop | documentdb_core.bson | p_spec documentdb_core.bson | func documentdb_api_distributed | update_postgres_index_worker | documentdb_core.bson | p_local_function_arg documentdb_core.bson | func (6 rows) -- show all aggregates exported \da+ documentdb_api_distributed.* List of aggregate functions Schema | Name | Result data type | Argument data types | Description --------------------------------------------------------------------- (0 rows) -- This is last (Tables/indexes) \d documentdb_api_distributed.* Table "documentdb_api_distributed.documentdb_cluster_data" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- metadata | documentdb_core.bson | | not null | Indexes: "documentdb_cluster_data_pkey" PRIMARY KEY, btree (metadata) Triggers: documentdb_versions_trigger AFTER DELETE OR UPDATE ON documentdb_api_distributed.documentdb_cluster_data FOR EACH STATEMENT EXECUTE FUNCTION documentdb_api_internal.update_documentdb_version_data() Index "documentdb_api_distributed.documentdb_cluster_data_pkey" Column | Type | Key? | Definition --------------------------------------------------------------------- metadata | documentdb_core.bson | yes | metadata primary key, btree, for table "documentdb_api_distributed.documentdb_cluster_data" query_sharding_tests.out000066400000000000000000001321631507310017400350000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 739000; SET documentdb.next_collection_id TO 7390; SET documentdb.next_collection_index_id TO 7390; SELECT documentdb_api.insert_one('qst', 'single_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('qst', 'comp_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.shard_collection('qst', 'single_shard', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.shard_collection('qst', 'comp_shard', '{ "a": "hashed", "b": "hashed", "c": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) -- cross shard queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "e": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7391_739006 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "e": 1 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) (7 rows) -- single shard queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "e": 1, "a": 4 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739006 collection Recheck Cond: (shard_key_value = '4004935074940511305'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "e": 1, "a": 4, "b": 2, "c": 6 } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) -- single shard with and EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": 4 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739006 collection Recheck Cond: (shard_key_value = '4004935074940511305'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": 4 }, { "b": 2 }, { "c": 6 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1, "a": 4 }, { "b": 2, "c": 6 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) -- all components speciied but not equals, cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": { "$ne": 4 } } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7391_739006 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@!=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1, "a": 4 }, { "b": 2, "c": { "$gt": 6 } } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) (7 rows) -- $or with a single branch - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "a": 4 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739006 collection Recheck Cond: (shard_key_value = '4004935074940511305'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "4" } ] }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "b": 2, "$or": [ { "e": 1, "a": 4, "c": 6 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) -- top level $or - N shard query but not all branches have shard key: cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1 }, { "a": 4 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7391_739006 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "5" } }'::documentdb_core.bson))) (7 rows) -- top level $or - all branches have shard key - N shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739012 collection Recheck Cond: ((shard_key_value = '1786987034919379147'::bigint) OR (shard_key_value = '4004935074940511305'::bigint)) Filter: (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '1786987034919379147'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND ((shard_key_value = '4112493706261607605'::bigint) OR (shard_key_value = '-6685363114159754435'::bigint)) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "9" } }'::documentdb_core.bson)))) (7 rows) -- $and and $or with $and having shard key and $or having shard key - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "a": 15}, { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7391_739013 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "15" } }'::documentdb_core.bson) AND (shard_key_value = '8792588867541173546'::bigint) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson))) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "a": 15, "b": 3, "c": 7, "g": 5 }, { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7392_739017 collection Recheck Cond: (shard_key_value = '5799615767555655734'::bigint) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "15" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "7" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "g" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "9" } }'::documentdb_core.bson)))) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '5799615767555655734'::bigint) (10 rows) -- $and and $or with $or having shard key - N shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "g": 15}, { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739012 collection Recheck Cond: ((shard_key_value = '1786987034919379147'::bigint) OR (shard_key_value = '4004935074940511305'::bigint)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "g" : { "$numberInt" : "15" } }'::documentdb_core.bson) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bson)) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson))) -> BitmapOr -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '1786987034919379147'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "g": 5 }, { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "g" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND ((shard_key_value = '4112493706261607605'::bigint) OR (shard_key_value = '-6685363114159754435'::bigint)) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "9" } }'::documentdb_core.bson)))) (7 rows) -- $and and $or with $or not having shard key - cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "g": 15}, { "$or": [ { "e": 1}, { "a": 4 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7391_739006 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "g" : { "$numberInt" : "15" } }'::documentdb_core.bson) AND ((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) OR (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson))) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "g": 5 }, { "$or": [ { "e": 1, "a": 4, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "g" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (((document OPERATOR(documentdb_api_catalog.@=) '{ "e" : { "$numberInt" : "1" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) OR ((document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "9" } }'::documentdb_core.bson)))) (7 rows) -- test all the same above but with $in instead of $or -- $in with a single branch - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739006 collection Recheck Cond: (shard_key_value = '4004935074940511305'::bigint) Filter: (document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) (10 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4 ] }, "b": { "$in": [ 2 ] }, "c": { "$in": [ 6 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "4" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "b" : { "$numberInt" : "2" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson) AND (shard_key_value = '4112493706261607605'::bigint)) (7 rows) -- $in with multiple branches - cross shard but limited subset of shards EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7391_739006 collection Recheck Cond: ((shard_key_value = '4004935074940511305'::bigint) OR (shard_key_value = '1786987034919379147'::bigint)) Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) -> BitmapOr -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '4004935074940511305'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '1786987034919379147'::bigint) (13 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 6, 7 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 5 Tasks Shown: One of 5 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "c" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson) AND ((shard_key_value = '4112493706261607605'::bigint) OR (shard_key_value = '7192756992769259220'::bigint) OR (shard_key_value = '7379984039362792367'::bigint) OR (shard_key_value = '6204020176564357320'::bigint) OR (shard_key_value = '7901297655174785112'::bigint) OR (shard_key_value = '8549209525301393538'::bigint) OR (shard_key_value = '-3894726655378290049'::bigint) OR (shard_key_value = '-4310157402589750110'::bigint))) (7 rows) -- $in with mixed equality $in EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$eq": 5 }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 6, 6 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7392_739017 collection Recheck Cond: ((shard_key_value = '7192756992769259220'::bigint) OR (shard_key_value = '6204020176564357320'::bigint) OR (shard_key_value = '7192756992769259220'::bigint) OR (shard_key_value = '6204020176564357320'::bigint)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "c" : [ { "$numberInt" : "6" }, { "$numberInt" : "6" } ] }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '7192756992769259220'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6204020176564357320'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '7192756992769259220'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6204020176564357320'::bigint) (17 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$eq": 5 }, "b": { "$in": [ 2, 3 ] }, "c": { "$eq": 6 } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 2 Tasks Shown: One of 2 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_7392_739017 collection Recheck Cond: ((shard_key_value = '7192756992769259220'::bigint) OR (shard_key_value = '6204020176564357320'::bigint)) Filter: ((document OPERATOR(documentdb_api_catalog.@=) '{ "a" : { "$numberInt" : "5" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "b" : [ { "$numberInt" : "2" }, { "$numberInt" : "3" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@=) '{ "c" : { "$numberInt" : "6" } }'::documentdb_core.bson)) -> BitmapOr -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '7192756992769259220'::bigint) -> Bitmap Index Scan on _id_ Index Cond: (shard_key_value = '6204020176564357320'::bigint) (13 rows) -- $in but not all are specified - full cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "c": { "$in": [ 6, 6 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "c" : [ { "$numberInt" : "6" }, { "$numberInt" : "6" } ] }'::documentdb_core.bson)) (7 rows) EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "b": { "$gte": 3 }, "c": { "$in": [ 6, 7 ] } } } ] }'); QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_7392_739014 collection Filter: ((document OPERATOR(documentdb_api_catalog.@*=) '{ "a" : [ { "$numberInt" : "4" }, { "$numberInt" : "5" } ] }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@>=) '{ "b" : { "$numberInt" : "3" } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@*=) '{ "c" : [ { "$numberInt" : "6" }, { "$numberInt" : "7" } ] }'::documentdb_core.bson)) (7 rows) documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expected/regex.out000066400000000000000000001027271507310017400317260ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 335000; SET documentdb.next_collection_id TO 3350; SET documentdb.next_collection_index_id TO 3350; SELECT create_collection('db','regex'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT insert_one('db','regex', '{"_id" : 99, "b": "abc123"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 100, "b" : "abc123", "description" : "this is single line " }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 101, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 102, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 103, "b" : "xyz789", "description" : "this is Multiple\nline description" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 104, "b" : "xyz790", "description" : "this is Multiple\n incline description" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 105, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 106, "a" : "hello a\bcde world" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 107, "a" : {"$regularExpression" : {"pattern" : "a\bcde\b", "options" : ""}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"pattern" : "hello", "options" : ""}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 109, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 110, "a" : {"$regularExpression" : {"pattern" : "a\\ycde\\y", "options" : ""}}}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 111, "a" : "a value", "b": "b value"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 112, "a" : "v2", "b": "bv2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 113, "a" : "v3", "b": "bv3"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 114, "a" : "v4", "b": "bv4"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 115, "a" : "v5", "b": "bv5"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 116, "a" : "v6", "b": "bv6"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Some unicodes & mixed numerical SELECT insert_one('db','regex', '{"_id" : 120, "number" : "୩༢༣༤༥"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 121, "number" : "02191996"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯678"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- Some unicode text SELECT insert_one('db','regex', '{"_id" : 130, "text" : "kyle"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 131, "text" : "박정수"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 132, "text" : "Fernández"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Invalid read of boolean in state IN_BSON_TYPE' LINE 1: ... from collection('db', 'regex') where document @@ '{"b": {"$... ^ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"b": 1}, "name": "index_on_sku"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"x": 1}, "name": "index_on_x" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "2" }, "numIndexesAfter" : { "$numberInt" : "3" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"F1": 1}, "name": "index_on_F1" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "3" }, "numIndexesAfter" : { "$numberInt" : "4" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"a": 1, "b": 1}, "name": "Compound_index_on_a_and_b" }]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "4" }, "numIndexesAfter" : { "$numberInt" : "5" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','regex'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Invalid read of boolean in state IN_BSON_TYPE' LINE 1: ... from collection('db', 'regex') where document @@ '{"b": {"$... ^ -- SELECT sku SELECT count(*) sku from collection('db', 'regex') where document @@ '{"b": {"$regex": "", "$options": ""} }'; sku --------------------------------------------------------------------- 15 (1 row) -- 100 to 103 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\bline\\b", "$options" : "" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } { "_id" : { "$numberInt" : "101" }, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" } { "_id" : { "$numberInt" : "102" }, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" } { "_id" : { "$numberInt" : "103" }, "b" : "xyz789", "description" : "this is Multiple\nline description" } (4 rows) -- No records. Will try to match \\y (as a char) in the document SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\\\yline\\\\y", "$options" : "" } }'; document --------------------------------------------------------------------- (0 rows) -- 109 Match \y as a char. For libbson \y is a special char. So to \y it needs to be escaped as \\y and for \\y, we need to provide as \\\\y SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\\\\ycline", "$options" : "" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "109" }, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription" } (1 row) -- 107 Match a where a's value was inserted as a Regular expression object. Here \b will not be used as a flag. This entire regular expression object (/a\bcde\b/) will be compared (as such) against the regular expression object that was inserted. This is like regex is compared with another regex. SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$regularExpression" : { "pattern" : "a\bcde\b", "options" : "" } }}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "107" }, "a" : { "$regularExpression" : { "pattern" : "a\bcde\b", "options" : "" } } } (1 row) -- 110 (Same as 107 match above.) --SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$regularExpression" : { "pattern": "a\\ycde\\y", "options" : ""} } }'; -- 100 and 101 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "le.*\\bline\\b", "$options" : "" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } { "_id" : { "$numberInt" : "101" }, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" } (2 rows) -- 105 Matching \b as a normal char inside the string. SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\bcline \bdescription", "$options" : "" } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "105" }, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" } (1 row) -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": { "$options": "i", "$regex": " line " } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } (1 row) -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": {"$regex": " line ","$options": "i"}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "100" }, "b" : "abc123", "description" : "this is single line " } (1 row) -- 106 108 SELECT document from collection('db', 'regex') where document @@ '{ "a" : { "$regularExpression" : { "pattern" : "hello", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "106" }, "a" : "hello a\bcde world" } { "_id" : { "$numberInt" : "108" }, "a" : { "$regularExpression" : { "pattern" : "hello", "options" : "" } } } (2 rows) -- 120 SELECT document from collection('db', 'regex') where document @@ '{ "number" : { "$regularExpression" : { "pattern" : "༣", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "120" }, "number" : "୩༢༣༤༥" } (1 row) -- 121 122 if ascii digits are present SELECT document from collection('db', 'regex') where document @@ '{ "number" : { "$regularExpression" : { "pattern" : "[[:digit:]]", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "121" }, "number" : "02191996" } { "_id" : { "$numberInt" : "122" }, "number" : "9୩୪୬୯678" } (2 rows) -- 131 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "(*UTF)정", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "131" }, "text" : "박정수" } (1 row) -- 131 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "\\p{Hangul}", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "131" }, "text" : "박정수" } (1 row) -- 130 131 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Xan}+$", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "text" : "kyle" } { "_id" : { "$numberInt" : "131" }, "text" : "박정수" } { "_id" : { "$numberInt" : "132" }, "text" : "Fernández" } (3 rows) -- 130 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Latin}", "options" : "" } } } '; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "130" }, "text" : "kyle" } { "_id" : { "$numberInt" : "132" }, "text" : "Fernández" } (2 rows) -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache. SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } (2 rows) BEGIN; /* Make use of Index */ SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } (2 rows) ROLLBACK; BEGIN; /* Make use of Index */ SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using "Compound_index_on_a_and_b" on documents_3350_335000 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "b" : { "$regularExpression" : { "pattern" : "b va.ue", "options" : "" } } }'::documentdb_core.bson)) (7 rows) ROLLBACK; -- shard the collection by "_id" select documentdb_api.shard_collection('db', 'regex', '{"_id": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) BEGIN; SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query on sharded collection. Index Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query on sharded collection. Index Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using "Compound_index_on_a_and_b" on documents_3350_335016 documents_3350 Index Cond: ((document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "b" : { "$regularExpression" : { "pattern" : "b va.ue", "options" : "" } } }'::documentdb_core.bson)) (7 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; -- 111 117 Multiple regex in a single query on sharded collection. Seq Scan Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; -- 111 117 Multiple regex in a single query on sharded collection. Seq Scan Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_3350_335016 documents_3350 Filter: ((document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "b" : { "$regularExpression" : { "pattern" : "b va.ue", "options" : "" } } }'::documentdb_core.bson)) (7 rows) ROLLBACK; SELECT drop_collection('db','regex') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) SELECT create_collection('db','regex'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"a": 1}, "name": "index_on_a"}]}', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- shard the collection by "a" select documentdb_api.shard_collection('db', 'regex', '{"a": "hashed"}', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT insert_one('db','regex', '{"_id" : 106, "a" : "hello a\bcde world" }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"pattern" : "hello", "options" : ""}} }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "0" }, "code" : { "$numberInt" : "1088" }, "errmsg" : "A shard key is not allowed to include any regular expression pattern." } ] } (1 row) SELECT insert_one('db','regex', '{"_id" : 111, "a" : "a value", "b": "b value"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 116, "a" : "v6", "b": "bv6"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) BEGIN; SET LOCAL enable_seqscan to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Index Path SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Index Path EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Bitmap Heap Scan on documents_3351_335040 documents_3351 Recheck Cond: (document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) Filter: (document OPERATOR(documentdb_api_catalog.@~) '{ "b" : { "$regularExpression" : { "pattern" : "b va.ue", "options" : "" } } }'::documentdb_core.bson) -> Bitmap Index Scan on index_on_a Index Cond: (document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) (10 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Seq Scan Path SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "117" }, "a" : "a value7", "b" : "b value7" } { "_id" : { "$numberInt" : "111" }, "a" : "a value", "b" : "b value" } (2 rows) ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Seq Scan Path EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 8 Tasks Shown: One of 8 -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_3351_335040 documents_3351 Filter: ((document OPERATOR(documentdb_api_catalog.@~) '{ "a" : { "$regularExpression" : { "pattern" : "a.vaLue", "options" : "i" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "b" : { "$regularExpression" : { "pattern" : "b va.ue", "options" : "" } } }'::documentdb_core.bson)) (7 rows) ROLLBACK; SELECT drop_collection('db','regex') IS NOT NULL; ?column? --------------------------------------------------------------------- t (1 row) regex5_tests_explain.out000066400000000000000000000360341507310017400346730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 1010000; SET documentdb.next_collection_id TO 101000; SET documentdb.next_collection_index_id TO 101000; SELECT insert_one('db','regex5', '{"x": "ayc"}'); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"x": ["abc", "xyz1"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"x": ["acd", "xyz23"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"F1" : "F1_value", "x": ["first regular expression", "second expression", "third value for x"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"F1" : "F1_value2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex5'); drop_primary_key --------------------------------------------------------------------- (1 row) \set prevEcho :ECHO \set ECHO none -- -- FORCING INDEX PATH -- BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- When x is non-array EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : ".*Yc", "$options": "i"}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : ".*Yc", "options" : "i" } } ] }'::documentdb_core.bson) (7 rows) -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : "^.*cd", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- When x'z value is array and regex matches second element of 2nd record and 3rd element in the 4th record. EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : "x.+1", "options" : "" } }, { "$regularExpression" : { "pattern" : "value .+ x", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Without any regex EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": ["acd", "first regular expression"]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "acd", "first regular expression" ] }'::documentdb_core.bson) (7 rows) -- Mix of Regex and text EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "second expression", { "$regularExpression" : { "pattern" : "xy.1", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Test for hasNull (10 filler records and 3 actual records to match) EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "second expression", null, { "$regularExpression" : { "pattern" : "xy.1", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Test for $all EXPLAIN (COSTS OFF) SELECT document FROM collection('db','regex5') WHERE document @@ '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Index Scan using index_wc on documents_101000_1010007 collection Index Cond: ((document OPERATOR(documentdb_api_catalog.@~) '{ "x" : { "$regularExpression" : { "pattern" : "expression", "options" : "" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "x" : { "$regularExpression" : { "pattern" : "value .+ x", "options" : "" } } }'::documentdb_core.bson)) (7 rows) ROLLBACK; -- -- RUN TIME PATH -- -- When x is non-array EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : ".*yc", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : ".*yc", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : "^.*cd", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- When x'z value is array and regex matches second element of 2nd record and 3rd element in the 4th record. EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ { "$regularExpression" : { "pattern" : "x.+1", "options" : "" } }, { "$regularExpression" : { "pattern" : "value .+ x", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Without any regex EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": ["acd", "first regular expression"]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "acd", "first regular expression" ] }'::documentdb_core.bson) (7 rows) -- Mix of Regex and text EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "second expression", { "$regularExpression" : { "pattern" : "xy.1", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Test for hasNull (10 filler records and 3 actual records to match) EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: (document OPERATOR(documentdb_api_catalog.@*=) '{ "x" : [ "second expression", null, { "$regularExpression" : { "pattern" : "xy.1", "options" : "" } } ] }'::documentdb_core.bson) (7 rows) -- Test for $all EXPLAIN (COSTS OFF) SELECT document FROM collection('db','regex5') WHERE document @@ '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; QUERY PLAN --------------------------------------------------------------------- Custom Scan (Citus Adaptive) Task Count: 1 Tasks Shown: All -> Task Node: host=localhost port=58070 dbname=regression -> Seq Scan on documents_101000_1010007 collection Filter: ((document OPERATOR(documentdb_api_catalog.@~) '{ "x" : { "$regularExpression" : { "pattern" : "expression", "options" : "" } } }'::documentdb_core.bson) AND (document OPERATOR(documentdb_api_catalog.@~) '{ "x" : { "$regularExpression" : { "pattern" : "value .+ x", "options" : "" } } }'::documentdb_core.bson)) (7 rows) SELECT drop_collection('db','regex5'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA regex5 CASCADE; regex5_tests_index.out000066400000000000000000000261001507310017400343330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 90000; SET documentdb.next_collection_id TO 900; SET documentdb.next_collection_index_id TO 900; SELECT create_collection('db','regex5'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \set prevEcho :ECHO \set ECHO none BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/regex5_tests_core.sql CREATE OR REPLACE FUNCTION assert_count_regex5(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex5') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex5', '{"_id": 1, "x": "ayc"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 2, "x": "xValue2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 3, "x": ["abc", "xyz1"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 4, "x": ["acd", "xyz23"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 5, "F1" : "F1_value", "x": ["first regular expression", "second expression", "third value for x"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 6, "F1" : "F1_value2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 7, "F1" : "this is the new value, done"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 8, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 9, "F1" : "hi, new y \\yvalue\\y; fine"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex5', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex5'); drop_primary_key --------------------------------------------------------------------- (1 row) -- When x is non-array SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : ".*Yc", "$options": "i"}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- When x's value is array and regex matches second element of 3rd record and 3rd element in the 5th record. SELECT assert_count_regex5(2, '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Without any regex SELECT assert_count_regex5(2, '{"x": {"$in": ["acd", "first regular expression"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Mix of Regex and text SELECT assert_count_regex5(2, '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for hasNull (10 filler records and 4 actual records to match) SELECT assert_count_regex5(16, '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*yc", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. With one REGEX and one normal string. SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz1", "xValue1"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. Two documents will match the $nin array. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz23", "xValue1"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. Single REGEX. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : "^a.c", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null (only null and single null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null (only null and multiple null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null, null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null SELECT assert_count_regex5(3, '{"x": {"$nin": [null, "second expression", {"$regex" : "xy.1", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. With all REGEX SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. With one REGEX and one normal string. SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "^.cd", "$options": ""}, "xyz23"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Empty array SELECT assert_count_regex5(0, '{"x": {"$all": []}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Single regex SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex": "^.V.+2$", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Single string and no regex SELECT assert_count_regex5(1, '{"x": {"$all": ["xValue2"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with null in the $all array SELECT assert_count_regex5(0, '{"x": {"$all": [null, {"$regex": "xValu.+2$", "$options": ""} ]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with only null in the $all array SELECT assert_count_regex5(14, '{"x": {"$all": [null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with only null in the $all array (with multiple null) SELECT assert_count_regex5(14, '{"x": {"$all": [null, null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) SELECT assert_count_regex5(4, '{"F1": {"$regex" : "Value", "$options": "i"}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) select document from collection('db','regex5') where document @@ '{"F1": {"$regex" : "word \bval\bue\b,", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done" } (1 row) select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "word \bval\bue\b,", "options" : "" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done" } (1 row) -- Work as word boundary {"F1" : "this is the new value, done"} select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\bValue\\b", "options" : "i" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "F1" : "this is the new value, done" } (1 row) -- rec 9 select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\\\yValue\\\\y", "options" : "i" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "F1" : "hi, new y \\yvalue\\y; fine" } (1 row) ROLLBACK; SELECT drop_collection('db','regex5'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA regex5 CASCADE; regex5_tests_runtime.out000066400000000000000000000257471507310017400347270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 90000; SET documentdb.next_collection_id TO 900; SET documentdb.next_collection_index_id TO 900; SELECT create_collection('db','regex5'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) BEGIN; set local enable_seqscan TO ON; \i sql/regex5_tests_core.sql CREATE OR REPLACE FUNCTION assert_count_regex5(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex5') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex5', '{"_id": 1, "x": "ayc"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 2, "x": "xValue2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 3, "x": ["abc", "xyz1"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 4, "x": ["acd", "xyz23"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 5, "F1" : "F1_value", "x": ["first regular expression", "second expression", "third value for x"]}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 6, "F1" : "F1_value2"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 7, "F1" : "this is the new value, done"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 8, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex5', '{"_id": 9, "F1" : "hi, new y \\yvalue\\y; fine"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex5', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex5'); drop_primary_key --------------------------------------------------------------------- (1 row) -- When x is non-array SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : ".*Yc", "$options": "i"}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- When x's value is array and regex matches second element of 3rd record and 3rd element in the 5th record. SELECT assert_count_regex5(2, '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Without any regex SELECT assert_count_regex5(2, '{"x": {"$in": ["acd", "first regular expression"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Mix of Regex and text SELECT assert_count_regex5(2, '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for hasNull (10 filler records and 4 actual records to match) SELECT assert_count_regex5(16, '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*yc", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. With one REGEX and one normal string. SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz1", "xValue1"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. Two documents will match the $nin array. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz23", "xValue1"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. Single REGEX. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : "^a.c", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null (only null and single null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null (only null and multiple null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null, null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $nin. with null SELECT assert_count_regex5(3, '{"x": {"$nin": [null, "second expression", {"$regex" : "xy.1", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. With all REGEX SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. With one REGEX and one normal string. SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "^.cd", "$options": ""}, "xyz23"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Empty array SELECT assert_count_regex5(0, '{"x": {"$all": []}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Single regex SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex": "^.V.+2$", "$options": ""}]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. Single string and no regex SELECT assert_count_regex5(1, '{"x": {"$all": ["xValue2"]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with null in the $all array SELECT assert_count_regex5(0, '{"x": {"$all": [null, {"$regex": "xValu.+2$", "$options": ""} ]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with only null in the $all array SELECT assert_count_regex5(14, '{"x": {"$all": [null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) -- Test for $all. with only null in the $all array (with multiple null) SELECT assert_count_regex5(14, '{"x": {"$all": [null, null]}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) SELECT assert_count_regex5(4, '{"F1": {"$regex" : "Value", "$options": "i"}}'); assert_count_regex5 --------------------------------------------------------------------- (1 row) select document from collection('db','regex5') where document @@ '{"F1": {"$regex" : "word \bval\bue\b,", "$options": ""}}'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done" } (1 row) select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "word \bval\bue\b,", "options" : "" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "8" }, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done" } (1 row) -- Work as word boundary {"F1" : "this is the new value, done"} select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\bValue\\b", "options" : "i" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "7" }, "F1" : "this is the new value, done" } (1 row) -- rec 9 select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\\\yValue\\\\y", "options" : "i" } } }'; document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "9" }, "F1" : "hi, new y \\yvalue\\y; fine" } (1 row) ROLLBACK; SELECT drop_collection('db','regex5'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA regex5 CASCADE; regex_options_index.out000066400000000000000000000206571507310017400346120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA regex_options; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex_options; SET citus.next_shard_id TO 80000; SET documentdb.next_collection_id TO 800; SET documentdb.next_collection_index_id TO 800; SELECT create_collection('db','regex_options'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \set prevEcho :ECHO \set ECHO none BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/regex_options_core.sql CREATE OR REPLACE FUNCTION assert_count_regex_options(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex_options') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex_options', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and without extended match flag (x) SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and with extended match flag (x) SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line when s flag is set. SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- multiline match flag SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line and case insensitive match SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus -- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will error out because $options needed a $regex. SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}'; psql:sql/regex_options_core.sql:79: ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Missing "$regex" after "$options"' LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"msg": {... ^ ROLLBACK; SELECT drop_collection('db','regex_options'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA regex_options CASCADE; regex_options_runtime.out000066400000000000000000000205271507310017400351620ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedCREATE SCHEMA regex_options; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex_options; SET citus.next_shard_id TO 700000; SET documentdb.next_collection_id TO 700; SET documentdb.next_collection_index_id TO 700; SELECT create_collection('db','regex_options'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) BEGIN; set local enable_seqscan TO ON; \i sql/regex_options_core.sql CREATE OR REPLACE FUNCTION assert_count_regex_options(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex_options') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex_options', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options'); drop_primary_key --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and without extended match flag (x) SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- With comment and space in pattern and with extended match flag (x) SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line when s flag is set. SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- multiline match flag SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- . matches new line and case insensitive match SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus -- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); assert_count_regex_options --------------------------------------------------------------------- (1 row) -- This will error out because $options needed a $regex. SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}'; psql:sql/regex_options_core.sql:79: ERROR: invalid input syntax JSON for BSON: Code: '2', Message 'Missing "$regex" after "$options"' LINE 1: ...ollection('db','regex_options') WHERE document @@ '{"msg": {... ^ ROLLBACK; SELECT drop_collection('db','regex_options'); drop_collection --------------------------------------------------------------------- t (1 row) DROP SCHEMA regex_options CASCADE; schema_validation.out000066400000000000000000001166651507310017400342150ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 17770000; SET documentdb.next_collection_id TO 177700; SET documentdb.next_collection_index_id TO 177700; -- create a collection and insert a document SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); ERROR: validator not supported yet set documentdb.enableSchemaValidation = true; SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ { "name" : "col", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col'; validator | validation_level | validation_action --------------------------------------------------------------------- { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "int" } } } } | strict | error (1 row) -- create again without schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col"}'); ERROR: Namespace schema_validation.col already exists but with different configuration options: { "validator" : { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "int" } } } }, "validationLevel" : "strict", "validationAction" : "error" } -- create again without schema validation level SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationAction": "warn"}'); ERROR: Namespace schema_validation.col already exists but with different configuration options: { "validator" : { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "int" } } } }, "validationLevel" : "strict", "validationAction" : "error" } -- create again without schema validation action SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "moderate"}'); ERROR: Namespace schema_validation.col already exists but with different configuration options: { "validator" : { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "int" } } } }, "validationLevel" : "strict", "validationAction" : "error" } -- create with unmatched schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"b": {"bsonType": "string"}}}}, "validationLevel": "strict", "validationAction": "error"}'); ERROR: Namespace schema_validation.col already exists but with different configuration options: { "validator" : { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "int" } } } }, "validationLevel" : "strict", "validationAction" : "error" } -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create collection without schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col3" }, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ { "name" : "col3", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col3'; validator | validation_level | validation_action --------------------------------------------------------------------- | | (1 row) -- create again with schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}}'); ERROR: Namespace schema_validation.col3 already exists but with different configuration options: { } -- create again with schema validation level SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validationLevel": "strict"}'); ERROR: Namespace schema_validation.col3 already exists but with different configuration options: { } -- create again with schema validation action SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validationAction": "error"}'); ERROR: Namespace schema_validation.col3 already exists but with different configuration options: { } -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3"}'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- create collection with schema validatorAction SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validationLevel": "strict"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col4" }, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ { "name" : "col4", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col4'; validator | validation_level | validation_action --------------------------------------------------------------------- | strict | error (1 row) -- create again with schema validatorAction SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}}'); ERROR: Namespace schema_validation.col4 already exists but with different configuration options: { "validationLevel" : "strict", "validationAction" : "error" } -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validationLevel": "strict"}'); create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) set documentdb.enableSchemaValidation = false; -- update validation action SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "warn"}'); ERROR: validator not supported yet set documentdb.enableSchemaValidation = true; SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "warn"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "string"}}}}}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- get updated collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col" }, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ { "name" : "col", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col'; validator | validation_level | validation_action --------------------------------------------------------------------- { "$jsonSchema" : { "bsonType" : "object", "properties" : { "a" : { "bsonType" : "string" } } } } | strict | warn (1 row) -- insert a document with type mismatch -- SELECT documentdb_api.insert('schema_validation','{"insert":"col", "documents":[{"_id":"8", "a":"yy"}]}'); -- SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation','col'); -- update: ignore validation when action = warn -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":1},"u":{"$set":{"a":"tt"}}}]}'); -- SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "error"}'); -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":2},"u":{"$set":{"a":"ss"}},"multi":true}]}'); -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":"yy"},"u":{"$set":{"a":"yyy"}}}]}'); -- update validation level -- SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationLevel": "moderate"}'); -- update document with type mismatch -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":"yy"},"u":{"$set":{"a":"yyy"}},"multi":true}]}'); -- SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation','col'); -- validator without $jsonSchema SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col1", "validator": {"a":{"$type":"int"}}, "validationLevel": "strict", "validationAction": "error"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col1" }, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ { "name" : "col1", "type" : "collection" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col1'; validator | validation_level | validation_action --------------------------------------------------------------------- { "a" : { "$type" : "int" } } | strict | error (1 row) -- select documentdb_api.insert('schema_validation', '{"insert":"col1", "documents":[{"_id":"1", "a":1}]}'); -- select documentdb_api.insert('schema_validation', '{"insert":"col1", "documents":[{"_id":"1", "a":"hello"}]}'); -- validator > 10k throw error SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col2", "validator": {"$jsonSchema":{"bsonType":"object","properties":{"name":{"bsonType":"string","description":"The name of the entity"},"age":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_1":{"bsonType":"string","description":"The name of the entity"},"age_1":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_1":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_1":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_1":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_1":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_1":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_2":{"bsonType":"string","description":"The name of the entity"},"age_2":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_2":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_2":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_2":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_2":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_2":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_3":{"bsonType":"string","description":"The name of the entity"},"age_3":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_3":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_3":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_3":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_3":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_3":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_4":{"bsonType":"string","description":"The name of the entity"},"age_4":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_4":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_4":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_4":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_4":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_4":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about theentity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_5":{"bsonType":"string","description":"The name of the entity"},"age_5":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_5":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_5":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_5":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_5":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"Listof contacts"},"info_5":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_6":{"bsonType":"string","description":"The name of the entity"},"age_6":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_6":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_6":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_6":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_6":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type:phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_6":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_7":{"bsonType":"string","description":"The name of the entity"},"age_7":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_7":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_7":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_7":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_7":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_7":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"largeField1":{"bsonType":"string","description":"A large field to increase validator size"},"largeField2":{"bsonType":"int","description":"Another large field to increase validator size"},"largeTextField":{"bsonType":"string","description":"A very large text field"}},"required":["name","age"]}}}'); ERROR: validator of size > 10KB is not supported. Contact Azure Support if you need to increase this limit. SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col2" }, "nameOnly": true }'); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation.$cmd.ListCollections", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- increase maxSchemaValidatorSize to 20KB SET documentdb.maxSchemaValidatorSize = 20480; SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col2", "validator": {"$jsonSchema":{"bsonType":"object","properties":{"name":{"bsonType":"string","description":"The name of the entity"},"age":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_1":{"bsonType":"string","description":"The name of the entity"},"age_1":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_1":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_1":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_1":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_1":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_1":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_2":{"bsonType":"string","description":"The name of the entity"},"age_2":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_2":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_2":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_2":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_2":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_2":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_3":{"bsonType":"string","description":"The name of the entity"},"age_3":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_3":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_3":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_3":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_3":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_3":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_4":{"bsonType":"string","description":"The name of the entity"},"age_4":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_4":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_4":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_4":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_4":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_4":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about theentity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_5":{"bsonType":"string","description":"The name of the entity"},"age_5":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_5":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_5":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_5":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_5":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"Listof contacts"},"info_5":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_6":{"bsonType":"string","description":"The name of the entity"},"age_6":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_6":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_6":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_6":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_6":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type:phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_6":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_7":{"bsonType":"string","description":"The name of the entity"},"age_7":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_7":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_7":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_7":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_7":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_7":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"largeField1":{"bsonType":"string","description":"A large field to increase validator size"},"largeField2":{"bsonType":"int","description":"Another large field to increase validator size"},"largeTextField":{"bsonType":"string","description":"A very large text field"}},"required":["name","age"]}}}'); ERROR: Unknown $jsonSchema keyword: description SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validator": { "$and": [ { "a": { "$gt": 2 } }, {"$jsonSchema": {"bsonType": "obect", "properties": {"a": {"bsonType": "int", "maximum":5}}}} ] } }'); ERROR: Unrecognized data type alias: obect SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validator": { "$jsonSchema": {"bsonType": "obect", "properties": {"a": {"bsonType": "int", "maximum":5}}}} } '); ERROR: Unrecognized data type alias: obect SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col5", "validator": { "$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum":"str"}}}} } '); ERROR: $jsonSchema keyword 'maximum' must be a number SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col6", "validator": { "$jsonSchema": {"bsonType": "object", "required":["a"]}} }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) schema_validation_insert.out000066400000000000000000002067551507310017400356010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 17771000; SET documentdb.next_collection_id TO 177710; SET documentdb.next_collection_index_id TO 177710; set documentdb.enableSchemaValidation = true; --------------------------------------Need $jsonSchema-------------------------------------- SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col", "documents":[{"_id":"1", "a":1}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- required not supported yet, so this should be inserted SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col", "documents":[{"_id":"2", "b":1}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- type mismatch SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"3", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- batch insert SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"4", "a":2},{"_id":"5", "a":3}, {"_id":"6", "a":"tt"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""2"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""2"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- 0 documents should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177711 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177711 | { "" : "2" } | { "_id" : "2", "b" : { "$numberInt" : "1" } } 177711 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "2" } } 177711 | { "" : "5" } | { "_id" : "5", "a" : { "$numberInt" : "3" } } (4 rows) -- set validationAction to warn SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col', '{"collMod":"col", "validationAction": "warn"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"7", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- 1 document should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177711 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177711 | { "" : "2" } | { "_id" : "2", "b" : { "$numberInt" : "1" } } 177711 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "2" } } 177711 | { "" : "5" } | { "_id" : "5", "a" : { "$numberInt" : "3" } } 177711 | { "" : "7" } | { "_id" : "7", "a" : "hello" } (5 rows) ---------------------------------------------Need top level operator----------------------------------------------------- -- $expr SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col1", "validator": { "$expr": {"$eq": [ "$a", "$b" ] } } }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col1", "documents":[{"_id":"1", "a":1, "b":1, "c":1}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col1", "documents":[{"_id":"2", "a":3, "b":1, "c":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- $and SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col2", "validator": { "$and": [ { "a": { "$gt": 2 } }, {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum":5}}}} ] } }'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"1", "a":4}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"2", "a":1}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- expect to throw error as 6 > 5 (maximum) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"3", "a":6}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) set documentdb.enableBypassDocumentValidation = true; SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"2", "a":1}], "bypassDocumentValidation": true}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) ---------------------------------------------simple case----------------------------------------------------- -- field SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col3", "validator": {"a":{"$type":"int"}}}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"1", "a":1}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"2", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) --$merge SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col_", "documents":[{"_id":"1001","a":"world"}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col_", "documents":[{"_id":"1002","a":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) select documentdb_api.insert('schema_validation_insertion', '{"insert":"col_", "documents":[{"_id":"1003","a":11}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- whenNotMatch is insert SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1001"}}, {"$merge" : { "into": "col3" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1002"}}, {"$merge" : { "into": "col3" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : { "$numberInt" : "2" } } (2 rows) -- WhenNotMatched is discard SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1003"}}, {"$merge" : { "into": "col3", "whenNotMatched": "discard" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : { "$numberInt" : "2" } } (2 rows) -- whenMatched is merge SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":22}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : { "$numberInt" : "22" } } (2 rows) ---- don't throw error as source and target schema is same SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"merge_same"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"merge_same"}}}],"bypassDocumentValidation": true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : "merge_same" } (2 rows) ---- throw error as source and target schema is different since key is same but value is different SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":22}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation -- whenMatched is replace select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":222, "b":1}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : { "$numberInt" : "222" }, "b" : { "$numberInt" : "1" } } (2 rows) ---- don't throw error as source and target schema is same SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"replace_same"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"replace_same"}}}],"bypassDocumentValidation": true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : "replace_same", "b" : { "$numberInt" : "1" } } (2 rows) ---- throw error as source and target schema is different SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":222, "b":1}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation -- validationLevel is moderate select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : { "$numberInt" : "222" }, "b" : { "$numberInt" : "1" } } (2 rows) SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "moderate"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) select documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test_3"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) select documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test_3"}}}], "bypassDocumentValidation": true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : "test", "b" : { "$numberInt" : "1" } } (2 rows) select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"ttt"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177714 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } 177714 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } (2 rows) --$out select documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col5"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "string" }}}, {"$out": "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177716 | { "" : "1001" } | { "_id" : "1001", "a" : "world" } 177716 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } (2 rows) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "int" }}}, {"$out": "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177716 | { "" : "1003" } | { "_id" : "1003", "a" : { "$numberInt" : "11" } } (1 row) SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col5', '{"collMod":"col5", "validator": {"a":{"$type":"int"}}}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "string" }}}, {"$out" : "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "int" }}}, {"$out" : "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177716 | { "" : "1003" } | { "_id" : "1003", "a" : { "$numberInt" : "11" } } (1 row) -- sharded collection test SELECT documentdb_api.shard_collection('schema_validation_insertion', 'col3', '{ "a": "hashed" }', false); shard_collection --------------------------------------------------------------------- (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"1", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""0"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"2", "a":5}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"3", "a":2}, {"_id":"4", "a":3}, {"_id":"5", "a":4}, {"_id":"6", "a":"string"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- 5 documents should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- -8397265933852323338 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } -4918719581749358852 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "3" } } -1389566185330078543 | { "" : "3" } | { "_id" : "3", "a" : { "$numberInt" : "2" } } 1786987034919379147 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "5" } } 4004935074940511305 | { "" : "5" } | { "_id" : "5", "a" : { "$numberInt" : "4" } } 4322365043291501017 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } (6 rows) -- set validationAction to warn SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationAction": "warn"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col3", "documents":[{"_id":"7", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- 6 document should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- -8397265933852323338 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } -4918719581749358852 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "3" } } -1389566185330078543 | { "" : "3" } | { "_id" : "3", "a" : { "$numberInt" : "2" } } 1786987034919379147 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "5" } } 3587377943449965360 | { "" : "7" } | { "_id" : "7", "a" : "hello" } 4004935074940511305 | { "" : "5" } | { "_id" : "5", "a" : { "$numberInt" : "4" } } 4322365043291501017 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "1" } } (7 rows) SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "strict"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) ---------------------------------------------update----------------------------------------------------- -- sharded collection test -- will succeed as validationAction is warn SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a": 1},"u":{"$set":{"a":"one"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- set validation action to error SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationAction": "error"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- should throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":4},"u":{"$set":{"a":"four"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- should succeed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":3},"u":{"$set":{"a":300}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- upsert succeeded SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"abc"},"u":{"$set":{"_id":500, "a":500}}, "upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""500"" } } ] }",t) (1 row) -- upsert failed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"abc"},"u":{"$set":{"a":"abcd"}}, "upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- should succeed with bypassDocumentValidation SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":4},"u":{"$set":{"a":"four"}}}], "bypassDocumentValidation": true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- multiple updates -- throw error as multi update is not allowed on sharded collection SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":2},"u":{"$set":{"a":200}}, "multi":true} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""319029277"" }, ""errmsg"" : ""Invalid write detected. Please validate the collection and/or shard key being written to"" } ] }",f) (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3'); shard_key_value | object_id | document --------------------------------------------------------------------- -1389566185330078543 | { "" : "3" } | { "_id" : "3", "a" : { "$numberInt" : "2" } } 2996843418540442358 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "300" } } -8397265933852323338 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } 5126337298865006124 | { "" : "5" } | { "_id" : "5", "a" : "four" } 6587320470102004679 | { "" : { "$numberInt" : "500" } } | { "_id" : { "$numberInt" : "500" }, "a" : { "$numberInt" : "500" } } 3587377943449965360 | { "" : "7" } | { "_id" : "7", "a" : "hello" } 1786987034919379147 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "5" } } 1872533437322552880 | { "" : "1" } | { "_id" : "1", "a" : "one" } (8 rows) -- will throw error as validationLevel is strict SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- moderate case SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "moderate"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- will succeed as validationLevel is moderate SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3'); shard_key_value | object_id | document --------------------------------------------------------------------- 3501436727987220735 | { "" : "5" } | { "_id" : "5", "a" : "fourty" } -1389566185330078543 | { "" : "3" } | { "_id" : "3", "a" : { "$numberInt" : "2" } } 2996843418540442358 | { "" : "4" } | { "_id" : "4", "a" : { "$numberInt" : "300" } } -8397265933852323338 | { "" : "1002" } | { "_id" : "1002", "a" : "ttt", "b" : { "$numberInt" : "1" } } 6587320470102004679 | { "" : { "$numberInt" : "500" } } | { "_id" : { "$numberInt" : "500" }, "a" : { "$numberInt" : "500" } } 3587377943449965360 | { "" : "7" } | { "_id" : "7", "a" : "hello" } 1786987034919379147 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "5" } } 1872533437322552880 | { "" : "1" } | { "_id" : "1", "a" : "one" } (8 rows) -- batch update SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":500},"u":{"$set":{"a":5000}}}, {"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}}, {"q":{"a":6},"u":{"$set":{"a":600, "_id":600}}, "upsert": true}, {"q":{"a":"string"},"u":{"$set":{"a":"str"}}, "upsert":true} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""2"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""2"" }, ""_id"" : { ""$numberInt"" : ""600"" } } ], ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""3"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) --unsharded collection test SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col4", "validator": {"a":{"$type":"int"}}, "validationLevel": "strict", "validationAction": "warn"}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col4", "documents":[{"_id":"1", "a":1}, {"_id":"2", "a":2}, {"_id":"3", "a":3}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col4", "documents":[{"_id":"4", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- will succeed as validationAction is warn SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":1},"u":{"$set":{"a":"one"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col4', '{"collMod":"col4", "validationAction": "error"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- should throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":2},"u":{"$set":{"a":"one"}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- should succeed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":3},"u":{"$set":{"a":300}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- upsert succeeded SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"abc"},"u":{"$set":{"_id":500, "a":500}}, "upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""1"" }, ""upserted"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""_id"" : { ""$numberInt"" : ""500"" } } ] }",t) (1 row) -- upsert failed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"abc"},"u":{"$set":{"a":"abcd"}}, "upsert":true}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- should succeed with bypassDocumentValidation SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":2},"u":{"$set":{"a":"one"}}}], "bypassDocumentValidation": true}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- multiple updates SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"one"},"u":{"$set":{"a":200}}, "multi":true} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""2"" }, ""n"" : { ""$numberInt"" : ""2"" } }",t) (1 row) -- will throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":300},"u":{"$set":{"a":"th"}}, "multi":true} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- will throw error as validationLevel is strict SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"hello"},"u":{"$set":{"a":"world"}}} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" }, ""writeErrors"" : [ { ""index"" : { ""$numberInt"" : ""0"" }, ""code"" : { ""$numberInt"" : ""525074461"" }, ""errmsg"" : ""Document failed validation"" } ] }",f) (1 row) -- moderate case SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col4', '{"collMod":"col4", "validationLevel": "moderate"}'); coll_mod --------------------------------------------------------------------- { "ok" : { "$numberInt" : "1" } } (1 row) -- will succeed as validationLevel is moderate SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"hello"},"u":{"$set":{"a":"ten"}}} ]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col4'); shard_key_value | object_id | document --------------------------------------------------------------------- 177717 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "200" } } 177717 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "200" } } 177717 | { "" : "3" } | { "_id" : "3", "a" : { "$numberInt" : "300" } } 177717 | { "" : "4" } | { "_id" : "4", "a" : "ten" } 177717 | { "" : { "$numberInt" : "500" } } | { "_id" : { "$numberInt" : "500" }, "a" : { "$numberInt" : "500" } } (5 rows) -------------------------------merge/out more case--------------------------------------------------------------- -- top level operator in schema information SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col_merge_tar", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "minimum": 5}}}}}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"1", "a":5}]}'); NOTICE: creating collection insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"2", "a":2}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"3", "a":"hello"}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""1"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- $merge SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "2" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "3" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177718 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "5" } } (1 row) -- merge with whenMatched select documentdb_api.update('schema_validation_insertion', '{"update":"col_source", "updates":[{"q":{"_id":"1"},"u":{"$set":{"a":11, "b":1}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177718 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "11" }, "b" : { "$numberInt" : "1" } } (1 row) select documentdb_api.update('schema_validation_insertion', '{"update":"col_source", "updates":[{"q":{"_id":"1"},"u":{"$set":{"a":111}, "$unset":{"b":""}}}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177718 | { "" : "1" } | { "_id" : "1", "a" : { "$numberInt" : "111" } } (1 row) -- $out SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col_out_tar", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum": 5}}}}}'); NOTICE: creating collection create_collection_view --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "2" }}, {"$out" : "col_out_tar" } ], "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "schema_validation_insertion.col_source", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_out_tar') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177720 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "2" } } (1 row) SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$out" : "col_out_tar" } ], "cursor": { "batchSize": 1 } }', 4294967294); ERROR: PlanExecutor error during aggregation :: caused by :: Document failed validation SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_out_tar') ORDER BY shard_key_value, object_id; shard_key_value | object_id | document --------------------------------------------------------------------- 177720 | { "" : "2" } | { "_id" : "2", "a" : { "$numberInt" : "2" } } (1 row) set documentdb.enableBypassDocumentValidation = false; set documentdb.enableSchemaValidation = false; setwindowfields_and_group_compliance.out000066400000000000000000014015571507310017400402030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 884500; SET documentdb.next_collection_id TO 88450; SET documentdb.next_collection_index_id TO 88450; CREATE SCHEMA setWindowFieldSchema; -- The test is intended to set an agreement between the setwindowfields and group aggregate operators -- to be working on both cases (if implemented) -- [Important] - When any operator is supported for both $group and $setWindowFields then please remove it from here. CREATE OR REPLACE FUNCTION get_unsupported_operators() RETURNS TABLE(unsupported_operator text) AS $$ BEGIN RETURN QUERY SELECT unnest(ARRAY[ '$bottom', '$bottomN', '$maxN', '$median', '$minN', '$percentile', '$stdDevSamp', '$stdDevPop', '$top', '$topN' ]) AS unsupported_operator; END; $$ LANGUAGE plpgsql; -- Make a non-empty collection SELECT documentdb_api.insert_one('db','setWindowField_compliance','{ "_id": 1 }', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) DO $$ DECLARE operator text; errorMessage text; supportedInSetWindowFields BOOLEAN; supportedInGroup BOOLEAN; querySpec bson; BEGIN FOR operator IN SELECT * FROM get_unsupported_operators() LOOP supportedInSetWindowFields := TRUE; supportedInGroup := TRUE; querySpec := FORMAT('{ "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "test": {"%s": { } } }}]}', operator)::documentdb_core.bson; BEGIN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', querySpec); EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%Unknown group operator%' OR errorMessage LIKE '%not implemented%' THEN supportedInGroup := FALSE; END IF; END; querySpec := FORMAT('{ "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": { "field": { "%s": { } } } }}]}', operator)::documentdb_core.bson; BEGIN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', querySpec); EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%not supported%' THEN supportedInSetWindowFields := FALSE; END IF; END; IF supportedInSetWindowFields <> supportedInGroup THEN RAISE NOTICE '[TEST FAILED] Operator % is not supported in %', operator, CASE WHEN supportedInSetWindowFields THEN '$group' ELSE '$setWindowFields' END; ELSEIF supportedInSetWindowFields THEN RAISE NOTICE '[TEST PASSED] Operator % is supported in both $group and $setWindowFields', operator; ELSE RAISE NOTICE '[TEST PASSED] Operator % is not supported in both $group and $setWindowFields', operator; END IF; END LOOP; END $$; NOTICE: [TEST PASSED] Operator $bottom is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $bottomN is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $maxN is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $median is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $minN is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $percentile is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $stdDevSamp is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $stdDevPop is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $top is supported in both $group and $setWindowFields NOTICE: [TEST PASSED] Operator $topN is supported in both $group and $setWindowFields DROP SCHEMA setWindowFieldSchema CASCADE; CREATE OR REPLACE FUNCTION check_aggregates(num_elements int) RETURNS void AS $fn$ DECLARE bson_spec jsonb; bson_spec_str text; group_by_spec text; setwindowFields_spec text; groupResult bson; setwindowFieldsResult bson; groupExplainResult jsonb; setwindowFieldsExplainResult jsonb; i int; BEGIN -- Initialize the BSON spec as an empty JSONB object bson_spec := '{}'::jsonb; -- Loop to add 50 fields to the BSON spec FOR i IN 1..num_elements LOOP bson_spec := jsonb_set(bson_spec, ARRAY['field' || i::text], jsonb_build_object('$sum', 1)); END LOOP; -- Output the BSON spec bson_spec_str := bson_spec::text; RAISE NOTICE '\n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (%) =======================' , num_elements; group_by_spec := '{ "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", ' || substring(bson_spec_str, 2, length(bson_spec_str) - 2) || ' }}]}'; setwindowFields_spec := '{ "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": ' || bson_spec_str || ' }}]}'; SET citus.log_remote_commands = 'on'; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', group_by_spec::documentdb_core.bson) INTO groupResult; RAISE NOTICE E'\n=============\nGroup by\n=============\nQuery: %\n\nResult: %', group_by_spec, groupResult; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', setwindowFields_spec::documentdb_core.bson) INTO setwindowFieldsResult; RAISE NOTICE E'\n=============\nSetWindowFields\n=============\nQuery: %\n\nResult: %', setwindowFields_spec, setwindowFieldsResult; RESET citus.log_remote_commands; END; $fn$ LANGUAGE plpgsql; -- Check aggregates with different number of aggregation operators SELECT check_aggregates(30); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (30) ======================= NOTICE: executing the command locally: SELECT documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) SELECT check_aggregates(50); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (50) ======================= NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62, c63, c64, c65, c66, c67, c68, c69, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79, c80, c81, c82, c83, c84, c85, c86, c87, c88, c89, c90, c91, c92, c93, c94, c95, c96, c97, c98, c99, c100), documentdb_core.bson_repath_and_build(c101, c102), false) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62, 'field31'::text AS c63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c64, 'field32'::text AS c65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c66, 'field33'::text AS c67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c68, 'field34'::text AS c69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c70, 'field35'::text AS c71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c72, 'field36'::text AS c73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c74, 'field37'::text AS c75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c76, 'field38'::text AS c77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c78, 'field39'::text AS c79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c80, 'field40'::text AS c81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c82, 'field41'::text AS c83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c84, 'field42'::text AS c85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c86, 'field43'::text AS c87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c88, 'field44'::text AS c89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c90, 'field45'::text AS c91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c92, 'field46'::text AS c93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c94, 'field47'::text AS c95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c96, 'field48'::text AS c97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c98, 'field49'::text AS c99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c100, 'field50'::text AS c101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c102 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30, 'field31'::text, field31, 'field32'::text, field32, 'field33'::text, field33, 'field34'::text, field34, 'field35'::text, field35, 'field36'::text, field36, 'field37'::text, field37, 'field38'::text, field38, 'field39'::text, field39, 'field40'::text, field40, 'field41'::text, field41, 'field42'::text, field42, 'field43'::text, field43, 'field44'::text, field44, 'field45'::text, field45, 'field46'::text, field46, 'field47'::text, field47, 'field48'::text, field48, 'field49'::text, field49, 'field50'::text, field50), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field32, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field34, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field36, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field38, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field40, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field42, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field44, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field46, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field48, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field50 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) SELECT check_aggregates(51); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (51) ======================= NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62, c63, c64, c65, c66, c67, c68, c69, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79, c80, c81, c82, c83, c84, c85, c86, c87, c88, c89, c90, c91, c92, c93, c94, c95, c96, c97, c98, c99, c100), documentdb_core.bson_repath_and_build(c101, c102, c103, c104), false) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62, 'field31'::text AS c63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c64, 'field32'::text AS c65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c66, 'field33'::text AS c67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c68, 'field34'::text AS c69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c70, 'field35'::text AS c71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c72, 'field36'::text AS c73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c74, 'field37'::text AS c75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c76, 'field38'::text AS c77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c78, 'field39'::text AS c79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c80, 'field40'::text AS c81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c82, 'field41'::text AS c83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c84, 'field42'::text AS c85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c86, 'field43'::text AS c87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c88, 'field44'::text AS c89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c90, 'field45'::text AS c91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c92, 'field46'::text AS c93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c94, 'field47'::text AS c95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c96, 'field48'::text AS c97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c98, 'field49'::text AS c99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c100, 'field50'::text AS c101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c102, 'field51'::text AS c103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c104 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30, 'field31'::text, field31, 'field32'::text, field32, 'field33'::text, field33, 'field34'::text, field34, 'field35'::text, field35, 'field36'::text, field36, 'field37'::text, field37, 'field38'::text, field38, 'field39'::text, field39, 'field40'::text, field40, 'field41'::text, field41, 'field42'::text, field42, 'field43'::text, field43, 'field44'::text, field44, 'field45'::text, field45, 'field46'::text, field46, 'field47'::text, field47, 'field48'::text, field48, 'field49'::text, field49, 'field50'::text, field50), documentdb_core.bson_repath_and_build('field51'::text, field51), false), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field32, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field34, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field36, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field38, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field40, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field42, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field44, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field46, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field48, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field50, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field51 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) SELECT check_aggregates(100); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (100) ======================= NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62, c63, c64, c65, c66, c67, c68, c69, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79, c80, c81, c82, c83, c84, c85, c86, c87, c88, c89, c90, c91, c92, c93, c94, c95, c96, c97, c98, c99, c100), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c101, c102, c103, c104, c105, c106, c107, c108, c109, c110, c111, c112, c113, c114, c115, c116, c117, c118, c119, c120, c121, c122, c123, c124, c125, c126, c127, c128, c129, c130, c131, c132, c133, c134, c135, c136, c137, c138, c139, c140, c141, c142, c143, c144, c145, c146, c147, c148, c149, c150, c151, c152, c153, c154, c155, c156, c157, c158, c159, c160, c161, c162, c163, c164, c165, c166, c167, c168, c169, c170, c171, c172, c173, c174, c175, c176, c177, c178, c179, c180, c181, c182, c183, c184, c185, c186, c187, c188, c189, c190, c191, c192, c193, c194, c195, c196, c197, c198, c199, c200), documentdb_core.bson_repath_and_build(c201, c202), false), false) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62, 'field31'::text AS c63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c64, 'field32'::text AS c65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c66, 'field33'::text AS c67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c68, 'field34'::text AS c69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c70, 'field35'::text AS c71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c72, 'field36'::text AS c73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c74, 'field37'::text AS c75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c76, 'field38'::text AS c77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c78, 'field39'::text AS c79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c80, 'field40'::text AS c81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c82, 'field41'::text AS c83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c84, 'field42'::text AS c85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c86, 'field43'::text AS c87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c88, 'field44'::text AS c89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c90, 'field45'::text AS c91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c92, 'field46'::text AS c93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c94, 'field47'::text AS c95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c96, 'field48'::text AS c97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c98, 'field49'::text AS c99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c100, 'field50'::text AS c101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c102, 'field51'::text AS c103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c104, 'field52'::text AS c105, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c106, 'field53'::text AS c107, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c108, 'field54'::text AS c109, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c110, 'field55'::text AS c111, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c112, 'field56'::text AS c113, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c114, 'field57'::text AS c115, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c116, 'field58'::text AS c117, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c118, 'field59'::text AS c119, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c120, 'field60'::text AS c121, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c122, 'field61'::text AS c123, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c124, 'field62'::text AS c125, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c126, 'field63'::text AS c127, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c128, 'field64'::text AS c129, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c130, 'field65'::text AS c131, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c132, 'field66'::text AS c133, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c134, 'field67'::text AS c135, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c136, 'field68'::text AS c137, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c138, 'field69'::text AS c139, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c140, 'field70'::text AS c141, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c142, 'field71'::text AS c143, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c144, 'field72'::text AS c145, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c146, 'field73'::text AS c147, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c148, 'field74'::text AS c149, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c150, 'field75'::text AS c151, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c152, 'field76'::text AS c153, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c154, 'field77'::text AS c155, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c156, 'field78'::text AS c157, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c158, 'field79'::text AS c159, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c160, 'field80'::text AS c161, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c162, 'field81'::text AS c163, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c164, 'field82'::text AS c165, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c166, 'field83'::text AS c167, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c168, 'field84'::text AS c169, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c170, 'field85'::text AS c171, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c172, 'field86'::text AS c173, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c174, 'field87'::text AS c175, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c176, 'field88'::text AS c177, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c178, 'field89'::text AS c179, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c180, 'field90'::text AS c181, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c182, 'field91'::text AS c183, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c184, 'field92'::text AS c185, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c186, 'field93'::text AS c187, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c188, 'field94'::text AS c189, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c190, 'field95'::text AS c191, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c192, 'field96'::text AS c193, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c194, 'field97'::text AS c195, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c196, 'field98'::text AS c197, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c198, 'field99'::text AS c199, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c200, 'field100'::text AS c201, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c202 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30, 'field31'::text, field31, 'field32'::text, field32, 'field33'::text, field33, 'field34'::text, field34, 'field35'::text, field35, 'field36'::text, field36, 'field37'::text, field37, 'field38'::text, field38, 'field39'::text, field39, 'field40'::text, field40, 'field41'::text, field41, 'field42'::text, field42, 'field43'::text, field43, 'field44'::text, field44, 'field45'::text, field45, 'field46'::text, field46, 'field47'::text, field47, 'field48'::text, field48, 'field49'::text, field49, 'field50'::text, field50), documentdb_core.bson_repath_and_build('field51'::text, field51, 'field52'::text, field52, 'field53'::text, field53, 'field54'::text, field54, 'field55'::text, field55, 'field56'::text, field56, 'field57'::text, field57, 'field58'::text, field58, 'field59'::text, field59, 'field60'::text, field60, 'field61'::text, field61, 'field62'::text, field62, 'field63'::text, field63, 'field64'::text, field64, 'field65'::text, field65, 'field66'::text, field66, 'field67'::text, field67, 'field68'::text, field68, 'field69'::text, field69, 'field70'::text, field70, 'field71'::text, field71, 'field72'::text, field72, 'field73'::text, field73, 'field74'::text, field74, 'field75'::text, field75, 'field76'::text, field76, 'field77'::text, field77, 'field78'::text, field78, 'field79'::text, field79, 'field80'::text, field80, 'field81'::text, field81, 'field82'::text, field82, 'field83'::text, field83, 'field84'::text, field84, 'field85'::text, field85, 'field86'::text, field86, 'field87'::text, field87, 'field88'::text, field88, 'field89'::text, field89, 'field90'::text, field90, 'field91'::text, field91, 'field92'::text, field92, 'field93'::text, field93, 'field94'::text, field94, 'field95'::text, field95, 'field96'::text, field96, 'field97'::text, field97, 'field98'::text, field98, 'field99'::text, field99, 'field100'::text, field100), false), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field32, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field34, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field36, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field38, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field40, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field42, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field44, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field46, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field48, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field50, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field52, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field54, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field56, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field58, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field60, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field62, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field64, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field66, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field68, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field70, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field72, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field74, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field76, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field78, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field80, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field82, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field84, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field86, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field88, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field90, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field92, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field94, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field96, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field98, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field100 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) SELECT check_aggregates(105); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (105) ======================= NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62, c63, c64, c65, c66, c67, c68, c69, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79, c80, c81, c82, c83, c84, c85, c86, c87, c88, c89, c90, c91, c92, c93, c94, c95, c96, c97, c98, c99, c100), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c101, c102, c103, c104, c105, c106, c107, c108, c109, c110, c111, c112, c113, c114, c115, c116, c117, c118, c119, c120, c121, c122, c123, c124, c125, c126, c127, c128, c129, c130, c131, c132, c133, c134, c135, c136, c137, c138, c139, c140, c141, c142, c143, c144, c145, c146, c147, c148, c149, c150, c151, c152, c153, c154, c155, c156, c157, c158, c159, c160, c161, c162, c163, c164, c165, c166, c167, c168, c169, c170, c171, c172, c173, c174, c175, c176, c177, c178, c179, c180, c181, c182, c183, c184, c185, c186, c187, c188, c189, c190, c191, c192, c193, c194, c195, c196, c197, c198, c199, c200), documentdb_core.bson_repath_and_build(c201, c202, c203, c204, c205, c206, c207, c208, c209, c210, c211, c212), false), false) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62, 'field31'::text AS c63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c64, 'field32'::text AS c65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c66, 'field33'::text AS c67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c68, 'field34'::text AS c69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c70, 'field35'::text AS c71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c72, 'field36'::text AS c73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c74, 'field37'::text AS c75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c76, 'field38'::text AS c77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c78, 'field39'::text AS c79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c80, 'field40'::text AS c81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c82, 'field41'::text AS c83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c84, 'field42'::text AS c85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c86, 'field43'::text AS c87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c88, 'field44'::text AS c89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c90, 'field45'::text AS c91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c92, 'field46'::text AS c93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c94, 'field47'::text AS c95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c96, 'field48'::text AS c97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c98, 'field49'::text AS c99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c100, 'field50'::text AS c101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c102, 'field51'::text AS c103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c104, 'field52'::text AS c105, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c106, 'field53'::text AS c107, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c108, 'field54'::text AS c109, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c110, 'field55'::text AS c111, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c112, 'field56'::text AS c113, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c114, 'field57'::text AS c115, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c116, 'field58'::text AS c117, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c118, 'field59'::text AS c119, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c120, 'field60'::text AS c121, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c122, 'field61'::text AS c123, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c124, 'field62'::text AS c125, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c126, 'field63'::text AS c127, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c128, 'field64'::text AS c129, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c130, 'field65'::text AS c131, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c132, 'field66'::text AS c133, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c134, 'field67'::text AS c135, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c136, 'field68'::text AS c137, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c138, 'field69'::text AS c139, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c140, 'field70'::text AS c141, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c142, 'field71'::text AS c143, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c144, 'field72'::text AS c145, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c146, 'field73'::text AS c147, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c148, 'field74'::text AS c149, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c150, 'field75'::text AS c151, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c152, 'field76'::text AS c153, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c154, 'field77'::text AS c155, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c156, 'field78'::text AS c157, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c158, 'field79'::text AS c159, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c160, 'field80'::text AS c161, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c162, 'field81'::text AS c163, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c164, 'field82'::text AS c165, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c166, 'field83'::text AS c167, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c168, 'field84'::text AS c169, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c170, 'field85'::text AS c171, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c172, 'field86'::text AS c173, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c174, 'field87'::text AS c175, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c176, 'field88'::text AS c177, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c178, 'field89'::text AS c179, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c180, 'field90'::text AS c181, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c182, 'field91'::text AS c183, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c184, 'field92'::text AS c185, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c186, 'field93'::text AS c187, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c188, 'field94'::text AS c189, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c190, 'field95'::text AS c191, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c192, 'field96'::text AS c193, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c194, 'field97'::text AS c195, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c196, 'field98'::text AS c197, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c198, 'field99'::text AS c199, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c200, 'field100'::text AS c201, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c202, 'field101'::text AS c203, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c204, 'field102'::text AS c205, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c206, 'field103'::text AS c207, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c208, 'field104'::text AS c209, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c210, 'field105'::text AS c211, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c212 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1}, "field101": {"$sum": 1}, "field102": {"$sum": 1}, "field103": {"$sum": 1}, "field104": {"$sum": 1}, "field105": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" }, "field101" : { "$numberInt" : "1" }, "field102" : { "$numberInt" : "1" }, "field103" : { "$numberInt" : "1" }, "field104" : { "$numberInt" : "1" }, "field105" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30, 'field31'::text, field31, 'field32'::text, field32, 'field33'::text, field33, 'field34'::text, field34, 'field35'::text, field35, 'field36'::text, field36, 'field37'::text, field37, 'field38'::text, field38, 'field39'::text, field39, 'field40'::text, field40, 'field41'::text, field41, 'field42'::text, field42, 'field43'::text, field43, 'field44'::text, field44, 'field45'::text, field45, 'field46'::text, field46, 'field47'::text, field47, 'field48'::text, field48, 'field49'::text, field49, 'field50'::text, field50), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field51'::text, field51, 'field52'::text, field52, 'field53'::text, field53, 'field54'::text, field54, 'field55'::text, field55, 'field56'::text, field56, 'field57'::text, field57, 'field58'::text, field58, 'field59'::text, field59, 'field60'::text, field60, 'field61'::text, field61, 'field62'::text, field62, 'field63'::text, field63, 'field64'::text, field64, 'field65'::text, field65, 'field66'::text, field66, 'field67'::text, field67, 'field68'::text, field68, 'field69'::text, field69, 'field70'::text, field70, 'field71'::text, field71, 'field72'::text, field72, 'field73'::text, field73, 'field74'::text, field74, 'field75'::text, field75, 'field76'::text, field76, 'field77'::text, field77, 'field78'::text, field78, 'field79'::text, field79, 'field80'::text, field80, 'field81'::text, field81, 'field82'::text, field82, 'field83'::text, field83, 'field84'::text, field84, 'field85'::text, field85, 'field86'::text, field86, 'field87'::text, field87, 'field88'::text, field88, 'field89'::text, field89, 'field90'::text, field90, 'field91'::text, field91, 'field92'::text, field92, 'field93'::text, field93, 'field94'::text, field94, 'field95'::text, field95, 'field96'::text, field96, 'field97'::text, field97, 'field98'::text, field98, 'field99'::text, field99, 'field100'::text, field100), documentdb_core.bson_repath_and_build('field101'::text, field101, 'field102'::text, field102, 'field103'::text, field103, 'field104'::text, field104, 'field105'::text, field105), false), false), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field32, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field34, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field36, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field38, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field40, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field42, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field44, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field46, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field48, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field50, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field52, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field54, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field56, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field58, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field60, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field62, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field64, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field66, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field68, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field70, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field72, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field74, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field76, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field78, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field80, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field82, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field84, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field86, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field88, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field90, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field92, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field94, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field96, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field98, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field100, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field102, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field104, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field105 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1}, "field101": {"$sum": 1}, "field102": {"$sum": 1}, "field103": {"$sum": 1}, "field104": {"$sum": 1}, "field105": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" }, "field101" : { "$numberInt" : "1" }, "field102" : { "$numberInt" : "1" }, "field103" : { "$numberInt" : "1" }, "field104" : { "$numberInt" : "1" }, "field105" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) SELECT check_aggregates(200); NOTICE: \n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (200) ======================= NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, c60, c61, c62, c63, c64, c65, c66, c67, c68, c69, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79, c80, c81, c82, c83, c84, c85, c86, c87, c88, c89, c90, c91, c92, c93, c94, c95, c96, c97, c98, c99, c100), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c101, c102, c103, c104, c105, c106, c107, c108, c109, c110, c111, c112, c113, c114, c115, c116, c117, c118, c119, c120, c121, c122, c123, c124, c125, c126, c127, c128, c129, c130, c131, c132, c133, c134, c135, c136, c137, c138, c139, c140, c141, c142, c143, c144, c145, c146, c147, c148, c149, c150, c151, c152, c153, c154, c155, c156, c157, c158, c159, c160, c161, c162, c163, c164, c165, c166, c167, c168, c169, c170, c171, c172, c173, c174, c175, c176, c177, c178, c179, c180, c181, c182, c183, c184, c185, c186, c187, c188, c189, c190, c191, c192, c193, c194, c195, c196, c197, c198, c199, c200), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c201, c202, c203, c204, c205, c206, c207, c208, c209, c210, c211, c212, c213, c214, c215, c216, c217, c218, c219, c220, c221, c222, c223, c224, c225, c226, c227, c228, c229, c230, c231, c232, c233, c234, c235, c236, c237, c238, c239, c240, c241, c242, c243, c244, c245, c246, c247, c248, c249, c250, c251, c252, c253, c254, c255, c256, c257, c258, c259, c260, c261, c262, c263, c264, c265, c266, c267, c268, c269, c270, c271, c272, c273, c274, c275, c276, c277, c278, c279, c280, c281, c282, c283, c284, c285, c286, c287, c288, c289, c290, c291, c292, c293, c294, c295, c296, c297, c298, c299, c300), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build(c301, c302, c303, c304, c305, c306, c307, c308, c309, c310, c311, c312, c313, c314, c315, c316, c317, c318, c319, c320, c321, c322, c323, c324, c325, c326, c327, c328, c329, c330, c331, c332, c333, c334, c335, c336, c337, c338, c339, c340, c341, c342, c343, c344, c345, c346, c347, c348, c349, c350, c351, c352, c353, c354, c355, c356, c357, c358, c359, c360, c361, c362, c363, c364, c365, c366, c367, c368, c369, c370, c371, c372, c373, c374, c375, c376, c377, c378, c379, c380, c381, c382, c383, c384, c385, c386, c387, c388, c389, c390, c391, c392, c393, c394, c395, c396, c397, c398, c399, c400), documentdb_core.bson_repath_and_build(c401, c402), false), false), false), false) AS document FROM (SELECT '_id'::text AS c1, documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson) AS c2, 'field1'::text AS c3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c4, 'field2'::text AS c5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c6, 'field3'::text AS c7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c8, 'field4'::text AS c9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c10, 'field5'::text AS c11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c12, 'field6'::text AS c13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c14, 'field7'::text AS c15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c16, 'field8'::text AS c17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c18, 'field9'::text AS c19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c20, 'field10'::text AS c21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c22, 'field11'::text AS c23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c24, 'field12'::text AS c25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c26, 'field13'::text AS c27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c28, 'field14'::text AS c29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c30, 'field15'::text AS c31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c32, 'field16'::text AS c33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c34, 'field17'::text AS c35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c36, 'field18'::text AS c37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c38, 'field19'::text AS c39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c40, 'field20'::text AS c41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c42, 'field21'::text AS c43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c44, 'field22'::text AS c45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c46, 'field23'::text AS c47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c48, 'field24'::text AS c49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c50, 'field25'::text AS c51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c52, 'field26'::text AS c53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c54, 'field27'::text AS c55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c56, 'field28'::text AS c57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c58, 'field29'::text AS c59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c60, 'field30'::text AS c61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c62, 'field31'::text AS c63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c64, 'field32'::text AS c65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c66, 'field33'::text AS c67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c68, 'field34'::text AS c69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c70, 'field35'::text AS c71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c72, 'field36'::text AS c73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c74, 'field37'::text AS c75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c76, 'field38'::text AS c77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c78, 'field39'::text AS c79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c80, 'field40'::text AS c81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c82, 'field41'::text AS c83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c84, 'field42'::text AS c85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c86, 'field43'::text AS c87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c88, 'field44'::text AS c89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c90, 'field45'::text AS c91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c92, 'field46'::text AS c93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c94, 'field47'::text AS c95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c96, 'field48'::text AS c97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c98, 'field49'::text AS c99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c100, 'field50'::text AS c101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c102, 'field51'::text AS c103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c104, 'field52'::text AS c105, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c106, 'field53'::text AS c107, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c108, 'field54'::text AS c109, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c110, 'field55'::text AS c111, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c112, 'field56'::text AS c113, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c114, 'field57'::text AS c115, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c116, 'field58'::text AS c117, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c118, 'field59'::text AS c119, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c120, 'field60'::text AS c121, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c122, 'field61'::text AS c123, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c124, 'field62'::text AS c125, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c126, 'field63'::text AS c127, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c128, 'field64'::text AS c129, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c130, 'field65'::text AS c131, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c132, 'field66'::text AS c133, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c134, 'field67'::text AS c135, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c136, 'field68'::text AS c137, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c138, 'field69'::text AS c139, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c140, 'field70'::text AS c141, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c142, 'field71'::text AS c143, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c144, 'field72'::text AS c145, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c146, 'field73'::text AS c147, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c148, 'field74'::text AS c149, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c150, 'field75'::text AS c151, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c152, 'field76'::text AS c153, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c154, 'field77'::text AS c155, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c156, 'field78'::text AS c157, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c158, 'field79'::text AS c159, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c160, 'field80'::text AS c161, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c162, 'field81'::text AS c163, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c164, 'field82'::text AS c165, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c166, 'field83'::text AS c167, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c168, 'field84'::text AS c169, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c170, 'field85'::text AS c171, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c172, 'field86'::text AS c173, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c174, 'field87'::text AS c175, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c176, 'field88'::text AS c177, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c178, 'field89'::text AS c179, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c180, 'field90'::text AS c181, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c182, 'field91'::text AS c183, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c184, 'field92'::text AS c185, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c186, 'field93'::text AS c187, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c188, 'field94'::text AS c189, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c190, 'field95'::text AS c191, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c192, 'field96'::text AS c193, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c194, 'field97'::text AS c195, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c196, 'field98'::text AS c197, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c198, 'field99'::text AS c199, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c200, 'field100'::text AS c201, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c202, 'field101'::text AS c203, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c204, 'field102'::text AS c205, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c206, 'field103'::text AS c207, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c208, 'field104'::text AS c209, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c210, 'field105'::text AS c211, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c212, 'field106'::text AS c213, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c214, 'field107'::text AS c215, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c216, 'field108'::text AS c217, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c218, 'field109'::text AS c219, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c220, 'field110'::text AS c221, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c222, 'field111'::text AS c223, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c224, 'field112'::text AS c225, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c226, 'field113'::text AS c227, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c228, 'field114'::text AS c229, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c230, 'field115'::text AS c231, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c232, 'field116'::text AS c233, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c234, 'field117'::text AS c235, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c236, 'field118'::text AS c237, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c238, 'field119'::text AS c239, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c240, 'field120'::text AS c241, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c242, 'field121'::text AS c243, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c244, 'field122'::text AS c245, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c246, 'field123'::text AS c247, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c248, 'field124'::text AS c249, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c250, 'field125'::text AS c251, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c252, 'field126'::text AS c253, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c254, 'field127'::text AS c255, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c256, 'field128'::text AS c257, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c258, 'field129'::text AS c259, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c260, 'field130'::text AS c261, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c262, 'field131'::text AS c263, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c264, 'field132'::text AS c265, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c266, 'field133'::text AS c267, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c268, 'field134'::text AS c269, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c270, 'field135'::text AS c271, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c272, 'field136'::text AS c273, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c274, 'field137'::text AS c275, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c276, 'field138'::text AS c277, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c278, 'field139'::text AS c279, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c280, 'field140'::text AS c281, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c282, 'field141'::text AS c283, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c284, 'field142'::text AS c285, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c286, 'field143'::text AS c287, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c288, 'field144'::text AS c289, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c290, 'field145'::text AS c291, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c292, 'field146'::text AS c293, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c294, 'field147'::text AS c295, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c296, 'field148'::text AS c297, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c298, 'field149'::text AS c299, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c300, 'field150'::text AS c301, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c302, 'field151'::text AS c303, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c304, 'field152'::text AS c305, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c306, 'field153'::text AS c307, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c308, 'field154'::text AS c309, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c310, 'field155'::text AS c311, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c312, 'field156'::text AS c313, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c314, 'field157'::text AS c315, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c316, 'field158'::text AS c317, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c318, 'field159'::text AS c319, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c320, 'field160'::text AS c321, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c322, 'field161'::text AS c323, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c324, 'field162'::text AS c325, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c326, 'field163'::text AS c327, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c328, 'field164'::text AS c329, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c330, 'field165'::text AS c331, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c332, 'field166'::text AS c333, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c334, 'field167'::text AS c335, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c336, 'field168'::text AS c337, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c338, 'field169'::text AS c339, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c340, 'field170'::text AS c341, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c342, 'field171'::text AS c343, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c344, 'field172'::text AS c345, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c346, 'field173'::text AS c347, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c348, 'field174'::text AS c349, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c350, 'field175'::text AS c351, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c352, 'field176'::text AS c353, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c354, 'field177'::text AS c355, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c356, 'field178'::text AS c357, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c358, 'field179'::text AS c359, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c360, 'field180'::text AS c361, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c362, 'field181'::text AS c363, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c364, 'field182'::text AS c365, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c366, 'field183'::text AS c367, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c368, 'field184'::text AS c369, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c370, 'field185'::text AS c371, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c372, 'field186'::text AS c373, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c374, 'field187'::text AS c375, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c376, 'field188'::text AS c377, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c378, 'field189'::text AS c379, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c380, 'field190'::text AS c381, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c382, 'field191'::text AS c383, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c384, 'field192'::text AS c385, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c386, 'field193'::text AS c387, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c388, 'field194'::text AS c389, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c390, 'field195'::text AS c391, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c392, 'field196'::text AS c393, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c394, 'field197'::text AS c395, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c396, 'field198'::text AS c397, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c398, 'field199'::text AS c399, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c400, 'field200'::text AS c401, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get('{ }'::documentdb_core.bson, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) AS c402 FROM (SELECT collection.document FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0_1 GROUP BY (documentdb_api_internal.bson_expression_get(agg_stage_0_1.document, '{ "" : "$_id" }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson))) agg_stage_0 NOTICE: ============= Group by ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1}, "field101": {"$sum": 1}, "field102": {"$sum": 1}, "field103": {"$sum": 1}, "field104": {"$sum": 1}, "field105": {"$sum": 1}, "field106": {"$sum": 1}, "field107": {"$sum": 1}, "field108": {"$sum": 1}, "field109": {"$sum": 1}, "field110": {"$sum": 1}, "field111": {"$sum": 1}, "field112": {"$sum": 1}, "field113": {"$sum": 1}, "field114": {"$sum": 1}, "field115": {"$sum": 1}, "field116": {"$sum": 1}, "field117": {"$sum": 1}, "field118": {"$sum": 1}, "field119": {"$sum": 1}, "field120": {"$sum": 1}, "field121": {"$sum": 1}, "field122": {"$sum": 1}, "field123": {"$sum": 1}, "field124": {"$sum": 1}, "field125": {"$sum": 1}, "field126": {"$sum": 1}, "field127": {"$sum": 1}, "field128": {"$sum": 1}, "field129": {"$sum": 1}, "field130": {"$sum": 1}, "field131": {"$sum": 1}, "field132": {"$sum": 1}, "field133": {"$sum": 1}, "field134": {"$sum": 1}, "field135": {"$sum": 1}, "field136": {"$sum": 1}, "field137": {"$sum": 1}, "field138": {"$sum": 1}, "field139": {"$sum": 1}, "field140": {"$sum": 1}, "field141": {"$sum": 1}, "field142": {"$sum": 1}, "field143": {"$sum": 1}, "field144": {"$sum": 1}, "field145": {"$sum": 1}, "field146": {"$sum": 1}, "field147": {"$sum": 1}, "field148": {"$sum": 1}, "field149": {"$sum": 1}, "field150": {"$sum": 1}, "field151": {"$sum": 1}, "field152": {"$sum": 1}, "field153": {"$sum": 1}, "field154": {"$sum": 1}, "field155": {"$sum": 1}, "field156": {"$sum": 1}, "field157": {"$sum": 1}, "field158": {"$sum": 1}, "field159": {"$sum": 1}, "field160": {"$sum": 1}, "field161": {"$sum": 1}, "field162": {"$sum": 1}, "field163": {"$sum": 1}, "field164": {"$sum": 1}, "field165": {"$sum": 1}, "field166": {"$sum": 1}, "field167": {"$sum": 1}, "field168": {"$sum": 1}, "field169": {"$sum": 1}, "field170": {"$sum": 1}, "field171": {"$sum": 1}, "field172": {"$sum": 1}, "field173": {"$sum": 1}, "field174": {"$sum": 1}, "field175": {"$sum": 1}, "field176": {"$sum": 1}, "field177": {"$sum": 1}, "field178": {"$sum": 1}, "field179": {"$sum": 1}, "field180": {"$sum": 1}, "field181": {"$sum": 1}, "field182": {"$sum": 1}, "field183": {"$sum": 1}, "field184": {"$sum": 1}, "field185": {"$sum": 1}, "field186": {"$sum": 1}, "field187": {"$sum": 1}, "field188": {"$sum": 1}, "field189": {"$sum": 1}, "field190": {"$sum": 1}, "field191": {"$sum": 1}, "field192": {"$sum": 1}, "field193": {"$sum": 1}, "field194": {"$sum": 1}, "field195": {"$sum": 1}, "field196": {"$sum": 1}, "field197": {"$sum": 1}, "field198": {"$sum": 1}, "field199": {"$sum": 1}, "field200": {"$sum": 1} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" }, "field101" : { "$numberInt" : "1" }, "field102" : { "$numberInt" : "1" }, "field103" : { "$numberInt" : "1" }, "field104" : { "$numberInt" : "1" }, "field105" : { "$numberInt" : "1" }, "field106" : { "$numberInt" : "1" }, "field107" : { "$numberInt" : "1" }, "field108" : { "$numberInt" : "1" }, "field109" : { "$numberInt" : "1" }, "field110" : { "$numberInt" : "1" }, "field111" : { "$numberInt" : "1" }, "field112" : { "$numberInt" : "1" }, "field113" : { "$numberInt" : "1" }, "field114" : { "$numberInt" : "1" }, "field115" : { "$numberInt" : "1" }, "field116" : { "$numberInt" : "1" }, "field117" : { "$numberInt" : "1" }, "field118" : { "$numberInt" : "1" }, "field119" : { "$numberInt" : "1" }, "field120" : { "$numberInt" : "1" }, "field121" : { "$numberInt" : "1" }, "field122" : { "$numberInt" : "1" }, "field123" : { "$numberInt" : "1" }, "field124" : { "$numberInt" : "1" }, "field125" : { "$numberInt" : "1" }, "field126" : { "$numberInt" : "1" }, "field127" : { "$numberInt" : "1" }, "field128" : { "$numberInt" : "1" }, "field129" : { "$numberInt" : "1" }, "field130" : { "$numberInt" : "1" }, "field131" : { "$numberInt" : "1" }, "field132" : { "$numberInt" : "1" }, "field133" : { "$numberInt" : "1" }, "field134" : { "$numberInt" : "1" }, "field135" : { "$numberInt" : "1" }, "field136" : { "$numberInt" : "1" }, "field137" : { "$numberInt" : "1" }, "field138" : { "$numberInt" : "1" }, "field139" : { "$numberInt" : "1" }, "field140" : { "$numberInt" : "1" }, "field141" : { "$numberInt" : "1" }, "field142" : { "$numberInt" : "1" }, "field143" : { "$numberInt" : "1" }, "field144" : { "$numberInt" : "1" }, "field145" : { "$numberInt" : "1" }, "field146" : { "$numberInt" : "1" }, "field147" : { "$numberInt" : "1" }, "field148" : { "$numberInt" : "1" }, "field149" : { "$numberInt" : "1" }, "field150" : { "$numberInt" : "1" }, "field151" : { "$numberInt" : "1" }, "field152" : { "$numberInt" : "1" }, "field153" : { "$numberInt" : "1" }, "field154" : { "$numberInt" : "1" }, "field155" : { "$numberInt" : "1" }, "field156" : { "$numberInt" : "1" }, "field157" : { "$numberInt" : "1" }, "field158" : { "$numberInt" : "1" }, "field159" : { "$numberInt" : "1" }, "field160" : { "$numberInt" : "1" }, "field161" : { "$numberInt" : "1" }, "field162" : { "$numberInt" : "1" }, "field163" : { "$numberInt" : "1" }, "field164" : { "$numberInt" : "1" }, "field165" : { "$numberInt" : "1" }, "field166" : { "$numberInt" : "1" }, "field167" : { "$numberInt" : "1" }, "field168" : { "$numberInt" : "1" }, "field169" : { "$numberInt" : "1" }, "field170" : { "$numberInt" : "1" }, "field171" : { "$numberInt" : "1" }, "field172" : { "$numberInt" : "1" }, "field173" : { "$numberInt" : "1" }, "field174" : { "$numberInt" : "1" }, "field175" : { "$numberInt" : "1" }, "field176" : { "$numberInt" : "1" }, "field177" : { "$numberInt" : "1" }, "field178" : { "$numberInt" : "1" }, "field179" : { "$numberInt" : "1" }, "field180" : { "$numberInt" : "1" }, "field181" : { "$numberInt" : "1" }, "field182" : { "$numberInt" : "1" }, "field183" : { "$numberInt" : "1" }, "field184" : { "$numberInt" : "1" }, "field185" : { "$numberInt" : "1" }, "field186" : { "$numberInt" : "1" }, "field187" : { "$numberInt" : "1" }, "field188" : { "$numberInt" : "1" }, "field189" : { "$numberInt" : "1" }, "field190" : { "$numberInt" : "1" }, "field191" : { "$numberInt" : "1" }, "field192" : { "$numberInt" : "1" }, "field193" : { "$numberInt" : "1" }, "field194" : { "$numberInt" : "1" }, "field195" : { "$numberInt" : "1" }, "field196" : { "$numberInt" : "1" }, "field197" : { "$numberInt" : "1" }, "field198" : { "$numberInt" : "1" }, "field199" : { "$numberInt" : "1" }, "field200" : { "$numberInt" : "1" } } NOTICE: executing the command locally: SELECT documentdb_api_internal.bson_dollar_merge_documents(document, documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field1'::text, field1, 'field2'::text, field2, 'field3'::text, field3, 'field4'::text, field4, 'field5'::text, field5, 'field6'::text, field6, 'field7'::text, field7, 'field8'::text, field8, 'field9'::text, field9, 'field10'::text, field10, 'field11'::text, field11, 'field12'::text, field12, 'field13'::text, field13, 'field14'::text, field14, 'field15'::text, field15, 'field16'::text, field16, 'field17'::text, field17, 'field18'::text, field18, 'field19'::text, field19, 'field20'::text, field20, 'field21'::text, field21, 'field22'::text, field22, 'field23'::text, field23, 'field24'::text, field24, 'field25'::text, field25, 'field26'::text, field26, 'field27'::text, field27, 'field28'::text, field28, 'field29'::text, field29, 'field30'::text, field30, 'field31'::text, field31, 'field32'::text, field32, 'field33'::text, field33, 'field34'::text, field34, 'field35'::text, field35, 'field36'::text, field36, 'field37'::text, field37, 'field38'::text, field38, 'field39'::text, field39, 'field40'::text, field40, 'field41'::text, field41, 'field42'::text, field42, 'field43'::text, field43, 'field44'::text, field44, 'field45'::text, field45, 'field46'::text, field46, 'field47'::text, field47, 'field48'::text, field48, 'field49'::text, field49, 'field50'::text, field50), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field51'::text, field51, 'field52'::text, field52, 'field53'::text, field53, 'field54'::text, field54, 'field55'::text, field55, 'field56'::text, field56, 'field57'::text, field57, 'field58'::text, field58, 'field59'::text, field59, 'field60'::text, field60, 'field61'::text, field61, 'field62'::text, field62, 'field63'::text, field63, 'field64'::text, field64, 'field65'::text, field65, 'field66'::text, field66, 'field67'::text, field67, 'field68'::text, field68, 'field69'::text, field69, 'field70'::text, field70, 'field71'::text, field71, 'field72'::text, field72, 'field73'::text, field73, 'field74'::text, field74, 'field75'::text, field75, 'field76'::text, field76, 'field77'::text, field77, 'field78'::text, field78, 'field79'::text, field79, 'field80'::text, field80, 'field81'::text, field81, 'field82'::text, field82, 'field83'::text, field83, 'field84'::text, field84, 'field85'::text, field85, 'field86'::text, field86, 'field87'::text, field87, 'field88'::text, field88, 'field89'::text, field89, 'field90'::text, field90, 'field91'::text, field91, 'field92'::text, field92, 'field93'::text, field93, 'field94'::text, field94, 'field95'::text, field95, 'field96'::text, field96, 'field97'::text, field97, 'field98'::text, field98, 'field99'::text, field99, 'field100'::text, field100), documentdb_api_internal.bson_dollar_merge_documents(documentdb_core.bson_repath_and_build('field101'::text, field101, 'field102'::text, field102, 'field103'::text, field103, 'field104'::text, field104, 'field105'::text, field105, 'field106'::text, field106, 'field107'::text, field107, 'field108'::text, field108, 'field109'::text, field109, 'field110'::text, field110, 'field111'::text, field111, 'field112'::text, field112, 'field113'::text, field113, 'field114'::text, field114, 'field115'::text, field115, 'field116'::text, field116, 'field117'::text, field117, 'field118'::text, field118, 'field119'::text, field119, 'field120'::text, field120, 'field121'::text, field121, 'field122'::text, field122, 'field123'::text, field123, 'field124'::text, field124, 'field125'::text, field125, 'field126'::text, field126, 'field127'::text, field127, 'field128'::text, field128, 'field129'::text, field129, 'field130'::text, field130, 'field131'::text, field131, 'field132'::text, field132, 'field133'::text, field133, 'field134'::text, field134, 'field135'::text, field135, 'field136'::text, field136, 'field137'::text, field137, 'field138'::text, field138, 'field139'::text, field139, 'field140'::text, field140, 'field141'::text, field141, 'field142'::text, field142, 'field143'::text, field143, 'field144'::text, field144, 'field145'::text, field145, 'field146'::text, field146, 'field147'::text, field147, 'field148'::text, field148, 'field149'::text, field149, 'field150'::text, field150), documentdb_core.bson_repath_and_build('field151'::text, field151, 'field152'::text, field152, 'field153'::text, field153, 'field154'::text, field154, 'field155'::text, field155, 'field156'::text, field156, 'field157'::text, field157, 'field158'::text, field158, 'field159'::text, field159, 'field160'::text, field160, 'field161'::text, field161, 'field162'::text, field162, 'field163'::text, field163, 'field164'::text, field164, 'field165'::text, field165, 'field166'::text, field166, 'field167'::text, field167, 'field168'::text, field168, 'field169'::text, field169, 'field170'::text, field170, 'field171'::text, field171, 'field172'::text, field172, 'field173'::text, field173, 'field174'::text, field174, 'field175'::text, field175, 'field176'::text, field176, 'field177'::text, field177, 'field178'::text, field178, 'field179'::text, field179, 'field180'::text, field180, 'field181'::text, field181, 'field182'::text, field182, 'field183'::text, field183, 'field184'::text, field184, 'field185'::text, field185, 'field186'::text, field186, 'field187'::text, field187, 'field188'::text, field188, 'field189'::text, field189, 'field190'::text, field190, 'field191'::text, field191, 'field192'::text, field192, 'field193'::text, field193, 'field194'::text, field194, 'field195'::text, field195, 'field196'::text, field196, 'field197'::text, field197, 'field198'::text, field198, 'field199'::text, field199, 'field200'::text, field200), false), false), false), false) AS document FROM (SELECT collection.document, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field1, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field2, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field3, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field4, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field5, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field6, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field7, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field8, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field9, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field10, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field11, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field12, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field13, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field14, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field15, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field16, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field17, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field18, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field19, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field20, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field21, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field22, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field23, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field24, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field25, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field26, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field27, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field28, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field29, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field30, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field31, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field32, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field33, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field34, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field35, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field36, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field37, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field38, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field39, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field40, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field41, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field42, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field43, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field44, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field45, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field46, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field47, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field48, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field49, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field50, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field51, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field52, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field53, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field54, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field55, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field56, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field57, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field58, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field59, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field60, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field61, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field62, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field63, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field64, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field65, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field66, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field67, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field68, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field69, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field70, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field71, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field72, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field73, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field74, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field75, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field76, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field77, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field78, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field79, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field80, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field81, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field82, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field83, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field84, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field85, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field86, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field87, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field88, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field89, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field90, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field91, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field92, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field93, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field94, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field95, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field96, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field97, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field98, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field99, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field100, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field101, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field102, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field103, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field104, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field105, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field106, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field107, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field108, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field109, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field110, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field111, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field112, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field113, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field114, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field115, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field116, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field117, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field118, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field119, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field120, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field121, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field122, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field123, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field124, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field125, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field126, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field127, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field128, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field129, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field130, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field131, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field132, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field133, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field134, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field135, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field136, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field137, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field138, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field139, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field140, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field141, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field142, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field143, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field144, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field145, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field146, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field147, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field148, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field149, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field150, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field151, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field152, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field153, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field154, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field155, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field156, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field157, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field158, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field159, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field160, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field161, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field162, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field163, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field164, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field165, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field166, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field167, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field168, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field169, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field170, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field171, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field172, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field173, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field174, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field175, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field176, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field177, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field178, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field179, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field180, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field181, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field182, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field183, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field184, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field185, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field186, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field187, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field188, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field189, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field190, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field191, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field192, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field193, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field194, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field195, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field196, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field197, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field198, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field199, documentdb_api_catalog.bsonsum(documentdb_api_internal.bson_expression_get(collection.document, '{ "" : { "$numberInt" : "1" } }'::documentdb_core.bson, true, '{ "now" : NOW_SYS_VARIABLE }'::documentdb_core.bson)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS field200 FROM documentdb_data.documents_88450_884505 collection WHERE (collection.shard_key_value OPERATOR(pg_catalog.=) '88450'::bigint)) agg_stage_0 NOTICE: ============= SetWindowFields ============= Query: { "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": {"field1": {"$sum": 1}, "field2": {"$sum": 1}, "field3": {"$sum": 1}, "field4": {"$sum": 1}, "field5": {"$sum": 1}, "field6": {"$sum": 1}, "field7": {"$sum": 1}, "field8": {"$sum": 1}, "field9": {"$sum": 1}, "field10": {"$sum": 1}, "field11": {"$sum": 1}, "field12": {"$sum": 1}, "field13": {"$sum": 1}, "field14": {"$sum": 1}, "field15": {"$sum": 1}, "field16": {"$sum": 1}, "field17": {"$sum": 1}, "field18": {"$sum": 1}, "field19": {"$sum": 1}, "field20": {"$sum": 1}, "field21": {"$sum": 1}, "field22": {"$sum": 1}, "field23": {"$sum": 1}, "field24": {"$sum": 1}, "field25": {"$sum": 1}, "field26": {"$sum": 1}, "field27": {"$sum": 1}, "field28": {"$sum": 1}, "field29": {"$sum": 1}, "field30": {"$sum": 1}, "field31": {"$sum": 1}, "field32": {"$sum": 1}, "field33": {"$sum": 1}, "field34": {"$sum": 1}, "field35": {"$sum": 1}, "field36": {"$sum": 1}, "field37": {"$sum": 1}, "field38": {"$sum": 1}, "field39": {"$sum": 1}, "field40": {"$sum": 1}, "field41": {"$sum": 1}, "field42": {"$sum": 1}, "field43": {"$sum": 1}, "field44": {"$sum": 1}, "field45": {"$sum": 1}, "field46": {"$sum": 1}, "field47": {"$sum": 1}, "field48": {"$sum": 1}, "field49": {"$sum": 1}, "field50": {"$sum": 1}, "field51": {"$sum": 1}, "field52": {"$sum": 1}, "field53": {"$sum": 1}, "field54": {"$sum": 1}, "field55": {"$sum": 1}, "field56": {"$sum": 1}, "field57": {"$sum": 1}, "field58": {"$sum": 1}, "field59": {"$sum": 1}, "field60": {"$sum": 1}, "field61": {"$sum": 1}, "field62": {"$sum": 1}, "field63": {"$sum": 1}, "field64": {"$sum": 1}, "field65": {"$sum": 1}, "field66": {"$sum": 1}, "field67": {"$sum": 1}, "field68": {"$sum": 1}, "field69": {"$sum": 1}, "field70": {"$sum": 1}, "field71": {"$sum": 1}, "field72": {"$sum": 1}, "field73": {"$sum": 1}, "field74": {"$sum": 1}, "field75": {"$sum": 1}, "field76": {"$sum": 1}, "field77": {"$sum": 1}, "field78": {"$sum": 1}, "field79": {"$sum": 1}, "field80": {"$sum": 1}, "field81": {"$sum": 1}, "field82": {"$sum": 1}, "field83": {"$sum": 1}, "field84": {"$sum": 1}, "field85": {"$sum": 1}, "field86": {"$sum": 1}, "field87": {"$sum": 1}, "field88": {"$sum": 1}, "field89": {"$sum": 1}, "field90": {"$sum": 1}, "field91": {"$sum": 1}, "field92": {"$sum": 1}, "field93": {"$sum": 1}, "field94": {"$sum": 1}, "field95": {"$sum": 1}, "field96": {"$sum": 1}, "field97": {"$sum": 1}, "field98": {"$sum": 1}, "field99": {"$sum": 1}, "field100": {"$sum": 1}, "field101": {"$sum": 1}, "field102": {"$sum": 1}, "field103": {"$sum": 1}, "field104": {"$sum": 1}, "field105": {"$sum": 1}, "field106": {"$sum": 1}, "field107": {"$sum": 1}, "field108": {"$sum": 1}, "field109": {"$sum": 1}, "field110": {"$sum": 1}, "field111": {"$sum": 1}, "field112": {"$sum": 1}, "field113": {"$sum": 1}, "field114": {"$sum": 1}, "field115": {"$sum": 1}, "field116": {"$sum": 1}, "field117": {"$sum": 1}, "field118": {"$sum": 1}, "field119": {"$sum": 1}, "field120": {"$sum": 1}, "field121": {"$sum": 1}, "field122": {"$sum": 1}, "field123": {"$sum": 1}, "field124": {"$sum": 1}, "field125": {"$sum": 1}, "field126": {"$sum": 1}, "field127": {"$sum": 1}, "field128": {"$sum": 1}, "field129": {"$sum": 1}, "field130": {"$sum": 1}, "field131": {"$sum": 1}, "field132": {"$sum": 1}, "field133": {"$sum": 1}, "field134": {"$sum": 1}, "field135": {"$sum": 1}, "field136": {"$sum": 1}, "field137": {"$sum": 1}, "field138": {"$sum": 1}, "field139": {"$sum": 1}, "field140": {"$sum": 1}, "field141": {"$sum": 1}, "field142": {"$sum": 1}, "field143": {"$sum": 1}, "field144": {"$sum": 1}, "field145": {"$sum": 1}, "field146": {"$sum": 1}, "field147": {"$sum": 1}, "field148": {"$sum": 1}, "field149": {"$sum": 1}, "field150": {"$sum": 1}, "field151": {"$sum": 1}, "field152": {"$sum": 1}, "field153": {"$sum": 1}, "field154": {"$sum": 1}, "field155": {"$sum": 1}, "field156": {"$sum": 1}, "field157": {"$sum": 1}, "field158": {"$sum": 1}, "field159": {"$sum": 1}, "field160": {"$sum": 1}, "field161": {"$sum": 1}, "field162": {"$sum": 1}, "field163": {"$sum": 1}, "field164": {"$sum": 1}, "field165": {"$sum": 1}, "field166": {"$sum": 1}, "field167": {"$sum": 1}, "field168": {"$sum": 1}, "field169": {"$sum": 1}, "field170": {"$sum": 1}, "field171": {"$sum": 1}, "field172": {"$sum": 1}, "field173": {"$sum": 1}, "field174": {"$sum": 1}, "field175": {"$sum": 1}, "field176": {"$sum": 1}, "field177": {"$sum": 1}, "field178": {"$sum": 1}, "field179": {"$sum": 1}, "field180": {"$sum": 1}, "field181": {"$sum": 1}, "field182": {"$sum": 1}, "field183": {"$sum": 1}, "field184": {"$sum": 1}, "field185": {"$sum": 1}, "field186": {"$sum": 1}, "field187": {"$sum": 1}, "field188": {"$sum": 1}, "field189": {"$sum": 1}, "field190": {"$sum": 1}, "field191": {"$sum": 1}, "field192": {"$sum": 1}, "field193": {"$sum": 1}, "field194": {"$sum": 1}, "field195": {"$sum": 1}, "field196": {"$sum": 1}, "field197": {"$sum": 1}, "field198": {"$sum": 1}, "field199": {"$sum": 1}, "field200": {"$sum": 1}} }}]} Result: { "_id" : { "$numberInt" : "1" }, "field1" : { "$numberInt" : "1" }, "field2" : { "$numberInt" : "1" }, "field3" : { "$numberInt" : "1" }, "field4" : { "$numberInt" : "1" }, "field5" : { "$numberInt" : "1" }, "field6" : { "$numberInt" : "1" }, "field7" : { "$numberInt" : "1" }, "field8" : { "$numberInt" : "1" }, "field9" : { "$numberInt" : "1" }, "field10" : { "$numberInt" : "1" }, "field11" : { "$numberInt" : "1" }, "field12" : { "$numberInt" : "1" }, "field13" : { "$numberInt" : "1" }, "field14" : { "$numberInt" : "1" }, "field15" : { "$numberInt" : "1" }, "field16" : { "$numberInt" : "1" }, "field17" : { "$numberInt" : "1" }, "field18" : { "$numberInt" : "1" }, "field19" : { "$numberInt" : "1" }, "field20" : { "$numberInt" : "1" }, "field21" : { "$numberInt" : "1" }, "field22" : { "$numberInt" : "1" }, "field23" : { "$numberInt" : "1" }, "field24" : { "$numberInt" : "1" }, "field25" : { "$numberInt" : "1" }, "field26" : { "$numberInt" : "1" }, "field27" : { "$numberInt" : "1" }, "field28" : { "$numberInt" : "1" }, "field29" : { "$numberInt" : "1" }, "field30" : { "$numberInt" : "1" }, "field31" : { "$numberInt" : "1" }, "field32" : { "$numberInt" : "1" }, "field33" : { "$numberInt" : "1" }, "field34" : { "$numberInt" : "1" }, "field35" : { "$numberInt" : "1" }, "field36" : { "$numberInt" : "1" }, "field37" : { "$numberInt" : "1" }, "field38" : { "$numberInt" : "1" }, "field39" : { "$numberInt" : "1" }, "field40" : { "$numberInt" : "1" }, "field41" : { "$numberInt" : "1" }, "field42" : { "$numberInt" : "1" }, "field43" : { "$numberInt" : "1" }, "field44" : { "$numberInt" : "1" }, "field45" : { "$numberInt" : "1" }, "field46" : { "$numberInt" : "1" }, "field47" : { "$numberInt" : "1" }, "field48" : { "$numberInt" : "1" }, "field49" : { "$numberInt" : "1" }, "field50" : { "$numberInt" : "1" }, "field51" : { "$numberInt" : "1" }, "field52" : { "$numberInt" : "1" }, "field53" : { "$numberInt" : "1" }, "field54" : { "$numberInt" : "1" }, "field55" : { "$numberInt" : "1" }, "field56" : { "$numberInt" : "1" }, "field57" : { "$numberInt" : "1" }, "field58" : { "$numberInt" : "1" }, "field59" : { "$numberInt" : "1" }, "field60" : { "$numberInt" : "1" }, "field61" : { "$numberInt" : "1" }, "field62" : { "$numberInt" : "1" }, "field63" : { "$numberInt" : "1" }, "field64" : { "$numberInt" : "1" }, "field65" : { "$numberInt" : "1" }, "field66" : { "$numberInt" : "1" }, "field67" : { "$numberInt" : "1" }, "field68" : { "$numberInt" : "1" }, "field69" : { "$numberInt" : "1" }, "field70" : { "$numberInt" : "1" }, "field71" : { "$numberInt" : "1" }, "field72" : { "$numberInt" : "1" }, "field73" : { "$numberInt" : "1" }, "field74" : { "$numberInt" : "1" }, "field75" : { "$numberInt" : "1" }, "field76" : { "$numberInt" : "1" }, "field77" : { "$numberInt" : "1" }, "field78" : { "$numberInt" : "1" }, "field79" : { "$numberInt" : "1" }, "field80" : { "$numberInt" : "1" }, "field81" : { "$numberInt" : "1" }, "field82" : { "$numberInt" : "1" }, "field83" : { "$numberInt" : "1" }, "field84" : { "$numberInt" : "1" }, "field85" : { "$numberInt" : "1" }, "field86" : { "$numberInt" : "1" }, "field87" : { "$numberInt" : "1" }, "field88" : { "$numberInt" : "1" }, "field89" : { "$numberInt" : "1" }, "field90" : { "$numberInt" : "1" }, "field91" : { "$numberInt" : "1" }, "field92" : { "$numberInt" : "1" }, "field93" : { "$numberInt" : "1" }, "field94" : { "$numberInt" : "1" }, "field95" : { "$numberInt" : "1" }, "field96" : { "$numberInt" : "1" }, "field97" : { "$numberInt" : "1" }, "field98" : { "$numberInt" : "1" }, "field99" : { "$numberInt" : "1" }, "field100" : { "$numberInt" : "1" }, "field101" : { "$numberInt" : "1" }, "field102" : { "$numberInt" : "1" }, "field103" : { "$numberInt" : "1" }, "field104" : { "$numberInt" : "1" }, "field105" : { "$numberInt" : "1" }, "field106" : { "$numberInt" : "1" }, "field107" : { "$numberInt" : "1" }, "field108" : { "$numberInt" : "1" }, "field109" : { "$numberInt" : "1" }, "field110" : { "$numberInt" : "1" }, "field111" : { "$numberInt" : "1" }, "field112" : { "$numberInt" : "1" }, "field113" : { "$numberInt" : "1" }, "field114" : { "$numberInt" : "1" }, "field115" : { "$numberInt" : "1" }, "field116" : { "$numberInt" : "1" }, "field117" : { "$numberInt" : "1" }, "field118" : { "$numberInt" : "1" }, "field119" : { "$numberInt" : "1" }, "field120" : { "$numberInt" : "1" }, "field121" : { "$numberInt" : "1" }, "field122" : { "$numberInt" : "1" }, "field123" : { "$numberInt" : "1" }, "field124" : { "$numberInt" : "1" }, "field125" : { "$numberInt" : "1" }, "field126" : { "$numberInt" : "1" }, "field127" : { "$numberInt" : "1" }, "field128" : { "$numberInt" : "1" }, "field129" : { "$numberInt" : "1" }, "field130" : { "$numberInt" : "1" }, "field131" : { "$numberInt" : "1" }, "field132" : { "$numberInt" : "1" }, "field133" : { "$numberInt" : "1" }, "field134" : { "$numberInt" : "1" }, "field135" : { "$numberInt" : "1" }, "field136" : { "$numberInt" : "1" }, "field137" : { "$numberInt" : "1" }, "field138" : { "$numberInt" : "1" }, "field139" : { "$numberInt" : "1" }, "field140" : { "$numberInt" : "1" }, "field141" : { "$numberInt" : "1" }, "field142" : { "$numberInt" : "1" }, "field143" : { "$numberInt" : "1" }, "field144" : { "$numberInt" : "1" }, "field145" : { "$numberInt" : "1" }, "field146" : { "$numberInt" : "1" }, "field147" : { "$numberInt" : "1" }, "field148" : { "$numberInt" : "1" }, "field149" : { "$numberInt" : "1" }, "field150" : { "$numberInt" : "1" }, "field151" : { "$numberInt" : "1" }, "field152" : { "$numberInt" : "1" }, "field153" : { "$numberInt" : "1" }, "field154" : { "$numberInt" : "1" }, "field155" : { "$numberInt" : "1" }, "field156" : { "$numberInt" : "1" }, "field157" : { "$numberInt" : "1" }, "field158" : { "$numberInt" : "1" }, "field159" : { "$numberInt" : "1" }, "field160" : { "$numberInt" : "1" }, "field161" : { "$numberInt" : "1" }, "field162" : { "$numberInt" : "1" }, "field163" : { "$numberInt" : "1" }, "field164" : { "$numberInt" : "1" }, "field165" : { "$numberInt" : "1" }, "field166" : { "$numberInt" : "1" }, "field167" : { "$numberInt" : "1" }, "field168" : { "$numberInt" : "1" }, "field169" : { "$numberInt" : "1" }, "field170" : { "$numberInt" : "1" }, "field171" : { "$numberInt" : "1" }, "field172" : { "$numberInt" : "1" }, "field173" : { "$numberInt" : "1" }, "field174" : { "$numberInt" : "1" }, "field175" : { "$numberInt" : "1" }, "field176" : { "$numberInt" : "1" }, "field177" : { "$numberInt" : "1" }, "field178" : { "$numberInt" : "1" }, "field179" : { "$numberInt" : "1" }, "field180" : { "$numberInt" : "1" }, "field181" : { "$numberInt" : "1" }, "field182" : { "$numberInt" : "1" }, "field183" : { "$numberInt" : "1" }, "field184" : { "$numberInt" : "1" }, "field185" : { "$numberInt" : "1" }, "field186" : { "$numberInt" : "1" }, "field187" : { "$numberInt" : "1" }, "field188" : { "$numberInt" : "1" }, "field189" : { "$numberInt" : "1" }, "field190" : { "$numberInt" : "1" }, "field191" : { "$numberInt" : "1" }, "field192" : { "$numberInt" : "1" }, "field193" : { "$numberInt" : "1" }, "field194" : { "$numberInt" : "1" }, "field195" : { "$numberInt" : "1" }, "field196" : { "$numberInt" : "1" }, "field197" : { "$numberInt" : "1" }, "field198" : { "$numberInt" : "1" }, "field199" : { "$numberInt" : "1" }, "field200" : { "$numberInt" : "1" } } check_aggregates --------------------------------------------------------------------- (1 row) three_column_data_table.out000066400000000000000000000457631507310017400353670ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2930000; SET documentdb.next_collection_id TO 293000; SET documentdb.next_collection_index_id TO 293000; SET documentdb.enableDataTableWithoutCreationTime to off; -- create table with 4 columns first SELECT documentdb_api.create_collection('db', '4col'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \d documentdb_data.documents_293000 Table "documentdb_data.documents_293000" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | creation_time | timestamp with time zone | | | Indexes: "collection_pk_293000" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '293000'::bigint) SELECT documentdb_api.insert_one('db', '4col', '{ "_id": 1}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- enable GUC SET documentdb.enableDataTableWithoutCreationTime to on; -- [1] let's test 4 column table after enabling GUC -- (1.1) insert to 4 column collection SELECT documentdb_api.insert_one('db', '4col', '{ "_id": 2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (1.2) multiple-insert to 4 column collection SELECT documentdb_api.insert('db', '{"insert":"4col", "documents":[ { "_id" : 3}, { "_id" : 4}, { "_id" : 5}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- (1.3) update to 4 column collection SELECT documentdb_api.update('db', '{"update":"4col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) -- (1.4) aggregate to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.4col", "firstBatch" : [ { "_id" : { "$numberInt" : "1" }, "a" : { "$numberInt" : "1" } }, { "_id" : { "$numberInt" : "2" } }, { "_id" : { "$numberInt" : "3" } }, { "_id" : { "$numberInt" : "4" } }, { "_id" : { "$numberInt" : "5" } } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- (1.5) aggregate to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$project" : {"a" : "GUC IS ENABLED"}},{"$merge" : { "into": "4col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.4col", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.4col", "firstBatch" : [ { "_id" : { "$numberInt" : "1" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "2" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "3" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "4" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "5" }, "a" : "GUC IS ENABLED" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- [2] let's test 3 column table after enabling GUC SELECT documentdb_api.create_collection('db', '3col'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) \d documentdb_data.documents_293001 Table "documentdb_data.documents_293001" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_293001" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '293001'::bigint) -- (2.1) insert to 3 column collection SELECT documentdb_api.insert_one('db', '3col', '{ "_id": 2}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (2.2) multiple-insert to 3 column collection SELECT documentdb_api.insert('db', '{"insert":"3col", "documents":[ { "_id" : 3}, { "_id" : 4}, { "_id" : 5}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- (2.3) update to 3 column collection SELECT documentdb_api.update('db', '{"update":"3col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) -- (2.4) aggregate to 3 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$project" : {"a" : "GUC IS ENABLED"}},{"$merge" : { "into": "3col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.3col", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.3col", "firstBatch" : [ { "_id" : { "$numberInt" : "2" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "3" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "4" }, "a" : "GUC IS ENABLED" }, { "_id" : { "$numberInt" : "5" }, "a" : "GUC IS ENABLED" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) --3. let's disable GUC SET documentdb.enableDataTableWithoutCreationTime to off; -- (3.1) insert to 3 column collection SELECT documentdb_api.insert_one('db', '3col', '{ "_id": 200}'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- (3.2) multiple-insert to 3 column collection SELECT documentdb_api.insert('db', '{"insert":"3col", "documents":[ { "_id" : 300}, { "_id" : 400}, { "_id" : 500}]}'); insert --------------------------------------------------------------------- ("{ ""n"" : { ""$numberInt"" : ""3"" }, ""ok"" : { ""$numberDouble"" : ""1.0"" } }",t) (1 row) -- (3.3) update to 3 column collection SELECT documentdb_api.update('db', '{"update":"3col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""0"" }, ""n"" : { ""$numberInt"" : ""0"" } }",t) (1 row) -- (3.4) aggregate to 3 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "4294967294" }, "ns" : "db.3col", "firstBatch" : [ { "_id" : { "$numberInt" : "2" }, "a" : "GUC IS ENABLED" } ] }, "ok" : { "$numberDouble" : "1.0" } } | { "qi" : { "$numberLong" : "4294967294" }, "qp" : false, "qk" : { "$numberInt" : "2" }, "qc" : { "aggregate" : "3col", "pipeline" : [ { "$match" : { } } ], "cursor" : { "batchSize" : { "$numberInt" : "1" } } }, "continuation" : [ { "table_name" : "documents_293001_2930020", "value" : { "$binary" : { "base64" : "AAAAAAUA", "subType" : "00" } } } ], "numIters" : { "$numberInt" : "1" }, "sn" : NOW_SYS_VARIABLE } | f | 4294967294 (1 row) -- (3.5) $merge to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$project" : {"a" : "GUC IS DISBALE"}},{"$merge" : { "into": "3col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.3col", "firstBatch" : [ ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); cursorpage | continuation | persistconnection | cursorid --------------------------------------------------------------------- { "cursor" : { "id" : { "$numberLong" : "0" }, "ns" : "db.3col", "firstBatch" : [ { "_id" : { "$numberInt" : "2" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "3" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "4" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "5" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "200" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "300" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "400" }, "a" : "GUC IS DISBALE" }, { "_id" : { "$numberInt" : "500" }, "a" : "GUC IS DISBALE" } ] }, "ok" : { "$numberDouble" : "1.0" } } | | f | 0 (1 row) -- lookup test -- create 4 column table for lookup SELECT documentdb_api.insert_one('db','three_column_data_table_from',' {"_id": 1, "col1": "Value1", "col2": ["item1", "item2"], "col3": 100 , "col4": ["item3", "item4"]}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','three_column_data_table_from','{ "_id": 2, "col1": "Value2", "col2": ["item5", "item6"], "col3": 120, "col4": ["item7"]}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) \d documentdb_data.documents_293002 Table "documentdb_data.documents_293002" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | creation_time | timestamp with time zone | | | Indexes: "collection_pk_293002" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '293002'::bigint) -- now create table with 3 column SET documentdb.enableDataTableWithoutCreationTime to on; SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 1, "item": "item1", "ref_col": "Value1"}', NULL); NOTICE: creating collection insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 2, "item": "item5", "ref_col": "Value2", "extra_col": "extra1"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 3, "item": "item5", "ref_col": "Value2", "extra_col": "item7"}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) \d documentdb_data.documents_293003 Table "documentdb_data.documents_293003" Column | Type | Collation | Nullable | Default --------------------------------------------------------------------- shard_key_value | bigint | | not null | object_id | bson | | not null | document | bson | | not null | Indexes: "collection_pk_293003" PRIMARY KEY, btree (shard_key_value, object_id) Check constraints: "shard_key_value_check" CHECK (shard_key_value = '293003'::bigint) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "three_column_data_table_to", "pipeline": [ { "$lookup": { "from": "three_column_data_table_from", "pipeline": [ { "$match": { "col3": { "$gt": 110 } }}], "as": "matched_docs", "localField": "ref_col", "foreignField": "col1" }} ], "cursor": {} }'); document --------------------------------------------------------------------- { "_id" : { "$numberInt" : "1" }, "item" : "item1", "ref_col" : "Value1", "matched_docs" : [ ] } { "_id" : { "$numberInt" : "2" }, "item" : "item5", "ref_col" : "Value2", "extra_col" : "extra1", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "col1" : "Value2", "col2" : [ "item5", "item6" ], "col3" : { "$numberInt" : "120" }, "col4" : [ "item7" ] } ] } { "_id" : { "$numberInt" : "3" }, "item" : "item5", "ref_col" : "Value2", "extra_col" : "item7", "matched_docs" : [ { "_id" : { "$numberInt" : "2" }, "col1" : "Value2", "col2" : [ "item5", "item6" ], "col3" : { "$numberInt" : "120" }, "col4" : [ "item7" ] } ] } (3 rows) users_libpq_permissioning.out000066400000000000000000000072741507310017400360340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path to documentdb_api_catalog; SET citus.next_shard_id TO 11980000; SET documentdb.next_collection_id TO 11980; SET documentdb.next_collection_index_id TO 11980; -- create new user with basic and insufficient permissions CREATE ROLE user_2 WITH LOGIN PASSWORD 'pass'; GRANT ALL PRIVILEGES ON SCHEMA documentdb_api_catalog TO user_2; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA documentdb_api_catalog TO user_2; GRANT SELECT ON ALL TABLES IN SCHEMA documentdb_data TO user_2; GRANT USAGE ON SCHEMA documentdb_data TO user_2; GRANT USAGE ON SCHEMA documentdb_api TO user_2; GRANT USAGE ON SCHEMA documentdb_api_internal TO user_2; -- create a collection SELECT documentdb_api.create_collection('db', 'test_coll'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) -- insert some data SELECT documentdb_api.insert_one('db','test_coll','{"_id":"1", "a": { "$numberInt" : "11" }, "b": { "$numberInt" : "214748" }, "c": { "$numberInt" : "100" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test_coll','{"_id":"2", "a": { "$numberInt" : "16" }, "b": { "$numberInt" : "214740" }, "c": { "$numberInt" : "-22" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT documentdb_api.insert_one('db','test_coll','{"_id":"3", "a": { "$numberInt" : "52" }, "b": { "$numberInt" : "121212" }, "c": { "$numberInt" : "101" }}', NULL); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- switch to the new user (user_2) SELECT current_user as original_user \gset ALTER TABLE documentdb_data.documents_11980 OWNER TO user_2; \c regression user_2 -- should fail index creation SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_coll", "indexes": [ { "key" : { "a": 1 }, "name": "index_a"}] }', true); ERROR: permission denied for schema documentdb_core -- switch back to default user \c regression :original_user ALTER TABLE documentdb_data.documents_11980 OWNER TO documentdb_admin_role; -- index creation should succeed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_coll", "indexes": [ { "key" : { "a": 1 }, "name": "index_a"}] }', true); create_indexes_non_concurrently --------------------------------------------------------------------- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } (1 row) -- revoke all privileges and drop role REVOKE ALL PRIVILEGES ON SCHEMA documentdb_api_catalog FROM user_2; REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA documentdb_api_catalog FROM user_2; REVOKE SELECT ON ALL TABLES IN SCHEMA documentdb_data FROM user_2; REVOKE USAGE ON SCHEMA documentdb_data FROM user_2; REVOKE USAGE ON SCHEMA documentdb_api FROM user_2; REVOKE USAGE ON SCHEMA documentdb_api_internal FROM user_2; DROP ROLE IF EXISTS user_2; write_commands_batching.out000066400000000000000000000402571507310017400354060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/expectedSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 662000; SET documentdb.next_collection_id TO 6620; SET documentdb.next_collection_index_id TO 6620; CREATE SCHEMA bulk_write; SELECT documentdb_api.create_collection('db', 'write_batching'); NOTICE: creating collection create_collection --------------------------------------------------------------------- t (1 row) CREATE FUNCTION bulk_write.do_bulk_insert(numIterations int, ordered bool) RETURNS bson SET search_path TO documentdb_core,documentdb_api_catalog, pg_catalog AS $fn$ DECLARE v_insertSpec bson; v_resultDocs bson; BEGIN WITH r1 AS ( SELECT array_agg(FORMAT('{ "_id": %s, "a": %s}', g, g)::bson) AS "documents" FROM generate_series(1, numIterations) g), r2 AS (SELECT 'write_batching' AS "insert", r1.documents AS "documents", ordered AS "ordered" FROM r1) SELECT row_get_bson(r2) INTO v_insertSpec FROM r2; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); RETURN v_resultDocs; END; $fn$ LANGUAGE plpgsql; CREATE FUNCTION bulk_write.do_bulk_update(numIterations int, ordered bool) RETURNS bson SET search_path TO documentdb_core,documentdb_api_catalog, pg_catalog AS $fn$ DECLARE v_updateSpec bson; v_resultDocs bson; BEGIN WITH r1 AS ( SELECT array_agg(FORMAT('{ "q": { "_id": %s}, "u": { "$inc": { "a": 1 } } }', MOD(g, 10) + 1)::bson) AS "documents" FROM generate_series(1, numIterations) g), r2 AS (SELECT 'write_batching' AS "update", r1.documents AS "updates", ordered AS "ordered" FROM r1) SELECT row_get_bson(r2) INTO v_updateSpec FROM r2; SELECT p_result INTO v_resultDocs FROM documentdb_api.update('db', v_updateSpec); RETURN v_resultDocs; END; $fn$ LANGUAGE plpgsql; -- try a small amount. BEGIN; SELECT bulk_write.do_bulk_insert(10, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "10" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ROLLBACK; -- try an extremely large batch (maxBatchSize) BEGIN; SELECT bulk_write.do_bulk_insert(25000, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "25000" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) ROLLBACK; -- try an extremely large batch (maxBatchSize + 1 ) fails BEGIN; SELECT bulk_write.do_bulk_insert(25001, false); ERROR: Write batch size must fall within the range of 1 to 25000, but 25001 operations were provided. CONTEXT: SQL statement "SELECT p_result FROM documentdb_api.insert('db', v_insertSpec)" PL/pgSQL function bulk_write.do_bulk_insert(integer,boolean) line 11 at SQL statement ROLLBACK; BEGIN; SELECT bulk_write.do_bulk_insert(25001, true); ERROR: Write batch size must fall within the range of 1 to 25000, but 25001 operations were provided. CONTEXT: SQL statement "SELECT p_result FROM documentdb_api.insert('db', v_insertSpec)" PL/pgSQL function bulk_write.do_bulk_insert(integer,boolean) line 11 at SQL statement ROLLBACK; -- introduce a failure in the 432'th position (Everything before that succeeds) BEGIN; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 432, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(5000, true); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "431" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "431" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 432 (1 row) ROLLBACK; -- introduce a failure in the 432'th position (Everything except that succeeds) BEGIN; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 432, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(5000, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "4999" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "431" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 5000 (1 row) ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(35, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "34" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "30" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 35 (1 row) ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(39, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "38" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "30" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 39 (1 row) ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(40, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "39" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "30" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 40 (1 row) ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); insert_one --------------------------------------------------------------------- { "n" : { "$numberInt" : "1" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) SELECT bulk_write.do_bulk_insert(41, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "40" }, "ok" : { "$numberDouble" : "1.0" }, "writeErrors" : [ { "index" : { "$numberInt" : "30" }, "code" : { "$numberInt" : "319029277" }, "errmsg" : "Duplicate key violation on the requested collection: Index '_id_'" } ] } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); count --------------------------------------------------------------------- 41 (1 row) ROLLBACK; -- now insert 10 docs and commit SELECT bulk_write.do_bulk_insert(10, false); do_bulk_insert --------------------------------------------------------------------- { "n" : { "$numberInt" : "10" }, "ok" : { "$numberDouble" : "1.0" } } (1 row) -- do a small bulk update BEGIN; SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching') WHERE document->'_id' = document->'a'; count --------------------------------------------------------------------- 10 (1 row) SELECT bulk_write.do_bulk_update(10, false); do_bulk_update --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } (1 row) SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching') WHERE document->'_id' = document->'a'; count --------------------------------------------------------------------- 0 (1 row) ROLLBACK; BEGIN; SELECT bulk_write.do_bulk_update(10, true); do_bulk_update --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10" }, "n" : { "$numberInt" : "10" } } (1 row) ROLLBACK; BEGIN; -- do a large number (fail) SELECT bulk_write.do_bulk_update(25001, false); ERROR: Batch sizes should always fall between 1 and 25000. Got 25001 operations. CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6620 WHERE shard_key_value = 6620" SQL statement "SELECT p_result FROM documentdb_api.update('db', v_updateSpec)" PL/pgSQL function bulk_write.do_bulk_update(integer,boolean) line 11 at SQL statement ROLLBACK; BEGIN; -- do a large number (fail) SELECT bulk_write.do_bulk_update(25001, true); ERROR: Batch sizes should always fall between 1 and 25000. Got 25001 operations. CONTEXT: SQL statement " SELECT documentdb_api_internal.update_worker($1, $2, $3, $4::documentdb_core.bson, $5::documentdb_core.bsonsequence, $6) FROM documentdb_data.documents_6620 WHERE shard_key_value = 6620" SQL statement "SELECT p_result FROM documentdb_api.update('db', v_updateSpec)" PL/pgSQL function bulk_write.do_bulk_update(integer,boolean) line 11 at SQL statement ROLLBACK; BEGIN; -- do a large number SELECT bulk_write.do_bulk_update(10000, false); do_bulk_update --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "10000" }, "n" : { "$numberInt" : "10000" } } (1 row) ROLLBACK; -- introduce an error in one document BEGIN; SELECT documentdb_api.update('db', '{ "update": "write_batching", "updates": [{ "q": { "_id": 5 }, "u": { "$set": { "a": "this is a string" } } }] }'); update --------------------------------------------------------------------- ("{ ""ok"" : { ""$numberDouble"" : ""1.0"" }, ""nModified"" : { ""$numberInt"" : ""1"" }, ""n"" : { ""$numberInt"" : ""1"" } }",t) (1 row) set local documentdb.batchWriteSubTransactionCount TO 40; SELECT bulk_write.do_bulk_update(50, false); do_bulk_update --------------------------------------------------------------------- { "ok" : { "$numberDouble" : "1.0" }, "nModified" : { "$numberInt" : "45" }, "n" : { "$numberInt" : "45" }, "writeErrors" : [ { "index" : { "$numberInt" : "3" }, "code" : { "$numberInt" : "67108893" }, "errmsg" : "Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string." }, { "index" : { "$numberInt" : "13" }, "code" : { "$numberInt" : "67108893" }, "errmsg" : "Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string." }, { "index" : { "$numberInt" : "23" }, "code" : { "$numberInt" : "67108893" }, "errmsg" : "Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string." }, { "index" : { "$numberInt" : "33" }, "code" : { "$numberInt" : "67108893" }, "errmsg" : "Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string." }, { "index" : { "$numberInt" : "43" }, "code" : { "$numberInt" : "67108893" }, "errmsg" : "Operation $inc cannot be performed because the target value is not numeric. Document { _id: 5 } contains the field 'a' which is of non-numeric type string." } ] } (1 row) ROLLBACK; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/minimal_schedule000066400000000000000000000001141507310017400314720ustar00rootroot00000000000000test: documentdb_distributed_setup test: documentdb_distributed_test_helpersdocumentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/mutate_schedule.sh000077500000000000000000000022261507310017400317650ustar00rootroot00000000000000#!/bin/bash targetFile=$1 pg_version=$2 source="${BASH_SOURCE[0]}" while [[ -h $source ]]; do scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" source="$(readlink "$source")" # if $source was a relative symlink, we need to resolve it relative to the path where the # symlink file was located [[ $source != /* ]] && source="$scriptroot/$source" done scriptDir="$( cd -P "$( dirname "$source" )" && pwd )" sed -i -e "s/!MAJOR_VERSION!/${pg_version}/g" $targetFile if (( $pg_version >= 16 )); then sed -i -e "s/!PG16_OR_HIGHER!/_pg16/g" $targetFile else sed -i -e "s/!PG16_OR_HIGHER!//g" $targetFile fi if (( $pg_version >= 17 )); then sed -i -e "s/!PG17_OR_HIGHER!/_pg17/g" $targetFile else sed -i -e "s/!PG17_OR_HIGHER!//g" $targetFile fi function ProcessMutateFile() { local mutateFile=$1 if [ -f $mutateFile ]; then cat $mutateFile | while read line do sed -i -e "$line" $targetFile done else echo "No version specific mutation at $mutateFile. Skipping" fi } ProcessMutateFile "./test_mutate_${pg_version}" ProcessMutateFile "$scriptDir/test_mutate_${pg_version}" documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/postgresql.conf000066400000000000000000000021041507310017400313200ustar00rootroot00000000000000shared_preload_libraries = 'citus,pg_cron,pg_documentdb_core,pg_documentdb,pg_documentdb_distributed' # Set default encoding to UTF8 for testing client_encoding = 'UTF8' max_connections = 300 cron.database_name = 'regression' max_prepared_transactions = 100 citus.propagate_set_commands = 'local' citus.shard_count = 8 citus.log_distributed_deadlock_detection = true citus.allow_unsafe_constraints = 'true' # Set default encoding to UTF8 for testing client_encoding = 'UTF8' cron.log_statement = false documentdb_core.bsonUseEJson = on documentdb.indexBuildScheduleInSec = 1 citus.enable_non_colocated_router_query_pushdown='true' wal_level = logical documentdb.blockedRolePrefixList = 'documentdb,pg,citus' # set compression threshold for index terms documentdb.index_term_compression_threshold = 128 documentdb.enableCompact = 'true' # Background worker job configs documentdb.bg_worker_database_name = 'regression' documentdb.enableBackgroundWorker = 'true' documentdb.enableBackgroundWorkerJobs = 'true' documentdb.rum_library_load_option = 'require_documentdb_extended_rum' documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/000077500000000000000000000000001507310017400270505ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/and.sql000066400000000000000000000115451507310017400303410ustar00rootroot00000000000000-- Based on and.js CREATE SCHEMA and1; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,and1; SET citus.next_shard_id TO 549000; SET documentdb.next_collection_id TO 5490; SET documentdb.next_collection_index_id TO 5490; SELECT 1 FROM drop_collection('db','and1'); SELECT 1 FROM insert_one('db','and1', '{"a":[1,2]}'); SELECT 1 FROM insert_one('db','and1', '{"a":"foo"}'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'and1'); CREATE OR REPLACE FUNCTION and1.assert_count(expected_row_count int, query bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','and1') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; CREATE OR REPLACE FUNCTION and1.check1() RETURNS void LANGUAGE plpgsql AS $$ BEGIN /* -- $and must be an array assert.throws(function() { '{"$and": 4}).toArray(); }); -- $and array must not be empty assert.throws(function() { '{"$and": []}).toArray(); }); -- $and elements must be objects assert.throws(function() { '{"$and": [4]}).toArray(); }); */ -- Check equality matching PERFORM assert_count(1, '{"$and": [{"a": 1}]}'); PERFORM assert_count(1, '{"$and": [{"a": 1}, {"a": 2}]}'); PERFORM assert_count(0, '{"$and": [{"a": 1}, {"a": 3}]}'); PERFORM assert_count(0, '{"$and": [{"a": 1}, {"a": 2}, {"a": 3}]}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}]}'); PERFORM assert_count(0, '{"$and": [{"a": "foo"}, {"a": "g"}]}'); -- Check $and with other fields PERFORM assert_count(1, '{"a": 2, "$and": [{"a": 1}]}'); PERFORM assert_count(0, '{"a": 0, "$and": [{"a": 1}]}'); PERFORM assert_count(0, '{"a": 2, "$and": [{"a": 0}]}'); PERFORM assert_count(1, '{"a": 1, "$and": [{"a": 1}]}'); -- Check recursive $and PERFORM assert_count(1, '{"a": 2, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"a": 0, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"a": 2, "$and": [{"$and": [{"a": 0}]}]}'); PERFORM assert_count(1, '{"a": 1, "$and": [{"$and": [{"a": 1}]}]}'); PERFORM assert_count(1, '{"$and": [{"a": 2}, {"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"$and": [{"a": 0}, {"$and": [{"a": 1}]}]}'); PERFORM assert_count(0, '{"$and": [{"a": 2}, {"$and": [{"a": 0}]}]}'); PERFORM assert_count(1, '{"$and": [{"a": 1}, {"$and": [{"a": 1}]}]}'); -- Some of these cases were more important with an alternative $and syntax -- that was rejected, but they're still valid check1s. -- Check simple regex PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}]}'); -- Check multiple regexes PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}, {"a": {"$regularExpression":{"pattern":"^f","options":""}}}, {"a": {"$regularExpression":{"pattern":"o","options":""}}}]}'); PERFORM assert_count(0, '{"$and": [{"a": {"$regularExpression":{"pattern":"foo","options":""}}}, {"a": {"$regularExpression":{"pattern":"^g","options":""}}}]}'); PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^f","options":""}}}, {"a": "foo"}]}'); -- Check regex flags PERFORM assert_count(0, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":""}}}, {"a": "foo"}]}'); --PERFORM assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":"i"}}}, {"a": "foo"}]}'); -- Check operator PERFORM assert_count(1, '{"$and": [{"a": {"$gt": 0}}]}'); /* -- Check where PERFORM assert_count(1, '{"a": "foo", "$where": "this.a==\"foo\""}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}], "$where": "this.a==\"foo\""}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}], "$where": "this.a==\"foo\""}'); -- Nested where ok PERFORM assert_count(1, '{"$and": [{"$where": "this.a==\"foo\""}]}'); PERFORM assert_count(1, '{"$and": [{"a": "foo"}, {"$where": "this.a==\"foo\""}]}'); PERFORM assert_count(1, '{"$and": [{"$where": "this.a==\"foo\""}], "$where": "this.a==\"foo\""}'); */ END; $$; SELECT check1(); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('and1', 'index_1', '{"a.$**": 1}'), true); BEGIN; set local enable_seqscan TO OFF; SELECT check1(); ROLLBACK; SELECT assert_count(1, '{"a": 1, "$and": [{"a": 2}]}'); SELECT assert_count(1, '{"$and": [{"a": 1}, {"a": 2}]}'); -- with regex options SELECT assert_count(1, '{"$and": [{"a": {"$regularExpression":{"pattern":"^F","options":"i"}}}, {"a": "foo"}]}'); SELECT drop_collection('db','and1'); DROP SCHEMA and1 CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/and3.sql000066400000000000000000000112721507310017400304210ustar00rootroot00000000000000-- Based on and3.js CREATE SCHEMA and3; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,and3; SET citus.next_shard_id TO 547000; SET documentdb.next_collection_id TO 5470; SET documentdb.next_collection_index_id TO 5470; SELECT drop_collection('db','and3'); SELECT 1 FROM insert_one('db','and3', '{"a":3}'); SELECT 1 FROM insert_one('db','and3', '{"a":"foo"}'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'and3'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('and3', 'index_1', '{"a.$**": 1}'), true); -- examined_row_count is currently ignored CREATE OR REPLACE FUNCTION and3.checkScanMatch(query bson, examined_row_count int, expected_row_count int) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','and3') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT checkScanMatch('{"a": {"$regularExpression":{"pattern":"o","options":""}}}', 1, 1); SELECT checkScanMatch('{"a": {"$regularExpression":{"pattern":"a","options":""}}}', 0, 0); SELECT checkScanMatch('{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}', 2, 1); SELECT checkScanMatch('{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}', 2, 2); SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 1, 1); SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 0, 0); SELECT checkScanMatch('{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 2, 1); SELECT checkScanMatch('{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}', 2, 2); SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}, {"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 1, 0); SELECT checkScanMatch('{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}, {"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}', 1, 1); SELECT checkScanMatch('{"$or": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 1, 1); SELECT checkScanMatch('{"$or": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 0, 0); SELECT checkScanMatch('{"$nor": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}', 2, 1); SELECT checkScanMatch('{"$nor": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}', 2, 2); SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 1, 1); SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 0, 0); SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}]}', 2, 1); SELECT checkScanMatch('{"$and": [{"$and": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}]}', 2, 2); SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 1, 1); SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 0, 0); SELECT checkScanMatch('{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}', 2, 1); SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"o","options":""}}}}]}]}', 2, 1); SELECT checkScanMatch('{"$and": [{"$or": [{"a": {"$not": {"$regularExpression":{"pattern":"a","options":""}}}}]}]}', 2, 2); SELECT checkScanMatch('{"$and": [{"$nor": [{"a": {"$regularExpression":{"pattern":"o","options":""}}}]}]}', 2, 1); SELECT checkScanMatch('{"$and": [{"$nor": [{"a": {"$regularExpression":{"pattern":"a","options":""}}}]}]}', 2, 2); -- $where is not yet supported SELECT checkScanMatch('{"$where": "this.a==1"}', 2, 1); SELECT checkScanMatch('{"$and": [{"$where": "this.a==1"}]}', 2, 1); SELECT checkScanMatch('{"a": 1, "$where": "this.a==1"}', 1, 1); SELECT checkScanMatch('{"a": 1, "$and": [{"$where": "this.a==1"}]}', 1, 1); SELECT checkScanMatch('{"$and": [{"a": 1}, {"$where": "this.a==1"}]}', 1, 1); SELECT checkScanMatch('{"$and": [{"a": 1, "$where": "this.a==1"}]}', 1, 1); SELECT checkScanMatch('{"a": 1, "$and": [{"a": 1}, {"a": 1, "$where": "this.a==1"}]}', 1, 1); -- these are supported SELECT checkScanMatch('{"a": 1, "$and": [{"a": 2}]}', NULL, 0); SELECT checkScanMatch('{"$and": [{"a": 1}, {"a": 2}]}', NULL, 0); SELECT drop_collection('db','and3'); DROP SCHEMA and3 CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/andor.sql000066400000000000000000000077741507310017400307130ustar00rootroot00000000000000-- Based on andor.js CREATE SCHEMA andor; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,andor; SET citus.next_shard_id TO 548000; SET documentdb.next_collection_id TO 5480; SET documentdb.next_collection_index_id TO 5480; CREATE OR REPLACE FUNCTION andor.ok(query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ BEGIN IF NOT EXISTS (SELECT 1 FROM collection('db','andor') WHERE document @@ query) THEN RAISE 'query return no rows: %', query::text; END IF; END; $$; SELECT 1 FROM drop_collection('db','andor'); SELECT 1 FROM insert_one('db','andor','{"a": 1}'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'andor'); CREATE OR REPLACE FUNCTION andor.test1() RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM ok('{"a": 1}'); PERFORM ok('{"$and": [{"a": 1}]}'); PERFORM ok('{"$or": [{"a": 1}]}'); PERFORM ok('{"$and": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$or": [{"$or": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$or": [{"a": 1}]}]}'); PERFORM ok('{"$or": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$or": [{"a": 1}]}]}]}'); PERFORM ok('{"$and": [{"$or": [{"$and": [{"a": 1}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$and": [{"a": 1}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$or": [{"a": 1}]}]}]}'); -- now test $nor PERFORM ok('{"$and": [{"a": 1}]}'); PERFORM ok('{"$nor": [{"a": 2}]}'); PERFORM ok('{"$and": [{"$and": [{"a": 1}]}]}'); PERFORM ok('{"$nor": [{"$nor": [{"a": 1}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"a": 2}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"a": 2}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$nor": [{"a": 2}]}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"$and": [{"a": 2}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$and": [{"a": 2}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$nor": [{"a": 1}]}]}]}'); END; $$; SELECT test1(); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('andor', 'index_1', '{"a.$**": 1}'), true); BEGIN; set local enable_seqscan TO OFF; SELECT test1(); ROLLBACK; -- Test an inequality base match. CREATE OR REPLACE FUNCTION andor.test2() RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM ok('{"a": {"$ne": 2}}'); PERFORM ok('{"$and": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$or": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$or": [{"$or": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$or": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$and": [{"$or": [{"$and": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}]}'); PERFORM ok('{"$or": [{"$and": [{"$or": [{"a": {"$ne": 2}}]}]}]}'); -- now test $nor PERFORM ok('{"$and": [{"a": {"$ne": 2}}]}'); PERFORM ok('{"$nor": [{"a": {"$ne": 1}}]}'); PERFORM ok('{"$and": [{"$and": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$nor": [{"$nor": [{"a": {"$ne": 2}}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"a": {"$ne": 1}}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"a": {"$ne": 1}}]}]}'); PERFORM ok('{"$and": [{"$and": [{"$nor": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$and": [{"$nor": [{"$and": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$and": [{"a": {"$ne": 1}}]}]}]}'); PERFORM ok('{"$nor": [{"$and": [{"$nor": [{"a": {"$ne": 2}}]}]}]}'); END; $$; SELECT 1 FROM drop_collection('db','andor'); SELECT 1 FROM insert_one('db','andor','{"a": 1}'); SELECT test2(); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('andor', 'index_2', '{"a.$**": 1}'), true); BEGIN; set local enable_seqscan TO OFF; SELECT test2(); ROLLBACK; SELECT drop_collection('db','andor'); DROP SCHEMA andor CASCADE; bson_aggregates_distinct_tests.sql000066400000000000000000000206731507310017400357770ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6630000; SET documentdb.next_collection_id TO 6630; SET documentdb.next_collection_index_id TO 6630; SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 1, "b": { "c": "foo" } }'); SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "bar" } }'); SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "baz" } }'); SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 2, "b": { "c": "foo" } }'); SELECT documentdb_api.insert_one('db', 'distinct1', '{ "a": 3, "b": { "c": "foo" } }'); -- this is what the query will look like from the GW PREPARE distinctQuery(text, text, text) AS (WITH r1 AS (SELECT DISTINCT bson_distinct_unwind(document, $3) AS document FROM documentdb_api.collection($1, $2)) SELECT bson_build_distinct_response(COALESCE(array_agg(document), '{}'::bson[])) FROM r1); PREPARE distinctQueryWithFilter(text, text, text, bson) AS (WITH r1 AS (SELECT DISTINCT bson_distinct_unwind(document, $3) AS document FROM documentdb_api.collection($1, $2) WHERE document @@ $4 ) SELECT bson_build_distinct_response(COALESCE(array_agg(document), '{}'::bson[])) FROM r1); EXECUTE distinctQuery('db', 'distinct1', 'a'); EXECUTE distinctQueryWithFilter('db', 'distinct1', 'a', '{ "a": { "$lt": 3 }}'); EXECUTE distinctQuery('db', 'distinct1', 'b.c'); SELECT documentdb_api.insert_one('db', 'distinct2', '{ "a": null }'); EXECUTE distinctQuery('db', 'distinct2', 'a.b'); SELECT documentdb_api.insert_one('db', 'distinct2', '{ "b": 1 }'); SELECT documentdb_api.insert_one('db', 'distinct2', '{ }'); EXECUTE distinctQuery('db', 'distinct2', 'b'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 2, 3, 4 ] }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": [ 3, 4, 5 ] }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "a": 9 }'); EXECUTE distinctQuery('db', 'distinct3', 'a'); EXECUTE distinctQuery('db', 'distinct3', 'a.0'); EXECUTE distinctQuery('db', 'distinct3', 'a.1'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "a" }, { "b": "d"} ], "c": 12 }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "b" }, { "b": "d"} ], "c": 12 }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "c" }, { "b": "e"} ], "c": 12 }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ { "b": "c" }, { "b": "f"} ], "c": 12 }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": [ ], "c": 12 }'); SELECT documentdb_api.insert_one('db', 'distinct3', '{ "e": { "b": "z" }, "c": 12 }'); EXECUTE distinctQuery('db', 'distinct3', 'e.b'); EXECUTE distinctQuery('db', 'distinct3', 'e.0.b'); EXECUTE distinctQuery('db', 'distinct3', 'e.1.b'); EXECUTE distinctQuery('db', 'distinct3', 'e'); EXECUTE distinctQueryWithFilter('db', 'distinct3', 'e.b', '{ "e.b": { "$gt": "d" } }'); SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 1 } } }'); SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 2 } } }'); SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "c": 3 } } }'); SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "b": { "notRelevant": 3 } } }'); SELECT documentdb_api.insert_one('db', 'distinct4', '{ "a": { "notRelevant": 3 } }'); EXECUTE distinctQueryWithFilter('db', 'distinct4', 'a.b.c', '{ "a.b.c": { "$gt": 0 } }'); EXECUTE distinctQueryWithFilter('db', 'distinct4', 'a.b.c', '{ "a.b.c": { "$gt": 1 } }'); -- test for DBRef SELECT documentdb_api.insert_one('db', 'distinct5', '{ "a": 1, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }}}'); select documentdb_api.insert_one('db', 'distinct5', '{ "a": 2, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19cea" }}}'); select documentdb_api.insert_one('db', 'distinct5', '{ "a": 3, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19cea" }}}'); select documentdb_api.insert_one('db', 'distinct6', '{ "_id": { "$oid" : "147f000000c1de008ec19cea" }, "c": 1}'); select documentdb_api.insert_one('db', 'distinct6', '{ "_id": { "$oid" : "147f000000c1de008ec19ceb" }, "c": 2}'); EXECUTE distinctQueryWithFilter('db', 'distinct5', 'a', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" } } }'); EXECUTE distinctQueryWithFilter('db', 'distinct5', 'a', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19cea" } } }'); -- optional parameter - $db SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 20, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }, "$db": "db" }}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 30, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ceb" }}}'); -- expect to get 20 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" }, "$db": "db" } }'); -- expect to get 30 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ceb" } } }'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 1, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce1" }}}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 2, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce2" }}}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 3, "b": { "$id" : { "$oid" : "147f000000c1de008ec19ce3" }, "$ref" : "distinct6" }}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 4, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce4" }}}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 5, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce5" }}}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 6, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }}}'); SELECT documentdb_api.insert_one('db2', 'distinct7', '{ "d": 7, "b": { "$ref" : "distinct6", "$id" : { "$oid" : "147f000000c1de008ec19ce6" }, "$db": "db", "tt":1}}'); -- expect to get 3 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": {"$id": { "$oid" : "147f000000c1de008ec19ce3" }, "$ref" : "distinct6"} }'); -- expect to get 7 EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 } }'); -- expect to get null EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db" } }'); -- expect to work in $in/$nin EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$in": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$nin": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); -- index SELECT documentdb_api_internal.create_indexes_non_concurrently('db2', '{ "createIndexes": "distinct7", "indexes": [ { "key": { "b": 1 }, "name": "ref_idx" } ] }', true); ANALYZE; begin; SET LOCAL enable_seqscan to off; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" } } }'); EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 } }'); EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": {"$id": { "$oid" : "147f000000c1de008ec19ce6" }, "$ref" : "distinct6"}}'); EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) EXECUTE distinctQueryWithFilter('db2', 'distinct7', 'd', '{ "b": { "$in": [ { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce6" },"$db": "db", "tt":1 }, { "$ref": "distinct6", "$id": { "$oid" : "147f000000c1de008ec19ce4" }} ] } }'); commit; bson_aggregation_arithmetic_operators_tests.sql000066400000000000000000001602161507310017400405610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6800000; SET documentdb.next_collection_id TO 6800; SET documentdb.next_collection_index_id TO 6800; -- $add operator -- Returns expected result SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$add": [ "$a", "$b", 0 ]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$add": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$add": [ "$a", 1]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": [ "$a", 1]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", 86400000]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", 100]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", {"$numberDouble": "43200000.56"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", {"$numberDecimal": "1e10"}]}}'); -- A single expression is also valid SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": "$a"}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": "$b"}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": NaN}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$add": null}}'); -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":2147483646}', '{"result": { "$add": [ "$a", 2]}}'); SELECT * FROM bson_dollar_project('{"a":1073741823, "b": 1073741825}', '{"result": { "$add": [ "$a", "$b"]}}'); -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$add": [ "$a", 2]}}'); -- Any null should project to null (even if it is a date overflow), non-existent paths return null if there is no date overflow SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$add": [ "$a", "$b", 0 ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$add": [ "$a", "$b", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": null}', '{"result": { "$add": [ "$a", "$b", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$add": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$add": [ "$a", "$a.b" ]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "9223372036854775807" }} }', '{"result": { "$add": [ "$a", 100, 100, null ]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "9223372036854775807" }}, "b": null }', '{"result": { "$add": [ "$a", 100, 100, "$b" ]}}'); -- Should return invalid date (INT64_MAX) if there is a decimal128 overflow SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "1e5000"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "Infinity"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": { "$numberLong" : "0" }}, {"$numberDouble": "NaN"}, {"$numberDecimal": "1"}]}}'); -- Should round to nearest even for date operations SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDouble": "819.4"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDouble": "819.56"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDecimal": "819.4899999"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$add": [ {"$date": "2019-01-30T07:30:10.136Z"}, {"$numberDecimal": "819.5359123621083"}]}}'); -- Should error with non-numeric or date expressions SELECT * FROM bson_dollar_project('{"a":{ }, "b": null}', '{"result": { "$add": [ "$a", 922, 1 ]}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": "false"}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": [2, 3]}', '{"result": { "$add": [ "$a", "$b", 1 ]}}'); SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$add": [ "$a.0", "$a.1", 0 ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", "string" ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", true ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$add": [ "$a", {} ]}}'); -- Should error if multiple dates are passed in SELECT * FROM bson_dollar_project('{"a":{ "$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":{ "$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ 1, 2, "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a": 100, "b": {"$date": { "$numberLong" : "1000" }}}', '{"result": { "$add": [ 1, 2, "$a", "$b", {"$date": {"$numberLong": "1000"}} ]}}'); -- Should error if date overflows SELECT * FROM bson_dollar_project('{"a": 100, "b": {"$date": { "$numberLong" : "9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a": -100, "b": {"$date": { "$numberLong" : "-9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a": -100, "b": {"$date": { "$numberLong" : "-9223372036854775807" }}}', '{"result": { "$add": [ "$a", "$b", "$c" ]}}'); SELECT * FROM bson_dollar_project('{"a": {"$numberDouble": "100.58"}, "b": {"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", "$b", {"$numberDouble": "9223372036854775800.22"} ]}}'); SELECT * FROM bson_dollar_project('{"a": {"$numberDouble": "100.58"}, "b": {"$date": { "$numberLong" : "0" }}}', '{"result": { "$add": [ "$a", "$b", NaN ]}}'); -- $subtract operator -- Returns expected result SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$subtract": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$subtract": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$subtract": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$subtract": [ "$a", 1]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "1232"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "1232"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDecimal": "102123"}}', '{"result": { "$subtract": [ "$a", {"$numberDecimal": "-1232"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$subtract": [ "$a", -1000]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", 86400000]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", -86400000]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}}', '{"result": { "$subtract": [ "$a", {"$numberDouble": "43200000.56"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": { "$numberLong" : "0" }}, "b": {"$date": { "$numberLong" : "86000" }}}', '{"result": { "$subtract": [ "$a", "$b"]}}'); -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":2147483646}', '{"result": { "$subtract": [ "$a", -2]}}'); SELECT * FROM bson_dollar_project('{"a":-1073741825, "b": 1073741825}', '{"result": { "$subtract": [ "$a", "$b"]}}'); -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$subtract": [ "$a", -2]}}'); SELECT * FROM bson_dollar_project('{"a":-9223372036854775807}', '{"result": { "$subtract": [ "$a", 2]}}'); -- Null or undefined path should result to null SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$subtract": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$subtract": [ "$a", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": null}', '{"result": { "$subtract": [ "$b", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$subtract": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$subtract": [ "$a", "$a.b" ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ "string", null ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ {"$date":{"$numberLong": "0"}}, null ]}}'); -- Should error if no numbers or dates are passed in SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [ "$a", 922 ]}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$subtract": [ "$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ "string", 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": [ 1, "string"]}}'); SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$subtract": [ "$a.0", 0 ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", true ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {} ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {} ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$subtract": [ "$a", {"$date": {"$numberLong": "2"}}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$date": {"$numberLong": "0"}}}', '{"result": { "$subtract": [ "$a", true]}}'); -- Should error if wrong number of args is provided SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": "$a" }}'); SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [] }}'); SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$subtract": [{"$subtract": [1, 2, 3]}, 2, 4, 5] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$subtract": ["$a", 1, 3] }}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": "string"}', '{"result": { "$subtract": ["$a", "$b", "$c"] }}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": "string"}', '{"result": { "$subtract": ["$a", "$b", "$c", 2, 3, 3, 3, 3] }}'); -- $multiply operator -- Returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": 1}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$multiply": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": { "$numberDouble" : "NaN" }}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$multiply": ["$a", { "$numberDouble" : "NaN" }] }}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$multiply": [ "$a", "$b", 3 ]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$multiply": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$multiply": [ "$a.b", "$a.c", -1]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$multiply": [ "$a", 1]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "1232"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "1232"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDecimal": "102123"}}', '{"result": { "$multiply": [ "$a", {"$numberDecimal": "-1232"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$multiply": [ "$a", -1000]}}'); -- Int32 overflow to -> Int64 SELECT * FROM bson_dollar_project('{"a":1073741824}', '{"result": { "$multiply": [ "$a", 2]}}'); SELECT * FROM bson_dollar_project('{"a":-1073741824}', '{"result": { "$multiply": [ "$a", 2, 2]}}'); -- Int64 overflow coerce to double SELECT * FROM bson_dollar_project('{"a":9223372036854775807}', '{"result": { "$multiply": [ "$a", 2]}}'); SELECT * FROM bson_dollar_project('{"a":-9223372036854775807}', '{"result": { "$multiply": [ "$a", 2]}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": null}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$multiply": "$a.b"}}'); SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$multiply": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$multiply": [ "$a", "$b", 3, 100, null ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$multiply": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$multiply": [ "$a", "$a.b" ]}}'); -- Should error if no number is provided SELECT * FROM bson_dollar_project('{"a":{ }}', '{"result": { "$multiply": [ "$a", 922 ]}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": false}', '{"result": { "$multiply": [ "$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": [ "string", 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$multiply": [ 1, "string"]}}'); SELECT * FROM bson_dollar_project('{"a":[1,2]}', '{"result": { "$multiply": [ "$a.0", 2 ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$multiply": [ "$a", true ]}}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$multiply": [ "$a", {} ]}}'); SELECT * FROM bson_dollar_project('{"a":{}}', '{"result": { "$multiply": [ "$a", 32 ]}}'); -- $divide operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [3, 2]}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$divide": ["$a", 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [{ "$numberDouble" : "NaN" }, 2]}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$divide": ["$a", { "$numberDouble" : "NaN" }] }}'); SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$divide": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$divide": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999999"}}', '{"result": { "$divide": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$divide": [ "$a", 5]}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [null, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [null, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": ["str", null]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$divide": ["$a", "$a.b"]}}'); SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$divide": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$divide": [ "$a", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$divide": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$divide": [ "$a", "$a.b" ]}}'); -- Divide by zero is not allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, {"$numberLong": "0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, {"$numberDecimal": "0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, 0.0]}}'); SELECT * FROM bson_dollar_project('{"a": 0.0}', '{"result": { "$divide": [2, "$a"]}}'); -- Number or args should be 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": {}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 2, 3, 4, 5, 6]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [{"$divide": [1, 0]}]}}'); -- Only numbers should be allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [1, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": ["str", 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [true, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$divide": [2, false]}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$divide": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$divide": ["$a", 5]}}'); -- $mod operator : basic SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [3, 2]}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", 4]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": 10, "c": 10}}', '{"result": { "$mod": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"b": -100, "c": -100}}', '{"result": { "$mod": [ "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "10.2"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberDouble": "0.99999999999999999"}}', '{"result": { "$mod": [ "$a", {"$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "10"}}', '{"result": { "$mod": [ "$a", 5]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "500000000000"}}', '{"result": { "$mod": [ "$a", {"$numberDouble": "450000000000.0"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "500000000000"}}', '{"result": { "$mod": [ "$a", {"$numberLong": "450000000000"}]}}'); SELECT * FROM bson_dollar_project('{"a":{"$numberLong": "5"}}', '{"result": { "$mod": [ "$a", {"$numberDouble": "3"}]}}'); SELECT * FROM bson_dollar_project('{"a":5}', '{"result": { "$mod": [ "$a", {"$numberDouble": "3"}]}}'); -- $mod operator : Nan and Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [{ "$numberDouble" : "NaN" }, 2]}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "NaN" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "Infinity" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "NaN" }, { "$numberDouble" : "NaN" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "Infinity" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Nan" }, { "$numberDouble" : "Infinity" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "NaN" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDouble" : "Infinity" }, { "$numberDouble" : "Infinity" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "Infinity" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "Nan" }] }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [null, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [null, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": ["str", null]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": ["$a", "$a.b"]}}'); SELECT * FROM bson_dollar_project('{"a":null, "b": 2}', '{"result": { "$mod": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1, "b": 2}', '{"result": { "$mod": [ "$a", null ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$mod": [ "$a", "$b" ]}}'); SELECT * FROM bson_dollar_project('{"a":1 }', '{"result": { "$mod": [ "$a", "$a.b" ]}}'); -- $mod operator : can't mod by zero SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": ["$a", { "$numberDouble" : "0" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, { "$numberDecimal" : "0" }] }}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$mod": [{ "$numberDecimal" : "Infinity" }, 0] }}'); -- $mod operator : Only numerics allowed SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [1, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": ["str", 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [true, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mod": [2, false]}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$mod": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$mod": ["$a", 5]}}'); -- $mod operator : Return types based on operands types -- Any operand Decimal => Result is Decimal -- Any operand Long and the result has no fraction => Result is Long -- Everything else => Result is Double SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberLong": "-1"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberDouble": "1.032"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, 21]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberLong": "10"}, {"$numberDecimal": "1.032"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, {"$numberDecimal": "1.032"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, {"$numberDouble": "1.032"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDecimal": "10"}, 21]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberDouble": "1.032"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberDouble": "7"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, 7]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10"}, {"$numberLong": "-1"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ {"$numberDouble": "10.78"}, {"$numberLong": "-1"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$mod": [ 89, 7]}}'); -- $abs: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDouble": "-232232.23"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-2323232"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-9223372036854775807"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": -2147483648}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDecimal": "-9223372036854775808"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{"a": -2}', '{"result": { "$abs": {"$add": [-2, "$a"]}}}'); -- $abs: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$abs": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": null}}'); -- $abs: can't calculate abs of MIN_INT64 SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": {"$numberLong": "-9223372036854775808"}}}'); -- $abs: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [{}]}}'); -- $abs: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$abs": [1, 2, 3, 4]}}'); -- $ceil: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberLong": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberLong": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "-23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "-23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "0.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": {"$log": [10, 2]}}}'); -- $ceil: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$ceil": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": null}}'); -- $ceil: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [{}]}}'); -- $ceil: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ceil": [1, 2, 3, 4]}}'); -- $exp: returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": 10}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberLong": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": {"$numberDecimal": "NaN"}}}'); -- $exp: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": null}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$exp": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": "$a"}}'); -- $exp: input should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": "str"}}'); SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$exp": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": [[]]}}'); -- $exp: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": ["str", 1]}}'); SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$exp": ["$a", 2 ,2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$exp": []}}'); -- $floor: returns expected value SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberLong": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberLong": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "-23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "-23064.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "0.000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": {"$log": [10, 2]}}}'); -- $floor: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$floor": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": null}}'); -- $floor: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [{}]}}'); -- $floor: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$floor": [1, 2, 3, 4]}}'); -- $ln: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "2.718281828459045"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "2.718281828459045235360287471352662"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "0.0001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "0.1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberLong": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{"$a": 1}', '{"result": { "$ln": "$a"}}'); -- $ln: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": "$a"}}'); SELECT * FROM bson_dollar_project('{"$a": null}', '{"result": { "$ln": "$a"}}'); -- $ln: supports only numerics SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [{}]}}'); -- $ln: should be positive number greater than 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDouble": "-2"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberDecimal": "0"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": {"$numberLong": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": -100}}'); -- $ln: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ln": [1, 2, 3, 4]}}'); -- $log: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [10, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "0.1"}, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "10"}, {"$numberDouble": "10"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "10"}, {"$numberDouble": "5"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, {"$numberDouble": "5"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberLong": "10"}, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberLong": "9223372036854775807"}, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "NaN"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "10"}, {"$numberDecimal": "NaN"}]}}'); -- $log: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [10, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": ["$a", 10]}}'); SELECT * FROM bson_dollar_project('{"$a": null}', '{"result": { "$log": ["$a", 2]}}'); -- $log: number must be positive number greater than 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [-1, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [0, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDecimal": "0"}, 10]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [{"$numberDouble": "-3"}, 10]}}'); -- $log: base must be positive number greater than 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDecimal": "1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDecimal": "0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, { "$numberDouble": "0"}]}}'); -- $log: arguments must be numbers SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [[], 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [2, "str"]}}'); -- $log: takes exactly 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": {}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log": [1]}}'); -- $log10: expected results SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": 10}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "10"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "10"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "10"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "10000"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "10000"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "0.0000000001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "0.001"}}}'); -- $log10: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$log10": "$a"}}'); -- $log10: argument must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [[]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [{}]}}'); -- $log10: argument must be positive number SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberLong": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "-1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDecimal": "0.000000000000"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": {"$numberDouble": "0.0000000"}}}'); -- $log10: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$log10": []}}'); -- $pow: returns expected SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDouble": "2"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberDouble": "31"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "10"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "62"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "10"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDecimal": "10"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [5, { "$numberDecimal": "-112"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1, { "$numberDecimal": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1, { "$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDecimal": "NaN"}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberDouble": "NaN"}, 2]}}'); -- should lose precision only when a double is returned SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, 35]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, {"$numberDecimal": "35"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [3, {"$numberDouble": "35"}]}}'); -- $pow: should coerce when there is overflow -- int32 -> int64 SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 31]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 62]}}'); -- int32 -> double SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 63]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, 66]}}'); -- int64 -> double SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "2" }, 63]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "2" }, 64]}}'); -- $pow: should return double for negative exponent with bases not [-1, 0, 1]. SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, { "$numberLong": "-2" }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-2, { "$numberLong": "-2" }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [-4, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "-1" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [{ "$numberLong": "1" }, -2]}}'); -- $pow: null/undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [null, 31]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, "$a"]}}'); -- $pow: arguments must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [[], 31]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, "a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [2, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [false, true]}}'); -- $pow: exponent can't be negative if base is 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -31]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -0.00000001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, {"$numberDecimal": "-0.00000001"}]}}'); -- $pow: takes exactly 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0, -31, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$pow": [1,2,3,4,5,6]}}'); -- $sqrt: returns expected SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": 4}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberLong": "4"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberLong": "9223372036854775807"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDouble": "4"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDecimal": "4"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {"$numberDecimal": "NaN"}}}'); -- $sqrt: null/undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$sqrt": "$a"}}'); -- $sqrt: arg must be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [[]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": {}}}'); -- $sqrt: arg must be greater than or equal to 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDouble": "-1000000"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDouble": "-0.00001"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": { "$numberDecimal": "-0.000000000000001"}}}'); -- $sqrt: takes exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [1, 2, 3, 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sqrt": [1, 2]}}'); -- $round: defaults to 0 if 1 arg is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDouble": "1.3" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.3" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDouble": "1.51" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.51" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.49" }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.49" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberDecimal": "1.68" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.68" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": 10023 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": { "$numberLong": "10023" }}}'); -- $round: double, long or int SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 50]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "1.32" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "132" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "132" }, 20]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [132, 20]}}'); -- $round: positive precision, limit to 35 digits for number decimal SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.397" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.397" }, 50]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.397" }, 35]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 35]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "132423423.397" }, 15]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "-123.397" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "1.298912343250054252245154325" }, {"$numberDecimal": "20.000000"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "0.0" }, {"$numberDecimal": "100.00000"}]}}'); -- $round: negative precision SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "123.391" }, -4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "123.391" }, -4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "1234532345" }, -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberLong": "1234532345" }, -20]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [123402345, -8]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [123402345, -19]}}'); -- $round: NaN, Infinity/-Infinity, Null/Undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "NaN" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "NaN" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDouble": "Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{ "$numberDecimal": "-Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [null, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [1232, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": ["$a", 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [343, "$a"]}}'); -- $round: overflow SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{"$numberLong": "9223372036854775806"}, -1]}}'); -- $round: num args should be either 1 or 2. SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1, 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [2147483647, -1, 4, 5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": []}}'); -- $round: args should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [{}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [1, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [true, 1]}}'); -- $round: precision must be >= -20 and <= 100 SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, -21]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, 101]}}'); -- $round: precision must be integral value in int64 range SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDecimal": "-21.1"} ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDouble": "-21.1"} ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$round": [214, {"$numberDecimal": "9223372036854775808"} ]}}'); -- $trunc: defaults to 0 if 1 arg is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDouble": "1.3" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.3" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDouble": "1.51" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.51" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.49" }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.49" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberDecimal": "1.68" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.68" }, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": 10023 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": { "$numberLong": "10023" }}}'); -- $trunc: double, long or int SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 50]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "1.32" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "132" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "132" }, 20]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [132, 20]}}'); -- $trunc: positive precision, limit to 35 digits for number decimal SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.397" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.397" }, 50]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.397" }, 35]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 35]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 100]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "132423423.397" }, 15]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "-123.397" }, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "1.298912343250054252245154325" }, {"$numberDecimal": "20.000000"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "0.0" }, {"$numberDecimal": "100.00000"}]}}'); -- $trunc: negative precision SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "123.391" }, -4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "123.391" }, -4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "1234532345" }, -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberLong": "1234532345" }, -20]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [123402345, -8]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [123402345, -19]}}'); -- $trunc: NaN, Infinity/-Infinity, Null/Undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "NaN" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "NaN" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDouble": "Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{ "$numberDecimal": "-Infinity" }, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [null, -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [1232, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": ["$a", 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [343, "$a"]}}'); -- $trunc: num args should be either 1 or 2. SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [2147483647, -1, 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [2147483647, -1, 4, 5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": []}}'); -- $trunc: args should be numeric SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [{}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [1, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [true, 1]}}'); -- $trunc: precision must be >= -20 and <= 100 SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, -21]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, 101]}}'); -- $trunc: precision must be integral value in int64 range SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDecimal": "-21.1"} ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDouble": "-21.1"} ]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$trunc": [214, {"$numberDecimal": "9223372036854775808"} ]}}'); -- Test which verifies the infinity and NaN behavior SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "inf"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "-inf"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "nan"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$toInt": {"$numberDecimal": "1e310"}}}'); -- This would have failed while converting to double earlier bson_aggregation_array_operators_tests.sql000066400000000000000000002532301507310017400375450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6900000; SET documentdb.next_collection_id TO 6900; SET documentdb.next_collection_index_id TO 6900; -- $in operator -- returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, [1, 2]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": ["$a", [1, { }]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": ["$a", [1, { "a": true}]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a", [1, { "b": true}]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", [1, true]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", [null, false]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": { "$in": ["$a.b", [1, [1, 2], 2]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": { "$in": ["$a.b", [1, [1, 3], 2]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": true}}', '{"result": { "$in": ["$a.b", []]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "NaN"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "0.0"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$numberDouble": "NaN"}, [1, {"$numberDouble": "Infinity"}]]}}'); -- null should match mising paths and null SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [null, ["$a", 2]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [null, [1, 2, 3, null]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": [null, [1, 2, 3, "$a.b"]]}}'); -- undefined expression as first shouldn't match null/undefined in array SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": ["$z", [1, 2, 3, "$a.b"]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": null}}', '{"result": { "$in": ["$z", [null]]}}'); -- nested expressions in array should be evaluated SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, [1, 2, {"$add": [1, 1, 1]}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, [1, 2, {"$add": [1, 1, 3]}]]}}'); SELECT * FROM bson_dollar_project('{"a": true, "b": [1, 2]}', '{"result": { "$in": ["$a", [1, 2, {"$isArray": "$b"}]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$in": [{"$literal": "$a"}, [1, 2, {"$literal": "$a"}]]}}'); -- second argument must be an array SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, "$b"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, {"$undefined": true}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, { }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3, "str"]}}'); SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$in": [3, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": 2}', '{"result": { "$in": [3, "$a"]}}'); -- number of arguments should be 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": 2}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, 2, 3, 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [1, 2, 3, 4, 6, 7, 8]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$in": [{"$not": []}, 2, 3]}}'); -- $size operator -- returns expected result SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[1, 2]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[1, [1,2]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": {"$literal": [1]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$size": ["$a"]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$size": "$a"}}'); -- should error if no array is passed in SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": "$b"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{ }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [true]}}'); -- should error if wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [null, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{"$divide": [1, 0]}, 2]}}'); -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [{"$divide": [1, 0]}]}}'); -- nested mongo evaluates expressions in array eventhough they are not needed for $size calculation -- for error validation. SELECT * FROM bson_dollar_project('{}', '{"result": { "$size": [[{"$divide": [1, 0]}, 2]]}}'); -- $arrayElemAt -- returns expected element positive idx SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberLong": "1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "1.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "1.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 3]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", 1]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", 0]}, {"$arrayElemAt": ["$a", 1]}]}], 0]}}'); -- returns expected element negative idx SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -4]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", -4]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", -4]}, {"$arrayElemAt": ["$a", -3]}]}], -1]}}'); -- returns no result idx out of bounds SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], -2]}, "otherResult": {"$add": [1,2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -20]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -30]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], -40]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", -60]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", -4]}, {"$arrayElemAt": ["$a", -3]}]}], -70]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1], 1]}, "otherResult": {"$add": [1,2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 4]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 6]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], 7]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$arrayElemAt": ["$a", 8]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 100, 3, 4]}', '{"result": { "$arrayElemAt": [[{"$add": [{"$arrayElemAt": ["$a", 0]}, {"$arrayElemAt": ["$a", 1]}]}], 9]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "2147483647.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "-2147483648.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "2147483647.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDecimal": "-2147483648.0"}]}}'); -- should return null if array is null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [null, -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": ["$a", -5]}}'); -- should error if first arg is not array SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [{}, -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": ["string", -5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [true, -5]}}'); -- should error if second arg is not a number SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], [1, 2]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], "string"]}}'); -- should return null if second arg is null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], "$a"]}}'); -- should error if second arg is not representable as a 32-bit integer SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberLong": "2147483648"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberLong": "-2147483649"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDouble": "1.1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDouble": "1.0003"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "2147483648.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, 2, 3, {"a": 5}], {"$numberDouble": "-2147483649.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "2147483648.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "-2147483649.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7], {"$numberDecimal": "1.0003"}]}}'); -- should honor nested expression errors even second arg is not a 32-bit integer or if the value is found (even if the index points to an expression that doesn't produce an error). SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[{"$divide": [1, 0]}], {"$numberDecimal": "1.0003"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[1, {"$divide": [1, 0]}], 0]}}'); -- should error if wrong number of args is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [7]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayElemAt": [[7, {"$divide": [1, 0]}], {"$numberLong": "2147483648"}, 2]}}'); -- $first operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[{"$add": [2, 4, 6]}, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{"a": [100, 2, 3, 4]}', '{"result": { "$first": "$a"}}'); -- null or undefined array should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": ["$a"]}}'); -- should error if no array is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [{}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": ["string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [1]}}'); -- should error with wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[], 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [{"$divide": [1, 0]}, 2]}}'); -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$first": [[1, 2, 3, 4, {"$divide": [1, 0]}]]}}'); -- $last operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[1]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[1, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[2, 3, 4, {"$add": [2, 4, 6]}]]}}'); SELECT * FROM bson_dollar_project('{"a": [100, 2, 3, 4]}', '{"result": { "$last": "$a"}}'); -- null or undefined array should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": ["$a"]}}'); -- should error if no array is provided SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [{}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": ["string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [1]}}'); -- should error with wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[], 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [{"$divide": [1, 0]}, 2]}}'); -- should honor nested expression errors SELECT * FROM bson_dollar_project('{}', '{"result": { "$last": [[{"$divide": [1, 0]}, 1, 2, 3, 4]]}}'); -- $objectToArray: returns expected array SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": "$b" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [{ "a": 1 }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": 2 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": [1, {"b": 2}] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": {"b": { "c": {"d": "hello"}}}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": {"$add": [1, 1]}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": { "a": 1, "b": {"c": { "d": { "$add": [1, 1]}}}}}}'); SELECT * FROM bson_dollar_project('{"a": {"b": {"c": 2}}}', '{"result": { "$objectToArray": { "a": "$a", "b": "$a.b", "c": "$a.b.c" }}}'); SELECT * FROM bson_dollar_project('{"a": {"b": {"c": 2}}}', '{"result": { "$objectToArray": "$a"}}'); -- $objectToArray: null or undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$objectToArray": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$objectToArray": {"$arrayElemAt": [[1], 5]}}}'); -- $objectToArray: expects document as input SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": "string"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": false}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": {"$add": [1, 2]}}}'); -- $objectToArray: accepts exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$objectToArray": [{}, {}]}}'); -- $arrayToObject: returns expected object SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", 1], ["b", {"$add": [1, 1]}]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a.b.c", true]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a.b.c", [1, 2, 3]]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": { "$literal": [[ "key", "value"], [ "qty", 25 ]]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": 1}, {"k": "b", "v": {"$add": [1, 1]}}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a.b.c", "v": true}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a.b.c", "v": [1, 2, 3]}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": { "$literal": [{ "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 }]}}}'); -- $arrayToObject: deduplicates if multiple keys are the same SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["a", "value2"], ["a", "final value"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "value2"], ["a", "final value"], ["b", true], ["c", 1], ["c", 2]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}, {"k": "b", "v": "value2"}, {"k": "c", "v": "value3"}, {"k": "c", "v": "final"}, {"k": "b", "v": "final"}, {"k": "a", "v": "final"}]]}}'); -- $arrayToObject: null or undefined returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": ["$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$objectToArray": [null]}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$objectToArray": {"$arrayElemAt": [[1], -2]}}]}}'); -- $objectToArray -> $arrayToObject roundtrips SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayToObject": { "$objectToArray": { "a": 1 }}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayToObject": { "$objectToArray": { "a": 1, "b": {"$add": [1, 1]}}}}}'); -- $arrayToObject: accepts exactly 1 arg SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1, 2]}}'); -- $arrayToObject: input must be array SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [{"$add": [1, 1]}]}}'); -- $arrayToObject: requires consistent input all objects or all arrays SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], {"k": "b", "v": 1}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "b", "v": 1}, ["a", "value"]]]}}'); -- $arrayToObject: key must be string SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[[1, "value"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "foo"], [2, 2]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": 1, "v": "value"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "value"}, {"k": "b", "v": "value"}, {"k": 1, "v": "value"}]]}}'); -- $arrayToObject: array input format must be of length 2 SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["value"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["a", "value"], ["b", "v"], [1, 2, 3]]]}}'); -- $arrayToObject: document input format must have 2 fields SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"k": "a"}]]}}'); -- $arrayToObject: document input must have a 'k' and a 'v' field SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "foo": "value"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"v": "a", "blah": "k"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "a", "v": "b"}, {"v": "a", "k": "k"}, {"blah": 1, "foo": 2}]]}}'); -- $arrayToObject: key must not contain embedded null byte SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "fo\u0000os", "v": "value"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[{"k": "fo\u0000", "v": "value"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["\u0000", "value"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$arrayToObject": [[["\u0000hello", "value"]]]}}'); --$slice Operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$slice": [[1,2,3],1,1]}}'); SELECT * FROM bson_dollar_project('{"a": [1,2,3]}', '{"result": { "$slice": ["$a",1,1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$slice": [[1,2,{"$add":[1,2,3]}],{"$add":[0,1]},1]}}'); SELECT * FROM bson_dollar_project('{"a": [1,2,3]}', '{"result": { "$slice": ["$b",1,1]}}'); --$slice with positive array field input select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10,10]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",2,10]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",10]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$b",10]} }'); --$slice with Negative array field input or Zero select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],-1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],-2]} }'); select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : ["$a",-1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],1,0]} }'); select bson_dollar_project('{"_id":"1", "a" : 1 }', '{"slicedArray" : { "$slice" : [[1,2,3,4,5],2,-1]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$b",-1,2]} }'); --$slice with other expression select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[{"$add": [1,2,3]},2,3,4,5],1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[{"$add": [1,2,3]},2,3,4,5],{"$multiply":[1,2]},3]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : ["$a",-2,2]} }'); --$slice with inclusion or exclusion spec select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":1, "d":1}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":0}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : ["$a",1,2]} , "b":0, "d":1}'); --$slice has NULL input select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [null,1,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[1,2,3],null,2]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"a" : { "$slice" : [[1,2,3],1,null]} }'); --Invalid Input Negative cases $slice projection select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : "str"}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["hello",1,2]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a","str",2]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,"str"]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,1.02]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,-1]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,0]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a"]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",1,2,4]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "NaN"},{ "$numberDecimal" : "NaN"}]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "NaN"},{ "$numberDecimal" : "Infinity"}]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "Infinity"},{ "$numberDecimal" : "NaN"}]}}'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : ["$a",{ "$numberDecimal" : "Infinity"},{ "$numberDecimal" : "Infinity"}]}}'); -- $concatArrays operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": []}}'); SELECT * FROM bson_dollar_project('{"array": []}', '{"result": { "$concatArrays": [[], "$array"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2", ["nested", "array"]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "2", ["nested", "array", ["more", "nested", "array"]]]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [[{"$add": [1, 1]}, [{"$add": [1,2]}]]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2"], "c": ["3", "4"]}}', '{"result": { "$concatArrays": ["$a.b", "$a.c"]}}'); -- $concatArrays the indexes are preserved and we can query the result via array index keys. WITH r1 AS (SELECT bson_dollar_project('{"doc": {"foo": "value"}, "array": ["first", "second"]}', '{"result": {"$concatArrays": [["$doc"], "$array"]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.2": "second"}'; WITH r1 AS (SELECT bson_dollar_project('{"doc": {"foo": "value"}, "array": ["first", "second"]}', '{"result": {"$concatArrays": [["$doc"], "$array"]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.0": {"foo": "value"}}'; WITH r1 AS (SELECT bson_dollar_project('{}', '{"result": {"$concatArrays": [["0", "1"], ["2", "3", "4", "5"]]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.0": "0"}'; WITH r1 AS (SELECT bson_dollar_project('{}', '{"result": {"$concatArrays": [["0", "1"], ["2", "3", "4", "5"]]}}') as result) SELECT * FROM r1 WHERE result @= '{"result.4": "4"}'; -- $concatArrays null/undefined argument should result in null. Nested nulls, should just be nulls in the final array SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": ["$undef"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": "$undef"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], null, ["3", "4"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4"], null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", null]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], ["3", "4", "$undef"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [["1","2"], "$undef", ["3", "4", "$undef"]]}}'); SELECT * FROM bson_dollar_project('{"doc": {"foo": "string"}, "array": ["first", "second", null]}', '{"result": { "$concatArrays": [["$doc"], "$array"]}}'); -- $concatArrays error when arguments are not an array SELECT * FROM bson_dollar_project('{"a": {"b": "1"}}', '{"result": { "$concatArrays": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "1"}}', '{"result": { "$concatArrays": ["$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [[1], {"a": "1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$concatArrays": ["string"]}}'); -- $filter simple cond SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": false}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": null}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": 1}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": 0}} }'); -- $filter use cond with expression and reference variable for each element SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", 3]}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); SELECT * FROM bson_dollar_project('{"a": {"$undefined": true}}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$filter": {"input": "$a", "cond": {"$lt": ["$$this", 4]}}} }'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$filter": {"input": "$undefinedPath", "cond": {"$lt": ["$$this", 4]}}} }'); SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this", null]}}} }'); SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$dummy", null]}, "as": "dummy"}}}'); -- $filter reference variable with dotted expression SELECT * FROM bson_dollar_project('{"a": [{"first": "foo", "second": "bar"}, {"first": "baz", "second": null}]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this.second", null]}}} }'); SELECT * FROM bson_dollar_project('{"a": [{"first": "foo", "second": "bar"}, {"first": "baz", "second": null}]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$dummy.second", null]}, "as": "dummy"}}}'); -- $filter with limit SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": 1}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberLong": "1"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDecimal": "5.00000"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "1.0"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": null}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": "$undefinedPath"}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": 5}} }'); SELECT * FROM bson_dollar_project('{"a": ["foo", "baz", null, "var", null, null, "blah"]}', '{"result": {"$filter": {"input": "$a", "cond": {"$ne": ["$$this", null]}, "limit": 4}} }'); -- $filter with nested filter and clashing variable names SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "cond": {"$filter": {"input": "$$this", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$this"]}, 3]}}}}}}'); SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "cond": {"$filter": {"input": "$$this", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$number"]}, 3]}, "as": "number"}}}}}'); SELECT * FROM bson_dollar_project('{"a": [[-100, 10, 20, 30, 40, 8000]]}', '{"result": {"$filter": {"input": "$a", "limit": 2, "as": "number", "cond": {"$filter": {"input": "$$number", "limit": 3, "cond": {"$gt": [{"$add": [0, "$$number"]}, 3]}, "as": "number"}}}}}'); -- $filter with $and/$or shouldn't fail when if condition is met before error in nested expression SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": {"$or": [{"$lt": ["$$this", 0]}, {"$ln": "$$this"}]}}}}'); SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": {"$and": [{"$gt": ["$$this", 0]}, {"$ln": "$$this"}]}}}}'); -- $filter, arg must be an object SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": "$a"}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": true}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": {"$filter": []}}'); -- $filter, object should have cond and input, as/limit are optional, any other path is invalid SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a"}}}'); SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"cond": true}}}'); SELECT * FROM bson_dollar_project('{"a": [-1,-2,-3,-4]}', '{"result": {"$filter": {"input": "$a", "cond": true, "sort": false}}}'); -- $filter, input should be an array SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": "$a", "cond": true}}}'); SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": "a", "cond": true}}}'); SELECT * FROM bson_dollar_project('{"a": { }}', '{"result": {"$filter": {"input": true, "cond": true}}}'); -- $filter, as variable name should be valid -- invalid SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "_element"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "1element"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "Element"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el@ement"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el-ement"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": ""}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": null}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": true}}}'); -- valid SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "element1"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "el_ement1"}}}'); SELECT * FROM bson_dollar_project('{"a": []}', '{"result": {"$filter": {"input": "$a", "cond": true, "as": "eLEMEnt"}}}'); -- $filter, limit must be representable as a 32bit integer and > 0 SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "1.1"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDecimal": "1.1"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberLong": "2147483648"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "2147483648.0"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "0.0"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": {"$numberDouble": "-1.0"}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2]}', '{"result": {"$filter": {"input": "$a", "cond": true, "limit": -100}} }'); -- $filter, undefined variable SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "as":"element", "cond": {"$gt": ["$$this", 3]}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$element", 3]}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", "$$filterValue"]}}} }'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4, 5, 6]}', '{"result": {"$filter": {"input": "$a", "cond": {"$gt": ["$$this", "$$filterValue.name.last"]}}} }'); -- $firstN, operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":1} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":11} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":100} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [], "n":100} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":3.000000} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":{"$numberDecimal": "2.000000"}} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775807"} } }}'); -- $firstN, operator with docs in db select documentdb_api.insert_one('db','dollarfirstN','{"a":[1,2,3] , "_id":1}'); select documentdb_api.insert_one('db','dollarfirstN','{"a":[42,67] , "_id":2}'); select documentdb_api.insert_one('db','dollarfirstN','{"a":[] , "_id":3}'); select documentdb_api.insert_one('db','dollarfirstN','{"a":[1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"] , "_id":4}'); select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarfirstN'); -- $firstN , operator with docs in db and invalid path select documentdb_api.insert_one('db','dollarFirstN','{"b":[] , "_id":5}'); select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarFirstN'); select bson_dollar_project(document, '{"result": { "$firstN": {"input": "$a", "n":"abc"} }}') from documentdb_api.collection('db','dollarFirstN'); --$firstN, operator invalid input SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": true, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": 5, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": "abcvde", "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": 4.56, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": true }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": "ayush_test_name" }}'); --$firstN, operator invalid n SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":"3"} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":0} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":-1} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n":3.124} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775808"} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4], "n": {"$numberDecimal": "0"} } }}'); -- $lastN, operator with docs in db select documentdb_api.insert_one('db','dollarLastN','{"a":[1,2,3] , "_id":1}'); select documentdb_api.insert_one('db','dollarLastN','{"a":[42,67] , "_id":2}'); select documentdb_api.insert_one('db','dollarLastN','{"a":[] , "_id":3}'); select documentdb_api.insert_one('db','dollarLastN','{"a":[1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"] , "_id":4}'); select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarLastN'); -- $lastN , operator with docs in db and invalid path select documentdb_api.insert_one('db','dollarLastN','{"b":[] , "_id":5}'); select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":3} }}') from documentdb_api.collection('db','dollarLastN'); select bson_dollar_project(document, '{"result": { "$lastN": {"input": "$a", "n":"abc"} }}') from documentdb_api.collection('db','dollarLastN'); --$firstN, operator missing or extra args SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"input": [1,2,3,4]} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"n": 5} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$firstN": {"n": 5, "input": [1,2,3], "abc":1} }}'); -- $lastN, operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":1} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":11} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,45,12,null,"asdhkas",12890.8912,{"$numberDecimal": "223.234823904823904823041212233"},{"$date": { "$numberLong" : "0" }},"\ud0008"], "n":100} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [], "n":100} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":3.000000} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":{"$numberDecimal": "2.000000"}} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775807"} } }}'); --$lastN, operator invalid input SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": true, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": 5, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": "abcvde", "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": 4.56, "n":3} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": true }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": "ayush_test_name" }}'); --$lastN, operator invalid n SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":"3"} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":0} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":-1} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n":3.124} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "9223372036854775808"} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4], "n": {"$numberDecimal": "0"} } }}'); --$lastN, operator missing or extra args SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"input": [1,2,3,4]} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"n": 5} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lastN": {"n": 5, "input": [1,2,3], "abc":1} }}'); -- $range, simple condition asc SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,100,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberLong": "50"},100,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberLong": "150"},{"$numberDecimal":"20.0000"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberDecimal": "150"},{"$numberDouble":"20.00000000"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50,{"$numberDecimal": "50"},{"$numberDouble":"20.00000000"}] } }'); -- $range, simple condition desc SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,-10,-1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,-3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [100,1,-3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberLong": "100"},-50,-3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberLong": "50"},{"$numberDecimal":"-20.0000"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberDecimal": "50"},{"$numberDouble":"-20.00000000"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [150,{"$numberDecimal": "150"},{"$numberDouble":"-20.00000000"}] } }'); -- $range, asc series but skip val negative SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,-1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,10,{"$numberDecimal":"-1.0000"}] } }'); -- $range, desc series but skip val positive SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [10,1,{"$numberDecimal":"1.0000"}] } }'); -- $range, expects only ranges in int_32 hence, if numbers overflow during range we should stop SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,2147483647,1073741824] } }'); -- $range, testing with values from document SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 42}', '{"result": {"$range": ["$distance",200,40] } }'); SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 88}', '{"result": {"$range": ["$distance",200,40] } }'); SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 288}', '{"result": {"$range": ["$distance",200,40] } }'); SELECT * FROM bson_dollar_project('{"city": "San Jose", "distance": 288}', '{"result": {"$range": [10,"$distance",5] } }'); -- $range, negative conditions starting number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [2147483648,214748364121,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [{"$numberDecimal":"0.35"},400,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": ["abvcf",400,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [true,400,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [null,400,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [null,400,40,400] } }'); -- $range, negative conditions ending number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [2147648,214748364121,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [-10, {"$numberDecimal":"0.35"},4] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [400,"abvcf",400] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [5,true,40] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,null] } }'); -- $range, negative conditions step number SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [21,21471,2147483648] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [-10,15, {"$numberDecimal":"0.35"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,400,"abvcf"] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [5,40,true] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,5,null] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [1,5,0] } }'); -- $range, tests large numbers SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [200,20000] }} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [200,20000] },0]} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [200,20000] },19799]} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [50000,65535960,100000] }} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [50000,65535960,100000] },0]} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [50000,65535960,100000] },654]} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$size":{"$range": [2000000,1073741924,1000000] }} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [2000000,1073741924,1000000] },0]} }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$arrayElemAt":[{"$range": [2000000,1073741924,1000000] },1071]} }'); -- $range, tests memory limit exceed SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [200,65535960] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [50000,65535960] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [0,1073741924] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$range": [0,6505360] } }'); -- $reverseArray, simple case SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4,5,6] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4,5,6,{"$numberLong":"1"}, {"$numberDecimal":"12389.2134234"}] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}, "$field"] } } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$literal": [1,2,3,4, {"$add":[1,2]}, "$field", [1.45,9,9]] } } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": "$nums" } }'); SELECT * FROM bson_dollar_project('{"key":[{"a":[8,9,10]},{"a":[3,2,1,-1]},{"a":[4,5,6]}]}', '{"result": {"$reverseArray": "$key.a" } }'); -- $reverseArray, operator cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$range":[1,4]} } }'); -- $reverseArray, null cases SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": "$noField" } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": null } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$reverseArray": {"$undefined":true} } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": {"$literal":null} } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": {"$literal":{"$undefined":true}} } }'); -- $reverseArray, negative cases SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": [1,2,345,5] } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": true } }'); SELECT * FROM bson_dollar_project('{"nums": [1,2,3,4, {"$add":[1,2]}, "$field", [145,9,9]]}', '{"result": {"$reverseArray": 1 } }'); -- $indexOfArray, simple cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[], 1,1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [null, 1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 2] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 4] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5], 5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 0, 111] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 111, 111] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 2, 5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 2, 7] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50, 7, 7] } }'); -- $indexOfArray, document based array SELECT * FROM bson_dollar_project('{"a": [1,2,345,5]}', '{"result": {"$indexOfArray": ["$a", 1] } }'); SELECT * FROM bson_dollar_project('{"a": [[1,2,345,5]]}', '{"result": {"$indexOfArray": ["$a", [1]] } }'); SELECT * FROM bson_dollar_project('{"a": [[1,2,345,5]]}', '{"result": {"$indexOfArray": ["$a", [1,2]] } }'); -- $indexOfArray, negative cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [true, 50.0, 1,50] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 11, 5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, -1, 5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1, -5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1.1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5.11] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5.11] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,5,4] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, "1",5] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,"50"] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,2,345,5,100,90,11,50,234], 50.0, 1,90000000000000] } }'); -- $indexOfArray, search for elements of different type SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], "2"] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], true] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"a":1}], {"a":1}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"$numberLong":"44374"}], {"$numberLong":"44374"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,{"$numberDecimal":"44374.124"}], {"$numberDecimal":"44374.124"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true,null], null] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true, {"$date": { "$numberLong" : "0" }}, null], {"$date": { "$numberLong" : "0" }}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1,"2",true, "This is â¤ï¸", null], "This is â¤ï¸"] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 44374, "2", true, {"$numberLong":"44374"}], {"$numberLong":"44374"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 44374, "2", true, {"$numberLong":"44374"}], {"$numberInt":"44374"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", true, {"$numberLong":"44374"}], {"$numberDecimal":"44374"}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", [true, {"$numberLong":"44374"}]], [true,{"$numberDecimal":"44374"}]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", [true, {"$numberLong":"44374"}, 1]], [1,true,{"$numberDecimal":"44374"}]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2}}], {"a":{"b":24, "d":2, "c":1 }}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2, "e": null}}], {"a":{"b":24,"c":1, "d":2, "e":null }}] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$indexOfArray": [[1, 4374, "2", {"a":{"b":24, "c":1,"d":2, "e": null}}], {"a":{"b":24,"c":1, "d":2, "e": {"$undefined":true} }}] } }'); -- $max, single input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": null } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$undefined":true} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"a":1} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": 5 } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$numberDouble":"5.454"} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$numberDecimal":"5.454"} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": {"$date": { "$numberLong" : "0" }} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [-2147483648, 2147483647, -9223372036854775808, 9223372036854775807, 0, 100, -100] } }'); -- $max, array input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,2,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [[1,2,3]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,2,3,5,3,2,1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,3,5,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,33, [1,2,3]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,200.0] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); -- $max, null cases within array SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [null, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{}, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{"$undefined": true}, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [null, NaN, 1, 2] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [{}, NaN, 1, 2] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$max": [1,{"$undefined":true},8,3,4,[1,2,3]] } }'); -- $max, input document cases SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": 130.5}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": NaN}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$max": ["$a", 223324342] } }'); SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$max": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$max": [1,2,45, "$a"] } }'); -- $min, single input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": null } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$undefined":true} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"a":1} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": 5 } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$numberDouble":"5.454"} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$numberDecimal":"5.454"} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": {"$date": { "$numberLong" : "0" }} } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [-2147483648, 2147483647, -9223372036854775808, 9223372036854775807, 0, 100, -100] } }'); -- $min, array input cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,2,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [[1,2,3]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,2,3,5,3,2,1] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,3,5,3] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,33, [1,2,3]] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,200.0] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); -- $min, null cases within array SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [null, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{}, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{"$undefined": true}, NaN] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [null, NaN, 1, 2] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [{}, NaN, 1, 2] } }'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$min": [1,{"$undefined":true},8,3,4,[1,2,3]] } }'); -- $min, input document cases SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": 130.5}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": NaN}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [1,2,3,5,3,2,1]}', '{"result": {"$min": ["$a", 223324342] } }'); SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$min": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [100,2,33, [1,2,3], {"$date": { "$numberLong" : "0" }}, {"$numberDecimal": "5.12124545487878787"},{}, NaN , {"$regex": "/ab/cdsd/abc", "$options" : ""}]}', '{"result": {"$min": [1,2,45, "$a"] } }'); -- $sum , single input SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$sum": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": "foo" }', '{"result": {"$sum": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": null }', '{"result": {"$sum": "$a" } }'); SELECT * FROM bson_dollar_project('{"b": null }', '{"result": {"$sum": "$a" } }'); -- $sum , array input SELECT * FROM bson_dollar_project('{"a": [ 7, 1, 2 ] }', '{"result": {"$sum": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [ "foo", 1, 2 ] }', '{"result": {"$sum": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [ 1, null, 2 ] }', '{"result": {"$sum": "$a" } }'); -- $sum , array expression SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$sum": [ "$a", "$b", "$c" ] } }'); SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$sum": [ "$a", { "$subtract": [ "$c", "$b" ] } ] } }'); -- $avg , single input SELECT * FROM bson_dollar_project('{"a": 5}', '{"result": {"$avg": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": "foo" }', '{"result": {"$avg": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": null }', '{"result": {"$avg": "$a" } }'); SELECT * FROM bson_dollar_project('{"b": null }', '{"result": {"$avg": "$a" } }'); -- $avg , array input SELECT * FROM bson_dollar_project('{"a": [ 7, 1, 2 ] }', '{"result": {"$avg": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [ "foo", 1, 2 ] }', '{"result": {"$avg": "$a" } }'); SELECT * FROM bson_dollar_project('{"a": [ 1, null, 2 ] }', '{"result": {"$avg": "$a" } }'); -- $avg , array expression SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$avg": [ "$a", "$b", "$c" ] } }'); SELECT * FROM bson_dollar_project('{"a": 1, "b": 2, "c": 3 }', '{"result": {"$avg": [ "$a", { "$subtract": [ "$c", "$b" ] } ] } }'); -- $map select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$map": {"input": "$a", "as": "x", "in": { "$add": ["$$x", 1] } } } }'); select *from bson_dollar_project('{"str": ["a", "b", "c"]}', '{"result": {"$map": {"input": "$str", "as": "y", "in": { "$concat": ["$$y", "ddd"] } } } }'); select *from bson_dollar_project('{"bools": [true, true, false, true] }', '{"allTrue": { "$map": { "input": "$bools", "as": "x", "in": { "$and": ["$$x", false] } } } }'); select *from bson_dollar_project('{ "a": ["Hello", "", "big", "World", "!"] }', '{"a": { "$map": { "input": "$a", "as": "x", "in": { "$concat": [{ "$trim": { "input" : "$$x" }}, {"$cond": {"if": { "$eq": [ "$$x", "" ] }, "then": "1", "else": "2" } }, { "$trim": { "input" : "$$x" } } ] } } } }'); select *from bson_dollar_project('{"a": [["a", "b"], ["b", "c"], ["c", "d"], ["e", "a"], ["y", "z"]] }', '{"result": {"$map": {"input": "$a","as": "x","in": { "$setUnion": ["$$x", ["a","b"]] }}}}'); select *from bson_dollar_project('{"a": [{"b": [1, 2, 3]},{"b": [4, 5, 6]}]}', '{"result": {"$map": {"input": "$a","as": "outer","in": {"$map": {"input": "$$outer.b","as": "inner","in": { "$multiply": ["$$inner", 2] }}}}}}'); -- $map in $addfield stage SELECT documentdb_api.insert_one('db','addFieldMap','{"_id":"1", "a": [{ "fieldA": "Hello World", "fieldB": "FOO" },{ "fieldA": "Goodbye everyone", "fieldB": "BAza" }]}', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "addFieldMap", "pipeline": [ { "$addFields": {"newField": { "$map": { "input": "$a", "as": "dummy", "in": {"fieldA_fieldB": { "$concat": ["$$dummy.fieldA", " -- ", "$$dummy.fieldB"] }} } } } } ], "cursor": {} }'); -- $map, nested case select *from bson_dollar_project('{"a":[{"fieldA":"abc","fieldB":2,"fieldC":[{"number":45, "foo":"ab"}, {"foo":"ac","number":1}]},{"fieldA":"def","fieldB":6,"fieldC":[{"foo":"kb", "number":10}]}]}', '{"result":{"$map":{"input":"$a","as":"dummy","in":{"fieldA":"$$dummy.fieldA","fieldB":"$$dummy.fieldB","fieldC":{"$map":{"input":"$$dummy.fieldC","as":"fieldC","in":{"foo":"$$fieldC.foo","number":{"$add":["$$fieldC.number",100]}}}}}}}}'); -- $map, negative cases select *from bson_dollar_project('{"a": 1}', '{"result": {"$map": {"input": "$a", "as": "x", "in": { "$add": ["$$x", 1] } } } }'); select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$map": {"input": "$a" }} }'); -- $reduce select *from bson_dollar_project('{"a": ["a", "b", "c"]}', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }'); select *from bson_dollar_project('{"a": [ 1, 2, 3, 4 ]}', '{"result": { "$reduce": { "input": "$a", "initialValue": { "sum": 5, "product": 2 }, "in": { "sum": { "$add" : ["$$value.sum", "$$this"] }, "product": { "$multiply": [ "$$value.product", "$$this" ] } } } } }'); select *from bson_dollar_project('{"a": [ [ 3, 4 ], [ 5, 6 ] ] }', '{"result": { "$reduce": { "input": "$a", "initialValue": [ 1, 2 ], "in": { "$concatArrays" : ["$$value", "$$this"] } } } }'); select *from bson_dollar_project('{"a": [[1, 2], [3, 4], [5, 6]] }', '{"result": { "$reduce": { "input": "$a", "initialValue": 0, "in": { "$add" : ["$$value", {"$reduce": {"input": "$$this","initialValue": 0, "in": { "$add": ["$$value", "$$this"] }}}] } } } }'); select *from bson_dollar_project('{ "a": ["Hello", "", "big", "World", "!"] }', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": [{ "$trim": { "input" : "$$value" }}, {"$cond": {"if": { "$eq": [ "$$value", "" ] }, "then": "1", "else": "2" } }, { "$trim": { "input" : "$$this" } } ] } } } }'); select *from bson_dollar_project('{"a": [2, 3, 5, 8, 13, 21,7,1]}','{"result": {"$reduce": { "input": "$a", "initialValue": 0, "in": { "$cond": [{ "$gt": ["$$this", 5] }, { "$add": ["$$value", 1] }, "$$value"] } } } }'); select *from bson_dollar_project('{"a": [true, true, false, true] }', '{"result": { "$reduce": { "input": "$bools", "initialValue": true, "in": { "$and": ["$$value", "$$this"] } } } }'); select *from bson_dollar_project('{"a": [1, null, 3, null, 5] }', '{"result": { "$reduce": { "input": "$a", "initialValue": 0, "in": { "$add": ["$$value", { "$ifNull": ["$$this", 0] }] } } } }'); select *from bson_dollar_project('{"a": [[1, 2], [2, 3], [3, 4]] }', '{"result": {"$reduce": {"input": "$a","initialValue": [],"in": { "$setUnion": ["$$value", "$$this"] }}}}'); select *from bson_dollar_project('{"a": [{ "a": 1 }, { "b": 2 }, { "a": 2 }, { "b": 3 },{ "c": 3 }, { "c": 4 }] }','{"result":{"$reduce": {"input": "$a","initialValue": {},"in":{ "$mergeObjects": ["$$value", "$$this"] }}}}'); select *from bson_dollar_project('{"a": [[1, 2], [3, 4], [5, 6]] }','{"result":{"$reduce": {"input": "$a","initialValue": 0,"in":{ "$sum": ["$$value",{ "$avg": "$$this" }] }}}}'); -- $reduce in $addfield stage SELECT documentdb_api.insert_one('db','addFieldReduce','{"_id":"1", "a": ["a", "b", "c"]}', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "addFieldReduce", "pipeline": [ { "$addFields": {"newField": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } } } ], "cursor": {} }'); -- $reduce, negative cases select *from bson_dollar_project('{"a": 1}', '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }'); select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$reduce": {"input": "$a", "initialValue": 0 }} }'); select *from bson_dollar_project('{"a": [1, 2, 3]}', '{"result": {"$reduce": {"input": "$a", "in": { "$concat": ["$$value", "$$this"] } }} }'); -- $maxN/minN, n too large SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 23 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 23 } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [1, 2, 3, 5, 7, 9], "n": {"$numberDecimal": "12345678901234567890" } } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [1, 2, 3, 5, 7, 9], "n": {"$numberDecimal": "12345678901234567890" } } }}'); -- $maxN/minN, n short SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 2 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 2 } }}'); -- $maxN/minN, n == 1 SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"], "n": 1 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"], "n": 1 } }}'); -- $maxN/minN, n missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": [1.1,2.2,"3"] } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": {"input": [1.1,2.2,"3"] } }}'); -- $maxN/minN, input missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": { "n": 1 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": { "n": 1 } }}'); -- $maxN/minN, n and input missing SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": { "x": 1 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$minN": { "x": 1 } }}'); -- $maxN/minN, use input from $d1 SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1]}', '{"result": { "$maxN": {"input": "$d1", "n": 23 } }}'); SELECT * FROM bson_dollar_project('{"d1": [1.1,2.1,3.1,4,5,6,7,8, 99,99,99,99,99]}', '{"result": { "$maxN": {"input": "$d1", "n": 2 } }}'); -- $maxN/minN, tests from official jstests SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [null, 2, null, 1], "n": 3 } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [null, 2, null, 1], "n": 3 } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$maxN": {"input": [1, 2, 3, 5, 7, 9], "n": 3 } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$minN": {"input": [1, 2, 3, 5, 7, 9], "n": 3 } }}'); --$maxN/minN, nested array SELECT * FROM bson_dollar_project('{"d1": [[1,2,3],[4,5,6],[7,8,9]]}', '{"result": { "$maxN": {"input": "$d1", "n": 3 } }}'); SELECT * FROM bson_dollar_project('{"d1": [[1,2,3],[4,5,6],[7,8,9]]}', '{"result": { "$minN": {"input": "$d1", "n": 3 } }}'); SELECT * FROM bson_dollar_project('{"d1": [[4,5,6],[7,8,9],1,2,3]}', '{"result": { "$maxN": {"input": "$d1", "n": 5 } }}'); SELECT * FROM bson_dollar_project('{"d1": [[7,8,9],[4,5,6],1,2,3]}', '{"result": { "$minN": {"input": "$d1", "n": 5 } }}'); --$maxN/minN, numberDecimal type array SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "-1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "2.23456789" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "-1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" },{"$numberDecimal": "1.23456789" }, { "$numberDecimal": "1.32456789" }, { "$numberDecimal": "1.34256789" }]}', '{"result": { "$minN": {"input": "$d1", "n": 4 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" }, 1, 3, -2, null, [3, {"numberDouble": "NaN"}], {"$numberDecimal": "Infinity" }]}', '{"result": { "$maxN": {"input": "$d1", "n": 7 } } }'); SELECT * FROM bson_dollar_project('{"d1": [{ "$numberDecimal": "NaN" }, 1, 3, -2, null, [3, {"numberDouble": "NaN"}], {"$numberDecimal": "Infinity" }]}', '{"result": { "$minN": {"input": "$d1", "n": 7 } } }'); -- $sortArray SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[9,7,4,6,8],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[9,7,4,6,8],"sortBy":-1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":["alpha","delta","charlie","bravo"],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":["alpha","delta","charlie","bravo"],"sortBy":-1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[17],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[13,2,{"a":"itemA"},4,25,3,"itemB",{"a":null},{"a":{"type":"x","flag":true}},{"$numberDecimal":"6.78"},{"a":"itemC"}],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[[1,9,2],[8,3,5],9,2,7,10,6],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result":{"$sortArray":{"input":[{"$numberDecimal":"NaN"},3,8,2,10,7,null," "],"sortBy":1}}}'); SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"a":1}}}}'); SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"a":-1}}}}'); SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"c.e":1}}}}'); SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"c.e":-1}}}}'); SELECT * FROM bson_dollar_project('{"group":[{"a":"item1","b":23,"c":{"d":"value1","e":"typeA"}},{"a":"item2","b":45,"c":{"d":"value2","e":"typeB"}},{"a":"item3","b":31,"c":{"d":"value3","e":"typeC"}}]}', '{"result":{"$sortArray":{"input":"$group","sortBy":{"b":-1,"a":1}}}}'); -- $sortArray, negative cases select *from bson_dollar_project('{}', '{"result": {"$sortArray": null } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": " " } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": "", "sortBy": 1 } } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"sortBy": 1 } } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4] } } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": "", "sortBy": 1} } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": {}, "sortBy": 1} } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortByy": 1} } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": 2} } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": ""} } }'); select *from bson_dollar_project('{}', '{"result": {"$sortArray": {"input": [1, 5, 3, 2, 4], "sortBy": {}} } }'); -- $zip select *from bson_dollar_project('{"a": [[1, 2, 3], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$a"} } }'); select *from bson_dollar_project('{"multitypes": [[1, true, {"value": 2}], ["a", [3, 2], "Great"]]}', '{"result": {"$zip": {"inputs": "$multitypes"} } }'); select *from bson_dollar_project('{"diffLen": [[ "a", "b" ], [ "b", "c", "d" ]]}', '{"result": {"$zip": {"inputs": "$diffLen"} } }'); select *from bson_dollar_project('{"useLongest": [[ 0, 1 ], [ 2, 3, 4, 5 ]]}', '{"result": {"$zip": {"inputs": "$useLongest", "useLongestLength": true} } }'); select *from bson_dollar_project('{"falseUseLongest": [[ 0 ], [ 2, 3 ]]}', '{"result": {"$zip": {"inputs": "$falseUseLongest", "useLongestLength": false} } }'); select *from bson_dollar_project('{"withDefaults": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$withDefaults", "useLongestLength": true, "defaults": [ "a", "b", "c" ]} } }'); select *from bson_dollar_project('{"emptyArray": [[], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$emptyArray"} } }'); select *from bson_dollar_project('{"emptyArrayUseLongest": [[], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$emptyArrayUseLongest", "useLongestLength": true} } }'); select *from bson_dollar_project('{"nullELemArray": [[null, null], [4, 5, 6]]}', '{"result": {"$zip": {"inputs": "$nullELemArray"} } }'); select *from bson_dollar_project('{"withDefaults": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$withDefaults", "useLongestLength": true, "defaults": "$withDefaults"} } }'); select *from bson_dollar_project('{"array1": [1, 2, 3], "array2": ["a", "b", "c"], "array3": ["x", "y", "z"] }', '{"result": {"$zip": {"inputs": [{ "$zip": { "inputs": ["$array1", "$array2"]}}, "$array3" ]} } }'); -- $zip, negative cases select *from bson_dollar_project('{"a": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$a", "defaults": [ "a", "b", "c" ]} } }'); select *from bson_dollar_project('{"a": [[ 0 ], [ 1, 2 ], [ 3 ]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": true, "defaults": [ "a", "b" ]} } }'); select *from bson_dollar_project('{"a": []}', '{"result": {"$zip": {"inputs": "$a"} } }'); select *from bson_dollar_project('{"a": null}', '{"result": {"$zip": {"inputs": "$a"} } }'); select *from bson_dollar_project('{"a": [1]}', '{"result": {"$zip": {"inputs": "$a"} } }'); select *from bson_dollar_project('{"a": [[1,2,3], "anString"]}', '{"result": {"$zip": {"inputs": "$a"} } }'); select *from bson_dollar_project('{"a": [[0], [1, 2]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": 0} } }'); select *from bson_dollar_project('{"a": [[0], [1, 2]]}', '{"result": {"$zip": {"inputs": "$a", "useLongestLength": true, "defaults": 0} } }'); bson_aggregation_bitwise_operators_tests.sql000066400000000000000000000142331507310017400400730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8900000; SET documentdb.next_collection_id TO 8900; SET documentdb.next_collection_index_id TO 8900; -- $bitAnd $bitOr $bitXor $bitNot select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,3] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,3] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [1] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2.1,3] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1.8,2,3] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3.7] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [1.4] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitAnd": [{"$numberDecimal": "1.18"},3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitOr": [{"$numberDecimal": "1.18"},3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitXor": [{"$numberDecimal": "1.18"},3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitNot": {"$numberDecimal": "1.18"} } }'); select *from bson_dollar_project('{}', '{"result": { "$bitAnd": [123456789012345678,3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitOr": [123456789012345678,3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitXor": [123456789012345678,3] } }'); select *from bson_dollar_project('{}', '{"result": { "$bitNot": 123456789012345678 } }'); select *from bson_dollar_project('{}', '{"result": { "$bitAnd": 1.3 } }'); select *from bson_dollar_project('{}', '{"result": { "$bitOr": 1.3 } }'); select *from bson_dollar_project('{}', '{"result": { "$bitXor": 1.3 } }'); select *from bson_dollar_project('{}', '{"result": { "$bitNot": 1.3 } }'); -- $bitAnd $bitOr $bitXor $bitNot, use $array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": "$array" } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": "$array" } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": "$array" } }'); select *from bson_dollar_project('{"array": [3]}', '{"result": { "$bitNot": "$array" } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": ["$array", 4] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": ["$array",5] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": ["$array",4] } }'); select *from bson_dollar_project('{"array": [3]}', '{"result": { "$bitNot": ["$array"] } }'); select *from bson_dollar_project('{"array": [1,2.1,3]}', '{"result": { "$bitAnd": "$array" } }'); select *from bson_dollar_project('{"array": [1.5,2,3]}', '{"result": { "$bitOr": "$array" } }'); select *from bson_dollar_project('{"array": [1,2,3.4]}', '{"result": { "$bitXor": "$array" } }'); select *from bson_dollar_project('{"array": [3.1]}', '{"result": { "$bitNot": "$array" } }'); -- $bitAnd $bitOr $bitXor $bitNot, null in array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [2,3,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [2,3,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [2,3,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [2,3,null] } }'); -- $bitAnd $bitOr $bitXor $bitNot, null array. select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [] } }'); -- $bitAnd $bitOr $bitXor $bitNot, nested array select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,3,[1,2]] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,3,[3,4]] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,3,[5,6]] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [[1]] } }'); -- $bitAnd $bitOr $bitXor $bitNot, dotted path tests SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitAnd": ["$array.b",3]}}'); SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitOr": ["$array.b",3]}}'); SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitXor": ["$array.b",3]}}'); SELECT * FROM bson_dollar_project('{"array": {"b": 1}}', '{"result": { "$bitNot": "$array.b"}}'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": [null] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,"$undefined"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,"$undefined"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,"$undefined"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": ["$undefined"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitAnd": [1,2,"$undefinedPath"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitOr": [1,2,"$undefinedPath"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitXor": [1,2,"$undefinedPath"] } }'); select *from bson_dollar_project('{"array": [1,2,3]}', '{"result": { "$bitNot": ["$undefinedPath"]} }'); bson_aggregation_boolean_operators_tests.sql000066400000000000000000000234251507310017400400470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5500000; SET documentdb.next_collection_id TO 5500; SET documentdb.next_collection_index_id TO 5500; -- $and operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": { }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, 0.1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, {"$numberDecimal": "0.1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, { }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, [ ]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [true, [ 1, 2]]}}'); SELECT * FROM bson_dollar_project('{"a": true, "b": true, "c": true}', '{"result": { "$and": ["$a", "$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": true}}', '{"result": { "$and": ["$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [{"$add": [0, 1]}, "$a.c"]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": false}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": "$a"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [0.1, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$and": [false, {"$numberDecimal": "0.1"}]}}'); SELECT * FROM bson_dollar_project('{"a": true, "b": true, "c": false}', '{"result": { "$and": ["$a", "$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": false}}', '{"result": { "$and": ["$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [{"$add": [0, 0]}, "$a.c"]}}'); -- If nested expression parses to a constant that evaluates to an error, the error from the nested expression will be thrown. SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [false, {"$divide": [1, 0]}, "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$and": [false, "$a.c", {"$subtract": [1, {"$date": {"$numberLong": "11232"}}]}]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$and": [{"$add": [0, 1]}, "$a.c", {"$not": [1,2]}]}}'); -- If nested expression parses to a non-constant (eg: path) that eventually evaluates to an error, shortcircuit evaluation will occur. SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$and": [false, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$and": [true, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); -- $or operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": -23.453}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": { "$numberDecimal": "-0.4" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": { }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, 0.1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, {"$numberDecimal": "0.1"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [true, { }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, [ ]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [[ 1, 2], true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [null, true]}}'); SELECT * FROM bson_dollar_project('{"a": true, "b": false, "c": true}', '{"result": { "$or": ["$a", "$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "b": true, "c": true}}', '{"result": { "$or": ["$z", "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 1]}, "$a.c"]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": false}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": "$z"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, false, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, 0.0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, {"$numberDecimal": "0.0"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [false, "$d"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$or": [null, false]}}'); SELECT * FROM bson_dollar_project('{"a": false, "b": false, "c": false}', '{"result": { "$or": ["$a", "$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "b": false, "c": false}}', '{"result": { "$or": ["$z", "$a.b", "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 0]}, "$a.c"]}}'); -- If nested expression parses to a constant that evaluates to an error should get that error. SELECT * FROM bson_dollar_project('{"a": false, "b": false, "c": false}', '{"result": { "$or": ["$a", "$b", "$c", {"$divide": []}]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$or": [false, {"$divide": [1, 0]}, "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": true}}', '{"result": { "$or": [false, "$a.c", {"$subtract": [1, {"$date": {"$numberLong": "11232"}}]}]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": false}}', '{"result": { "$or": [{"$add": [0, 1]}, "$a.c", {"$not": [1,2]}]}}'); -- If nested expression parses to a non-constant should error. SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$or": [true, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); SELECT * FROM bson_dollar_project('{"a": { "c": 0}}', '{"result": { "$or": [false, {"$divide": [1, "$a.c"]}, "$a.c"]}}'); -- $not operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": false}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$numberDecimal": "0"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": ["$z"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$and": [false, true]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$or": [false, false]}}}'); SELECT * FROM bson_dollar_project('{"a": false}', '{"result": { "$not": ["$a"]}}'); SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": { "$not": ["$a"]}}'); SELECT * FROM bson_dollar_project('{"a": 0.0}', '{"result": { "$not": ["$a"]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": -1.23}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$numberDecimal": "-0.3"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$and": [true, true]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": {"$or": [false, true]}}}'); SELECT * FROM bson_dollar_project('{"a": true}', '{"result": { "$not": ["$a"]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$not": ["$a"]}}'); SELECT * FROM bson_dollar_project('{"a": 0.1}', '{"result": { "$not": ["$a"]}}'); -- should return error for wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [true, false, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$not": [{"$divide": [1, 0]}, false, 2, 3]}}'); bson_aggregation_comparison_operators_tests.sql000066400000000000000000000567061507310017400406120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5700000; SET documentdb.next_collection_id TO 5700; SET documentdb.next_collection_index_id TO 5700; SET client_min_messages TO DEBUG3; -- $cmp -- should return 0 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$cmp": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cmp": ["$a", {}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$cmp": [{"$literal": "$a"}, "$a.b"]}}'); -- should return 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00001, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$cmp": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$cmp": ["$a", {"b": 1, "c": 1}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$cmp": [{"b": "$a"}, "$a"]}}'); -- should return -1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [-1, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [null, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [{"$numberDouble": "NaN"}, 0.00001]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$cmp": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$cmp": ["$a", [3, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$cmp": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); -- $eq operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$eq": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$eq": ["$a", {}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$eq": [{"$literal": "$a"}, "$a.b"]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$numberDouble": "NaN"}, 0.00001]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$eq": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$eq": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$eq": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$eq": ["$a", {"b": 1, "c": 1}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$eq": [{"b": "$a"}, "$a"]}}'); -- $ne operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$numberDouble": "NaN"}, 0.00001]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$ne": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$ne": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$ne": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$ne": ["$a", {"b": 1, "c": 1}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$ne": [{"b": "$a"}, "$a"]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [1, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$ne": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$ne": ["$a", {}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": "$a"}}', '{"result": { "$ne": [{"$literal": "$a"}, "$a.b"]}}'); -- $gt operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.1, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$gt": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$gt": ["$a", {"b": 1, "c": 1}]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$gt": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [{"$numberDouble": "NaN"}, 0.1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [null, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$gt": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gt": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$gt": ["$a", {}]}}'); -- $gte operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$gte": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.1, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$gte": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$gte": ["$a", {"b": 1, "c": 1}]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$gte": ["$a", {}]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [null, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$numberDouble": "NaN"}, 0.1]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$gte": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$gte": ["$a", [1, 2, 3, 4, 5]]}}'); -- $lt operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [-1, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [{"$numberDouble": "NaN"}, 0.1]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$lt": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [3, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lt": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$lt": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [0.1, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$lt": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lt": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lt": ["$a", {"b": 1, "c": 1}]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$lt": ["$a", {}]}}'); -- $lte operator -- should return true SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [-1, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["string", "stringa"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["String", "string"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [false, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.00001, 0.0001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [-1, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": null}', '{"result": { "$lte": ["$a", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", "str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.00002, 0.00002]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [[3,2,1,2,4,6], [3,2,1,2,4,6]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$numberDouble": "NaN"}, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{"a": 3}', '{"result": { "$lte": [{"$add": [2, "$a"]}, {"$multiply": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 4, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [3, 2, 3, 4]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lte": ["$a", {"b": 1, "c": 1, "d": 2}]}}'); -- should return false SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [2, 1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0, -1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [null, "$a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": ["str", "s"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [true, false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.0001, 0.00001]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [0.1, {"$numberDouble": "NaN"}]}}'); SELECT * FROM bson_dollar_project('{"a": 1}', '{"result": { "$lte": [{"$add": [2, "$a"]}, {"$subtract": [2, "$a"]}]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3, 3, 5]]}}'); SELECT * FROM bson_dollar_project('{"a": [1, 2, 3, 4]}', '{"result": { "$lte": ["$a", [1, 2, 3]]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 1, "d": 0}}', '{"result": { "$lte": ["$a", {"b": 1, "c": 1}]}}'); -- should error for wrong number of args SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, 3, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": 2}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [1, 2, 3, 4, 5]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [2, 1, 0]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$divide": [1, 0]}]}}'); -- should error if there is an error in nested expressions SELECT * FROM bson_dollar_project('{}', '{"result": { "$cmp": [2, {"$subtract": [1, {"$date": { "$numberLong": "1" }}]}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$eq": [{"$divide": [1, 0]}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$ne": [{"$not": []}, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gt": [{"$in": [1, 2]}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$gte": [{"$divide": [1, 0, 3]}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lt": [{"$divide": [1, 0, {"$not": []}]}, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$lte": [{"$add": [{"$date": { "$numberLong": "1" }}, {"$date": { "$numberLong": "1" }}]}, 3]}}'); bson_aggregation_conditional_operators_tests.sql000066400000000000000000000325211507310017400407300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5800000; SET documentdb.next_collection_id TO 5800; SET documentdb.next_collection_index_id TO 5800; -- $ifNull: should return first not null SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": ["not null", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, null, "not null"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [{"$arrayElemAt": [[1], 2]}, "not null", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", "not null", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", {"$add":[1,2]}, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", [1, 2, {"$add":[1,2]}], null]}}'); SELECT * FROM bson_dollar_project('{"b": 2}', '{"result": {"$ifNull": [null, "$a", "$b", null]}}'); -- $ifNull: should not return result if last expression is undefined field or an expression with no result SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "$a", "$b"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, null, {"$arrayElemAt": [[1], 2]}]}}'); -- $ifNull: should have at least 2 arguments SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": {}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": "string"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": false}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [{"$divide": [1, 0]}]}}'); -- $ifNull: should honor nested expression errors, even if a not null expression is found SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", {"$divide": [1, 0]}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$ifNull": [null, "not null", {"$ifNull": [1]}]}}'); -- $cond: returns then when condition is true SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$gt": [3, 2]}, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$lt": [2, 3]}, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{"b": true}', '{"result": {"$cond": ["$b", "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "else": "else", "then": "then" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "if": true, "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "if": true, "then": "then"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 2]}, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$lt": [2, 3]}, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{"b": true}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": "else"}}}'); -- $cond: returns else when condition is false SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$gt": [3, 3]}, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [{"$lt": [3, 3]}, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": ["$b", "then", "else"]}}'); SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": ["$b", "then", {"$add": [1, 2]}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 3]}, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$lt": [3, 3]}, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{"b": false}', '{"result": {"$cond": {"if": "$b", "then": "then", "else": [1, 2, {"$add": [1, 2]}]}}}'); -- $cond: null/undefined conditions should evaluate to false and return else SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [null, "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": ["$a", "then", "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": null, "then": "then", "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "$a", "then": "then", "else": "else"}}}'); -- $cond: returns no result when the returned expression is an undefined field or an expression with no result SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": {"$gt": [3, 3]}, "then": "then", "else": {"$ifNull": [null, null, {"$arrayElemAt": [[1], 2]}]}}}}'); -- $cond: if is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "else": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "then": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {}}}'); -- $cond: then is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "if", "else": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"else": "else", "if": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "$a"}}}'); -- $cond: else is required SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": "if", "then": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"then": "then", "if": "$a"}}}'); -- $cond: unknown argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": "then", "else": "$a", "foo": "blah"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"foo": "blah"}}}'); -- $cond: requires 3 arguments error SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, true, true, true, true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": true}}'); -- $cond: nested expression errors honored even if result is not affected by it SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [false, {"$divide": [1, 0]}, "else"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": [true, "then", {"$divide": [1, 0]}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": false, "then": {"$divide": [1, 0]}, "else": "else"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$cond": {"if": true, "then": "then", "else": {"$divide": [1, 0]}}}}'); -- $switch: returns expected branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": true, "then": "second branch is true"}]}}}'); SELECT * FROM bson_dollar_project('{"a": 1, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$lt": ["$a", "$b"]}, "then": "a < b"}]}}}'); SELECT * FROM bson_dollar_project('{"a": 3, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$lt": ["$a", "$b"]}, "then": "a < b"}], "default": "a = b"}}}'); SELECT * FROM bson_dollar_project('{"a": 2, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$not": {"$eq": ["$a", "$b"]}}, "then": "a != b"}], "default": "a = b"}}}'); SELECT * FROM bson_dollar_project('{"a": 0, "b": 2}', '{"result": {"$switch": {"branches": [{"case": {"$gt": ["$a", "$b"]}, "then": "a > b"}, {"case": {"$not": {"$eq": ["$a", "$b"]}}, "then": "a != b"}], "default": "a = b"}}}'); -- $switch: null/undefined should evaluate to false SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": null, "then": "first branch is true"}], "default": "it was false"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": "$a", "then": "first branch is true"}], "default": "it was false"}}}'); -- $switch: shouldn't return result if resulting expression is undefined field or expression with undef result SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "$b"}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": {"$arrayElemAt": [[1], 2]}}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": ""}], "default": {"$arrayElemAt": [[1], 2]}}}}'); -- $switch: requires object argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": "Str"}}'); -- $switch: branches must be an array SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": {}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": "true"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": false}}}'); -- $switch: found an unknown argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [], "foo": "blah"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"foo": "blah", "branches": {}}}}'); -- $switch: requires at least one branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": []}}}'); -- $switch: default is required only when there is no matching branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"case": null, "then": "it is null"}]}}}'); -- $switch: found unknown argument to a branch SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"foo": "blah"}]}}}'); -- $switch: branch requires a case expression SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"then": "blah"}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {}]}}}'); -- $switch: branch requires a then expression SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "$b"}, {"case": "blah"}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false}]}}}'); -- Fails for constant error expressions SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": {"$ifNull": []}}]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": "false"}], "default": {"$ifNull": []}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": false, "then": "false"}], "default": {"$ifNull": []}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": {"$divide": [1, 0]}, "then": "false"}], "default": {"$ifNull": []}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": {"$divide": [1, 0]}, "then": "false"}], "default": {"$ifNull": []}}}}'); -- Fail for non-constant error branch expressions (eg: paths) if that branch is matched SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": true, "then": {"$divide": [1, "$a"]}}]}}}'); -- Does not fail for non-constant error expressions (eg: paths) if a valid branch is found SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": true, "then": "first branch is true"}, {"case": false, "then": {"$divide": [1, "$a"]}}]}}}'); -- Does not fail for non-constant branch error expressions (eg: paths) if the default expression is matched. SELECT * FROM bson_dollar_project('{"a": 0}', '{"result": {"$switch": {"branches": [{"case": false, "then": "first branch is true"}, {"case": false, "then": {"$divide": [1, "$a"]}}], "default": "I am the default"}}}'); bson_aggregation_cursor_tests.sql000066400000000000000000000553461507310017400356560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, public; SET citus.next_shard_id TO 3120000; SET documentdb.next_collection_id TO 3120; SET documentdb.next_collection_index_id TO 3120; SET citus.multi_shard_modify_mode TO 'sequential'; CREATE SCHEMA aggregation_cursor_test; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }', i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; CREATE TYPE aggregation_cursor_test.drain_result AS (filteredDoc bson, docSize int, continuationFiltered bson, persistConnection bool); CREATE FUNCTION aggregation_cursor_test.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL, sort bson DEFAULT NULL, filter bson default null, obfuscate_id bool DEFAULT false) RETURNS SETOF aggregation_cursor_test.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; BEGIN WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "find", filter AS "filter", sort AS "sort", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; CREATE FUNCTION aggregation_cursor_test.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, obfuscate_id bool DEFAULT false, singleBatch bool DEFAULT NULL) RETURNS SETOF aggregation_cursor_test.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'get_aggregation_cursor_test' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- STREAMING BASED: -- test getting the first page (with max page size) - should limit to 2 docs at a time. SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 6, pageSize => 100000); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 6, pageSize => 100000); -- test smaller docs (500KB) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); -- test smaller batch size(s) SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 0, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 2, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 3, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 0, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$skip": 0 }]}'); -- test singleBatch SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}', singleBatch => TRUE); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }]}', singleBatch => FALSE); -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', skipVal => 0, limitVal => 0); -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); BEGIN; SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); ROLLBACK; -- inside a transaction block BEGIN; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); ROLLBACK; -- With local execution off. BEGIN; set local citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); ROLLBACK; -- with sharded SELECT documentdb_api.shard_collection('db', 'get_aggregation_cursor_test', '{ "_id": "hashed" }', false); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 6, pageSize => 100000); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 6, pageSize => 100000); -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); -- inside a transaction block BEGIN; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); ROLLBACK; -- With local execution off. BEGIN; set local citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2, obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3, obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1, obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1, obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }', obfuscate_id => true); ROLLBACK; -- test for errors when returnKey is set to true SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "returnKey" : true, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); -- test for no errors when returnKey is set to false SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "returnKey" : false, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); -- test for errors when returnKey and showRecordId are set to true SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "filter" : { "title" : "a" }, "limit" : 1, "singleBatch" : true, "batchSize" : 1, "showRecordId": true, "returnKey" : true, "lsid" : { "id" : { "$binary" : { "base64": "apfUje6LTzKH9YfO3smIGA==", "subType" : "04" } } }, "$db" : "test" }'); -- test for ntoreturn in find command with unset documentdb.version SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "limit" : 1, "batchSize" : 1, "ntoreturn":1 ,"$db" : "test" }'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 ,"$db" : "test" }'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 , "batchSize":1, "$db" : "test" }'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "movies", "ntoreturn":1 , "limit":1, "$db" : "test" }'); -- Test $limit for large docs, even when batch size is enough to fit all limited docs, the response size should enforce persisted cursors for $limit SELECT 1 FROM drop_collection('db','get_aggregation_cursor_test'); DO $$ DECLARE i int; BEGIN -- each doc is ~16MB FOR i IN 1..5 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test', FORMAT('{ "_id": %s, "a": "%s" }', i, repeat('a', 16777000))::documentdb_core.bson); END LOOP; END; $$; SELECT * FROM aggregation_cursor_test.drain_find_query(loopCount => 5, pageSize => 10, limitVal => 5);bson_aggregation_data_size_operators_tests.sql000066400000000000000000000102371507310017400403700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8500000; SET documentdb.next_collection_id TO 8500; SET documentdb.next_collection_index_id TO 8500; -- $bsonSize operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"x":1} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [{"a":1}] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"$undefined":true} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"x":1 , "b": 5, "c": {"$numberLong": "10"} } }}'); -- $bsonSize operator , large size documents SELECT * FROM bson_dollar_project(('{"input" : "' || LPAD('', 16000000, 'a') || '"}')::bson, '{"result": { "$bsonSize": "$$ROOT" }}'); -- $bsonSize operator , document based tests SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$$ROOT" }}'); SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$ROOT" }}'); SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$ROOT.b" }}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$$CURRENT" }}'); SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$CURRENT" }}'); SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":12} }', '{"result": { "$bsonSize": "$$CURRENT.b" }}'); -- $bsonSize operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [1,2] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": [1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": 11 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": true }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": "12absd" }}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$bsonSize": "$a" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$bsonSize": {"$regex": "a*b", "$options":""} }}'); -- $binarySize operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": null }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$undefined":true} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "abvd" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "hello!" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "abc\\0c" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "I â¤ï¸ documentdb" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "🙈" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": "アユシュ・サルージャã§ã™"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}}}'); -- $binarySize operator , large size documents SELECT * FROM bson_dollar_project(('{"input" : "' || LPAD('', 16000000, 'a') || '"}')::bson, '{"result": { "$binarySize": "$input" }}'); -- $binarySize operator , document based tests SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$binarySize": "$a" }}'); SELECT * FROM bson_dollar_project('{"a":"temp", "b":{"a":12} }', '{"result": { "$binarySize": "$a" }}'); SELECT * FROM bson_dollar_project('{"a":1, "b":{"a":"world!"} }', '{"result": { "$binarySize": "$b.a" }}'); -- $binarySize operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": [1,2] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": [1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": 11 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": true }}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$binarySize": "$a" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$binarySize": {"$regex": "a*b", "$options":""} }}'); bson_aggregation_date_operators_tests.sql000066400000000000000000004170421507310017400373470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5900000; SET documentdb.next_collection_id TO 5900; SET documentdb.next_collection_index_id TO 5900; -- $hour, $minute, $second, $millisecond: simple SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T07:30:10.5Z"}}', '{"hour": {"$hour": "$date"}, "minute": {"$minute": "$date"}, "second": {"$second": "$date"}, "ms": {"$millisecond": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T10:30:10.5Z"}}', '{"hour": {"$hour": [ "$date" ]}, "minute": {"$minute": [ "$date" ]}, "second": {"$second": [ "$date" ]}, "ms": {"$millisecond": [ "$date" ]}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T23:59:59.28Z"}}', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); -- 2022-12-14T01:28:46.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "639926cee6bda3127f153bf1" } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$timestamp" : { "t": 1670981326, "i": 1 } } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); -- 2022-12-14T01:31:47.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "63992783f5e4d92817ef6ccc" } }', '{"hour": {"$hour": { "date": "$date" }}, "minute": {"$minute": { "date": "$date" }}, "second": {"$second": { "date": "$date" }}, "ms": {"$millisecond": { "date": "$date" }}}'); -- $hour, $minute, $second, $millisecond: with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+08:05"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:00.001Z"}, "tz": "-08:05"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-08"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-0801"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.020Z"}, "tz": "+1210"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "UTC"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+00"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "+0000"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.000Z"}, "tz": "-00:00"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); -- should observe daylight savings or not SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-06-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-12-01T00:00:01.201Z"}, "tz": "US/Pacific"}', '{"hour": {"$hour": { "date": "$date", "timezone": "$tz" }}, "minute": {"$minute": { "date": "$date", "timezone": "$tz" }}, "second": {"$second": { "date": "$date", "timezone": "$tz" }}, "ms": {"$millisecond": { "date": "$date", "timezone": "$tz" }}}'); -- $year, $month, $dayOfMonth: simple SELECT * FROM bson_dollar_project('{"date": {"$date": "2005-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "month": {"$month": "$date"}, "dayOfMonth": {"$dayOfMonth": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2999-02-28T10:30:10.5Z"}}', '{"year": {"$year": [ "$date" ]}, "month": {"$month": [ "$date" ]}, "dayOfMonth": {"$dayOfMonth": [ "$date" ]}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T23:59:59.28Z"}}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); -- 2022-12-14T01:28:46.000Z SELECT * FROM bson_dollar_project('{"date": {"$oid" : "639926cee6bda3127f153bf1" }}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$timestamp" : { "t": 1670981326, "i": 1 } }}', '{"year": {"$year": { "date": "$date" }}, "month": {"$month": { "date": "$date" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date" }}}'); -- $year, $month, $dayOfMonth: with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T23:59:59.28Z"}, "tz": "+01"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "+12"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "+12:01"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "-1159"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1930-12-31T11:59:00.000Z"}, "tz": "-12"}', '{"year": {"$year": { "date": "$date", "timezone": "$tz" }}, "month": {"$month": { "date": "$date", "timezone": "$tz" }}, "dayOfMonth": {"$dayOfMonth": { "date": "$date", "timezone": "$tz" }}}'); -- $week and $isoWeek -- $week range is 0-53, weeks are from Sunday-Saturday. -- $isoWeek ranges is 1-53, weeks are Monday-Sunday. -- 2023-01-01 is first Sunday of the year. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"week": {"$week": "$date"}, "isoWeek": {"$isoWeek": "$date"}}'); -- 2023-01-08 is second Sunday of the year. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-08T07:30:10.5Z"}}', '{"week": {"$week": "$date"}, "isoWeek": {"$isoWeek": "$date"}}'); -- 2022-01-01 is Saturday SELECT * FROM bson_dollar_project('{"date": {"$date": "2022-01-01T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date"}}, "isoWeek": {"$isoWeek": { "date": "$date"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2022-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); -- $week and $isoWeek: leap year SELECT * FROM bson_dollar_project('{"date": {"$date": "2020-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2000-12-31T07:30:10.5Z"}}', '{"week": [ {"$week": "$date"} ], "isoWeek": [ {"$isoWeek": "$date"} ]}'); -- $dayOfYear SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-31T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": [ "$date" ]}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-02-28T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": { "date": "$date" }}}'); -- $dayOfYear: leap year should add 1 day SELECT * FROM bson_dollar_project('{"leapDate": {"$date": "2024-03-01T07:30:10.5Z"}, "nonLeapDate": {"$date": "2023-03-01T07:30:10.5Z"}}', '{"leapDayOfYear": {"$dayOfYear": { "date": "$leapDate" }}, "nonLeapDayOfYear": {"$dayOfYear": { "date": "$nonLeapDate" }}}'); SELECT * FROM bson_dollar_project('{"leapDate": {"$date": "2024-12-31T07:30:10.5Z"}, "nonLeapDate": {"$date": "2023-12-31T07:30:10.5Z"}}', '{"leapDayOfYear": {"$dayOfYear": { "date": "$leapDate" }}, "nonLeapDayOfYear": {"$dayOfYear": { "date": "$nonLeapDate" }}}'); -- $dayOfWeek and $isoDayOfWeek both are 1-7 following $week or $isoWeek. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"name": "Sunday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-02T07:30:10.5Z"}}', '{"name": "Monday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1999-02-02T07:30:10.5Z"}}', '{"name": "Tuesday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-03-15T07:30:10.5Z"}}', '{"name": "Wednesday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-11-29T07:30:10.5Z"}}', '{"name": "Thursday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2028-05-19T07:30:10.5Z"}}', '{"name": "Friday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"name": "Saturday", "dayOfWeek": {"$dayOfWeek": "$date"}, "isoDayOfWeek": {"$isoDayOfWeek": "$date"}}'); -- $year and $isoWeekYear SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2006-01-01T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2006-01-02T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"year": {"$year": "$date"}, "isoWeekYear": {"$isoWeekYear": "$date"}}'); -- date part operators with nested operators -- add 1 year to the date. SELECT * FROM bson_dollar_project('{"date": {"$date": "2023-01-01T07:30:10.5Z"}}', '{"year": {"$year": { "$add": ["$date", {"$numberLong": "31540000000"}]}}}'); -- date part operators, null/undefined date or timezone, should return null. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": null}}'); SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": [ null ]}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"date": null}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"date": "$a"}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": null }}}'); SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": [ "$a" ]}}'); SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": "$a" }}}'); SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": [ null ]}}'); SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": "$a"}}'); SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": "$a" }}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"date": {"$date": "2012-12-31T07:30:10.5Z"}, "timezone": null }}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": null}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": "$a"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2012-12-31T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": "$timezone"}}}'); -- negative tests for date part operators -- -- date part operators: date expression should be convertible to date: timestamp, object id or date time. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": "str"}}'); SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": true}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": false}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": false}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": "str"}}'); SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": 1}}'); SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": 1}}'); SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": 1}}'); SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": 1}}'); SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": [[]]}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": [[]]}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": {}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": []}}}'); SELECT * FROM bson_dollar_project('{"date": {"date": {"$date": "2012-12-31T07:30:10.5Z"} }}', '{"isoWeek": {"$isoWeek": "$date"}}'); -- date part operators: timezone argument should be string SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": true}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"month": {"$month": {"date": "$date", "timezone": false}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfMonth": {"$dayOfMonth": {"date": "$date", "timezone": []}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": {"date": "$date", "timezone": 1}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfWeek": {"$dayOfWeek": {"date": "$date", "timezone": {}}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"hour": {"$hour": {"date": "$date", "timezone": false}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"minute": {"$minute": {"date": "$date", "timezone": [[[]]]}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"second": {"$second": {"date": "$date", "timezone": {}}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"millisecond": {"$millisecond": {"date": "$date", "timezone": 1}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date", "timezone": {"$date": {"$numberLong": "0"}}}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeekYear": {"$isoWeekYear": {"date": "$date", "timezone": {"$oid": "639926cee6bda3127f153bf1"}}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": "$date", "timezone": true}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": true}}}'); -- date part operators: object argument. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": {"timezone": true}}}'); SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": {}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"timezone": []}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"timezone": 1}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"timezone": {}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": {}}}'); SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"timezone": [[[]]]}}}'); SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": {"timezone": {}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": {}}}'); SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"timezone": {"$date": {"$numberLong": "0"}}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"timezone": {"$oid": "639926cee6bda3127f153bf1"}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"timezone": true}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"timezone": true}}}'); -- date part operators: object with date and timezone arguments. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": {"random": true}}}'); SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": {"foo": 1}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": {"timezone": [], "date": 1, "time": 1}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": {"timezone": 1, "dat": 2}}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": {"timezon": {}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": {"datetime": 1}}}'); SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": {"timeZone": [[[]]]}}}'); SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": {"Timezone": {}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": {"unknown": "1"}}}'); SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": {"location": {"$date": {"$numberLong": "0"}}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": {"timezonE": {"$oid": "639926cee6bda3127f153bf1"}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": {"timezone": true, "foo": 1}}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": {"date": 1, "info": ""}}}'); -- date part operators: array argument, should be single element array. SELECT * FROM bson_dollar_project('{ }', '{"year": {"$year": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{ }', '{"month": {"$month": []}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfMonth": {"$dayOfMonth": [1, 2]}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfYear": {"$dayOfYear": [[], []]}}'); SELECT * FROM bson_dollar_project('{ }', '{"dayOfWeek": {"$dayOfWeek": []}}'); SELECT * FROM bson_dollar_project('{ }', '{"hour": {"$hour": [1, 2, 3, 4]}}'); SELECT * FROM bson_dollar_project('{ }', '{"minute": {"$minute": []}}'); SELECT * FROM bson_dollar_project('{ }', '{"second": {"$second": ["srr", "foo"]}}'); SELECT * FROM bson_dollar_project('{ }', '{"millisecond": {"$millisecond": [1, 2]}}'); SELECT * FROM bson_dollar_project('{ }', '{"week": {"$week": []}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeekYear": {"$isoWeekYear": [1, 2, 3, 4, 5]}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoDayOfWeek": {"$isoDayOfWeek": []}}'); SELECT * FROM bson_dollar_project('{ }', '{"isoWeek": {"$isoWeek": [1, []]}}'); -- date part operators: unrecognized timezones SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": ""}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": "\u0000\u0000"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"year": {"$year": {"date": "$date", "timezone": "+8"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"month": {"$month": {"date": "$date", "timezone": "+080"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfMonth": {"$dayOfMonth": {"date": "$date", "timezone": "+08:800"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfYear": {"$dayOfYear": {"date": "$date", "timezone": "-888888"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dayOfWeek": {"$dayOfWeek": {"date": "$date", "timezone": "US/Unknown"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"hour": {"$hour": {"date": "$date", "timezone": "+"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"minute": {"$minute": {"date": "$date", "timezone": "08:09"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"second": {"$second": {"date": "$date", "timezone": "Etc/Invalid"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"millisecond": {"$millisecond": {"date": "$date", "timezone": "US/Pacifi"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"week": {"$week": {"date": "$date", "timezone": "America/LosAngeles"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeekYear": {"$isoWeekYear": {"date": "$date", "timezone": "UST"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoDayOfWeek": {"$isoDayOfWeek": {"date": "$date", "timezone": "+080\u00001"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"isoWeek": {"$isoWeek": {"date": "$date", "timezone": "+080\u0000"}}}'); -- $dateToParts no timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1990-01-01T23:13:00.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": true }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-12-31T15:13:25.003Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-12-31T15:13:25.003Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": false }}}'); -- $dateToParts with timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "Europe/London" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "America/New_York" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "+01" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "-01" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "-0001" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}, "tz": "America/New_York"}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "$tz", "iso8601": {"$eq": ["$tz", "America/New_York"]} }}}'); -- oid == 2017-06-19T15:13:25.713Z UTC. SELECT * FROM bson_dollar_project('{"_id": {"$oid": "58c7cba47bbadf523cf2c313"}}', '{"dateParts": {"$dateToParts": { "date": "$_id", "timezone": "Europe/London" }}}'); -- $dateToParts should return null SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": null }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": "$iso" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": null }}}'); SELECT * FROM bson_dollar_project('{"_id": 1 }', '{"dateParts": {"$dateToParts": { "date": "$date", "timezone": "UTC", "iso8601": true }}}'); SELECT * FROM bson_dollar_project('{"_id": 1 }', '{"dateParts": {"$dateToParts": { "date": null, "timezone": "UTC", "iso8601": true }}}'); -- $dateToParts 'date' argument is required SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "$tz" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "$tz", "iso8601": true }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "timezone": "Unknown", "iso8601": true }}}'); -- $dateToParts 'iso8601' should be a bool SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": {"$add": [1, 1]} }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "$date", "iso8601": "str" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str" }}}'); -- $dateToParts 'date' must be a date, timestamp or oid SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": true }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": "str" }}}'); -- $dateToParts 'timezone' must be a string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str", "timezone": 1 }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateParts": {"$dateToParts": { "date": {"$add": [1, 1]}, "iso8601": "str", "timezone": {"$add": [1]} }}}'); -- $dateToParts 'timezone' is unknown SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": ""}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "\u0000\u0000"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+8"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+080"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "+08:800"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "-888888"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "Ut"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2035-06-23T07:30:10.5Z"}}', '{"dateToParts": {"$dateToParts": {"date": "$date", "timezone": "Unknown"}}}'); -- $dateToString no timezone default format SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-06-01T00:01:02.003Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0906-06-01T08:01:02.023Z"}}', '{"dateString": {"$dateToString": { "date": "$date" }}}'); -- $dateToString with timezone default format SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/Los_Angeles" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/Los_Angeles" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Europe/London" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Europe/London" }}}'); -- $dateToString random formats SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%d%d***%d***%d**%d*%d" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0006-06-01T00:01:02.003Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%%%%%%%%%%%%%%%%%%---%Y---%%%%%%%%%%%%" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "0906-06-01T08:01:02.023Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "This is a custom format:\u0000....%Y-%d-%m....\u0000"}}}'); -- $dateToString timezone specifiers SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-06-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)", "timezone": "America/Los_Angeles" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "America/Los_Angeles" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "Africa/Asmera" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+08" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+0059" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "+5959" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-19T15:13:25.713Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "UTC offset: %z (%Z minutes)","timezone": "-00:01" }}}'); -- $dateToString multiple timezones SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Europe/London" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Australia/Eucla" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Asia/Katmandu" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "Europe/Amsterdam" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "1900-07-10T11:41:22.418Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/Caracas" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-04T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T15:09:12.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "America/New_York" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)" }}}'); -- $dateToString natural vs iso dates SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T15:09:12.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U-d%j, ISO: %G-W%u-%V-d%j" }}}'); -- $dateToString long format strings > 256 bytes SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZNMIX was placed on: %Y-%m-%d %H:%M:%S" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2038-01-01T15:08:51.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "The order: RIMSLABOZXERCQTXYYSJFUOPCAUWTDPXHEMCUUTUWZZSPLMXNWSIYDZ was placed on: %Y-%m-%d %H:%M:%S" }}}'); -- $dateToString returns null if no onNull is specified and any arg expression is null or undefined SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "$tz", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": null, "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/New_York", "format": "$format" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "America/New_York", "format": null }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": null, "timezone": "America/New_York"}}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$literal": null}, "timezone": "America/New_York"}}}'); -- $dateToString onNull expression is only returned and honored when 'date' argument is null SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "date was null or undefined" }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$date" }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": {"$date": "2017-12-04T15:09:14.911Z"} }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$newYorkDate", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "date was null or undefined" }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "timezone": "$tz", "onNull": "date was null or undefined" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-12-04T15:09:14.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "$format", "onNull": "date was null or undefined" }}}'); -- $dateToString when date is null and onNull expression points to a non existent path in the document, no result is returned SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a" }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$b" }}}'); SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$c" }}}'); -- $dateToString 'date' is required SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a" }}}'); -- $dateToString unknown field SELECT * FROM bson_dollar_project('{"date": null}', '{"dateString": {"$dateToString": { "date": "$date", "format": "Natural: %Y-W%w-%U, ISO: %G-W%u-%V", "onNull": "$a", "customField": "a" }}}'); -- $dateToString an object is required as an argument SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": "$arg"}}'); SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": null}}'); SELECT * FROM bson_dollar_project('{"arg": {"date": null, "format": "%Y", "timezone": "UTC"}}', '{"dateString": {"$dateToString": []}}'); -- $dateToString invalid format modifier SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %i %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%i %Y-%m-%d %H:%M:%S %z (%Z minutes)", "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes) %i", "timezone": "UTC" }}}'); -- $dateToString unmatched % at end of format string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": "%Y-%m-%d %H:%M:%S %z (%Z minutes)%%%", "timezone": "UTC" }}}'); -- $dateToString 'format' argument must be a string SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": true, "timezone": "UTC" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "format": 1, "timezone": "UTC" }}}'); -- $dateToString 'date' must be an oid, timestamp or date SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "", "timezone": "UTC" }}}'); -- $dateToString 'timezone' must be string and a valid timezone SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": true }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "Unknown" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "+8" }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "2017-07-04T14:56:42.911Z"}}', '{"dateString": {"$dateToString": { "date": "$date", "timezone": "+80000000" }}}'); -- $dateToString date component outside of supported range SELECT * FROM bson_dollar_project('{"date": {"$date": "9999-12-31T11:59:59.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$add": ["$date", {"$numberLong": "86400000"}]} }}}'); SELECT * FROM bson_dollar_project('{"date": {"$date": "9999-12-31T11:59:59.911Z"}}', '{"dateString": {"$dateToString": { "date": {"$add": ["$date", {"$numberLong": "86400000"}]}, "format": "%Y" }}}'); -- $dateFromParts null cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": null }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"$undefined":true} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":200, "timezone":null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": null} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": 5, "isoDayOfWeek":null} }}'); -- $dateFromParts undefined cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": {"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": {"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2029, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":200, "timezone":{"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : {"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": {"$undefined":true}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear" : 2029, "isoWeek": 5, "isoDayOfWeek":{"$undefined":true}} }}'); -- $dateFromParts non-iso format cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2029} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2000, "month": 5, "day":5} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1970, "month": 2, "day": 10, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2000, "month": 2, "day": 29, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450} }}'); -- $dateFromParts non-iso format cases with timezone select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "UTC"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "America/Denver"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "Asia/Kolkata"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "+04:30"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 5, "day": 10, "hour":2 , "minute":20, "second":5, "millisecond":450, "timezone": "+0430"} }}'); -- $dateFromParts iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2023, "isoWeek":12, "isoDayOfWeek": 2} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone": "+04:30"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":12, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone": "+0430"} }}'); -- $dateFromParts iso cases with timezone select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2029, "isoWeek":20, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12, "timezone": "America/Denver"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2023, "isoWeek":12, "isoDayOfWeek": 2, "timezone": "America/Los_Angeles"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":20, "minute":45, "second":12 , "timezone": "Asia/Kolkata"} }}'); -- $dateFromParts cases with carrying when range is not valid for iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2017, "isoWeek":0, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2000, "isoWeek":0, "isoDayOfWeek": 5 ,"hour":18, "minute":45, "second":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2000, "isoWeek":0, "isoDayOfWeek": 15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 1, "isoWeek":0, "isoDayOfWeek": 15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2011, "isoWeek":-24, "isoDayOfWeek": -15 ,"hour":28, "minute":450, "second":124 , "millisecond":876} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2011, "isoWeek":-24, "isoDayOfWeek": -15 ,"hour":-28, "minute":-450, "second":-124 , "millisecond":876} }}'); -- $dateFromParts cases with carrying when range is not valid for non-iso format select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": 15, "day": 100, "hour":23 , "minute":210, "second":1115, "millisecond":450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 2020, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 1, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year" : 9999, "month": -15, "day": 1200, "hour":213 , "minute":2110, "second":-1115, "millisecond":-450} }}'); -- $dateFromParts cases negative cases select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": 1 }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": "abc" }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017, "isoWeekYear": 2012} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": {"$numberDecimal": "2014.5"} } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": 1 }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": "abc" }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017, "isoWeekYear": 2012} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":2017.5} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year":"2017"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2017, "abcd":1} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012.12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": "2012"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "timezone": "hello"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2012, "timezone": 1} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 0} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 11110} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 0} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 11110} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 32769, "day": 100, "second": 50, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 32769, "second": 50, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "second": 32769, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": 32769, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -24, "minute":32769} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": -32769, "day": 100, "second": 50, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": -32769, "second": 50, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "second": -32769, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -32769, "minute":100} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "month": 12, "day": 1, "hour": -24, "minute":-32769} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 2010, "millisecond": {"$numberDecimal": "-18999999999999999888888888"}} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "month":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeekYear": 2012, "day":12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 1209, "isoWeek": 12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"year": 1209, "isoDayOfWeek": 12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"month": 1209, "isoDayOfWeek": 12} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"month": 1209} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateFromParts": {"isoWeek": 1209} }}'); -- $dateFromParts document based cases select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month", "day": "$day", "hour":"$hour" , "minute":"$minute", "second":"$second", "millisecond":"$millisecond"} }}'); select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month"} }}'); select * from bson_dollar_project('{"year" : 2011, "month": 2, "day": 28, "hour":23 , "minute":59, "second":50, "millisecond":450, "timezone": "America/Los_Angeles"}', '{"result": {"$dateFromParts": {"year" : "$year", "month": "$month" , "timezone": "$timezone"} }}'); select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek" ,"hour":"$hour", "minute":"$minute", "second":"$second"} }}'); select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek"} }}'); select * from bson_dollar_project(' {"isoWeekYear": 2024, "isoWeek":50, "isoDayOfWeek": 2 ,"hour":18, "minute":45, "second":12, "timezone" : "America/New_York"}', '{"result": {"$dateFromParts": {"isoWeekYear": "$isoWeekYear", "isoWeek": "$isoWeek", "isoDayOfWeek": "$isoDayOfWeek", "timezone": "$timezone"} }}'); --$dateTrunc null cases select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": null }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"$undefined": true} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": null } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": {"$undefined": true} } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "timezone": null , "binSize": 5 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "timezone": {"$undefined": true} , "binSize":5 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "timezone": "+04:45", "unit": null , "binSize": 5 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "timezone": "-0430", "unit": {"$undefined": true} , "binSize":5 } }}'); -- $dateTrunc case when startOfWeek is null select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "startOfWeek": null , "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "startOfWeek": {"$undefined": true}, "binSize": 2 } }}'); -- $dateTrunc case when startOfWeek null but unit is not week select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "startOfWeek": null , "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "startOfWeek": {"$undefined": true} , "binSize": 2 } }}'); -- $dateTrunc cases with unit millisecond select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "millisecond", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "millisecond" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "millisecond", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "millisecond" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "millisecond" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "millisecond" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit second select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "second" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "second", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "second" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "second" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "second" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit minute select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "minute", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "minute" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "minute", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "minute" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "minute" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "minute" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit hour select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "hour", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "hour" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour", "binSize": 2, "timezone": "America/Los_Angeles" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour" , "binSize": 200000, "timezone": "America/New_York" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "hour" , "binSize": 200000, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "hour" , "binSize": 4500 } }}'); /* This test case has overflow, postgres added this check in newer minor versions. * Todo: add this test back and check overflow after we bump up the postgres minor version (>=15.7 and >=16.3). */ -- select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "hour" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit day select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "day", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "day" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "day", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "day" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "day" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "day" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit week select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "week" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "week", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "week" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "week" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "week" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit month select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "month", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "month" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "month", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "month" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "month" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "month" , "binSize": 450000000 } }}'); -- $dateTrunc cases with unit year select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "year", "binSize": 2 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}}, "unit": "year" , "binSize": 200000 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "year", "binSize": 2, "timezone": "America/Denver" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "951850555381"}}, "unit": "year" , "binSize": 200000, "timezone": "Asia/Kolkata" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "year" , "binSize": 4500 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "7498555381"}}, "unit": "year" , "binSize": 450000000 } }}'); -- $dateTrunc invalid cases select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": "A" }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"abc": 1} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": 1 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "456" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "456" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": "1" } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": 1.5 } }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "year", "binSize": 1 , "timezone": 123} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": {"$date" : {"$numberLong": "1707123355381"}} , "unit": "week", "binSize": 1 , "startOfWeek": "Menday"} }}'); select * from bson_dollar_project('{}', '{"result": {"$dateTrunc": {"date": "A" , "unit": "456" } }}'); -- $dateAdd null based cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": null } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"$undefined":true} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {} } }'); -- $dateAdd cases when input parts are null or undefined select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": null , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":null , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":null, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$undefined":true} , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":{"$undefined":true} , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":{"$undefined":true}, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": {"$undefined":true} } } }'); -- $dateAdd normal cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":-30 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":3 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"quarter" , "amount":45 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":145 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"week" , "amount":-14 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"hour" , "amount":4 } } }'); -- $dateAdd cases with timezone handling select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount":2, "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount":12, "timezone": "America/New_York" } } }'); -- dst offset not applied for hours select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount":24, "timezone": "Europe/Paris" } } }'); -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "Europe/Paris" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"second" , "amount":1, "timezone": "-05:30" } } }'); -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":5, "timezone": "America/New_York" } } }'); -- $dateAdd cases with input validation of ranges which are calculated manually. With these inputs we should error that it's out of range. This is a pre-addition validation select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 584942419} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"quarter" , "amount": 1754827252} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount": 7019309005} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"day" , "amount": 213503982336} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount": 5124095576041} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"minute" , "amount": 307445734562401} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 18446744073744001} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 1, "hex": "a"} } }'); -- $dateAdd cases with error cases select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56.55} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"years" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"unit":"day" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"unit":"day" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": "abcd" , "amount": 56, "unit": 5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56, "unit": 5, "timezone": "abcd"} } }'); -- $dateAdd cases with overflow select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"year" , "amount": 584942416} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"month" , "amount": 584942416} } }'); select * from bson_dollar_project('{}','{"result": {"$dateAdd": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount": 58411942416} } }'); -- $dateAdd cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":3 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":10 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":60 }','{"result": {"$dateAdd": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); -- $dateSubtract null based cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": null } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"$undefined":true} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {} } }'); -- $dateSubtract cases when input parts are null or undefined select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": null , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":null , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":null, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$undefined":true} , "unit":"month" , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":{"$undefined":true} , "amount":30000000000, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":{"$undefined":true}, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":1, "timezone": {"$undefined":true} } } }'); -- $dateSubtract normal cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":-30 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":3 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1709205288000"} } , "unit":"year" , "amount":1 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"quarter" , "amount":45 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":145 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"week" , "amount":-14 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"hour" , "amount":4 } } }'); -- $dateSubtract cases with timezone handling select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount":2, "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount":12, "timezone": "America/New_York" } } }'); -- dst offset not applied for hours select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount":24, "timezone": "Europe/Paris" } } }'); -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "Europe/Paris" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"day" , "amount":1, "timezone": "+04:00" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"second" , "amount":1, "timezone": "-05:30" } } }'); -- dst offset applied select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":5, "timezone": "America/New_York" } } }'); -- $dateSubtract cases with input validation of ranges which are calculated manually. With these inputs we should error that it's out of range. This is a pre-subtraction validation select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 584942419} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"quarter" , "amount": 1754827252} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"month" , "amount": 7019309005} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"week" , "amount": 30500568906} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"day" , "amount": 213503982336} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"hour" , "amount": 5124095576041} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"minute" , "amount": 307445734562401} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 18446744073744001} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"second" , "amount": 1, "hex": "a"} } }'); -- $dateSubtract cases with error cases select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56.55} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"years" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "unit":"year" , "amount": 56, "field":5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"unit":"day" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"unit":"day" , "amount": 56} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": "abcd" , "amount": 56, "unit": 5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1612062000000"} } , "amount": 56, "unit": 5, "timezone": "abcd"} } }'); -- $dateSubtract cases with overflow select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"year" , "amount": 584942416} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"month" , "amount": 584942416} } }'); select * from bson_dollar_project('{}','{"result": {"$dateSubtract": {"startDate": {"$date": {"$numberLong": "1603563000000"} } , "unit":"hour" , "amount": 58411942416} } }'); -- $dateSubtract cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"second" , "amount":300 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"month" , "amount":3 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"year" , "amount":10 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1615647600000"} } , "unit":"day" , "amount":60 }','{"result": {"$dateSubtract": {"startDate": "$startDate", "amount": "$amount", "unit":"$unit"} } }'); -- $dateDiff null cases select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": null , "unit":"minute" , "endDate": {"$date": {"$numberLong": "1678924740000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "unit":"minute" , "endDate": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": "-05:00", "startOfWeek" : null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$undefined":true} , "unit":"minute" , "endDate": {"$date": {"$numberLong": "1678924740000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "unit":"minute" , "endDate": {"$undefined":true} } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": {"$undefined":true} } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": {"$undefined":true} } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" , "timezone": "-05:00", "startOfWeek" : {"$undefined":true} } } }'); -- $dateDiff null cases with document select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezones" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unist", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDsate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$sstartDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); -- startOfWeek is ignored when unit is not week select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" , "timezone": "-05:00", "startOfWeek" : null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" , "timezone": "-05:00", "startOfWeek" : 1 } } }'); -- $dateDiff unit milliseconds select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "millisecond" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "millisecond", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); -- $dateDiff unit seconds select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "second" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "second", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); -- $dateDiff unit minute select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "minute" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "minute"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); -- $dateDiff unit hour select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "hour" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "hour"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "hour"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "hour", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); -- $dateDiff unit day select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "day" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "day", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); -- days in 2024 year select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "day"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "day", "timezone": "America/Denver"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); -- $dateDiff unit week select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678924740500"} } , "endDate": {"$date": {"$numberLong": "4740000"} }, "unit": "week" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "UTC" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678920740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678488740500"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "+05:00" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week", "timezone": "America/New_York" }','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1678406400000"} } , "endDate": {"$date": {"$numberLong": "1678924740000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1604255016000"} } , "endDate": {"$date": {"$numberLong": "1604275200000"} }, "unit": "week", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); -- weeks in 2024 year select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "week"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1704067200000"} } , "endDate": {"$date": {"$numberLong": "1735603200000"} }, "unit": "week", "timezone": "America/Denver"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "timezone": "$timezone"} } }'); -- week startOfWeek cases select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "MONDAY"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "monday"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1611512616000"} } , "endDate": {"$date": {"$numberLong": "1611541416000"} }, "unit": "week", "startOfWeek": "tuesday"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek"} } }'); select * from bson_dollar_project('{"startDate": {"$date": {"$numberLong": "1610859600000"} } , "endDate": {"$date": {"$numberLong": "1610859540000"} }, "unit": "week", "startOfWeek": "sunday", "timezone": "America/New_York"}','{"result": {"$dateDiff": {"startDate": "$startDate" , "endDate": "$endDate", "unit": "$unit", "startOfWeek": "$startOfWeek", "timezone": "$timezone"} } }'); -- $dateDiff unit month select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "month" } } }'); -- $dateDiff unit quarter select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "quarter" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "quarter" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "quarter" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "quarter" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "quarter" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "quarter" } } }'); -- $dateDiff unit year select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1293840000000"} }, "unit": "year" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "endDate": {"$date": {"$numberLong": "1309392000000"} }, "unit": "year" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "year" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1267401600000"} } , "endDate": {"$date": {"$numberLong": "1272585600000"} }, "unit": "year" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "993859200000"} } , "endDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "year" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "993859200000"} } , "startDate": {"$date": {"$numberLong": "1262304000000"} }, "unit": "year" } } }'); -- $dateDiff invalid cases select * from bson_dollar_project('{}','{"result": {"$dateDiff": 1 } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": "abc" } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": ["abc"] } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {} } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "month" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"startDate": 1 , "unit": "month", "endDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": 1 , "unit": "month", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"hex":1, "endDate": 1 , "unit": "month", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "ashd", "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": 1, "startDate": {"$date": {"$numberLong": "1262304000000"} } } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : 1 } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : "abcd" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateDiff": {"endDate": {"$date": {"$numberLong": "1262304000000"} } , "unit": "week", "startDate": {"$date": {"$numberLong": "1262304000000"} }, "timezone" : "UTC", "startOfWeek": "hello" } } }'); -- $dateFromString null cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": null } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": null } } }'); -- checking with undefined as well select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": {"$undefined": true} } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": {"$undefined": true} } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": {"$undefined": true} } } }'); -- onError null does not effect null response select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": "UTC", "onError": null} } }'); -- $dateFromString null cases with document select * from bson_dollar_project('{"dateString": null}','{"result": {"$dateFromString": {"dateString": "$dateString" } } }'); select * from bson_dollar_project('{"dateString": "2021-01-11", "format": null }','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format" } } }'); select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": null }','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone" } } }'); select * from bson_dollar_project('{"dateString": {"$undefined": true} }','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "2021-01-11", "format": {"$undefined": true}}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format" } } }'); select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": {"$undefined": true}}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone" } } }'); -- onError null does not effect null response select * from bson_dollar_project('{"dateString": "2021-01-11", "format": "%Y-%m-%d", "timezone": "UTC", "onError": null}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "timezone": "$timezone", "onError": "$onError"} } }'); -- $dateFromString normal cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.506Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ABCD 2021-01-11T12.53.12.506Z", "format": "ABCD %Y-%m-%dT%H.%M.%S.%LZ"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2025-12-31", "format": "%Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "20-1-1", "format": "%Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Year 2025, Month 12, Day 31", "format": "Year %Y, Month %m, Day %d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z"} } }'); -- millisecond can be of min 1 and max 3 digits select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.5Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); -- millisecond of 2 digits select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12.53.12.50Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"} } }'); -- iso date format select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "53.7.2017", "format": "%V.%u.%G"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "1.1.1", "format": "%V.%u.%G"} } }'); -- iso part only requires year select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017", "format": "%G"} } }'); -- % format specifier parsing test select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "%% %Y-%m-%dT%H:%M:%S.%LZ"} } }'); -- $dateFromString normal cases with document select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.506Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "ABCD 2021-01-11T12.53.12.506Z", "format": "ABCD %Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "2025-12-31", "format": "%Y-%m-%d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "20-1-1", "format": "%Y-%m-%d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "Year 2025, Month 12, Day 31", "format": "Year %Y, Month %m, Day %d"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12.506Z"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); -- millisecond can be of min 1 and max 3 digits select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.5Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); -- millisecond of 2 digits select * from bson_dollar_project('{"dateString": "2021-01-11T12.53.12.50Z", "format": "%Y-%m-%dT%H.%M.%S.%LZ"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); -- iso date format select * from bson_dollar_project('{"dateString": "53.7.2017", "format": "%V.%u.%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); select * from bson_dollar_project('{"dateString": "1.1.1", "format": "%V.%u.%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); -- iso part only requires year select * from bson_dollar_project('{"dateString": "2017", "format": "%G"}','{"result": {"$dateFromString": {"dateString": "$dateString" , "format": "$format"} } }'); -- $dateFromString cases with onNull select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": "5"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": 1} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": {"$date": {"$numberLong": "1678924740500"} }} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "$missing", "onNull": "$missing"} } }'); -- only when dateString is nullish value, onNull is considered select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2018-02-06T11:56:02Z", "format": null, "onNull": 1} } }'); -- onNull with document cases select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": "5"}','{"result": {"$dateFromString": {"dateString": "$dateFromString", "format": "$format", "onNull": "$onNull"} } }'); select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": 1}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "onNull": "$onNull"} } }'); select * from bson_dollar_project('{"dateString": null, "format": "%Y-%m-%dT%H:%M:%S.%LZ", "onNull": {"$date": {"$numberLong": "1678924740500"} }}','{"result": {"$dateFromString": {"dateString": "$dateString", "format": "$format", "onNull": "$onNull"} } }'); -- $dateFromString cases with timezone select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "UTC"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "+01:00"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506Z", "format": "%Y-%m-%dT%H:%M:%S.%LZ", "timezone": "America/Denver"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506+130", "format": "%Y-%m-%dT%H:%M:%S.%L%Z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506-130", "format": "%Y-%m-%dT%H:%M:%S.%L%Z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Year is 2021 , Month is 12 and Day is @ 12 with minute offset +560", "format": "Year is %Y , Month is %m and Day is @ %d with minute offset %Z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506+0130", "format": "%Y-%m-%dT%H:%M:%S.%L%z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506-01:30", "format": "%Y-%m-%dT%H:%M:%S.%L%z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 UTC", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 MST", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2021-01-11T12:53:12.506 GMT-03:00", "format": "%Y-%m-%dT%H:%M:%S.%L %z"} } }'); -- $dateFromString invalid cases select * from bson_dollar_project('{}','{"result": {"$dateFromString": "a" } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": 1 } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": 5} } }'); select * FROM bson_dollar_project('{"dates": { "startDate": "2024-04-15", "endDate": "2024-05-14" }}','{ "result": { "$dateFromString": {"dateString": "$dates", "format": "%Y-%m-%d"}}}'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": 1} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 1002", "format": "%Y %j" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "Jenuery 1 2024", "format": "%B %d %Y" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "act 1 2024", "format": "%b %d %Y" } } }'); -- unkown argument in input select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2022-10-12", "format": " %Y-%m-%d", "unknown":1} } }'); -- passing timezone as input with existing timezone in string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 GMT+02:00", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 GMT", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07-12T22:23:55 +02:20", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); -- not enough data select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-07T22:23:55 GMT+02:00", "format": "%Y-%mT%H:%M:%S %z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017", "format": "%C"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ISO Week 1, 2018", "format": "ISO Week %V, %Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "12/31/2018", "format": "%m/%d\\0/%Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2017-12", "format": "%Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "ISO Day 6", "format": "ISO Day %V"} }}'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "12/31/2018", "format": "%m/%d/%G"} } }'); -- % format specifier test select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "% %Y-%m-%dT%H:%M:%S.%LZ"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "% 2021-01-11T12:53:12.506Z", "format": "%%Y-%m-%dT%H:%M:%S.%LZ"} } }'); -- $dateFromString cases with onError select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": 5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2022-10-12", "format": null } } }'); -- if dateString is not a string, onError should be considered select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": 5, "format": null } } }'); -- passing timezone as input with existing timezone in string select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07-12T22:23:55 GMT+02:00", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07-12T22:23:55 GMT", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled", "dateString": "2017-07-12T22:23:55 +02:20", "format": "%Y-%m-%dT%H:%M:%S %z", "timezone": "Europe/Paris"} } }'); -- not enough data select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-07T22:23:55 GMT+02:00", "format": "%Y-%mT%H:%M:%S %z"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "ISO Week 1, 2018", "format": "ISO Week %V, %Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "12/31/2018", "format": "%m/%d\\0/%Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "2017-12", "format": "%Y"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "ISO Day 6", "format": "ISO Day %V"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": "error handled","dateString": "12/31/2018", "format": "%m/%d/%G"} } }'); -- checking with changing onError return type select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": 5} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"onError": {"$date": {"$numberLong": "1678924740500"} },"dateString": "2022-10-12", "format": " %Y-%m-%d"} } }'); -- adding extra format specifiers select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 234 04:34:11", "format": "%Y %j %H:%M:%S" } } }'); -- exception test for value of dayOfyear is 999 select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "2024 999", "format": "%Y %j" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "year is 2024 and the days are 234 and time is 04:34:11", "format": "year is %Y and the days are %j and time is %H:%M:%S" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "dec 1 2024 04:34:11", "format": "%b %d %Y %H:%M:%S" } } }'); select * from bson_dollar_project('{}','{"result": {"$dateFromString": {"dateString": "janUary 1 2024 04:34:11", "format": "%B %d %Y %H:%M:%S" } } }'); -- Defensive check to prevent error from ms conversion to timestamptz SELECT * FROM bson_dollar_project('{}', '{"result": {"$dateToString": {"date":{"$toDate": {"$numberDouble": "-244058800000000"}}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$dateToString": {"date":{"$toDate": {"$numberDouble": "9664590969990000"}}}}}'); -- parse with preset formats select * from bson_dollar_project('{"dateString": "2021-01-11 11:00:03"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "2021-01-11T12:53:12"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "July 4th, 2017"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "July 4th, 2017 12:39:30 BST"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "July 4th, 2017 11am"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); select * from bson_dollar_project('{"dateString": "2017-Jul-04 noon"}','{"result": {"$dateFromString": {"dateString": "$dateString"} } }'); bson_aggregation_expression_variable_tests.sql000066400000000000000000000611671507310017400404030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4910000; SET documentdb.next_collection_id TO 4910; SET documentdb.next_collection_index_id TO 4910; -- $$ROOT as a variable. SELECT documentdb_api_catalog.bson_expression_get('{ "a": 1 }', '{ "c": "$$ROOT" }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.a" }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.a.b" }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": "$$ROOT.c" }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$isArray": "$$ROOT.a.b" } }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$isArray": "$$ROOT.a" } }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": [ 1, 2, 3 ] } }', '{ "c": { "$size": "$$ROOT.a.b" } }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": 2 } }', '{ "c": { "$eq": [ "$$ROOT.a.b", 2 ] } }'); SELECT documentdb_api_catalog.bson_expression_get('{ "a": { "b": 2 } }', '{ "c": { "$eq": [ "$$ROOT.a.b", 3 ] } }'); -- override $$CURRENT should change the meaning of path expressions since $a -> $$CURRENT.a SELECT * FROM bson_dollar_project('{"a": 1}', '{"b": {"$filter": {"input": [{"a": 10, "b": 8}, {"a": 7, "b": 8}], "as": "CURRENT", "cond": {"$and": [{"$gt": ["$a", 8]}, {"$gt": ["$b", 7]}]}}}}'); -- $reduce with multiple documents in a collection to ensure variable context is reset between every row evaluation SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 1, "a": ["a", "b", "c"]}'); SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 2, "a": ["d", "e", "f"]}'); SELECT documentdb_api.insert_one('db', 'remove_variable_tests', '{"_id": 3, "a": ["g", "h", "i"]}'); select bson_dollar_project(document, '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$value", "$$this"] } } } }') from documentdb_api.collection('db', 'remove_variable_tests'); -- $$REMOVE should not be written select bson_dollar_project('{}', '{"result": "$$REMOVE" }'); select bson_dollar_project(document, '{"result": [ "$a", "$$REMOVE", "final" ] }') from documentdb_api.collection('db', 'remove_variable_tests'); select bson_dollar_project(document, '{"result": { "$reduce": { "input": "$a", "initialValue": "", "in": { "$concat": ["$$REMOVE", "$$this"] } } } }') from documentdb_api.collection('db', 'remove_variable_tests'); -- $let aggregation operator -- verify that defined variables work SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": "$$foo"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"sum": {"$add": ["$a", 10]}}, "in": "$$sum"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"sumValue": {"$add": ["$a", 10]}}, "in": "$$sumValue"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$a"}, "in": "$$value"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$CURRENT"}, "in": "$$value"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$ROOT"}, "in": "$$value"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": "$$REMOVE"}, "in": "$$value"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"日本語": 10}, "in": "$$日本語"}}}'); -- verify nested let work and can also override variables SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo2": "$$foo"}, "in": {"a": "$$foo", "b": "$$foo2"}}}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "$$foo"}, "in": {"a": "$$foo"}}}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "this is a foo override"}, "in": {"a": "$$foo"}}}}}}'); SELECT * FROM bson_dollar_project('{ }', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo2": "$$foo"}, "in": {"$let": {"vars": {"foo3": "this is my foo3 variable"}, "in": {"foo": "$$foo", "foo2": "$$foo2", "foo3": "$$foo3"}}}}}}}}'); -- nested works with expressions that define variables SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$let": {"vars": {"value": "100"}, "in": {"$filter": {"input": "$input", "as": "value", "cond": {"$gte": ["$$value", 4]}}}}}}'); SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$let": {"vars": {"value": "100"}, "in": {"$filter": {"input": "$input", "as": "this", "cond": {"$gte": ["$$value", 4]}}}}}}'); SELECT * FROM bson_dollar_project('{ "input": [1, 2, 3, 4, 5]}', '{"result": {"$filter": {"input": "$input", "as": "value", "cond": {"$let": {"vars": {"value": 100}, "in": {"$gte": ["$$value", 4]}}}}}}'); -- override current SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"CURRENT": {"a": "this is a in new current"}}, "in": "$a"}}}'); -- use dotted paths on variable expressions SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": {"a": "value a field"}}, "in": "$$value.a"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": [{"a": "nested field in array"}]}, "in": "$$value.a"}}}'); SELECT * FROM bson_dollar_project('{ "a": 10}', '{"result": {"$let": {"vars": {"value": {"a": "value a field"}}, "in": "$$value.nonExistent"}}}'); -- test with multiple rows on a collection and a non constant spec such that caching is not in the picture to test we don't have memory corruption on the variable data itself SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 1, "name": "santi", "hobby": "running"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 2, "name": "joe", "hobby": "soccer"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 3, "name": "daniel", "hobby": "painting"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 4, "name": "lucas", "hobby": "music"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 5, "name": "richard", "hobby": "running"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 6, "name": "daniela", "hobby": "reading"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 7, "name": "isabella", "hobby": "video games"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 8, "name": "daniel II", "hobby": "board games"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 9, "name": "jose", "hobby": "music"}'); SELECT documentdb_api.insert_one('db', 'dollar_let_test', '{"_id": 10, "name": "camille", "hobby": "painting"}'); SELECT bson_dollar_project(document, FORMAT('{"result": {"$let": {"vars": {"intro": "%s", "hobby_text": " , and my hobby is: "}, "in": {"$concat": ["$$intro", "$name", "$$hobby_text", "$hobby"]}}}}', 'Hello my name is: ')::bson) FROM documentdb_api.collection('db', 'dollar_let_test'); -- negative cases SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": [1, 2, 3]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": true, "in": "a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {}}}}'); SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": {"$let": {"in": "$a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": [], "in": "$$123"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"123": "123 variable"}, "in": "$$123"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"ROOT": "new root"}, "in": "$$ROOT"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"REMOVE": "new remove"}, "in": "$$REMOVE"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"MyVariable": "MyVariable"}, "in": "$$MyVariable"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"_variable": "_variable"}, "in": "$$_variable"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"with space": "with space"}, "in": "$$with space"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"hello!": "with space"}, "in": "$$FOO"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$_variable"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$with spaces"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$hello!"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$FOO"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$.a"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"variable": "with space"}, "in": "$$variable."}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"a.b": "a.b"}, "in": "$$a.b"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$let": {"vars": {"foo": "this is my foo variable"}, "in": {"$let": {"vars": {"foo": "$$foo2"}, "in": {"a": "$$foo"}}}}}}'); -- $$NOW SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"1", "a": "umbor" }', NULL); SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"2", "a": "gabby" }', NULL); SELECT documentdb_api.insert_one('db','now_test_1','{"_id":"3", "a": "jo" }', NULL); -- $$NOW with dotted expression should evaluate to EOD SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$NOW.foo" }, "filter": {} }'); CREATE SCHEMA time_system_variables_test; -- Function to replace the value of $$NOW with NOW_SYS_VARIABLE CREATE OR REPLACE FUNCTION time_system_variables_test.mask_time_value(query text, out result text) RETURNS SETOF TEXT AS $$ BEGIN FOR result IN EXECUTE query LOOP RETURN QUERY SELECT REGEXP_REPLACE( result, '\{\s*"\$date"\s*:\s*\{\s*"\$numberLong"\s*:\s*"[0-9]+"\s*\}\s*\}', 'NOW_SYS_VARIABLE', 'g' ); END LOOP; RETURN; END; $$ LANGUAGE plpgsql; SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$NOW" }, "filter": {} }') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$NOW" } }') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "nowField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$NOW" } }') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": "$$NOW" } }') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": "$$NOW" } }') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ] }') $Q$); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "now_test_1", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ] }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_1", "projection": { "other": "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$NOW" ]} }, "let": { "varRef": "3" } }'); -- $$NOW in $lookup SELECT documentdb_api.insert_one('db','now_test_from','{"_id":1,"a":"alpha","b":["x","y"],"c":10,"d":["m","n"]}',NULL); SELECT documentdb_api.insert_one('db','now_test_from','{"_id":2,"a":"beta","b":["p","q"],"c":20,"d":["z"]}',NULL); SELECT documentdb_api.insert_one('db','now_test_to','{"_id":1,"x":"x","a":"alpha","c":10}',NULL); SELECT documentdb_api.insert_one('db','now_test_to','{"_id":2,"x":"p","a":"beta","y":"t","c":20}',NULL); SELECT documentdb_api.insert_one('db','now_test_to','{"_id":3,"x":"p","a":"beta","y":"z","c":30}',NULL); SELECT documentdb_api.insert_one('db','now_test_from_2','{"_id":1,"z":"val1","c":10}',NULL); SELECT documentdb_api.insert_one('db','now_test_from_2','{"_id":2,"z":"val2","c":20}',NULL); SELECT time_system_variables_test.mask_time_value($q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$match":{"$expr":{"$eq":["$c","$$c"]}}},{"$addFields":{"newC":"$$c","now":"$$NOW"}}],"as":"joined","localField":"a","foreignField":"a","let":{"c":"$c"}}}],"cursor":{}}') $q$); SELECT time_system_variables_test.mask_time_value($q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$sort":{"_id":1}},{"$match":{"$expr":{"$eq":["$c","$$NOW"]}}}],"as":"joined","localField":"a","foreignField":"a","let":{"c":"$c"}}}],"cursor":{}}') $q$); SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$addFields":{"extra":"$$NOW"}},{"$lookup":{"from":"now_test_from_2","localField":"z","foreignField":"c","as":"inner","let":{"v":"$c"},"pipeline":[{"$match":{"$expr":{"$eq":["$z","$$v"]}}}]}}],"as":"joined","localField":"a","foreignField":"a"}}],"cursor":{}}') $Q$); SELECT time_system_variables_test.mask_time_value($Q$ SELECT document FROM bson_aggregation_pipeline('db','{"aggregate":"now_test_to","pipeline":[{"$lookup":{"from":"now_test_from","pipeline":[{"$addFields":{"extra":"$$NOW"}},{"$lookup":{"from":"now_test_from_2","localField":"z","foreignField":"c","as":"inner","let":{"v":"$$NOW"},"pipeline":[{"$match":{"$expr":{"$eq":["$z","$$v"]}}}]}}],"as":"joined","localField":"a","foreignField":"a"}}],"cursor":{}}') $Q$); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate":"now_test_to", "pipeline":[{ "$match":{ "_id":3 }},{ "$addFields":{ "nowField1":"$$NOW" }},{ "$lookup":{ "from":"now_test_from", "pipeline":[{ "$addFields":{ "nowField2":"$$NOW" }},{ "$lookup":{ "from":"now_test_from_2", "localField":"z", "foreignField":"c", "as":"inner", "let":{ "v":"$c" }, "pipeline":[{ "$match":{ "$expr":{ "$eq":["$z","$$v"] }}}] }}], "as":"joined", "localField":"a", "foreignField":"a" }}], "cursor":{} }') \gset \set result0 :document SELECT :'result0'::json->>'nowField1' = :'result0'::json->'joined'->0->>'nowField2'; -- $$NOW in transactions. We expect same values. SELECT documentdb_api.insert_one('db','now_test_2','{"_id": 0}', NULL); BEGIN; SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result1 :document SELECT pg_sleep(2); SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result2 :document SELECT pg_sleep(2); SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result3 :document SELECT :'result1'::bson->>'nowField' = :'result2'::bson->>'nowField' AND :'result2'::bson->>'nowField' = :'result3'::bson->>'nowField'; END; -- $$NOW outside transaction block. We expect different values. SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result4 :document SELECT pg_sleep(2); SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result5 :document SELECT pg_sleep(2); SELECT document FROM bson_aggregation_find('db', '{ "find": "now_test_2", "projection": { "nowField" : "$$NOW" }, "filter": {} }') as document \gset \set result6 :document SELECT :'result4'::bson->>'nowField' <> :'result5'::bson->>'nowField' AND :'result5'::bson->>'nowField' <> :'result6'::bson->>'nowField'; -- Earlier queries should have higher $$NOW values SELECT :'result4'::bson->>'nowField' < :'result5'::bson->>'nowField' AND :'result5'::bson->>'nowField' < :'result6'::bson->>'nowField'; -- $$NOW with cursors CREATE TYPE time_system_variables_test.drain_result AS (filteredDoc bson, nowCompareResult bool, persistConnection bool); DO $$ DECLARE i int; BEGIN FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'now_cursor_tests', FORMAT('{ "_id": %s }', i)::documentdb_core.bson); END LOOP; END; $$; -- Drains a find query and compares the value of 'nowField' across all batches returned by the cursor. CREATE FUNCTION time_system_variables_test.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL) RETURNS SETOF time_system_variables_test.drain_result AS $$ DECLARE i int; doc bson; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; currentBatch jsonb[]; currentDoc jsonb; currentNowValue text; finalResult bool; BEGIN WITH r1 AS (SELECT 'now_cursor_tests' AS "find", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'now_cursor_tests' AS "collection", 4294967295::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967295); finalResult := TRUE; currentNowValue := ((doc->>'cursor')::bson->>'firstBatch')::jsonb->0->>'nowField'; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, persistConn)::time_system_variables_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); currentBatch := ( SELECT ARRAY( SELECT jsonb_array_elements( ((doc->>'cursor')::bson->>'nextBatch')::jsonb) ) ); IF currentBatch IS NOT NULL AND array_length(currentBatch, 1) > 0 THEN FOR i IN 1..array_length(currentBatch, 1) LOOP currentDoc := currentBatch[i]; finalResult := finalResult AND (currentNowValue = currentDoc->>'nowField'); currentNowValue := currentDoc->>'nowField'; END LOOP; END IF; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- Drains an aggregate query and compares the value of 'nowField' across all batches returned by the cursor. CREATE FUNCTION time_system_variables_test.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, singleBatch bool DEFAULT NULL) RETURNS SETOF time_system_variables_test.drain_result AS $$ DECLARE i int; doc bson; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; currentBatch jsonb[]; currentDoc jsonb; currentNowValue text; finalResult bool; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'now_cursor_tests' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'now_cursor_tests' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); finalResult := TRUE; currentNowValue := ((doc->>'cursor')::bson->>'firstBatch')::jsonb->0->>'nowField'; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); currentBatch := ( SELECT ARRAY( SELECT jsonb_array_elements( ((doc->>'cursor')::bson->>'nextBatch')::jsonb) ) ); IF currentBatch IS NOT NULL AND array_length(currentBatch, 1) > 0 THEN FOR i IN 1..array_length(currentBatch, 1) LOOP currentDoc := currentBatch[i]; finalResult := finalResult AND (currentNowValue = currentDoc->>'nowField'); currentNowValue := currentDoc->>'nowField'; END LOOP; END IF; SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson) INTO STRICT doc; RETURN NEXT ROW(doc, finalResult, FALSE)::time_system_variables_test.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; SELECT time_system_variables_test.mask_time_value($Q$ SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "now_cursor_tests", "pipeline": [ { "$addFields": { "nowField" : "$$NOW" }} ], "cursor": { "batchSize": 2 } }', 4294967294); $Q$); SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "nowField": "$$NOW" }'); SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1, "nowField": "$$NOW" }'); SELECT * FROM time_system_variables_test.drain_find_query(loopCount => 12, pageSize => 2, project => '{ "a": 1, "nowField": "$$NOW" }'); SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 12, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}'); SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}'); SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1, "nowField": "$$NOW" } }]}', singleBatch => TRUE); SELECT * FROM time_system_variables_test.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$project": { "nowField": "$$NOW" } }, { "$limit": 3 }]}'); bson_aggregation_file_cursor_tests.sql000066400000000000000000000520621507310017400366450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, public; SET citus.next_shard_id TO 3160000; SET documentdb.next_collection_id TO 3160; SET documentdb.next_collection_index_id TO 3160; SET citus.multi_shard_modify_mode TO 'sequential'; set documentdb.useFileBasedPersistedCursors to on; CREATE SCHEMA aggregation_cursor_test_file; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..10 LOOP PERFORM documentdb_api.insert_one('db', 'get_aggregation_cursor_test_file', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }', i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; CREATE TYPE aggregation_cursor_test_file.drain_result AS (filteredDoc bson, docSize int, continuationFiltered bson, persistConnection bool); CREATE FUNCTION aggregation_cursor_test_file.drain_find_query( loopCount int, pageSize int, project bson DEFAULT NULL, skipVal int4 DEFAULT NULL, limitVal int4 DEFAULT NULL, sort bson DEFAULT NULL, filter bson default null, obfuscate_id bool DEFAULT false) RETURNS SETOF aggregation_cursor_test_file.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; findSpec bson; getMoreSpec bson; BEGIN WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "find", filter AS "filter", sort AS "sort", project AS "projection", skipVal AS "skip", limitVal as "limit", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO findSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize") SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => findSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test_file.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test_file.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; CREATE FUNCTION aggregation_cursor_test_file.drain_aggregation_query( loopCount int, pageSize int, pipeline bson DEFAULT NULL, obfuscate_id bool DEFAULT false, singleBatch bool DEFAULT NULL) RETURNS SETOF aggregation_cursor_test_file.drain_result AS $$ DECLARE i int; doc bson; docSize int; cont bson; contProcessed bson; persistConn bool; aggregateSpec bson; getMoreSpec bson; BEGIN IF pipeline IS NULL THEN pipeline = '{ "": [] }'::bson; END IF; WITH r0 AS (SELECT pageSize AS "batchSize", singleBatch AS "singleBatch" ), r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "aggregate", pipeline AS "pipeline", row_get_bson(r0) AS "cursor" FROM r0) SELECT row_get_bson(r1) INTO aggregateSpec FROM r1; WITH r1 AS (SELECT 'get_aggregation_cursor_test_file' AS "collection", 4294967294::int8 AS "getMore", pageSize AS "batchSize" ) SELECT row_get_bson(r1) INTO getMoreSpec FROM r1; SELECT cursorPage, continuation, persistConnection INTO STRICT doc, cont, persistConn FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => aggregateSpec, cursorId => 4294967294); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, persistConn)::aggregation_cursor_test_file.drain_result; FOR i IN 1..loopCount LOOP SELECT cursorPage, continuation INTO STRICT doc, cont FROM documentdb_api.cursor_get_more(database => 'db', getMoreSpec => getMoreSpec, continuationSpec => cont); SELECT documentdb_api_catalog.bson_dollar_project(doc, ('{ "ok": 1, "cursor.id": 1, "cursor.ns": 1, "batchCount": { "$size": { "$ifNull": [ "$cursor.firstBatch", "$cursor.nextBatch" ] } }, ' || ' "ids": { "$ifNull": [ "$cursor.firstBatch._id", "$cursor.nextBatch._id" ] } }')::documentdb_core.bson), length(doc::bytea)::int INTO STRICT doc, docSize; IF obfuscate_id THEN SELECT documentdb_api_catalog.bson_dollar_add_fields(doc, '{ "ids.a": "1" }'::documentdb_core.bson) INTO STRICT doc; END IF; SELECT documentdb_api_catalog.bson_dollar_project(cont, '{ "continuation.value": 0 }'::documentdb_core.bson) INTO STRICT contProcessed; RETURN NEXT ROW(doc, docSize, contProcessed, FALSE)::aggregation_cursor_test_file.drain_result; END LOOP; END; $$ LANGUAGE plpgsql; -- PERSISTED BASED: -- test getting the first page (with max page size) - should limit to 2 docs at a time. SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 6, limitVal => 300000, pageSize => 100000); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 6, pageSize => 100000, pipeline => '{ "": [{ "$limit": 300000 }]}'); -- test smaller docs (500KB) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, limitVal => 300000, pageSize => 100000, project => '{ "a": 1 }'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); -- test smaller batch size(s) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 0, project => '{ "a": 1 }', limitVal => 300000); -- this will fail (with cursor in use) SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 12, pageSize => 1, project => '{ "a": 1 }', limitVal => 300000); SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967294::int8]); -- now this works SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 2, project => '{ "a": 1 }', limitVal => 300000); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 3, project => '{ "a": 1 }', limitVal => 300000); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 0, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967294::int8]); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 12, pageSize => 1, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$limit": 300000 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 3, pipeline => '{ "": [{ "$project": { "a": 1 } }, { "$skip": 1 }]}'); -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', limitVal => 300000); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', skipVal => 0, limitVal => 300000); -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 300000 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); BEGIN; SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }, { "$limit": 1 }, { "$addFields": { "c": "$a" }}]}'); ROLLBACK; -- With local execution off. set citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', limitVal => 300000); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); RESET citus.enable_local_execution; -- with sharded SELECT documentdb_api.shard_collection('db', 'get_aggregation_cursor_test_file', '{ "_id": "hashed" }', false); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 6, pageSize => 100000); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 6, pageSize => 100000); -- FIND: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} '); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); -- AGGREGATE: Test streaming vs not SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }'); -- With local execution off. set citus.enable_local_execution to off; SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, skipVal => 2, obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, filter => '{ "_id": { "$gt": 2 }} ', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 4, pageSize => 100000, limitVal => 3, obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 2, pageSize => 100000, limitVal => 1, obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 1, pageSize => 0, limitVal => 1, obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_find_query(loopCount => 5, pageSize => 100000, sort => '{ "_id": -1 }'); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$skip": 2 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$match": { "_id": { "$gt": 2 }} }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 4, pageSize => 100000, pipeline => '{ "": [{ "$limit": 3 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 2, pageSize => 100000, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 1, pageSize => 0, pipeline => '{ "": [{ "$limit": 1 }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 100000, pipeline => '{ "": [{ "$sort": { "_id": -1 } }]}', obfuscate_id => true); SELECT * FROM aggregation_cursor_test_file.drain_aggregation_query(loopCount => 5, pageSize => 2, pipeline => '{ "": [{ "$group": { "_id": "$_id", "c": { "$max": "$a" } } }] }', obfuscate_id => true); RESET citus.enable_local_execution; -- start draining first page first (should not persist connection and have a query file) SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%4294967291%' ORDER BY 1; -- can't reuse the same cursorId SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967291::int8]); SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%4294967291%' ORDER BY 1; SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967291); -- set max cursors to 5 set documentdb.maxCursorFileCount to 5; SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967292); SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967293); SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967294); SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967295); SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967296); -- delete a cursor and see that it succeeds one time. SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%429496729%' ORDER BY 1; SELECT documentdb_api_internal.delete_cursors(ARRAY[4294967295::int8]); SELECT * FROM pg_ls_dir('pg_documentdb_cursor_files') f WHERE f LIKE '%429496729%' ORDER BY 1; SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967295); SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page(database => 'db', commandSpec => '{ "find": "get_aggregation_cursor_test_file", "skip": 1, "batchSize": 2, "projection": { "_id": 1 } }', cursorId => 4294967298);bson_aggregation_miscellaneous_operators_tests.sql000066400000000000000000000023601507310017400412660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4900000; SET documentdb.next_collection_id TO 4900; SET documentdb.next_collection_index_id TO 4900; CREATE OR REPLACE FUNCTION generate_random_values(p_doc bson, p_rand_spec bson) RETURNS bool AS $$ DECLARE random_number numeric; BEGIN FOR cnt in 1..3000 LOOP SELECT (bson_expression_get(p_doc, p_rand_spec)->>'field')::float8 INTO random_number; IF random_number < 0 AND random_number >= 1 THEN RAISE NOTICE '$rand generated out of range double value'; RETURN false; END IF; END LOOP; RETURN true; END $$ LANGUAGE plpgsql; -- $rand error cases where the value of $rand non - object / non empty SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": 5 } }'); SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": false } }'); SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": [5] } }'); SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": {"value": 5} } }'); -- $rand valid empty params SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": {} } }'); SELECT generate_random_values('{"a": 1}', '{ "b" : { "$rand": [] } }'); bson_aggregation_object_operators_tests.sql000066400000000000000000000376331507310017400377040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 367000; SET documentdb.next_collection_id TO 3670; SET documentdb.next_collection_index_id TO 3670; -- -- $mergeObjects operator -- -- simple merge SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": {"a": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "1"}, {"b": true}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "1"}, {"b": true, "c": 2}]}}'); -- null and undefined return empty doc SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": "$undefinedField"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [null, null, null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [null, "$undefinedField", null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$mergeObjects": [{"a": "onlyDoc"}, "$undefinedField", null]}}'); -- with field expressions referencing parent doc SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }}', '{"result": { "$mergeObjects": "$b"}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c", "$b"]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c", "$d"]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": { "f": [true, "1"] }}, "c": {"foo": true}}', '{"result": { "$mergeObjects": ["$c.d", "$b.d"]}}'); -- last path found wins when there is a clash SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": false}}', '{"result": { "$mergeObjects": ["$b", "$c"]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": false}}', '{"result": { "$mergeObjects": ["$b", "$c", {"d": "this is my final string"}]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": { "z": false}}}', '{"result": { "$mergeObjects": ["$b", {"d": "this is my final string"}, "$c.d"]}}'); SELECT * FROM bson_dollar_project('{"a": "1", "b": { "d": [true, "1"] }, "c": {"d": { "z": false}}}', '{"result": { "$mergeObjects": [{"d": "this is my final string"}, "$b", "$c.d", {"hello": "world"}]}}'); -- nested expressions are evaluated on result document SELECT * FROM bson_dollar_project('{"_id": 4, "a": 1}', '{"result": { "$mergeObjects": [{"id": { "$add": ["$_id", "$a"]}}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"isArray": {"$isArray": "$a.b"}}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"b": [{"$literal": "$b"}]}]}}'); SELECT * FROM bson_dollar_project('{"a": {"b": ["1","2","3"]}}', '{"result": { "$mergeObjects": ["$a", {"b": [{"$literal": "$b"}, "$a"]}]}}'); -- -- expressions that evaluate to non objects are not valid SELECT * FROM bson_dollar_project('{"_id": 4, "a": 1}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); SELECT * FROM bson_dollar_project('{"_id": 4, "a": "string"}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); SELECT * FROM bson_dollar_project('{"_id": 4, "a": true}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); SELECT * FROM bson_dollar_project('{"_id": 4, "a": 2.0}', '{"result": { "$mergeObjects": [{"id": "$a"}, "$a"]}}'); SELECT * FROM bson_dollar_project('{"_id": 4, "a": 2.0}', '{"result": { "$mergeObjects": [{"$add": [1, 2, 3]}]}}'); -- $setField operator -- $setField should be given an Object no array SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": {"$setField": [ "field", "input", "value" ]}}}'); -- Extra param called thing gives an error SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "thing": "a", "field": "a", "input": "$$ROOT", "value": "newValue" } }]}}'); -- All required args -and- input param of field is a number SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": 123, "input": "$$ROOT", "value": "newValue" } }]}}'); -- All required args -and- input: $$ROOT SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "input": "$$ROOT", "value": "newValue" } }]}}'); -- Missing param input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "value": "newValue" } }]}}'); -- Missing param field SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "input": "$$ROOT", "value": "newValue" } }]}}'); -- Missing param value SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": { "field": "a", "input": "$$ROOT" } }]}}'); -- Wrong type for field, must be a string not null or bool SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [ { "$literal": "b"}, {"$setField": { "field": true, "value": "REMOVE" } }]}}'); SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [ { "$literal": "b"}, {"$setField": { "field": null, "value": "REMOVE" } }]}}'); -- The next item should add "$x.y.z" : "newValue" to the input doc {"a":"b"} SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "newValue" } }]}}'); -- Not yet implemented fully for $$REMOVE -- SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldA": [{"$setField": {"field": "a", "input": "$$ROOT", "value": "$$REMOVE" } }]}}'); -- here we test the "value" as magic value $$REMOVE as value, that should remove "baz" from the input, using $literal as means to give field name. Field not present SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); -- here we test the "value" as magic $$REMOVE as part of the value, that should not remove "baz" from the input, using $literal as means to give field name. Field not present SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "$x.y.z"}, "input": {"a":"b"}, "value": "no$$REMOVE" } }]}}'); -- here we test the "value" as magic $$REMOVE that should remove "baz" from the input, using $literal as means to give field name. Field *is* present. SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": {"$literal" : "baz"}, "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); -- here we test the "value" as magic $$REMOVE that should remove "baz" from the input. Same as prev test w/o using $literal operator. SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": "$$REMOVE" } }]}}'); -- here we test the "value" as a empty document SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": {} } }]}}'); -- here we test the "value" as a document with 1 item SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": { "x" : "y"} } }]}}'); -- Not yet implemented, fully for $$ROOT -- here we use $$ROOT in probably wrong "value" field, should pick up the record { "d1": {"val": "a"}} as the value of the new field SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": {"a":"b"}, "value": "$$ROOT" } }]}}'); -- here we use $$ROOT that pickups the { "d1": {"val": "a"}} and should add "baz" : "foooooo" SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": "$$ROOT", "value": "foooooo" } }]}}'); -- Check that we can use dot path like $$ROOT.d1: SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": "$$ROOT.d1", "value": "foooooo" } }]}}'); -- Check that we can use dot path like $$REMOVE in a non $setField context SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$concat": "$$REMOVE" } ]}}'); -- Inject a null as "input", via "input" SELECT * FROM bson_dollar_project('{ "d1": {"val": "a"}}', '{"result": { "fieldA": [{"$setField": { "field": "baz", "input": null, "value": "foooooo" } }]}}'); -- insert where we overwrite the tail. SELECT * FROM bson_dollar_project('{"a1": { "b": 1, "c": 1, "d": 1 }, "b1": { "d": 2, "e": 3 } }', '{"result": { "$mergeObjects": [ "$a1", "$b1" ]}}'); -- testing multiple scenarios with $$REMOVE to check all work properly SELECT * FROM bson_dollar_project('{"a": 1}', '{ "result": { "$bsonSize": "$$REMOVE" } }'); SELECT * FROM bson_dollar_project('{"a": 1}', '{ "result": { "$bsonSize": { "a": 1, "test": "$$REMOVE" } } }'); SELECT * FROM bson_dollar_project('{ "_id": 16, "group": 2, "obj": { "a": 1, "b": 1 } }', '{ "mergedDocument": { "$mergeObjects": ["$obj", { "b": "$$REMOVE" } ] } }'); -- $getField operator SELECT insert_one('db','test_get_field',' { "_id": 0, "a": 1, "b": "test" }'); -- positive cases -- entire expression -- field parsed from $literal SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "a" }, "input": {"a": { "b": 3 }}}}}}'); -- field parsed from expression SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "a" }, "input": {"a": { "b": 3 }}}}}}'); -- field is a path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "test_get_field", "pipeline": [{"$project": {"result": {"fieldValue": {"$getField": {"field": "$b", "input": {"test": { "b": 3 }}}}}}}]}'); -- input be a system variable SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "a", "input": "$$ROOT"}}}}'); -- input be null SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "a", "input": null}}}}'); -- input be a path SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); -- input be a missing path SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$adf"}}}}'); -- input be constant SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "dx"}}}}'); -- get array field value SELECT * FROM bson_dollar_project('{"a": { "b": ["1"] }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); -- get document field value SELECT * FROM bson_dollar_project('{"a": { "b": {"c": "1"} }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": "$a"}}}}'); -- field name contains $ and . SELECT * FROM bson_dollar_project('{"a": { "b": {"c": "nested text"}, "b.c": "plain text" }}', '{"result": { "fieldValue": {"$getField": {"field": "b.c", "input": "$a"}}}}'); SELECT * FROM bson_dollar_project('{"a": { "$b.01": {"c": "1"} }}', '{"result": { "fieldValue": {"$getField": {"field": { "$literal": "$b.01" }, "input": "$a"}}}}'); -- nested expression SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": {"field": "b", "input": { "$getField": "a" }}}}}'); -- test pipeline SELECT documentdb_api.insert_one('db','getfield','{"_id":"1", "a": null }', NULL); SELECT documentdb_api.insert_one('db','getfield','{"_id":"2", "a": { "b": 1 } }', NULL); SELECT documentdb_api.insert_one('db','getfield','{"_id":"3"}', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "getfield", "pipeline": [ { "$project": { "fieldValue": { "$getField": { "field": "b", "input": "$a" }}}}], "cursor": {} }'); -- shorthand expression -- input will be $$CURRENT SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": "a"}}}'); SELECT * FROM bson_dollar_project('{"a": { "b": 3 }}', '{"result": { "fieldValue": {"$getField": "b"}}}'); -- negative cases -- full expression -- field is required SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"input": {}}}}}'); -- input is required SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": "a"}}}}'); -- field must be a string SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": null, "input": {}}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": 1, "input": {}}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": {"field": [], "input": {}}}}}'); -- shorthand expression -- field must be a string SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$getField": []}}}'); -- $unsetField -- postive cases -- null input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": null}}}}'); -- empty input SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {}}}}}'); -- remove from input argument not current document SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {"a": 1, "b": 2}}}}}'); -- won't traverse objects automatically with dotted field SELECT * FROM bson_dollar_project('{"a": {"b": 1}, "a.b": 2}', '{"result": { "fieldValue": {"$unsetField": {"field": "a.b", "input": "$$ROOT"}}}}'); -- field name starts with $ SELECT * FROM bson_dollar_project('{"$a": 1, "b": 2}', '{"result": { "fieldValue": {"$unsetField": {"field": { "$const": "$a" }, "input": "$$ROOT"}}}}'); -- take specific path from current document SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}}', '{"result": { "fieldValue": {"$unsetField": {"field": "b", "input": "$a"}}}}'); -- cooperate with getField SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}}', '{"result": { "fieldValue": {"$unsetField": {"field": "b", "input": {"$getField": "a"}}}}}'); -- unset an array SELECT * FROM bson_dollar_project('{"a": {"b": 1, "c": 2}, "d": [2, 3]}', '{"result": { "fieldValue": {"$unsetField": {"field": "d", "input": "$$ROOT"}}}}'); -- negative cases SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": 1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a"}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": null, "value": 1}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": {"$add": [2, 3]}, "input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "$a", "input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": 5, "input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": ["a"], "input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": null, "input": null}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": 3}}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "fieldValue": {"$unsetField": {"field": "a", "input": {"$add": [2, 3]}}}}}'); bson_aggregation_pg17_tests_lookup_inner_join.sql000066400000000000000000000002731507310017400407070ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 9437000; SET documentdb.next_collection_id TO 94370; SET documentdb.next_collection_index_id TO 94370; \i sql/bson_aggregation_tests_lookup_inner_join_core.sqlbson_aggregation_pipeline_operator_expMovingAvg.sql000066400000000000000000000204701507310017400413170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4156000; SET documentdb.next_collection_id TO 41560; SET documentdb.next_collection_index_id TO 41560; -- insert data -- positive case SELECT documentdb_api.insert_one('db','test1','{ "_id": 1, "name": "p1", "cost": 20, "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 2, "name": "p1", "cost": 22.4, "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 4, "name": "p1", "cost": 18.7, "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 5, "name": "p2", "cost": 89, "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 6, "name": "p2", "cost": 101, "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test1','{ "_id": 8, "name": "p2", "cost": 104.3, "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); -- N is long SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 12345678901234} } } } } ] }'); -- negative case -- no sortBy SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); -- alpha and N all exist SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666, "N": 2} } } } } ] }'); -- miss input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"alpha": 0.666, "N": 2} } } } } ] }'); -- miss alpha and N SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost"} } } } } ] }'); -- incorrect parameter SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpah": 0.666} } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "M": 2} } } } } ] }'); -- N is float SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2.3} } } } } ] }'); -- alpha >= 1 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 2} } } } } ] }'); -- alpha <= 0 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test1", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": -2.8} } } } } ] }'); -- data contains null SELECT documentdb_api.insert_one('db','test2','{ "_id": 1, "name": "p1", "cost": 20, "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 2, "name": "p1", "cost": null, "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 4, "name": "p1", "cost": 18.7, "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 5, "name": "p2", "cost": null, "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 6, "name": "p2", "cost": 101, "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test2','{ "_id": 8, "name": "p2", "cost": 104.3, "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test2", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test2", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); -- input contains string SELECT documentdb_api.insert_one('db','test3','{ "_id": 1, "name": "p1", "cost": "asd", "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 2, "name": "p1", "cost": 22.4, "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 3, "name": "p1", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 4, "name": "p1", "cost": "zxc", "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 5, "name": "p2", "cost": 89, "date": { "$date": { "$numberLong": "1718841600001"}}}'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 6, "name": "p2", "cost": "qwe", "date": { "$date": { "$numberLong": "1718841600002" } } }'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 7, "name": "p2", "cost": 119, "date": { "$date": { "$numberLong": "1718841600003" } } }'); SELECT documentdb_api.insert_one('db','test3','{ "_id": 8, "name": "p2", "cost": "vbn", "date": { "$date": { "$numberLong": "1718841600004"}} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test3", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "N": 2} } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "test3", "pipeline": [ { "$setWindowFields": { "partitionBy": "$name", "sortBy": {"date": 1}, "output":{"expMovingAvgForCost": { "$expMovingAvg":{"input": "$cost", "alpha": 0.666} } } } } ] }'); bson_aggregation_pipeline_operator_linearFill.sql000066400000000000000000001104611507310017400407660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 466000; SET documentdb.next_collection_id TO 4660; SET documentdb.next_collection_index_id TO 4660; ---------------------------- -- Prepare data ---------------------------- SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "p3", "cost": 2, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); ---------------------------- -- positive case ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$linearFill": "$quantity"}, "quantity2": { "$linearFill": "$quantity"}}}}]}'); ----------------------------------------------- -- positive case with different sort key value ----------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 501 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 501 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": -10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "501" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 1, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "501" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 2, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 9, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 10, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 510 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 11, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 12, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 19, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 0, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 520 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ---------------------------- -- positive corner case ---------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}} , "quantity": null }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); --------------------------------------------- -- positive case with Infinity and -Infinity --------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": 500 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": -Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": 500 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "a1", "b": "b1", "cost": 5, "date": { "$date": { "$numberLong": "1"}}, "quantity": -Infinity }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "a1", "b": "b2", "cost": 8, "date": { "$date": { "$numberLong": "2"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "a1", "b": "b1", "cost": 8, "date": { "$date": { "$numberLong": "3"}}, "quantity": -Infinity }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); -------------------------------------------- -- positive case to test manual window trim -------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006"}}, "quantity": 600 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600009"}}, "quantity": 700 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ---------------------------------------------- -- positive case with different numeric types ---------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); ----------------------------------- -- positive corner case with sortBy ----------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); --------------------- -- negative case --------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); -- without sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); -- sortBy is not numeric or date SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); -- mixed numeric and date type in sortBy SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "1", "cost": 5, "date": 1, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "2", "cost": 8, "date": 2, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); -- sortBy with repeated value in one partition SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": 0}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 9, "val": 9}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "test": 10, "val": 10}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "test": 10, "val": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "test": 11, "val": 11}', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); -- fill non-numeric field SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity"}}}}]}'); -- window fields existed in the input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$linearFill": "$quantity", "window":{ "documents": ["unbounded", "unbounded"]}}}}}]}'); ------------------------ -- Infinity result test ------------------------ SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": { "$numberDecimal": "-9.999999999999999999999999999999999E+6144" }}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 2, "val": { "$numberDecimal": "9.999999999999999999999999999999999E+6144" }}', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "test": 0, "val": { "$numberDecimal": "9.999999999999999999999999999999999E+6144" }}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "test": 1, "val": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "test": 2, "val": { "$numberDecimal": "-9.999999999999999999999999999999999E+6144" }}', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "test": 1 }, "output": {"val": { "$linearFill": "$val"}}}}]}'); bson_aggregation_pipeline_operator_locf.sql000066400000000000000000000441171507310017400376340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 475000; SET documentdb.next_collection_id TO 4750; SET documentdb.next_collection_index_id TO 4750; ---------------------------- -- Prepare data ---------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "p3", "cost": 2, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 12, "a": "p4", "cost": 2, "date": { "$date": { "$numberLong": "1718841600031"} }, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 13, "a": "p4", "cost": 8, "date": { "$date": { "$numberLong": "1718841605032" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 14, "a": "p4", "cost": 8, "date": { "$date": { "$numberLong": "1718841606033" } } }', NULL); ---------------------------- -- positive case ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a","output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "$locf": "$quantity"}, "quantity2": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"output": {"quantity": { "$locf": "$quantity"}}}}]}'); ---------------------------- -- positive corner case ---------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); ---------------------------------------------- -- positive case with different types ---------------------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600000"}}, "quantity": "string501" }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": "string501" }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": "string501" }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": 600}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": -1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); -- fill non-numeric field SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); ----------------------------------- -- positive corner case with sortBy ----------------------------------- SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); -- sortBy is not numeric or date SELECT documentdb_api.drop_collection('db','setWindowFields'); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); -- without sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"quantity": { "$locf": "$quantity"}}}}]}'); -- sortBy with repeated value in one partition SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity"}}}}]}'); --------------------- -- negative case --------------------- -- window fields existed in the input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "$locf": "$quantity", "window":{ "documents": ["unbounded", "unbounded"]}}}}}]}'); bson_aggregation_pipeline_stage_densify.sql000066400000000000000000000433241507310017400376210ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 477000; SET documentdb.next_collection_id TO 4770; SET documentdb.next_collection_index_id TO 4770; SELECT insert_one('db','densify','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 2, "a": "abc", "cost": 5, "quantity": 507, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 3, "a": "abc", "cost": 3, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 4, "a": "abc", "cost": 7, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 11, "a": "def", "cost": 16, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 12, "a": "def", "cost": 11, "quantity": 507, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 13, "a": "def", "cost": -5, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SELECT insert_one('db','densify','{ "_id": 14, "a": "def", "cost": 9, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); -- Validations of $densify stage and negative test cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": "Not an object" }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": [ ] }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": 1 } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a" } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": "A" } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "na" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "full" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "partition" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1] } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2, 3] } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, { "$date": { "$numberLong": "1718841600000" } }] } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "full", "step": "Hello" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : "partition", "step": "Hello" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, {"$numberDouble": 2}], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": {"$numberDecimal": "1"} } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 1, "unit": "sec" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 1, "unit": "Hour" } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": -1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": 0 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [1, 2], "step": {"$numberDecimal": "-1e1000"} } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "range": { "bounds" : [2, 1], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "partitionByFields": "a", "range": { "bounds" : "full", "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "a", "partitionByFields": ["$a"], "range": { "bounds" : "full", "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "$a", "partitionByFields": ["a"], "range": { "bounds" : "full", "step": 1 } } }]}'); -- Valid cases that works -- Check an empty table returns value when used with range based partition SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "empty_table", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [1, 10], "step": 1 } } }]}'); -- Range with lower and upper bounds SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1.2 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [-10, -5], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [11, 15], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [3, 10], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": [{ "$date" : { "$numberLong" : "1718841610000" } }, { "$date" : { "$numberLong" : "1718841615000" } }], "step": 1, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}') -- Partition mode SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 3, "unit": "second" } } }, {"$project": { "formatted": { "$dateToString": { "date": "$date" } }}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": { "$numberDecimal": "1.5"} } } }]}'); -- Full mode SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1, "unit": "second" } } }, {"$project": { "a": 1, "formatted": { "$dateToString": { "date": "$date" } }}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 3, "unit": "second" } } }, {"$project": { "a": 1, "formatted": { "$dateToString": { "date": "$date" } }}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": { "$numberDecimal": "1.5"} } } }]}'); -- Explains EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "empty_table", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [1, 10], "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Shard collection SELECT documentdb_api.shard_collection('db', 'densify', '{"a": "hashed"}', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }, {"$sort": { "a": 1, "cost": 1}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Reshard multikey SELECT documentdb_api.shard_collection('db', 'densify', '{"a": "hashed", "quantity": "hashed"}', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "partition", "step": 1 } } }, {"$sort": { "a": 1, "quantity": 1, "cost": 1}}]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "full", "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": [8, 12], "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "partition", "step": 1 } } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a", "quantity"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Test that internal number of documents generated limits are working -- Tests inspired from aggregation/sources/densify/generated_limit.js, currently we don't support setParameter so only a unit test should be suffice to test internal limits SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 10; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 11], "step": 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 45], "step": 4 } } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 10], "step": 4 } } }]}'); -- should pass SELECT insert_one('db','densify_limit','{ "_id": 1, "a": "abc", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify_limit','{ "_id": 2, "a": "abc", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); SELECT insert_one('db','densify_limit','{ "_id": 3, "a": "def", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify_limit','{ "_id": 4, "a": "def", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); -- Test limit works across partitions SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 20; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Verify existing documents don't count towards the limit SELECT insert_one('db','densify_limit','{ "_id": 5, "a": "abc", "cost": 5, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify_limit','{ "_id": 6, "a": "def", "cost": 5, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": "full", "step": 1 } } }]}'); -- Should pass now -- Check time also works SELECT drop_collection('db', 'densify_limit') IS NOT NULL; SELECT insert_one('db','densify_limit','{ "_id": 1, "a": "abc", "cost": 0, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT insert_one('db','densify_limit','{ "_id": 2, "a": "abc", "cost": 12, "quantity": 501, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SET documentdb.test.internalQueryMaxAllowedDensifyDocs TO 5; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "date", "partitionByFields": ["a"], "range": { "bounds": "partition", "step": 1 , "unit": "second"} } }]}'); RESET documentdb.test.internalQueryMaxAllowedDensifyDocs; -- Test memory limit too SET documentdb.test.internaldocumentsourcedensifymaxmemorybytes TO 100; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "densify_limit", "pipeline": [{"$densify": { "field": "cost", "partitionByFields": ["a"], "range": { "bounds": [0, 40], "step": 1 } } }]}'); RESET documentdb.test.internalDocumentSourceDensifyMaxmemoryBytes; SHOW documentdb.test.internalQueryMaxAllowedDensifyDocs; SHOW documentdb.test.internalDocumentSourceDensifyMaxmemoryBytes;bson_aggregation_pipeline_stage_fill.sql000066400000000000000000000513711507310017400371070ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 468000; SET documentdb.next_collection_id TO 4680; SET documentdb.next_collection_index_id TO 4680; ---------------------------- -- Prepare data ---------------------------- SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "p2", "cost": 3, "date": { "$date": { "$numberLong": "1718841600011" } }, "quantity": 1 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } }, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "p2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "p2", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"} }, "quantity": 4 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 11, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600021"} }, "quantity": 100 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 10, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841605022" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 9, "a": "p3", "cost": 8, "date": { "$date": { "$numberLong": "1718841606023" } } }', NULL); ---------------------------- -- positive case ---------------------------- SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "method": "locf"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "value": 123}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "value": 567}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "_id": 1 },"output": {"quantity": { "value": "test"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": -1 },"output": {"quantity": { "value": {"$numberDecimal": "123"}}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "value": 123}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a", "cost"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); ---------------------------- -- positive corner case ---------------------------- SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": null }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "locf"}}}}]}'); SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc1", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc2", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc3", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc4", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); -------------------------------------------- -- positive case to test manual window trim -------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600005"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600006"}}, "quantity": 600 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600007"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600008"}}, "quantity": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 9, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600009"}}, "quantity": 700 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["a"], "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); ---------------------------------------------- -- positive case with different numeric types ---------------------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberLong": "500" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600011"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 6, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600012" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 7, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600013" } } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 8, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600014"}} , "quantity": { "$numberDouble": "503" } }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 },"output": {"quantity": { "method": "linear"}}}}]}'); SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": { "$numberDecimal": "500" } }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": { "$numberInt": "501" }}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); ----------------------------------- -- positive corner case with sortBy ----------------------------------- SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "def", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "def", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); --------------------- -- negative case --------------------- SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); -- without sortBy field SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "output": {"quantity": { "method": "linear"}}}}]}'); -- sortBy is not numeric or date SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "a": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); -- sortBy with repeated value in one partition SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "cost": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); -- partionBy and partitionByFields both are present SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "partitionByFields": ["a"], "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); -- partitionByFields element starts with $ SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionByFields": ["$a"], "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); -- output field is not present in the document SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }}}]}'); -- fill non-numeric field SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": "503" }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": "abc", "cost": 5, "date": { "$date": { "$numberLong": "1718841600001"}}, "quantity": 500 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600002"}}, "quantity": null}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": "abc", "cost": 8, "date": { "$date": { "$numberLong": "1718841600003"}}}', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600004"}} , "quantity": 503 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": "abc", "cost": 4, "date": { "$date": { "$numberLong": "1718841600005"}} , "quantity": "503" }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"quantity": { "method": "linear"}}}}]}'); -- fill with missing value SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": 1, "c": 5 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": 2, "c": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": 3 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4 }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"output": {"c": { "value": "$a"}}}}]}'); -- fill with mixed types SELECT documentdb_api.drop_collection('db','filltest'); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 1, "a": 1, "b": 1, "c": 5 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 2, "a": 2, "b": null, "c": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 3, "a": 3, "b": 3 }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 4, "a": 4, "b": null }', NULL); SELECT documentdb_api.insert_one('db','filltest','{ "_id": 5, "a": 5, "b": 5, "c": null }', NULL); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "linear" } ,"c": { "value": "$a" }}}}]}'); SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "locf" } ,"c": { "value": "$a" }}}}]}'); -- fill with multi methods SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "locf", "method": "linear" }}}}]}'); -- explain plan validation EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "method": "linear" }}}}]}'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "b": { "value": 1 }}}}]}'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db','{ "aggregate": "filltest", "pipeline": [{"$fill": {"sortBy": {"a" : 1}, "output": { "c": { "method": "linear" }, "b": { "value": 1 }}}}]}'); bson_aggregation_pipeline_stage_setWindowFields.sql000066400000000000000000006026671507310017400413050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 455000; SET documentdb.next_collection_id TO 4550; SET documentdb.next_collection_index_id TO 4550; SELECT 1 from documentdb_api.drop_collection('db','setWindowFields'); -- Add error and validation tests for setWindowFields stage SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 4, "a": "abc", "cost": 10, "quantity": 504, "date": { "$date": { "$numberLong": "1718841615000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 5, "a": "def", "cost": 8, "quantity": 505, "date": { "$date": { "$numberLong": "1718841620000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 6, "a": "ghi", "cost": 4, "quantity": 506, "date": { "$date": { "$numberLong": "1718841630000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 7, "a": "abc", "cost": 10, "quantity": 507, "date": { "$date": { "$numberLong": "1718841640000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 8, "a": "def", "cost": 8, "quantity": 508, "date": { "$date": { "$numberLong": "1718841680000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 9, "a": "ghi", "cost": 4, "quantity": 509, "date": { "$date": { "$numberLong": "1718841700000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 10, "a": "abc", "cost": 10, "quantity": 510, "date": { "$date": { "$numberLong": "1718841800000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 11, "a": "def", "cost": 8, "quantity": 511, "date": { "$date": { "$numberLong": "1718841900000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 12, "a": "ghi", "cost": 4, "quantity": 512, "date": { "$date": { "$numberLong": "1718842600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields','{ "_id": 13, "a": "abc", "cost": 80, "quantity": 515, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 1, "a": "abc", "cost": 80, "quantity": 515, "date": 1 }', NULL); -- date type mismatch SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 2, "a": "abc", "cost": 80, "quantity": 515 }', NULL); -- date is missing SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 3, "a": "abc", "cost": "80", "quantity": 515 }', NULL); -- cost type mismatch SELECT documentdb_api.insert_one('db','setWindowFields_invalidtypes','{ "_id": 4, "a": "abc", "quantity": 515 }', NULL); -- cost is missing -- Validations of $setWindowFields stage and negative test cases SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": "Not an object" }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "partitionBy": 1, "sortBy": {"a": 1} } }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "unknownField": {} } }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": [1] } }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": { "$concatArrays": [[1], [2]] }}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": 1, "sortBy": { "a" : "asc" }}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$sum": 1} }, "partitionBy": 1, "sortBy": "Not an Object"}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": "Not an object" }}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total": {"$unknownOperator": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "$total": {"$sum": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "": {"$unknownOperator": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1}, "total2": "Not an object" }}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": "Not an object"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "unknownBound": [1, 2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "": [1, 2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": "not an array" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": { "a": 1, "b": 2 } }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current", "current"], "unknownBound": [1, 2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["current", "current"], "unknownBound": [1, 2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current", "current"], "unit": "second" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [-1 , 1] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , 1] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , "current"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["current" , "unbounded"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["unbounded" , 1] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [-1 , "unbounded"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": ["" , ""] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1, "b": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": -1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["unbounded" , "unbounded"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, 2, 3] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, "text"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, {"a": 1}] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "documents": [1, -1] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": [1, "current"] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "output": { "total1": {"$sum": 1 , "window": { "range": ["current", -2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2] }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "day" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "days" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": { "sortBy": {"a": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "Day" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": {"_id": 1 }}, {"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 2 }}, {"$setWindowFields": { "sortBy": {"date": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 3 }}, {"$setWindowFields": { "sortBy": {"cost": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$match": { "_id": 4 }}, {"$setWindowFields": { "sortBy": {"cost": 1}, "output": { "total1": {"$sum": 1 , "window": { "range": ["current", 2]}}}}}]}'); -- Common Positive tests for $setWindowFields stage and explains SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"output": {"total": { "$sum": 1}}}}]}'); -- No partitionBy or sortBy SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"sortBy": {"a": 1, "quantity": -1}, "output": {"total": { "$sum": 1}}}}]}'); -- No partitionBy -- [Optimization] Partition by on same shard key pushes the $setWindowFields stage to the shard SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_sharded','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SELECT documentdb_api.shard_collection('db', 'setWindowFields_sharded', '{"a": "hashed"}', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$cost", "output": {"total": { "$sum": 1}}}}, {"$sort": { "a": 1, "_id": 1 }}]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$cost", "output": {"total": { "$sum": 1}}}}]}'); -- different partitionby, not pushed to shards SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}, { "$sort" : {"a" : 1, "_id" : 1}}]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); -- same partitioBy as shardkey, pushed to shards SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$match": {"a": "def"}}, {"$setWindowFields": { "output": {"total": { "$sum": 1}}}}]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$match": {"a": "def"}}, {"$setWindowFields": { "output": {"total": { "$sum": 1}}}}]}'); -- target a single shard with $match, pushed to shard -- Push to shard doesn't work when there is multi key shard key SELECT documentdb_api.shard_collection('db', 'setWindowFields_sharded', '{"a": "hashed", "b": "hashed"}', true); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": { "partitionBy": "$a", "output": {"total": { "$sum": 1}}}}]}'); -- same partitioBy as first key in shardkey, not pushed to shards ----------------------------------------------------------- -- $sum accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$sum": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$sum": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$sum": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$sum": 1, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); ----------------------------------------------------------- -- $count accumulator tests ----------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [0, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": [-10, 10]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", -1]}}}}}]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); -- Should error since $count take no argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": "str"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": true }}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": {"fst": 1} }}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"countInGroup": { "$count": [1, "$a"] }}}}]}'); -- test on shard collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalCount": { "$count": {}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"countInGroup": { "$count": {}, "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); -- test on shard collection with range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-0.5, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-1, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_sharded", "pipeline": [{"$setWindowFields": {"sortBy": {"quantity": 1}, "output": {"totalCount": { "$count": {}, "window": {"range": [-1, 1]}}}}}]}'); ----------------------------------------------------------- -- $avg accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$avg": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$avg": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$avg": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$avg": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); ----------------------------------------------------------- -- $push accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$push": "$$varRef", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "let": {"varRef": "Hello"}}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$push": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$match": {"quantity": {"$type": "number"}}}, {"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$push": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$push": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); --------------------- -- Missing Field Test --------------------- SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 1, "a": "abc", "quantity": 30, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 2, "a": "abc", "quantity": [], "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 3, "a": "abc", "quantity": {}, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 4, "a": "abc", "quantity": null, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 5, "a": "abc", "quantity": { "$undefined": true }, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_push_missingFields','{ "_id": 6, "a": "abc", "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); -- Should push every quantity except a NULL from _id: 6 document where quantity is missing SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": { "qty": "$quantity" }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": [ "$quantity" ], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_push_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$push": "$non_existing" } } } } ]}'); ----------------------------------------------------------- -- $addToSet accumulator tests ----------------------------------------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": 1}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": [1]}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": []}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "{}", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": {}}}}}]}'); ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"addedSet": { "$addToSet": ["$$varRef1", "$$varRef2"], "window": {"documents": ["unbounded", "unbounded"]}}}}}], "let": {"varRef1": "Hello", "varRef2": "World"}}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"addedSet": { "$addToSet": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$match": {"quantity": {"$type": "number"}}}, {"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$addToSet": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$addToSet": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); --------------------- -- Missing Field Test --------------------- SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 1, "a": "abc", "quantity": 30, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 2, "a": "abc", "quantity": [], "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 3, "a": "abc", "quantity": {}, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 4, "a": "abc", "quantity": null, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 5, "a": "abc", "quantity": { "$undefined": true }, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','setWindowFields_addToSet_missingFields','{ "_id": 6, "a": "abc", "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); -- Should addToSet every quantity except a NULL from _id: 6 document where quantity is missing SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": { "qty": "$quantity" }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": [ "$quantity" ], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_addToSet_missingFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"addedSet": { "$addToSet": "$non_existing" } } } } ]}'); ----------------------------------------------------------- -- $covariancePop & $covarianceSamp accumulator tests ----------------------------------------------------------- -- empty collection SELECT documentdb_api.insert_one('db','empty_covar_col',' { "_id": 0, "x": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_covar_col", "pipeline": [{"$setWindowFields": {"output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_covar_col", "pipeline": [{"$setWindowFields": {"output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); -- collection with single document SELECT documentdb_api.insert_one('db','single_col',' { "_id": 0, "x": 1, "y": 2 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_col", "pipeline": [{"$setWindowFields": {"output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_col", "pipeline": [{"$setWindowFields": {"output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); -- document with non-numeric values SELECT documentdb_api.insert_one('db','non_numeric_col',' { "_id": 0, "x": "a", "y": "b" }'); SELECT documentdb_api.insert_one('db','non_numeric_col',' { "_id": 1, "x": "c", "y": "d" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with mixed values SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 0, "x": 1, "y": "a" }'); SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 1, "x": 2, "y": 0 }'); SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 2, "x": 3, "y": "b" }'); SELECT documentdb_api.insert_one('db','mixed_col',' { "_id": 3, "x": 4, "y": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with NAN values SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 0, "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 1, "x": 2, "y": 3 }'); SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "NaN" } }'); SELECT documentdb_api.insert_one('db','nan_col',' { "_id": 3, "x": 4, "y": 4 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with Infinity values SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 0, "type": "a", "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 1, "type": "a", "x": 2, "y": {"$numberDecimal": "Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 2, "type": "a", "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 3, "type": "a", "x": 4, "y": 4 }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 5, "type": "b", "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 6, "type": "b", "x": 2, "y": 3 }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 7, "type": "b", "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col',' { "_id": 8, "type": "b", "x": 4, "y": {"$numberDecimal": "Infinity" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with Decimal128 values SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 0, "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 1, "x": 2, "y": 3 }'); SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "4.0" } }'); SELECT documentdb_api.insert_one('db','decimal_col',' { "_id": 3, "x": 4, "y": 5 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- number overflow SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 0, "x": 1, "y": {"$numberDecimal": "100000004"} }'); SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 1, "x": 2, "y": {"$numberDecimal": "10000000007"} }'); SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "1000000000000013"} }'); SELECT documentdb_api.insert_one('db','overflow_col',' { "_id": 3, "x": 4, "y": {"$numberDecimal": "1000000000000000000"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- long values return double SELECT documentdb_api.insert_one('db','long_col',' { "_id": 0, "x": 1, "y": {"$numberLong": "10000000004"} }'); SELECT documentdb_api.insert_one('db','long_col',' { "_id": 1, "x": 2, "y": {"$numberLong": "10000000007"} }'); SELECT documentdb_api.insert_one('db','long_col',' { "_id": 2, "x": 3, "y": {"$numberLong": "10000000013"} }'); SELECT documentdb_api.insert_one('db','long_col',' { "_id": 3, "x": 4, "y": {"$numberLong": "10000000016"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- evaluate data in expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", {"$multiply": ["$x", "$y"]}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", {"$multiply": ["$x", "$y"]}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- negative cases -- incorrect arguments won't throw error SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y", "$z"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": [5], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["a", {}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y", "$z"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": [5], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["a", {}], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 0, "x": 1, "y": 2, "type": "a", "date": { "$date": { "$numberLong": "1718841600000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 1, "x": 2, "y": 3, "type": "a", "date": { "$date": { "$numberLong": "1718841605000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 2, "x": 3, "y": 4, "type": "a", "date": { "$date": { "$numberLong": "1718841610000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 3, "x": 4, "y": 5, "type": "a", "date": { "$date": { "$numberLong": "1718841615000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 4, "x": 5, "y": 6, "type": "a", "date": { "$date": { "$numberLong": "1718841620000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 5, "x": 6, "y": 7, "type": "a", "date": { "$date": { "$numberLong": "1718841630000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 6, "x": 7, "y": 8, "type": "b", "date": { "$date": { "$numberLong": "1718841640000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 7, "x": 8, "y": 9, "type": "b", "date": { "$date": { "$numberLong": "1718841680000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 8, "x": 9, "y": 10, "type": "b", "date": { "$date": { "$numberLong": "1718841700000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 9, "x": 10, "y": 11, "type": "b", "date": { "$date": { "$numberLong": "1718841800000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 10, "x": 11, "y": 12, "type": "b", "date": { "$date": { "$numberLong": "1718841900000" } } }'); SELECT documentdb_api.insert_one('db','window_col',' { "_id": 11, "x": 12, "y": 13, "type": "b", "date": { "$date": { "$numberLong": "1718842600000" } } }'); -- without window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"]}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"]}}}}]}'); -- document window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); -- range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"range": [-2, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"range": [-2, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); -- unsharded collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}]}'); -- shard collection SELECT documentdb_api.shard_collection('db', 'window_col', '{ "type": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": { "documents": ["unbounded", -1]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"covariancePop": { "$covariancePop": ["$x", "$y"], "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"covarianceSamp": { "$covarianceSamp": ["$x", "$y"], "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort": { "type": 1, "_id": 1 }}]}'); ----------------------------------------------------------- -- $rank accumulator tests ----------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}}}}}]}'); -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}, "window": []}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {}, "window": {"documents": [-1, 1]}}}}}]}'); -- error when input is not empty document to $rank SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": {"a":1}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rank": { "$rank": "$a" }}}}]}'); -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"rank": { "$rank": {} }}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {} }}}}]}'); -- error when window is present > rank input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {"a":1}, "window":[] }}}}]}'); -- error when rank is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {"a":1} }}}}]}'); -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rank": { "$rank": {} }}}}]}'); ----------------------------------------------------------- -- $denseRank accumulator tests ----------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}}}}}]}'); -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}, "window": []}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {}, "window": {"documents": [-1, 1]}}}}}]}'); -- error when input is not empty document to $denseRank SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": {"a":1}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"denseRank": { "$denseRank": "$a" }}}}]}'); -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); -- error when window is present > denseRank input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {"a":1}, "window":[] }}}}]}'); -- error when denseRank is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {"a":1} }}}}]}'); -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"denseRank": { "$denseRank": {} }}}}]}'); ----------------------------------------------------------- -- $documentNumber accumulator tests ----------------------------------------------------------- -- no values overlap all unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); -- values overlap non-unique values for sortBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); -- field not present sort by field and also heterogenous bson type SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}}}}}]}'); -- error scenario window provided in input. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}, "window": []}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {}, "window": {"documents": [-1, 1]}}}}}]}'); -- error when input is not empty document to $documentNumber SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": {"a":1}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1} ,"output": {"rowNumber": { "$documentNumber": "$a" }}}}]}'); -- error when input does not have a sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a" ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); -- error when window is present > rowNumber input valiation > sort by clause SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {"a":1}, "window":[] }}}}]}'); -- error when rowNumber is not having empty document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {"a":1} }}}}]}'); -- error when sort is not as expected SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields_invalidtypes", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"cost": 1, "a":-1} ,"output": {"rowNumber": { "$documentNumber": {} }}}}]}'); ----------------------------------------------------------- -- $integral and $derivative accumulator tests ----------------------------------------------------------- SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" }}, "a": "abc", "kilowatts": 2.95}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" }}, "a": "abc", "kilowatts": 2.7}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" }}, "a": "abc", "kilowatts": 2.6}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" }}, "a": "abc", "kilowatts": 2.98}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" }}, "a": "abc", "kilowatts": 2.5}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" }}, "a": "abc", "kilowatts": 2.25}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" }}, "a": "abc", "kilowatts": 2.75}', NULL); SELECT documentdb_api.insert_one('db', 'powerConsumption', '{"powerMeterID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" }}, "a": "abc", "kilowatts": 2.82}', NULL); -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "minute" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -10, 20 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "millisecond" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "second" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "minute" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "day" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "week" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- Negative tests -- unknown argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour", "unknown": 1 }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral (with no 'unit') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral (with no 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral sort by unknown field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "unknown": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral with invalid 'unit' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "year" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral with no input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral with invalid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$unknown", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- $integral with invalid window range SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, "current" ] } } } } }, { "$unset": "_id" } ]}'); -- $integral input is str SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$str", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- test integral without timestamp SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 0, "y": 1}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 1, "y": 2}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 2, "y": 1}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 1, "x": 3, "y": 4}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 0, "y": 100}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 2, "y": 105}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 4, "y": 107}', NULL); SELECT documentdb_api.insert_one('db', 'collNumeric', '{"partitionID": 2, "x": 6, "y": -100}', NULL); -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); -- Negative tests, common negative tests for $integral -- $integral (with unit and without timestamp) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y", "unit": "hour" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); -- test derivative with timestamp SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 1295.1, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 1295.63, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 1296.25, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 1296.76, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 10234.1, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 10234.33, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 10234.73, "a": "abc"}', NULL); SELECT documentdb_api.insert_one('db', 'deliveryFleet', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 10235.13, "a": "abc"}', NULL); -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "millisecond" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "second" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "minute" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "day" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "week" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); -- Negative tests -- $derivative (with no 'unit') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative with invalid 'unit' SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "month" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative (with no 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative (with invalid str 'sortBy') SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "str": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative sort by unknown field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "unknown": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative with no window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative with invalid input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$str", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- $derivative with no input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- unknown argument SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour", "unknown": 1 }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- test derivative without timestamp -- Validations SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y"}, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); -- Negative tests -- $derivative (with 'unit' and without timestamp) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y", "unit": "hour" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); -- $derivative (window is with date range) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ], "unit": "second"} } } } }, { "$unset": "_id" } ]}'); -- test integral and derivative with shard SELECT documentdb_api.shard_collection('db', 'collNumeric', '{ "type": "hashed" }', false); SELECT documentdb_api.shard_collection('db', 'deliveryFleet', '{ "type": "hashed" }', false); SELECT documentdb_api.shard_collection('db', 'powerConsumption', '{ "type": "hashed" }', false); -- derivative SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "derivative": { "$derivative": { "input": "$y"}, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "deliveryFleet", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "second" } } } } }, { "$match": { "truckAverageSpeed": { "$gt": 50 } } }, { "$unset": "_id" } ]}'); -- integral SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 2 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNumeric", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ "unbounded", "current" ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -1, 2 ], "unit": "minute" } } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerConsumption", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ -10, 20 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); -- test integral and derivative with invalid mixed types -- insert non-date data SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 1295.1}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 1295.63}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 1296.25}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "1", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 1296.76}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "miles": 10234.1}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814660000" } }, "miles": 10234.33}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "miles": 10234.73}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": { "$date": { "$numberLong": "1589814720000" } }, "miles": 10235.13}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "2", "timeStamp": 0, "miles": 10234.73}', NULL); SELECT documentdb_api.insert_one('db', 'IntegralInvalid', '{"truckID": "3", "timeStamp": 1, "miles": 10234.73}', NULL); -- derivative failed SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "IntegralInvalid", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$derivative": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); -- integral failed SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{"aggregate": "IntegralInvalid", "pipeline": [ { "$setWindowFields": { "partitionBy": "$truckID", "sortBy": { "timeStamp": 1 }, "output": { "truckAverageSpeed": { "$integral": { "input": "$miles", "unit": "hour" }, "window": { "range": [ -30, 0 ], "unit": "second" } } } } }, { "$unset": "_id" } ]}'); -- test integral and derivative with infinity/null/NaN mixed types SELECT documentdb_api.insert_one('db', 'collNaN', '{"partitionID": 1, "x": 0, "y": {"$numberDecimal": "NaN" }}', NULL); -- test NaN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNaN", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collNaN", "pipeline": [ { "$setWindowFields": { "partitionBy": "$partitionID", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); -- test infinity SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 0, "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 1, "x": 2, "y": {"$numberDecimal": "Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 2, "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 3, "x": 4, "y": 4 }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 5, "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 6, "x": 2, "y": 3 }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 7, "x": 3, "y": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_col_integral',' { "_id": 8, "x": 4, "y": {"$numberDecimal": "Infinity" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col_integral", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_col_integral", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); -- test null SELECT documentdb_api.insert_one('db','null_col',' { "_id": 0, "x": 1, "y": 2 }'); SELECT documentdb_api.insert_one('db','null_col',' { "_id": 1, "x": 2, "y": null }'); SELECT documentdb_api.insert_one('db','null_col',' { "_id": 2, "x": 3, "y": 3 }'); SELECT documentdb_api.insert_one('db','null_col',' { "_id": 3, "x": 4, "y": 4 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "null_col", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$integral": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "null_col", "pipeline": [ { "$setWindowFields": { "partitionBy": "$_id", "sortBy": { "x": 1 }, "output": { "integral": { "$derivative": { "input": "$y" }, "window": { "range": [ -1, 1 ]} } } } }, { "$unset": "_id" } ]}'); -- test decimal overflow SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "kilowatts": { "$numberDecimal": "1E+320" } }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814690000" } }, "kilowatts": { "$numberDecimal": "2E+340" } }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814700000" } }, "kilowatts": { "$numberDecimal": "2E+330" } }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814800000" } }, "kilowatts": { "$numberDecimal": "3E+332" } }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDecimal', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814900000" } }, "kilowatts": { "$numberDecimal": "3.123E+331" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerMeterDataDecimal", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); -- test double overflow SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814630000" } }, "kilowatts": 1e308 }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814900000" } }, "kilowatts": 1e308 }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814910000" } }, "kilowatts": 1e308 }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814920000" } }, "kilowatts": 1e308 }'); SELECT documentdb_api.insert_one('db', 'powerMeterDataDouble', '{"powerMeterID": "1", "timeStamp": { "$date": { "$numberLong": "1589814930000" } }, "kilowatts": 1e308 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "powerMeterDataDouble", "pipeline": [ { "$setWindowFields": { "partitionBy": "$powerMeterID", "sortBy": { "timeStamp": 1 }, "output": { "powerMeterKilowattHours": { "$integral": { "input": "$kilowatts", "unit": "hour" }, "window": { "range": [ "unbounded", "current" ], "unit": "hour" } } } } }, { "$unset": "_id" } ]}'); ----------------------------------------------------------- -- $shift accumulator tests ----------------------------------------------------------- --------------------- -- Negative Tests --------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); -- window not allowed with $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }, "window": {"range": [-1, 1]}}}}}]}'); -- range not allowed with $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }}}}}]}'); -- missing sortBy in $setWindowFields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "by": 1 }}}}}]}'); -- missing ouput field in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity" }}}}}]}'); -- missing by field in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1.1 }}}}}]}'); -- non-integer by field in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": {"t": 1} }}}}}]}'); -- non-integer by field in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": {"undefined": true} }}}}}]}'); -- non-integer by field in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1, "default": "$quantity" }}}}}]}'); -- non-constant default expression in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1, "default": ["$sasdf"] }}}}}]}'); -- non-constant default expression in $shift SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 2147483649}}}}}]}'); -- by value greater than int32 max value --------------------- -- Valid tests --------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": 1 }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": "$quantity", "by": -2 }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": 0 }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": 1, "default": "Not available" }}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity" : 1}, "output": {"shiftQuantity": { "$shift": { "output": ["$quantity", "$cost"], "by": -2, "default": [0, 0] }}}}}]}'); ----------------------------------------------------------- -- $top accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$top": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $bottom accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$bottom": {"output": "$quantity", "sortBy": {"cost": -1}}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $topN accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$topN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $bottomN accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$bottomN": {"output": "$quantity", "sortBy": {"cost": -1}, "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); /* Negative tests FOR $top(N)/$bottom(N) */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": [1]}}}}] }'); -- spec should be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": "hello"}}}}] }'); -- spec should be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$top": {"output": "hello"}}}}} ] }'); -- missing sortBy SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottom": {"sortBy": {"quantity": 1}}}}}} ] }'); -- missing output field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "hello", "sortBy": {"quantity": 1}}}}}} ] }'); -- missing n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"n": 2, "sortBy": {"quantity": 1}}}}}} ] }'); -- missing output SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "hello", "n": 2}}}}} ] }'); -- missing sortBy SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "$quantity", "n": 2, "sortBy": {"quantity": 1}, "fourth": true}}}}} ] }'); -- extra field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": -2, "sortBy": {"quantity": 1}}}}}} ] }'); -- negative n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": 2.2, "sortBy": {"quantity": 1}}}}}} ] }'); -- non-integer n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": "a", "sortBy": {"quantity": 1}}}}}} ] }'); -- non-integer n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": {"$undefined": true}, "sortBy": {"quantity": 1}}}}}} ] }'); -- undefined n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$topN": {"output": "$quantity", "n": {"$numberDecimal": "Infinity"}, "sortBy": {"quantity": 1}}}}}} ] }'); -- undefined n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "games", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$bottomN": {"output": "$quantity", "n": 2, "sortBy": 1}}}}} ] }'); -- sortBy is not an object ----------------------------------------------------------- -- $stdDevPop & $stdDevSamp accumulator tests ----------------------------------------------------------- -- empty collection SELECT documentdb_api.insert_one('db','empty_stddev_col',' { "_id": 0, "num": {} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); -- collection with single document SELECT documentdb_api.insert_one('db','single_stddev_col',' { "_id": 0, "num": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_stddev_col", "pipeline": [{"$setWindowFields": {"output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); -- document with non-numeric values SELECT documentdb_api.insert_one('db','non_numeric_stddev_col',' { "_id": 0, "num": "a"}'); SELECT documentdb_api.insert_one('db','non_numeric_stddev_col',' { "_id": 1, "num": "c"}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "non_numeric_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with mixed values SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 0, "num": "a" }'); SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 1, "num": 0 }'); SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 2, "num": "b" }'); SELECT documentdb_api.insert_one('db','mixed_stddev_col',' { "_id": 3, "num": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mixed_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with NAN values SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 0, "num": 2 }'); SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 1, "num": 3 }'); SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "NaN" } }'); SELECT documentdb_api.insert_one('db','nan_stddev_col',' { "_id": 3, "num": 4 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nan_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with Infinity values SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 0, "type": "a", "num": 2 }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 1, "type": "a", "num": {"$numberDecimal": "Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 2, "type": "a", "num": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 3, "type": "a", "num": 4 }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 5, "type": "b", "num": 2 }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 6, "type": "b", "num": 3 }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 7, "type": "b", "num": {"$numberDecimal": "-Infinity" } }'); SELECT documentdb_api.insert_one('db','inf_stddev_col',' { "_id": 8, "type": "b", "num": {"$numberDecimal": "Infinity" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "inf_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stddevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- document with Decimal128 values SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 0, "num": 2 }'); SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 1, "num": 3 }'); SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "4.0" } }'); SELECT documentdb_api.insert_one('db','decimal_stddev_col',' { "_id": 3, "num": 5 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "decimal_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- number overflow SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 0, "num": {"$numberDecimal": "100000004"} }'); SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 1, "num": {"$numberDecimal": "10000000007"} }'); SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 2, "num": {"$numberDecimal": "1000000000000013"} }'); SELECT documentdb_api.insert_one('db','overflow_stddev_col',' { "_id": 3, "num": {"$numberDecimal": "1000000000000000000"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "overflow_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- long values return double SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 0, "x": 1, "num": {"$numberLong": "10000000004"} }'); SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 1, "x": 2, "num": {"$numberLong": "10000000007"} }'); SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 2, "x": 3, "num": {"$numberLong": "10000000013"} }'); SELECT documentdb_api.insert_one('db','long_stddev_col',' { "_id": 3, "x": 4, "num": {"$numberLong": "10000000016"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- large values return nan SELECT documentdb_api.insert_one('db','large_stddev_col',' { "_id": 0, "num": {"$numberDecimal": "1E+310" } }'); SELECT documentdb_api.insert_one('db','large_stddev_col',' { "_id": 1, "num": {"$numberDecimal": "2E+310" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": 1, "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": 1, "sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); -- evaluate data in expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": {"$multiply": ["$x", "$num"]}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": {"$multiply": ["$x", "$num"]}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- array value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": ["$num"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": ["$num"], "window": { "documents": ["unbounded", "current"]}}}}}]}'); -- negative cases -- incorrect arguments won't throw error SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": {"a": "$num"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": 3, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "long_stddev_col", "pipeline": [{"$setWindowFields": {"sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": {"a": "$x"}, "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 0, "num": 2, "type": "a", "date": { "$date": { "$numberLong": "1718841600000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 1, "num": 3, "type": "a", "date": { "$date": { "$numberLong": "1718841605000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 2, "num": 4, "type": "a", "date": { "$date": { "$numberLong": "1718841610000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 3, "num": 5, "type": "a", "date": { "$date": { "$numberLong": "1718841615000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 4, "num": 6, "type": "a", "date": { "$date": { "$numberLong": "1718841620000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 5, "num": 7, "type": "a", "date": { "$date": { "$numberLong": "1718841630000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 6, "num": 8, "type": "b", "date": { "$date": { "$numberLong": "1718841640000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 7, "num": 9, "type": "b", "date": { "$date": { "$numberLong": "1718841680000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 8, "num": 10, "type": "b", "date": { "$date": { "$numberLong": "1718841700000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 9, "num": 11, "type": "b", "date": { "$date": { "$numberLong": "1718841800000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 10, "num": 12, "type": "b", "date": { "$date": { "$numberLong": "1718841900000" } } }'); SELECT documentdb_api.insert_one('db','window_stddev_col',' { "_id": 11, "num": 13, "type": "b", "date": { "$date": { "$numberLong": "1718842600000" } } }'); -- without window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num"}}}}]}'); -- document window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); -- range window SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"range": [-2, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"range": [-2, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"range": [-3, 3], "unit": "minute"}}}}}]}'); -- unsharded collection SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}]}'); -- shard collection SELECT documentdb_api.shard_collection('db', 'window_stddev_col', '{ "type": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", -1]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": { "_id": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": "$type", "sortBy": {"_id": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": { "date": 1}, "output": {"stdDevPop": { "$stdDevPop": "$num", "window": { "documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "window_stddev_col", "pipeline": [{"$setWindowFields": {"partitionBy": { "$cond": [{ "$eq": [{ "$mod": ["$_id", 2] }, 0] }, "even", "odd"] }, "sortBy": {"date": 1}, "output": {"stdDevSamp": { "$stdDevSamp": "$num", "window": {"documents": ["unbounded", "current"]}}}}}, {"$sort" : {"type" : 1, "_id" : 1}}]}'); ----------------------------------------------------------- -- $first accumulator tests ----------------------------------------------------------- ---------------------- -- No window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$first": {"output": "$date"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$first": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); -- the sortBy inside $first is just treated as output expression ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$first": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$first": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$first": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $last accumulator tests ----------------------------------------------------------- ---------------------- -- No window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$last": {"output": "$date"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$last": {"output": "$quantity", "sortBy": {"cost": -1}}}}}}]}'); -- the sortBy inside $last is just treated as output expression ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$last": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$last": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$last": {"quantity": "$quantity", "cost": "$cost"}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $firstN accumulator tests ----------------------------------------------------------- ---------------------- -- No window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"firstDate": { "$firstN": {"input": "$date", "n": 2}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$firstN": {"input": "$quantity", "n": 3}}}}}]}'); ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 4}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$firstN": {"input": "$quantity", "n": 5}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$firstN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$firstN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 2}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $lastN accumulator tests ----------------------------------------------------------- ---------------------- -- No window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": { "$lastN": {"input": "$quantity", "n": 2}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$lastN": {"input": "$quantity", "n": 3}}}}}]}'); ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", -1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 4}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"cheapQuantity": { "$lastN": {"input": "$quantity", "n": 5}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$lastN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$lastN": {"input": {"quantity": "$quantity", "cost": "$cost"}, "n": 2}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); /* Negative tests for $firstN/$lastN */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": [1]}}}}] }'); -- spec should be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": "hello"}}}}] }'); -- spec should be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "hello"}}}}} ] }'); -- missing n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": {"n": 2}}}}} ] }'); -- missing input SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$lastN": {"input": "$quantity", "n": 2, "third": true}}}}} ] }'); -- extra field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": -2}}}}} ] }'); -- negative n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": 2.2}}}}} ] }'); -- non-integer n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": "a"}}}}} ] }'); -- non-integer n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": {"$undefined": true}}}}}} ] }'); -- undefined n SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [ {"$setWindowFields": {"partitionBy": "$a", "output": {"lastDate": {"$firstN": {"input": "$quantity", "n": {"$numberDecimal": "Infinity"}}}}}} ] }'); -- undefined n /* Test $first, $last, $firstN, $lastN with $group stage as code path is common with $setWindowFields */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$firstN": {"input": "$quantity", "n": 3 }}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$lastN": {"input": "$quantity", "n": 3}}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$lastN": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$first": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$first": "$quantity"}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$last": {"input": ["$quantity", "$cost"], "n": 3}}}}] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$group": {"_id": "$a", "res": {"$last": "$quantity"}}}] }'); ----------------------------------------------------------- -- $maxN accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$maxN": {"input": "$quantity", "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $minN accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"expensiveQuantity": { "$minN": {"input": "$quantity", "n": 3}, "window": {"range": [-20, 20], "unit": "second"}}}}}]}'); ----------------------------------------------------------- -- $min accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$min": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$min": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$min": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$min": "$quantity", "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); ----------------------------------------------------------- -- $max accumulator tests ----------------------------------------------------------- ---------------------- -- Document window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$max": "$quantity"}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [0, 0]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-1, 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-10, 10]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["current", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", 1]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"a": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", -1]}}}}}]}'); ---------------------------- -- Document window with sort ---------------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"_id": -1}, "output": {"totalQuantity": { "$max": "$quantity"}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"quantity": 1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": ["unbounded", "current"]}}}} }]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": {"date": -1}, "output": {"totalQuantity": { "$max": "$quantity", "window": {"documents": [-1, 1]}}}} }]}'); ---------------------- -- Range window ---------------------- SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-3, 3]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["unbounded", "current"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "quantity": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "unbounded"]}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "second"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "minute"}}}}}]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": [-5, 5], "unit": "day"}}}}}]}'); -- "CURRENT ROW" in a range frame does not always refer to the current physical row; it refers to the first peer with the same sort key value. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": "$a", "sortBy": { "date": 1 }, "output": {"totalInGroup": { "$max": "$quantity", "window": {"range": ["current", "current"], "unit": "day"}}}}}]}'); -- Tests for $last SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 1, "storeId": 1, "area": "Delhi", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1756720800000" } }, "status": "open" }', NULL); SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 2, "storeId": 2, "area": "Mumbai", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1756902000000" } }, "status": "closed" }', NULL); SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 3, "storeId": 3, "area": "Kolkata", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1757086200000" } }, "status": "open" }', NULL); SELECT documentdb_api.insert_one('db','lastSetWindowFields','{ "_id": 4, "storeId": 4, "area": "Chennai", "company": "ABC Cares", "lastUpdated": { "$date" : { "$numberLong" : "1757235600000" } }, "status": "open" }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "lastSetWindowFields", "pipeline":[{"$match":{"company":{"$in":["ABC Cares"]}}}, {"$setWindowFields": {"partitionBy":"$company","sortBy": {"lastUpdated": {"$numberInt" : "1" } }, "output" : { "lastUpdatedDateForStore" : { "$last" : "$lastUpdated", "window" : { "documents" : [ "current", "unbounded" ] } } } } } ]}');bson_aggregation_pipeline_tests.sql000066400000000000000000001363001507310017400361340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 411000; SET documentdb.next_collection_id TO 4110; SET documentdb.next_collection_index_id TO 4110; SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'aggregation_pipeline') ORDER BY object_id; -- add newField SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); -- do 2 addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$set": { "newField2": "someOtherField" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$set": { "newField2": "someOtherField" } } ], "cursor": {} }'); -- add $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); -- add $unset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unset": "_id" }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); -- add skip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }], "cursor": {} }'); -- add limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 2 }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 2 }], "cursor": {} }'); -- add skip + limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }, { "$limit": 1 }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$skip": 1 }, { "$limit": 1 }], "cursor": {} }'); -- try match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }], "cursor": {} }'); -- match + project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1 } }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1 } }], "cursor": {} }'); -- match + project + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); -- unwind SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" } ], "cursor": {} }'); -- match and then unwind SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$unwind": "$a.b" } ], "cursor": {} }'); -- unwind and then match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$match": { "$expr": { "$not": { "$isArray": "$a.b" } } } } ], "cursor": {} }'); -- unwind and addfields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); -- $addFields then addFields is inlined. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "x": 1, "y": 2, "xyz": 3 } }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "x": 1, "y": 2, "xyz": 3 } }, { "$addFields": { "xyz": "$_id" } } ], "cursor": {} }'); -- $project then addFields can be inlined only on exclusion today SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); -- error scenarios for $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "a": 0, "boolean": 1 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "cursor": {} }'); -- replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceRoot": { "newRoot": "$e" } } ], "cursor": {} }'); -- count SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$count": "d" }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$count": "d" }, { "$addFields": { "e": "$d" } }], "cursor": {} }'); -- replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceWith": "$e" } ], "cursor": {} }'); -- sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sort": { "_id": 1 } }], "cursor": {} }'); -- sort + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); -- match + sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$sort": { "_id": 1 } } ], "cursor": {} }'); -- sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sortByCount": { "$eq": [ { "$mod": [ { "$toInt": "$_id" }, 2 ] }, 0 ] } }, { "$sort": { "_id": 1 } }], "cursor": {} }'); -- $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); -- $group with keys having dotted path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d.e": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); -- $group with first/last SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); -- $group with first/last sorted (TODO) -- add $sample SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 2 } }, { "$project": { "_id": "1" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 2 } }, { "$project": { "_id": "1" } } ], "cursor": {} }'); -- Sample after pass-through stages EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$project": { "_id": "1" } }, { "$sample": { "size": 2 } }], "cursor": {} }'); -- Sample after sample EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$sample": { "size": 3 } }, { "$sample": { "size": 2 } }], "cursor": {} }'); -- Sample after other stage EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$sample": { "size": 2 } }], "cursor": {} }'); -- internalInhibitOptimization SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); -- facet SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "c" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } }]}'); EXPlAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }]}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline" : [{ "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet" : { "results" : [ { "$match" : { "result" : true } } ] } }, { "$facet": { "a" : [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "b" : [ { "$count": "d" } ], "c": [ { "$unwind": "$a.b" } ] } }]}'); -- facet with parent transform: SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unwind": "$a.b" }, { "$facet": { "a" : [ { "$unset": "_id" } ], "b" : [ { "$count": "d" } ], "c": [ { "$replaceWith": { "f": "$_id" } } ] } } ], "cursor": {} }'); -- facet negative tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ "hello" ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$facet": { "a" : [ { "$count": "d", "$unset": "b" } ] } } ], "cursor": {} }'); -- FIND SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": 2 }'); BEGIN; set local documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": 2 }'); ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": { "$gt": "1" } }, "projection": { "a.b": 1 }, "sort": { "_id": 1 }, "skip": 1, "limit": -2 }'); -- count SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline" }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); -- count with skip SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": 0 }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": 1 }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": null }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -3.14159 }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -9223372036854775808 }'); SELECT document FROM bson_aggregation_count('db', '{ "count": "non_existent_coll" }'); SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline" }'); SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": null }'); SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -3.14159 }'); SELECT document FROM documentdb_api.count_query('db', '{ "count": "aggregation_pipeline", "query": {}, "skip": -9223372036854775808 }'); -- handling of skip as an aggregation stage; this is different from skip in a count query SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": 0 }], "cursor": {}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": 1 }], "cursor": {}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": null }], "cursor": {}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": -3.14159 }], "cursor": {}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": {}}, { "$skip": -9223372036854775808 }], "cursor": {}}'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline" }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "aggregation_pipeline", "query": { "_id": { "$gt": "1" } } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_count('db', '{ "count": "non_existent_coll" }'); -- distinct SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "aggregation_pipeline", "key": "_id" }'); SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "non_existent_coll", "key": "foo" }'); SELECT document FROM documentdb_api.distinct_query('db', '{ "distinct": "aggregation_pipeline", "key": "_id" }'); SELECT document FROM documentdb_api.distinct_query('db', '{ "distinct": "non_existent_coll", "key": "foo" }'); -- Explain for LIMIT 1 + Point query BEGIN; set local documentdb.enableCursorsOnAggregationQueryRewrite to on; -- with singleBatch we should not see customScan EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": "1" }, "singleBatch": true }'); -- with _id query and limit 1 we should see custom scan with primary key lookup. EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline", "filter": { "_id": "2" }, "limit": 1 }'); ROLLBACK; -- $lookup SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 1, "movie_title" : "Interstellar", "ticket_price" : 15, "tickets_sold" : 120 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings','{ "_id" : 2, "movie_title" : "Inception", "ticket_price" : 13, "tickets_sold" : 100 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 3, "movie_title" : "Dune", "ticket_price" : 18, "tickets_sold" : 95 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 4, "movie_title" : ["Interstellar", "Dune", "Inception"], "ticket_price" : 14, "tickets_sold" : 250 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 5 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 6, "movie_title" : {"a": "v", "b" : 2, "c" : [5, 6, 7]} }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_screenings',' { "_id" : 7, "movie_title" : [{"a": { "b" : 2}}, [5, 6, 7], 9, "z"] }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog',' { "_id" : 11, "title" : "Interstellar", "genre": "Sci-Fi", "available_seats" : 50 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog',' { "_id" : 12, "title" : "Interstellar", "genre": "Sci-Fi", "available_seats" : 70 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 13, "title" : "Dune", "genre": "Sci-Fi", "available_seats" : 30 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 14, "title" : "Blade Runner", "genre": "Cyberpunk", "available_seats" : 40 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 15, "title" : "Inception", "genre": "Thriller", "available_seats" : 60 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 16, "title" : null, "genre": "Unknown", "available_seats" : 0 }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 17, "title" : {"a": "x", "b" : 1, "c" : [1, 2, 3]}, "genre": "Experimental" }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 18, "title" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "genre": "Experimental Array" }', NULL); SELECT documentdb_api.insert_one('db','agg_pipeline_movie_catalog','{ "_id" : 19, "title" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "genre": "Experimental Array" }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } }, { "$sample": { "size": 3 } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "coll_dne", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [], "as": "c" } } ], "cursor": {} }'); BEGIN; set local citus.enable_local_execution to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); ROLLBACK; SELECT documentdb_api.shard_collection('db', 'agg_pipeline_movie_screenings', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); BEGIN; set local citus.enable_local_execution to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); ROLLBACK; SELECT documentdb_api.shard_collection('db', 'agg_pipeline_movie_catalog', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "agg_pipeline_movie_catalog", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "coll_dne", "as": "matched_docs", "localField": "title", "foreignField": "title", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [], "as": "c" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "as": "matched_docs", "pipeline": [ { "$documents": [ { "a": 1}, { "a": 2 } ] } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "as": "matched_docs", "foreignField": "foo", "localField": "_id", "pipeline": [ { "$documents": [ { "a": 1}, { "a": 2 } ] } ] } } ], "cursor": {} }'); -- $lookup.pipeline Negative tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": { "$count": "efe" }, "as": "c" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ "$count" ], "as": "c" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ { } ], "as": "c" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_movie_screenings", "pipeline": [ { "$lookup": { "from": "colldne", "pipeline": [ { "$count": "efe", "$match": { "year": 2018 } } ], "as": "c" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$match": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$project": { "newField" : "1", "a.y": ["p", "q"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$skip": 1 } ], "cursor": {} }'); -- test sort behavior on sharded/unsharded SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate" : "agg_pipeline_movie_catalog", "pipeline" : [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } }, { "this_predicate_matches_nothing" : true } ] } }, { "$sort" : { "_id" : -1.0 } }, { "$limit" : 1.0 }, { "$project" : { "_id" : 1.0, "b" : { "$round" : "$a" } } } ], "cursor" : { }, "lsid" : { "id" : { "$binary" : { "base64": "VJmzOaS5R46C4aFkQzrFaQ==", "subType" : "04" } } }, "$db" : "test" }'); $Q$); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline'); SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate" : "aggregation_pipeline", "pipeline" : [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } }, { "this_predicate_matches_nothing" : true } ] } }, { "$sort" : { "_id" : -1.0 } }, { "$limit" : 1.0 }, { "$project" : { "_id" : 1.0, "b" : { "$round" : "$a" } } } ], "cursor" : { }, "lsid" : { "id" : { "$binary" : { "base64": "VJmzOaS5R46C4aFkQzrFaQ==", "subType" : "04" } } }, "$db" : "test" }') $Q$); -- unionWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": "aggregation_pipeline" } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$unionWith": { "coll": "aggregation_pipeline" } }, { "$match": { "a": "no" } }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "aggregation_pipeline", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "coll": "agg_pipeline_movie_catalog", "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [{ "$match": { "nonexist": { "$exists": true } } }, { "$unionWith": { "coll": "agg_pipeline_movie_catalog", "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ { "$match" : { "$or" : [ { "_id" : { "$lt" : 9999.0 }, "some_other_field" : { "$ne" : 3.0 } } ] } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$unionWith": { "pipeline": [ { "$documents": [ { "a": 1 }, { "a": 2 } ]}] } } ], "cursor": {} }'); -- $addFields nested usage SELECT documentdb_api.insert_one('db','aggregation_pipeline','{ "_id": 100, "movie": "Nebula Drift", "critics": [7, 8, 9], "audience": [8, 7], "bonusPoints": 2 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline','{ "_id": 200, "movie": "Quantum Heist", "critics": [6, 6, 7], "audience": [7, 6], "bonusPoints": 3 }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$match": { "bonusPoints": { "$gte": 0 } } }, { "$addFields": { "totalCritics": { "$sum": "$critics" }, "totalAudience": { "$sum": "$audience" } } }, { "$addFields": { "totalScore": { "$add": [ "$totalCritics", "$totalAudience", "$bonusPoints" ] } } } ], "cursor": {} }'); -- NumberDouble Range+1 and Range-1 Negative test $skip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "-9223372036854776833"} } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "9223372036854775296"} } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline", "pipeline": [ { "$skip": {"$numberDouble" : "-9223372036854776832"} } ], "cursor": {} }'); -- samplerate /* insert 100 documents */ /* test unshard case */ DO $$ DECLARE i int; BEGIN FOR i IN 1..100 LOOP PERFORM documentdb_api.insert_one('db', 'agg_pipeline_samplerate', FORMAT('{ "_id": %s }',i)::documentdb_core.bson); END LOOP; END; $$; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); /* sampleRate will random select document, use greater than 0 to make sure slice of documents is selected */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); /* test shard case */ SELECT documentdb_api.shard_collection('db', 'agg_pipeline_samplerate', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 1 } }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0 } }, {"$count": "count"} ], "cursor": {} }'); /* sampleRate will random select document, use greater than 0 to make sure slice of documents is selected */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 0.5 } }, { "$count": "numMatches" }, { "$addFields": { "gtZero": { "$gt": ["$numMatches", 0] } } }, {"$project": { "_id": 0, "gtZero": 1 } }], "cursor": {} }'); -- negative samplerate SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": -1.23 } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": null } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": NaN } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": Infinity } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": -Infinity } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": "0.65" } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": 10 } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_pipeline_samplerate", "pipeline": [ { "$match": { "$sampleRate": false } }, { "$limit": 1 }, {"$count": "count"} ], "cursor": {} }'); -- Pipeline directly push to shards if all stages refer to same collection and that is not sharded and is present on the same node as coordinator. SELECT documentdb_api.insert_one('pipelineDB','agg_pipeline_optimizations','{ "_id": 1, "a": "RANDOM_A", "b": {"c": ["SAMPLE1", "SAMPLE2"], "d": [[1,2], [3, 4]]} }', NULL); SELECT documentdb_api.insert_one('pipelineDB','agg_pipeline_optimizations','{ "_id": 2, "a": "RANDOM_B", "b": {"c": ["SAMPLE3", "SAMPLE4"], "d": [[5,6], [7, 8]]} }', NULL); SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations" } ] }'); SELECT documentdb_api.create_collection('pipelineDB', 'agg_pipeline_optimizations_new'); EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations_new" } ] }'); EXPLAIN (VERBOSE OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$merge": "agg_pipeline_optimizations" } ] }'); -- Shard the collection now SELECT documentdb_api.shard_collection('pipelineDB', 'agg_pipeline_optimizations', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$match": { "a": "RANDOM_A" } } ] }'); SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('pipelineDB', '{ "aggregate": "agg_pipeline_optimizations", "pipeline": [ { "$project": { "a" : 1 } } ] }'); -- Test limit on aggregation stages CREATE OR REPLACE FUNCTION check_aggregation_stages_limit(num_stages int) RETURNS boolean AS $fn$ DECLARE pipeline jsonb := '[]'::jsonb; aggregate_spec jsonb; BEGIN -- Create a json array of form [{$match: {}}] with num_stages elements FOR i IN 1..num_stages LOOP pipeline := pipeline || '{"$match": {}}'::jsonb; END LOOP; aggregate_spec := jsonb_build_object('aggregate', 'dummy', 'pipeline', pipeline); PERFORM document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson); RETURN true; END; $fn$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION check_lookup_stages_limit(num_inline_stages int, num_non_inline_stages int) RETURNS boolean AS $fn$ DECLARE pipeline jsonb := '[]'::jsonb; aggregate_spec jsonb; lookup_spec jsonb; BEGIN -- Create a json array of form [{$match: {}}] with num_stages elements FOR i IN 1..num_inline_stages LOOP pipeline := pipeline || '{"$match": { }}'::jsonb; END LOOP; FOR i IN 1..num_non_inline_stages LOOP pipeline := pipeline || '{"$count": "dummy" }'::jsonb; END LOOP; lookup_spec := jsonb_build_object('$lookup', jsonb_build_object('from', 'dummy', 'as', 'dummy', 'localField', 'dummy', 'foreignField', 'dummy', 'pipeline', pipeline)); aggregate_spec := jsonb_build_object('aggregate', 'dummy', 'pipeline', '[]'::jsonb || lookup_spec); PERFORM document FROM bson_aggregation_pipeline('db', aggregate_spec::text::documentdb_core.bson); RETURN true; END; $fn$ LANGUAGE plpgsql; SELECT check_aggregation_stages_limit(100); SELECT check_aggregation_stages_limit(1000); SELECT check_aggregation_stages_limit(1001); SELECT check_lookup_stages_limit(1, 1); SELECT check_lookup_stages_limit(1000, 0); SELECT check_lookup_stages_limit(0, 1000); SELECT check_lookup_stages_limit(500, 500); SELECT check_lookup_stages_limit(1000, 1); SELECT check_lookup_stages_limit(1, 1000); SET documentdb.aggregation_stages_limit = 1005; SELECT check_aggregation_stages_limit(1001); SELECT check_lookup_stages_limit(1000, 1); SELECT check_lookup_stages_limit(1, 1000); RESET documentdb.aggregation_stages_limit; -- $lookup and $unwind stage combined when null results need to be preserved SELECT documentdb_api.insert_one('db','lookup_directors','{ "_id": 1, "name": "Alex Veridian" }', NULL); SELECT documentdb_api.insert_one('db','lookup_directors','{ "_id": 2, "name": "Morgan Slate" }', NULL); SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 1, "title": "Shadow Horizon", "director": "Alex Veridian" }', NULL); SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 2, "title": "Neon Abyss", "director": "Morgan Slate" }', NULL); SELECT documentdb_api.insert_one('db','lookup_movies','{ "_id": 3, "title": "Celestial Rift", "director": "Alex Veridian" }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "lookup_movies", "pipeline": [ { "$lookup": { "from": "lookup_directors", "localField": "director", "foreignField": "name", "as": "director_info" } }, { "$unwind": { "path": "$director_info", "preserveNullAndEmptyArrays": true } }, { "$match": { "title": "Celestial Rift" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "lookup_movies", "pipeline": [ { "$lookup": { "from": "lookup_directors", "localField": "director", "foreignField": "name", "as": "director_info" } }, { "$unwind": { "path": "$director_info", "preserveNullAndEmptyArrays": true } }, { "$match": { "title": "Celestial Rift" } } ], "cursor": {} }');bson_aggregation_pipeline_tests_bucket_auto.sql000066400000000000000000000403251507310017400405220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 5110000; SET documentdb.next_collection_id TO 51100; SET documentdb.next_collection_index_id TO 51100; /* Insert data */ SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 1, "product" : "apple", "price" : 1, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 2, "product" : "peach", "price" : 2, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 3, "product" : "melon", "price" : 5, "year": 2021}', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto',' { "_id" : 4, "product" : "melon", "price" : 7, "year": 2021}', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 5, "product" : "melon", "price" : 20, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 6, "product" : "apple", "price" : 30, "year": 2022 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 7, "product" : "melon", "price" : 60, "year": 2022 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 8, "product" : "peach", "price" : 62, "year": 2022 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 9, "product" : "banana", "price" : 170, "year": 2023 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 10, "product" : "banana", "price" : 300, "year": 2023 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 11, "product" : "peach", "price" : 320, "year": 2023 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 12, "product" : "peach", "price" : 350, "year": 2024 }', NULL); /* positive cases: */ -- $bucketAuto with only required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); -- $bucketAuto with diferent num of buckets SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 4 } } ] }'); -- $bucketAuto with output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "count": { "$sum": 1 }, "averageAmount": { "$avg": "$price" } } } } ] }'); -- $bucketAuto without count in output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "averageAmount": { "$avg": "$price" } } } } ] }'); -- $bucketAuto with expression in groupBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 1] }, "buckets": 3 } } ] }'); -- $bucketAuto with another stage before it SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$match": { "product": "melon" } }, { "$bucketAuto": { "groupBy": "$price", "buckets": 2 } } ] }'); -- groupBy non-integar field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3 } } ] }'); -- unevenly distributed data SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); -- try granularity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": "R5" } } ] }'); -- $bucketAuto with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$let": { "vars": { "adjustedAmount": { "$multiply": ["$price", 10] } }, "in": "$$adjustedAmount" }}, "buckets": 3 } } ] }'); -- With let at aggregation level SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "let": { "multiplier": 10 }, "pipeline": [ { "$bucketAuto": { "groupBy": { "$multiply": ["$price", "$$multiplier"] }, "buckets": 3 } } ] }'); -- less buckets will be returned if the unique values are less than the buckets specified SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 8 } } ] }'); -- Expand bucket: same value should go to the same bucket, even if this makes the buckets uneven SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$year", "buckets": 3 } } ] }'); /* all granularity types */ DO $$ DECLARE i int; BEGIN FOR i IN 0..99 LOOP PERFORM documentdb_api.insert_one('db', 'bucketAutoGranularity', FORMAT('{ "_id": %s, "amount": %s }', i + 1, i)::documentdb_core.bson); END LOOP; END; $$; -- POWERSOF2 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "POWERSOF2" } } ] }'); -- 1-2-5 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "1-2-5" } } ] }'); -- R5 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R5" } } ] }'); -- R10 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R10" } } ] }'); -- R20 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R20" } } ] }'); -- R40 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R40" } } ] }'); -- R80 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "R80" } } ] }'); -- E6 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E6" } } ] }'); -- E12 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E12" } } ] }'); -- E24 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E24" } } ] }'); -- E48 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E48" } } ] }'); -- E96 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E96" } } ] }'); -- E192 SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAutoGranularity", "pipeline": [ { "$bucketAuto": { "groupBy": "$amount", "buckets": 5, "granularity": "E192" } } ] }'); /* groupBy array or document field */ SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 1, "valueArray" : [1, 2, 3], "valueDocument" : { "a": 1, "b": 2 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 2, "valueArray" : [4, 5, 6], "valueDocument" : { "a": 3, "b": 4 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 3, "valueArray" : [9, 8], "valueDocument" : { "a": 5, "b": 6 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 4, "valueArray" : [10, 11, 12], "valueDocument" : { "a": 4, "b": 8 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 5, "valueArray" : [3, 14, 15], "valueDocument" : { "a": 2, "b": 10 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAutoGroupBy', '{ "_id" : 6, "valueArray" : [6, 17, 18], "valueDocument" : { "a": 11, "b": 12 } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAutoGroupBy", "pipeline": [ { "$bucketAuto": { "groupBy": "$valueArray", "buckets": 3, "output": { "Ids" : { "$push": "$_id" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAutoGroupBy", "pipeline": [ { "$bucketAuto": { "groupBy": "$valueDocument", "buckets": 3, "output": { "Ids" : { "$push": "$_id" } } } } ] }'); /* negative cases, validations: */ -- required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "buckets": 3 } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price" } } ] }'); -- groupBy must be a path with prefix $ or expression SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "price", "buckets": 3 } } ] }'); -- buckets must be a positive integer SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": "abc" } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3.1 } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": -3 } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 0 } } ] }'); -- output must be document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": 1 } } ] }'); -- unknown argument of $bucketAuto SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "unknown": 1 } } ] }'); -- granularity must be a string SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": 1 } } ] }'); -- unsupported granularity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "granularity": "abc" } } ] }'); -- when has granularity, groupby value must be a non-negative number SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3, "granularity": "POWERSOF2" } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 100] }, "buckets": 3, "granularity": "POWERSOF2" } } ] }'); /* Explain */ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); /* running $bucketAuto with intermediate size of more than 100mb */ DO $$ DECLARE i int; BEGIN -- each doc is "%s": 5 MB - ~5.5 MB & there's 60 of them FOR i IN 1..60 LOOP PERFORM documentdb_api.insert_one('db', 'bucketAuto_sizes_test', FORMAT('{ "_id": %s, "groupName": "ABC", "tag": { "%s": [ %s "d" ] } }', i, i, repeat('"' || i || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; /* should fail with intermediate size error */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "bucketAuto_sizes_test", "pipeline": [ { "$bucketAuto": { "groupBy": "$_id", "buckets": 2, "output": { "allTags" : { "$push" : "$tag" } } } } ] }'); /* sharded collection */ SELECT documentdb_api.shard_collection('db', 'dollarBucketAuto', '{ "price": "hashed" }', false); /* positive cases: */ -- $bucketAuto with only required fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); -- $bucketAuto with diferent num of buckets SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 4 } } ] }'); -- $bucketAuto with output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "count": { "$sum": 1 }, "averageAmount": { "$avg": "$price" } } } } ] }'); -- $bucketAuto without count in output fields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3, "output": { "averageAmount": { "$avg": "$price" } } } } ] }'); -- $bucketAuto with expression in groupBy field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": { "$subtract": ["$price", 1] }, "buckets": 3 } } ] }'); -- $bucketAuto with another stage before it SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucketAuto": { "groupBy": "$price", "buckets": 2 } } ] }'); -- groupBy non-integar field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$product", "buckets": 3 } } ] }'); -- unevenly distributed data SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); -- test with null values SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 13, "product" : "peach", "price" : null, "year": 2024 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketAuto','{ "_id" : 14, "product" : "peach", "price" : null, "year": 2024 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 5 } } ] }'); /* Explain */ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketAuto", "pipeline": [ { "$bucketAuto": { "groupBy": "$price", "buckets": 3 } } ] }'); bson_aggregation_pipeline_tests_coll_agnostic.sql000066400000000000000000000043471507310017400410410ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 314000; SET documentdb.next_collection_id TO 3140; SET documentdb.next_collection_index_id TO 3140; -- collection agnostic with no pipeline should work and return 0 rows. SELECT document from bson_aggregation_pipeline('agnosticTests', '{ "aggregate" : 1.0, "pipeline" : [ ], "cursor" : { }, "txnNumber" : 100, "lsid" : { "id" : { "$binary" : { "base64": "AAAAAA==", "subType" : "04" } } }, "$db" : "agnosticTests" }'); -- $document tests SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [] } ], "cursor": {}}'); SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": { "$isArray": "field1" } }, { "field2": 20 } ] }], "cursor": {}}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": [ { "field1": 10 }, { "field2": 20 } ] }, { "$addFields": { "field2": 30 } } ], "cursor": {} }'); -- error cases SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": null }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": "String Value" }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [ { "$documents": {} }], "cursor": {}}'); -- bugfix scenario: SELECT document FROM bson_aggregation_pipeline('agnosticTests', '{ "aggregate": 1, "pipeline": [{ "$documents": [ { "userId": "User1", "sessionId": "S1", "points": 100 } ] }, { "$group": { "_id": "$sessionId", "firstFivePoints": { "$firstN": { "input": "$points", "n": 5 } } } } ] }'); bson_aggregation_pipeline_tests_facet_group.sql000066400000000000000000000115061507310017400405120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 313000; SET documentdb.next_collection_id TO 3130; SET documentdb.next_collection_index_id TO 3130; SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 1, "a": { "b": 1, "c": 1} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 2, "a": { "b": 1, "c": 2} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 3, "a": { "b": 1, "c": 3} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 4, "a": { "b": 2, "c": 1} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 5, "a": { "b": 2, "c": 2} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 6, "a": { "b": 2, "c": 3} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 7, "a": { "b": 3, "c": 1} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 8, "a": { "b": 3, "c": 2} }', NULL); SELECT documentdb_api.insert_one('db','agg_facet_group','{ "_id": 9, "a": { "b": 3, "c": 3} }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet2" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet1" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT documentdb_api.shard_collection('db', 'agg_facet_group', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet2" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$facet": { "facet1" : [ { "$group": { "_id": "$a.b", "first": { "$first" : "$name" } } } ], "facet1" : [ { "$group": { "_id": "$a.b", "last": { "$last" : "$name" }}}]}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": 1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : 1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "agg_facet_group", "pipeline": [ { "$addFields": {"name": "$a.c"} }, { "$sort": { "a.b": -1, "name" : -1 } }, { "$group": { "_id": "$a.b", "first": { "$first" : "$name" }, "last": { "$last": "$name" } } } ] }'); bson_aggregation_pipeline_tests_geonear.sql000066400000000000000000001143601507310017400376360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 498000; SET documentdb.next_collection_id TO 49800; SET documentdb.next_collection_index_id TO 49800; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 1, "a": { "b": [ 0, 0]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 2, "a": { "b": [ 1.1, 1.1]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 3, "a": { "b": [ 2.29, 2.29]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 4, "a": { "b": [ 3.31, 3.31]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 5, "a": { "b": [ 4.42, 4.42]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 6, "a": { "b": [ 5.5, 5.5]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 7, "a": { "b": [ 6.66, 6.66]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 8, "a": { "b": [ 7.74, 7.74]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 9, "a": { "b": [ 8.81, 8.81]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 10, "a": { "geo": {"type": "Point", "coordinates": [35.3, 35.4]}} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 11, "a": { "geo": {"type": "LineString", "coordinates": [[35.36, 35.42], [32.3, 30]]}} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 12, "a": { "geo": {"type": "Polygon", "coordinates": [[[35.73, 35.74], [38.6, 35.3], [38.7, 39.2], [35.73, 35.74]]]}} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 13, "a": { "geo": {"type": "MultiPoint", "coordinates": [[35.43, 35.44], [32.3, 30]]}} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 14, "a": { "geo": {"type": "MultiLineString", "coordinates": [[[35.83, 35.84], [32.3, 30]]]}} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 15, "a": { "geo": {"type": "MultiPolygon", "coordinates": [[[[35.312, 35.441], [38.644, 35.3231], [38.71, 39.32], [35.312, 35.441]]]]}} }', NULL); -- Validations (more validations to follow) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$match": { "query": { } } }, { "$geoNear": { "near": [5, 6], "key": "a.b", "distanceField": "dist.calculated" } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated" } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": "value" } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": true, "distanceField": "dist.calculated", "key": "a" } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "$text": { "$search": "cat" } } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "$or": [{"$text": { "$search": "cat" }}, {"b": 2}] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "a": {"$near": [1, 1]}} } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "query": { "a": {"$nearSphere": {"coordinates": [1, 1]}}} } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": -1} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "-Infinity"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "NaN"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "minDistance": {"$numberDouble": "-NaN"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "-Infinity"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "NaN"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "maxDistance": {"$numberDecimal": "-NaN"}} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a"} }, { "$match": { "a": { "$near": {"coordinates": [1,1]}}}} ]}'); -- Tests for verifying strict index usage SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } }] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b" } }] }'); -- Test whether we can push $geonear to runtime based on the GUC SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear", "indexes": [{"key": {"a.b": 1}, "name": "ab_idx" }, {"key": {"a.geo": 1}, "name": "a_geo_idx" }, {"key": {"a.geo.type": 1}, "name": "a_geo_type_idx" }]}', true); BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); ROLLBACK; BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); ROLLBACK; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }, {"key": {"a.geo": "2dsphere"}, "name": "my_2ds_ageo_idx" }, {"key": {"a.c": "2d"}, "name": "my_2d_ac_idx" }]}', true); -- Also test multiple indexes when geospatial indexes are available BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); ROLLBACK; BEGIN; SET LOCAL documentdb.enable_force_push_geonear_index to off; SET LOCAL enable_seqscan to off; -- the seqscan cost is lower than the bitmap heap index scan at this point EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "query": { "a.b": { "$gte": 4 } } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.geo", "query": { "a.geo.type": "MultiPoint" } } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } }] }'); ROLLBACK; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','agg_geonear'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'agg_geonear') ORDER BY collection_id, index_id; \d documentdb_data.documents_4980 -- If geo indexes are available on different paths then also geonear should fail SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "not_available" } }] }'); BEGIN; -- Find using $geoNear set local citus.enable_local_execution TO OFF; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 6378.1 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 0.001 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); --min/max distance test SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 500 kms SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0, 2], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "maxDistance": 0.2, "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "maxDistance": 0.2, "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } ]}'); -- min / maxDistance Explains EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); -- Upto 500 kms EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } ]}'); -- Upto 2 cartesian distance EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } ]}'); -- Upto 0.1 radians ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'agg_geonear', '{"_id": "hashed"}', false); BEGIN; -- Find using $geoNear set local citus.enable_local_execution TO OFF; SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 6378.1 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": false, "key": "a.b", "includeLocs": "dist.location", "distanceMultiplier": 0.001 } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); --min/max distance test SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 500 kms SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0, 2], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 2 cartesian distance SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.1 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "maxDistance": 0.2, "near": [5, 6, 0.1], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6, 0.1], "maxDistance": 0.2, "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location"} } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Upto 0.2 radians -- As of version 1.16 ORDER BY clauses are not pushed to shards it can pick either 2d or 2dsphere index for use in shards and sorts the data in coordinator. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "spherical": true, "key": "a.b", "includeLocs": "dist.location" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [35, 35] }, "distanceField": "dist.calculated", "key": "a.geo"} } ]}'); -- min / maxDistance Explains EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); -- Upto 500 kms EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a.b", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 2} } ]}'); -- Upto 2 cartesian distance EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b", "spherical": true, "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 0.1} } ]}'); -- Upto 0.1 radians ROLLBACK; -- Legacy geonear spherical queries are pushed to 2dsphere index if that is the only index available SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear_legacy", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'agg_geonear_legacy') ORDER BY collection_id, index_id; SELECT documentdb_api.insert_one('db','agg_geonear_legacy','{ "_id": 1, "a": [1, 1] }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": true } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": true } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Same non spherical query doesn't work though SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear_legacy", "pipeline": [ { "$geoNear": { "near": [0, 0], "distanceField": "dist.calculated", "key": "a", "spherical": false } }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); -- Tests with other stages. $lookup SELECT documentdb_api.insert_one('db','geonear_lookup_1','{ "_id": 1, "a": [10, 10], "x": 5 }', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geonear_lookup_1", "indexes": [{"key": {"a": "2dsphere"}, "name": "lookup1_2ds_a_idx" }]}', true); SELECT documentdb_api.insert_one('db','geonear_lookup_2','{ "_id": 5, "foo": "bar", "a": [5, 5], "x": 5 }', NULL); SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "geonear_lookup_1", "pipeline": [ { "$geoNear": {"near": {"type": "Point", "coordinates": [0, 1]}, "distanceField": "dist.calculated", "spherical": true, "key": "a"}}, {"$lookup": {"from": "geonear_lookup_2", "localField": "x", "foreignField": "x", "as": "new"}}, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ] } '); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "geonear_lookup_1", "pipeline": [ { "$geoNear": {"near": {"type": "Point", "coordinates": [0, 1]}, "distanceField": "dist.calculated", "spherical": true, "key": "a"}}, {"$lookup": {"from": "geonear_lookup_2", "localField": "x", "foreignField": "x", "as": "new"}}, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ] } '); -- This fails because no valid index on geonear_lookup_2 for $geoNear SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} } ], "as": "c" } }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geonear_lookup_2", "indexes": [{"key": {"a": "2dsphere"}, "name": "lookup2_2ds_a_idx" }]}', true); -- Now it should pass SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ], "as": "c" } }]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db','{ "aggregate": "geonear_lookup_1", "pipeline": [ ' '{ "$lookup": { "from": "geonear_lookup_2", "pipeline": [{ "$geoNear": { "near": { "type": "Point", "coordinates": [5, 6] }, "distanceField": "dist.calculated", "key": "a"} }, { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ], "as": "c" } }]}'); -- Additional checks with legacy pair array BEGIN; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 16, "a": { "c": [[10, 10], [20, 20], [30, 30], [40, 40]]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 17, "a": { "c": [{"x": 10, "y": 10}, {"x": 20, "y": 20}, {"x": 30, "y": 30}, {"x": 40, "y": 40}]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 18, "a": { "c": [[]]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 19, "a": { "c": [{}]} }', NULL); SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [30, 30], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c", "spherical": true } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [30, 30], "distanceField": "dist.calculated", "key": "a.c", "spherical": true } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); ROLLBACK; BEGIN; set citus.enable_local_execution TO OFF; SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 16, "a": { "c": [[10, 10], [20, 20], [30, 30], [40, 40]]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 17, "a": { "c": [{"x": 10, "y": 10}, {"x": 20, "y": 20}, {"x": 30, "y": 30}, {"x": 40, "y": 40}]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 18, "a": { "c": [[]]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear','{ "_id": 19, "a": { "c": [{}]} }', NULL); EXPLAIN VERBOSE SELECT * FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "agg_geonear", "pipeline": [ { "$geoNear": { "near": [10, 10], "distanceField": "dist.calculated", "key": "a.c" } } , { "$addFields": { "dist.calculated": {"$round":[ { "$multiply": ["$dist.calculated", 100000] }] } } } ]}'); ROLLBACK; SELECT documentdb_api.insert_one('db','boundstest','{ "_id": 1, "geo": [ 0, 0]}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "boundstest", "indexes": [{"key": {"geo": "2d"}, "name": "2d_bounds_idx", "max": 1, "min": -1 }]}', true); -- Errors out with point not in interval based on index bounds. -- TODO: add index bound tests for sharded collection once ORDER BY pushdown to shards is supported SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [0, 6], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [5, 0], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "boundstest", "pipeline": [ { "$geoNear": { "near": [1, -1], "distanceField": "dist.calculated", "key": "geo", "includeLocs": "dist.location", "minDistance": 0, "maxDistance": 500000} } ]}'); RESET enable_seqscan; RESET documentdb.forceUseIndexIfAvailable; SELECT documentdb_api.drop_collection('db', 'boundstest') IS NOT NULL; SELECT documentdb_api.insert_one('db','valid_extract','{ "_id" : 1, "a" : { "b" : { "type" : "Point", "coordinates" : [ 10, 10 ] } } }', NULL); SELECT documentdb_api.insert_one('db','invalid_extract1','{ "_id" : 2, "a" : { "b" : { "type" : "MultiPoint", "coordinates" : [ [ 10, 10 ], [ 15, 15 ] ] } } }', NULL); -- This now fails to because no valid index, and without index this invalid extract will not happen SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "valid_extract", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b"} } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "invalid_extract1", "pipeline": [ { "$geoNear": { "near": [5, 6], "distanceField": "dist.calculated", "key": "a.b"} } ]}'); SELECT documentdb_api.drop_collection('db', 'valid_extract') IS NOT NULL; SELECT documentdb_api.drop_collection('db', 'invalid_extract1') IS NOT NULL; bson_aggregation_pipeline_tests_graphlookup.sql000066400000000000000000000163141507310017400405510ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 912000; SET documentdb.next_collection_id TO 9120; SET documentdb.next_collection_index_id TO 9120; SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 1, "userName" : "Sam" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 2, "userName" : "Alex", "friend" : "Sam" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 3, "userName" : "Jamie", "friend" : "Alex" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 4, "userName" : "Taylor", "friend" : "Alex" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 5, "userName" : "Morgan", "friend" : "Jamie" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_socialgroup', '{ "_id" : 6, "userName" : "Jordan", "friend" : "Taylor" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 0, "placeCode" : "P1", "nearby" : [ "P2", "P3" ] }'); SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 1, "placeCode" : "P2", "nearby" : [ "P1", "P4" ] }'); SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 2, "placeCode" : "P3", "nearby" : [ "P1" ] }'); SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 3, "placeCode" : "P4", "nearby" : [ "P2", "P5" ] }'); SELECT documentdb_api.insert_one('db', 'graphlookup_places', '{ "_id" : 4, "placeCode" : "P5", "nearby" : [ "P4" ] }'); SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 1, "userName" : "Sam", "homePlace" : "P1" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 2, "userName" : "Alex", "homePlace" : "P1" }'); SELECT documentdb_api.insert_one('db', 'graphlookup_visitors', '{ "_id" : 3, "userName" : "Jamie", "homePlace" : "P2" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "depthField": "stepsCount" } } ]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "depthField": "stepsCount" } } ]}'); -- $graphLookup inside $facet SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$facet": { "inner": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ] } } ]}'); -- $graphLookup inside $lookup SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$lookup": { "from": "graphlookup_socialgroup", "as": "inner", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ] } } ]}'); -- source can be sharded SELECT documentdb_api.shard_collection('db', 'graphlookup_visitors', '{ "_id": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); -- target cannot be sharded SELECT documentdb_api.shard_collection('db', 'graphlookup_places', '{ "_id": "hashed" }', false); SELECT documentdb_api.shard_collection('db', 'graphlookup_socialgroup', '{ "_id": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_socialgroup", "pipeline": [ { "$graphLookup": { "from": "graphlookup_socialgroup", "startWith": "$friend", "connectFromField": "friend", "connectToField": "userName", "as": "friendChain" } } ]}'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_visitors", "pipeline": [ { "$graphLookup": { "from": "graphlookup_places", "startWith": "$homePlace", "connectFromField": "nearby", "connectToField": "placeCode", "as": "reachablePlaces", "maxDepth": 2 } } ]}'); -- Construct random numeric relationship between 1000 users and 5 interests DO $$ DECLARE i int; BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('db', 'graphlookup_members', FORMAT('{ "_id": %s, "userName": %s, "links": [ %s, %s, %s ], "interests": [ %s, %s, %s ] }', i, i, FLOOR(RANDOM() * 10) + 1 , FLOOR(RANDOM() * 10) + 1, FLOOR(RANDOM() * 10) + 1, FLOOR(RANDOM() * 5) + 1, FLOOR(RANDOM() * 5) + 1, FLOOR(RANDOM() * 5) + 1 )::documentdb_core.bson); END LOOP; END; $$; -- $graphlookup with restrictSearchWithMatch SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "graphlookup_members", "indexes": [{"key": {"userName": 1, "interests": 1}, "name": "userName_1_interests_1" }]}', true); \d+ documentdb_data.documents_9123; ANALYZE documentdb_data.documents_9123; BEGIN; SET enable_seqscan TO off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "graphlookup_members", "pipeline": [ { "$match": { "userName": { "$lte": 50 } } }, { "$graphLookup": { "from": "graphlookup_members", "startWith": "$links", "connectFromField": "links", "connectToField": "userName", "as": "interestFriends", "restrictSearchWithMatch": { "interests" : { "$lte": 3 } } } }]}'); ROLLBACK;bson_aggregation_pipeline_tests_index_pushdown.sql000066400000000000000000000064601507310017400412550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 416000; SET documentdb.next_collection_id TO 4160; SET documentdb.next_collection_index_id TO 4160; -- create entries with accid == 1, 2, val == 3, 4 with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 1), ((s % 2) + 3), repeat(md5(random()::text), 50))::json as textVal from generate_series(1, 25000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 1, "val": 5 }'); DO $$ DECLARE v_output record; BEGIN FOR i IN 1..5 LOOP with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 1), ((s % 2) + 3), repeat(md5(random()::text), 50))::json from generate_series(1, 15000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) INTO v_output FROM r2; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 1, "val": 5 }'); -- create entries with accid == 3, 4, val == 5, 6 SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 2, "val": 6 }'); DO $$ DECLARE v_output record; BEGIN FOR i IN 1..5 LOOP with r1 AS (SELECT FORMAT('{ "accid": %s, "val": %s, "text": "%s" }', ((s % 2) + 3), ((s % 2) + 5), repeat(md5(random()::text), 50))::json from generate_series(1, 15000) s), r2 AS (SELECT json_build_object('insert', 'agg_pipeline_index_pushdown', 'documents', json_agg(r1)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) INTO v_output FROM r2; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'agg_pipeline_index_pushdown', '{ "accid": 2, "val": 6 }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "agg_pipeline_index_pushdown", "indexes": [ { "key": { "accid": 1, "val": 1 }, "name": "myIdx1" }]}', true); ANALYZE documentdb_data.documents_4160; -- First scenario with enable_indexscan to off: This technically loads 25000 rows on the bitmap scan BEGIN; set local documentdb.enableRumIndexScan to off; set local seq_page_cost to 5; set local rum.enable_semifast_gettuple to on; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "agg_pipeline_index_pushdown", "filter": { "accid": 1 }, "skip": 100, "limit": 100 }'); ROLLBACK; -- now turn on the flag - we should only load as many rows as the skip/limit BEGIN; set local documentdb.enableRumIndexScan to on; set local seq_page_cost to 5; set local rum.enable_semifast_gettuple to on; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, BUFFERS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "agg_pipeline_index_pushdown", "filter": { "accid": 1 }, "skip": 100, "limit": 100 }'); ROLLBACK; bson_aggregation_pipeline_tests_let.sql000066400000000000000000001410251507310017400370000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 413000; SET documentdb.next_collection_id TO 4130; SET documentdb.next_collection_index_id TO 4130; SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'aggregation_pipeline_let') ORDER BY object_id; -- add newField -- with let enabled EXPLAIN (VERBOSE ON) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": 20 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": 20 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": { "$avg": [ 20, 40 ] } } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varNotRef" }, "filter": {}, "let": { "varRef": { "$avg": [ 20, 40 ] } } }'); -- let support in $expr SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varRef" ]} }, "let": { "varRef": "3" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ]} }, "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varNotRef" ]} }, "let": { "varRef": "3" } }'); -- let support in $expr with nested $let SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); -- same scenario but with aggregation pipeline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ "$_id", "$$varRef" ]} } } ], "let": { "varRef": "3" } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varNotRef" ] } } } ], "let": { "varRef": 3 } }'); -- let support in $expr with nested $let SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} }, "let": { "varRef": 3 } }'); -- same scenario but with aggregation pipeline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } }} } } ], "let": { "varRef": 3 } }'); -- find/aggregate with variables referencing other variables on the same let spec should work SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]} } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }}], "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]} } }'); -- nested $let should also work SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" }, "filter": {}, "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]}, "nestedLet": {"$let": {"vars": {"add": {"$add": ["$$multiply", 1]}}, "in": "$$add"}} } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" }}], "let": { "varRef": 20, "add": {"$add": ["$$varRef", 2]}, "multiply": {"$multiply": ["$$add", 2]}, "nestedLet": {"$let": {"vars": {"add": {"$add": ["$$multiply", 1]}}, "in": "$$add"}} } }'); -- if we change the order and the variable that we're referencing is defined afterwards we should fail SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "add": {"$add": ["$$varRef", 2]}, "varRef": 20, "multiply": {"$multiply": ["$$add", 2]} } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{"$project": { "varRef" : "$$varRef", "add": "$$add", "multiply": "$$multiply" }}], "let": { "add": {"$add": ["$$varRef", 2]}, "varRef": 20, "multiply": {"$multiply": ["$$add", 2]} } }'); -- $addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$set": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); -- pipeline with inlined $project then addFields, on exclusion SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": "$$varRef", "xyz": "$_id" } } ], "let": {"varRef": 1}}'); EXPLAIN (COSTS OFF, VERBOSE ON ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "a": 0, "boolean": 0 } }, { "$addFields": { "a": 1, "xyz": "$_id" } } ], "let": {"varRef": 1}}'); -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceRoot": { "newRoot": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } }} ], "let": { "varRef": 3 } }'); -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceWith": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); -- $group (with simple aggregators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ], "let": { "varRef": 3 } }'); -- $group (with sorted accumulators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "first": { "$first" : "$a.b" } } } ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "last": { "$last" : "$a.b" } } } ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "top": {"$top": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "bottom": {"$bottom": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); -- $project SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "_id": 1, "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); -- $unionWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": { "c": "foo" }}, { "$unionWith": { "coll": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "bar": "$$varRef" } } ] } } ], "let": { "varRef": 30 }}'); -- $sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$sortByCount": { "$lt": [ "$_id", "$$varRef" ] } } ], "let": { "varRef": "2" } }'); -- $facet SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField": "myvalue" }}, { "$facet": { "sb1": [ { "$addFields": { "myVar": "$$varRef" }} ], "sb2": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ] }} ], "let": { "varRef": "2" } }'); -- $graphLookup SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 1, "name" : "Dev" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 2, "name" : "Eliot", "reportsTo" : "Dev" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 3, "name" : "Ron", "reportsTo" : "Eliot" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 4, "name" : "Andrew", "reportsTo" : "Eliot" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 5, "name" : "Asya", "reportsTo" : "Ron" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_gl', '{ "_id" : 6, "name" : "Dan", "reportsTo" : "Andrew" }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_gl", "pipeline": [ { "$graphLookup": { "from": "aggregation_pipeline_let_gl", "startWith": { "$max": [ "$reportsTo", "$$reportsTo" ] }, "connectFromField": "reportsTo", "connectToField": "name", "as": "reportingHierarchy" } } ], "let": { "reportsTo": "Dev" } }'); -- $inverseMatch SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_inv', '{ "_id" : 1, "policy" : { "name": "Dev" } }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_let_inv', '{ "_id" : 1, "policy" : { "name": "Elliot" } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_inv", "pipeline": [ { "$inverseMatch": { "path": "policy", "from": "aggregation_pipeline_let_gl", "pipeline": [{"$match": {"$expr": { "$eq": [ "$name", "$$varRef"] }} }] } }], "let": { "varRef": "Dev" } }'); -- $window operators SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 1, "a": "abc", "cost": 10, "quantity": 501, "date": { "$date": { "$numberLong": "1718841600000" } } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 2, "a": "def", "cost": 8, "quantity": 502, "date": { "$date": { "$numberLong": "1718841605000" } } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_setWindowFields','{ "_id": 3, "a": "ghi", "cost": 4, "quantity": 503, "date": { "$date": { "$numberLong": "1718841610000" } } }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_setWindowFields", "pipeline": [{"$setWindowFields": {"partitionBy": { "$concat": ["$a", "$$varRef" ] }, "output": {"total": { "$sum": "$$varRefNum"}}}}], "let": { "varRef": "prefix", "varRefNum": 2 } }'); -- $lookup SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom',' {"_id": 1, "name": "American Steak House", "food": ["filet", "sirloin"], "quantity": 100 , "beverages": ["beer", "wine"]}', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom','{ "_id": 2, "name": "Honest John Pizza", "food": ["cheese pizza", "pepperoni pizza"], "quantity": 120, "beverages": ["soda"]}', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 1, "item": "filet", "restaurant_name": "American Steak House", "qval": 100 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 2, "item": "cheese pizza", "restaurant_name": "Honest John Pizza", "drink": "lemonade", "qval": 120 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelineto','{ "_id": 3, "item": "cheese pizza", "restaurant_name": "Honest John Pizza", "drink": "soda", "qval": 140 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom_second',' {"_id": 1, "country": "America", "qq": 100 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_pipelinefrom_second','{ "_id": 2, "country": "Canada", "qq": 120 }', NULL); -- Add a $lookup with let SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQval": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- Add a $lookup with let but add a subquery stage SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$addFields": { "addedQvalBefore": "$$qval" }}, { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQvalAfter": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- nested $lookup SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- multiple variable in lookup let SELECT documentdb_api.insert('db', '{"insert":"orderscoll", "documents":[ { "_id": 1, "orderId": "A001", "productId": "P001", "quantity": 10 }, { "_id": 2, "orderId": "A002", "productId": "P002", "quantity": 5 }, { "_id": 3, "orderId": "A003", "productId": "P001", "quantity": 2 } ] }'); SELECT documentdb_api.insert('db', '{"insert":"products", "documents":[ { "_id": "P001", "name": "Product 1", "price": 100 }, { "_id": "P002", "name": "Product 2", "price": 200 } ] }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$_id", "$$productId" ] } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$_id", "$$productId" ] } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); -- only part of the pipeline uses let SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "_id": { "$gt": "P001" } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); EXPLAIN (COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "orderscoll", "pipeline": [ { "$lookup": { "from": "products", "let": { "productId": "$productId", "hello" : "parag" }, "pipeline": [ { "$match": { "_id": { "$gt": "P001" } } }, { "$project": { "name": 1, "price": 1, "_id": 0 , "field" : "$$hello" } } ], "as": "productDetails" } }, { "$unwind": "$productDetails" } ] , "cursor": {} }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }}, { "$addFields": { "addedVal": "$$qval" }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$sort": { "_id": 1 }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }}, { "$addFields": { "addedVal": "$$secondVar" }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- with an expression that returns empty, the variable should be defined as empty SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "c": "$$c" }, "filter": {}, "let": { "c": {"$getField": {"field": "c", "input": {"a": 1}}}} }'); -- $literal should be treated as literal SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "c": "$$c" }, "filter": {}, "let": { "c": {"$literal": "$$NOW"}} }'); -- these should fail - parse and validate no path, CURRENT or ROOT in let spec. SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$a" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$ROOT" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": "$$CURRENT" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField" : "$$varRef" }, "filter": {}, "let": { "varRef": { "$sum": [ "$a", "$a" ] } } }'); -- internal, lookup expression eval merge should wrap variables into $literal and if the variable evaluates to empty, should transform into $$REMOVE SELECT documentdb_api_internal.bson_dollar_lookup_expression_eval_merge('{"_id": 1, "b": "$someField"}', '{ "local_b" : "$b", "local_a": "$a" }'::documentdb_core.bson, '{}'::documentdb_core.bson); SELECT documentdb_api_internal.bson_dollar_lookup_expression_eval_merge('{"_id": 1, "b": "$someField"}', '{ "local_b" : "$b", "local_a": "$a", "local_var1": "$$var1" }'::documentdb_core.bson, '{"var1": {"$literal": "ABC"}}'::documentdb_core.bson); -- lookup with let when a field is missing the path a variable references and when that field is a string in the form of a field expression SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"1", "a": { } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"2", "b": 1 }', NULL); SELECT documentdb_api.insert_one('db','aggregation_pipeline_let_lookup_missing','{"_id":"3", "a": "$notAFieldPath" }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_lookup_missing", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_lookup_missing", "as": "res", "let": {"local_a": "$a"}, "pipeline": [ { "$match": {"$expr": {"$eq": ["$$local_a", "$a"]}}}, {"$project":{"_id": 1}} ] } } ], "cursor": {} }'); /* Shard the collections */ SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let', '{ "_id": "hashed" }', false); -- let support in $expr WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$lt": [ "$_id", "$$varNotRef" ] } }, "let": { "varRef": "3" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- let support in $expr with nested $let WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- same scenario but with aggregation pipeline WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": "3" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- let support in $expr with nested $let WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "newField": "$$varRef" }, "filter": { "$expr": { "$let": { "vars": { "varNotRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } }, "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- same scenario but with aggregation pipeline WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$match": { "$expr": { "$let": { "vars": { "varRef": 2 }, "in": { "$lt": [ { "$toInt": "$_id" }, "$$varRef" ] } } } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- find/aggregate with variables referencing other variables on the same let spec should work WITH c1 AS ( SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_pipeline_let", "projection": { "varRef": "$$varRef", "add": "$$add", "multiply": "$$multiply" }, "filter": {}, "let": { "varRef": 20, "add": { "$add": ["$$varRef", 2] }, "multiply": { "$multiply": ["$$add", 2] } } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- nested $let should also work WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$project": { "varRef": "$$varRef", "add": "$$add", "multiply": "$$multiply", "nestedLet": "$$nestedLet" } }], "let": { "varRef": 20, "add": { "$add": ["$$varRef", 2] }, "multiply": { "$multiply": ["$$add", 2] }, "nestedLet": { "$let": { "vars": { "add": { "$add": ["$$multiply", 1] } }, "in": "$$add" } } } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $addFields WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField1": "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceRoot": { "newRoot": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } }} ], "let": { "varRef": 3 } }'); -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$replaceWith": { "newField" : "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } }} ], "let": { "varRef": 3 } }'); -- $group (with simple aggregators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" } } } ], "let": { "varRef": 3 } }'); -- $group (with sorted accumulators) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "first": { "$first" : "$a.b" } } } ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$addFields": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id" : "$$varRef", "c": { "$sum": "$$varRef" }, "last": { "$last" : "$a.b" } } } ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "top": {"$top": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [{ "$set": {"newField": "new"} }, { "$sort": { "_id": 1} }, { "$group": { "_id": "$$varRef", "bottom": {"$bottom": {"output": [ "$_id" ], "sortBy": { "_id": 1 }}}}} ], "let": { "varRef": 3 } }'); -- $project WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$project": { "_id": 1, "newField": "$$varRef", "c": { "$lt": [ "$_id", "$$varRef" ] } } } ], "let": { "varRef": 3 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $unionWith WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "c": "foo" } }, { "$unionWith": { "coll": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "bar": "$$varRef" } } ] } } ], "let": { "varRef": 30 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $sortByCount WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$sortByCount": { "$lt": [ "$_id", "$$varRef" ] } } ], "let": { "varRef": "2" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $facet WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let", "pipeline": [ { "$addFields": { "newField": "myvalue" } }, { "$facet": { "sb1": [ { "$addFields": { "myVar": "$$varRef" } } ], "sb2": [ { "$group": { "_id": "$$varRef", "c": { "$sum": "$$varRef" } } } ] } } ], "let": { "varRef": "2" } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $graphLookup SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_gl', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_gl", "pipeline": [ { "$graphLookup": { "from": "aggregation_pipeline_let_gl", "startWith": { "$max": [ "$reportsTo", "$$reportsTo" ] }, "connectFromField": "reportsTo", "connectToField": "name", "as": "reportingHierarchy" } } ], "let": { "reportsTo": "Dev" } }'); -- $inverseMatch SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_inv', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_inv", "pipeline": [ { "$inverseMatch": { "path": "policy", "from": "aggregation_pipeline_let_gl", "pipeline": [{"$match": {"$expr": { "$eq": [ "$name", "$$varRef"] }} }] } }], "let": { "varRef": "Dev" } }'); -- $window operators SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_setWindowFields', '{ "_id": "hashed" }', false); -- $setWindowFields WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_setWindowFields", "pipeline": [ { "$setWindowFields": { "partitionBy": { "$concat": ["$a", "$$varRef"] }, "output": { "total": { "$sum": "$$varRefNum" } } } } ], "let": { "varRef": "prefix", "varRefNum": 2 } }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- $lookup SELECT documentdb_api.shard_collection('db', 'aggregation_pipeline_let_pipelineto', '{ "_id": "hashed" }', false); -- $lookup with nested pipeline and let WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } } }, { "$addFields": { "addedQval": "$$qval" } } ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } } } ], "cursor": {} }') ) SELECT * FROM c1 ORDER BY document -> '_id'; -- Add a $lookup with let but add a subquery stage -- $lookup with nested pipeline using $sort and $match with let WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } } } ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } } } ], "cursor": {} }') ) SELECT * FROM c1 ORDER BY document -> '_id'; SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [ { "$addFields": { "addedQvalBefore": "$$qval" }}, { "$sort": { "_id": 1 } }, { "$match": { "$expr": { "$eq": [ "$quantity", "$$qval" ] } }}, { "$addFields": { "addedQvalAfter": "$$qval" }} ], "as": "matched_docs", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- nested $lookup SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_let_pipelineto", "pipeline": [ { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom", "pipeline": [{ "$addFields": { "addedVal": "$$qval" }}, { "$lookup": { "from": "aggregation_pipeline_let_pipelinefrom_second", "localField": "qq", "foreignField": "qval", "as": "myExtra", "let": { "secondVar": "$quantity" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$qq", "$$secondVar" ] } }} ] }} ], "as": "myMatch", "localField": "restaurant_name", "foreignField": "name", "let": { "qval": "$qval" } }} ], "cursor": {} }'); -- Test for lookup with let and $match with $expr SELECT documentdb_api.insert_one('db','lookup_left',' { "_id" : 1, "item" : 1 }', NULL); SELECT documentdb_api.insert_one('db','lookup_left',' { "_id" : 2, "item" : 2 }', NULL); -- Fill right collection with more than 100 MB of data DO $$ DECLARE i int; BEGIN FOR i IN 1..50 LOOP PERFORM documentdb_api.insert_one('db', 'lookup_right', FORMAT('{ "_id": %s, "name": %s, "c": { "%s": [ %s "d" ] } }', i, i, i, REPEAT('"' || i || REPEAT('a', 1000) || '", ', 5000))::documentdb_core.bson, NULL); END LOOP; END; $$; -- This will throw size error because $match in not inlined with right query as it is not the first stage SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$project": { "c": 0 } }, { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$project": { "c": 0 } }, { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); -- This should not throw error as $match is inlined with right query SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); -- Shard left collection and right collections SET citus.explain_all_tasks to on; SET citus.max_adaptive_executor_pool_size to 1; SELECT documentdb_api.shard_collection('{ "shardCollection": "db.lookup_left", "key": { "_id": "hashed" }, "numInitialChunks": 2 }'); WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline( 'db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] } } }, { "$project": { "c": 0 } } ], "as": "myMatch", "let": { "item_name": "$item" } } } ], "cursor": {} }' ) ) SELECT * FROM c1 ORDER BY document -> '_id'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "db.lookup_right", "key": { "_id": "hashed" }, "numInitialChunks": 2 }'); WITH c1 AS ( SELECT document FROM bson_aggregation_pipeline( 'db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] } } }, { "$project": { "c": 0 } } ], "as": "myMatch", "let": { "item_name": "$item" } } } ], "cursor": {} }' ) ) SELECT * FROM c1 ORDER BY document -> '_id'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "lookup_left", "pipeline": [ { "$lookup": { "from": "lookup_right", "pipeline": [ { "$match": { "$expr": { "$eq": [ "$name", "$$item_name" ] }}}, { "$project": { "c": 0 } }], "as": "myMatch", "let": { "item_name": "$item" } }} ], "cursor": {} }'); RESET citus.explain_all_tasks; RESET citus.max_adaptive_executor_pool_size; -- query match -- ignore variableSpec (turn off all GUCs that enable bson_query_match) SET documentdb_core.enableCollation TO off; SET documentdb.enableLetAndCollationForQueryMatch TO off; SET documentdb.enableVariablesSupportForWriteCommands TO off; SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"a": "$$varRef"} }', '{ "let": {"varRef": "cat"} }', NULL); -- use variableSpec (turn GUC on) SET documentdb.enableLetAndCollationForQueryMatch TO on; -- query match: wrong access of variable in query (outside $expr) SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "$$varRef"}', '{ "let": {"varRef": "cat"} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 5}', '{"a": {"$lt": "$$varRef"} }', '{ "let": {"varRef": 10} }', NULL); -- query match: using $expr SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$eq": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "cat"} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"$expr": {"$and": [{"$eq": ["$a", "$$varRef1"] }, {"$eq": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$ne": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "dog"} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$gt": ["$a", "$$varRef"] } }', '{ "let": {"varRef": 5} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$gte": ["$a", "$$varRef"] } }', '{ "let": {"varRef": -2} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$or": [{"$lt": ["$a", "$$varRef1"] }, {"$gt": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 2} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$and": [{"$lt": ["$a", "$$varRef1"] }, {"$gt": ["$b", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 2} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": 2}', '{"$expr": {"$not": {"$lt": ["$a", "$$varRef"] } } }', '{ "let": {"varRef": 5} }', NULL); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"$expr": {"$in": ["$a", ["$$varRef1", "$$varRef2"]] } }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL); -- query match: sharded collection SELECT documentdb_api.shard_collection('db', 'coll_query_op_let', '{ "_id": "hashed" }', false); SELECT documentdb_api.insert_one('db', 'coll_query_op_let', '{"_id": 1, "a": "cat" }', NULL); SELECT documentdb_api.insert_one('db', 'coll_query_op_let', '{"_id": 2, "a": "dog" }', NULL); SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$eq": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "cat"} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$ne": ["$a", "$$varRef"] } }', '{ "let": {"varRef": "dog"} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$in": ["$a", ["$$varRef1", "$$varRef2"]] } }', '{ "let": {"varRef1": "cat", "varRef2": "dog"} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$lt": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 2} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$lte": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 2} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$gt": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$gte": ["$_id", "$$varRef"] } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$and": [{"$lt": ["$_id", "$$varRef1"] }, {"$gt": ["$_id", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 1} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$or": [{"$lt": ["$_id", "$$varRef1"] }, {"$gt": ["$_id", "$$varRef2"] } ]} }', '{ "let": {"varRef1": 2, "varRef2": 1} }', NULL) ORDER BY document->'_id'; SELECT document from documentdb_api.collection('db', 'coll_query_op_let') WHERE documentdb_api_internal.bson_query_match(document, '{"$expr": {"$not": {"$lt": ["$_id", "$$varRef"] } } }', '{ "let": {"varRef": 1} }', NULL) ORDER BY document->'_id'; RESET documentdb.enableLetAndCollationForQueryMatch; RESET documentdb.enableVariablesSupportForWriteCommands; -- let with geonear SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "agg_geonear_let", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }]}'); SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 1, "a": { "b": [ 5, 5]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 2, "a": { "b": [ 5, 6]} }', NULL); SELECT documentdb_api.insert_one('db','agg_geonear_let','{ "_id": 3, "a": { "b": [ 5, 7]} }', NULL); SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": "$location", "distanceField": "dist.calculated", "key": "a.b" } } ] } $$); SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : "Not a valid point" }, "distanceField": "dist.calculated", "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : [5, 6] }, "distanceField": "dist.calculated", "minDistance": "$p", "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); SELECT document FROM bson_aggregation_pipeline('db', $$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": { "$literal" : [5, 6] }, "distanceField": "dist.calculated", "maxDistance": { "$literal": [1, 2] }, "key": "a.b" } } ], "let": { "pointRef": [5, 6], "dist1": 0, "dist2": 2} } $$); -- a valid query SELECT document FROM bson_aggregation_pipeline('db', $spec$ { "aggregate": "agg_geonear_let", "pipeline": [ { "$geoNear": { "near": "$$pointRef", "distanceField": "dist.calculated", "minDistance": "$$dist1", "maxDistance": "$$dist2", "key": "a.b" } } ], "let": { "pointRef": [5, 5], "dist1": 0, "dist2": 2} } $spec$); bson_aggregation_pipeline_tests_maxnminn_group.sql000066400000000000000000000400721507310017400412550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1116000; SET documentdb.next_collection_id TO 11160; SET documentdb.next_collection_index_id TO 11160; SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userA", "points": 10 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userB", "points": 55 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userC", "points": 3 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T1", "person" : "userD", "points": 20 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userA", "points": 40 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userB", "points": 18 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userC", "points": 7 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test1',' { "teamId": "T2", "person" : "userD", "points": 60 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userA", "points": null }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userB", "points": 55 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userC", "points": {"$undefined":true} }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userD", "points": 20 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userA", "points": null }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T1", "person" : "userB", "points": 99 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userA", "points": null }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userB", "points": 18 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userC", "points": 7 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userD", "points": {"$undefined":true} }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userA", "points": 40 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test2',' { "teamId": "T2", "person" : "userB", "points": {"$undefined":true} }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userA", "points": 10 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userB", "points": 55 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userC", "points": [[2,4],8,1,5] }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T1", "person" : "userD", "points": 20 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userA", "points": 40 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userB", "points": [[3,6],2,7] }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userC", "points": 7 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test3',' { "teamId": "T2", "person" : "userD", "points": 60 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 1, "teamId": "T1", "person" : "userA", "points": 10 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 2, "teamId": "T1", "person" : "userB", "points": 55 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 3, "teamId": "T1", "person" : "userC", "points": 3 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 4, "teamId": "T1", "person" : "userD", "points": 20 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 5, "teamId": "T2", "person" : "userA", "points": 40 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 6, "teamId": "T2", "person" : "userB", "points": 18 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 7, "teamId": "T2", "person" : "userC", "points": 7 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test4',' { "_id": 8, "teamId": "T2", "person" : "userD", "points": 60 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userA", "points": 10 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userB", "points": [[1,2],[3,4]] }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userC", "points": "apple" }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T1", "person" : "userD", "points": 20 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userA", "points": 40 }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userC", "points": [[3,4],8,1] }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userB", "points": "port" }'); SELECT documentdb_api.insert_one('db','bson_maxminn_group_test5',' { "teamId": "T2", "person" : "userD", "points": 60 }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); /*n == 1*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 1 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 1 } } } } ] }'); /*n == 0*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 0 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 0 } } } } ] }'); /*n == -1*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": -1 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": -1 } } } } ] }'); /*n == 0.5*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 0.5 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 0.5 } } } } ] }'); /*n is a variable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": "$$nValue" } } } } ], "let": { "nValue": 3 } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": "$$nValue" } } } } ], "let": { "nValue": 3 } }'); /*input is a document*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": {"$bitAnd": ["$points", 7]}, "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": {"$bitAnd": ["$points", 7]}, "n": 3 } } } } ] }'); /*n is a object*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": {"key" :{"value": {"points": "$points" }}}, "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": {"key" :{"value": {"points": "$points" }}}, "n": 3 } } } } ] }'); /*input is a nested array*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": [[2,3], "$points"], "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": [[2,3], "$points"], "n": 3 } } } } ] }'); /*n too large */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); /*n missing */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points"} } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points"} } } } ] }'); /*input missing */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"n": 3 } } } } ] }'); /*test null/$undefined */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test2", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); /* nested array */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test3", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); /* sharded tests */ EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT documentdb_api.shard_collection('db', 'bson_maxminn_group_test4', '{ "_id": "hashed" }', false); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test4", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); /* test string and nested array */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 3 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 100 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test5", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 100 } } } } ] }'); /* $maxN are subject to the 100 MB limit */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 12345678 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$maxN": {"input": "$points", "n": 9223372036854775807 } } } } ] }'); /* $minN are subject to the 100 MB limit */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 12345678 } } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_maxminn_group_test1", "pipeline": [ { "$group": { "_id": "$teamId", "NScore":{"$minN": {"input": "$points", "n": 9223372036854775807 } } } } ] }');bson_aggregation_pipeline_tests_merge_objects_group.sql000066400000000000000000000155351507310017400422460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1220000; SET documentdb.next_collection_id TO 12200; SET documentdb.next_collection_index_id TO 12200; SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 1, "year": 2020, "category": "X", "metrics": { "2020A": 10, "2020B": 200 } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 2, "year": 2019, "category": "X", "metrics": { "2019A": 150, "2019B": 250, "2019C": 0, "2019D": 0 } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 3, "year": 2020, "category": "Y", "metrics": { "2020A": 250 } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 4, "year": 2019, "category": "Y", "metrics": { "2019C": 80, "2019D": 180 } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl1','{ "_id": 5, "year": 2020, "category": "Z", "metrics": { "2019C": 900, "2019D": 210 } }', NULL); /* running multiple $mergeObjects accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 13, "group": 1, "obj": {}, "val": null }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 14, "group": 1, "obj": { "x": 2, "y": 2 } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 15, "group": 1, "obj": { "x": 1, "z": 3, "y": null } }', NULL); SELECT documentdb_api.insert_one('db','mergeObjTestColl2','{ "_id": 16, "group": 2, "obj": { "x": 1, "y": 1 }, "val": null }', NULL); /* running multiple $mergeObjects accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj.x" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": { "result": "$obj.y" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$val" } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj" } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$obj.x" } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": { "result": "$obj.y" } } } } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl2", "pipeline": [ { "$group": { "_id": "$group", "mergedObj": { "$mergeObjects": "$val" } } } ] }'); /* running mergeObjects with intermediate size of more than 100mb */ DO $$ DECLARE i int; BEGIN -- each doc is "%s": 5 MB - ~5.5 MB & there's 25 of them FOR i IN 1..25 LOOP PERFORM documentdb_api.insert_one('db', 'mergeObjSizeTest', FORMAT('{ "_id": %s, "groupName": "A", "largeObj": { "%s": [ %s "d" ] } }', i, i, repeat('"' || i || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); END LOOP; END; $$; /* should fail with intermediate size error */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjSizeTest", "pipeline": [ { "$group": { "_id": "$groupName", "mergedObj": { "$mergeObjects": "$largeObj" } } } ] }'); /* shard collections and test for order and validations */ SELECT documentdb_api.shard_collection('db', 'mergeObjTestColl1', '{ "_id": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$category", "mergedMetrics": { "$mergeObjects": "$metrics" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "lastCategory": { "$mergeObjects": { "category": "$category" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mergeObjTestColl1", "pipeline": [ { "$sort": { "category": 1 } }, { "$group": { "_id": "$year", "shouldFail": { "$mergeObjects": "$category" } } } ] }'); select documentdb_api.drop_collection('db','mergeObjTestColl1'); select documentdb_api.drop_collection('db','mergeObjTestColl2'); select documentdb_api.drop_collection('db','mergeObjSizeTest'); bson_aggregation_pipeline_tests_percentile_median.sql000066400000000000000000000254731507310017400416730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- will move to bson_aggregation_pipeline_stage_setWindowFields.sql and remove this file after window operator is done, just like $stddevopo did SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1033000; SET documentdb.next_collection_id TO 10330; SET documentdb.next_collection_index_id TO 10330; SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 1, "group": 1, "dataVal": 111, "dataVal2": 111, "dataVal3": {"$numberDecimal": "111"}, "dataVal4": 111, "dataVal5": NaN }', NULL); SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 2, "group": 1, "dataVal": 11, "dataVal2": 11, "dataVal3": {"$numberDecimal": "11"}, "dataVal4": 11, "dataVal5": Infinity }', NULL); SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 3, "group": 1, "dataVal": 11111, "dataVal2": "string", "dataVal3": {"$numberDecimal": "11111"}, "dataVal4": {"$numberDecimal": "2E+310"}, "dataVal5": Infinity }', NULL); SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 4, "group": 1, "dataVal": 1, "dataVal2": 1, "dataVal3": {"$numberDecimal": "1"}, "dataVal4": 1, "dataVal5": -Infinity }', NULL); SELECT documentdb_api.insert_one('db','testPercentileAndMedian',' { "_id" : 5, "group": 1, "dataVal": 1111, "dataVal2": 1111, "dataVal3": {"$numberDecimal": "1111"}, "dataVal4": 1111, "dataVal5": NaN }', NULL); -- positive test case for percentile SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": null, "p": [ 0.95 ], "method": "approximate" } } } } ] }'); -- contain non-numeric value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal2", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal2", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); -- contain decimal value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal3", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal3", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); -- data value exceeds double range taken as infinity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal4", "p": [ 0.95 ], "method": "approximate" } } } } ] }'); -- handle NaN and Infinity values SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal5", "p": [ 1, 0, 0.1, 0.9, 0.4 ], "method": "approximate" } } } } ] }'); -- with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [{"$group": {"_id": null,"percentileVal": {"$percentile": {"p": "$$ps", "input": "$dataVal","method": "approximate"}}}}], "let": {"ps": [0.95, 0.5]}}'); -- positive test case for median SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate" } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": null, "method": "approximate" } } } } ] }'); -- contain non-numeric value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal2", "method": "approximate" } } } } ] }'); -- contain decimal value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal3", "method": "approximate" } } } } ] }'); -- data value exceeds double range taken as infinity SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal4", "method": "approximate" } } } } ] }'); -- handle NaN and Infinity values SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal5", "method": "approximate" } } } } ] }'); -- with $let SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [{"$group": {"_id": null,"medianVal": {"$median": {"input": "$$val","method": "approximate"}}}}], "let": {"val": 5}}'); -- negative test case for percentile -- invalid input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": 1 } } } ] }'); -- unkonwn field in input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "approximate", "unknownField": "unknownValue" } } } } ] }'); -- p value not an array SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": 1.5, "method": "approximate" } } } } ] }'); -- p value is an empty array SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [], "method": "approximate" } } } } ] }'); -- p value is an array with invalid value SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 1.5 ], "method": "approximate" } } } } ] }'); -- invalid method SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ], "method": "invalid" } } } } ] }'); -- missing input field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "p": [ 0.95 ], "method": "approximate" } } } } ] }'); -- missing p field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "method": "approximate" } } } } ] }'); -- missing method field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95 ] } } } } ] }'); -- negative test case for median -- invalid input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": 1 } } } ] }'); -- unkonwn field in input document SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate", "unknownField": "unknownValue" } } } } ] }'); -- invalid method SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "invalid" } } } } ] }'); -- missing input field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "method": "approximate" } } } } ] }'); -- missing method field SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal" } } } } ] }'); /* shard collection */ SELECT documentdb_api.shard_collection('db', 'testPercentileAndMedian', '{ "_id": "hashed" }', false); -- percentile SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "percentileVal": { "$percentile": { "input": "$dataVal", "p": [ 0.95, 0.5 ], "method": "approximate" } } } } ] }'); -- median SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testPercentileAndMedian", "pipeline": [ { "$group": { "_id": "$group", "medianVal": { "$median": { "input": "$dataVal", "method": "approximate" } } } } ] }');bson_aggregation_pipeline_tests_point_read.sql000066400000000000000000000221171507310017400403400ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 423000; SET documentdb.next_collection_id TO 4230; SET documentdb.next_collection_index_id TO 4230; SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db','aggregation_find_point_read_noncoll','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('agg_db','aggregation_find_point_read','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('agg_db', '{ "createIndexes": "aggregation_find_point_read", "indexes": [ { "key": { "$**": "text" }, "name": "my_txt" }]}', true); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('agg_db', 'aggregation_find_point_read') ORDER BY object_id; -- basic point read (colocated table) - uses fast path SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }}'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }}'); -- same point read on non-colocated table - uses slow path EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "aggregation_find_point_read_noncoll", "filter": { "_id": "2" }}'); -- now test point reads with various find features for fast path -- limit EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 0 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 1 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 2 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "limit": 3 }'); -- skip EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 1 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 2 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 3 }'); -- skip + limit EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0, "limit": 0 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 0, "limit": 1 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 1, "limit": 1 }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "skip": 2, "limit": 2 }'); -- sort EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "_id": 1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "_id": -1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": -1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": 1 } }'); -- projection EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "projection": { "a.b": 1 } }'); -- filter EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "a": { "$exists": true } }, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "a": { "$exists": false } }, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 1 } }, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 2 } }, "sort": { "a": 1 } }'); -- filter with special operators EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "$text": { "$search": "abc" } }, "sort": { "$meta": 1 } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "g": { "$nearSphere": { "$geometry": { "type" : "Point", "coordinates": [0, 0] } }} }, "sort": { "a": 1 } }'); -- filters with and/nested and. EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "$and": [ { "_id": { "$gt": "1" } }, { "$and": [ {"_id": "2" }, {"_id": { "$gt": "0" } } ] } ] } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": { "$gt": "1" }, "_id": "2", "_id": { "$gt": "0" } } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "$and": [ { "a": { "$gt": "1" } }, { "$and": [ {"_id": "2" }, {"a": { "$gt": "0" } } ] } ] } }'); EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "a": { "$gt": "1" }, "_id": "2", "a": { "$gt": "0" } } }'); -- singleBatch EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2" }, "sort": { "a": 1 }, "singleBatch": true }'); -- batchSize EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('agg_db', '{ "find": "aggregation_find_point_read", "filter": { "_id": "2", "_id": { "$gt": 2 } }, "sort": { "a": 1 }, "batchSize": 0 }');bson_aggregation_pipeline_tests_push_group.sql000066400000000000000000000106171507310017400404110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1012000; SET documentdb.next_collection_id TO 10120; SET documentdb.next_collection_index_id TO 10120; SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 1, "product" : "beer", "pricingInfo" : { "msrp": 10, "retailPrice": 15 }, "stock" : 2, "year": 2020 }', NULL); SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 2, "product" : "red wine", "pricingInfo" : { "msrp": 4, "retailPrice": 9 }, "stock" : 1, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 3, "product" : "bread", "pricingInfo" : { "msrp": 3, "retailPrice": 11 }, "stock" : 5 , "year": 2020}', NULL); SELECT documentdb_api.insert_one('db','testGroupWithPush',' { "_id" : 4, "product" : "whiskey", "pricingInfo" : { "msrp": 4, "retailPrice": 10 }, "stock" : 3 , "year": 2022}', NULL); SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 5, "product" : "bread", "pricingInfo" : { "msrp": 75, "retailPrice": 100 }, "stock" : 1, "year": 2021 }', NULL); /* running multiple $push accumulators with different expressions */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "wholesalePricing": { "$sum": ["$pricingInfo.msrp", 1] }, "qty": "$stock"} } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "retailPricing": { "$subtract": ["$pricingInfo.retailPrice", 1] }, "isBread": { "$in": ["$product", ["bread"]] } } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "shouldBeNull": { "$subtract": ["$invalidName", 12] } } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "combinedPrice": { "$add": ["$pricingInfo.msrp", "$pricingInfo.retailPrice"] } } } } } ] }'); /* shard collection */ SELECT documentdb_api.shard_collection('db', 'testGroupWithPush', '{ "_id": "hashed" }', false); /* run same $push queries to ensure consistency */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "wholesalePricing": { "$sum": ["$pricingInfo.msrp", 1] }, "qty": "$stock"} } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "retailPricing": { "$subtract": ["$pricingInfo.retailPrice", 1] }, "isBread": { "$in": ["$product", ["bread"]] } } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "shouldBeNull": { "$subtract": ["$invalidName", 12] } } } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [ { "$group": { "_id": "$year", "items": { "$push": { "combinedPrice": { "$add": ["$pricingInfo.msrp", "$pricingInfo.retailPrice"] } } } } } ] }'); -- Test for missing values SELECT documentdb_api.insert_one('db','testGroupWithPush','{ "_id" : 7, "product" : "bread", "pricingInfo" : { "msrp": 75, "retailPrice": 100 }, "year": 2021 }', NULL); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": { "qty": "$stock"} } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": "$stock" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "testGroupWithPush", "pipeline": [{"$match": {"product": "bread"}}, { "$group": { "_id": "$product", "items": { "$push": ["$stock"] } } } ] }'); bson_aggregation_pipeline_tests_redact.sql000066400000000000000000000420231507310017400374540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5150000; SET documentdb.next_collection_id TO 51500; SET documentdb.next_collection_index_id TO 51500; /* Insert data, normal case*/ SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 2, "level": "restricted", "content": "content 2", "details": { "level": "public", "value": "content 2.1", "moreDetails": { "level": "restricted", "info": "content 2.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 3, "level": "public", "content": "content 3", "details": { "level": "restricted", "value": "content 3.1", "moreDetails": { "level": "public", "info": "content 3.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 4, "content": "content 4", "details": { "level": "public", "value": "content 4.1" } }', NULL); SELECT documentdb_api.insert_one('db','redactTest1','{ "_id": 5, "level": "public", "content": "content 5", "details": { "level": "public", "value": "content 5.1", "moreDetails": [{ "level": "restricted", "info": "content 5.1.1" }, { "level": "public", "info": "content 5.1.2" }] } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest1", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "public"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest1", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "public"] }, "then": "$$DESCEND", "else": "$$PRUNE" } } } ], "cursor": {} }'); /* Insert data, add validation for array-nested subdocument, array of documents, array of arrays, empty document being returned, test DESCEND and PRUNE*/ SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 1, "level": 1, "a": { "level": 2, "b": { "level": 4, "c": { "level": 1, "d": 8 } } }, "e": 20 }', NULL); SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 2, "level": 4, "a": { "level": 3, "b": [{ "level": 1, "e": 4 }] } }', NULL); SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 3, "level": 2, "a": { "b": { "level": 3, "n": 12 } } }', NULL); SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 4, "level": 3, "a": [{ "level": 5, "b": 20 }] }', NULL); SELECT documentdb_api.insert_one('db','redactTest2','{ "_id": 5, "level": 3, "b": { "level": 3, "d": [ { "level": 1, "e": 4 }, { "level": 5, "g": 9 }, [{ "level": 1, "r": 11 }, 52, 42, 75, { "level": 5, "s": 3 }]] } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 4]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 5]}, "$$DESCEND", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest2", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 5]}, { "$literal" :"$$DESCEND"}, "$$PRUNE"] } } ], "cursor": {} }'); /* Insert data, test KEEP*/ SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 1, "level": 1, "a": { "level": 1, "b": 1 }, "c": { "level": 1, "d": 1 }}', NULL); SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 2, "level": 2, "a": { "level": 2, "b": 2 }, "c": { "level": 2, "d": 2 }}', NULL); SELECT documentdb_api.insert_one('db','redactTest3','{ "_id": 3, "level": 3, "a": { "level": 3, "b": 3 }, "c": { "level": 3, "d": 3 }}', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); /*test directly systemvariable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$PRUNE"}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$DESCEND"}], "cursor": {} }'); /*switch case*/ SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 1, "title": "Document 1", "classification": "confidential", "content": "This is confidential content.", "metadata": { "author": "Alice", "revision": 3 } }', NULL); SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 2, "title": "Document 2", "classification": "public", "content": "This is public content.", "metadata": { "author": "Bob", "revision": 1 } }', NULL); SELECT documentdb_api.insert_one('db','redactTestSwitch','{ "_id": 3, "title": "Document 3", "classification": "restricted", "content": "This content is restricted.", "metadata": { "author": "Charlie", "revision": 2 } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTestSwitch", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$classification", "confidential"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "restricted"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {} }'); /*$lookup $let and $redact example*/ SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 1, "name": "Alice"}', NULL); SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 2, "name": "Bob"}', NULL); SELECT documentdb_api.insert_one('db','redactUsers','{ "_id": 3, "name": "Charlie"}', NULL); SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 1, "user_id": 1, "order_amount":150, "status": "completed"}', NULL); SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 2, "user_id": 1, "order_amount":200, "status": "pending"}', NULL); SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 3, "user_id": 2, "order_amount":500, "status": "completed"}', NULL); SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 4, "user_id": 2, "order_amount":50, "status": "completed"}', NULL); SELECT documentdb_api.insert_one('db','redactOrders','{ "_id": 5, "user_id": 3, "order_amount":300, "status": "pending"}', NULL); /* $redact with $let*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$$ROOT.order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /* add $let with the same level with $lookup, different variable with $let in $redact*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id" }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /* two level $let has the same variable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id", "totalAmount": { "$sum": "$user_orders.order_amount" } }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$gt": [ "$$totalAmount", 40 ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /* redact use top level $let*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactUsers", "pipeline": [ { "$lookup": { "from": "redactOrders", "localField": "_id", "foreignField": "user_id", "as": "user_orders", "let": { "user_id": "$_id" }, "pipeline": [ { "$redact": { "$cond": { "if": { "$let": { "vars": { "totalAmount": { "$sum": "$order_amount" } }, "in": { "$and": [ { "$gt": [ "$$totalAmount", 40 ] }, { "$lt": [ "$$user_id", 2 ] } ] } } }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /*facet with redact test case user data*/ SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 1, "name": "Alice", "email": "alice@example.com", "age": 25 }', NULL); SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 2, "name": "Bob", "email": "bob@example.com", "age": 25 }', NULL); SELECT documentdb_api.insert_one('db', 'facetUsers', '{ "_id": 3, "name": "Charlie", "email": "charlie@example.com", "age": 30 }', NULL); /*facet with redact case, one is empty array and the other is not*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "facetUsers", "pipeline": [ { "$facet": { "ageGroup": [ { "$group": { "_id": "$age", "users": { "$push": "$name" } } } ], "redactEmail": [ { "$redact": { "$cond": { "if": { "$eq": ["$email", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "facetUsers", "pipeline": [ { "$facet": { "ageGroup": [ { "$group": { "_id": "$age", "users": { "$push": "$name" } } } ], "redactEmail": [ { "$redact": { "$cond": { "if": { "$eq": ["$email", "alice@example.com"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /*graphLookup with redact test case employee data*/ SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 1, "employee_id": 1, "name": "Alice", "manager_id": null, "email": "alice@example.com" }', NULL); SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 2, "employee_id": 2, "name": "Bob", "manager_id": 1, "email": "bob@example.com" }', NULL); SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 3, "employee_id": 3, "name": "Charlie", "manager_id": 1, "email": "charlie@example.com" }', NULL); SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 4, "employee_id": 4, "name": "David", "manager_id": 2, "email": "david@example.com" }', NULL); SELECT documentdb_api.insert_one('db', 'graphLookupEmployee', '{ "_id": 5, "employee_id": 5, "name": "Eve", "manager_id": 2, "email": "eve@example.com" }', NULL); /*graphLookup with redact test case, prune employee do not have subordinates*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "graphLookupEmployee", "pipeline": [ { "$graphLookup": { "from": "graphLookupEmployee", "startWith": "$employee_id", "connectFromField": "employee_id", "connectToField": "manager_id", "as": "subordinates" } }, { "$redact": { "$cond": { "if": { "$eq": [{ "$size": "$subordinates" }, 0] }, "then": "$$PRUNE", "else": "$$KEEP" } } } ], "cursor": {} }'); /*unionWith with redact test case user and employee data*/ SELECT documentdb_api.insert_one('db', 'unionWithUsers', '{ "_id": 1, "name": "Alice", "role": "admin", "address": { "city": "New York", "zip": "10001" } }', NULL); SELECT documentdb_api.insert_one('db', 'unionWithUsers', '{ "_id": 2, "name": "Bob", "role": "user", "address": { "city": "Los Angeles", "zip": "90001" } }', NULL); SELECT documentdb_api.insert_one('db', 'unionWithEmployees', '{ "_id": 101, "name": "Charlie", "role": "admin", "department": "HR", "address": { "city": "San Francisco", "zip": "94101" } }', NULL); SELECT documentdb_api.insert_one('db', 'unionWithEmployees', '{ "_id": 102, "name": "David", "role": "user", "department": "IT", "address": { "city": "Chicago", "zip": "60601" } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "unionWithUsers", "pipeline": [ { "$unionWith": { "coll": "unionWithEmployees", "pipeline": [ { "$redact": { "$cond": { "if": { "$gt": ["$_id", 101] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ] } } ], "cursor": {} }'); /*negative case*/ /*redact input as number*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": 1 }], "cursor": {} }'); /*redact input as string*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "string" }], "cursor": {} }'); /*redact input as boolean*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": true }], "cursor": {} }'); /*redact input system variable not KEEP or PRUNE or DESCEND*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$NOTVALID"}], "cursor": {} }'); /*redact input as array*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": ["$$KEEP", "$$PRUNE"]} ], "cursor": {} }'); /*redact input cond return not KEEP or PRUNE or DESCEND*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$NOTVALID"} } } ], "cursor": {} }'); /*throw exception when $$KEEP $$PRUEN $$DESCEND are used in other stages*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"filteredField" : "$$PRUNE"} } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"newField" : "$$DESCEND"} } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$project": {"newField" :{ "$add":["$$KEEP",1]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$addFields": {"newField" : "$$DESCEND"} } ], "cursor": {} }'); /*EXPLAIN*/ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$PRUNE"} } } ] }'); /*sharded collection*/ SELECT shard_collection('db', 'redactTest3', '{ "amount": "hashed" }', false); /*positive cases:*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 1]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 2]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": [{"$lte": ["$level", 3]}, "$$KEEP", "$$PRUNE"] } } ], "cursor": {} }'); /*test directly systemvariable*/ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" }], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$PRUNE"}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$DESCEND"}], "cursor": {} }'); /*EXPLAIN*/ EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": "$$KEEP" } ] }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "redactTest3", "pipeline": [ { "$redact": { "$cond": {"if": {"$eq": ["$level", 1]}, "then": "$$KEEP", "else": "$$PRUNE"} } } ] }'); bson_aggregation_pipeline_tests_stddevpopsamp_group.sql000066400000000000000000000313451507310017400423240ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1015000; SET documentdb.next_collection_id TO 10150; SET documentdb.next_collection_index_id TO 10150; SELECT documentdb_api.insert_one('db','tests',' { "_id" : 1, "group": 1, "num" : 4 }'); SELECT documentdb_api.insert_one('db','tests',' { "_id" : 2, "group": 1, "num" : 7 }'); SELECT documentdb_api.insert_one('db','tests',' { "_id" : 3, "group": 1, "num" : 13 }'); SELECT documentdb_api.insert_one('db','tests',' { "_id" : 4, "group": 1, "num" : 16 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /* empty collection */ SELECT documentdb_api.insert_one('db','empty_col',' {"num": {} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_col", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "empty_col", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*single number value in collection*/ SELECT documentdb_api.insert_one('db','single_num',' {"num": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*two number values in collection*/ SELECT documentdb_api.insert_one('db','two_nums',' {"num": 1 }'); SELECT documentdb_api.insert_one('db','two_nums',' {"num": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "two_nums", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "two_nums", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*single char value in collection*/ SELECT documentdb_api.insert_one('db','single_char',' {"num": "a" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*single number and single char in collection*/ SELECT documentdb_api.insert_one('db','single_num_char',' {"num": 1 }'); SELECT documentdb_api.insert_one('db','single_num_char',' {"num": "a" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_num_char", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*number and char mixed in collection*/ SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": 1 }'); SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": "a" }'); SELECT documentdb_api.insert_one('db','num_char_mixed',' {"num": 1 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_char_mixed", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_char_mixed", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*string in collection*/ SELECT documentdb_api.insert_one('db','num_string',' {"num": "string1" }'); SELECT documentdb_api.insert_one('db','num_string',' {"num": "string2" }'); SELECT documentdb_api.insert_one('db','num_string',' {"num": "strign3" }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_string", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_string", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*large number values in collection*/ SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000004"} }'); SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000007"} }'); SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000013"} }'); SELECT documentdb_api.insert_one('db', 'large_num',' {"num": {"$numberLong": "10000000016"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "large_num", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*double in collection*/ SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "4.0"} }'); SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "7.0"} }'); SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "13.0"} }'); SELECT documentdb_api.insert_one('db', 'double',' {"num": {"$numberDouble": "16.0"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "double", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "double", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*numberDecimal in collection*/ SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "4"} }'); SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "7"} }'); SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "13"} }'); SELECT documentdb_api.insert_one('db', 'num_decimal',' {"num": {"$numberDecimal": "16"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_decimal", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_decimal", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*NaN and Infinity*/ SELECT documentdb_api.insert_one('db', 'single_nan',' {"num": {"$numberDecimal": "NaN" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); SELECT documentdb_api.insert_one('db', 'nans',' {"num": {"$numberDecimal": "NaN" } }'); SELECT documentdb_api.insert_one('db', 'nans',' {"num": {"$numberDecimal": "-NaN"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nans", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "nans", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 4 }'); SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 7 }'); SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 13 }'); SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : {"$numberDecimal": "NaN" } }'); SELECT documentdb_api.insert_one('db','mix_nan',' { "num" : 16 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_nan", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); SELECT documentdb_api.insert_one('db', 'single_infinity',' {"num": {"$numberDecimal": "Infinity"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_infinity", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "single_infinity", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); SELECT documentdb_api.insert_one('db', 'infinities',' {"num": { "$numberDecimal": "Infinity" } }'); SELECT documentdb_api.insert_one('db', 'infinities',' {"num": { "$numberDecimal": "-Infinity" } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "infinities", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "infinities", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 4 }'); SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 7 }'); SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 13 }'); SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : { "$numberDecimal": "Infinity" } }'); SELECT documentdb_api.insert_one('db','mix_inf',' { "num" : 16 }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_inf", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "mix_inf", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*number overflow*/ SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "100000004"} }'); SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "10000000007"} }'); SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "1000000000000013"} }'); SELECT documentdb_api.insert_one('db','num_overflow',' { "num" : {"$numberDecimal": "1000000000000000000"} }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_overflow", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_overflow", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /*array test*/ SELECT documentdb_api.insert_one('db','num_array',' { "num" : [4, 7, 13, 16] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_array", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "num_array", "pipeline": [ { "$group": { "_id": 1, "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /* shard collection */ SELECT documentdb_api.shard_collection('db', 'tests', '{ "_id": "hashed" }', false); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": "$num" } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": "$num" } } } ] }'); /* nagetive tests */ SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevPop": ["$num"] } } } ] }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "tests", "pipeline": [ { "$group": { "_id": "$group", "stdDev": { "$stdDevSamp": ["$num"] } } } ] }'); bson_aggregation_pipeline_tests_top_bottom_group.sql000066400000000000000000000331461507310017400416220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 10120000; SET documentdb.next_collection_id TO 101200; SET documentdb.next_collection_index_id TO 101200; SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Alpha", "team": "T1", "points": 10 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Beta", "team": "T1", "points": 5 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Gamma", "team": "T1", "points": 7 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Delta", "team": "T1", "points": 20 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Epsilon", "team": "T1"}', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Zeta", "team": "T1", "points": [3, 2] }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Alpha", "team": "T2", "points": {"$undefined":true} }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Beta", "team": "T2", "points": 15 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Gamma", "team": "T2", "points": 18 }', NULL); SELECT documentdb_api.insert_one('db','pipeline_group_tests','{ "user": "Delta", "team": "T2", "points": 8 }', NULL); /* Negative tests */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ]}}}} ] }'); -- missing sortBy SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"sortBy": { "points": 1 }}}}} ] }'); -- missing output SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"sortBy": { "points": 1 }, "n": 1}}}} ] }'); -- n isn't supported with $top SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ]}}}} ] }'); -- missing sortBy SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"sortBy": { "points": 1 }}}}} ] }'); -- missing output SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"sortBy": { "points": 1 }, "n": 1}}}} ] }'); -- n isn't supported with $top SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "n": 1}}}} ] }'); -- missing sortBy SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"sortBy": {"points": 1}, "n": 1}}}} ] }'); -- missing output SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); -- missing n SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": "a"}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$undefined": true}}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$numberDecimal": "Infinity"}}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": -1}}}} ] }'); -- n is negative SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 0.5}}}} ] }'); -- n is not an integer SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "n": 1}}}} ] }'); -- missing sortBy SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"sortBy": {"points": 1}, "n": 1}}}} ] }'); -- missing output SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); -- missing n SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": "a"}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$undefined": true}}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": {"$numberDecimal": "Infinity"}}}}} ] }'); -- n is not a number SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": -1}}}} ] }'); -- n is negative SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 0.5}}}} ] }'); -- n is not an integer SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": 1, "n": 1}}}} ] }'); -- sortBy is not an object /* $top operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$sort": {"user": 1}}, {"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); -- different sort in sortBy stage but documents in output field are sorted by $top spec /* $topN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$sort": {"user": 1}}, {"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); -- different sort in sortBy stage but documents in output field are sorted by $top spec /* $bottom operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); /* $bottomN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); /* shard collection */ SELECT documentdb_api.shard_collection('db', 'pipeline_group_tests', '{ "_id": "hashed" }', false); /* run same queries to ensure consistency */ /* $top operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$top": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); /* $topN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$topN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); /* $bottom operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottom": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }}}}}] }'); /* $bottomN operator with $group */ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [ {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": 1 }, "n": 3}}}} ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$match" : { "team" : "T1" }}, {"$group": {"_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "pipeline_group_tests", "pipeline": [{"$group": { "_id": "$team", "user": {"$bottomN": {"output": [ "$user", "$points" ], "sortBy": { "points": -1 }, "n": 3}}}}] }');bson_aggregation_pipeline_tests_vector_hnsw.sql000066400000000000000000003565351507310017400405730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- init a test user and set vector pre-filtering on SELECT current_user as original_test_user \gset CREATE ROLE test_filter_user_hnsw WITH LOGIN INHERIT SUPERUSER CREATEDB CREATEROLE IN ROLE :original_test_user; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8200000; SET documentdb.next_collection_id TO 8200; SET documentdb.next_collection_index_id TO 8200; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents(collectionName text, beginId integer, numDocuments integer, docPerBatch integer, numDimensions integer DEFAULT 3) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN if numDimensions < 3 then RAISE EXCEPTION 'Number of dimensions must be greater than or equal to 3'; end if; RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS ( SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), rv AS (SELECT counter, CASE WHEN numDimensions > 3 THEN array_to_string(array_agg(random()), ',') ELSE '' END AS vect FROM r1 LEFT JOIN generate_series(1, GREATEST(numDimensions-3, 0)) ON true GROUP BY counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || CASE WHEN numDimensions > 3 THEN ', ' || vect ELSE '' END || ' ] }') AS documentValue FROM rv order by counter), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------------------------------------------------------------- -- HNSW -- HNSW create index, error cases SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector'); ANALYZE; -- by default, HNSW index is enabled SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "unknown", "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": -4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 101, "efConstruction": 160, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": -16, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 40, "efConstruction": 1001, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": "40", "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 40, "efConstruction": "16", "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "unknown", "dimensions": 3 } } ] }', true); -- efConstruction is less than 2*m SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 64, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "efConstruction": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "unknown", "similarity": "IP", "dimensions": 3 } } ] }', true); -- check dimensions exceeds 2000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 2001 } } ] }', true); SET documentdb.enableVectorHNSWIndex = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": -4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); SET documentdb.enableVectorHNSWIndex = on; -- HNSW create index, success cases SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "efConstruction": 32, "similarity": "IP", "dimensions": 3 } } ] }', true); -- HNSW search, success cases CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 2 } } } ], "cursor": {} }'); COMMIT; BEGIN; SET LOCAL enable_seqscan = off; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 2 } } } ], "cursor": {} }'); ROLLBACK; -- HNSW search, error cases SET documentdb.enableVectorHNSWIndex = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10000000 } } } ], "cursor": {} }'); SET documentdb.enableVectorHNSWIndex = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10000000 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": -5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": "5" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5.5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": -1, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": "1", "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 0, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1 } } } ], "cursor": {} }'); -- check dimension of query vector exceeds 2000 DO $$ DECLARE dim_num integer := 2001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; DO $$ DECLARE dim_num integer := 2000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.1, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.8, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); -- efSearch = 1, get 1 document BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); COMMIT; -- efSearch = 3, get 3 documents BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 3 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 5, "path": "v", "efSearch": 3 } } } ], "cursor": {} }'); COMMIT; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); ---------------------------------------------------------------------------------------------------- -- turn on vector pre-filtering, check dynamic efSearch select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 1, 150, 2000); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_efsearch", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_efsearch'); ANALYZE; -- 150 less than 10000 documents, use efConstruction as efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- check efSeache with score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- generate 1000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 151, 1000, 2000); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- more than 10000 and less than 1M documents, use default efSearch 40 -- generate 9000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_efsearch', 1151, 9000, 2000); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_efsearch", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; ---------------------------------------------------------------------------------------------------- -- hnsw search with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_filter'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); SET documentdb.enableVectorPreFilter = on; -- filter without index SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); ANALYZE; -------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } } ], "cursor": {} }'); -------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); -- check the vector index is forced to be used ALTER ROLE test_filter_user_hnsw SET documentdb.enableVectorPreFilter = "True"; SELECT current_setting('citus' || '.next_shard_id') as vector_citus__next_shard_id \gset SELECT current_setting('documentdb' || '.next_collection_id') as vector__next_collection_id \gset SELECT current_setting('documentdb' || '.next_collection_index_id') as vector__next_collection_index_id \gset \c - test_filter_user_hnsw SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } } ], "cursor": {} }'); -- default efSearch = efConstruction(16) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } } } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } } ], "cursor": {} }'); \c - :original_test_user SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT set_config('citus' || '.next_shard_id', '' || :vector_citus__next_shard_id, FALSE); SELECT set_config('documentdb' || '.next_collection_id', '' || :vector__next_collection_id, FALSE); SELECT set_config('documentdb' || '.next_collection_index_id', '' || :vector__next_collection_index_id, FALSE); -------------------------------------------------- -- hnsw search: pre-filtering match with different indexes -- "filter": {"meta.a": [ { "b" : 3 } ]}, match with idx_meta.a BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- "filter": {"meta": { "a" : [ { "b" : 3 } ] }, match with documentIndex_meta BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- "filter": {"meta.a.b": 3 }, match with idx_meta.a.b BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- hnsw filter string: default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string: with $and, efSearch = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string: with $and, efSearch = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string: with $or, efSearch = 3, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 3 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string: with $or, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string: with $or, $and, efSearch = 10, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "efSearch": 10 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "efSearch": 10 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter string:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- hnsw filter number, with default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter number, with $and, efSearch = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter number, with $and, default efSearch, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter number, with $or, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter number, with $or, default efSearch, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter number: with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$eq": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lte": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$ne": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$in": [ 2,3 ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$nin": [ 2 ] } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gt": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lt": 2 } }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- hnsw filter boolean: with default efSearch BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter boolean, with efSearch = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter boolean, with c = false, efSearch = 1, match 2 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 1 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw filter boolean, with c = false, efSearch = 3, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "efSearch": 3 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: filter boolean, with $eq, $ne, $in, $nin, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$eq": true}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$ne": true}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$in": [true]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$nin": [true]}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- hnsw search: with filter, different distance metric -- hnsw search: cosine similarity CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index_cos", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: inner product CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index_cos"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index_ip", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: restore to euclidean distance CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_filter", "index": "hnsw_index_ip"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; -------------------------------------------------- -- hnsw search: with filter and score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and score projection, efSearch = 4, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and score projection, efSearch = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and score projection, $ne, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and score projection, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- hnsw search: with filter and shard -- TODO, current implementation does not support sharded collection, need to fix in part 3 BEGIN; SET LOCAL client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_hnsw_filter', '{"_id":"hashed"}', false); END; ANALYZE; -- hnsw search: with filter and shard, default efSearch, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and shard, $ne, efSearch = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and shard, number, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and shard, boolean, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- hnsw search: with filter and shard, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "efSearch": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; SET documentdb.enableVectorPreFilter = off; -------------------------------------------------- -- create hnsw index and search with nProbes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5, "efSearch": 10 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 5, "efSearch": 10 } } } ], "cursor": {} }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); -- create ivf index and search with efSearch SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 10, "nProbes": 5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10, "nProbes": 5 } } } ], "cursor": {} }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); -- create ivf index and search with efSearch, hnsw index is disabled SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 5 } } } ], "cursor": {} }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); select documentdb_api.drop_collection('db', 'aggregation_pipeline_vector'); ---------------------------------------------------------------------------------------------------- -- Vector search with empty vector field -- hnsw SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_empty_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "vectorIndex", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 4 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 3, "a": "some sentence" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 4, "a": "some other sentence", "v": [3, 2, 1 ] }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_empty_vector'); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 16 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 16 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; SELECT drop_collection('db','aggregation_pipeline_empty_vector'); DROP ROLE IF EXISTS test_filter_user_hnsw; ---------------------------------------------------------------------------------------------------- -- exact search SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_hnsw_exact', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector_hnsw_exact'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); ANALYZE; -- error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": {} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": 123 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": "abc" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": [1,2,3] } } } ], "cursor": {} }'); -- COS BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- IP CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_hnsw_exact", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- L2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_hnsw_exact", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_hnsw_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- efSearch BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": true } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); ROLLBACK; -- exact = false BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": false } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": false } } } ], "cursor": {} }'); ROLLBACK; -- filter:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- shard SELECT documentdb_api.shard_collection('db','aggregation_pipeline_vector_hnsw_exact', '{"_id":"hashed"}', false); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- shard is not supported with filter yet BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_hnsw_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "efSearch": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; SELECT drop_collection('db','aggregation_pipeline_vector_hnsw_exact'); ---------------------------------------------------------------------------------------------------- -- Half vector -- hnsw SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_halfvec'); -- error cases, create index SET documentdb.enableVectorCompressionHalf = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "none" } } ] }', true); SET documentdb.enableVectorCompressionHalf = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": "binary" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": "scalar" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": 123 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": {} } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001, "compression": ["half"] } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2001 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2000 } } ] }', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 2.5 } } } ], "cursor": {} }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4001, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4000, "compression": "half" } } ] }', true); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); -- check index size of half vector and full vector SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_halfvec'); SELECT setseed(0); SELECT batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_halfvec', 10, 2000, 500, 1536); SELECT setseed(0); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 1536, "compression": "half" } } ] }', true); ANALYZE; SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_fullvec'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_fullvec'); SELECT setseed(0); SELECT batch_insert_testing_vector_documents('aggregation_pipeline_hnsw_fullvec', 10, 2000, 500, 1536); SELECT setseed(0); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_fullvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "full_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 1536 } } ] }', true); ANALYZE; -- The index size of table includes meta pages(2 pages, 16kB) -- Each document has 1536 dimensions, therefore the vector index for each document is -- for half vector: 1536 * 2 = 3072 bytes, will take 1/2 page(<4kB), total 1000 pages -- for full vector: 1536 * 4 = 6144 bytes, will take 1 page(<8kB), total 2000 pages SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_hnsw_halfvec', 1024), '{"result":"$indexSizes"}'); SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_hnsw_fullvec', 1024), '{"result":"$indexSizes"}'); -- full vector index size - half vector index size -- (# of documents) * 0.5 * page size = 2000 * 0.5 * 8 = 8000kB with half_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8205','SELECT pg_indexes_size(''%s'')') as half_vec_size), full_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8206','SELECT pg_indexes_size(''%s'')') as full_vec_size) SELECT (full_vec_size.vec_size - half_vec_size.vec_size) as diff FROM half_vec_size, full_vec_size; SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_halfvec'); SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_fullvec'); SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_halfvec'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_hnsw_halfvec'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); ANALYZE; -- check half vector search, L2 similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); -- oversampling, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0.5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": "0" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": [] } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 1.5 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 1.5 } } } ], "cursor": {} }'); ROLLBACK; -- filter BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); -- check filter with half vector, COS similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_hnsw_halfvec", "index": "half_index"}'); -- check exact search with half vector, IP similarity SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 16, "efConstruction": 64, "similarity": "IP", "dimensions": 3, "compression": "half" } } ] }', true); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- oversampling failed with exact search SET documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "efSearch": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- filter BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lte": "some sentence"}}, "efSearch": 100 } } } ], "cursor": {} }'); ROLLBACK; -- check value of vector is out of range -- create index failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 22222, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "larage_vector": [22222222222222.0, 5.0, 0.1 ] }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 3 } } ] }', true); -- search failed SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 11111111111111.0, 4.9, 1.0 ], "k": 4, "path": "v", "efSearch": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); -- insert failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_hnsw_halfvec', '{ "_id": 33333, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [33333333333333.0, 5.0, 0.1 ] }'); -- check dimension of query vector exceeds 4000 DO $$ DECLARE dim_num integer := 4001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; DO $$ DECLARE dim_num integer := 4000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_hnsw_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; SELECT documentdb_api.drop_collection('db','aggregation_pipeline_hnsw_halfvec'); ---------------------------------------------------------------------------------------------------- -- PQ vector -- hnsw SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_hnsw_pq'); -- error cases, create index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3, "compression": "pq" } } ] }', true); SET documentdb.enableVectorCompressionPQ = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 4000, "compression": "pq" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_hnsw_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 2000, "compression": "pq" } } ] }', true); SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api.drop_collection('db', 'aggregation_pipeline_hnsw_pq'); DROP FUNCTION IF EXISTS batch_insert_testing_vector_documents;bson_aggregation_pipeline_tests_vector_hnsw_planner.sql000066400000000000000000000130401507310017400422670ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8400000; SET documentdb.next_collection_id TO 8400; SET documentdb.next_collection_index_id TO 8400; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents_hnsw_planner(collectionName text, beginId integer, numDocuments integer, docPerBatch integer) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS (SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || ' ] }') AS documentValue FROM r1), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('vector_db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------------------------------------------------------------- -- HNSW -- HNSW create index, error cases SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('vector_db', 'agg_vector_hnsw_planner', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); ANALYZE; -- HNSW search, success cases SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; -- should not go via Citus planner (with pushdown to index) set documentdb.enable_force_push_vector_index to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); SELECT batch_insert_testing_vector_documents_hnsw_planner('agg_vector_hnsw_planner', 10, 100, 10); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1 } } } ], "cursor": {} }'); -- create indexes for vector filter SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "a": 1 }, "name": "a_1" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "b": 1 }, "name": "b_1" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('vector_db', '{ "createIndexes": "agg_vector_hnsw_planner", "indexes": [ { "key": { "c": 1 }, "name": "c_1" } ] }', true); set documentdb.enableVectorPreFilter to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "a": { "$lt": "s" }} } } } ], "cursor": {} }'); set documentdb.enableVectorPreFilterV2 to on; -- This is currently a post-filter and will not use the filter index. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "a": { "$lt": "s" }} } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('vector_db', '{ "aggregate": "agg_vector_hnsw_planner", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "efSearch": 1, "filter": { "_id": { "$lt": 5 }} } } } ], "cursor": {} }'); bson_aggregation_pipeline_tests_vector_ivf.sql000066400000000000000000003443141507310017400403700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- init a test user and set vector pre-filtering on SELECT current_user as original_test_user \gset CREATE ROLE test_filter_user_ivf WITH LOGIN INHERIT SUPERUSER CREATEDB CREATEROLE IN ROLE :original_test_user; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8100000; SET documentdb.next_collection_id TO 8100; SET documentdb.next_collection_index_id TO 8100; CREATE OR REPLACE FUNCTION batch_insert_testing_vector_documents(collectionName text, beginId integer, numDocuments integer, docPerBatch integer, numDimensions integer DEFAULT 3) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE endId integer := beginId + numDocuments - 1; batchCnt integer := 0; batchIdx integer := 0; batchBeginId integer := 0; batchEndId integer := 0; v_insertSpec bson; v_resultDocs bson; BEGIN if numDimensions < 3 then RAISE EXCEPTION 'Number of dimensions must be greater than or equal to 3'; end if; RAISE NOTICE 'Inserting % documents into %', numDocuments, collectionName; if numDocuments%docPerBatch = 0 then batchCnt := numDocuments/docPerBatch; else batchCnt := numDocuments/docPerBatch + 1; end if; RAISE NOTICE 'Begin id: %, Batch size: %, batch count: %', beginId, docPerBatch, batchCnt; WHILE batchIdx < batchCnt LOOP batchBeginId := beginId + batchIdx * docPerBatch; batchEndId := beginId + (batchIdx + 1) * docPerBatch - 1; if endId < batchEndId then batchEndId := endId; end if; WITH r1 AS ( SELECT counter from generate_series(batchBeginId, batchEndId) AS counter), rv AS (SELECT counter, CASE WHEN numDimensions > 3 THEN array_to_string(array_agg(random()), ',') ELSE '' END AS vect FROM r1 LEFT JOIN generate_series(1, GREATEST(numDimensions-3, 0)) ON true GROUP BY counter), r2 AS ( SELECT ('{ "_id": ' || counter || ', "a": "some sentence", "v": [ ' || 10+counter || ', ' || 15+counter || ', ' || 1.1+counter || CASE WHEN numDimensions > 3 THEN ', ' || vect ELSE '' END || ' ] }') AS documentValue FROM rv order by counter), r3 AS ( SELECT collectionName as insert, array_agg(r2.documentValue::bson) AS documents FROM r2) SELECT row_get_bson(r3) INTO v_insertSpec FROM r3; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); batchIdx := batchIdx + 1; END LOOP; END; $fn$; --------------------------------------------------------------------------------------------------------------------------- -- IVF SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); -- check dimensions exceeds 2000 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 2001 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); -- numLists <= data size, using data as centroids, to avoid randomized centroids generated by pgvector ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 2 } } } ], "cursor": {} }'); COMMIT; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); COMMIT; -- IVF search, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 10000000 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": -5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": "5" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 5.5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": -1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": "1", "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 0, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1 } } } ], "cursor": {} }'); -- check dimension of query vector exceeds 2000 DO $$ DECLARE dim_num integer := 2001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; DO $$ DECLARE dim_num integer := 2000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1.8, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); -- default nProbes = numLists(2) BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v" } } } ], "cursor": {} }'); COMMIT; -- numLists > data size, pgvector will generate randomized centroids, using original vector data to query CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1000, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1000 } } } ], "cursor": {} }'); COMMIT; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); COMMIT; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector'); BEGIN; SET LOCAL enable_seqscan to off; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "nProbes": 1 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ROLLBACK; select documentdb_api.drop_collection('db', 'aggregation_pipeline_vector'); ---------------------------------------------------------------------------------------------------- -- turn on vector pre-filtering, check dynamic nProbes select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 1, 150, 2000); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_nprobes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 150, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_nprobes'); ANALYZE; -- 150 less than 10000 documents, use numLists as nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- check nProbes with score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] }}}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- generate 1000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 151, 1000, 2000); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- more than 10000 and less than 1M documents, nProbes = 10000/(numOfRows/numlist) = 10000/(10150/150) = 148 -- generate 9000 documents and insert into collection select batch_insert_testing_vector_documents('aggregation_pipeline_ivf_nprobes', 1151, 9000, 2000); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SET LOCAL documentdb.enableVectorCalculateDefaultSearchParam = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; -- nProbes = 10000/(numOfRows/numlist) = 10000/(10150/1) = 1 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_nprobes", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_nprobes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_nprobes", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ] } } } ], "cursor": {} }'); ROLLBACK; ---------------------------------------------------------------------------------------------------- -- ivf search with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_filter'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); SET documentdb.enableVectorPreFilter = on; -- filter without index SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a.b": 3} } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some sentence" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); ANALYZE; -------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } } ], "cursor": {} }'); -------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; -- check the vector index is forced to be used ALTER ROLE test_filter_user_ivf SET documentdb.enableVectorPreFilter = "True"; SELECT current_setting('citus' || '.next_shard_id') as vector_citus__next_shard_id \gset SELECT current_setting('documentdb' || '.next_collection_id') as vector__next_collection_id \gset SELECT current_setting('documentdb' || '.next_collection_index_id') as vector__next_collection_index_id \gset \c - test_filter_user_ivf SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } } ], "cursor": {} }'); -- default nProbes = numLists(4) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] } ] } } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence"}}, { "meta.a": [ { "b" : 3 } ] } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence"}}, { "meta.a": [ { "b" : 3 } ] } ] }, "nProbes": 100 } } } ], "cursor": {} }'); \c - :original_test_user SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT set_config('citus' || '.next_shard_id', '' || :vector_citus__next_shard_id, FALSE); SELECT set_config('documentdb' || '.next_collection_id', '' || :vector__next_collection_id, FALSE); SELECT set_config('documentdb' || '.next_collection_index_id', '' || :vector__next_collection_index_id, FALSE); -------------------------------------------------- -- ivf search: pre-filtering match with different indexes -- "filter": {"meta.a": [ { "b" : 3 } ]}, match with idx_meta.a BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- "filter": {"meta": { "a" : [ { "b" : 3 } ] }, match with documentIndex_meta BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- "filter": {"meta.a.b": 3 }, match with idx_meta.a.b BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- ivf filter string: default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": "some sentence"} } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $and, nProbes = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $and, nProbes = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $or, nProbes = 3, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 3 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $or, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $or, $and, nProbes = 10, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "nProbes": 10 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or":[{"$and":[{"meta.a":{"$gt":"other sentence"}},{"meta.a":{"$lt":"some sentence"}}]},{"meta.a":{"$in":[{"b":3},{"b":5}]}}]}, "nProbes": 10 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter string: with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.a": { "$lt": "some sentence" } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- ivf filter number, with default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": 2 } } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter number, with $and, nProbes = 1, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter number, with $and, default nProbes, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter number, with $or, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter number, with $or, default nProbes, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$eq": 1 } }, { "meta.b": { "$eq": 2 } } , { "meta.b": { "$eq": 5 } } ] } } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter number, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$eq": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lte": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$ne": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$in": [ 2,3 ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$nin": [ 2 ] } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$gt": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.b": { "$lt": 2 } }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.b": { "$gt": 1 } }, { "meta.b": { "$lt": 5 } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- ivf filter boolean, with default nProbes BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true } } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter boolean, with nProbes = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": true }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter boolean, with c = false, nProbes = 1, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 1 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter boolean, with c = false, nProbes = 3, match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 3 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "c": false }, "nProbes": 3 } } } ], "cursor": {} }'); ROLLBACK; -- ivf filter boolean, with $eq, $ne, $in, $nin, $and, $or BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$eq": true}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$ne": true}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$in": [true]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"c": { "$nin": [true]}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "c": { "$eq": true } }, { "c": { "$eq": false } } ] }, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- ivf search: with filter, different distance metric -- ivf search: cosine similarity CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index_cos", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- ivf search: inner product CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index_cos"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- ivf search: restore to euclidean distance CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index_ip"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; -------------------------------------------------- -- ivf search: with filter and score projection BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and score projection, nProbes = 4, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 4 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and score projection, nProbes = 3, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 3 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and score projection, $ne, nProbes = 1, match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and score projection, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 100 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -------------------------------------------------- -- ivf search: with filter and shard -- TODO, current implementation does not support sharded collection, need to fix in part 3 BEGIN; SET LOCAL client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_ivf_filter', '{"c":"hashed"}', false); END; ANALYZE; -- reindex, numLists = 2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_filter", "index": "ivf_index"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3 } } ] }', true); ANALYZE; -- ivf search: with filter and shard, default nProbes, match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 } } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 4, "path": "v", "filter": {"meta.a.b": 3 } } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, nProbes = 1, v= [ 3.0, 5.0, 1.1 ], no match document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 5.0, 1.1 ], "k": 2, "path": "v", "filter": {"meta": { "a" : [ { "b" : 3 } ] } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 15.0, 5.0, 0.1 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 3.0, 4.9, 1.0 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 1, v= [ 13.0, 5.0, 0.1 ], match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, $ne, nProbes = 2, v= [ 13.0, 5.0, 0.1 ], match 3 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 2 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "nProbes": 2 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, number, nProbes = 1, v= [ 8.0, 5.0, 0.1 ], match 2 documents BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 8.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 8.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"meta.b": { "$gte": 2 } }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, filtering on shard field, nProbes = 1, v= [ 13.0, 5.0, 0.1 ], match 1 document BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 13.0, 5.0, 0.1 ], "k": 2, "path": "v", "filter": {"c": { "$eq": false}}, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- ivf search: with filter and shard, $or, multiple filters BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_filter", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "nProbes": 1 } } } , { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); ROLLBACK; SET documentdb.enableVectorPreFilter = off; ---------------------------------------------------------------------------------------------------- -- Vector search with empty vector field SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_empty_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "vectorIndex", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 5, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 4 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 3, "a": "some sentence" }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_empty_vector', '{ "_id": 4, "a": "some other sentence", "v": [3, 2, 1 ] }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_empty_vector'); ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF)SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_empty_vector", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 5 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; SELECT drop_collection('db','aggregation_pipeline_empty_vector'); DROP ROLE IF EXISTS test_filter_user_ivf; ---------------------------------------------------------------------------------------------------- -- exact search SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_vector_ivf_exact', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_vector_ivf_exact'); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); ANALYZE; -- error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": {} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": 123 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": "abc" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": [1,2,3] } } } ], "cursor": {} }'); -- COS BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- IP CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_ivf_exact", "index": "foo_1"}'); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "IP", "dimensions": 3 } } ] }', true); RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- L2 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_vector_ivf_exact", "index": "foo_1"}'); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_vector_ivf_exact", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 4, "similarity": "L2", "dimensions": 3 } } ] }', true); RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- nProbes BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": true } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); ROLLBACK; -- exact = false BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "exact": false } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": false } } } ], "cursor": {} }'); ROLLBACK; -- filter:, with $eq, $gt, $lt, $gte, $lte, $ne, $in, $and, $or, $regex BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$gt": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$lt": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 15.0, 5.0, 0.1 ], "k": 4, "path": "v", "filter": {"meta.a": { "$ne": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$regex": "^some", "$options" : "i"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "$eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$in": ["some sentence", "other sentence"]}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$and": [ { "meta.a": { "eq": "other sentence" } }, { "meta.b": { "$lt": 10 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"$or": [ { "meta.a": { "$gt": "other sentence" } }, { "meta.b": { "$gt": 1 } } ] }, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- shard SET client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','aggregation_pipeline_vector_ivf_exact', '{"_id":"hashed"}', false); RESET client_min_messages; ANALYZE; BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); EXPLAIN (VERBOSE on, COSTS off) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "v", "nProbes": 1, "exact": true } } } ], "cursor": {} }'); COMMIT; -- shard is not supported with filter yet BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_vector_ivf_exact", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "exact": true, "nProbes": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; SELECT drop_collection('db','aggregation_pipeline_vector_ivf_exact'); ---------------------------------------------------------------------------------------------------- -- Half vector -- ivf SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_halfvec'); -- error cases, create index SET documentdb.enableVectorCompressionHalf = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "none" } } ] }', true); SET documentdb.enableVectorCompressionHalf = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": "binary" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": "scalar" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": 123 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": {} } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001, "compression": ["half"] } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2001 } } ] }', true); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2000 } } ] }', true); RESET client_min_messages; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 2.5 } } } ], "cursor": {} }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4001, "compression": "half" } } ] }', true); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4000, "compression": "half" } } ] }', true); RESET client_min_messages; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); -- check index size of half vector and full vector SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_halfvec'); SELECT setseed(0); SELECT batch_insert_testing_vector_documents('aggregation_pipeline_ivf_halfvec', 10, 2000, 500, 1536); SELECT setseed(0); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 1536, "compression": "half" } } ] }', true); ANALYZE; SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_fullvec'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_fullvec'); SELECT setseed(0); SELECT batch_insert_testing_vector_documents('aggregation_pipeline_ivf_fullvec', 10, 2000, 500, 1536); SELECT setseed(0); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_fullvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "full_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 1, "similarity": "L2", "dimensions": 1536 } } ] }', true); ANALYZE; -- Each document has 1536 dimensions, therefore the vector index for each document is -- for half vector: 1536 * 2 = 3072 bytes, will take 1/2 page(<4kB), total 1000 pages -- for full vector: 1536 * 4 = 6144 bytes, will take 1 page(<8kB), total 2000 pages SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_ivf_halfvec', 1024), '{"result":"$indexSizes"}'); SELECT documentdb_api_catalog.bson_dollar_project(documentdb_api.coll_stats('db', 'aggregation_pipeline_ivf_fullvec', 1024), '{"result":"$indexSizes"}'); -- full vector index size - half vector index size -- (# of documents) * 0.5 * page size = 2000 * 0.5 * 8 = 8000kB with half_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8105','SELECT pg_indexes_size(''%s'')') as half_vec_size), full_vec_size as (SELECT ROUND((SUM(result::bigint))/1024) as vec_size FROM run_command_on_shards('documentdb_data.documents_8106','SELECT pg_indexes_size(''%s'')') as full_vec_size) SELECT (full_vec_size.vec_size - half_vec_size.vec_size) as diff FROM half_vec_size, full_vec_size; SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_halfvec'); SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_fullvec'); SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_halfvec'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','aggregation_pipeline_ivf_halfvec'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); -- check half vector search, L2 similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); RESET client_min_messages; -- oversampling, error cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": 0.5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": "0" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "oversampling": [] } } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 3, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "k": 5, "path": "v", "vector": [ 3.0, 4.9, 1.0 ], "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); -- check filter with half vector, cosine similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); RESET client_min_messages; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); ANALYZE; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100 } } } ], "cursor": {} }'); ROLLBACK; -- oversampling = 1.5 BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "oversampling": 1.5 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "oversampling": 1.5 } } } ], "cursor": {} }'); ROLLBACK; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "aggregation_pipeline_ivf_halfvec", "index": "half_index"}'); -- check exact search with half vector, IP similarity SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 64, "similarity": "IP", "dimensions": 3, "compression": "half" } } ] }', true); RESET client_min_messages; BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- oversampling failed with exact search SET documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SET documentdb.enableVectorPreFilter = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "nProbes": 100, "exact": true, "oversampling": 2 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); BEGIN; SET LOCAL enable_seqscan to off; SET LOCAL documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": {"meta.a": { "$eq": "some sentence"}}, "nProbes": 100, "exact": true, "oversampling": 1 } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); ROLLBACK; -- check value of vector is out of range -- create index failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 22222, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "larage_vector": [22222222222222.0, 5.0, 0.1 ] }'); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "similarity": "COS", "dimensions": 3, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_halfvec", "indexes": [ { "key": { "larage_vector": "cosmosSearch" }, "name": "large_half_index", "cosmosSearchOptions": { "kind": "vector-ivf", "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; -- search failed SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 11111111111111.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); -- insert failed SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_ivf_halfvec', '{ "_id": 33333, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [33333333333333.0, 5.0, 0.1 ] }'); -- check dimension of query vector exceeds 4000 DO $$ DECLARE dim_num integer := 4001; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; DO $$ DECLARE dim_num integer := 4000; vect_text text; pipeine_text text; BEGIN vect_text := (SELECT array_agg(n)::public.vector::text FROM generate_series(1, dim_num) AS n) ; pipeine_text := (SELECT '{ "aggregate": "aggregation_pipeline_ivf_halfvec", "pipeline": [ { "$search": { "cosmosSearch": { "vector": ' || vect_text || ', "k": 2, "path": "v" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db'::text, pipeine_text::bson); END; $$; SELECT documentdb_api.drop_collection('db','aggregation_pipeline_ivf_halfvec'); ----------------------------------------------------------------------------------------------------- -- PQ vector -- ivf SELECT documentdb_api.create_collection('db', 'aggregation_pipeline_ivf_pq'); -- error cases, create index SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 3, "compression": "pq" } } ] }', true); SET documentdb.enableVectorCompressionPQ = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 4000, "compression": "pq" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_ivf_pq", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 16, "similarity": "L2", "dimensions": 2000, "compression": "pq" } } ] }', true); SET documentdb.enableVectorCompressionPQ = off; SELECT documentdb_api.drop_collection('db', 'aggregation_pipeline_ivf_pq'); DROP FUNCTION IF EXISTS batch_insert_testing_vector_documents;bson_aggregation_pipeline_tests_vector_native.sql000066400000000000000000000333661507310017400410740ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8300000; SET documentdb.next_collection_id TO 8300; SET documentdb.next_collection_index_id TO 8300; SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; -- Vector search with vectorSearch BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 5.0, 1.1 ], "limit": 1, "path": "v" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v" } } ], "cursor": {} }'); ROLLBACK; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": {"a": "some sentence"} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 5.0, 1.1 ], "limit": 1, "path": "v", "filter": {} } } ], "cursor": {} }'); SELECT documentdb_api.shard_collection('db','aggregation_pipeline_native_vector', '{"_id":"hashed"}', false); ANALYZE; -- vectorSearch with shard BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.0, 1.0 ], "limit": 2, "path": "v", "numCandidates": 100 } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.0, 1.0 ], "limit": 2, "path": "v", "numCandidates": 100 } } ], "cursor": {} }'); ROLLBACK; ---------------------------------------------------------------------------------------------------- -- vectorSearch with filter SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 6, "meta":{ "a": "some sentence", "b": 1 }, "c": true , "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 7, "meta":{ "a": "some other sentence", "b": 2}, "c": true , "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 8, "meta":{ "a": "other sentence", "b": 5 }, "c": false, "v": [13.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 9, "meta":{ "a" : [ { "b" : 3 } ] }, "c": false, "v": [15.0, 5.0, 0.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_native_vector_filter', '{ "_id": 10, "meta":{ "a" : [ { "b" : 5 } ] }, "c": false }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"a": "some sentence"} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": {} } } ], "cursor": {} }'); set documentdb.enableVectorPreFilter = on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.a": 1 }, "name": "idx_meta.a" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.b": 1 }, "name": "numberIndex_meta.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta.a.b": 1 }, "name": "idx_meta.a.b" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "meta": 1 }, "name": "documentIndex_meta" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_native_vector_filter", "indexes": [ { "key": { "c": 1 }, "name": "boolIndex_c" } ] }', true); -------------------------------------------------- -- no match index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"unknownPath": "some sentence"} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 2, "path": "v", "filter": {"meta.c": "some sentence"} } } ], "cursor": {} }'); -- wrong filter type SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 1, "path": "v", "filter": "some sentence" } } ], "cursor": {} }'); -------------------------------------------------- -- multiple index path SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "meta.b": { "$eq": 5 } } ] }, { "c": { "$eq": false } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.b": { "$eq": 2 } }, { "c": { "$eq": false } } ] }, { "meta.b": { "$lt": 5 } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"$and": [ { "$or": [{ "meta.a": { "$regex": "^some", "$options" : "i" } }, { "meta.b": { "$eq": 5 } } ] }, { "meta.b": { "$lt": 5 } } ] } } }, { "$project": {"searchScore": {"$round": [ {"$multiply": ["$__cosmos_meta__.score", 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "numCandidates": 100 } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 4, "path": "v", "filter": {"meta.a": [ { "b" : 3 } ]}, "numCandidates": 100 }} ], "cursor": {} }'); SELECT documentdb_api.shard_collection('db','aggregation_pipeline_native_vector_filter', '{"_id":"hashed"}', false); ANALYZE; -- vectorSearch with filter and shard SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_native_vector_filter", "pipeline": [ { "$vectorSearch": { "queryVector": [ 3.0, 4.9, 1.0 ], "limit": 10, "path": "v", "filter": {"$or": [ { "meta.a": { "$eq": "some sentence" } }, { "meta.b": { "$gt": 2 } }, {"c": { "$eq": false } } ] }, "numCandidates": 100 } } ], "cursor": {} }'); set documentdb.enableVectorPreFilter = off; -------------------------------------------------- -- Vector search with knnBeta SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id": 6, "a": "some sentence", "v": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'aggregation_pipeline_knnbeta', '{ "_id": 7, "a": "some other sentence", "v": [8.0, 5.0, 0.1 ] }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "aggregation_pipeline_knnbeta", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); BEGIN; SET LOCAL enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ROLLBACK; set documentdb.enableVectorPreFilter = on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": {"a": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "filter": "some" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v", "filter": {} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "score": {"a": "some sentence"} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v", "score": 100 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "knnBeta": { "vector": [ 3.0, 5.0, 1.1 ], "k": 1, "path": "v", "score": {} } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "aggregation_pipeline_knnbeta", "pipeline": [ { "$search": { "unknowType": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); set documentdb.enableVectorPreFilter = off; bson_aggregation_set_operators_tests.sql000066400000000000000000001207021507310017400372170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9000000; SET documentdb.next_collection_id TO 9000; SET documentdb.next_collection_index_id TO 9000; -- $setIntersection operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1,2,3],[2,3,4]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [["a","b","c"],["a","d","c"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"a" : { "$setIntersection" : [[1.1,2.2,3.3],[1.1,2.2,4.4]]} }'); -- $setIntersection operator: No matching element: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1,2,3],[4,5,6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"a" : { "$setIntersection" : [[1,1,2],[3,3,4]]} }'); -- $setIntersection operator: Nested Elements: -- NOTE: we don't recurse into arrays and considers only the first/outer-level array select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[[1,{"a":1, "b":1}],2,3],[4,[1,{"a":1, "b":1}],6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[{"a":[1,2,3],"b":1},2,3],[4,{"a":[1,2,3],"b":1},6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[[1,2,3]],[[3,2,1]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[{"a":1,"b":1}],[{"b":1,"a":1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[["a","b","c"]],[["a","b","c"]]]} }'); ---- $setIntersection operator: decimal,double and long: select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); ---- $setIntersection operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ { "$numberLong" : "1" },2,3],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ { "$numberDecimal" : "1" },2,3],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1,2,3],[{ "$numberDecimal" : "1" },2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1.1],[{ "$numberDecimal" : "1.1" }]]} }'); -- 1.1 is not fixed integer and type is different so not considering both as equal. select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[ 1.00],[{ "$numberDecimal" : "1.00" }]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1],[{ "$numberDecimal" : "1.00" }]]} }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[1],[1.00]]} }'); ---- $setIntersection operator: Null,Nan,Infinity,undefined and undefined path: select bson_dollar_project('{"_id":"1" }', '{"setIntersection" : { "$setIntersection" : [null]} }'); select bson_dollar_project('{"_id":"1" }', '{"setIntersection" : { "$setIntersection" : ["$a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [[1,2,3],null]} }'); select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [{ "$undefined" : true }]} }'); select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : { "$undefined" : true }} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"setIntersection" : { "$setIntersection" : ["$undefinePath", [1]] } }'); select bson_dollar_project('{"_id":"1"}', '{"intersection" : { "$setIntersection" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[null,{ "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "-NaN"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setIntersection" : { "$setIntersection" : [[NaN],[{"$numberDouble": "-NaN"}]]} }'); ---- $setIntersection operator: literals and operators: select bson_dollar_project('{"_id":"1", "a" :[1,2,3]}', '{"intersection" : { "$setIntersection" : ["$a",[2,3,4]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ {"$slice" : [[1,2,3,4,5,6,7],2,5]} ,[2,3,4]]} }'); select bson_dollar_project('{"_id":"1","a":[1,2,3] }', '{"intersection" : { "$setIntersection" : [ {"$slice" : ["$a",0,3]} ,[2,3,4]]} }'); ---- $setIntersection operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.135Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"intersection" : { "$setIntersection" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); ---- $setIntersection operator: Negative: select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : {} } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : 1 } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : [1] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"intersection" : { "$setIntersection" : [[1],{}]} }'); -- $setUnion operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],[2,3,4]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [["a","b","c"],["a","d","c"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.2,3.3],[1.1,2.2,4.4]]} }'); -- $setUnion operator: No matching element: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],[4,5,6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,1,2],[3,3,4]]} }'); -- $setUnion operator: Nested Elements: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[[1,{"a":1, "b":1}],2,3],[4,[1,{"a":1, "b":1}],6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[{"a":[1,2,3],"b":1},2,3],[4,{"a":[1,2,3],"b":1},6]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[[1,2,3]],[[3,2,1]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[{"a":1,"b":1}],[{"b":1,"a":1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[["a","b","c"]],[["a","b","c"]]]} }'); ---- $setUnion operator: decimal,double and long: select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1.1,2.1,3.1],[2.10,3.10,4.0]]} }'); ---- $setUnion operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ { "$numberLong" : "1" },2,3],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ { "$numberDecimal" : "1" },2,3],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1,2,3],[{ "$numberDecimal" : "1" },2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1.1],[{ "$numberDecimal" : "1.1" }]]} }'); -- 1.1 is not fixed integer and type is different so not considering both as equal. select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[ 1.00],[{ "$numberDecimal" : "1.00" }]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1],[{ "$numberDecimal" : "1.00" }]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1],[1.00]]} }'); ---- $setUnion operator: Null,Nan,Infinity,undefined and undefined path: select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [null]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : ["$a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[1,2,3],null]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [{ "$undefined" : true }]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : { "$undefined" : true }} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"setUnion" : { "$setUnion" : ["$undefinePath", [1]] } }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[null,{ "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "-NaN"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"union" : { "$setUnion" : [[NaN],[{"$numberDouble": "-NaN"}]]} }'); ---- $setUnion operator: literals and operators: select bson_dollar_project('{"_id":"1", "a" :[1,2,3]}', '{"union" : { "$setUnion" : ["$a",[2,3,4]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ {"$slice" : [[1,2,3,4,5,6,7],2,5]} ,[2,3,4]]} }'); select bson_dollar_project('{"_id":"1","a":[1,2,3] }', '{"union" : { "$setUnion" : [ {"$slice" : ["$a",0,3]} ,[2,3,4]]} }'); ---- $setUnion operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"union" : { "$setUnion" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); ---- $setUnion operator: Negative: select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : {} } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : 1 } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : [1] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5] }', '{"union" : { "$setUnion" : [[1],{}]} }'); -- $setEquals operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [["a","b","c"],["a","b","c"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1.1,2.1,3.1],[1.1,2.1,3.1]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,4]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [["a","b","c"],["b","b","c"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1.1,2.1,3.1],[1.2,2.2,3.2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[],[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3,4],[1,2,3,4,5]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]} }'); -- $setEquals operator: Nested test: select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[[1,2],[1,2]],[[1,2],[1,2]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[[1,2],[1,2]],[[2,3],[1,2]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[1,2,1,2],[[2,3],[1,2]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{"a":1},{"b":1}],[{"a":1},{"b":1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{"a":1},{"b":1}],[{"a":1},{"b":2}]]} }'); -- $setEquals operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberLong" : "1" }],[1]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberLong" : "1" },{ "$numberDouble" : "1.0" }],[1],[{ "$numberDecimal" : "1.0" }]]} }'); select bson_dollar_project('{"_id":"1"}', '{"setEqual" : { "$setEquals" : [[{ "$numberDouble" : "1.1" }],[1.1],[{ "$numberDecimal" : "1.1" }]]} }'); --$setEquals with operators and literals select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4,5] }', '{"setEqual" : { "$setEquals" : [["$a"],["$b"]] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [["$a"],["$b"]] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [[{"$slice": ["$a",1,3]}],[{"$slice": ["$b",1,3]}]] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"setEqual" : { "$setEquals" : [[{"$slice": ["$a",1,4]}],[{"$slice": ["$b",1,3]}]] } }'); ---- $setEquals operator: Other BsonType Binary, code, DateTime, Timestamp, Minkey, Maxkey: select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "zg==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "01"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [ [{"$binary": { "base64": "ww==", "subType": "01"}}], [{"$binary": { "base64": "ww==", "subType": "02"}}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1770981326, "i": 1 } }], [{"$timestamp" : { "t": 1870981326, "i": 1 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$timestamp" : { "t": 1670981326, "i": 1 } }], [{"$timestamp" : { "t": 1670981326, "i": 2 } }]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "639926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$oid": "639926cee6bda3127f153bf1"}],[{"$oid": "739926cee6bda3127f153bf1"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$code": "var a = 1;"}],[{ "$code": "var a = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$code": "var a = 1;"}],[{ "$code": "var b = 1;"}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test2", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}],[{ "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "447f000000c1de008ec19ceb" }}}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); -- $setEquals operator: Negative test: select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : {} } }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : 1 } }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [1] } }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : ["$a",[1,2,3]] } }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1,2,3],"$a"] } }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1],{}]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : null} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : { "$undefined" : true}} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [null]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [null,null]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [[1,2,3],null]} }'); select bson_dollar_project('{"_id":"1" }', '{"setEqual" : { "$setEquals" : [{ "$undefined" : true}]} }'); -- $setDifference operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2],[1,2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,1,2,2,3,3],[1,2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3,4],[1,2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3,4],[1,2,5,6,7]]} }'); ---- $setDifference operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDecimal" : "1.0"},{"$numberDouble" : "2.0"},3,4],[1,2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDecimal" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[1.1,2.1]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$numberLong" : "1"},{"$numberDouble" : "2.0"},3,4],[1,2]]} }'); -- $setDifference operator: different types and Nested case: select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [["a","b","c"],["a"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"}],[{ "$numberDouble" : "-NaN"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2019-01-30T07:30:10.137Z"}] ]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[[1,2],[1,2,3]],[[1,2]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[{"a":1},{"b":1}],[{"a":1},{"b":2}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null,null]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],null]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null,[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : ["$a",[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [{"$undefined": true},[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1,2,3],{"$undefined": true}]} }'); -- $setDifference operator: with Inner Operators : select bson_dollar_project('{"_id":"1", "a": [1,2,3], "b": [1,2]}', '{"difference" : { "$setDifference" : ["$a","$b"]} }'); select bson_dollar_project('{"_id":"1", "a": [1,2,3,5], "b": [1,2,3,4]}', '{"difference" : { "$setDifference" : ["$a","$b"]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"difference" : { "$setDifference" : [{"$slice": ["$a",1,6]},{"$slice": ["$b",1,6]}] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"difference" : { "$setDifference" : [{"$slice": ["$a",1,3]},{"$slice": ["$b",1,3]}] } }'); -- $setDifference operator: Negative Cases : select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[],[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1,2,3]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [1,2]} }'); select bson_dollar_project('{"_id":"1"}', '{"difference" : { "$setDifference" : [[1],2]} }'); -- $setIsSubset operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[1,2,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2],[1,2,3,4]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,1,2,2,3,3],[1,2,3,4,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3,4],[1,2]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1,2,3,4],[1,2,5,6,7]]} }'); ---- $setIsSubset operator: same value with different type: -- if type is different is value is not fixed integer then it is not considering that as a match, e.g, double's 1.1 is not equals to decimal's 1.1 -- if type is different and values can be converted to fixed integer  then only it is considering as a match, e.g, double's 1.0 is equals to decimal's 1.0 select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDecimal" : "1.0"},{"$numberDouble" : "2.0"},3,4],[1,2,4,3]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDecimal" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[1.1,2.1,3,4,5]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4],[{"$numberDouble" : "1.1"},{"$numberDecimal" : "2.1"},3,4,5]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$numberLong" : "1"},{"$numberDouble" : "2.0"}],[1,2,3,4]]} }'); -- $setIsSubset operator: different types and Nested case: select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [["a","b","c"],["a","b","c","d"]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"}],[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"},{ "$numberDouble" : "-NaN"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{ "$numberDouble" : "-NaN"}],[null, { "$numberDouble" : "Infinity"},{ "$numberDouble" : "-Infinity"},{ "$numberDouble" : "NaN"}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$maxKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$minKey" : 1}],[{"$minKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$minKey" : 1}],[{"$maxKey" : 1}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"$date": "2013-12-12T06:23:15.134Z"}], [{"$date": "2013-12-12T06:23:15.134Z"}] ]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[[1,2],[1,2,3]],[[1,2],[1,2,3],[1,2,3,4]]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"a":1},{"b":1}],[{"a":1},{"b":1},{"c":2}]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[{"a":1},{"b":2}],[{"a":1},{"b":1},{"c":2}]]} }'); -- $setIsSubset operator: with Inner Operators : select bson_dollar_project('{"_id":"1", "a": [1,2,3], "b": [1,2,3,4]}', '{"isSubset" : { "$setIsSubset" : ["$a","$b"]} }'); select bson_dollar_project('{"_id":"1", "a": [1,2,3,5], "b": [1,2,3,4]}', '{"isSubset" : { "$setIsSubset" : ["$a","$b"]} }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4,5,6] }', '{"isSubset" : { "$setIsSubset" : [{"$slice": ["$a",1,6]},{"$slice": ["$b",1,6]}] } }'); select bson_dollar_project('{"_id":"1", "a" : [1,2,3,4,5], "b" : [1,2,3,4] }', '{"isSubset" : { "$setIsSubset" : [{"$slice": ["$a",1,3]},{"$slice": ["$b",1,3]}] } }'); -- $setIsSubset operator: Negative Cases : select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[],[],[]]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1,2,3]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [1,2]} }'); select bson_dollar_project('{"_id":"1"}', '{"isSubset" : { "$setIsSubset" : [[1],2]} }'); select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : null} }'); select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : [[1,2,3],null]} }'); select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : [[1,2,3],"$a"]} }'); select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : ["$a",[1,2,3]]} }'); select bson_dollar_project('{"_id":"1" }', '{"isSubset" : { "$setIsSubset" : { "$undefined" : true}} }'); --$allElementsTrue : Test for True Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true,true]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1,"app", 11.2, {"$numberLong":"10"}, {"$numberDouble":"10"}, {"$numberDecimal":"10"}, [1,2,3], {"X": "Y"}]]}}'); SELECT * FROM bson_dollar_project('{"a" : 1, "b" : "test"}', '{"result": { "$allElementsTrue": [["$a", "$b"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDouble" : "0.1"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDecimal" : "0.1"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[-1, -2.9, {"$numberDecimal" : "0.1"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1, {"$add": [0,1]}]]}}'); --$allElementsTrue : Test for False Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true,false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, 0, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, null, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, "$b", 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$undefined" : true}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDouble" : "0.0"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberDecimal" : "0.0"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[true, 1, {"$numberLong" : "0"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[false, 0, 0, 1]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1, {"$add": [0,0]}]]}}'); --$allElementsTrue : Negative Test SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": ["a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [{"$undefined" : true}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1,2,3],[3,4,5]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [[1,2,3],1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": [1, [1,2,3]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$allElementsTrue": ["$b"]}}'); --$anyElementTrue : Test for True Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true,false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,true,false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,false,null,"$b",{"$undefined": true}, true]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1,"app", 11.2, {"$numberLong":"10"}, {"$numberDouble":"10"}, {"$numberDecimal":"10"}, [1,2,3], {"X": "Y"}]]}}'); SELECT * FROM bson_dollar_project('{"a" : 1, "b" : "test"}', '{"result": { "$anyElementTrue": [["$a", "$b"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1, {"$numberDouble" : "0.1"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[true, 1, {"$numberDecimal" : "0.1"}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 1, {"$undefined" : true}, 10]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, null, {"$numberDouble" : "0.1"}, 0]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, "$b", {"$numberDecimal" : "1.0"}, 0]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, {"$numberLong" : "1"}, 0]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0, {"$add": [0,1]}]]}}'); --$anyElementTrue : Test for False Outputs SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false,false]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0,false,null,"$b",{"$undefined": true}, {"$numberDecimal" : "0.0"}, {"$numberDouble" : "0.0"}, {"$numberLong" : "0"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, {"$undefined" : true}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, {"$numberDouble" : "0.0"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false,{"$numberDecimal" : "0.0"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, {"$numberLong" : "0"}]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[false, 0, null]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[0, {"$add": [0,0]}]]}}'); --$anyElementTrue : Negative Test SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": ["a"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [null]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [{"$undefined" : true}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[1,2,3],[3,4,5]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [[1,2,3],1]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": [1, [1,2,3]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$anyElementTrue": ["$b"]}}'); bson_aggregation_stage_addfield_tests.sql000066400000000000000000000155361507310017400372550ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 310000; SET documentdb.next_collection_id TO 3100; SET documentdb.next_collection_index_id TO 3100; SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"1", "int": 10, "a" : { "b" : [ "x", 1, 2.0, true ] } }', NULL); SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db','addFieldOps','{"_id":"3", "boolean": false, "a" : "no", "b": "yes", "c": true }', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; -- add newField SELECT bson_dollar_add_fields(document, '{ "newField" : "1", "a.y": ["p", "q"]}') FROM documentdb_api.collection('db', 'addFieldOps'); -- add field that evaluates $_id SELECT bson_dollar_add_fields(document, '{ "newField" : "3", "a": "$_id"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- Add integer field (note that, {"field" : 1} is treated as inclusion for $project but add for $addFields) SELECT bson_dollar_add_fields(document, '{ "int" : 1, "doble": 2.0, "bool": false, "a.d": false, "a.b.c": "$_id"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields array duplication -- Expected value of the field "a" of dco(id=1), after the following addField: { "a.b.c": "_"} is: -- "a": {"b" : ["c" : "-", "c" : "-","c" : "-","c" : "-",]} SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "-"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields intege in a nested paths SELECT bson_dollar_add_fields(document, '{ "a" : {"b" : 1}}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields intege in a nested paths SELECT bson_dollar_add_fields(document, '{ "a" : {"b" : { "d": 2.5}}}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFileds to check the a.b field of doc(id=2) changes -- from: {"a" : { "b" : {"c": 3}} -- to: "a" : { "b" : {"c": 3, "d": "-"} SELECT bson_dollar_add_fields(document, '{ "a.b.d" : "-"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields: Applying multiple expressions with overlapping field paths SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields: Applying multiple expressions with overlapping field paths SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "$_id", "a.b.d" : "$b", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields: If matching subpath in a document has an array, remaining path of the addFields spec tree is duplicated for all array elelemnts. Remain subpath may need recursion. SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "_c", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- addFields where "$a.b" needs to be evaluated while writing a path SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "$a.b", "a.b.d" : "_d", "a.b.e": "_e"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- Evaluating array of expessions i.e., : [, ] is not a documented behavior SELECT bson_dollar_add_fields(document, '{ "newarray" : [{ "$literal": 1.0 }, {"copyId": "$_id"}]}') FROM documentdb_api.collection('db', 'addFieldOps'); -- add newField with concatArrays SELECT bson_dollar_add_fields(document, '{ "newField" : "1", "a.b": {"$concatArrays" : [[7], [8], [9]]}}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "_id" : false}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "_id" : 121}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "_id" : 212.2}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "_id" : "someString"}') FROM documentdb_api.collection('db', 'addFieldOps'); -- path collision tests SELECT bson_dollar_add_fields(document, '{ "a.b.c.d.e" : "_c", "a.b.c" : "_d"}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "a.b.c" : "_c", "a.b" : "_d"}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : 1.0}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : "$a.b"}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b.c": "$_id", "a.b": "1.0"}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a" : { "b" : { "c": { "d": "$_id"}}}, "a.b": {"c" : 1.0}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; -- Array Expression and Nested Expression evaluation tests SELECT bson_dollar_add_fields(document, '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'addFieldOps'); SELECT bson_dollar_add_fields(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'addFieldOps'); -- Spec trees are equivalent SELECT bson_dollar_add_fields(document, '{"a.b": {"c" : "value"}}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; SELECT bson_dollar_add_fields(document, '{"a.b.c": "value"}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; -- Test nested array projections SELECT bson_dollar_add_fields('{"_id":"1", "a" : [1, {"d":1}, [3, 4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); SELECT bson_dollar_add_fields('{"_id":"1", "a" : [1, {"d":1}, [ { "c" : { "b" : 1 } },4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); -- Empty spec is a no-op according to 4.4.13\jstests\aggregation\sources\addFields\use_cases.js SELECT bson_dollar_add_fields(document, '{}') FROM documentdb_api.collection('db', 'addFieldOps') ORDER BY object_id; bson_aggregation_stage_bucket_tests.sql000066400000000000000000000250021507310017400367630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5120000; SET documentdb.next_collection_id TO 51200; SET documentdb.next_collection_index_id TO 51200; -- Insert data SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 1, "product" : "almonds", "pricing" : { "bulk": 10, "store": 15 }, "stock" : 2, "year": 2020 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 2, "product" : "peach", "pricing" : { "bulk": 10, "store": 9 }, "stock" : 1, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 3, "product" : "banana", "pricing" : { "bulk": 10, "store": 15 }, "stock" : 5 , "year": 2020}', NULL); SELECT documentdb_api.insert_one('db','dollarBucket',' { "_id" : 4, "product" : "melon", "pricing" : { "bulk": 4, "store": 10 }, "stock" : 3 , "year": 2022}', NULL); SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 5, "product" : "banana", "pricing" : { "bulk": 75, "store": 100 }, "stock" : 1, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 6, "product" : "banana", "pricing" : { "bulk": 75, "store": 100 }, "stock" : 1, "year": 2021 }', NULL); SELECT documentdb_api.insert_one('db','dollarBucket','{ "_id" : 7, "product" : "banana", "pricing" : { "store": 15, "bulk": 10 }, "stock" : 1, "year": 2020 }', NULL); -- positive cases: -- $bucket with only required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); -- $bucket with default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others" } } ] }'); -- $bucket with output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); -- $bucket with output fields and default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); -- $bucket with nested field path in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$pricing.bulk", "boundaries": [10, 20, 30], "default": "unknown" } } ] }'); -- $bucket with expression in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": { "$subtract": ["$year", 2019] }, "boundaries": [1, 2, 3, 4] } } ] }'); -- $bucket with another stage before it SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); -- $bucket without count in output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "averageStock": { "$avg": "$stock" }, "totalStock": { "$sum": "$stock" } } } } ] }'); -- $bucket with default value equals to the highest boundaries value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2021 } } ] }'); -- groupBy non-integar field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$product", "boundaries": ["a", "c", "n"], "default": "others" } } ] }'); -- groupBy array or document field SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 1, "valueArray" : [1, 2, 3], "valueDocument" : { "a": 1, "b": 2 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 2, "valueArray" : [4, 5, 6], "valueDocument" : { "a": 3, "b": 4 } }', NULL); SELECT documentdb_api.insert_one('db','dollarBucketGroupBy', '{ "_id" : 3, "valueArray" : [9, 8], "valueDocument" : { "a": 5, "b": 6 } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketGroupBy", "pipeline": [ { "$bucket": { "groupBy": "$valueArray", "boundaries": [[0], [5], [10]] } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucketGroupBy", "pipeline": [ { "$bucket": { "groupBy": "$valueDocument", "boundaries": [{"a": 0}, {"a": 5}, {"a": 10}] } } ] }'); -- negative cases, validations: -- required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "boundaries": [2020, 2021,2022,2023] } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year"} } ] }'); -- groupBy must be a path with prefix $ or expression SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); -- boundaries is acsending constant array, more than one element, same type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": 2020 } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020] } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2020, 2022, 2023] } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 1999, 2023] } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, "a", 2022, 2023] } } ] }'); -- default must be a constant, the default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value, if having same type. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "$pricing" } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2020 } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2022, 2023], "default": 2021 } } ] }'); -- output must be document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "output": 1 } } ] }'); -- More validations -- unknown argument of $bucket SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "averageStock": { "$avg": "$stock" }}, "unknown": 1 } } ] }'); -- document cannot fall into any bucket with no default being set. SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021] } } ] }'); -- sharded collection SELECT documentdb_api.shard_collection('db', 'dollarBucket', '{ "_id": "hashed" }', false); -- $bucket with only required fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); -- $bucket with default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others" } } ] }'); -- $bucket with output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); -- $bucket with output fields and default value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022], "default": "others", "output": { "count": { "$sum": 1 }, "averageStock": { "$avg": "$stock" } } } } ] }'); -- $bucket with nested field path in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$pricing.bulk", "boundaries": [10, 20, 30], "default": "unknown" } } ] }'); -- $bucket with expression in groupBy field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": { "$subtract": ["$year", 2019] }, "boundaries": [1, 2, 3, 4] } } ] }'); -- $bucket with another stage before it SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$match": { "product": "banana" } }, { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023] } } ] }'); -- $bucket without count in output fields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021, 2022, 2023], "output": { "averageStock": { "$avg": "$stock" }, "totalStock": { "$sum": "$stock" } } } } ] }'); -- $bucket with default value equals to the highest boundaries value SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$year", "boundaries": [2020, 2021], "default": 2021 } } ] }'); -- groupBy non-integar field SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "dollarBucket", "pipeline": [ { "$bucket": { "groupBy": "$product", "boundaries": ["a", "c", "n"], "default": "others" } } ] }'); bson_aggregation_stage_facet_tests.sql000066400000000000000000000133511507310017400365740ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9610000; SET documentdb.next_collection_id TO 961000; SET documentdb.next_collection_index_id TO 961000; -- Insert data SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 1, "product" : "beer", "unitPrice" : 12, "stock" : 2 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 2, "product" : "red wine", "unitPrice" : 20, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 3, "product" : "bread", "unitPrice" : 10, "stock" : 5 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 4, "product" : ["beer", "bread", "red wine"], "unitPrice" : 10, "stock" : 5 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 5, "product" : "beer", "unitPrice" : 12, "stock" : 2 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 6, "product" : "red wine", "unitPrice" : 20, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 7, "product" : "bread", "unitPrice" : 10, "stock" : 5 }', NULL); SELECT documentdb_api.insert_one('db','facetTest',' { "_id" : 8, "product" : ["beer", "bread", "red wine"], "unitPrice" : 10, "stock" : 5 }', NULL); -- Test filter generation empty input SELECT bson_array_agg(document, 'myarray'::text) FROM documentdb_api.collection('db', 'facet1'); -- Test filter generation SELECT bson_array_agg(document, 'myarray'::text) FROM documentdb_api.collection('db', 'facetTest'); SELECT bson_object_agg(document) FROM documentdb_api.collection('db', 'facetTest'); -- Test full facetSQL sql WITH "stage0" as ( SELECT documentdb_api_catalog.bson_dollar_add_fields(document, '{ "name" : { "$numberInt" : "1" } }'::bson) as document FROM documentdb_api.collection('db', 'facetTest') ), "stage1" as ( WITH FacetStage AS ( WITH "FacetStage00" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONFIRSTONSORTED( bson_expression_get(document, '{ "$first" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage01" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'first':: text, "acc0" ) AS document FROM "FacetStage00" ), "FacetStage10" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONLASTONSORTED( bson_expression_get(document, '{ "$last" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage11" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'last':: text, "acc0" ) AS document FROM "FacetStage10" ) select bson_array_agg(document :: bytea, 'facet1' :: text) as facet_row from "FacetStage01" UNION ALL select bson_array_agg(document :: bytea, 'facet2' :: text) as facet_row from "FacetStage11" ) SELECT bson_dollar_facet_project(bson_object_agg(facet_row), true) FROM FacetStage ) SELECT * from "stage1"; -- Test full facetSQL sql BEGIN; set local parallel_tuple_cost TO 0.00001; set local parallel_setup_cost TO 0; set local min_parallel_table_scan_size TO 0; set local min_parallel_index_scan_size TO 0; set local max_parallel_workers to 4; set local max_parallel_workers_per_gather to 4; set local max_parallel_maintenance_workers to 4; set local enable_seqscan TO off; SET JIT To off; EXPLAIN(costs off) WITH "stage0" as ( SELECT documentdb_api_catalog.bson_dollar_add_fields(document, '{ "name" : { "$numberInt" : "1" } }'::bson) as document FROM documentdb_api.collection('db', 'facetTest') ), "stage1" as ( WITH FacetStage AS ( WITH "FacetStage00" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONFIRSTONSORTED( bson_expression_get(document, '{ "$first" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage01" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'first':: text, "acc0" ) AS document FROM "FacetStage00" ), "FacetStage10" as ( SELECT bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) AS "accid", BSONLASTONSORTED( bson_expression_get(document, '{ "$last" : "$stock" }'::bson, true) ) AS "acc0" FROM documentdb_api.collection('db', 'facetTest') GROUP BY bson_expression_get(document, '{ "_id" : "$unitPrice" }'::bson, true) ), "FacetStage11" as ( SELECT documentdb_core.bson_repath_and_build( '_id' :: text, "accid", 'last':: text, "acc0" ) AS document FROM "FacetStage10" ) select bson_array_agg(document :: bytea, 'facet1' :: text) as facet_row from "FacetStage01" UNION ALL select bson_array_agg(document :: bytea, 'facet2' :: text) as facet_row from "FacetStage11" ) SELECT bson_dollar_facet_project(bson_object_agg(facet_row), true) FROM FacetStage ) SELECT * from "stage1" ROLBACK;bson_aggregation_stage_index_stats.sql000066400000000000000000000057071507310017400366230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 385000; SET documentdb.next_collection_id TO 3850; SET documentdb.next_collection_index_id TO 3850; CREATE OR REPLACE FUNCTION query_and_flush(field text) RETURNS bson set enable_seqscan to false AS $$ DECLARE docText bson; BEGIN SELECT cursorPage INTO docText FROM documentdb_api.aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "indexstats1", "pipeline": [ { "$match": { "%s": { "$gt": 500 } } }, { "$count": "c" } ], "cursor": {} }', field)::documentdb_core.bson); IF VERSION() LIKE 'PostgreSQL 14%' THEN PERFORM pg_sleep(3); ELSE PERFORM pg_stat_force_next_flush(); END IF; RETURN docText; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.drop_collection('db', 'indexstats1'); -- fails on non existent collection SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- Create Collection SELECT documentdb_api.create_collection('db', 'indexstats1'); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- Add 1000 docs SELECT COUNT(*) FROM (SELECT documentdb_api.insert_one('db','indexstats1',FORMAT('{ "a" : %s, "_id": %s }', i, i)::bson, NULL) FROM generate_series(1, 10000) i) ins; -- create index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexstats1", "indexes": [ { "key": { "a": 1 }, "name": "a_1" } ] }', true); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- query using index. SELECT query_and_flush('_id'); SELECT query_and_flush('_id'); SELECT query_and_flush('a'); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- shard SELECT documentdb_api.shard_collection('db', 'indexstats1', '{ "_id": "hashed" }', false); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- query using index. SELECT query_and_flush('_id'); SELECT query_and_flush('_id'); SELECT query_and_flush('a'); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": {} }, { "$project": { "accesses.since": 0 }} ]}'); -- invalid cases SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$indexStats": { "a": 1 } }, { "$project": { "accesses.since": 0 }} ]}'); SELECT * FROM bson_aggregation_pipeline('db', '{ "aggregate": "indexstats1", "pipeline": [ { "$match": { "a": 1 } }, { "$indexStats": { } }, { "$project": { "accesses.since": 0 }} ]}'); bson_aggregation_stage_inversematch_tests.sql000066400000000000000000000506731507310017400402120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 9630000; SET documentdb.next_collection_id TO 963000; SET documentdb.next_collection_index_id TO 963000; -- Insert data SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 1, "city_id": 101, "city": "Beijing", "province": "Beijing", "airport": "Beijing Capital", "policy": { "flight_type": "domestic"} }', NULL); SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 2, "city_id": 102, "city": "Shanghai", "province": "Shanghai", "airport": "Pudong International", "policy": { "$or": [ { "origin": "Guangdong"}, {"flight_type": "domestic"}] } }', NULL); SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 3, "city_id": 103, "city": "Guangzhou", "province": "Guangdong", "airport": "Baiyun International", "policy": { "$in": [{"is_emergency": true}, {"is_vip": true}] }}', NULL); SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 4, "city_id": 104, "city": "Shenzhen", "province": "Guangdong", "airport": "Baoan International", "policy": { "$or": [ {"$and": [{"flight_type": "domestic"}, {"origin": "Guangdong"}]}, {"$or": [{"is_emergency": true}, {"is_vip": true}]} ] }}', NULL); SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 5, "city_id": 105, "city": "Chengdu", "province": "Sichuan", "airport": "Shuangliu International", "policy": { "tags": { "$all": ["domestic", "vip"]}}}', NULL); -- positive cases SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Beijing"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "international"}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Beijing"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "domestic"}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Shanghai"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "international"}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Shanghai"}}, { "$inverseMatch": {"path": "policy", "input": {"flight_type": "domestic"}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": {"is_emergency": true}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "domestic", "origin": "Guangdong" }}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "international", "origin": "Guangdong" }}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "flight_type": "domestic", "origin": "Guangdong", "is_vip": true }}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": [{ "flight_type": "domestic"}, {"is_emergency": true}]}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{"$match": {"province": "Guangdong"}}, { "$inverseMatch": {"path": "policy", "input": { "tags": ["domestic", "vip"]}}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }}}]}'); -- Validate errors SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"pathRule": "policy", "input": {"flight_type": "domestic"} }}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "inputValue": {"flight_type": "domestic"} }}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "", "input": {"flight_type": "domestic"} }}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "input": ["flight_type", "domestic"] }}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": {"path": "policy", "input": [{"flight_type": "domestic"}, ""] }}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [ { "$inverseMatch": [{"path": "policy", "input": [{"flight_type": "domestic"}, ""] }, {"path": "policy2", "input": {}}]}]}'); -- insert a document with an invalid query SELECT documentdb_api.insert_one('invmatch','chinese_cities','{ "_id": 6, "city_id": 106, "city": "Hangzhou", "province": "Zhejiang", "airport": "Hangzhou Xiaoshan International", "specialPolicy": { "tags": { "$allValues": ["domestic", "vip"]}}}', NULL); -- any inverseMatch that queries that path should fail SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "specialPolicy", "input": { "origin": "Guangdong" }, "defaultResult": false}}]}'); -- if we query "policy" path without defaultResult in the spec it should not match for the Hangzhou city which doesn't define the policy as the default value is false SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }}}]}'); -- with defaultResult true should return all documents that don't define the path and false shouldn't return them SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }, "defaultResult": true}}]}'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "chinese_cities", "pipeline": [{ "$inverseMatch": {"path": "policy", "input": { "origin": "Guangdong" }, "defaultResult": false}}]}'); -- add tests with lookup for RBAC "like" scenarios SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 1, "user_id": 100, "roles": ["basic"]}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 2, "user_id": 101, "roles": ["basic", "sales"]}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 3, "user_id": 102, "roles": ["admin"]}', NULL); SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 1, "order": 100, "paid": true, "total": 0, "rule": {"roles": {"$in": ["basic", "sales", "admin"]}}}', NULL); SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 2, "order": 102, "paid": true, "total": 1000, "rule": {"roles": {"$in": ["sales", "admin"]}}}', NULL); SELECT documentdb_api.insert_one('invmatch','sales','{ "_id": 3, "order": 103, "paid": true, "total": 1000, "rule": {"roles": {"$in": ["admin"]}}}', NULL); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 100} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 101} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 102} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); -- use from collection instead of lookup (new feature) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 101}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}, {"$project": {"roles": 1, "_id": 0}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lt": 102 }}}, {"$limit": 1}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lte": 102 }}}, {"$limit": 2}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}} ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}]}} ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": {}}} ], "cursor": {} }'); -- test with sharded collections. SELECT documentdb_api.shard_collection('invmatch', 'sales', '{"order": "hashed"}', false); SELECT documentdb_api.shard_collection('invmatch', 'user_roles', '{"_id": "hashed"}', false); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 100} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 101} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$lookup": { "from": "user_roles", "pipeline": [ { "$match": {"user_id": 102} } ], "as": "roles" }}, { "$inverseMatch": {"path": "rule", "input": "$roles"}}, {"$project": {"roles": 0, "rule": 0}} ], "cursor": {} }'); -- use from collection instead of lookup (new feature) SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 101}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}, {"$project": {"roles": 1, "_id": 0}}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lt": 102 }}}, {"$limit": 1}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$ne": 200 }}}, {"$limit": 1}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": { "$lte": 102 }}}, {"$limit": 2}]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}} ], "cursor": {} }'); -- drop and recreate so that it is not sharded and test with group and sort SELECT documentdb_api.drop_database('invmatch'); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 2, "user_id": 101, "role": "admin"}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 1, "user_id": 100, "role": "basic"}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 5, "user_id": 103, "role": "basic"}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 3, "user_id": 102, "role": "sales"}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 4, "user_id": 100, "role": "sales"}', NULL); SELECT documentdb_api.insert_one('invmatch','user_roles','{ "_id": 6, "user_id": 102, "role": "admin"}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 5, "order": 102, "order_total": 1000, "amount": 100, "rule": "admin"}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 1, "order": 100, "order_total": 50, "amount": 20, "rule": "basic"}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 2, "order": 102, "order_total": 1000, "amount": 300, "rule": "sales"}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 4, "order": 100, "order_total": 50, "amount": 5, "rule": "basic"}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 3, "order": 102, "order_total": 1000, "amount": 200, "rule": "basic"}', NULL); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, { "$group": { "_id": "$order", "ruleToCreate": {"$push": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$project": {"rule": {"role": {"$arrayToObject": [[[{"$literal": "$in"}, "$ruleToCreate"]]]}}, "_id": 1, "payed": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}}], "cursor": {} }'); SELECT documentdb_api.drop_collection('invmatch', 'payments'); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 5, "order": 102, "order_total": 1000, "amount": 100, "rule": { "role": "admin"}}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 1, "order": 100, "order_total": 50, "amount": 20, "rule": { "role": "basic"}}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 2, "order": 102, "order_total": 1000, "amount": 300, "rule": { "role": "sales"}}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 4, "order": 100, "order_total": 50, "amount": 5, "rule": { "role": "basic"}}', NULL); SELECT documentdb_api.insert_one('invmatch','payments','{ "_id": 3, "order": 102, "order_total": 1000, "amount": 200, "rule": { "role": "admin"}}', NULL); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 102}}]}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": [{"$match": {"user_id": 100}}]}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ { "$group": { "_id": "$order", "rule": {"$mergeObjects": "$rule"}, "payed": {"$sum": "$amount"}}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": 1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('invmatch', '{ "aggregate": "payments", "pipeline": [ {"$sort": {"order": -1}}, {"$inverseMatch": {"path": "rule", "from": "user_roles", "pipeline": []}}], "cursor": {} }'); -- negative cases SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": {}, "input": "$roles"}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "", "input": "$roles"}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": [true]}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": true}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "input": {}, "from": "collection"}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "collection"}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"rule": "rule"}} ], "cursor": {} }'); SELECT document from bson_aggregation_pipeline('invmatch', '{ "aggregate": "sales", "pipeline": [ { "$inverseMatch": {"path": "rule", "from": "mycoll", "pipeline": []}} ], "cursor": {} }'); bson_aggregation_stage_lookup_pg17_tests.sql000066400000000000000000000002621507310017400376560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 60000; SET documentdb.next_collection_id TO 6000; SET documentdb.next_collection_index_id TO 6000; \i sql/bson_aggregation_stage_lookup_tests_core.sqlbson_aggregation_stage_lookup_tests.sql000066400000000000000000000002621507310017400370200ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 60000; SET documentdb.next_collection_id TO 6000; SET documentdb.next_collection_index_id TO 6000; \i sql/bson_aggregation_stage_lookup_tests_core.sqlbson_aggregation_stage_lookup_tests_core.sql000066400000000000000000001357401507310017400400420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 4, "item_name" : ["shirt", "hat", "pants"], "price" : 10, "order_quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 5}', NULL); SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 1, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 120 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items',' { "_id" : 11, "item_code" : "shirt", "product_description": "product 1", "stock_quantity" : 240 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 2, "item_code" : "hat", "product_description": "product 2", "stock_quantity" : 80 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 3, "item_code" : "shoes", "product_description": "product 3", "stock_quantity" : 60 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 4, "item_code" : "pants", "product_description": "product 4", "stock_quantity" : 70 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 5, "item_code" : null, "product_description": "product 4", "stock_quantity" : 70 }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 6, "item_code" : {"a": "x", "b" : 1, "c" : [1, 2, 3]}, "product_description": "complex object" }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 7, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); SELECT documentdb_api.insert_one('db','catalog_items','{ "_id" : 8, "item_code" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"], "product_description": "complex array" }', NULL); -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases'); -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Create Index on catalog_items SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "catalog_items", "indexes": [ {"key": {"item_code": 1}, "name": "idx_catalog_items_item_code"} ] }', true ); -- Test Index pushdown SELECT documentdb_distributed_test_helpers.drop_primary_key('db','catalog_items'); BEGIN; set local enable_seqscan TO off; EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; ROLLBACK; -- Insert data into a new collection to be sharded (shard key can't be an array, but can be null or object) SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 1, "item_name" : "shirt", "price" : 12, "order_quantity" : 2 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases_sharded','{ "_id" : 2, "item_name" : "pants", "price" : 20, "order_quantity" : 1 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 3, "item_name" : "hat", "price" : 10, "order_quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 4}', NULL); SELECT documentdb_api.insert_one('db','customer_purchases_sharded',' { "_id" : 5, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); -- Shard customer_purchases collection on item_name SELECT documentdb_api.shard_collection('db','customer_purchases_sharded', '{"item_name":"hashed"}', false); -- Test filter generation on sharded left collection SELECT bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') FROM documentdb_api.collection('db', 'customer_purchases_sharded'); -- Test Index pushdown on sharded left collection BEGIN; set local enable_seqscan TO off; SET JIT To off; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; $Q$); ROLLBACK; SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'customer_purchases_sharded') order by object_id; -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; set citus.enable_local_execution to off; -- Test lookup on sharded left collection WITH t1_0 AS(SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS lookup_filters FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1_0.document, t2_0_agg.matched_array , 'matched_docs'::text) as document FROM t1_0 LEFT JOIN LATERAL ( WITH "LookupStage_0_0" as (SELECT * FROM documentdb_api.collection('db', 'catalog_items') AS t2_0 WHERE bson_dollar_in(t2_0.document, t1_0.lookup_filters) ) SELECT COALESCE(array_agg("LookupStage_0_0".document::documentdb_core.bson), '{}'::bson[]) as matched_array FROM "LookupStage_0_0" ) t2_0_agg ON TRUE; -- Test lookup on sharded left collection (rewrite avoiding the the CTE error) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Apply subpipeline on the out side of the join. This is a better execution plan since -- we are not applying the subpipeline on the entire 'from' collection WITH simple_lookup as ( WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 -- perform lookup LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ) -- subpipeline moved down SELECT bson_dollar_add_fields(bson_dollar_lookup_project, '{"matched_docs.hello": "newsubpipelinefield"}') from simple_lookup; WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')), -- subpipeline moved up t2 as (SELECT bson_dollar_add_fields(document, '{"matched_docs.hello": "newsubpipelinefield"}') as document from documentdb_api.collection('db', 'catalog_items')) -- now perform lookup SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Lookup subpipeline applied after the join is done (this is the community version semantics) WITH lookup_stage as ( -- Create CTE for the left/source collection (say t1) WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"item_code" : "item_name"}') AS match, 'mdocs' asname FROM documentdb_api.collection('db', 'customer_purchases_sharded')) SELECT t1.document, t2_agg.document as matched FROM t1 -- perform lateral join on the right collection (aka joined collection) LEFT JOIN LATERAL ( SELECT document FROM documentdb_api.collection('db', 'catalog_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE ), -- Apply subpipeline after lateral join subpipeline_stage1 as ( SELECT lookup_stage.document, bson_dollar_add_fields(lookup_stage.matched, '{"new": "field"}') as matched from lookup_stage) -- Aggregate the results so, if there multiple matches they are folded in an array SELECT bson_dollar_lookup_project(subpipeline_stage1.document, COALESCE(array_agg(subpipeline_stage1.matched::documentdb_core.bson), '{}'::bson[]), 'matched_docs'::text) FROM subpipeline_stage1 GROUP BY subpipeline_stage1.document; set citus.enable_local_execution to on; -- Test coalesce path, return empty array when no match found SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 0, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 1, "a": null}', NULL); SELECT documentdb_api.insert_one('db','coalesce_source','{"_id": 2}', NULL); SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 0, "b": 1}', NULL); SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 1, "b": null}', NULL); SELECT documentdb_api.insert_one('db','coalesce_foreign','{"_id": 2}', NULL); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') FROM documentdb_api.collection('db', 'coalesce_source'); WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"nonex" : "a"}') AS match FROM documentdb_api.collection('db', 'coalesce_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'coalesce_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Test dotted path SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 0, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 1, "a": null}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 2}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_source','{"_id": 3, "a": {"c": 1}}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 0, "b": 1}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 1, "b": null}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 2}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 3, "b": {"c" : 1}}', NULL); SELECT documentdb_api.insert_one('db','dotted_path_foreign','{"_id": 4, "b": {"c" : 2}}', NULL); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') FROM documentdb_api.collection('db', 'dotted_path_source'); WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_path_foreign') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Empty from collection tests SELECT * FROM documentdb_api.collection('db', 'from1NonExistent'); WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b.c" : "a.c"}') AS match FROM documentdb_api.collection('db', 'dotted_path_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'from1NonExistent') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Dotted path on mathched array name (some.documents) SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 0, "a": {"b" : 1}}', NULL); SELECT documentdb_api.insert_one('db','dotted_as_source2','{"_id": 1}', NULL); SELECT documentdb_api.insert_one('db','dotted_as_foreign2','{"_id": 0, "target": 1}', NULL); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source2'); WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"target" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source2')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'same.documents'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_foreign2') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- Dotted path that goes through objects and arrays SELECT documentdb_api.insert_one('db','dotted_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 0}', NULL); SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 1}', NULL); SELECT documentdb_api.insert_one('db','dotted_foreign','{"_id": 2}', NULL); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"_id" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_source'); -- Dotted AS path that is already present in the left document SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 0, "a": [{"b": 1}, {"b": 2}]}', NULL); SELECT documentdb_api.insert_one('db','dotted_as_source','{"_id": 1, "c": [{"d": 1}, {"d": 2}]}', NULL); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') FROM documentdb_api.collection('db', 'dotted_as_source'); WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"c.d" : "a.b"}') AS match FROM documentdb_api.collection('db', 'dotted_as_source')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'a.b'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE(array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'dotted_as_source') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- (B) Lookup with pipeline support -- (B).1 Data Ingestion SELECT documentdb_api.insert_one('db','establishments',' {"_id": 1, "establishment_name": "The Grand Diner", "dishes": ["burger", "fries"], "order_quantity": 100 , "drinks": ["soda", "juice"]}', NULL); SELECT documentdb_api.insert_one('db','establishments','{ "_id": 2, "establishment_name": "Pizza Palace", "dishes": ["veggie pizza", "meat pizza"], "order_quantity": 120, "drinks": ["soda"]}', NULL); SELECT documentdb_api.insert_one('db','menu','{ "_id": 1, "item_name": "burger", "establishment_name": "The Grand Diner"}', NULL); SELECT documentdb_api.insert_one('db','menu','{ "_id": 2, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "water"}', NULL); SELECT documentdb_api.insert_one('db','menu','{ "_id": 3, "item_name": "veggie pizza", "establishment_name": "Pizza Palace", "drink": "soda"}', NULL); -- (B).1 Simple Lookup with pipeline -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $match : { order_quantity : { $gt, 110}} -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); -- (B).2 Index creation on the from collection SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "establishments", "indexes": [ {"key": {"establishment_name": 1}, "name": "idx_establishments_establishment_name"}, {"key": {"order_quantity": 1}, "name": "idx_establishments_order_quantity"} ] }', true ); -- (B).3.a Index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; -- Adding a $sort in the pipeline BEGIN; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; BEGIN; SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "order_quantity": { "$gt": 110 } }}, { "$sort": { "_id": 1 }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; -- (B).3.b Index usage with optimization: (if lookup has a join condition and the lookup pipeline has $match as the first -- stage we push the $match filter up with the join. If both conditions are one same property both the filters should be -- part of the index condition) BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$match": { "establishment_name" : { "$eq" : "Pizza Palace" } }}], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; -- (B).4 Nested lookup pipeline (lookup pipeline containing lookup) -- { -- $lookup : -- { -- from : establishments, -- to: menu, -- localField: establishment_name, -- foreignField: establishment_name, -- pipeline: { -- [ -- { -- $lookup : { -- from : establishments, -- to: establishments, -- localField: _id, -- foreignField: _id, -- pipeline: { -- [ -- { unwind : "dishes"} -- ] -- } -- } -- } -- ] -- } -- } --} SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); -- (B).5 Nested lookup pipeline (lookup pipeline containing lookup) index usage BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$unwind": "$dishes" } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "as": "matched_docs_id" } } ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "bar": "$dishes" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$sort": { "dishes": 1 } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO off; EXPLAIN(costs off) SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "menu", "pipeline": [ { "$lookup": { "from": "establishments", "pipeline": [ { "$lookup": { "from": "establishments", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$project": { "_id": "bar" } } ], "as": "matched_docs_id" } } ], "as": "matched_docs", "localField": "establishment_name", "foreignField": "establishment_name" }} ], "cursor": {} }'); ROLLBACK; -- Lookup Tests for array index-based paths SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 1, "a" : [{"x" : 1}] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 2, "a" : {"x" : 1} }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 3, "a" : [{"x": 2}, {"x": 1}] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 4, "a" : [{"y": 1}, {"x": 1}] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 5, "a" : [2, 3] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 6, "a" : {"x": [1, 2]} }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 7, "a" : [{"x": 1}, {"y": 1}] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 8, "a" : [{"x": [1, 2]}, {"y": 1}] }', NULL); SELECT documentdb_api.insert_one('db','array_path_purchases',' { "_id" : 9, "a" : [[{"x": [1, 2]}, {"y": 1}]] }', NULL); SELECT documentdb_api.insert_one('db','array_path_items',' { "_id" : 1, "b" : 1 }', NULL); -- Test filter generation SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.x.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.1.y"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); SELECT bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.0.x"}'), document FROM documentdb_api.collection('db', 'array_path_purchases'); -- Test full lookup sql WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"b" : "a.0.x"}') AS match FROM documentdb_api.collection('db', 'array_path_purchases')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_items') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; WITH t1 AS (SELECT document, bson_dollar_lookup_extract_filter_expression(document, '{"a.0.x" : "b"}') AS match FROM documentdb_api.collection('db', 'array_path_items')) SELECT bson_dollar_lookup_project(t1.document, t2_agg.agg, 'matched_docs'::text) FROM t1 LEFT JOIN LATERAL ( SELECT COALESCE (array_agg(t2.document::documentdb_core.bson), '{}'::bson[]) as agg FROM documentdb_api.collection('db', 'array_path_purchases') AS t2 WHERE bson_dollar_in(t2.document, t1.match) ) t2_agg ON TRUE; -- test lookup with operator type document contents SELECT documentdb_api.insert_one('db', 'operator_lookup_left', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); SELECT documentdb_api.insert_one('db', 'operator_lookup_right', '{ "_id": 1, "a": 1, "b": { "$isArray": 1, "OtherField": 1 }}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "a", "foreignField": "a", "as": "myfoo" } }] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "operator_lookup_left", "pipeline": [ { "$project": { "_id": "500" }}, { "$lookup": { "from": "operator_lookup_right", "localField": "_id", "foreignField": "_id", "as": "myfoo" } }] }'); -- Test for Index push down crash when Foreign Field = '_id' and the target collection is sharded SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 1, "item_name" : "itemA", "price" : 12, "order_quantity" : 2 }', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test','{ "_id" : 2, "item_name" : "itemE", "price" : 20, "order_quantity" : 1 }', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 3, "item_name" : "itemC", "price" : 10, "order_quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 4, "item_name" : ["itemA", "itemC", "itemE"], "price" : 10, "order_quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 5}', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 6, "item_name" : {"a": "x", "b" : 1, "c" : [1, 2, 3]} }', NULL); SELECT documentdb_api.insert_one('db','purchases_pushdown_test',' { "_id" : 7, "item_name" : [{"a": { "b" : 1}}, [1, 2, 3], 1, "x"] }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemA", "item_description": "product 1", "in_stock" : 120 }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test',' { "_id" : "itemB", "item_description": "product 1", "in_stock" : 240 }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemC", "item_description": "product 2", "in_stock" : 80 }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemD", "item_description": "product 3", "in_stock" : 60 }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemE", "item_description": "product 4", "in_stock" : 70 }', NULL); SELECT documentdb_api.insert_one('db','items_pushdown_test','{ "_id" : "itemF", "item_description": "product 4", "in_stock" : 70 }', NULL); SELECT documentdb_api.shard_collection('db','items_pushdown_test', '{"_id":"hashed"}', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "purchases_pushdown_test", "pipeline": [ { "$lookup": { "from": "items_pushdown_test", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN -- UDF Unit test for merge documents at path SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path(NULL, NULL, NULL); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{}', 'a'); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'a'); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": "text"}', '{ "b" : true}', 'd'); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a'); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": { "b": "text", "c": true }}', '{ "random" : false }', 'a.b'); SELECT documentdb_api_internal.bson_dollar_merge_documents_at_path('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "random" : false }', 'a.b'); -- UDF tests for merge documents with override Array SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', false); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', false); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', false); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', false); SELECT documentdb_api_internal.bson_dollar_merge_documents(NULL, NULL, NULL); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{}', true); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": "text"}', '{ "a" : true}', true); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": { "b": "text", "c": true }}', '{ "a.b.random" : false }', true); SELECT documentdb_api_internal.bson_dollar_merge_documents('{"a": [{ "b": "text", "c": true }, { "b": "text2", "c": false }]}', '{ "a.b.random" : false }', true); -- todo: remove these duplicated tests SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id", "pipeline": [ { "$addFields": { "myBar": 1 } }, { "$limit": 10 }] } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs" } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "includeArrayIndex": "idx" } } ], "cursor": {} }'); -- this will not inline EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "_id" } }, { "$unwind": { "path": "$matched_docs", "preserveNullAndEmptyArrays" : true } } ], "cursor": {} }'); -- should inline and use LEFT JOIN -- Test for removal of inner join SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "customer_purchases", "indexes": [ { "key": { "item_name": 1 }, "name": "customer_purchases_item_name_1" } ] }', TRUE); BEGIN; set local enable_seqscan to off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); ROLLBACK; BEGIN; set local enable_seqscan to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "customer_purchases", "pipeline": [ { "$match": { "item_name": { "$exists": true } } }, { "$lookup": { "from": "catalog_items", "as": "matched_docs", "localField": "item_name", "foreignField": "item_code" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); ROLLBACK; -- do a multi layer lookup that matches on _id SELECT COUNT(documentdb_api.insert_one('db', 'source1', FORMAT('{ "_id": %s, "field1": "value%s", "fieldsource1": "foo" }', i, i)::bson)) FROM generate_series(1, 100) i; SELECT COUNT(documentdb_api.insert_one('db', 'source2', FORMAT('{ "_id": "value%s", "field2": "othervalue%s", "fieldsource2": "foobar" }', i, i)::bson)) FROM generate_series(1, 100) i; SELECT COUNT(documentdb_api.insert_one('db', 'source3', FORMAT('{ "_id": "othervalue%s", "field3": "someothervalue%s", "fieldsource3": "foobarfoo" }', i, i)::bson)) FROM generate_series(1, 100) i; SELECT COUNT(documentdb_api.insert_one('db', 'source4', FORMAT('{ "_id": "someothervalue%s", "field4": "yetsomeothervalue%s", "fieldsource4": "foobarbaz" }', i, i)::bson)) FROM generate_series(1, 100) i; -- create indexes on the intermediate fields SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "source1", "indexes": [ { "key": { "field1": 1 }, "name": "field1_1" } ] }', TRUE); ANALYZE documentdb_data.documents_6020; ANALYZE documentdb_data.documents_6021; ANALYZE documentdb_data.documents_6022; ANALYZE documentdb_data.documents_6023; -- should always pick up _id index. BEGIN; set local enable_indexscan to off; set local enable_bitmapscan to off; set local enable_material to off; set local documentdb.useLegacyForcePushdownBehavior to off; EXPLAIN (COSTS OFF, ANALYZE ON, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "source1", "pipeline": [ { "$match": { "field1": { "$eq": "value10" } } }, { "$lookup": { "from": "source2", "as": "source2_docs", "localField": "field1", "foreignField": "_id" } }, { "$unwind": { "path": "$source2_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source3", "as": "source3_docs", "localField": "source2_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source3_docs", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "source4", "as": "source4_docs", "localField": "source3_docs", "foreignField": "_id" } }, { "$unwind": { "path": "$source4_docs", "preserveNullAndEmptyArrays": true } } ]}'); ROLLBACK; -- Test lookup query building works with aggregates EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "abc", "pipeline": [ { "$lookup": { "from": "def", "as": "lookup_count", "let" : { "a" : "$A", "b" : "$B", "c" : "$C" }, "pipeline": [ { "$group": { "_id": "$groupId", "total_score": { "$sum": "$Abc.score" }, "count": { "$sum": 1 } } }] }}]}');bson_aggregation_stage_merge_tests.sql000066400000000000000000001505221507310017400366130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 7850000; SET documentdb.next_collection_id TO 7850; SET documentdb.next_collection_index_id TO 7850; --Test without Enabling feature flag of $merge SELECT documentdb_api.insert_one('sourceDB','withoutFlag',' { "_id" : 1, "country" : "India", "state" : "Rajasthan", "Code" : "RJ03" }', NULL); SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "withoutFlag", "pipeline": [ {"$merge" : { "into": "targetwithoutFlag" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); --Test without Enabling flag for $merge stage target collection creation SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "withoutFlag", "pipeline": [ {"$merge" : { "into": "targetwithoutFlag" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); -- custom udf testing SELECT * FROM documentdb_api_internal.bson_dollar_merge_add_object_id('{"_id" : 1, "a" : 1}', documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}')); SELECT * FROM documentdb_api_internal.bson_dollar_merge_add_object_id('{"a" : 1, "_id" : 1}', documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}')); SELECT count(*) FROM documentdb_api_internal.bson_dollar_merge_generate_object_id('{"a" : "dummy bson"}'); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : 1, "b" : 3}', 'a'::TEXT), 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : 2, "b" : 2}', 'a'::TEXT), 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : {"b" : 1 }, "c" : 2}', '{"a" : {"b" : 1}}', 'a.b'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : {"b" : 1 }, "c" : 2}', '{"a" : {"b" : 2}}', 'a.b'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : [1,2,3], "c" : 2}', '{"a" : 2}', 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : [1,2,3], "c" : 2}', '{"a" : 4}', 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : [1,2,3], "b" : 3}','a'::TEXT), 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"b" : 3}', 'a'::TEXT), 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_join('{"a" : 1, "b" : 2}', documentdb_api_internal.bson_dollar_extract_merge_filter('{"a" : null}','a' ::TEXT), 'a'::TEXT); SELECT * FROM documentdb_api_internal.bson_dollar_merge_fail_when_not_matched('{"a" : "this is a dummy bson"}', 'this is dummy text'::TEXT); -- Merge with default option SELECT documentdb_api.insert_one('defDb','defSrc',' { "_id" : 1, "a" : 1 }', NULL); SELECT documentdb_api.insert_one('defDb','defSrc',' { "_id" : 2, "a" : 2 }', NULL); SELECT documentdb_api.insert_one('defDb','defTar',' { "_id" : 1, "b" : 2 }', NULL); SELECT * FROM aggregate_cursor_first_page('defDb', '{ "aggregate": "defSrc", "pipeline": [ {"$merge" : { "into": "defTar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('defDb', 'defTar'); -- simplest test case working SELECT documentdb_api.insert('db', '{"insert":"moviesDB", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : { "into": "budgets" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'budgets'); -- simple test case target database is not same as source database SELECT documentdb_api.insert_one('sourceDB','sourceDumpData',' { "_id" : 1, "country" : "India", "state" : "Rajasthan", "Code" : "RJ03" }', NULL); SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "sourceDumpData", "pipeline": [ {"$merge" : { "into": {"db" : "targetDB" , "coll" : "targetDumpData"}, "on" : "_id", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('targetDB', 'targetDumpData'); -- object id missing test SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$project" : {"_id" : 0}}, {"$merge" : { "into": "budgets2" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT count(document) FROM documentdb_api.collection('db', 'budgets2'); -- test when merge input is string SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : "normalString" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "moviesDB", "pipeline": [ {"$merge" : "dotted.String" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','normalString'); SELECT document FROM documentdb_api.collection('db', 'dotted.String'); -- unique index test SELECT documentdb_api.insert_one('db','uniqueIndexTestSrc',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"a": 1}, "name": "index_2", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"e": 1}, "name": "index_3", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"f": 1}, "name": "index_4", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["b" , "c" , "a"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["c" , "b" , "a"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : "_id", "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "uniqueIndexTestSrc", "pipeline": [ {"$merge" : { "on" : ["_id"], "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'uniqueIndexTestTarget'); -- _id unique index test SELECT documentdb_api.insert_one('db','objectIDUniqueIndex',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1, "field1" : 1, "field2" : 2}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "uniqueIndexTestTarget", "indexes": [{"key": {"field1": 1, "field2" : 1, "_id" : 1}, "name": "index_id", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : "_id","into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["_id"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["field1","_id","field2"],"into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDUniqueIndex", "pipeline": [ {"$merge" : { "into": "uniqueIndexTestTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); --test source collection is sharded. SELECT documentdb_api.insert('db', '{"insert":"soruceShardedTest", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); SELECT documentdb_api.shard_collection('db', 'soruceShardedTest', '{ "employee": "hashed" }', false); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "soruceShardedTest", "pipeline": [ {"$merge" : { "into": "soruceShardedTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'soruceShardedTarget'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "soruceShardedTest", "pipeline": [{"$project" : { "_id" : 1, "employee" : 1, "Budget" : {"$add" : ["$Budget" , 1000]} }} ,{"$merge" : { "into": "soruceShardedTarget", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'soruceShardedTarget'); -- simple replace scenario SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplace", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataReplace", "documents":[ { "_id" : 1, "a": 10 }, { "_id" : 3, "a": 30 }, { "_id" : 4, "a": 40 } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplace", "pipeline": [ {"$merge": {"into": "targetDataReplace", "whenMatched": "replace", "whenNotMatched": "discard"}} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataReplace'); -- let's create index and match on other key and try to replace _id field when source and target ID are same SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplaceId", "documents":[{ "_id" : 1, "a": 10 }]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataReplaceId", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataReplaceId", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceId", "pipeline": [ {"$merge" : { "into": "targetDataReplaceId", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataReplaceId'); -- let's create index and match on other key and try to replace _id field whe source and target ID's are different. SELECT documentdb_api.insert('db', '{"insert":"sourceDataReplaceIdDiff", "documents":[{ "_id" : 1, "a": 10 }]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataReplaceIdDiff", "documents":[{ "_id" : 2, "a": 10, "b" : 10 }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataReplaceIdDiff", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceIdDiff", "pipeline": [ {"$merge" : { "into": "targetDataReplaceIdDiff", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- Now let's see what happens when we are not projecting _id from source and source _id is getting generated and if source objectID is generated then it will be not same as targets. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataReplaceIdDiff", "pipeline": [ {"$project" : { "_id": 0 }}, {"$merge" : { "into": "targetDataReplaceIdDiff", "on" : "a", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataReplaceIdDiff'); -- simple merge scenario SELECT documentdb_api.insert('db', '{"insert":"sourceWhenMatchMerge", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetWhenMatchMerge", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); -- As all doc from source matches with target so there should not be any change in target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); -- Let's Add one more column by projection and see if it merges in target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$project" : {"_id" : 1, "new_column" : "testing merge"}}, {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); -- let's try to modify value of existing column of target collection. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceWhenMatchMerge", "pipeline": [ {"$project" : {"_id" : 1, "year" : {"$add" : ["$year" , 1]}}}, {"$merge" : { "into": "targetWhenMatchMerge", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); select document from documentdb_api.collection('db', 'targetWhenMatchMerge'); -- let's create index and match on other key and try to merge when _id field on source and target ID are same SELECT documentdb_api.insert('db', '{"insert":"sourceDataMergeId", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataMergeId", "documents":[{ "_id" : 1, "a": 10 }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMergeId", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeId", "pipeline": [ {"$merge" : { "into": "targetDataMergeId", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataMergeId'); -- let's create index and match on other key and try to merge when _id field on source and target ID are different SELECT documentdb_api.insert('db', '{"insert":"sourceDataMergeIdDiff", "documents":[{ "_id" : 1, "a": 10, "b" : 10 }]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataMergeIdDiff", "documents":[{ "_id" : 2, "a": 10 }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMergeIdDiff", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeIdDiff", "pipeline": [ {"$merge" : { "into": "targetDataMergeIdDiff", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataMergeIdDiff'); -- Now let's see what happens when we are not projecting _id from source and source _id is getting generated and if source objectID is generated then it will be not same as target's. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMergeIdDiff", "pipeline": [ {"$project" : { "_id": 0 }}, {"$merge" : { "into": "targetDataMergeIdDiff", "on" : "a", "whenMatched" : "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','targetDataMergeIdDiff'); -- merge whenNotMatched fail -- 1) this will not fail as all the doc from source are matching with target SELECT documentdb_api.insert('db', '{"insert":"sourceNotMatchedFailed", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetNotMatchedFailed", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 3, "a": 3, "b": "g" } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedFailed", "pipeline": [ {"$merge" : { "into": "targetNotMatchedFailed", "whenMatched" : "replace" , "whenNotMatched" : "fail" } } ], "cursor": { "batchSize": 1 } }', 4294967294 ); select document FROM documentdb_api.collection('db','targetNotMatchedFailed'); -- 2) this will fail as not one source doc is not matching with target and user has selected failure option. SELECT documentdb_api.insert_one('db','sourceNotMatchedFailed',' { "_id" : 10, "a" : 1, "b" : 1 }', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedFailed", "pipeline": [ {"$merge" : { "into": "targetNotMatchedFailed", "whenMatched" : "replace" , "whenNotMatched" : "fail" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); select document FROM documentdb_api.collection('db','targetNotMatchedFailed'); -- merge whenNotMatched Discard SELECT documentdb_api.insert('db', '{"insert":"sourceNotMatchedDiscard", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetNotMatchedDiscard", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 5, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceNotMatchedDiscard", "pipeline": [ {"$merge" : { "into": "targetNotMatchedDiscard", "whenMatched" : "replace" , "whenNotMatched" : "discard" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); select document FROM documentdb_api.collection('db','targetNotMatchedDiscard'); -- WhanMathched : keepexisting SELECT documentdb_api.insert('db', '{"insert":"sourceMatchedKeepExisting", "documents":[ { "_id" : 1, "a": 1, "b": "a" }, { "_id" : 2, "a": 2, "b": "b" }, { "_id" : 3, "a": 3, "b": "c" } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetMatchedKeepExisting", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedKeepExisting", "pipeline": [ {"$merge" : { "into": "targetMatchedKeepExisting", "whenMatched" : "keepExisting" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); select document from documentdb_api.collection('db','targetMatchedKeepExisting'); -- WhanMathched : fail SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedKeepExisting", "pipeline": [ {"$merge" : { "into": "targetMatchedKeepExisting", "whenMatched" : "fail" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); select document FROM documentdb_api.collection('db','targetMatchedKeepExisting'); -- whenMatched : _id are getting changed in case of replace SELECT documentdb_api.insert('db', '{"insert":"sourceMatchedIdTests", "documents":[ { "_id" : 4, "a": 1, "b": "a" }, { "_id" : 5, "a": 2, "b": "b" }, { "_id" : 6, "a": 3, "b": "c" } ]}'); SELECT documentdb_api.insert('db', '{"insert":"targetMatchedIdTests", "documents":[ { "_id" : 1, "a": 1, "b": "e" }, { "_id" : 2, "a": 2, "b": "f" }, { "_id" : 6, "a": 3, "b": "g" } ]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetMatchedIdTests", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceMatchedIdTests", "pipeline": [ {"$merge" : { "on" : "a", "into": "targetMatchedIdTests", "whenMatched" : "replace" , "whenNotMatched" : "insert" } } ] , "cursor": { "batchSize": 1 } }', 4294967294); select document FROM documentdb_api.collection('db','targetMatchedIdTests'); -- complex pipeline with last stage merge with replace and insert mode. SELECT documentdb_api.insert_one('db','bson_agg_merge_src',' {"_id": 1, "company": "Company A", "products": ["product1", "product2"], "amount": 100 , "services": ["service1", "service2"]}', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_src','{ "_id": 2, "company": "Company B", "products": ["product3", "product4"], "amount": 120, "services": ["service3"]}', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 1, "item": "product1", "company_name": "Company A"}', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 2, "item": "product3", "company_name": "Company B", "extra": "value1"}', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_dest','{ "_id": 3, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_dest", "pipeline": [ { "$lookup": { "from": "bson_agg_merge_src", "pipeline": [ { "$match": { "amount": { "$gt": 110 } }}], "as": "joined_docs", "localField": "company_name", "foreignField": "company" } }, {"$sort" : {"_id" : -1}} , {"$group" :{"_id" : "$company_name"}}, {"$project" : {"joined_docs" : 0}}, {"$merge" : { "into": "bson_agg_merge_final", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','bson_agg_merge_final'); -- when target collection has array SELECT documentdb_api.insert_one('db','bson_agg_merge_src_array',' { "_id" : 1, "a" : 1 }', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_src_array',' { "_id" : 2, "a" : 5 }', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_dest_array',' { "_id" : 1, "a" : [1,2,3,4] }', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bson_agg_merge_dest_array", "indexes": [{"key": {"a": 1}, "name": "index_2", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_src_array", "pipeline":[ {"$merge" : { "into": "bson_agg_merge_dest_array", "on" : "a", "whenMatched" : "replace", "whenNotMatched" : "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','bson_agg_merge_dest_array'); -- when query has sort clause SELECT documentdb_api.insert_one('db','bson_agg_merge_sort_src','{ "_id": 1, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); SELECT documentdb_api.insert_one('db','bson_agg_merge_sort_src','{ "_id": 2, "item": "product5", "company_name": "Company C", "extra": "value3"}', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_sort_src", "pipeline": [ {"$sort" : {"_id" : -1}} , {"$merge" : { "into": "bson_agg_merge_sort_dest", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','bson_agg_merge_sort_dest'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "bson_agg_merge_dest", "pipeline": [ {"$sort" : {"_id" : -1}} , {"$group" : {"_id" : "$_id"}}, {"$merge" : { "into": "bson_agg_merge_sort_group", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','bson_agg_merge_sort_group'); -- when query has multiple sort clause or multiple resjunk columns SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 1, "a" : 45, "b" : 10 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 2, "a" : 87, "b" : 7 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 3, "a" : 29, "b" : 17 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 4, "a" : 13, "b" : 99 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 5, "a" : 45, "b" : 113 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 6, "a" : 87, "b" : 76 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 7, "a" : 29, "b" : 86 }', NULL); SELECT documentdb_api.insert_one('db','resJunkSrc',' { "_id" : 8, "a" : 13, "b" : 20 }', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "resJunkSrc", "pipeline": [ {"$sort" : {"a" : -1, "b" : 1}} , {"$merge" : { "into": "resJunkeTarget", "whenMatched": "replace", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db','resJunkeTarget'); -- test when source collection is view SELECT documentdb_api.create_collection('db', 'sourceCollForView'); SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 2, "a" : 2, "b" : 2 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceCollForView", "documents":[{ "_id" : 3, "a" : 3, "b" : 3 }]}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "sourceView", "viewOn": "sourceCollForView", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceView", "pipeline": [ {"$merge" : { "into" : "targetViewedOutput" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'targetViewedOutput'); -- Let's look at explain plan for unshared collection SELECT documentdb_api.create_collection('db', 'sourceExplain'); SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 2, "a" : 2, "b" : 1 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 3, "a" : 3, "b" : 1 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 4, "a" : 4, "b" : 1 }]}'); SELECT documentdb_api.insert('db', '{"insert":"sourceExplain", "documents":[{ "_id" : 5, "a" : 5, "b" : 1 }]}'); EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); --explain when merge is not first stage of pipeline EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{ "$match" : {"_id" :1}}, {"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); -- Let's look at explain plan for sharded collection SELECT documentdb_api.shard_collection('db', 'sourceExplain', '{ "a": "hashed" }', false); EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "whenMatched" : "replace" }} ] }'); -- Let's look at explain plan for when on field is indexed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "sourceExplain", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "explainTarget", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); -- citus will wrap our query in a subquery: SELECT document, target_shard_key_value FROM (our query) AS subquery EXPLAIN VERBOSE SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "sourceExplain", "pipeline": [{"$merge" : { "into": "explainTarget", "on" : "a", "whenMatched" : "replace" }} ] }'); -- source and target are same SELECT documentdb_api.create_collection('db', 'AsSourceAsTarget'); SELECT documentdb_api.insert_one('db','AsSourceAsTarget',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "AsSourceAsTarget", "pipeline": [ {"$project" : {"new" : "data"}}, {"$merge" : { "into": "AsSourceAsTarget" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'AsSourceAsTarget'); -- Negative tests : Invalid input SELECT documentdb_api.create_collection('db', 'negInvalidInput'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : 1} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "xman" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "apple"} }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : 1} }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "database", "coll" : 1} }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : {"db" : "apple", "haha" : "haha"} }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "on" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "on" : [1] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenMatched" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenMatched" : "falsevalue" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenNotMatched" : 1 }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl", "whenNotMatched" : "falsevalue" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl" }}, {} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "outColl" }}, {"project" : {"a" : 1} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into": "targetNotExists", "on" : [] }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- Negative test cases when on fields value are not unique index. SELECT documentdb_api.create_collection('db', 'indexNegColl'); SELECT documentdb_api.insert_one('db','indexNegColl',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); SELECT documentdb_api.create_collection('db', 'indexNegOutColl'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"b": 1}, "name": "index_2", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"c": 1}, "name": "index_3", "unique" : false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"d": 1}, "name": "index_A"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"e": 1, "f" : 1, "g" : 1}, "name": "index_4"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"x": 1, "y" : 1, "z" : 1}, "name": "index_5", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"parag": 1}, "name": "index_6", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"jain": 1}, "name": "index_7", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"partialTest": 1}, "name": "index_8", "unique" : true, "partialFilterExpression": {"a": {"$gt": 1}}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexNegOutColl", "indexes": [{"key": {"partialTest": 1, "partialTest2" : 1}, "name": "index_9", "unique" : true, "partialFilterExpression": {"a": {"$gt": 1}}}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "c" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "d" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "c"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["b", "d"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "e" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["f","g"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["e","f","g"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "f" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","z","y","f"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "x" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","z"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","_id"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["parag","jain"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["partialTest"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : "partialTest" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["partialTest", "partialTest2"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a", "a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["a", "b", "b"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["c", "a", "c"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["x","y"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "indexNegOutColl", "on" : ["z","x"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- _id Negative unique test SELECT documentdb_api.insert_one('db','objectIDNegUniqueIndex',' { "_id" : 10, "a" : 1, "b" : 1, "c" : 1 , "d" : 1, "e" : 1, "f" : 1}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"b": 1}, "name": "index_2", "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "objectIDTargetNegUniqueIndex", "indexes": [{"key": {"a": 1, "b" : 1}, "name": "index_3", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["_id", "a"],"into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["a", "_id"], "into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "objectIDNegUniqueIndex", "pipeline": [ {"$merge" : { "on" : ["a", "_id", "b"], "into": "objectIDTargetNegUniqueIndex" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- Negative tests : when target collection does not exist SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["_id","a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "indexNegColl", "pipeline": [ {"$merge" : { "into": "targetNotExist", "on" : ["a","_id"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); --Negative test when target collection is a view SELECT documentdb_api.create_collection('db', 'targetCollForView'); SELECT documentdb_api.insert('db', '{"insert":"targetCollForView", "documents":[{ "_id" : 1, "a" : 1 }]}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "targetView", "viewOn": "targetCollForView", "pipeline": [ { "$sort": { "a": 1 } } ] }'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "targetCollForView", "pipeline": [ {"$merge" : { "into" : "targetView" }} ], "cursor": { "batchSize": 1 } }', 4294967294); --Negative tests : when on field is missing/array in source document SELECT documentdb_api.insert('db', '{"insert":"sourceDataMissing", "documents":[{ "_id" : 3, "b": "c" }]}'); SELECT documentdb_api.insert('db', '{"insert":"targetDataMissingTest", "documents":[{ "_id" : 3, "b": "c" }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataMissingTest", "indexes": [{"key": {"a": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMissing", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataMissing", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT documentdb_api.insert('db', '{"insert":"sourceDataArray", "documents":[{ "_id" : 3, "a" : [1,2,3], "b": "c" }]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataArray", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataArray", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT documentdb_api.insert('db', '{"insert":"sourceDataNull", "documents":[{ "_id" : 3, "a" : null , "b": "c" }]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataNull", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataNull", "pipeline": [ {"$merge" : { "into": "targetDataMissingTest", "on" : ["a"] }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- Negative test when non-Immutable function present in query -- As in below query we call empty_data_table() which is non-Immutable function because targetcollection in lookup stage is empty. SELECT documentdb_api.create_collection('db', 'nonImmutable'); SELECT documentdb_api.insert_one('db','nonImmutable',' { "_id" : 1, "a" : 1, "b" : 1 }', NULL); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ {"$lookup": {"from": "bar", "as": "x", "localField": "f_id", "foreignField": "_id"}}, {"$merge" : { "into": "bar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- As below query usage system_rows and random function which are non-Immutable functions. SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ { "$sample": { "size": 1000000 } }, {"$merge" : { "into": "bar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- Merge inside transaction BEGIN; SELECT documentdb_api.insert('db', '{"insert":"insideTransaction", "documents":[{ "_id" : 3, "a" : 3, "b": "c" }]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "insideTransaction", "pipeline": [ {"$merge" : { "into": "targetTransaction", "on" : "a" }} ], "cursor": { "batchSize": 1 } }', 4294967294); END; -- Option not supported failures SELECT documentdb_api.create_collection('db', 'optionNotSupported'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "negInvalidInput", "pipeline": [ {"$merge" : { "into" : "optionNotSupportedOut", "whenMatched" : [] }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT documentdb_api.shard_collection('db', 'optionNotSupportedOut', '{ "a": "hashed" }', false); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "optionNotSupported", "pipeline": [ {"$merge" : { "into" : "optionNotSupportedOut" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "optionNotSupported", "pipeline": [ { "$match": { "name": "test" } }, { "$graphLookup": {"from": "optionNotSupported", "startWith": "$id", "connectFromField": "id", "connectToField": "ReportsTo", "as": "reportingHierarchy"}}, {"$merge":{ "into": "targetDataReplace"}}], "cursor": { "batchSize": 1 } }', 4294967294); -- simple test case target database is not same as source database SELECT * FROM aggregate_cursor_first_page('sourceDB', '{ "aggregate": "sourceDumpData", "pipeline": [ {"$merge" : { "into": {"db" : "targetDB" , "coll" : "targetDumpData"}, "on" : "_id", "whenMatched" : "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- let's verify we insert or update proper data in database. --try to insert 16 MB Document SELECT documentdb_api.insert_one('db','sourceDataValidation','{ "_id": 1, "item": "a" }' , NULL); SELECT * FROM aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); --try to insert bad _id field SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3]}}, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }'); -- try to update 16 MB document SELECT documentdb_api.insert_one('db','targetDataValidation','{ "_id": 1, "item": "a" }' , NULL); SELECT * FROM aggregate_cursor_first_page('db', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$merge" : {"into" : "targetDataValidation"}} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); --try to update bad _id field SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "targetDataValidation", "indexes": [{"key": {"item": 1}, "name": "index_1", "unique" : true}]}', true); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3], "item" : 1}}, {"$merge" : {"into" : "targetDataValidation", "on" : "item"}} ], "cursor": { "batchSize": 1 } }'); -- Basic Test with enable Native colocation SET documentdb.enableNativeColocation=true; SELECT documentdb_api.insert('db', '{"insert":"nativeSrc", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); --insert SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nativeSrc", "pipeline": [ {"$merge" : { "into": "nativeTar" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'nativeTar'); --replace SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nativeSrc", "pipeline": [ {"$merge" : { "into": "nativeTar"}} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'nativeTar'); SET documentdb.enableNativeColocation=false; bson_aggregation_stage_out_tests_2.sql000066400000000000000000000362561507310017400365530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 9830000; SET documentdb.next_collection_id TO 9830; SET documentdb.next_collection_index_id TO 9830; -- simplest test case working with db database SELECT documentdb_api.insert('db', '{"insert":"source", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : "target"} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'target'); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "db", "coll" : "target2" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db', 'target2'); SELECT documentdb_api.drop_collection('db','source'); SELECT documentdb_api.drop_collection('db','target'); SELECT documentdb_api.drop_collection('db','target2'); -- simplest test case working SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 }, { "_id" : 2, "movie": "Captain America the winter soldier", "Budget": 170000000, "year": 2011 }, { "_id" : 3, "movie": "Aveneger Endgame", "Budget": 160000000, "year": 2012 }, { "_id" : 4, "movie": "Spider Man", "Budget": 150000000, "year": 2012 }, { "_id" : 5, "movie": "Iron Man 2", "Budget": 140000000, "year": 2013 }, { "_id" : 6, "movie": "Iron Man 1", "Budget": 130000000, "year": 2013 } ]}'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target"} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb', 'target'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "newdb", "coll" : "target2" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb', 'target2'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); SELECT documentdb_api.drop_collection('newdb','target2'); -- when source and target collection are same SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$project" : {"data" : "updating same"} } ,{"$out" : { "db" : "newdb", "coll" : "source" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb', 'source'); SELECT documentdb_api.drop_collection('newdb','source'); -- case where target collection already exist: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); SELECT documentdb_api.insert('newdb', '{"insert":"target", "documents":[{ "_id" : 1, "data": "This is target collection"}]}'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "newdb", "coll" : "target" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb', 'target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- when target db is different: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : { "db" : "db2", "coll" : "target" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('db2', 'target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('db2','target'); -- index validation: -- 1. If source and target are same collection, only data will get updated index should remain SELECT documentdb_api.insert('newdb', '{"insert":"src", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "src", "indexes": [{ "key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1" }] }'::documentdb_core.bson, true); SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "src", "indexes": [{ "key": {"his is some index" :1}, "name": "index_2" }] }'::documentdb_core.bson, true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "src" }') ORDER BY 1; SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "src", "pipeline": [ {"$project" : {"data" : "updating data"} }, {"$out" : { "db" : "newdb", "coll" : "src" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "src" }') ORDER BY 1; SELECT document FROM documentdb_api.collection('newdb', 'src'); SELECT documentdb_api.drop_collection('newdb','src'); -- 2. if target already exist only data will get updated index should remain SELECT documentdb_api.insert('newdb', '{"insert":"src", "documents":[{ "_id" : 1, "data": "This is source collection"}]}'); SELECT documentdb_api.insert('newdb', '{"insert":"tar", "documents":[{ "_id" : 1, "data": "This is target collection"}]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "tar", "indexes": [{ "key": {"a": 1, "b" : 1, "c" :1}, "name": "index_1" }] }'::documentdb_core.bson, true); SELECT documentdb_api_internal.create_indexes_non_concurrently('newdb', '{ "createIndexes": "tar", "indexes": [{ "key": {"his is some index" :1}, "name": "index_2" }] }'::documentdb_core.bson, true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "tar" }') ORDER BY 1; SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "src", "pipeline": [ {"$project" : {"data" : "updating data"} }, {"$out" : { "db" : "newdb", "coll" : "tar" } } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('newdb', '{ "listIndexes": "tar" }') ORDER BY 1; SELECT document FROM documentdb_api.collection('newdb', 'tar'); SELECT documentdb_api.drop_collection('newdb','src'); SELECT documentdb_api.drop_collection('newdb','tar'); -- complex query with last stage $out: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "company": "Company A", "products": ["product1", "product2"], "amount": 100 , "services": ["service1", "service2"]}', NULL); SELECT documentdb_api.insert_one('newdb','source','{ "_id": 2, "company": "Company B", "products": ["product3", "product4"], "amount": 120, "services": ["service3"]}', NULL); SELECT documentdb_api.insert_one('newdb','target','{ "_id": 1, "item": "product1", "company_name": "Company A"}', NULL); SELECT documentdb_api.insert_one('newdb','target','{ "_id": 2, "item": "product3", "company_name": "Company B", "extra": "value1"}', NULL); SELECT documentdb_api.insert_one('newdb','target','{ "_id": 3, "item": "product3", "company_name": "Company B", "extra": "value2"}', NULL); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "target", "pipeline": [ { "$lookup": { "from": "source", "pipeline": [ { "$match": { "quantity": { "$gt": 110 } }}], "as": "joined_docs", "localField": "company_name", "foreignField": "company" } }, {"$sort" : {"_id" : -1}} , {"$group" :{"_id" : "$company_name"}}, {"$project" : {"matched_docs" : 0}} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb','target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- case when _id is missing from last stage: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$project" : {"_id" : 0} } ,{"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT bson_dollar_project(document,'{"_id" : {"$gt" : ["$_id", null]} }') FROM documentdb_api.collection('newdb','target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- test when source collection is view SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); SELECT documentdb_api.create_collection_view('newdb', '{ "create": "sourceView", "viewOn": "source", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "sourceView", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document FROM documentdb_api.collection('newdb', 'target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- test when source is sharded: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); SELECT documentdb_api.shard_collection('newdb', 'source', '{ "a": "hashed" }', false); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT document from documentdb_api.collection('newdb','target'); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- Negative test cases SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : 1 } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"coll" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a", "coll" : "a", "other" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : "a", "coll" : 1} } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : {"db" : 1, "coll" : "a"} } ], "cursor": { "batchSize": 1 } }', 4294967294); -- test when target is view: SELECT documentdb_api.insert('newdb', '{"insert":"source", "documents":[{ "_id" : 1, "a" : 1, "b" : 1 }]}'); SELECT documentdb_api.create_collection_view('newdb', '{ "create": "targetView", "viewOn": "source", "pipeline": [ { "$project": { "_id": 1, "c" : {"$add" : ["$a","$b"]} } } ] }'); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "targetView" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT documentdb_api.drop_collection('newdb','source'); -- test when target is sharded: SELECT documentdb_api.insert_one('newdb','source',' {"_id": 1, "name": "Test Case"}', NULL); SELECT documentdb_api.insert_one('newdb','target',' {"_id": 1, "name": "Test Case"}', NULL); SELECT documentdb_api.shard_collection('newdb', 'target', '{ "a": "hashed" }', false); SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "source", "pipeline": [ {"$out" : "target" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT documentdb_api.drop_collection('newdb','source'); SELECT documentdb_api.drop_collection('newdb','target'); -- let's verify we insert or update proper data in database. --try to insert 16 MB Document SELECT documentdb_api.insert_one('newdb','sourceDataValidation','{ "_id": 1, "item": "a" }' , NULL); SELECT * FROM aggregate_cursor_first_page('newdb', FORMAT('{ "aggregate": "sourceDataValidation", "pipeline": [ {"$addFields" : { "newLargeField": "%s"} }, {"$out" : "targetDataValidation"} ], "cursor": { "batchSize": 1 } }',repeat('a', 16*1024*1024) )::bson, 4294967294); --try to insert bad _id field SELECT * FROM aggregate_cursor_first_page('newdb', '{ "aggregate": "sourceDataValidation", "pipeline": [ {"$project" : {"_id" : [1,2,3]}}, {"$out" : "targetDataValidation"} ], "cursor": { "batchSize": 1 } }'); -- Let's take a look at explain plan --1) colocated tables , single shard distributed SELECT documentdb_api.insert_one('newdb','explainsrc',' {"_id": 1, "name": "Test Case"}', NULL); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('newdb', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); --2) non colocated tables, hash shard distributed SELECT documentdb_api.insert_one('db','explainsrc',' {"_id": 1, "name": "Test Case"}', NULL); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); --3) sharded source SELECT documentdb_api.shard_collection('newdb', 'explainsrc', '{ "a": "hashed" }', false); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "explainsrc", "pipeline": [{"$out" : "target"} ] }'); -- simplest test case working with db database SELECT documentdb_api.insert('db', '{"insert":"source", "documents":[ { "_id" : 11, "movie": "Thor", "Budget": 123456, "year": 1987 } ]}'); --validate empty collection check SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "source", "pipeline": [ {"$out" : ""} ], "cursor": { "batchSize": 1 } }', 4294967294); -- out should fail when query has mutable function, if query non existent collection or query has $sample stage SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ {"$lookup": {"from": "bar", "as": "x", "localField": "f_id", "foreignField": "_id"}}, {"$out" : "bar" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "nonImmutable", "pipeline": [ { "$sample": { "size": 1000000 } }, {"$out" : "bar" } ], "cursor": { "batchSize": 1 } }', 4294967294);bson_aggregation_stage_project_tests.sql000066400000000000000000000356561507310017400371740ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 32000; SET documentdb.next_collection_id TO 3200; SET documentdb.next_collection_index_id TO 3200; SELECT documentdb_api.insert_one('db','projectops','{"_id":"1", "a" : { "b" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"2", "a" : { "b" : [ 0, 1, 2]} }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"6", "a" : [ { "c" : 0 }, 2 ] }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"8", "a" : { "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','projectops','{"_id":"9", "c" : { "d" : 1 } }', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b" : 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": 1 }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a" : { "b": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b.1 query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b.1": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b.1": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b.1 expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": { "1" : 1 } }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a" : { "b": { "1" : 1 } } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- path collsion due to conflicting paths SELECT bson_dollar_project(document, '{ "a.b.1": 1, "a.b": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b.1": 1, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- path collsion due to conflicting paths SELECT bson_dollar_project(document, '{ "a.b": 1, "a.b.1": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b": 1, "a.b.1": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b, and a.c query with id excluded and included - should be both a.b and a.c SELECT bson_dollar_project(document, '{ "a.b": 1, "a.c": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b": 1, "a.c": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b and a.c expressed as nested object SELECT bson_dollar_project(document, '{ "a" : { "b": 1, "c": 1 }, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a" : { "b": 1, "c": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- Hybrid: a.c and a.b as object and dotted. SELECT bson_dollar_project(document, '{ "a" : { "b": 1 }, "a.c": 1, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a" : { "c": 1 }, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b excluded query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b" : 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- basic a.b and a.c with mixed inclusion (error path) query with id excluded and included SELECT bson_dollar_project(document, '{ "a.b" : 1, "a.c": 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "a.b" : 1, "a.c": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- special case projections SELECT bson_dollar_project(document, '{ "_id" : 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- field 'const' projections - this just projects a const value for all rows. SELECT bson_dollar_project(document, '{ "_id" : 1, "c": "someString", "a": [ 1, 2, 3] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "c": "someString", "a": [ 1, 2, 3] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- mix and match field path projection and const value projection. SELECT bson_dollar_project(document, '{ "_id" : 1, "c": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "c": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- const field and path projection with the same field name - see which one wins - it's the one on the right. SELECT bson_dollar_project(document, '{ "_id" : 0, "a": [ "1" ], "a": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a": 1, "a": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- mix and match field path projection and const value projection. SELECT bson_dollar_project(document, '{ "_id" : 1, "a.g": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.g": [ "1" ], "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.g": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a": { "g": [ "1" ] }, "a.b": 1 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a": { "g": [ "1" ], "b": 1 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- mix and match field path projection and const values on different roots. SELECT bson_dollar_project(document, '{ "_id" : 0, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "c": 1, "e.f": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c.d": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c": [ "1" ] }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- field selector that is an object -- TODO - actual expression support SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a.c": { "$literal" : 1.0 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": { "$literal" : 1.0 } } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "c": "$a.b" }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": "$a.b" } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": 1, "a": { "c": "$a" } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "a.b": { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- Fields selector, intermediate node having hasField set tests SELECT bson_dollar_project(document, '{ "_id" : 0, "c": { "b" : "1"} , "x" : "1"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{ "_id" : 0, "x" : "1", "c": { "b" : "1" }}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- Add multiple function calls SELECT bson_dollar_project(document, '{ "a.b" : 1, "_id": 0 }'), bson_dollar_project(document, '{"a.c": 0, "_id": 0 }') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_unset('{ "_id": 1, "x": 1, "y": [{ "z": 1, "foo": 1 }] }', '{ "": ["x", "y.z"] }'); SELECT bson_dollar_unset('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": "copies" }'); SELECT bson_dollar_unset('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": ["isbn", "author.first", "copies.warehouse"] }'); -- in aggregation you can unset or project the _id away. SELECT bson_dollar_unset('{"_id": 1, "a": 1, "b": 2 }', '{ "": "_id" }'); SELECT bson_dollar_project('{"_id": 1, "a": 1, "b": 2 }', '{ "_id": 0 }'); -- Spec tree equivalency tests SELECT bson_dollar_project(document, '{"a.b.c" : "1"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b" : { "c": "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a" : { "b.c": "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- path collision tests SELECT bson_dollar_project(document, '{"a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "1"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b": 1, "a" : { "b" : { "c": "$_id"}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b": {"c" : 1.0}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b": {"c" : "$a.b"}, "a" : { "b" : { "c": { "d": "$_id"}}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b.c": "$_id", "a.b": "1.0"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": { "d": "$_id"}}}, "a.b": {"c" : 1.0}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- Invalid key format tests SELECT bson_dollar_project(document, '{"$a.b": 1, "a.b.c": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"$isArray": 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"$keyName": "newVal"}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT documentdb_api.insert_one('db','projectops','{"_id":"10", "a" : { "b" : { "c" : "abc" } } }', NULL); -- Spec tree equivalency tests SELECT bson_dollar_project(document, '{"a.b.c" : 1}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a.b" : { "c": 1}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a" : { "b.c": 1}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT bson_dollar_project(document, '{"a" : { "b" : { "c": 1}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; SELECT documentdb_api.insert_one('db','projectops','{"_id":"11", "a" : { "b_" : { "c" : { "d" : 100 } }, "c" : { "d" : { "e" : "_e"}}}}', NULL); -- Spec tree test to check if a node is incorrectly marked with Intermediate_WithField SELECT bson_dollar_project(document, '{"a.b.c" : { "d" : 1 }, "a.c.d" : {"e" : "1"}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- test to check if internal "_id" respects the inclusion/exclusion SELECT documentdb_api.insert_one('db','projectops','{"_id":"12", "a" : { "_id" : { "idVal" : 100 }, "b" : { "c" : { "_id" : "idVal"}}}}', NULL); SELECT bson_dollar_project(document, '{"_id" : 1, "a" : {"_id" : 1}, "a.b" : { "c" : {"_id" : 0}}}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; -- Test nested array projections SELECT bson_dollar_project('{"_id":"1", "a" : [1, {"d":1}, [3, 4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); SELECT bson_dollar_project('{"_id":"1", "a" : [1, {"d":1}, [ { "c" : { "b" : 1 } },4], "x"] }', '{"a" : { "c" : { "d": "1"}}}'); -- a.b.0 excluded with _id included should still write out non-intermediate paths SELECT bson_dollar_project('{ "_id": 3, "x": { "y": 1 } }', '{ "_id" : 1, "x.y": 0 }'); SELECT bson_dollar_project('{ "_id": 5, "x": { "y": [ 1, 2, 3]}, "v": { "w": [ 4, 5, 6 ]}}', '{ "_id" : 1, "x.y": 0 }'); SELECT bson_dollar_project('{ "_id": 6, "x": { "y": 4}, "v": { "w": 4}}', '{ "_id" : 1, "x.y": 0 }'); SELECT bson_dollar_project('{ "_id": 10, "a": 10, "x": 1 }', '{ "_id" : 1, "x.y": 0 }'); -- Empty spec is a no-op SELECT bson_dollar_project(document, '{}') FROM documentdb_api.collection('db', 'projectops') ORDER BY object_id; bson_aggregation_stage_replaceroot_tests.sql000066400000000000000000000067661507310017400400450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 33000; SET documentdb.next_collection_id TO 3300; SET documentdb.next_collection_index_id TO 3300; SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"1", "int": 10, "x" : {"y" : [1, 2]}, "a" : { "b" : { "arr": [ "x", 1, 2.0, true ]} } }', NULL); SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"2", "double": 2.0, "a" : { "b" : {"c": 3} } }', NULL); SELECT documentdb_api.insert_one('db','replaceRootOps','{"_id":"3", "boolean": false, "a" : {"x" : "no", "b": {"id": "$_id"}}, "b": "yes", "c": true }', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'replaceRootOps') ORDER BY object_id; -- replace by newRoot SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"], "2" : { "x" : "$a.b"} }}') FROM documentdb_api.collection('db', 'replaceRootOps'); -- Multiple "newRoot". Uses the most recent one. SELECT bson_dollar_replace_root(document, '{ "newRoot": {}, "newRoot": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); -- Can't have anything other than "newRoot" SELECT bson_dollar_replace_root(document, '{ "newRoot1": {"myArr": ["$_id", "$a"]}}') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": {"myArr": ["$_id", "$a"]}, "b": "c"}') FROM documentdb_api.collection('db', 'replaceRootOps'); -- 'newRoot' is empty document SELECT bson_dollar_replace_root(document, '{ "newRoot": { } }') FROM documentdb_api.collection('db', 'replaceRootOps'); -- newRoot is required SELECT bson_dollar_replace_root(document, '{ }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": 10 }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": "$a" }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": "$a.b" }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": "$x.y" }') FROM documentdb_api.collection('db', 'replaceRootOps'); -- newRoot is an operator expression SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$isArray" : "$a.b.arr"} }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$literal" : 2.0 } }') FROM documentdb_api.collection('db', 'replaceRootOps'); -- if the operator expression references a field which is a field path expression in the original document {"a": {"b": {"id": "$_id"}}}, "$_id" should be treated as a literal. SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$mergeObjects": [ { "dogs": 0, "cats": 0, "birds": 0, "fish": 0 }, "$a.b" ] } }') FROM documentdb_api.collection('db', 'replaceRootOps'); -- SELECT bson_dollar_replace_root(document, '{ "newRoot": { "$mergeObjects": [ ["dogs", "cats", "birds", "fish"], "$a.b" ] } }') FROM documentdb_api.collection('db', 'replaceRootOps'); -- negative SELECT bson_dollar_replace_root('{}', '{ "newRoot": 1 }') FROM documentdb_api.collection('db', 'replaceRootOps'); SELECT bson_dollar_replace_root('{}', '{ "newRoot": "$x" }') FROM documentdb_api.collection('db', 'replaceRootOps'); bson_aggregation_stage_sample_tests.sql000066400000000000000000000047421507310017400367770ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- CREATE EXTENSION IF NOT EXISTS tsm_system_rows; SET citus.next_shard_id TO 70000; SET documentdb.next_collection_id TO 7000; SET documentdb.next_collection_index_id TO 7000; -- Insert data SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 1, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 2, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 3, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 4, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 5, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); SELECT documentdb_api.insert_one('db','sampleTest',' { "_id" : 6, "product" : "beer", "unitPrice" : 1, "stock" : 1 }', NULL); -- Tests and explain for collection with data -- SYSTEM sampling method, SYSTEM_ROWS performs block-level sampling, -- so that the sample is not completely random but may be subject to clustering effects. -- especially if only a small number of rows are requested. -- https://www.postgresql.org/docs/current/tsm-system-rows.html -- Sample with cursor for unsharded collection not supported - use persisted cursor SELECT * FROM documentdb_api.aggregate_cursor_first_page(database => 'db', commandSpec => '{ "aggregate": "sampleTest", "pipeline": [ { "$sample": { "size": 3 } }, { "$project": { "_id": 0 } } ], "cursor": { "batchSize": 1 } }', cursorId => 4294967294); -- Shard orders collection on item SELECT documentdb_api.shard_collection('db','sampleTest', '{"product":"hashed"}', false); -- If the collection is sharded, have to call TABLESAMPLE SYSTEM_ROWS(n) LIMIT n -- SYSTEM_ROWS(n) may always be optimal, but important, as one but all shards may be -- emptty. If we use SYSTEM_ROWS( : [, ] is not a documented behavior SELECT bson_dollar_set(document, '{ "newarray" : [{ "$literal": 1.0 }, {"copyId": "$_id"}]}') FROM documentdb_api.collection('db', 'setOps'); -- add newField with concatArrays SELECT bson_dollar_set(document, '{ "newField" : "1", "a.b": {"$concatArrays" : [[7]]}}') FROM documentdb_api.collection('db', 'setOps'); SELECT bson_dollar_set(document, '{ "_id" : false}') FROM documentdb_api.collection('db', 'setOps'); SELECT bson_dollar_set(document, '{ "_id" : 121}') FROM documentdb_api.collection('db', 'setOps'); SELECT bson_dollar_set(document, '{ "_id" : 212.2}') FROM documentdb_api.collection('db', 'setOps'); SELECT bson_dollar_set(document, '{ "_id" : "someString"}') FROM documentdb_api.collection('db', 'setOps'); bson_aggregation_stage_unwind_tests.sql000066400000000000000000000067501507310017400370230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 4800000; SET documentdb.next_collection_id TO 4800; SET documentdb.next_collection_index_id TO 4800; -- Test basic usage SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [[1, 2], [2, 3], [4, 5]] } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : { "c" : 1 } } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : [1, 2, 3] }', '$a'); SELECT bson_dollar_unwind('{"_id":"1", "a" : [1, {"c":1}, [3,4], "x"] }', '$a'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [{"a":1}, {"a":2}, {"a":3}] } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : [1, 2] } }', '$a.b'); SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : { "x" : [1, 2] } } }', '$a.c'); SELECT bson_dollar_unwind('{"_id":"1", "x": "y", "a" : { "b" : [1, 2, 3], "c" : { "x" : [1, 2] } } }', '$a.c.x'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3, null] } }', '$a.b'); -- Preserve null and empty SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true}'::bson); -- Project idx field SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":"idx"}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":false, "includeArrayIndex":"idx"}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":false, "includeArrayIndex":"idx"}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true, "includeArrayIndex":"idx"}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : null } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":true, "includeArrayIndex":"idx"}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":""}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "includeArrayIndex":"","preserveNullAndEmptyArrays":true}'::bson); SELECT bson_dollar_unwind('{"_id":"1", "a" : { } }', '{"path":"$a.b", "includeArrayIndex":"","preserveNullAndEmptyArrays":false}'::bson); -- Project conflicting idx SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "includeArrayIndex":"_id"}'::bson); -- Test invalid paths SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', 'a.b'); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', ''); SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : 4 } }', '$'); -- Invalid Arguments SELECT bson_dollar_unwind('{"_id":"1", "a" : { "b" : [1, 2, 3] } }', '{"path":"$a.b", "preserveNullAndEmptyArrays":"a"}'::bson); bson_aggregation_string_operators_tests.sql000066400000000000000000004050611507310017400377360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 620000; SET documentdb.next_collection_id TO 6200; SET documentdb.next_collection_index_id TO 6200; -- $concat operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : "apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : "â„¹ï¸ â¤ï¸ documentdb"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple ","is ","a ","fruit", " ", "."]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["ℹï¸","â¤ï¸","documentdb"]} }'); -- $concat operator: with literals and operators test: select bson_dollar_project('{"_id":"1", "x": "1"}', '{"result" : { "$concat" : "$x"} }'); select bson_dollar_project('{"_id":"1", "x": "3"}', '{"result" : { "$concat" : ["1", {"$concat": ["foo","$x","bar"]}, "2"] } }'); select bson_dollar_project('{"_id":"1", "product": "mango", "qty": "10"}', '{"result" : { "$concat" : ["$product","-","$qty"]} }'); -- $concat operator: null undefined test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", "a", null, "fruit"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : {"$undefined": true}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", "a", {"$undefined": true} , "fruit"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["$a","$b"]} }'); --$concat with large input data select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2","string1", "string2"]} }'); -- $concat operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u0000"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u000Ac"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u0022"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["a","b\u000C"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["Copyright 2023 ","\u00A9 ","Concatstring ", "Inc.", " All rights reserved"]} }'); -- $concat operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : true} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : 1.2} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : [{"$numberDecimal": "10"}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$concat" : ["apple", "is", 1, "fruit"]} }'); select bson_dollar_project('{"_id":"1", "x": ["hello ","this ","is ","test"]}', '{"result" : { "$concat" : "$x"} }'); -- $split operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["hello, this is a test case"," "]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["mango,banana,lemon,grapes",","]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["Iâ¤ï¸documentdb","â¤ï¸"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["1abcd2abcd3abcd4abcd","abcd"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["app","apple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["app","app"]} }'); -- $split operaator: delimeter in front and end select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["abcabcabc","abc"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["testcase "," "]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [" testcase "," "]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["testcase "," "]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["test case "," "]} }'); -- $split operator: with literals and operators test: select bson_dollar_project('{"_id":"1", "x": "apple is a fruit", "y" : " "}', '{"result" : { "$split" : ["$x","$y"]} }'); select bson_dollar_project('{"_id":"1", "x": "name,age,address,height,weight", "y" : ","}', '{"result" : { "$split" : ["$x","$y"]} }'); select bson_dollar_project('{"_id":"1","a":"ram"}', '{"result" : { "$split" : [{"$concat" : ["apple ","is ", "a " , "fruit "] }," "]} }'); select bson_dollar_project('{"_id":"1","a":"ram"}', '{"result" : { "$split" : [{"$concat" : ["apple is a fruit"] }, {"$concat" : [" "] }]} }'); -- $split operator: null undefined output test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [null,null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true},{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1,null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true},"app"]} }'); select bson_dollar_project('{"_id":"1", "a": "apple is a fruit"}', '{"result" : { "$split" : ["$a","$b"]} }'); -- $split operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a\u0000b\u0000c\u0000d","\u0000"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["\u000A","\u000A"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022","\u00A9"]} }'); -- $split operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : "apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["apple", ""]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1, "test"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["test", 1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$numberDecimal" : "1.231"}, 1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : {"$undefined": true}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : ["a","b","c"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$split" : [1]} }'); -- $strLenBytes operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ""} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "A"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "Apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "🙈"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["Apple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "abcdefghijklmnopqrstuvwxyz"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "1234567890"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "!@#$%^&*(){}[];:<>?"} }'); -- $strLenBytes operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["I â¤ï¸ documentdb"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "I â¤ï¸ documentdb"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "A\u0000B"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "\uA000BCD"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : "👩ðŸ½ðŸ‘¨ðŸ½ðŸ§‘ðŸ½ðŸ‘§ðŸ½ðŸ‘¦ðŸ½ðŸ§’ðŸ½ðŸ‘¨ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦°ðŸ§“ðŸ½ðŸ‘´ðŸ½ðŸ‘µðŸ½ðŸ‘¶ðŸ½ðŸ§‘ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦±ðŸ‘¨ðŸ½â€ðŸ¦±ðŸ§‘ðŸ½â€ðŸ¦±ðŸ‘©ðŸ½â€ðŸ¦²ðŸ‘¨ðŸ½â€ðŸ¦²ðŸ§‘ðŸ½â€ðŸ¦²ðŸ‘©ðŸ½â€ðŸ¦³ðŸ‘¨ðŸ½â€ðŸ¦³ðŸ§‘ðŸ½â€ðŸ¦³ðŸ‘±ðŸ½â€â™€ï¸ðŸ‘±ðŸ½â€â™‚ï¸ðŸ‘±ðŸ½ðŸ‘¸ðŸ½ðŸ¤´ðŸ½ðŸ«…ðŸ½ðŸ‘³ðŸ½â€â™€ï¸ðŸ‘³ðŸ½â€â™‚ï¸ðŸ‘³ðŸ½ðŸ‘²ðŸ½ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ‘¼ðŸ½"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); -- $strLenBytes operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenBytes" : "$a"} }'); select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenBytes" : {"$concat" : ["$a", "Apple is a fruit"]} } }'); -- $strLenBytes operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : 1} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$strLenBytes" : "$a"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["apple","cat"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [1,"cat"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["cat",1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : {"$undefined": true}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : [{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenBytes" : ["$a"]} }'); -- $strLenCP operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ""} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "A"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "Apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "🙈"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["Apple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "abcdefghijklmnopqrstuvwxyz"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "1234567890"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "!@#$%^&*(){}[];:<>?"} }'); -- $strLenCP operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["I â¤ï¸ documentdb"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "I â¤ï¸ documentdb"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "A\u0000B"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "\uA000BCD"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : "👩ðŸ½ðŸ‘¨ðŸ½ðŸ§‘ðŸ½ðŸ‘§ðŸ½ðŸ‘¦ðŸ½ðŸ§’ðŸ½ðŸ‘¨ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦°ðŸ§“ðŸ½ðŸ‘´ðŸ½ðŸ‘µðŸ½ðŸ‘¶ðŸ½ðŸ§‘ðŸ½â€ðŸ¦°ðŸ‘©ðŸ½â€ðŸ¦±ðŸ‘¨ðŸ½â€ðŸ¦±ðŸ§‘ðŸ½â€ðŸ¦±ðŸ‘©ðŸ½â€ðŸ¦²ðŸ‘¨ðŸ½â€ðŸ¦²ðŸ§‘ðŸ½â€ðŸ¦²ðŸ‘©ðŸ½â€ðŸ¦³ðŸ‘¨ðŸ½â€ðŸ¦³ðŸ§‘ðŸ½â€ðŸ¦³ðŸ‘±ðŸ½â€â™€ï¸ðŸ‘±ðŸ½â€â™‚ï¸ðŸ‘±ðŸ½ðŸ‘¸ðŸ½ðŸ¤´ðŸ½ðŸ«…ðŸ½ðŸ‘³ðŸ½â€â™€ï¸ðŸ‘³ðŸ½â€â™‚ï¸ðŸ‘³ðŸ½ðŸ‘²ðŸ½ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ‘¼ðŸ½"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); -- $strLenCP operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenCP" : "$a"} }'); select bson_dollar_project('{"_id":"1", "a" : "One apple a day, keeps doctor away"}', '{"result" : { "$strLenCP" : {"$concat" : ["$a", "Apple is a fruit"]} } }'); -- $strLenCP operator: Negative test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : 1} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$strLenCP" : "$a"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["apple","cat"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [1,"cat"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["cat",1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : {"$undefined": true}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : [{"$undefined": true}]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strLenCP" : ["$a"]} }'); --$trim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "", "chars" :""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "111apple111", "chars" :"1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "123apple321", "chars" :"333333222222111111"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple ", "chars" :"pl"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple ", "chars" :" ppl"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple ", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple ", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "ABCDOGABC", "chars" :"ABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA Remove this too", "chars" :"Removthiscarto "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); --$trim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "ABCDOGABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\napple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0000 \n apple \t \u200A "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple\u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0080\u00E2apple\u0080"}} }'); --$trim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "\napple", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); -- $trim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); -- $trim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$z","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$trim" : {"input": "$a","chars": "$z"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": null, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :null}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); -- $trim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": 1}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": 1, "unknowarG": "1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$trim" : {"input": "", "chars" : ["apple"]}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$trim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$trim" : {"input": "apple", "chars" : "$a"}} }'); --$ltrim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "", "chars" :""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "111apple", "chars" :"1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "123apple", "chars" :"333333222222111111"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple ", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "ABCDOG", "chars" :"ABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA", "chars" :"Removthiscarto "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "1234apple", "chars" :"12345678"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); --$ltrim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "ABCDOGABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\napple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0000 \n apple \t \u200A "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple\u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0080\u00E2apple\u0080"}} }'); --$ltrim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "\napple", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); -- $ltrim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); -- $ltrim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$z","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$ltrim" : {"input": "$a","chars": "$z"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": null, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :null}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); -- $ltrim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": 1}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": 1, "unknowarG": "1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$ltrim" : {"input": "", "chars" : ["apple"]}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$ltrim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$ltrim" : {"input": "apple", "chars" : "$a"}} }'); --$rtrim operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "", "chars" :""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple111", "chars" :"1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple321", "chars" :"333333222222111111"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :"pl"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :" ppl"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple ", "chars" :" "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "DOGABC", "chars" :"ABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "Remove this characters AAAAAAAAAAAAAAAAAA Remove this too", "chars" :"Removthiscarto "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "1234apple5678", "chars" :"12345678"}} }'); --$rtrim operator : without chars test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "DOGABC"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\napple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0000 \n apple \t \u200A "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple\u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0080\u00E2apple\u0080"}} }'); --$rtrim operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\n I 💗 documentdb \n", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "😀😀😎😎😋😎😎ðŸ˜ðŸ˜", "chars" :"ðŸ˜ðŸ˜€"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "\napple", "chars" :"\n "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0000 \n apple \t \u200A ", "chars" :" \u0000 \n\t\u200A"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple", "chars" :"\u00E2 "}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u00E2apple\u00E2", "chars" :" \u00E2"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": " \u0080\u00E2apple\u0080", "chars" :"\u0080\u00E2"}} }'); -- $rtrim operator: literals and operators : select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : " 0this is test0 ", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": {"$concat" : ["1","2","3","string","1","2","3"]}, "chars": {"$concat":["12","3"]} }} }'); -- $rtrim operator: null test: select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$z","chars": "$b"}} }'); select bson_dollar_project('{"_id":"1", "a" : "0 this is test 0", "b": "0 " }', '{"result" : { "$rtrim" : {"input": "$a","chars": "$z"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": null, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :null}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": {"$undefined" : true}, "chars" :"apple"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "apple", "chars" :{"$undefined" : true}}} }'); -- $rtrim operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": 1}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": 1, "unknowarG": "1"}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$rtrim" : {"input": "", "chars" : ["apple"]}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$rtrim" : {"input": "$a"}} }'); select bson_dollar_project('{"_id":"1", "a" : 1}', '{"result" : { "$rtrim" : {"input": "apple", "chars" : "$a"}} }'); --$indexOfBytes operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["",""]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["apple","ple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",0,10]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",10,0]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","xyz"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["","",1,3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4,5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",4,6]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",2147483647,7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,2147483647]} }'); --$indexOfBytes operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\n\u200A"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",4,7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["I â¤ï¸ documentdb ","â¤ï¸"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2,4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",3,4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["ðŸ˜ðŸ˜ŸðŸ˜´ðŸ¥²ðŸ˜€ðŸ˜‹ðŸ˜ŽðŸ™ˆðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ˜²ðŸ˜â¤ï¸ðŸ•·ï¸ðŸ™ˆðŸ’”👳ðŸ½â€â™‚ï¸","😎🙈🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸"]} }'); -- $indexOfBytes operator: literals and operators : select bson_dollar_project('{"_id":"1","a":"1234567", "b":"456","c":2, "d":9 }', '{"result" : { "$indexOfBytes" : ["$a","$b","$c","$d"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [{"$concat" : ["a","p","p","l","e"]},{"$concat" : ["p","l"]},{"$add": [0,1]},{"$add" :[3,2]}]} }'); -- $indexOfBytes operator: null test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [null,"a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [{"$undefined": true},"a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["$x","y"]} }'); -- $indexOfBytes operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a",1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a",null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","$x"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",-1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b","x"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,-3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,"z"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["a","b",1,"$t"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",2147483648,7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,2147483648]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1.2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfBytes" : ["appleple","ple",1,1.3]} }'); --$indexOfCP operator : basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["",""]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["apple","ple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",0,10]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",10,0]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","xyz"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["","",2,3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4,5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",4,6]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",2147483647,7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,2147483647]} }'); --$indexOfCP operator : Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["\u0000\u00E2\t\n\u200A\u0080","\n\u200A"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["\u0000\u00E2\t\n\u200A\u0080","\u0080",7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["I â¤ï¸ documentdb ","â¤ï¸"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",2,4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜²ðŸ˜ŽðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸ðŸ˜ðŸ˜²ðŸ˜Ž","🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™‚ï¸",3,4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["ðŸ˜ðŸ˜ŸðŸ˜´ðŸ¥²ðŸ˜€ðŸ˜‹ðŸ˜ŽðŸ™ˆðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸ðŸ˜²ðŸ˜â¤ï¸ðŸ•·ï¸ðŸ™ˆðŸ’”👳ðŸ½â€â™‚ï¸","😎🙈🧔ðŸ½â€â™‚ï¸ðŸ§”ðŸ½ðŸ§”ðŸ½â€â™‚ï¸ðŸ§”ðŸ½â€â™€ï¸"]} }'); -- $indexOfCP operator: literals and operators : select bson_dollar_project('{"_id":"1","a":"1234567", "b":"456","c":2, "d":9 }', '{"result" : { "$indexOfCP" : ["$a","$b","$c","$d"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [{"$concat" : ["a","p","p","l","e"]},{"$concat" : ["p","l"]},{"$add": [0,1]},{"$add" :[3,2]}]} }'); -- $indexOfCP operator: null test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [null,"a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [{"$undefined": true},"a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["$x","y"]} }'); -- $indexOfCP operator: Negative test : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : []} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : [1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a",1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a",null]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","$x"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",-1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b","x"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,-3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,"z"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["a","b",1,"$t"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",2147483648,7]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,2147483648]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1.2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$indexOfCP" : ["appleple","ple",1,1.3]} }'); -- $toUpper operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ""} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "A"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "Apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "🙈"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "I use to eat one apple 🎠a day that became reason of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["Apple"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "abcdefghijklmnopqrstuvwxyz"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "1234567890"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "!@#$%^&*(){}[];:<>?"} }'); -- $toUpper operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["I â¤ï¸ documentdb"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "I â¤ï¸ documentdb"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "A\u0000B"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "a\u0000B\u000d"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "\uA000Bcd"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "a\u0000B\u0000\u0000z"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); -- $toUpper operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : 55.5} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : 1234567899877345} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberInt": "3456"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberLong": "3456213324342"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberDecimal": "3456213324342.324789234567934"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$numberDecimal": "1e10"} } }'); -- $toUpper operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "0" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "86401" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$date": { "$numberLong" : "-33563519937977" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$timestamp": { "t" : 1671991326 , "i": 0}} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$timestamp": { "t" : 0 , "i": 0}} } }'); -- $toUpper operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : {"$toUpper": "abcde" } } }'); select bson_dollar_project('{"_id":"2", "test": "this is a test"}', '{"result" : { "$toUpper" : "$test" } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toUpper" : {"$concat":["a","b","c","1"]} } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toUpper" : "$test" } }'); -- $toUpper operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : ["a","b"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : [1,"b"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toUpper" : true } }'); -- $toLower operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ""} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "A"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "Apple"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "🙈"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "I USE To Eat One aPple 🎠a dAy That Became rEasOn of my breakup 💔 as one apple a day keeps doctor away and she👧🽠was a doctor 🧑ðŸ½â€âš•ï¸"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["aPPLE"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "abcLHKSFHdefghijklmnopqrstuvwxyz"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "1234567890"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "!@#$%^&*(){}[];:<>?"} }'); -- $toLower operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["I â¤ï¸ documentdb"]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "I â¤ï¸ documentdb"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "A\u0000B"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "a\u0000B\u000d"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "\uA000Bcd"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "a\u0000B\u0000\u0000z"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟"} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9"]} }'); -- $toLower operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : 55.5} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : 1234567899877345} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberInt": "3456"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberLong": "3456213324342"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberDecimal": "3456213324342.324789234567934"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$numberDecimal": "1e10"} } }'); -- $toLower operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "0" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "86400" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$date": { "$numberLong" : "-33563519937977" }} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$timestamp": { "t" : 1671991326 , "i": 0}} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$timestamp": { "t" : 0 , "i": 0}} } }'); -- $toLower operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : {"$toUpper": "abcde" } } }'); select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$toLower" : "$test" } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toLower" : {"$concat":["A","B","C","1"]} } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$toLower" : "$test" } }'); -- $toLower operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : ["a","b"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : [1,"b"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$toLower" : true } }'); -- $strcasecmp operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "\u0080D\u20ac", "\u0080d\u20ac"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "\u0080D\u20ac\u000D", "\u0080d\u20ac\u000d"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "I â¤ï¸ documentdb", "I â¤ï¸ documentdb" ] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", "😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟" ] } }'); -- $strcasecmp operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["1.2345",1.2345] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["1.234512345566666234324",1.234512345566666234324] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [1.234512345566666234324, "1.234512345566666234324"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.234512345566666234324"}, "1.234512345566666234324"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.2e10"}, "1e10"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$numberDecimal": "1.2e10"}, "1e10"] } }'); -- $strcasecmp operator: date and timestamps: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "1970-01-01T00:00:00.000Z", {"$date": { "$numberLong" : "0" }} ] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "1970-01-01T00:00:00.000Z", {"$date": { "$numberLong" : "0" }} ] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "0906-06-01T08:01:02.023Z", {"$date": { "$numberLong" : "-33563519937977" }} ] } }'); -- select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "DEC 25 18:02:06:000", {"$timestamp": { "t" : 1671991326 , "i": 0}} ] } }'); -- $strcasecmp operator: expressions: select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$strcasecmp" : ["$test", "this is a test"] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$strcasecmp" : ["$test", ""] } }'); -- $strcasecmp operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "0906-06-01T08:01:02.023Z", true ] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ ""] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["", ["a"]] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [{"$binary": {"base64": "ww==", "subType": "01"}},"a"] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : ["", {"$regex": "/ab/cdsd/abc", "$options" : ""}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$strcasecmp" : [ "" , "a2", 123] } }'); -- $substr operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 0 , 0]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 0 , 5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2 , 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2 , -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 2, 3]} }'); -- $substr operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [55.5, 0, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [1234567899877345, 0, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberInt": "3456"}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberLong": "3456213324342"}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberDecimal": "3456213324342.324789234567934"}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$numberDecimal": "1e10"}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberLong": "2342342"}, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberLong": "2"}, 1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 2.9, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["This isa test", 1, 4.2] } }'); -- $substr operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "0" }}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "86400" }}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$date": { "$numberLong" : "-33563519937977" }}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, -1] } }'); -- $substr operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["I â¤ï¸ documentdb", 1, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["A\u0000B", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["a\u0000B\u000d", 0, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 16]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 0, -1]} }'); -- $substr operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$toUpper": "abcde" }, 0, -1] } }'); select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substr" : ["$test", 0, -1] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substr" : [{"$concat":["A","B","C","1"]}, 0, -1] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substr" : ["$test", 0, -1] } }'); -- $substr negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [[1, 2], 1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"a" : "b"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [NaN, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["I â¤ï¸ documentdb", 2, 4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["\uA000Bcd", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", null, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : ["hello", 1, null] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : {"a" : "b"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substr" : null } }'); select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substr" : "$a.b" } }'); -- $substrBytes operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 0 , 0]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 0 , 5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2 , 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2 , -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 2, 3]} }'); -- $substrBytes operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [55.5, 0, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [1234567899877345, 3, 6]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberInt": "3456"}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberLong": "3456213324342"}, 6, 15] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberDecimal": "3456213324342.324789234567934"}, 13, 5] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$numberDecimal": "1e10"}, 2, 2] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberLong": "2342342"}, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberLong": "2"}, 1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 2.9, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["This isa test", 1, 4.2] } }'); -- $substrBytes operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "0" }}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "86400" }}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$date": { "$numberLong" : "-33563519937977" }}, 5, 8] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 4, 12] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, -1] } }'); -- $substrBytes operator: Unicode representation and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["I â¤ï¸ documentdb", 1, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["A\u0000B", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["a\u0000B\u000d", 0, -1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 16]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 0, -1]} }'); -- $substrBytes operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$toUpper": "abcde" }, 0, -1] } }'); select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substrBytes" : ["$test", 0, -1] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrBytes" : [{"$concat":["A","B","C","1"]}, 0, -1] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrBytes" : ["$test", 0, -1] } }'); -- $substrBytes negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [[1, 2], 1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"a" : "b"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [NaN, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["I â¤ï¸ documentdb", 2, 4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["\uA000Bcd", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", null, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : ["hello", 1, null] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : {"a" : "b"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : null } }'); select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substrBytes" : "$a.b" } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrBytes" : [null, 1, null] } }'); -- $substrCP operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 0 , 0]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 0 , 5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2 , 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2 , 51]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 2, 3]} }'); -- $substrCP operator: numbers, integers decimal: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [55.5, 0, 3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [1234567899877345, 0, 9]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberInt": "3456"}, 0, 4] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberLong": "3456213324342"}, 0, 10] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberDecimal": "3456213324342.324789234567934"}, 0, 25] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$numberDecimal": "1e10"}, 0, 5] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberLong": "2342342"}, 5] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 0, {"$numberLong": "23423423"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberLong": "2"}, 1] } }'); -- $substrCP operator: date and time types select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "0" }}, 0, 20] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "86400" }}, 0, 20] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$date": { "$numberLong" : "-33563519937977" }}, 0, 20] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$timestamp": { "t" : 1671991326 , "i": 0}}, 0, 20] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$timestamp": { "t" : 0 , "i": 0}}, 0, 20] } }'); -- $substrCP operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["jalapeño", 4, 3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["jalapeño", 6, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "cafétéria", 5, 4]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "cafétéria", 7, 3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [ "寿å¸sushi", 0, 3]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["I â¤ï¸ documentdb", 2, 1]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["I â¤ï¸ documentdb", 1, 5]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["A\u0000B", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["a\u0000B\u000d", 0, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["\uA000Bcd", 1, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$susbtrCP" : ["a\u0000B\u0000\u0000z", 2, 2]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["😀ðŸ˜ðŸ˜‚🤣😃😄😅😆😉😊😋😎🥲🙈🤔😪😟", 40, 13]} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2]} }'); -- $substrCP operator: expressions: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$toUpper": "abcde" }, 0, 5] } }'); select bson_dollar_project('{"_id":"2", "test": "THIS IS a test"}', '{"result" : { "$substrCP" : ["$test", 0, 5] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrCP" : [{"$concat":["A","B","C","1"]}, 0, 5] } }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$substrCP" : ["$test", 0, 5] } }'); select bson_dollar_project('{"_id":"2"}', '{"output":{"$substrCP" : ["∫aÆ’",0,{"$subtract" : [{"$strLenCP" : "∫aÆ’"},0]}]}}'); -- $substrCP negative test cases: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [[1, 2], 1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"a" : "b"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$oid" : "639926cee6bda3127f153bf1"}, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [NaN, -1, 1]}}'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$binary": {"base64": "ww==", "subType": "01"}}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [{"$regex": "/ab/cdsd/abc", "$options" : ""}, 0, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", null, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, null] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : {"a" : "b"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : null } }'); select bson_dollar_project('{"_id":"1", "a" : {"b" : ["hello", 1, 2]}}', '{"result" : { "$substrCP" : "$a.b" } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : [null, 1, null] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1.1, 1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, 1.1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", -1, 1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", 1, NaN] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["hello", NaN, 1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", {"$numberDecimal": "2342342.908123098234"}, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 3, {"$numberDecimal": "2.9934234"}] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 2.9, -1] } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$substrCP" : ["This isa test", 1, 4.2] } }'); -- $regexMatch operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"", "regex" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"a", "regex" : "a" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"a", "regex" : "b" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"v_core", "regex" : "Ru-Based" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple is a fruit", "regex" : "is" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexMatch" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); -- $regexMatch operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexMatch" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexMatch" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexMatch" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexMatch" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexMatch" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexMatch" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); -- $regexMatch operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexMatch" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexMatch" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexMatch" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexMatch" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexMatch" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexMatch" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); -- $regexMatch operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexMatch" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexMatch" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexMatch" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexMatch" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexMatch" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); -- $regexMatch operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexMatch" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexMatch" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexMatch" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexMatch" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); -- $regexMatch operator: false cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"a","regex" : null }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"a","regex" : "$z" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"apple","regex" : "boy" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexMatch" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexMatch" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); -- $regexMatch operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexMatch" : {"input":"$a", "regex" : "$b" }} }'); select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexMatch" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); -- $regexMatch operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input":"", "regex" : "", "extra" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : { "regex" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : { "input" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": 1, "regex" : "", "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : 1, "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : "a", "options" : 1 }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "a", "regex" : "a", "options" : "g" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexMatch" : {"input": "string", "regex" :"(m(p)"} } }'); -- $regexFind operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"", "regex" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"a", "regex" : "a" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple is a fruit", "regex" : "is" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexFind" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); -- $regexFind operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFind" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFind" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFind" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFind" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFind" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFind" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); -- $regexFind operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFind" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFind" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFind" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFind" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFind" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFind" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); -- $regexFind operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexFind" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexFind" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexFind" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexFind" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexFind" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); -- $regexFind operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexFind" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexFind" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexFind" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexFind" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); -- $regexFind operator: null cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"a","regex" : null }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"a","regex" : "$z" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"apple","regex" : "boy" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFind" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexFind" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); -- $regexFind operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexFind" : {"input":"$a", "regex" : "$b" }} }'); select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexFind" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); -- $regexFind operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input":"", "regex" : "", "extra" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : { "regex" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : { "input" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": 1, "regex" : "", "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : 1, "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : "a", "options" : 1 }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "a", "regex" : "a", "options" : "g" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFind" : {"input": "string", "regex" :"(m(p)"} } }'); -- $regexFindAll operator: basic test: select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"", "regex" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"a", "regex" : "a" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple is a fruit", "regex" : "is" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"apple is a fruit", "regex" : "fruit" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE", "regex" : "apple" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE", "regex" : "apple", "options": "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"APPLE","regex" : {"$regex" : "apple", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"2"}', '{"result" : { "$regexFindAll" : {"input":"Banana","regex" : {"$regex" : "banana", "$options" : "i"} }} }'); -- $regexFindAll operator: complex regex pattern test: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFindAll" : {"input":"1234567890","regex" : "\\d{3}", "options" : "" }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFindAll" : {"input":"Hello World","regex" : "\\bworld\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFindAll" : {"input":"Microsoft IDC","regex" : "id", "options" : "i" }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFindAll" : {"input":"Hello, World!","regex" : "[,!]", "options" : "i" }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : "\\b\\w{5}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFindAll" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "options" : "i" }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFindAll" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : "

(.*?)

", "options" : "i" }} }'); select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 100, 'a') || '", "regex": "((((((((((((((()))))))))))))))"}} }')::bson); select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 50000, 'c') || LPAD('', 50000, 'd') || 'e", "regex": "' || LPAD('',2500*3,'(d)') || 'e"}} }')::bson); -- $regexFindAll operator: complex regex pattern with BSON_TYPE_REGEX: select bson_dollar_project('{"_id":"4"}', '{"result" : { "$regexFindAll" : {"input":"1234567890","regex" : {"$regex" : "\\d{3}", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"3"}', '{"result" : { "$regexFindAll" : {"input":"Hello World","regex" : {"$regex" : "\\bworld\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"5"}', '{"result" : { "$regexFindAll" : {"input":"Microsoft IDC","regex" : {"$regex" : "id", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"6"}', '{"result" : { "$regexFindAll" : {"input":"Hello, World!","regex" : {"$regex" : "[,!]", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"7"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "\\b\\w{5}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"8"}', '{"result" : { "$regexFindAll" : {"input":"Email me at john@example.com or call 555-123-4567 for more information.","regex" : {"$regex" : "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b|\\b\\d{3}-\\d{3}-\\d{4}\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"9"}', '{"result" : { "$regexFindAll" : {"input":"

Hello

Paragraph 1

Paragraph 2

","regex" : {"$regex" : "

(.*?)

", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "ABCDXYZABCDXYZABCDXYZ", "regex" : "BC(P(DE)?)?"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "aaa aa", "regex" : "(a*?)"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "aaaaa aaaa", "regex" : "(aa)"} } }'); -- $regexFindAll operator: captures in output: select bson_dollar_project('{"_id":"10"}', '{"result" : { "$regexFindAll" : {"input":"John Doe, 25 years old","regex" : {"$regex" : "(\\w+) (\\w+), (\\d+) years old", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"11"}', '{"result" : { "$regexFindAll" : {"input":"Date: 2023-07-14","regex" : {"$regex" : "Date: (\\d{4}-\\d{2}-\\d{2})", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"12"}', '{"result" : { "$regexFindAll" : {"input":"Product: Apple iPhone 12","regex" : {"$regex" : "Product: (\\w+) (\\w+) (\\d+)", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"13"}', '{"result" : { "$regexFindAll" : {"input":"Email: john@example.com","regex" : {"$regex" : "Email: ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"14"}', '{"result" : { "$regexFindAll" : {"input":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","regex" : {"$regex" : "(\\b\\w{5}\\b)", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "", "regex" : "(missing)|()"} } }'); -- $regexFindAll operator: different options: select bson_dollar_project('{"_id":"15"}', '{"result" : { "$regexFindAll" : {"input":"Hello\nworld","regex" : {"$regex" : "^world", "$options" : "m"} }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : "i"} }} }'); select bson_dollar_project('{"_id":"17"}', '{"result" : { "$regexFindAll" : {"input":"123\n456\n789","regex" : {"$regex" : "\\d+", "$options" : "g"}}}}'); select bson_dollar_project('{"_id":"18"}', '{"result" : { "$regexFindAll" : {"input":"This is a long text","regex" : {"$regex" : "long text", "$options" : "is"} }} }'); select bson_dollar_project('{"_id":"20"}', '{"result" : { "$regexFindAll" : {"input":"Hello there","regex" : {"$regex" : "Hello\\s there", "$options" : "x"} }} }'); -- $regexFindAll operator: empty cases: select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":null,"regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"a","regex" : null }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"$z","regex" : {"$regex" : "", "$options" : ""} } } }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"a","regex" : "$z" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"apple","regex" : "boy" }} }'); select bson_dollar_project('{"_id":"16"}', '{"result" : { "$regexFindAll" : {"input":"The quick brown FOX","regex" : {"$regex" : "\\bfox\\b", "$options" : ""} }} }'); select bson_dollar_project('{"_id":"19"}', '{"result" : { "$regexFindAll" : {"input":"This is a\nmultiline\nstring","regex" : {"$regex" : "multiline string", "$options" : "ix"} }} }'); -- $regexFindAll operator: expression cases: select bson_dollar_project('{"_id":"1","a":"apple", "b":"app"}', '{"result" : { "$regexFindAll" : {"input":"$a", "regex" : "$b" }} }'); select bson_dollar_project('{"_id":"1","a":"APPLE", "b":"app", "c" : "i"}', '{"result" : { "$regexFindAll" : {"input":"$a", "regex" : "$b", "options" :"$c" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": {"$concat" : ["APPLE", "IS", "FRUIT"]}, "regex" : {"$toLower" : "APPLE"}, "options": {"$concat" : "i"} }} }'); -- $regexFindAll operator: negative test cases : select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input":"", "regex" : "", "extra" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : { "regex" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : { "input" : ""}} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": 1, "regex" : "", "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : 1, "options" : "" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : "a", "options" : 1 }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : {"$regex" : "", "$options": "i"}, "options" : "i" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "a", "regex" : "a", "options" : "g" }} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : null} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : 1} }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"", "options" : "\u0000"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"\u0000", "options" : "i"} } }'); select bson_dollar_project('{"_id":"1"}', '{"result" : { "$regexFindAll" : {"input": "string", "regex" :"(m(p)"} } }'); select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('',100000, 'a') || '", "regex": "(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"}} }')::bson); select bson_dollar_project('{"_id":"1"}', ('{"result" : { "$regexFindAll" : {"input" : "' || LPAD('', 50000, 'c') || LPAD('', 50000, 'd') || 'e", "regex": "' || LPAD('',2728*3,'(d)') || 'e"}} }')::bson); --regex Operators : with multiple document in collection --creating collection SELECT create_collection('db','regexMultiDocumentTest'); --inserting data SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":1, "input" : "apple", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":2, "input" : "apple is sweet", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":3, "input" : "apple is lime", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":4, "input" : "lime is blue", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":5, "input" : "blue is berry", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":6, "input" : "need apple for nothing", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":7, "input" : "One apple a day keeps doctor away", "regex" : "apple", "option" : "i"}', NULL); SELECT documentdb_api.insert_one('db','regexMultiDocumentTest','{"_id":8, "input" : "red apple is red ?", "regex" : "apple", "option" : "i"}', NULL); --case 1: when regex and options are constant we compile regex only once SELECT bson_dollar_project(document, '{"result" : { "$regexMatch" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); SELECT bson_dollar_project(document, '{"result" : { "$regexFind" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); SELECT bson_dollar_project(document, '{"result" : { "$regexFindAll" : {"input" : "$input", "regex": "apple", "options" : "i"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); --case 2: when regex and options are not constant we compile regex every document SELECT bson_dollar_project(document, '{"result" : { "$regexMatch" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); SELECT bson_dollar_project(document, '{"result" : { "$regexFind" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); SELECT bson_dollar_project(document, '{"result" : { "$regexFindAll" : {"input" : "$input", "regex": "$regex", "options" : "$option"} }}') from documentdb_api.collection('db','regexMultiDocumentTest'); --dropping collection SELECT drop_collection('db','regexMultiDocumentTest'); -- $replaceOne basic tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint", "find": "blue and green paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "blue paint with green paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "ross", "replacement": "rachel"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": "one"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": ""}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "", "replacement": "foo"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "rachel", "replacement": "ross"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "rachel", "replacement": "ross"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "", "find": "rachel", "replacement": ""}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": ""}}}'); -- $replaceOne null tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": "ross", "replacement": "rachel"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": null, "replacement": "yelo"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": "", "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "albatross", "find": null, "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": "f", "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": null, "find": null, "replacement": "chandler"}}}'); -- $replaceOne with path select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "$test.nest", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "wandering hellostater", "find": "$test.nest", "replacement": "phoebe"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "wandering cheapskate", "find": "cheap", "replacement": "$test.nest"}}}'); select bson_dollar_project('{"_id":"1", "test": {"input": "hello", "find": "ello", replacement: "atred"}}', '{"result": {"$replaceOne": {"input": "$input", "find": "$find", "replacement": "$replacement"}}}'); -- $replaceOne with missing path select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "$test.nesty", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "$madame", "replacement": "non"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "replacement": "$non"}}}'); -- $replaceOne unsupported data types select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": 1, "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": 2, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": "el", "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2], "find": "el", "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": {"$binary": {"base64": "ww==", "subType": "01"}}, "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "yellow", "find": "el", "replacement": {"$regex": "/ab/cdsd/abc", "$options" : ""}}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": NaN, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"a": "this is a string"}}', '{"result": {"$replaceOne": {"input": "$test", "find": "is", "replacement": "chandler"}}}'); -- $replaceOne missing/additional argument select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"find": NaN, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test", "find": "asdf"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"input": "$test"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceOne": {"find": NaN}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "replacement": "$non", "newField": "he"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceOne": {"input": "Present monsieur", "find": "si", "newField": "he"}}}'); -- $replaceOne operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "I â¤ï¸ documentdb", "find": "â¤ï¸", "replacement": "\u0000B"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "jalapeño", "find": "peñ", "replacement": "寿å¸"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "a\u0000B\u000d", "find": "\u000d", "replacement": "🥲"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "cafétéria", "find": "caf", "replacement": "é"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceOne": {"input": "cafe\u0301", "find": "café", "replacement": "CAFE" }}}'); -- $replaceAll basic tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": ""}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": "O"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foo bar", "find": "o", "replacement": "OO"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "foooo bar", "find": "o", "replacement": "O"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint", "find": "blue and green paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with green paintbrush", "find": "blue paint", "replacement": "red paint"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "ross", "replacement": "rachel"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": "one"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": ""}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "", "replacement": "foo"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "rachel", "replacement": "ross"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "rachel", "replacement": "ross"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "", "find": "rachel", "replacement": ""}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": ""}}}'); -- $replaceAll null tests select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": "ross", "replacement": "rachel"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": null, "replacement": "yelo"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": "", "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross", "find": null, "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": "f", "replacement": null}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": null, "find": null, "replacement": "chandler"}}}'); -- $replaceAll with path select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "$test.nest", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "wandering hellostater", "find": "$test.nest", "replacement": "phoebe"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "wandering cheapskate", "find": "cheap", "replacement": "$test.nest"}}}'); -- $replaceAll with missing path select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "$test.nesty", "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "$madame", "replacement": "non"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "replacement": "$non"}}}'); -- $replaceAll unsupported data types select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": 1, "find": "el", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": 2, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "el", "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": ["\u0022\u00A9\u0022\u00A9\u0022\u00A9\u0022\u00A9", 1, 2], "find": "el", "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": {"$binary": {"base64": "ww==", "subType": "01"}}, "replacement": 3}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "el", "replacement": {"$regex": "/ab/cdsd/abc", "$options" : ""}}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": NaN, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": {"a": "this is a string"}}', '{"result": {"$replaceAll": {"input": "$test", "find": "is", "replacement": "chandler"}}}'); -- $replaceAll missing/additional argument select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"find": NaN, "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test", "find": "asdf"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"input": "$test"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"replacement": "chandler"}}}'); select bson_dollar_project('{"_id":"1", "test": "hello"}', '{"result": {"$replaceAll": {"find": NaN}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "replacement": "$non", "newField": "he"}}}'); select bson_dollar_project('{"_id":"1", "test": {"nest": "hello"}}', '{"result": {"$replaceAll": {"input": "Present monsieur", "find": "si", "newField": "he"}}}'); -- $replaceAll operator: special characters and escape sequences test: select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "I â¤ï¸ documentdb", "find": "â¤ï¸", "replacement": "\u0000B"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "jalapeño", "find": "peñ", "replacement": "寿å¸"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "a\u0000B\u000d", "find": "\u000d", "replacement": "🥲"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "cafétéria", "find": "caf", "replacement": "é"}}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "cafe\u0301", "find": "café", "replacement": "CAFE" }}}'); -- $replaceAll multiple replacements select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "The quick fox jumped over the laze dog", "find": "d", "replacement": "cat" }}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "albatross and its wings", "find": " ", "replacement": "huge" }}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "blue paint with blue paintbrush", "find": "blue paint", "replacement": "green paint" }}}'); select bson_dollar_project('{"_id":"1"}', '{"result": {"$replaceAll": {"input": "yellow", "find": "", "replacement": "z" }}}'); bson_aggregation_tests_lookup_inner_join.sql000066400000000000000000000002701507310017400400460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 731000; SET documentdb.next_collection_id TO 7310; SET documentdb.next_collection_index_id TO 7310; \i sql/bson_aggregation_tests_lookup_inner_join_core.sqlbson_aggregation_tests_lookup_inner_join_core.sql000066400000000000000000000227061507310017400410660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Insert data SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 1, "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); SELECT documentdb_api.insert_one('lookupdb','planes','{ "_id" : 2, "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 3, "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('lookupdb','planes',' { "_id" : 4, "model" : "737", "price" : 50, "quantity" : 30 }', NULL); SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 1, "plane_model" : "A330", "gates" : 30 }', NULL); SELECT documentdb_api.insert_one('lookupdb','gate_availability',' { "_id" : 11, "plane_model" : "A340", "gates" : 10 }', NULL); SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 2, "plane_model" : "A380", "gates" : 5 }', NULL); SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 3, "plane_model" : "A350", "gates" : 20 }', NULL); SELECT documentdb_api.insert_one('lookupdb','gate_availability','{ "_id" : 4, "plane_model" : "737", "gates" : 110 }', NULL); -- set up indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "planes", "indexes": [ { "key": { "model": 1 }, "name": "planes_model_1" } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('lookupdb', '{ "createIndexes": "gate_availability", "indexes": [ { "key": { "plane_model": 1 }, "name": "plane_model_1" } ] }', TRUE); -- Remove primary key ALTER TABLE documentdb_data.documents_7311 DROP CONSTRAINT collection_pk_7311; ALTER TABLE documentdb_data.documents_7312 DROP CONSTRAINT collection_pk_7312; ANALYZE documentdb_data.documents_7311; ANALYZE documentdb_data.documents_7312; BEGIN; set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.enableLookupInnerJoin to on; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); ROLLBACK; -- Insert a lot more data DO $$ DECLARE i int; BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A380", "price" : 280, "quantity" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes','{ "model" : "A340", "price" : 140, "quantity" : 1 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "A330", "price" : 10, "quantity" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','planes',' { "model" : "737", "price" : 50, "quantity" : 30 }', NULL); END LOOP; END; $$; DO $$ DECLARE i int; BEGIN FOR i IN 1..250 LOOP PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A330", "gates" : 30 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability',' { "plane_model" : "A340", "gates" : 10 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A380", "gates" : 5 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "A350", "gates" : 20 }', NULL); PERFORM documentdb_api.insert_one('lookupdb','gate_availability','{ "plane_model" : "737", "gates" : 110 }', NULL); END LOOP; END; $$; -- Now test index usage BEGIN; set local documentdb.forceBitmapScanForLookup to on; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN with force bitmap scan, should use materialize seq scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.forceBitmapScanForLookup to off; set local documentdb.enableLookupInnerJoin to off; -- LEFT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); set local documentdb.enableLookupInnerJoin to on; -- RIGHT JOIN without force bitmap scan, should use index scan EXPLAIN (SUMMARY OFF, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{ "aggregate": "planes", "pipeline": [ { "$match": { "model": { "$exists": true } } }, { "$lookup": { "from": "gate_availability", "as": "matched_docs", "localField": "model", "foreignField": "plane_model" } }, { "$unwind": "$matched_docs" } ], "cursor": {} }'); ROLLBACK; -- Cleanup SELECT documentdb_api.drop_collection('lookupdb', 'planes'); SELECT documentdb_api.drop_collection('lookupdb', 'gate_availability'); -- lookup with point read where inner plan depends on external param crash fix scenario SELECT documentdb_api.insert_one('lookupdb','Dishes',' { "_id" : 1, "dishId" : 1, "ingredients": [1, 2, 3, 4] }', NULL); SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 1, "shopId" : 101, "name": "Salt" }', NULL); SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 2, "shopId" : 101, "name": "Clove" }', NULL); SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 3, "shopId" : 101, "name": "Olive" }', NULL); SELECT documentdb_api.insert_one('lookupdb','Ingredients',' { "_id" : 4, "shopId" : 101, "name": "Pepper" }', NULL); SELECT documentdb_api.insert_one('lookupdb','Shops',' { "_id" : 101, "name": "ABC Mart" }', NULL); -- Get collection IDs for each collection and store them in variables SELECT collection_id AS dishes_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Dishes' \gset SELECT collection_id AS ingredients_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Ingredients' \gset SELECT collection_id AS shops_id FROM documentdb_api_catalog.collections WHERE database_name = 'lookupdb' AND collection_name = 'Shops' \gset -- Dynamically run ANALYZE commands using the collection IDs SELECT 'ANALYZE documentdb_data.documents_' || :'dishes_id' \gexec SELECT 'ANALYZE documentdb_data.documents_' || :'ingredients_id' \gexec SELECT 'ANALYZE documentdb_data.documents_' || :'shops_id' \gexec BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); ROLLBACK; BEGIN; set local seq_page_cost to 1; set local documentdb.enableLookupInnerJoin to off; EXPLAIN (COSTS OFF, SUMMARY OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('lookupdb', '{"aggregate": "Dishes", "pipeline": [{"$match": {"dishId": 1}}, {"$unwind": "$ingredients"} , {"$lookup": {"from": "Ingredients", "localField": "ingredients", "foreignField": "_id", "as": "ingredient_info"}} , {"$unwind": "$ingredient_info"} , {"$lookup": {"from": "Shops", "localField": "ingredient_info.shopId", "foreignField": "_id", "as": "shop_info"}}, {"$unwind": "$shop_info"}]}'); ROLLBACK;bson_aggregation_timestamp_operators_tests.sql000066400000000000000000000064421507310017400404330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 8800000; SET documentdb.next_collection_id TO 8800; SET documentdb.next_collection_index_id TO 8800; -- $tsSecond operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": null }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": {"$undefined":true} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": { "$timestamp": { "t": 1622431468, "i": 1 }} }}'); -- $tsSecond operator , input document tests SELECT * FROM bson_dollar_project('{"a": { "$timestamp": { "t": 1622431468, "i": 1 }} }', '{"result": { "$tsSecond": "$a" }}'); -- $tsSecond operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": "" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": [1,2] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": [1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": 11 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": true }}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$tsSecond": "$a" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsSecond": {"$regex": "a*b", "$options":""} }}'); -- $tsIncrement operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": null }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": {"$undefined":true} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": { "$timestamp": { "t": 1622431468, "i": 1 }} }}'); -- Create Collection SELECT documentdb_api.create_collection('db', 'timestampTest'); -- $tsIncrement/$tsSecond operator , input document tests SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "a", "tsValue": { "$timestamp": { "t": 1622431468, "i": 1 }} }', NULL); SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "a", "tsValue": { "$timestamp": { "t": 1622431468, "i": 2 }} }', NULL); SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124193, "i": 1 }} }', NULL); SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124192, "i": 1 }} }', NULL); SELECT documentdb_api.insert_one('db','timestampTest','{ "symbol": "b", "tsValue": { "$timestamp": { "t": 1714124192, "i": 2 }} }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{"aggregate": "timestampTest", "pipeline": [{ "$project": {"_id": 0, "tsValue": 1, "incrementValue": {"$tsIncrement": "$tsValue"}, "secondValue": {"$tsSecond": "$tsValue"}}} ]}'); -- $tsIncrement operator negative tests SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": "" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": [1,2] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": [1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": 11 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": true }}'); SELECT * FROM bson_dollar_project('{"a":1}', '{"result": { "$tsIncrement": "$a" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tsIncrement": {"$regex": "a*b", "$options":""} }}'); bson_aggregation_trigonometric_operators_tests.sql000066400000000000000000001454461507310017400413250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 7800000; SET documentdb.next_collection_id TO 7800; SET documentdb.next_collection_index_id TO 7800; -- SET client_min_messages TO DEBUG3; -- $degreesToRadians operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 45 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": -45 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 90 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 180 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 270 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": 1000 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": -1000 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDecimal": "90" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$degreesToRadians": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": null }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": "$a" }}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "NaN"} }}'); -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "Infinity"} }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": {"$numberDouble": "-Infinity"} }}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": "str" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": ["str"] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": true }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$degreesToRadians": false }}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$degreesToRadians": [2, "$a"] }}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$degreesToRadians": ["$a", 5] }}'); -- $radiansToDegrees operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 3.141592653589793}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": -3.141592653589793}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 6.283185307179586}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 12.566370614359172}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": { "$numberDecimal": "9.42477796076938" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$radiansToDegrees": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$radiansToDegrees": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$radiansToDegrees": ["$a", 5]}}'); -- $sin operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$sin": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$sin": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "NaN"}}}'); -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sin": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$sin": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$sin": ["$a", 5]}}'); -- $cos operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$cos": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$cos": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "NaN"}}}'); -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cos": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$cos": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cos": ["$a", 5]}}'); -- $tan operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$tan": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$tan": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "NaN"}}}'); -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tan": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$tan": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$tan": ["$a", 5]}}'); -- $sinh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$sinh": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$sinh": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "NaN"}}}'); -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$sinh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$sinh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$sinh": ["$a", 5]}}'); -- $cosh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$cosh": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$cosh": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "NaN"}}}'); -- Should error if expression evaluates to Infinity/-Infinity SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$cosh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$cosh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$cosh": ["$a", 5]}}'); -- $tanh operator -- Radian argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": -1}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 0}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$divide": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 3.141592653589793 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$multiply": [3.141592653589793, 1.5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$multiply": [3.141592653589793, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": 100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": -100}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$numberDecimal": "1.5707963267948966" }}}'); SELECT * FROM bson_dollar_project('{"a": 4.71238898}', '{"result": { "$tanh": "$a"}}'); -- Degree argument SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": -45 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 0 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 90 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 180 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 270 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": 1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": -1000 }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "-1e-10" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "-0.0001" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDecimal": "90" } }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": { "$degreesToRadians": { "$numberDouble": "0.99999999999999" } }}}'); SELECT * FROM bson_dollar_project('{"a": 30}', '{"result": { "$tanh": { "$degreesToRadians": "$a" }}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "NaN"}}}'); -- Infinity/-Infinity returns Infinity/-Infinitytively SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$tanh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$tanh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$tanh": ["$a", 5]}}'); -- $asin operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.7071067811865475 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.7071067811865475 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.8660254037844386 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.8660254037844386 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "0.1" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-0.1" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -0.5 }}'); SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$asin": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$asin": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "NaN"}}}'); -- Should error if expression lies outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": -10.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asin": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$asin": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$asin": ["$a", 5]}}'); -- $acos operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.7071067811865475 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.7071067811865475 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.8660254037844386 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.8660254037844386 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "0.1" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-0.1" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": { "$numberDecimal": "-0.0001" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -0.5 }}'); SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$acos": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$acos": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "NaN"}}}'); -- Should error if expression lies outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": -10.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acos": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$acos": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$acos": ["$a", 5]}}'); -- $atan operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": 100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": -100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$add": [10, 5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": { "$subtract": [10, 15] }}}'); SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$atan": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$atan": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$atan": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -10}', '{"result": { "$atan": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "NaN"}}}'); -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$atan": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$atan": ["$a", 5]}}'); -- $atan2 operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-1, -1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, 0] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0.9999999999, 0.9999999999] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-0.9999999999, -0.9999999999] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 0] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-1, 0] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0, -1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [0.5, 0.5] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-0.5, -0.5] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [10, 10] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-10, -10] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [100, 100] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [-100, -100] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$divide": [1, 2]}, {"$divide": [1, 2] }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$multiply": [-0.5, 1]}, {"$multiply": [-0.5, 1] }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$add": [10, 5]}, {"$add": [10, 5] }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$subtract": [10, 15]}, {"$subtract": [10, 15] }]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "0.1" }, { "$numberDecimal": "0.2" }] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "-0.1" }, { "$numberDecimal": "-0.2" }] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDecimal": "100" }, { "$numberDecimal": "-0.2" }] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDouble": "0.1" }, { "$numberDouble": "0.2" }] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{ "$numberDouble": "-0.1" }, { "$numberDouble": "-0.2" }] }}'); SELECT * FROM bson_dollar_project('{"a": 0.5, "b": 0.5}', '{"result": { "$atan2": ["$a", "$b"] }}'); SELECT * FROM bson_dollar_project('{"a": -0.5, "b": -0.5}', '{"result": { "$atan2": ["$a", "$b"] }}'); SELECT * FROM bson_dollar_project('{"a": 10, "b": 10}', '{"result": { "$atan2": ["$a", "$b"] }}'); SELECT * FROM bson_dollar_project('{"a": -10, "b": -10}', '{"result": { "$atan2": ["$a", "$b"] }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, null] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["$a", null] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, "$a"] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, 50] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [50, 100] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, "$a"] }}'); -- NaN, returns NaN. NaN, null returns null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [10, NaN] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [NaN, 10] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, NaN] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "NaN"}, null] }}'); -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, {"$numberDouble": "Infinity"}] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "Infinity"}, null] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [null, {"$numberDouble": "-Infinity"}] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [{"$numberDouble": "-Infinity"}, null] }}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["str", 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, "str"] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [true, 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, true] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [false, 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, false] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": ["$a", 1] }}'); -- Should error for wrong number of arguments SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1, 1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [] }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atan2": [1, 1, 1] }}'); -- $asinh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": 100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": -100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$add": [10, 5] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": { "$subtract": [10, 15] }}}'); SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$asinh": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$asinh": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$asinh": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -10}', '{"result": { "$asinh": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "NaN"}}}'); -- Infinity/-Infinity returns Infinity/-Infinity respectively SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$asinh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$asinh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$asinh": ["$a", 5]}}'); -- $acosh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$add": [10, 5] }}}'); SELECT * FROM bson_dollar_project('{"a": 1.5}', '{"result": { "$acosh": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": 10}', '{"result": { "$acosh": "$a" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "Infinity"}}}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "NaN"}}}'); -- Should error for values less than 1 SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$subtract": [10, 15] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": {"$numberDouble": "-Infinity"}}}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$acosh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$acosh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$acosh": ["$a", 5]}}'); -- $atanh operator SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -1 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -0.9999999999 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$numberDecimal": "1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$numberDecimal": "-1e-10" }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -0.5 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$divide": [1, 2] }}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": { "$multiply": [-0.5, 1] }}}'); SELECT * FROM bson_dollar_project('{"a": 0.5}', '{"result": { "$atanh": "$a" }}'); SELECT * FROM bson_dollar_project('{"a": -0.5}', '{"result": { "$atanh": "$a" }}'); -- Null or undefined should return null SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": "$a"}}'); -- NaN returns NaN SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": NaN}}'); -- Should error for values outside [-1, 1] SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": {"$numberDouble": "-Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -1.0000000001 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -10 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": 100 }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": -100 }}'); -- Should error for non-number expressions. SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": "str"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": ["str"]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": true}}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$atanh": false}}'); SELECT * FROM bson_dollar_project('{"a": "str"}', '{"result": { "$atanh": [2, "$a"]}}'); SELECT * FROM bson_dollar_project('{"a": {}}', '{"result": { "$atanh": ["$a", 5]}}'); bson_aggregation_type_operators_tests.sql000066400000000000000000001517561507310017400374220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6910000; SET documentdb.next_collection_id TO 69100; SET documentdb.next_collection_index_id TO 69100; -- $isNumber: return true for numbers false otherwise SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [["not null"]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$add": [1, 2]}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [true]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [false]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": "1"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberLong": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberDecimal": "1"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {"$numberDouble": "1.0"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": {}}}'); -- $isNumber: returns null with null or undefined SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": null}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": "$a"}}'); -- $isNumber: error number of args should be 1 SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [1, 2]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$isNumber": [[], 2]}}'); -- $type: returns expected type SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "1", "value": {"$numberDouble": "1.0"}, "expected": "double"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "2", "value": "string", "expected": "string"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "3", "value": {}, "expected": "object"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "4", "value": [], "expected": "array"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "5", "value": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}, "expected": "binData"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "6", "value": {"$oid" : "639926cee6bda3127f153bf1" }, "expected": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "7", "value": true, "expected": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "8", "value": {"$date": "2022-01-01T00:00:00.000Z"}, "expected": "date"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "9", "value": null, "expected": "null"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "10", "value": { "$regex": "a.*b", "$options": "" }, "expected": "regex"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "11", "value": { "$code": "var a = 1;"}, "expected": "javascript"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "12", "value": 1, "expected": "int"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "13", "value": {"$timestamp" : { "t": 1670981326, "i": 1 }}, "expected": "timestamp"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "14", "value": {"$numberLong" : "1"}, "expected": "long"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "15", "value": {"$numberDecimal" : "1"}, "expected": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "16", "value": {"$minKey" : 1}, "expected": "minKey"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "17", "value": {"$maxKey" : 1}, "expected": "maxKey"}'); SELECT * from documentdb_api.insert_one('db', 'dollarType', '{"_id": "18", "expected": "missing"}'); SELECT bson_dollar_project(document, '{"output": {"$type": "$value"}, "expected": 1}') FROM documentdb_api.collection('db', 'dollarType'); -- $convert: returns expected values -- double value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "1", "value": {"$numberDouble": "1.3"}, "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "2", "value": {"$numberDouble": "1.3"}, "expected": "1.3", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "3", "value": {"$numberDouble": "1.3"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "4", "value": {"$numberDouble": "0.0"}, "expected": false, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "5", "value": {"$numberDouble": "-0.1"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "6", "value": {"$numberDouble": "1.3"}, "expected": {"$date": "1970-01-01T00:00:00.001Z"}, "convertTo": "date"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "7", "value": {"$numberDouble": "1.3"}, "expected": 1, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "8", "value": {"$numberDouble": "1.3"}, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "9", "value": {"$numberDouble": "1.3"}, "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); -- str value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "10", "value": "myString", "expected": "myString", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "11", "value": "1.3", "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "12", "value": "1E-2", "expected": {"$numberDouble": "0.01"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "13", "value": "13423423E-25", "expected": {"$numberDouble": "1.3423423e-18"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "14", "value": "0000000.0000000", "expected": {"$numberDouble": "0.0"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "15", "value": "1.3", "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "16", "value": "1E-2", "expected": {"$numberDecimal": "0.01"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "17", "value": "-13423423E25", "expected": {"$numberDecimal": "-1.3423423E+32"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "18", "value": "000000.000000", "expected": {"$numberDecimal": "0.000000"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "19", "value": "-1232", "expected": {"$numberLong": "-1232"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "20", "value": "00053235", "expected": {"$numberLong": "53235"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "21", "value": "00053235", "expected": 53235, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "22", "value": "00000000000", "expected": 0, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "23", "value": "665a1c0f8a2b4f7cd317a2b4", "expected": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "24", "value": "", "expected": true, "convertTo": "bool"}'); -- objectId value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "26", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "27", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": "665a1c0f8a2b4f7cd317a2b4", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "28", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "29", "value": {"$oid": "665a1c0f8a2b4f7cd317a2b4"}, "expected": {"$date": "2024-05-31T18:50:55.000Z"}, "convertTo": "date"}'); -- bool value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "30", "value": false, "expected": {"$numberDouble": "0"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "31", "value": true, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "32", "value": false, "expected": {"$numberDecimal": "0"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "33", "value": true, "expected": {"$numberDecimal": "1"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "34", "value": false, "expected": {"$numberLong": "0"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "35", "value": true, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "36", "value": false, "expected": 0, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "37", "value": true, "expected": 1, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "38", "value": false, "expected": "false", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "39", "value": true, "expected": "true", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "40", "value": false, "expected": false, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "45", "value": true, "expected": true, "convertTo": "bool"}'); -- date value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "46", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$date": "2024-05-31T18:50:55.000Z"}, "convertTo": "date"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "47", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": "2024-05-31T18:50:55.000Z", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "48", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "49", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberLong": "1717181455000"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "50", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberDouble": "1717181455000"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "51", "value": {"$date": "2024-05-31T18:50:55.000Z"}, "expected": {"$numberDecimal": "1717181455000"}, "convertTo": "decimal"}'); -- int value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "52", "value": 1, "expected": 1, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "53", "value": 1, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "54", "value": -11, "expected": {"$numberDouble": "-11"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "55", "value": 523453, "expected": {"$numberDecimal": "523453"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "56", "value": 523453, "expected": {"$numberLong": "523453"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "57", "value": 1, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "58", "value": 0, "expected": false, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "59", "value": 25, "expected": "25", "convertTo": "string"}'); -- long value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "61", "value": {"$numberLong": "1" }, "expected": {"$numberLong": "1" }, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "62", "value": {"$numberLong": "1" }, "expected": 1, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "63", "value": {"$numberLong": "1" }, "expected": {"$numberDouble": "1"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "64", "value": {"$numberLong": "-11" }, "expected": {"$numberDouble": "-11"}, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "65", "value": {"$numberLong": "523453" }, "expected": {"$numberDecimal": "523453"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "66", "value": {"$numberLong": "523453" }, "expected": {"$numberLong": "523453"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "67", "value": {"$numberLong": "1" }, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "68", "value": {"$numberLong": "0" }, "expected": false, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "69", "value": {"$numberLong": "25" }, "expected": "25", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "70", "value": {"$numberLong": "25" }, "expected": {"$date": "1970-01-01T00:00:00.025Z"}, "convertTo": "date"}'); -- decimal value SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "71", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberDecimal": "1.3"}, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "72", "value": {"$numberDecimal": "1.3"}, "expected": "1.3", "convertTo": "string"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "73", "value": {"$numberDecimal": "1.3"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "74", "value": {"$numberDecimal": "0.0"}, "expected": false, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "75", "value": {"$numberDecimal": "-0.1"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "76", "value": {"$numberDecimal": "1.3"}, "expected": {"$date": "1970-01-01T00:00:00.001Z"}, "convertTo": "date"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "77", "value": {"$numberDecimal": "1.3"}, "expected": 1, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "78", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberLong": "1"}, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "79", "value": {"$numberDecimal": "1.3"}, "expected": {"$numberDouble": "1.3"}, "convertTo": "double"}'); -- other supported types to bool SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "80", "value": {"$minKey": 1}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "81", "value": {"foo": 1}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "82", "value": ["foo", 1], "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "83", "value": {"$binary": { "base64": "bGlnaHQgdw==", "subType": "01"}}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "84", "value": { "$regex": "a.*b", "$options": "" }, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "85", "value": { "$code": "var a = 1;"}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "86", "value": {"$maxKey": 1}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "87", "value": {"$timestamp" : { "t": 1670981326, "i": 1 }}, "expected": true, "convertTo": "bool"}'); SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "88", "value": { "$dbPointer" : { "$ref" : "db.test", "$id" : { "$oid" : "347f000000c1de008ec19ceb" }}}, "expected": true, "convertTo": "bool"}'); -- str to date is not yet supported, will be added with $dateFromString -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "89", "value": "2024-05-31", "expected": {"$date": "2024-05-31T00:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "90", "value": "2024-05-31T00:00:00.001Z", "expected": {"$date": "2024-05-31T00:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "91", "value": "2024-05-31T00:00:00.001+0500", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "92", "value": "2024-05-31 00:00:00.001 +0500", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "93", "value": "2024-05-31T00:00:00.001+5", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "94", "value": "2024-05-31T00:00:00.001+05", "expected": {"$date": "1969-12-31T19:00:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "95", "value": "2024-05-31T00:00:00.001+050", "expected": {"$date": "1969-12-31T23:10:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "96", "value": "2024-05-31T00:00:00.001+0510", "expected": {"$date": "1969-12-31T18:50:00.001Z"}, "convertTo": "date"}'); -- SELECT * from documentdb_api.insert_one('db', 'convertColl', '{"_id": "97", "value": "2024-05-31T00:00:00.001+0501", "expected": {"$date": "1969-12-31T18:59:00.001Z"}, "convertTo": "date"}'); -- call convert with the value and convertTo and check if the output is equal to the expected output. SELECT bson_dollar_project(document, '{"result": { "$eq": [{"$convert": { "input": "$value", "to": "$convertTo"}}, "$expected"]}}') FROM documentdb_api.collection('db', 'convertColl'); -- $convert to BinData SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "RG9jdW1lbnREQiBpcyBjb29sbGwh", "to": {"type": "binData", "subtype": 8}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "RG9jdW1lbnREQiBpcyBjb29sbGwh", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "UEdNb25nbyBpcyBHQSE", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 0}, "format": "hex"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 6}, "format": "hex"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "a27", "to": {"type": "binData", "subtype": 0}, "format": "utf8"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "UEdNb25nbyBpcyBHQSE=", "to": {"type": "binData"}, "format": "utf8"}}}'); SELECT * from bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": {"$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); SELECT * from bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": {"$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{"tt": "binData", "f": "hex"}', '{"result": {"$convert": { "input": "4a6f686e20446f65", "to": {"type": "$tt", "subtype": 0}, "format": "$f"}}}'); -- error: $convert to BinData with no format SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData"}}}'); -- error: $convert to BinData with non-string input SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": 123, "to": "binData", "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": false, "to": "binData", "format": "base64"}}}'); -- error: uuid format and uuid subtype violations SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 4}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData"}, "format": "uuid"}}}'); -- error: $convert to BinData with input-format mismatch SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "123", "to": "binData", "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3uUsMxSE6S0cVkebjm=fg==", "to": {"type": "binData", "subtype": 4}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 0}, "format": "base64"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3u+UsMxSE6S0cVkebjmfg==", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "hn3u+UsMxSE6S0cVkebjm/fg==", "to": {"type": "binData", "subtype": 0}, "format": "base64url"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "äöäöä", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 4}, "format": "uuid"}}}'); SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "451e4567-e89b-42d3-a456-556642440000", "to": {"type": "binData", "subtype": 4}, "format": "hex"}}}'); -- error: auto format not supported for to BinData SELECT * from bson_dollar_project('{}', '{"result": {"$convert": { "input": "SGVsbG8gd29ybGQh", "to": {"type": "binData", "subtype": 0}, "format": "auto"}}}'); -- error: auto format not supported for BinData to string yet SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex" } }, "to": "string", "format": "auto" } }}'); -- BinData to string using $convert SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "base64" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "utf8" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "💻🤠🔫", "to": "binData", "format": "utf8" } }, "to": "string", "format": "utf8" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "base64url" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "167dee52-c331-484e-92d1-c56479b8e670", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": "string", "format": "hex" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": "binData", "format": "hex" } }, "to": "string", "format": "hex" } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": {"type": "binData", "subtype": 5}, "format": "hex" } }, "to": "string", "format": "hex" } }}'); SELECT * FROM bson_dollar_project('{"i": "a27", "tt": "binData", "f": "hex"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "$tt", "subtype": 0}, "format": "$f" } }, "to": "string", "format": "$f" } }}'); SELECT * FROM bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": "string", "format": "uuid" } }}'); -- $convert from BinData to BinData SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "SGVsbG8gd29ybGQh", "to": "binData", "format": "base64" } }, "to": {"type": "binData", "subtype": 4} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "💻🤠🔫", "to": "binData", "format": "utf8" } }, "to": {"type": "binData", "subtype": 0} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 0} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "10000000-1000-1000-1000-100000000000", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 4} } }}'); SELECT * FROM bson_dollar_project('{}', '{"result": { "$convert": { "input": { "$convert": { "input": "4a6f686e20446f65", "to": "binData", "format": "hex" } }, "to": {"type": "binData", "subtype": 130} } }}'); SELECT * FROM bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "utf8" } }, "to": {"type": "binData", "subtype": "$ts"} } }}'); SELECT * FROM bson_dollar_project('{"i": "167dee52-c331-484e-92d1-c56479b8e670"}', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": 4}, "format": "uuid" } }, "to": {"type": "binData", "subtype": 4} } }}'); SELECT * FROM bson_dollar_project('{"i": "SGVsbG8gd29ybGQh", "ts": 0 }', '{"result": { "$convert": { "input": { "$convert": { "input": "$i", "to": {"type": "binData", "subtype": "$ts"}, "format": "utf8" } }, "to": {"type": "binData", "subtype": 0} } }}'); -- $convert with null to type should return null with and without onNull SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": null}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": "$missingField"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": null, "onNull": "Input was null"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": 1, "to": "$missingField", "onNull": "Input was null"}}}'); -- $convert with null input should return null without onNull and onNull expression if specified even if 'to' is null SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": "string"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": "bool"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": null, "onNull": "Input was null"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": null, "onNull": "Input was null"}}}'); -- $convert with null and undefined/missing onNull should return empty SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": null, "to": null, "onNull": "$onNullField"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": "$missingField", "to": null, "onNull": "$onNullField"}}}'); -- $convert with error outside of parsing should honor onError SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "1", "value": {"$numberDouble": "1.3"}, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "2", "value": {"$numberDouble": "1.3"}, "convertTo": "array"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "3", "value": {"$numberDouble": "1.3"}, "convertTo": "object"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "4", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "double"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "5", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "6", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "long"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "7", "value": { "$oid" : "347f000000c1de008ec19ceb" }, "convertTo": "decimal"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "8", "value": true, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "9", "value": false, "convertTo": "date"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "10", "value": {"$date": "2024-05-31T00:00:00.000Z"}, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "11", "value": {"$date": "2024-05-31T00:00:00.000Z"}, "convertTo": "int"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "12", "value": 1, "convertTo": "date"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "13", "value": 1.3, "convertTo": "minKey"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "14", "value": 1.3, "convertTo": "missing"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "15", "value": 1.3, "convertTo": "object"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "16", "value": 1.3, "convertTo": "array"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "17", "value": 1.3, "convertTo": "binData"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "18", "value": 1.3, "convertTo": "undefined"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "19", "value": 1.3, "convertTo": "null"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "20", "value": 1.3, "convertTo": "regex"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "21", "value": 1.3, "convertTo": "dbPointer"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "22", "value": 1.3, "convertTo": "javascript"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "23", "value": 1.3, "convertTo": "symbol"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "24", "value": 1.3, "convertTo": "javascriptWithScope"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "25", "value": 1.3, "convertTo": "timestamp"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "26", "value": 1.3, "convertTo": "maxKey"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "27", "value": 1, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "28", "value": {"$numberLong": "1"}, "convertTo": "objectId"}'); SELECT * from documentdb_api.insert_one('db', 'convertCollWithErrors', '{"_id": "29", "value": {"$numberDecimal": "1"}, "convertTo": "objectId"}'); SELECT bson_dollar_project(document, '{"output": {"$convert": { "input": "$value", "to": "$convertTo", "onError": "There was an error in $convert"}}}') FROM documentdb_api.collection('db', 'convertCollWithErrors'); -- $convert undefined/missing field used for onError should return empty result SELECT bson_dollar_project(document, '{"output": {"$convert": { "input": "$value", "to": "$convertTo", "onError": "$missingField"}}}') FROM documentdb_api.collection('db', 'convertCollWithErrors'); -- $convert errors in parsing should be honored even if onError is set SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": { "input": {"$divide": [1, 0]}, "to": "string", "onError": "There was an error in $convert"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": "$myField"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"to": 1, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"myCustomInput": 1, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": "someType", "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "1.1"}, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "255"}, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": {"$numberDouble": "-2.0"}, "onError": "There was an error"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": 1, "to": [], "onError": "There was an error"}}}'); -- $convert identifies the target types with numbers SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": -1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 127}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 0}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 1}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 2}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 3}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 4}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 5}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 6}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 7}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 8}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 9}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 10}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 11}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 12}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 13}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 14}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 15}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 16}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {}, "to": 17}}}'); -- double max + 1 and min-1 range $convert, $toLong SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "9223372036854775296"}, "to": "long"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "-9223372036854776833"}, "to": "long"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "9223372036854775296"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-9223372036854776833"}}}'); -- min supported value for $convert, $toLong SELECT * FROM bson_dollar_project('{}', '{"result": {"$convert": {"input": {"$numberDouble" : "-9223372036854776832"}, "to": "long"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-9223372036854776832"}}}'); -- -- -- $to* alias tests. -- call the shorthand convert $to* aliases. WITH toQuery AS (SELECT bson_dollar_project( document, format( '{"expected": 1, "output": { "$%s": "$value" } }', CASE TRIM(BOTH '"' FROM document->>'convertTo') WHEN 'double' THEN 'toDouble' WHEN 'string' THEN 'toString' WHEN 'objectId' THEN 'toObjectId' WHEN 'bool' THEN 'toBool' WHEN 'date' THEN 'toDate' WHEN 'int' THEN 'toInt' WHEN 'long' THEN 'toLong' WHEN 'decimal' THEN 'toDecimal' ELSE 'toInvalid' -- fail for easier diagnostics END )::bson ) as outDoc FROM documentdb_api.collection('db', 'convertColl')) SELECT bson_dollar_project(outDoc, '{"result": {"$eq": ["$output", "$expected"]}}') FROM toQuery; -- $toObjectId negative tests -- only supports 24 char hex string, objectId, null/undefined, and requires exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "this is a string"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "asdsfsdzzzzsersdfrtghtsz"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toObjectId": "639926cee6bda3127f153bfZ"}}'); -- $toInt negative tests -- only supports numeric, bool or string and must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": [{"$date": "2022-01-01T00:00:00.000Z"}]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "2147483648"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "-Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "-Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberDecimal": "-2147483649"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": {"$numberLong": "-2147483649"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "-2147483649" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "2147483648" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "This contains a number: 324423" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": " 324423" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "324423 " }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "0x01" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toInt": "" }}'); -- $toLong negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "9223372036854775808"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "-Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDouble": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "-Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "Infinity"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "NaN"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": {"$numberDecimal": "-9223372036854775809"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "-9223372036854775809" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "9223372036854775808" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "This contains a number: 324423" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": " 324423" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "324423 " }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "0x01" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toLong": "" }}'); -- $toDouble negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"$numberDecimal": "1.8E309"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": {"$numberDecimal": "-1.8E309"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "1.8E309" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "-1.8E309" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "This contains a number: 324423.23" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": " 324423.0" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "324423.00001 " }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "0x01" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDouble": "" }}'); -- $toDecimal negative tests -- only support numeric, date, bool or string, must not overflow/underflow. Takes exactly 1 argument. SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "123423.8E6145" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "-123423.8E6145" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "This contains a number: 324423.23" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": " 324423.0" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "324423.00001 " }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "0x01" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDecimal": "" }}'); -- $toString negative tests -- only support numeric, date, bool, string, objectId. Takes exactly 1 argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": {"$timestamp" : { "t": 1670981326, "i": 1 }}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toString": [[]]}}'); -- $toDate negative tests -- Currently double, decimal128, long, objectId, timestamp, date and string are supported. -- Numeric, will be added to the Unix epoch 0 and shouldn't exceed int64 limits. Takes exactly 1 argument SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"input": ""}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": []}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": [[]]}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDouble": "9223372036854775808"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDecimal": "9223372036854775808"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDecimal": "-9223372036854775809"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": {"$numberDouble": "-9223372036854775809"}}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": 1}}'); -- $toDate test for string case SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2022-01-01T00:00:00.000Z"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2022-01-01 00:00:00.000"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2018-03-20T12:00:00+0500"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2018-03-20"}}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toDate": "2017-Jul-04 noon"}}'); -- $$toHashedIndexKey tests --test int select *from bson_dollar_project('{"tests": 3}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 3 } }'); --test double select *from bson_dollar_project('{"tests": 3.1}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 3.1 } }'); --test string select *from bson_dollar_project('{"tests": "abc"}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": "abc" } }'); --test int64 select *from bson_dollar_project('{"tests": 123456789012345678}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": 123456789012345678 } }'); --test array select *from bson_dollar_project('{"tests": [1, 2, 3.1]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [1, 2, 3.1] } }'); --test nested array select *from bson_dollar_project('{"tests": [1, 2, 3.1,[4, 5], 6]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [1, 2, 3.1,[4, 5], 6] } }'); --test nested object select *from bson_dollar_project('{"tests": [{"$numberDecimal": "1.2"},3]}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": [{"$numberDecimal": "1.2"},3] } }'); --test null select *from bson_dollar_project('{"tests": null}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": null } }'); --test NaN select *from bson_dollar_project('{"tests": {"$numberDouble": "NaN"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "NaN"} } }'); --test Infinity select *from bson_dollar_project('{"tests": {"$numberDouble": "Infinity"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "Infinity"} } }'); --test -Infinity select *from bson_dollar_project('{"tests": {"$numberDouble": "-Infinity"}}', '{"result": { "$toHashedIndexKey": "$tests" } }'); select *from bson_dollar_project('{}', '{"result": { "$toHashedIndexKey": {"$numberDouble": "-Infinity"} } }'); --test path select *from bson_dollar_project('{"tests": {"test" : 5}}', '{"result": { "$toHashedIndexKey": "$tests.test" } }'); select *from bson_dollar_project('{"tests": 3}', '{"result": { "$toHashedIndexKey": "$test" } }'); select *from bson_dollar_project('{"tests": {"test" : 5}}', '{"result": { "$toHashedIndexKey": "$tests.tes" } }'); -- $toUUID tests -- equivalent $convert query should be tested after extended $convert syntax is supported -- positive tests SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": null }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": "123e4567-e89b-12d3-a456-426614174000" }}'); SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": ["123e4567-e89b-12d3-a456-426614174000"] }}'); -- negative tests -- invalid string SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": "invalid-uuid-1234" }}'); -- invalid type SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": 1234 }}'); -- invalid count number of array input SELECT * FROM bson_dollar_project('{}', '{"result": {"$toUUID": ["123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174000"] }}');bson_base_aggregates_tests_runtime.sql000066400000000000000000000272561507310017400366370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 61000; SET documentdb.next_collection_id TO 6100; SET documentdb.next_collection_index_id TO 6100; -- insert basic numeric data. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"1", "i32": { "$numberInt" : "11" }, "i64": { "$numberLong" : "11" }, "idbl": { "$numberDouble" : "11.0" }}'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"2", "i32": { "$numberInt" : "-2" }, "i64": { "$numberLong" : "-2" }, "idbl": { "$numberDouble" : "-2.0" }}'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"3", "i32": { "$numberInt" : "20" }, "i64": { "$numberLong" : "20" }, "idbl": { "$numberDouble" : "20" }}'); -- Compute sum/Avg; they should be in the respective types. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); -- Now add some values that are non numeric. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"4", "i32": "stringValue", "i64": "stringValue", "idbl": "stringValue"}'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"5", "i32": true, "i64": false, "idbl": true}'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"6", "i32": [1, 2, 3], "i64": [4, 5, 6], "idbl": [7, 8, 9]}'); -- Compute sum and average for filters that result in 0 rows. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; SELECT BSONSUM(document), BSONAVERAGE(document) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @@ '{ "nonExistentField": 1 }'; -- Compute sum/Avg; They should be the same since non-numeric values do not impact the sum/avg. SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONSUM(document), BSONAVERAGE(document) FROM documentdb_api.collection('db', 'testAggregates'); -- Now add values that cause int32/int64 to roll over to the next highest type (mixed type sum) SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"7", "i32": { "$numberInt" : "2147483645" }, "i64": { "$numberLong" : "9223372036854775801" }, "idbl": { "$numberDouble" : "1e20" }}'); -- sum/Avg should now move to the next available type SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); -- Now add a field that only exists in i32 - for i64/dbl it won't be there and it'll be a double field to test upgrade when the value type changes. SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"8", "i32": { "$numberDouble" : "31.6" }}'); -- sum/Avg They all should be dbl and partial data should be ignored for i64/idbl SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); -- Query non existent field. SELECT BSONSUM(document -> 'nao existe'), BSONAVERAGE(document -> 'nao existe') FROM documentdb_api.collection('db', 'testAggregates'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"9", "a" : { "b" : 1 } }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"10", "a" : { "b" : 2 } }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"11", "a" : { "b" : [ 0, 1, 2 ] } }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"12", "a" : [ { "b" : 1 }, { "b" : 3 } ] }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"13", "a" : [ { "b" : 0 }, { "b" : 1 }, { "b" : 3 } ] }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"14", "a" : [ { "b" : 0 }, { "b" : 1 }, { "b" : 3 } ] }'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"15", "a" : [ { "b" : [ -1, 1, 2 ] }, { "b" : [ 0, 1, 2 ] }, { "b" : [ 0, 1, 7 ] } ]}'); SELECT documentdb_api.insert_one('db','testAggregates','{"_id":"16", "a" : [ { "b" : 9 } ]}'); SELECT BSONMAX(bson_expression_get(document, '{ "": "$a.b" }')) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @? '{ "a.b": 1}'; SELECT BSONMIN(bson_expression_get(document, '{ "": "$a.b" }')) FROM documentdb_api.collection('db', 'testAggregates') WHERE document @? '{ "a.b": 1}'; -- Rebuild bson objects from aggregates SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); -- Null values in aggregates SELECT BSONMAX(document-> 'nao existe') FROM documentdb_api.collection('db', 'testAggregates'); SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'nao existe'), 'sum'::text, BSONSUM(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); -- Rebuild with prepared statement PREPARE q1 (text, text, text) AS SELECT bson_repath_and_build($1, BSONMAX(document-> 'i32'), $2, BSONSUM(document-> 'i32'), $3, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); EXECUTE q1 ('max', 'sum', 'average'); -- Invalid rebuild arguments SELECT bson_repath_and_build('max'::text, BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); SELECT bson_repath_and_build(BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); SELECT bson_repath_and_build('max'::text, 'max2', BSONMAX(document-> 'i32'), 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); SELECT bson_repath_and_build(BSONMAX(document-> 'i32'), 'max'::text, 'sum'::text, BSONSUM(document-> 'i32'), 'average'::text, BSONAVERAGE(document-> 'i32')) FROM documentdb_api.collection('db', 'testAggregates'); -- Shard the collection SELECT documentdb_api.shard_collection('db', 'testAggregates', '{"_id":"hashed"}', false); -- Try basic aggregates when sharded SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONMIN(document-> 'i32'), BSONMIN(document-> 'i64'), BSONMIN(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONMAX(document-> 'i32'), BSONMAX(document-> 'i64'), BSONMAX(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); -- shard on a path that not all documents have: SELECT documentdb_api.shard_collection('db', 'testAggregates', '{"_id":"hashed"}', false); SELECT BSONSUM(document-> 'i32'), BSONSUM(document-> 'i64'), BSONSUM(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONAVERAGE(document-> 'i32'), BSONAVERAGE(document-> 'i64'), BSONAVERAGE(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONMIN(document-> 'i32'), BSONMIN(document-> 'i64'), BSONMIN(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); SELECT BSONMAX(document-> 'i32'), BSONMAX(document-> 'i64'), BSONMAX(document -> 'idbl') FROM documentdb_api.collection('db', 'testAggregates'); -- validation from field_name_validation.js SELECT documentdb_api.insert_one('db', 'testAggregates', '{ "_id": { "a": 1, "b": 2 }, "c.d": 3 }'); SELECT BSONSUM(bson_expression_get(document, '{ "": "$c.d" }')) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); SELECT BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }')) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); SELECT bson_repath_and_build('e.f'::text, BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }'))) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); SELECT bson_repath_and_build('$e'::text, BSONSUM(bson_expression_get(document, '{ "": "$_id.b" }'))) FROM documentdb_api.collection('db', 'testAggregates') GROUP BY bson_expression_get(document, '{ "": "$_id.a" }'); SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 1, "a": 1 }'); SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 2, "a": 2 }'); SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 3, "a": 3 }'); SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 4, "a": 4 }'); SELECT documentdb_api.insert_one('db', 'testAggregatesWithIndex', '{ "_id": 5, "a": 5 }'); -- simulate a count BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; -- create an index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('testAggregatesWithIndex', 'idx_1', '{ "a": 1 }'), true); -- repeat BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; -- now shard the collection. SELECT documentdb_api.shard_collection('db', 'testAggregatesWithIndex', '{ "_id": "hashed" }', false); -- repeat BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT BSONSUM('{ "": 1 }') FROM documentdb_api.collection('db', 'testAggregatesWithIndex'); ROLLBACK; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_base_operators.sql000066400000000000000000000064161507310017400336310ustar00rootroot00000000000000SET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 4700000; SET documentdb.next_collection_id TO 4700; SET documentdb.next_collection_index_id TO 4700; SELECT '{"a":1,"b":"c"}'::bson->'a'; SELECT '{"a":1,"b":"c"}'::bson->'b'; SELECT '{"a":1,"b":["c"]}'::bson->'b'; SELECT '{"a":1,"b":{"c":3}}'::bson->'b'; SELECT '{"a":1,"b":"c"}'::bson->'c' IS NULL; SELECT '{"a":1,"b":"c"}'::bson->NULL IS NULL; SELECT bson_get_value('{"a":1,"b":"c"}', 'a'); SELECT bson_get_value('{"a":1,"b":"c"}', 'b'); SELECT bson_get_value('{"a":1,"b":["c"]}', 'b'); SELECT bson_get_value('{"a":1,"b":{"c":3}}', 'b'); SELECT bson_get_value('{"a":1,"b":"c"}', 'c') IS NULL; SELECT bson_get_value('{"a":1,"b":"c"}', NULL) IS NULL; SELECT * FROM bson_object_keys('{"a":1,"b":2}'); SELECT * FROM bson_object_keys('{"b":1,"a":2}'); SELECT * FROM bson_object_keys('{"b":1,"b":2}'); SELECT * FROM bson_object_keys(NULL); SELECT '{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a'; SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberInt": "10" }, "b" : "c" }'::bson->>'a')::float; SELECT '{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a'; SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberLong": "11" }, "b" : "c" }'::bson->>'a')::float; SELECT '{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a'; SELECT ('{ "a": { "$numberDouble": "11" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberDouble": "11" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberDouble": "1.23e100" }, "b" : "c" }'::bson->>'a')::float; SELECT ('{ "a": { "$numberDouble": "11.12" }, "b" : "c" }'::bson->>'a')::float; SELECT '{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a'; SELECT ('{ "a": { "$numberDecimal": "11" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::int; SELECT ('{ "a": { "$numberDecimal": "11" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::int8; SELECT ('{ "a": { "$numberDecimal": "1.23e100" }, "b" : "c" }'::bson->>'a')::float; SELECT ('{ "a": { "$numberDecimal": "11.12" }, "b" : "c" }'::bson->>'a')::float; SELECT ('{ "a": { "$numberDecimal": "1123123e2000" }, "b" : "c" }'::bson->>'a')::float; SELECT '{ "a": true, "b" : "c" }'::bson->>'a'; SELECT '{ "a": false, "b" : "c" }'::bson->>'a'; SELECT ('{ "a": true, "b" : "c" }'::bson->>'a')::boolean; SELECT ('{ "a": false, "b" : "c" }'::bson->>'a')::boolean; -- other types other than string are returned as an object when used with ->> SELECT '{ "a": {"$oid": "62e034e129274a635b24d895"}, "b" : "c" }'::bson->>'a'; WITH r1 AS (SELECT 1.0::float8 as dbl, 'text' AS txt, 3::int4 as int32, 44::int8 as int64, '{ "": [1, 2, 3]}'::bson as bsonValue, '{"a": 1, "b": 2}'::bson as bsonObj) SELECT row_get_bson(r) FROM r1 r; SELECT '{"a":1,"b":"c"}'::bson::bytea::bson = '{"a":1,"b":"c"}'::bson; bson_composite_index_only_scan_pg16_tests.sql000066400000000000000000000002721507310017400400510ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 6920000; SET documentdb.next_collection_id TO 692000; SET documentdb.next_collection_index_id TO 692000; \i sql/bson_composite_index_only_scan_tests_core.sql bson_composite_index_only_scan_tests.sql000066400000000000000000000002671507310017400372200ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 690000; SET documentdb.next_collection_id TO 69000; SET documentdb.next_collection_index_id TO 69000; \i sql/bson_composite_index_only_scan_tests_core.sql bson_composite_index_only_scan_tests_core.sql000066400000000000000000000333251507310017400402310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET documentdb.enableExtendedExplainPlans to on; SET documentdb.enableIndexOnlyScan to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; SELECT documentdb_api.drop_collection('idx_only_scan_db', 'idx_only_scan_coll') IS NOT NULL; SELECT documentdb_api.create_collection('idx_only_scan_db', 'idx_only_scan_coll'); SELECT collection_id as coll_id FROM documentdb_api_catalog.collections WHERE collection_name = 'idx_only_scan_coll' AND database_name = 'idx_only_scan_db' \gset SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_1" }] }', true); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 1, "country": "USA", "provider": "AWS"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 2, "country": "USA", "provider": "Azure"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 3, "country": "Mexico", "provider": "GCP"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 4, "country": "India", "provider": "AWS"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 5, "country": "Brazil", "provider": "Azure"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 6, "country": "Brazil", "provider": "GCP"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 7, "country": "Mexico", "provider": "AWS"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 8, "country": "USA", "provider": "Azure"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 9, "country": "India", "provider": "GCP"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 10, "country": "Mexico", "provider": "AWS"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 11, "country": "USA", "provider": "Azure"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 12, "country": "Spain", "provider": "GCP"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 13, "country": "Italy", "provider": "AWS"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 14, "country": "France", "provider": "Azure"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 15, "country": "France", "provider": "GCP"}'); select documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 16, "country": "Mexico", "provider": "AWS"}'); SELECT 'ANALYZE documentdb_data.documents_' || :'coll_id' \gexec set enable_seqscan to off; set enable_bitmapscan to off; -- test index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); -- now run VACUUM should see the heap blocks go down SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); -- now update a document to change the country SELECT documentdb_api.update('idx_only_scan_db', '{"update": "decimal128", "updates":[{"q": {"_id": 8},"u":{"$set":{"country": "Italy"}},"multi":false}]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$eq": "USA"}}}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); SELECT document FROM bson_aggregation_count('idx_only_scan_db', '{"count": "idx_only_scan_coll", "query": {"country": {"$in": ["USA", "Italy"]}}}'); -- match with count EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); -- range queries should also use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gt": "Brazil"}, "country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); -- No filters and not sharded should use _id_ index EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{"$match": {}}, { "$count": "count" }]}'); -- now test with compound index SELECT documentdb_api_internal.create_indexes_non_concurrently('idx_only_scan_db', '{ "createIndexes": "idx_only_scan_coll", "indexes": [ { "key": { "country": 1, "provider": 1 }, "storageEngine": { "enableOrderedIndex": true }, "name": "country_provider_1" }] }', true); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": "GCP"}} }, { "$count": "count" }]}'); -- if the filter doesn't match the first field in the index, shouldn't use the compound index and not index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"provider": {"$eq": "AWS"}} }, { "$count": "count" }]}'); -- if we project something out it shouldn't do index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Mexico"}} }, { "$group" : { "_id" : "$country", "n" : { "$sum" : 1 } } }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }]}'); -- negation, elemMatch, type and size queries should not use index only scan EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$ne": "Mexico"}} }, { "$count": "count" }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$type": "string"}} }, { "$count": "count" }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$size": 2}} }, { "$count": "count" }]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$elemMatch": {"$eq": "Mexico"}}} }, { "$count": "count" }]}'); -- if we turn the GUC off by it shouldn't use index only scan set documentdb.enableIndexOnlyScan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$lt": "Mexico"}} }, { "$count": "count" }]}'); set documentdb.enableIndexOnlyScan to on; -- if we insert a multi-key value, it shouldn't use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', '{"_id": 17, "country": "Mexico", "provider": ["AWS", "GCP"]}'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}, "provider": {"$eq": ["AWS", "GCP"]}} }, { "$count": "count" }]}'); CALL documentdb_api.drop_indexes('idx_only_scan_db', '{ "dropIndexes": "idx_only_scan_coll", "index": "country_provider_1" }'); -- now insert a truncated term, should not use index only scan SELECT documentdb_api.insert_one('idx_only_scan_db', 'idx_only_scan_coll', FORMAT('{ "_id": 18, "country": { "key": "%s", "provider": "%s" } }', repeat('a', 10000), repeat('a', 10000))::bson); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); -- if we delete it and vacuum it should use index only scan again SELECT documentdb_api.delete('idx_only_scan_db', '{ "delete": "idx_only_scan_coll", "deletes": [ {"q": {"_id": {"$eq": 18} }, "limit": 0} ]}'); SELECT 'VACUUM documentdb_data.documents_' || :'coll_id' \gexec EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$eq": "Mexico"}} }, { "$count": "count" }]}'); -- TODO support sharded collections, currently we don't because of the shard_key_value filter -- SELECT documentdb_api.shard_collection('idx_only_scan_db', 'idx_only_scan_coll', '{ "country": "hashed" }', FALSE); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$gte": "Brazil"}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- EXPLAIN (COSTS OFF, VERBOSE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); -- SELECT document FROM bson_aggregation_pipeline('idx_only_scan_db', '{ "aggregate" : "idx_only_scan_coll", "pipeline" : [{ "$match" : {"country": {"$in": ["Mexico", "USA"]}} }, { "$group" : { "_id" : "1", "n" : { "$sum" : 1 } } }]}'); bson_composite_index_prepare_for_unique_tests.sql000066400000000000000000000061021507310017400411170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api,documentdb_core,documentdb_api_catalog; SET citus.next_shard_id TO 5880000; SET documentdb.next_collection_id TO 588000; SET documentdb.next_collection_index_id TO 588000; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{ "createIndexes": "collection", "indexes": [ { "name": "a_1", "key": { "a": 1 }, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true } } ] }', TRUE); \d documentdb_data.documents_588001; -- inserting and querying works fine. select COUNT(documentdb_api.insert_one('prep_unique_db', 'collection', FORMAT('{ "a": %s, "b": %s }', i, 100-i)::bson)) FROM generate_series(1, 100) i; -- insert a duplicate, should not fail SELECT documentdb_api.insert_one('prep_unique_db', 'collection', '{ "a": 1 }'); ANALYZE documentdb_data.documents_588001; set citus.propagate_set_commands to 'local'; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local enable_seqscan to off; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}} }'); ROLLBACK; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.enableIndexOrderByPushdown to on; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}}, "sort": {"a": 1} }'); ROLLBACK; -- multiple fields work fine SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{ "createIndexes": "collection", "indexes": [ { "name": "a_1_b_1", "key": { "a": 1, "b": 1 }, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true } } ] }', TRUE); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('prep_unique_db', '{ "listIndexes": "collection" }') ORDER BY 1; \d documentdb_data.documents_588001; ANALYZE documentdb_data.documents_588001; BEGIN; set local documentdb.enableExtendedExplainPlans to on; set local enable_seqscan to off; EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS OFF, TIMING OFF, SUMMARY OFF) select document FROM bson_aggregation_find('prep_unique_db', '{ "find": "collection", "filter": {"a": {"$gt": 2}, "b": 3} }'); ROLLBACK; -- test error paths SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{"createIndexes": "collection", "indexes": [{"key": {"a": 1 }, "storageEngine": { "enableOrderedIndex": false, "buildAsUnique": true }, "name": "invalid"}]}',true); SELECT documentdb_api_internal.create_indexes_non_concurrently('prep_unique_db', '{"createIndexes": "collection", "indexes": [{"key": {"b": 1 }, "unique": true, "storageEngine": { "enableOrderedIndex": true, "buildAsUnique": true }, "name": "invalid"}]}',true); bson_composite_order_by_index_tests.sql000066400000000000000000001247721507310017400370500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 680000; SET documentdb.next_collection_id TO 68000; SET documentdb.next_collection_index_id TO 68000; set documentdb.enableExtendedExplainPlans to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; SELECT documentdb_api.drop_collection('comp_db', 'query_orderby') IS NOT NULL; SELECT documentdb_api.create_collection('comp_db', 'query_orderby'); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby", "indexes": [ { "key": { "a": 1, "c": 1 }, "storageEngine": { "enableCompositeTerm": true }, "name": "a_c" }] }', true); \d documentdb_data.documents_68001 -- now insert some sample docs SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 1, "a": 1, "c": 1 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 2, "a": -2, "c": 2 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 3, "a": "string", "c": 2 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 4, "a": { "$minKey": 1 }, "c": 2 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 5, "a": true, "c": 2 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 6, "a": null, "c": 2 }'); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 7, "a": { "b": 1 }, "c": 2 }'); ANALYZE documentdb_data.documents_68001; set enable_seqscan to off; -- no pushdown EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); -- now the order by succeeds with an index scan SET documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); -- do a reverse walk EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": -1 } }'); -- now check the correctness (things are ordered) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$exists": true }}, "sort": { "a": -1 } }'); -- validate type bracketing SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": -100 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gte": -2 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": false }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": true }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gte": true }}, "sort": { "a": 1 } }'); -- validate runtime recheck functions SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^str" }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^str" }}, "sort": { "a": -1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": -1 } }'); -- validate ordering with truncation SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 10, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '2', 'cd1233')::bson); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 11, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '1', 'cd1234')::bson); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 9, "a": "%s", "c": "%s" }', 'abcde' || repeat('z', 3000) || '3', 'cd1235')::bson); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 12, "a": "%s", "c": "%s" }', 'abcde', 'cd1232' || repeat('z', 3000) || '1')::bson); SELECT documentdb_api.insert_one('comp_db', 'query_orderby', FORMAT('{ "_id": 13, "a": "%s", "c": "%s" }', 'abcde', 'cd1232')::bson); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "projection": { "_id": 1 }, "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "projection": { "_id": 1 }, "filter": { "a": { "$regex": "^abc" }}, "sort": { "a": -1 } }'); -- validate sort works after an array is inserted SELECT documentdb_api.insert_one('comp_db', 'query_orderby', '{ "_id": 8, "a": [ 1, 2, 3 ], "c": 2 }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby", "filter": { "a": { "$gt": -100 }}, "sort": { "a": 1 } }'); -- validate that we use disjoint sets more efficiently SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf_arr", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a_1_id_1" }] }', true); -- insert an array to make this a multi-key index SELECT documentdb_api.insert_one('comp_db', 'query_orderby_perf_arr', '{ "_id": 0, "a": [ true, false ] }'); -- now insert documents 1 - 100 SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf_arr', FORMAT('{ "_id": %s, "a": [ %s, %s ] }', i, i, 100 - i)::bson)) FROM generate_series(1, 100) AS i; -- now query the index with an order by set documentdb.forceDisableSeqScan to on; ANALYZE documentdb_data.documents_68002; -- should not use the index for sort (since it's a multi-key index) EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); -- now check the performance SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); -- only pushes filter down SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); set documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); -- only pushes filter down EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf_arr", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); -- test the same for non multi-key index --------------------------------------------------------------------------------- -- validate that we use disjoint sets more efficiently SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a_1" }] }', true); -- now insert documents 1 - 100 SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf', FORMAT('{ "_id": %s, "a": %s }', i, i)::bson)) FROM generate_series(1, 100) AS i; -- now query the index with an order by set documentdb.forceDisableSeqScan to on; ANALYZE documentdb_data.documents_68003; -- should use the index for sort EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); -- now check correctness. SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": -1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": -1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": -1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": -1 } }'); -- now check the performance EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$in": [ 3, 49, 90 ] }}, "sort": { "a": -1 } }'); -- scans 1 loop for checking multi-key - then scans 4 loops for entries 0, 1, 2, 3. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3 }}, "sort": { "a": -1 } }'); -- scans 1 loop for checking multi-key - then scans 5 loops for entries 96, 97, 98, 99, 100. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$gt": 96 }}, "sort": { "a": -1 } }'); -- only scans th relevant entries EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 94, "$gt": 90 }}, "sort": { "a": -1 } }'); -- scans only > 96 and stops. EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": 1 } }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "query_orderby_perf", "filter": { "a": { "$lt": 3, "$gt": 96 }}, "sort": { "a": -1 } }'); -- groupby pushdown works for non-multi-key indexes EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$exists": true } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); set enable_bitmapscan to off; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); -- the same does not work on multi-key indexes EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$exists": true } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); set enable_bitmapscan to off; -- for non-multi-key requires, prefix equality until the min order by key only. -- can't push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); -- can push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$gte": 1 } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$sort": { "a": 1, "_id": 1 } } ] }'); -- but not these EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1, "a": 1 } } ] }'); -- for multi-key indexes, we can push down the order by only if there's equality until the max order by key. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); -- can push this EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "a": 1, "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "a": 1 } } ] }'); -- but not these EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$in": [ 1, 2 ] } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$match": { "a": { "$gte": 1 } } }, { "$sort": { "a": 1, "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf_arr", "pipeline": [ { "$sort": { "_id": 1, "a": 1 } } ] }'); -- now insert composite rows that cause truncation and assert that it gets ordered properly. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "query_orderby_perf2", "indexes": [ { "key": { "b": 1, "c": 1 }, "enableCompositeTerm": true, "name": "b_1" }] }', true); SELECT COUNT(documentdb_api.insert_one('comp_db', 'query_orderby_perf2', FORMAT('{ "_id": %s, "b": "%s", "c": %s }', i * 5 + j, repeat('aaaa', 10 * i), j)::bson)) FROM generate_series(50, 500) i JOIN generate_series(1, 5) AS j ON True; ANALYZE documentdb_data.documents_68004; SET documentdb.enableIndexOrderbyPushdown to on; set documentdb.forceUseIndexIfAvailable to on; set enable_bitmapscan to off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }'); EXPLAIN (COSTS OFF) WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' >= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }'); EXPLAIN (COSTS OFF) WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' <= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; -- validate the order is correct WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": 1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' >= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; WITH s1 AS (SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "query_orderby_perf2", "pipeline": [ { "$match": { "b": { "$exists": true } } }, { "$sort": { "b": -1 } } ] }')), s2 AS (SELECT COALESCE(document -> 'b' <= (LAG(document, 1) OVER ()) -> 'b', true) AS greater_check FROM s1) SELECT MIN(greater_check::int4), MAX(greater_check::int4) FROM s2; reset documentdb.forceDisableSeqScan; -- add the complex tests that were in the composite filter order by select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 1, "a": { "b": 1 } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 2, "a": { "b": null } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 3, "a": { "b": "string value" } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 4, "a": { "b": true } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 5, "a": { "b": false } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 6, "a": { "b": [] } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 7, "a": { "b": [1, 2, 3] } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 8, "a": { "b": [1, { "$minKey": 1 }, 3, true] } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 9, "a": { "b": [1, { "$maxKey": 1 }, 3, true] } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 10, "a": { "b": { "c": 1 } } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 11, "a": { "b": { "$maxKey": 1 } } }'); -- now some more esoteric values select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 12, "a": null }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 13, "a": [ {} ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 14, "a": [ 1 ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 15, "a": [ 1, { "b": 3 } ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 16, "a": [ null, { "b": 4 } ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 17, "a": [ {}, { "b": 3 } ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 18, "a": [ { "c": 1 } ] }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 19, "a": [ { "c": 1 }, { "b": 3 } ] }'); -- baseline select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 20, "a": { "b": 0 } }'); select * from documentdb_api.insert_one('comp_db', 'sortcoll', '{ "_id": 21, "a": { "b": { "$minKey": 1 } } }'); -- test ordering in the composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b_1" }] }', true); -- now sort manually (we can't rely on the index pushdown feature yet since that requires a filter) BEGIN; set local documentdb.forceDisableSeqScan to on; set local documentdb.enableIndexOrderbyPushdown to on; set local documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": 1 } } ] }'); ROLLBACK; BEGIN; set local documentdb.forceDisableSeqScan to on; set local documentdb.enableIndexOrderbyPushdown to on; SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": 1 } } ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "a.b": -1 } } ] }'); ROLLBACK; set documentdb.forceDisableSeqScan to on; set documentdb.enableIndexOrderbyPushdown to on; set documentdb.enableExtendedExplainPlans to on; -- can't push this down (no equality prefix) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$sort": { "_id": 1 } } ] }'); -- can't push order by down here: EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } }, { "$sort": { "_id": 1 } } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$gt": 5 } } }, { "$sort": { "_id": 1 } } ] }'); -- but this is okay EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$eq": 1 } } }, { "$sort": { "_id": 1 } } ] }'); -- this one isn't okay since we need to resort across a.b EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$in": [ 1, 2 ] } } }, { "$sort": { "_id": 1 } } ] }'); -- but this is fine: EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$in": [ 1 ] } } }, { "$sort": { "_id": 1 } } ] }'); -- allows incremental sorting set enable_sort to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$eq": 1 } } }, { "$sort": { "_id": 1, "c": 1 } } ] }'); -- forced order by pushdown respects ordering when there is none. set documentdb_rum.forceRumOrderedIndexScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } } ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "sortcoll", "pipeline": [ { "$match": { "a.b": { "$exists": true } } } ] }'); -- test order by with primary key _id and composite index on _id with _id filter & order reset documentdb.forceDisableSeqScan; select COUNT(documentdb_api.insert_one('comp_db', 'idIndexOrder', FORMAT('{ "_id": %s, "a": %s }', i , i)::bson)) FROM generate_series(1, 100) AS i; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "idIndexOrder", "indexes": [ { "key": { "_id": 1 }, "enableCompositeTerm": true, "name": "id_2" }] }', true); -- now validate pushdown set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "idIndexOrder", "pipeline": [ { "$match": { "_id": { "$gte": 10, "$lte": 25 } } }, { "$sort": { "_id": 1 } }, { "$skip": 5 }, { "$limit": 5 } ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "idIndexOrder", "pipeline": [ { "$match": { "_id": { "$gte": 10, "$lte": 25 } } }, { "$sort": { "_id": 1 } }, { "$skip": 5 }, { "$limit": 5 } ] }'); -- now repeat sort for nulls with 3 dotted paths set documentdb.forceDisableSeqScan to off; SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 1, "a": { "b": { "c": 1 } } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 2, "a": { "b": [ { "c": 2 } ] } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 3, "a": [ { "b": [ { "c": 1 } ] } ] }'); -- combinations of those paths going missing SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 4, "a": { "b": { "d": 1 } } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 5, "a": { "b": [ { "c": 2 }, {} ] } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 6, "a": { "b": [ { "c": 2 }, 2 ] } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 7, "a": { "b": [ 2 ] } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 8, "a": { "b": [ {} ] } }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 9, "a": [ { "b": { "c": 3 } }, { "b": { "d": 1 } } ] }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 10, "a": [ { "b": { "c": 3 } }, { "b": 2 } ] }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 11, "a": [ { "b": { "c": 3 } }, { } ] }'); SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 12, "a": [ { "b": { "c": 3 } }, 1 ] }'); -- baseline SELECT * FROM documentdb_api.insert_one('comp_db', 'sortcoll3', '{ "_id": 13, "a": { "b": { "c": 0 } } }'); set documentdb.forceDisableSeqScan to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b.c_1" }] }', true); SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": 1 } }'); -- with forced order by scans, recheck of the index on the runtime needs to happen. reset documentdb.forceDisableSeqScan; SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 1, "a": "%s" }', repeat('a', 9999) || 'bb')::bson); SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 2, "a": "%s" }', repeat('a', 9999) || 'cb')::bson); SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 3, "a": "%s" }', repeat('a', 9999) || 'ab')::bson); -- 4 does not match SELECT documentdb_api.insert_one('comp_db', 'large_keys', FORMAT('{ "_id": 4, "a": "%s" }', repeat('a', 9999) || 'ac')::bson); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "large_keys", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_2" }] }', true); set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "large_keys", "pipeline": [ { "$match": { "a": { "$regex": ".+b$" } } }, { "$sort": { "a": 1 } }, { "$project": { "_id": 1 } } ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "large_keys", "pipeline": [ { "$match": { "a": { "$regex": ".+b$" } } }, { "$sort": { "a": 1 } }, { "$project": { "_id": 1 } } ] }'); reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b.c_-1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b_-1" }] }', true); set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": -1 } }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": -1 } }'); SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": -1 } }'); SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": -1 } }'); -- partial sort pushdown EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": -1, "_id": 1 } }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); -- mixed asc/desc indexes reset documentdb.forceDisableSeqScan; CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "sortcoll3", "index": "a.b.c_-1" }'); CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "sortcoll", "index": "a.b_-1" }'); -- recreate with mixed asc/desc SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll3", "indexes": [ { "key": { "a.b.c": 1, "_id": -1 }, "enableCompositeTerm": true, "name": "a.b.c_1_id-1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "sortcoll", "indexes": [ { "key": { "a.b": -1, "_id": 1 }, "enableCompositeTerm": true, "name": "a.b_-1_id_1" }] }', true); set documentdb.forceDisableSeqScan to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": -1 } }'); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll3", "filter": {}, "sort": { "a.b.c": 1, "_id": -1 } }'); SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "sortcoll", "filter": {}, "sort": { "a.b": -1, "_id": 1 } }'); -- test order by functionality with group reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "ordering_groups", "indexes": [ { "key": { "a": 1 }, "enableOrderedIndex": true, "name": "a_1" }] }', true); -- a is either 0 or 1 or 2 select COUNT(documentdb_api.insert_one('comp_db', 'ordering_groups', FORMAT('{ "_id": %s, "a": %s }', i , i % 3)::bson)) FROM generate_series(1, 100) AS i; ANALYZE documentdb_data.documents_68009; set documentdb.forceDisableSeqScan to on; set documentdb.enableIndexOrderbyPushdown to on; EXPLAIN (ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "ordering_groups", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db', '{ "aggregate": "ordering_groups", "pipeline": [ { "$group": { "_id": "$a", "c": { "$count": 1 } } } ] }'); -- sorting on prefix with missing path is not allowed unless it's equality. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "compOrderSkip", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1}, "name": "idx1", "enableOrderedIndex": true } ] }'); select COUNT(documentdb_api.insert_one('comp_db', 'compOrderSkip', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i , i, i % 5, i % 10, i % 20 )::bson)) FROM generate_series(1, 100) AS i; -- now given that it's not multi-key, we can push down sorts to the index fully *iff* missing fields are equality. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": 2 }, "sort": { "a": 1, "b": 1, "d": 1 } }'); -- cannot push non equality in the non-sorted prefix EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 5, 6 ]} }, "sort": { "a": 1, "b": 1, "d": 1 } }'); -- once it's multi-key this isn't allowed. SELECT documentdb_api.insert_one('comp_db', 'compOrderSkip', FORMAT('{ "_id": %s, "a": [ %s, 2, 3 ], "b": %s, "c": %s, "d": %s }', 200, 201, 202, 203, 204 )::bson); EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "compOrderSkip", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "c": 2 }, "sort": { "a": 1, "b": 1, "d": 1 } }'); --composite index selection with order by. SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_c_d_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_d_1" }] }', true); -- insert 100 docs select COUNT(documentdb_api.insert_one('comp_db', 'index_orderby_selection', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i, i % 3, i % 10, i % 100, i )::bson)) FROM generate_series(1, 100) AS i; ANALYZE documentdb_data.documents_68010; -- order by should use the order by filter index (a_b_c_1) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); -- if we're querying just filters, use a_b_d since it's better EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 } }'); set documentdb.enableIndexOrderbyPushdownLegacy to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); -- the same should work if the indexes were created in the reverse order CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_c_d_1" }'); CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_d_1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_d_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "enableOrderedIndex": true, "name": "a_b_c_d_1" }] }', true); set documentdb.enableIndexOrderbyPushdownLegacy to off; -- order by should use the order by filter index (a_b_c_1) EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 }, "sort": { "a": 1, "b": 1, "c": 1 } }'); -- if we're querying just filters, use a_b_d since it's better EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "a": { "$in": [ 1, 2 ] }, "b": { "$in": [ 2, 3 ] }, "d": 10 } }'); -- order by backward scan with unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "unique_sort", "indexes": [ { "key": { "a": 1, "b": 1 }, "enableOrderedIndex": true, "name": "a_b_1", "unique": true }] }', true); select COUNT(documentdb_api.insert_one('comp_db', 'unique_sort', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s, "d": %s }', i, i, i, i, i )::bson)) FROM generate_series(1, 100) AS i; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('comp_db', '{ "find": "unique_sort", "sort": { "a": -1, "b": -1 }}'); -- test index selectivity for orderby vs filters. CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_c_d_1" }'); CALL documentdb_api.drop_indexes('comp_db', '{ "dropIndexes": "index_orderby_selection", "index": "a_b_d_1" }'); TRUNCATE documentdb_data.documents_68011; ANALYZE documentdb_data.documents_68011; -- now create 2 types of indexes: One that only matches the order by and one that matches the order and filters SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "orderKey": 1, "otherPath": 1 }, "enableOrderedIndex": true, "name": "sortIndex_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db', '{ "createIndexes": "index_orderby_selection", "indexes": [ { "key": { "filter1": 1, "filter2": 1, "orderKey": 1, "filter3": 1 }, "enableOrderedIndex": true, "name": "filterSortIndex_1" }] }', true); SELECT COUNT(*) FROM ( SELECT documentdb_api.insert_one('comp_db', 'index_orderby_selection', FORMAT('{ "_id": %s, "filter1": "filter1-%s", "filter2": "filter2-%s", "filter3": %s, "orderKey": %s, "otherPath": "somePath-%s" }', i, i % 10, i, i % 100, i, i)::bson) FROM generate_series(1, 10000) i) j; set documentdb.enableIndexOrderbyPushdown to on; reset enable_sort; -- this has all the paths matching. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": "filter2-55", "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); -- this one can't push the order by but should prefer the filter. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": { "$gte": "filter2-55" }, "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); SELECT documentdb_api.coll_mod('comp_db', 'index_orderby_selection', '{ "collMod": "index_orderby_selection", "index": { "name": "filterSortIndex_1", "hidden": true }}'); -- now it picks the sort index EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT * FROM bson_aggregation_find('comp_db', '{ "find": "index_orderby_selection", "filter": { "filter1": "filter1-5", "filter2": { "$gte": "filter2-55" }, "filter3": { "$gt": 50 } }, "sort": { "orderKey": 1 }, "limit": 10 }'); bson_composite_prefer_ordered_tests.sql000066400000000000000000000225261507310017400370350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 685000; SET documentdb.next_collection_id TO 68500; SET documentdb.next_collection_index_id TO 68500; set documentdb.enableExtendedExplainPlans to on; set documentdb.enableIndexOrderbyPushdown to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; SELECT documentdb_api.drop_collection('comp_db2', 'query_ordered_pref') IS NOT NULL; SELECT documentdb_api.create_collection('comp_db2', 'query_ordered_pref'); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "query_ordered_pref", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_1" }] }', true); \d documentdb_data.documents_68501 SELECT COUNT(documentdb_api.insert_one('comp_db2', 'query_ordered_pref', FORMAT('{ "_id": %s, "a": %s }', i, i)::bson)) FROM generate_series(1, 10000) AS i; ANALYZE documentdb_data.documents_68501; set enable_bitmapscan to off; set documentdb.forceDisableSeqScan to on; set documentdb_rum.preferOrderedIndexScan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50 } }, "projection": { "_id": 1 }, "limit": 5 }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50, "$lt": 900 } }, "projection": { "_id": 1 }, "limit": 5 }'); set documentdb_rum.preferOrderedIndexScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50 } }, "projection": { "_id": 1 }, "limit": 5 }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "query_ordered_pref", "filter": { "a": { "$gt": 50, "$lt": 900 } }, "projection": { "_id": 1 }, "limit": 5 }'); -- test ordered scan in the presence of deletes set documentdb.enableExtendedExplainPlans to off; reset documentdb.forceDisableSeqScan; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "ordered_delete", "indexes": [ { "key": { "a": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }'); SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": %s }', i, i % 50)::bson)) FROM generate_series(1, 100) i; ANALYZE documentdb_data.documents_68502; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); -- now delete everthing reset documentdb.forceDisableSeqScan; DELETE FROM documentdb_data.documents_68502; -- vacuum the table VACUUM documentdb_data.documents_68502; -- query the data set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); -- now try with a posting tree at the end. reset documentdb.forceDisableSeqScan; CALL documentdb_api.drop_indexes('comp_db2', '{ "dropIndexes": "ordered_delete", "index": "a_1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "ordered_delete", "indexes": [ { "key": { "a": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 1 }', i)::bson)) FROM generate_series(1, 5000) i; SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 2 }', i)::bson)) FROM generate_series(10001, 15000) i; SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 3 }', i)::bson)) FROM generate_series(20001, 25000) i; SELECT COUNT(documentdb_api.insert_one('comp_db2', 'ordered_delete', FORMAT('{ "_id": %s, "a": 4 }', i)::bson)) FROM generate_series(30001, 35000) i; ANALYZE documentdb_data.documents_68502; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lte": 4 } } }'); -- delete the first half of TIDs from some of the posting trees DELETE FROM documentdb_data.documents_68502 WHERE object_id >= '{ "": 10001 }' AND object_id < '{ "": 12000 }'; DELETE FROM documentdb_data.documents_68502 WHERE object_id >= '{ "": 20001 }' AND object_id < '{ "": 22500 }'; VACUUM documentdb_data.documents_68502; reset documentdb.forceDisableSeqScan; set enable_indexscan to off; set enable_bitmapscan to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lte": 4 } } }'); SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); reset enable_indexscan; reset enable_bitmapscan; set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE OFF, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); SELECT document FROM bson_aggregation_pipeline('comp_db2', '{ "aggregate": "ordered_delete", "pipeline": [ { "$match": { "a": { "$lte": 4 } } }, { "$group": { "_id": "$a", "c": { "$count": 1 } }} ] }'); -- now delete everthing reset documentdb.forceDisableSeqScan; DELETE FROM documentdb_data.documents_68502; -- vacuum the table VACUUM documentdb_data.documents_68502; -- query the data set documentdb.forceDisableSeqScan to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "ordered_delete", "filter": { "a": { "$lt": 4 } } }'); -- test scan skipping behavior. reset documentdb.forceDisableSeqScan; SELECT COUNT(documentdb_api.insert_one('comp_db2', 'skip_entry_asc', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s }', ((i * 100) + (j * 10) + k), i, j, k)::bson)) FROM generate_series(1, 5) i, generate_series(1, 10) j, generate_series(1, 100) k; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "skip_entry_asc", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); SELECT COUNT(documentdb_api.insert_one('comp_db2', 'skip_entry_desc', FORMAT('{ "_id": %s, "a": %s, "b": %s, "c": %s }', ((i * 100) + (j * 10) + k), i, j, k)::bson)) FROM generate_series(1, 5) i, generate_series(1, 10) j, generate_series(1, 100) k; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_db2', '{ "createIndexes": "skip_entry_desc", "indexes": [ { "key": { "a": -1, "b": -1, "c": -1 }, "name": "a_1", "enableOrderedIndex": true } ] }', TRUE); ANALYZE documentdb_data.documents_68503; -- now test the behavior of partial skipping set documentdb.forceDisableSeqScan to on; set documentdb.enableExtendedExplainPlans to on; set documentdb_rum.enableSkipIntermediateEntry to off; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_desc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$in": [ 2, 3 ] }, "c": { "$gte": 3, "$lte": 5 } } }'); -- with skip entries on we skip relevant portions of the tree set documentdb_rum.enableSkipIntermediateEntry to on; EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_desc", "filter": { "a": { "$gte": 2, "$lte": 4 }, "c": { "$gte": 3, "$lte": 5 } } }'); EXPLAIN (ANALYZE ON, COSTS OFF, VERBOSE ON, BUFFERS OFF, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_db2', '{ "find": "skip_entry_asc", "filter": { "a": { "$in": [ 2, 3 ] }, "c": { "$gte": 3, "$lte": 5 } } }');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_decimal128.sql000066400000000000000000000457441507310017400324610ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 176000; SET documentdb.next_collection_id TO 17600; SET documentdb.next_collection_index_id TO 17600; SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1.0" },"_id":1,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1" },"_id":2,"b":2}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-1.0" },"_id":3,"b":3}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "NaN" },"_id":4,"b":4}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-NaN" },"_id":5,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "Infinity" },"_id":6,"b":6}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "-Infinity" },"_id":7,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "2234567832345678423.28293013835682" },"_id":8,"b":8}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "141592653.950332e2013" },"_id":9,"b":9}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "0" },"_id":10,"b":10}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberLong": "1" },"_id":11,"b":11}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberLong": "-1" },"_id":12,"b":12}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberInt": "1" },"_id":13,"b":13}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberInt": "-1" },"_id":14,"b":14}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "-1.00" },"_id":15,"b":15}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "1.00" },"_id":16,"b":16}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": [{ "$numberDecimal": "1.00" }, { "$numberDecimal": "2.00" }, { "$numberDecimal": "3.50" }, { "$numberDecimal": "5.00001" }],"_id":17,"b":17}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "NaN" },"_id":18,"b":15}'); -- Basic find queries SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "Inf"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-Inf"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "NaN"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-NaN"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "1"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "1.0000000"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-1"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "-1.00000"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @= '{ "a": {"$numberDecimal": "2234567832345678423.28293013835682"} }'; --find with order by SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') ORDER BY bson_orderby(document, '{ "a": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') ORDER BY bson_orderby(document, '{ "a": -1 }') DESC; -- comparision operations SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @<= '{ "a": {"$numberDecimal": "Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "-Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @>= '{ "a": {"$numberDecimal": "-Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "-Infinity"} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : 2} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "5.00001"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "5.00001"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "5.02"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "5.00001"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$in" : [{"$numberDecimal": "5.00001"}, {"$numberDecimal": "inf"}] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$ne" : {"$numberDecimal": "5.00001"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$nin" : [{"$numberDecimal": "-1"}, {"$numberDecimal": "inf"}, {"$numberDecimal": "-inf"}]} }'; -- logical find queries SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-Infinity"}}}, {"a" : {"$lt" : { "$numberDecimal" : "Infinity"}}}] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$or": [{ "a": {"$gt": { "$numberDecimal" : "5"}}}, {"a" : {"$lt" : { "$numberDecimal" : "-5"}}}] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$nor": [{ "a": {"$gt": { "$numberDecimal" : "5"}}}, {"a" : {"$lt" : { "$numberDecimal" : "-5"}}}] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": { "$not": {"$gt": { "$numberDecimal" : "-5"} } } }'; -- query element operator SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$exists": true, "$gt": { "$numberDecimal" : "5"} } }'; -- array query operators SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$all": [{ "$numberDecimal": "1.00" }, { "$numberDecimal": "2.00" }, { "$numberDecimal": "3.50" }, { "$numberDecimal": "5.00001" }] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$elemMatch": { "$gt": {"$numberDecimal": "3"}, "$lt": {"$numberDecimal": "5.2"}} } }'; -- Update operations with $mul and $inc BEGIN; SELECT documentdb_api.update('db', '{"update": "decimal128", "updates":[{"q": {"a": -1},"u":{"$mul":{"a": {"$numberDecimal": "11.1"}}},"multi":true}]}'); SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gte": { "$numberDecimal" : "-11.1"}}}, {"a" : {"$lte" : { "$numberDecimal" : "11.1"}}}] }'; ROLLBACK; BEGIN; SELECT documentdb_api.update('db', '{"update": "decimal128", "updates":[{"q": {"a": 1},"u":{"$inc":{"a": {"$numberDecimal": "50.012e2"}}},"multi":true}]}'); SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gte": {"$numberInt": "5000"}}}, {"a" : {"$lte" : {"$numberInt": "5003"}}}] }'; ROLLBACK; -- Overflow operation with decimal128 SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "9.999999999999999999999999999999999e6144"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-9.999999999999999999999999999999999e6144"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "9.999999999999999999999999999999999e6144"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "1.111111111111111111111111111111111e6144"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-9.999999999999999999999999999999999e6144"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "-1.111111111111111111111111111111111e6144"} } } }', '{}'); -- Testing index on decimal 128 values -- BUG: Without this queries always seem to prefer the primary key index. SELECT documentdb_distributed_test_helpers.drop_primary_key('db','decimal128'); -- Creating an index on the 'a' which is d128 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('decimal128', 'd128_path_a', '{"a": 1}'), true); BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- EXPLAIN QUERIES EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @<= '{ "a": {"$numberDecimal": "Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @> '{ "a": {"$numberDecimal": "-Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @>= '{ "a": {"$numberDecimal": "-Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @< '{ "a": {"$numberDecimal": "-Infinity"} }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-Infinity"}}}, {"a" : {"$lt" : { "$numberDecimal" : "Infinity"}}}] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "$and": [{ "a": {"$gt": { "$numberDecimal" : "-2"}}}, {"a" : {"$lt" : { "$numberDecimal" : "2"}}}] }'; ROLLBACK; -- Testing cases where decimal128 operations will signal exception with intel math lib and validating if these matches protocol defined behavior -- Testing to decimal128 conversion methods using $mul, because $convert is not implemented yet (decimal128 to other types can't be tested now) -- TODO Add proper test after implementing $convert SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "-2147483648"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "-9223372036854775808"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); -- normal & inexact double conversion SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "-9.99000000000000000e+02"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "9.535874331e+301"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "1"} } } }', '{}'); -- Inexact result SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+6794057649266099302E-6176"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+4548926796094754899573057849605421E+2026"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+6794057649266099302E-6176"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "+4548926796094754899573057849605421E+2026"} } } }', '{}'); -- Overflow signal with inexact SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+9579756848909076089047118570486504E+6111"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+1938648456739575048278564590634903E+6111"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "+9579756848909076089047118570486504E+6111"} } }', '{ "": { "$inc": { "a.b": {"$numberDecimal": "+1938648456739575048278564590634903E+6111"} } } }', '{}'); -- Underflow signal with inexact (no test case found for $inc) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "-7548269564658974956438658719038456E-6120"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "+9875467895987245907845734785643106E-2179"} } } }', '{}'); -- Invalid exceptions are skipped because no valid test cases found (this is generally signalled if "SNaN" is part of operation which is not valid Decimal128 value to store) -- TEST for double and decimal128 ordering SELECT documentdb_api.delete('db', '{"delete":"decimal128", "deletes":[{"q":{},"limit":0}]}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "0.3" },"_id":1,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "0.3" },"_id":2,"b":2}'); SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDouble": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDouble": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDouble": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDouble": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDouble": "0.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDecimal": "0.3"}} }'; SELECT documentdb_api.delete('db', '{"delete":"decimal128", "deletes":[{"q":{},"limit":0}]}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDouble": "1.3" },"_id":3,"b":3}'); SELECT 1 FROM documentdb_api.insert_one('db', 'decimal128', '{"a": { "$numberDecimal": "1.3" },"_id":4,"b":4}'); SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDecimal": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDecimal": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDecimal": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDecimal": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lt" : {"$numberDouble": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gt" : {"$numberDouble": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$gte" : {"$numberDouble": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$lte" : {"$numberDouble": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDouble": "1.3"}} }'; SELECT object_id, document FROM documentdb_api.collection('db', 'decimal128') WHERE document @@ '{ "a": {"$eq" : {"$numberDecimal": "1.3"}} }';documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_deduplicate.sql000066400000000000000000000022251507310017400330760ustar00rootroot00000000000000 SET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 4600000; SET documentdb.next_collection_id TO 4600; SET documentdb.next_collection_index_id TO 4600; SELECT documentdb_api_internal.bson_deduplicate_fields(null); SELECT documentdb_api_internal.bson_deduplicate_fields('{}') = '{}'; SELECT documentdb_api_internal.bson_deduplicate_fields('{"a":1, "a": 1}') = '{"a":1}'; SELECT documentdb_api_internal.bson_deduplicate_fields('{"a":1, "a": 1}') = '{"a":1}'; SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "b": [{"c": 1, "c": 2}, {"c": {"e": 1, "z": [], "e": 2}}], "a": null}') = '{"a": null, "b" : [{"c": 2}, {"c": {"e": 2, "z": []}}]}'; SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "b": [{"c": 1, "c": [1, 1, "text", {"d": 1, "d": 2}]}, {"c": {"e": 1, "e": 2}}], "a": 2}') = '{"a": 2, "b": [{"c": [1, 1, "text", {"d": 2}]}, {"c": {"e": 2}}]}'; SELECT documentdb_api_internal.bson_deduplicate_fields('{"a": 1, "a.b": 2, "a.b.c": "text"}') = '{"a": 1, "a.b": 2, "a.b.c": "text"}'; bson_dollar_operators_negation_tests_core.sql000066400000000000000000000054061507310017400402310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 4, "a" : { "b" : null }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 5, "a" : { "b" : true }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); -- do a search SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; -- do the complement SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; -- do the NOTs SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; -- Now try $gte/$lt SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; -- $gte: Minkey (Exists doesn't factor in this) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": true } }'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$exists": false } }'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }';bson_dollar_operators_negation_tests_explain_core.sql000066400000000000000000000064661507310017400417600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 4, "a" : { "b" : null }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 5, "a" : { "b" : true }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 6, "a" : { "b" : { "$numberDouble": "Infinity" } }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 7, "a" : { "b" : { "$numberDouble": "NaN" } }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 8, "a" : { "b" : "stringb8" }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 9, "a" : { "b" : "stringb9" }}', NULL); SELECT documentdb_api.insert_one('db','simple_negation_tests_explain', '{"_id": 10, "a" : { "b" : "stringb10" }}', NULL); -- do a search EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gt": 2 }}'; -- do the complement EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lte": 2 }}'; -- do the NOTs EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gt": 2 } }}'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lte": 2 } }}'; -- Now try $gte/$lt EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$gte": 2 }}'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$lt": 2 }}'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$gte": 2 } }}'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$lt": 2 } }}'; -- $gte: Minkey (Exists doesn't factor in this) EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": true } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$exists": false } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": true } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'simple_negation_tests_explain') WHERE document @@ '{ "a.b": { "$not": { "$exists": false } } }';bson_dollar_operators_negation_tests_explain_index.sql000066400000000000000000000015461507310017400421310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 514000; SET documentdb.next_collection_id TO 5140; SET documentdb.next_collection_index_id TO 5140; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests_explain'); SELECT documentdb_api.create_collection('db', 'simple_negation_tests_explain'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "simple_negation_tests_explain", "indexes": [{ "key": { "$**": 1 }, "name": "myIdx1" }] }'::documentdb_core.bson, true); BEGIN; SET local search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_explain_core.sql ROLLBACK;bson_dollar_operators_negation_tests_explain_runtime.sql000066400000000000000000000012451507310017400425010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 513000; SET documentdb.next_collection_id TO 5130; SET documentdb.next_collection_index_id TO 5130; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests_explain'); SELECT documentdb_api.create_collection('db', 'simple_negation_tests_explain'); BEGIN; SET local search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; \o /dev/null \o set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_explain_core.sql ROLLBACK;bson_dollar_operators_negation_tests_index.sql000066400000000000000000000017671507310017400404160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 512000; SET documentdb.next_collection_id TO 5120; SET documentdb.next_collection_index_id TO 5120; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests') IS NULL; SELECT documentdb_api.create_collection('db', 'simple_negation_tests') IS NULL; \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "simple_negation_tests", "indexes": [{ "key": { "$**": 1 }, "name": "myIdx1" }] }', TRUE); \o BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql ROLLBACK; SELECT documentdb_api.shard_collection('db', 'simple_negation_tests', '{ "_id": "hashed" }', false); BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql ROLLBACK;bson_dollar_operators_negation_tests_runtime.sql000066400000000000000000000015031507310017400407560ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 512000; SET documentdb.next_collection_id TO 5120; SET documentdb.next_collection_index_id TO 5120; SET client_min_messages=WARNING; SELECT documentdb_api.drop_collection('db', 'simple_negation_tests') IS NULL; SELECT documentdb_api.create_collection('db', 'simple_negation_tests') IS NULL; \o /dev/null \o BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql ROLLBACK; SELECT documentdb_api.shard_collection('db', 'simple_negation_tests', '{ "_id": "hashed" }', false); BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_operators_negation_tests_core.sql ROLLBACK;bson_dollar_ops_basic_compare_tests_core.sql000066400000000000000000000506121507310017400377760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 5, "a" : { "b" : true }}', NULL); /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 6, "a" : 1}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 7, "a" : true}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 8, "a" : [0, 1, 2]}', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 9, "a" : { "c": 1 }}', NULL); /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": true }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": "c" }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": true }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": "c" }'; /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b.1": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b.1": 1 }'; /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : 1 } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : 1 } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ 0, 1, 2 ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a" : 1 }'; /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 0, 1] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": [true, false] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 0, 1] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": [true, false] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 0, 1] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": [true, false] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 0, 1] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": [true, false] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 2 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 3 }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 0, 1] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [0, 1, 2] }'; SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": [true, false] }'; SELECT documentdb_api.insert_one('db','querydollartest', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c" : { "d" : [ [ -1, 1, 2 ] ] } }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0" : { "d" : [ [ -1, 1, 2 ] ] } }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ [ -1, 1, 2 ] ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : [ -1, 1, 2 ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : [ -1, 1, 2 ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.0" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.1" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ [ -1, 1, 2 ] ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : [ -1, 1, 2 ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : [ -1, 1, 2 ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.0" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.1" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0.2" : 2 }'; -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.1" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.2" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.0.d.0.2" : [ 2 ] }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : -1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.0" : 2 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.1" : 1 }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @= '{ "c.d.2" : 2 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 1 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a": 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 1 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b" : 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 1 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.0": 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 1}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "a.b.0": 0}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 1}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.0.d": 0}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 1}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @? '{ "c.d.0": 0}'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "string" }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": "int" }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": 16 }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ "int", "string" ] }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a.b": [ 16, "string" ] }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": "array" }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @# '{ "a": [ "array", "object" ] }'; SELECT COUNT(*) FROM documentdb_api.collection('db','querydollartest') WHERE document @@ '{ "a": { "$type": "number" } }'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; SELECT object_id, document FROM documentdb_api.collection('db','querydollartest') WHERE document @!*= '{ "a.b": [ 1, "c", [0, 1, 2] ]}'; -- Test double type ordering (see nan.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 16, "e" : {"$numberDouble": "-Infinity" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 17, "e" : {"$numberDouble": "-3" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 18, "e" : {"$numberDouble": "0" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 19, "e" : {"$numberDouble": "3" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 20, "e" : {"$numberDouble": "Infinity" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 21, "e" : {"$numberDouble": "NaN" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 22, "e" : {"$numberDouble": "-NaN" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 23, "e" : null }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 24, "e" : [] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 25, "e" : { "c": 1 } }', NULL); SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$numberDouble": "NaN" } }'; SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lt" : { "$numberDouble": "NaN" } } }'; SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$lte" : { "$numberDouble": "NaN" } } }'; SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gt" : { "$numberDouble": "NaN" } } }'; SELECT document -> 'e' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "e": { "$gte" : { "$numberDouble": "NaN" } } }'; -- Test for nulls (null.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 26, "f" : 1 }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 27, "f" : null }', NULL); SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": null, "_id": { "$gte": 26 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "f": { "$ne" : null }, "_id": { "$gte": 26 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$eq" : null }, "_id": { "$gte": 26 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "g": { "$ne" : null }, "_id": { "$gte": 26 } }'; -- Test for nulls (null2.js) SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 28, "h" : [ { "b": 5 }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 29, "h" : [ { }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 30, "h" : [ ] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 31, "h" : [{}, { "b": 5 } ] }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 32, "h" : [5, { "b": 5 } ] }', NULL); SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": null, "_id": { "$gte": 28 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$in" : [ null ] }, "_id": { "$gte": 28 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$ne": null }, "_id": { "$gte": 28 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "h.b": { "$nin" : [ null ] }, "_id": { "$gte": 28 } }'; SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 33, "j" : { "$numberInt" : "1" } }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 34 }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 35, "j" : null }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 36, "j" : { "k" : { "$numberInt" : "1" }} }', NULL); SELECT documentdb_api.insert_one('db','querydollartest', '{ "_id": 37, "j" : { "k" : { "$numberInt" : "2" }} }', NULL); SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "j.k": null }' AND document @>= '{ "_id": 33 }'; -- Test for nulls/undefined SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 38, "l": null }'); SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 39, "l": {"$undefined": true} }'); SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 40 }'); SELECT documentdb_api.insert_one('db', 'querydollartest', '{ "_id": 41, "l": 1 }'); SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": null, "_id": { "$gte": 38 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$in": [ null, 5 ] }, "_id": { "$gte": 38 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$all": [ null ] }, "_id": { "$gte": 38 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$ne": null }, "_id": { "$gte": 38 } }'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartest') WHERE document @@ '{ "l": { "$nin": [ null, 5 ] }, "_id": { "$gte": 38 } }';bson_dollar_ops_basic_compare_tests_errors.sql000066400000000000000000000044361507310017400403650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql /* Insert with a.b being an object with various types*/ set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 390000; SET documentdb.next_collection_id TO 3900; SET documentdb.next_collection_index_id TO 3900; SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 5, "a" : { "b" : true }}', NULL); /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 6, "a" : 1}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 7, "a" : true}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 8, "a" : [0, 1, 2]}', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 9, "a" : { "c": 1 }}', NULL); /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); SELECT documentdb_api.insert_one('db','querydollartesterrors', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); -- Negative test for $in/$nin SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartesterrors') WHERE document @@ '{ "h.b": { "$in" : [{"$elemMatch": {"b": 1}}] }}'; SELECT document-> '_id' FROM documentdb_api.collection('db', 'querydollartesterrors') WHERE document @@ '{ "h.b": { "$nin" : [{"$elemMatch": {"b": 1}}] }}';bson_dollar_ops_basic_compare_tests_explain_core.sql000066400000000000000000000116311507310017400415140ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql /* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ 1, 2, true ]}'::bson; /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @> '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @>= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @< '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @<= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": 1 } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": { "b": [ true, false ] } }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!= '{ "a": [ { "b": [ 2, 3, 4 ] } ] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @!*= '{ "a.b": [ { "b": [ 2, 3, 4 ] }, 2, true ]}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 1 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @? '{ "a.b": 0 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [1] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [0, 1] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [[0]] }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'querydollartest') WHERE document @&= '{ "a.b": [] }'; bson_dollar_ops_basic_compare_tests_explain_index.sql000066400000000000000000000020111507310017400416630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; SELECT documentdb_api.drop_collection('db', 'querydollartest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'querydollartest'); SET client_min_messages=WARNING; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('querydollartest', 'index_2', '{"$**": 1}'), TRUE); BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql ROLLBACK; bson_dollar_ops_basic_compare_tests_explain_index_no_bitmap.sql000066400000000000000000000023031507310017400437170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; SELECT documentdb_api.drop_collection('db', 'querydollartest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'querydollartest'); SET client_min_messages=WARNING; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('querydollartest', 'index_2', '{"$**": 1}'), TRUE); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'querydollartest'); BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; set local enable_bitmapscan to off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql ROLLBACK; bson_dollar_ops_basic_compare_tests_explain_runtime.sql000066400000000000000000000007401507310017400422460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 52000; SET documentdb.next_collection_id TO 5200; SET documentdb.next_collection_index_id TO 5200; SELECT documentdb_api.drop_collection('db', 'querydollartest'); SELECT documentdb_api.create_collection('db', 'querydollartest'); SET client_min_messages=WARNING; -- avoid plans that use primary key index \i sql/bson_dollar_ops_basic_compare_tests_explain_core.sql bson_dollar_ops_basic_compare_tests_index.sql000066400000000000000000000005601507310017400401520ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql ROLLBACK;bson_dollar_ops_basic_compare_tests_index_backcompat.sql000066400000000000000000000006511507310017400423370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql ROLLBACK;bson_dollar_ops_basic_compare_tests_index_no_bitmap.sql000066400000000000000000000006241507310017400422030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql ROLLBACK;bson_dollar_ops_basic_compare_tests_runtime.sql000066400000000000000000000004711507310017400405270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 510000; SET documentdb.next_collection_id TO 5100; SET documentdb.next_collection_index_id TO 5100; BEGIN; set local enable_seqscan = on; \i sql/bson_dollar_ops_basic_compare_tests_core.sql ROLLBACK;bson_dollar_ops_basic_text_ops_tests_core.sql000066400000000000000000000025671507310017400402230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 1, "address" : "sfo0001", "comment" : "This is a dentist clinic"}', NULL); SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 2, "address" : "sfo0010", "comment" : "Here you can get\nthe most delicious food\nin the world"}', NULL); SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 3, "address" : "Sfo0010", "comment" : "[dupe] Here you can get\nthe most delicious food\nin the world"}', NULL); SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 4, "address" : "la0001", "comment" : "I never been here"}', NULL); SELECT documentdb_api.insert_one('db','queryregexopstest', '{"_id": 5, "address" : "la7777", "comment" : "The dog in the yard\nalways barks at me" }', NULL); /* now query regex */ /* db.queryregexopstest.find( { address: { $regex: /0001$/ } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "0001$" }'; /* TODO: passing options: db.queryregexopstest.find( { address: { $regex: /^SFO/i } } ) */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "address": "^sfo" }'; /* Match multiple spaces */ SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "comment": "\\s\\s+" }'; bson_dollar_ops_basic_text_ops_tests_explain_core.sql000066400000000000000000000002461507310017400417330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/* validate explain */ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','queryregexopstest') WHERE document @~ '{ "a.b": "^.+$" }'; bson_dollar_ops_basic_text_ops_tests_explain_index.sql000066400000000000000000000026361507310017400421170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1500000; SET documentdb.next_collection_id TO 1500; SET documentdb.next_collection_index_id TO 1500; SELECT documentdb_api.drop_collection('db', 'queryregexopstest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryregexopstest'); -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api_internal.create_indexes_non_concurrently. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('queryregexopstest', 'index_2', '{"$**": 1}'), TRUE); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','queryregexopstest'); SELECT documentdb_api.drop_collection('db', 'querytextopstest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'querytextopstest'); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','querytextopstest'); BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan = off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_basic_text_ops_tests_explain_core.sql END; bson_dollar_ops_basic_text_ops_tests_explain_runtime.sql000066400000000000000000000006341507310017400424670ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 1400000; SET documentdb.next_collection_id TO 1400; SET documentdb.next_collection_index_id TO 1400; SELECT documentdb_api.create_collection('db', 'queryregexopstest'); SELECT documentdb_api.create_collection('db', 'querytextopstest'); \i sql/bson_dollar_ops_basic_text_ops_tests_explain_core.sql bson_dollar_ops_basic_text_ops_tests_index.sql000066400000000000000000000004721507310017400403730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 450000; SET documentdb.next_collection_id TO 4500; SET documentdb.next_collection_index_id TO 4500; BEGIN; set local enable_seqscan = off; \i sql/bson_dollar_ops_basic_text_ops_tests_core.sql ROLLBACK;bson_dollar_ops_basic_text_ops_tests_runtime.sql000066400000000000000000000004711507310017400407460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 450000; SET documentdb.next_collection_id TO 4500; SET documentdb.next_collection_index_id TO 4500; BEGIN; set local enable_seqscan = on; \i sql/bson_dollar_ops_basic_text_ops_tests_core.sql ROLLBACK;bson_dollar_ops_collation_tests_runtime.sql000066400000000000000000003462171507310017400377370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7990000; SET documentdb.next_collection_id TO 7990; SET documentdb.next_collection_index_id TO 7990; -- (1) insert some docs SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 1, "a": "Cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 2, "a": "dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 3, "a": "cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 4, "a": "Dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 5, "a": "caT" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 6, "a": "doG" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 7, "a": "goat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 8, "a": "Goat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 9, "b": "Cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 10, "b": "dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 11, "b": "cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 12, "b": "Dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 13, "b": "caT", "a" : "raBbIt" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 14, "b": "doG" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 15, "b": "goat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 16, "b": "Goat" }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 17, "a": ["Cat", "CAT", "dog"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 18, "a": ["dog", "cat", "CAT"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 19, "a": ["cat", "rabbit", "bAt"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 20, "a": ["Cat"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 21, "a": ["dog"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 22, "a": ["cat"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 23, "a": ["CAT"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 24, "a": ["cAt"] }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 25, "a": { "b" : "cAt"} }'); SELECT documentdb_api.insert_one('db', 'ci_search', '{ "_id": 26, "a": [{ "b": "CAT"}] }'); SET documentdb_core.enableCollation TO off; -- With collation off and colation string in find and aggregate commands should not throw an error SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "a": { "$eq": "cat" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SET documentdb_core.enableCollation TO on; -- (2) Find query unsharded collection SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 10, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$all": ["cAt", "DOG"] } }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength": 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 5} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); -- range query without index on path "a" SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$gt": "CAT" }, "a" : {"$lt" : "RABBIT"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$gt": "CAT" }, "a" : {"$lt" : "RABBIT"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); -- (3) Shard collection SELECT documentdb_api.shard_collection('db', 'ci_search', '{ "_id": "hashed" }', false); -- (4) Find query sharded collection BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "b": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; -- elemMatch with collation BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$eq": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$gt": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$lt": "cAt"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a": { "$elemMatch": {"$eq": "cAt", "gte" : "BAT"} } }, "skip": 0, "limit": 7, "collation": { "locale": "en", "strength" : 1} }'); END; -- (5) Aggregation queries sharded collection BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "a": { "$eq": "cat" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$gt": "DOG" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$eq": "RABBIT" } } }, { "$project": { "b": 1 } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "_id": { "$gt": 1 } } }, { "$project": { "b": 1, "c": "$a", "_id": 0 } }, { "$match": { "c": { "$eq": "rAbBiT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$unwind": "$a" }, {"$match": { "a": { "$gt": "POP", "$lt": "TOP" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$match": { "a": { "$gte": "hobbit" } } }, { "$unwind": "$a" } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$addFields": { "x": "mANgO" } }, { "$addFields": { "Y": "TANGO" } }, { "$match": { "$and" : [{ "a": { "$gte": "POMELO" }}, { "x": { "$eq": "MANGO" }}]}} ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$addFields": { "e": { "f": "$a" } } }, { "$replaceRoot": { "newRoot": "$e" } }, { "$match" : { "f": { "$elemMatch": {"$eq": "cAt"} } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 5} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : ["cat", "DOG" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search", "filter": { "a" : {"$in" : [[{ "b" : "caT"}], [{ "c" : "caT"}]] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 100, "collation": { "locale": "en", "strength" : 1} }'); END; -- (6) currently unsupported scenarions: -- unsupported: $bucket SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$bucket": { "groupBy": "$price", "boundaries": [0, 10, 20, 30], "default": "Other", "output": { "categoryMatch": { "$sum": { "$cond": [ { "$eq": ["$a", "PETS"] }, 1, 0 ] } } } } } ], "collation": { "locale": "en", "strength": 1 } }'); -- unsupported: $geoNear SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$geoNear": { "near": { "type": "Point", "coordinates": [ 0 , 10 ] }, "distanceField": "dist.calculated", "maxDistance": 2, "query": { "a": "cAT" } } } ], "collation": { "locale": "en", "strength": 1 } }'); -- unsupported: $fill SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$fill": { "sortBy": { "timestamp": 1 }, "partitionBy": "$status", "output": { "$cond": { "if": { "$eq": ["$a", "cAt"] }, "then": { "type": "feline" }, "else": { "type": "other" } } } } } ], "collation": { "locale": "en", "strength": 1 } }'); -- unsupported: $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$group": { "_id": "$a", "set": { "$addToSet": "$a" } }} ], "collation": { "locale": "en", "strength": 1 } }'); -- unsupported: $setWindowFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$setWindowFields": { "sortBy": { "_id": 1 }, "output": { "total": { "$eq": ["$a", "cAt"] } } }} ], "collation": { "locale": "en", "strength": 1 } }'); -- unsupported: $sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sortByCount": { "input": "$a", "as": "a", "by": { "$cond": { "if": { "$eq": [ "$a", "caT" ] }, "then": [{"x": 30}] , "else": [{"x": 30}] }} }} ], "collation": { "locale": "en", "strength": 1 } }'); -- (6.B) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search", "pipeline": [ { "$sort": { "_id": 1 } }, { "$addFields": { "e": { "f": "$a" } } }, { "$replaceRoot": { "newRoot": "$e" } }, { "$match" : { "f": { "$elemMatch": {"$eq": "cAt"} } } }, {"$project": { "items" : { "$filter" : { "input" : "$f", "as" : "animal", "cond" : { "$eq" : ["$$animal", "CAT"] } }} }} ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- (7) Insert More docs SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 1, "a": "Cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 2, "a": "dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 3, "a": "cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 4, "a": "CaT" }'); SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 5, "b": "Dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search2', '{ "_id": 6, "b": "DoG" }'); -- (8) Query results with different collations SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "a": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3, "caseLevel": true, "caseFirst": "off", "numericOrdering": true } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1.93 } }'); -- (8) a. collation has no effect on $regex SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "a": { "$regex": "^c", "$options": "" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1 } }'); -- (9) Error message Tests SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "none"} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en_DB", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "shifted"} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 0, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : -1, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 6, "caseLevel": true, "caseFirst": "bad", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "abcd", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "fr_FR", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper", "numericOrdering": true, "alternate": "shifted", "backwards" : "0"} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true, "alternate": "non-ignorable", "backwards" : true, "normalization" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true, "alternate": "non-ignorable", "backwards" : true, "normalization" : true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 0.9 } }'); -- (10) collation variations SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "fr", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "de", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "bn", "strength" : 1, "caseLevel": false, "caseFirst": "lower", "numericOrdering": true} }'); -- collation with sort/order by SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CaT", "a": "cat", "b": "CaT"}'); SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CAt", "a": "cat", "b": "CAt"}'); SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "CAT", "a": "cat", "b": "CAT"}'); SELECT documentdb_api.insert_one('db', 'coll_order_tests0', '{"_id": "cAT", "a": "cat", "b": "cAT"}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); -- collation with sort/order by with collation-aware _id SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$lte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "upper" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests0", "filter": { "a": {"$gte": "cat"} }, "sort": { "_id": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1, "caseLevel": true, "caseFirst": "lower" } }'); -- collation with sort/order by: numericOrdering is respected SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 1, "a": "cat", "b": "10"}'); SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 2, "a": "cat", "b": "2"}'); SELECT documentdb_api.insert_one('db', 'coll_order_tests1', '{"_id": 3, "a": "cat", "b": "3"}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : false } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : true } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : false } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_order_tests1", "filter": { "a": "cat" }, "sort": { "b": -1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "numericOrdering" : true } }'); -- collation with sort/order by: setWindowFields SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "coll_order_tests1", "pipeline": [{"$setWindowFields": { "sortBy": {"b": -1}, "output": {"res": { "$push": "$b", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "collation": { "locale": "en", "numericOrdering" : false } }'); SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "coll_order_tests1", "pipeline": [{"$setWindowFields": { "sortBy": {"b": -1}, "output": {"res": { "$push": "$b", "window": {"documents": ["unbounded", "unbounded"]}}}}}], "collation": { "locale": "en", "numericOrdering" : true } }'); -- (11) Unsupported scenarios SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "ci_search2", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "collation" : {"locale" : "en", "strength": 1} }'); SELECT documentdb_api.update('update', '{"update":"ci_search2", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "collation" : {"locale" : "en", "strength": 1}, "arrayFilters": [ { "a": 2 } ]}]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ci_search2", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true, "collation" : {"locale" : "en", "strength": 1}}]}', TRUE); -- (12) Test Id filters respect collation SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "Cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "cat" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "CaT" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "Dog" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": "DoG" }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": { "a" : "cat" } }'); SELECT documentdb_api.insert_one('db', 'ci_search3',' { "_id": { "a": "CAT"} }'); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "a": { "a": "Dog" } } '); SELECT documentdb_api.insert_one('db', 'ci_search3', '{ "_id": [ "cat", "CAT "] }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT documentdb_api.shard_collection('db', 'ci_search', '{ "_id": "hashed" }', false); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id": { "$eq": "cat" } }, { "_id": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search3", "filter": { "$or" : [{ "_id.a": { "$eq": "cat" } }, { "_id.a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); -- (12) Check index with partial filter expression with collation SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 1, "a" : { "b" : "DOG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 2, "a" : { "b" : "dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 3, "a" : { "b" : "Cat" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 4, "a" : { "b" : "Dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 5, "a" : { "b" : "cAT" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 6, "a" : { "b" : "DoG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search4', '{"_id": 7, "a" : { "b" : "DOG" }}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search4", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$eq": "dog" } }, "collation" : {"locale" : "en", "strength" : 2} } ] }', TRUE ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search4", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$eq": "dog" } } } ] }', TRUE ); BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query pushed to the index when no collattion SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } } }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } } }'); ROLLBACK; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query not pushed to the index when collattion is specified SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } }, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "a.b": { "$eq": "dog" }, "a": { "$ne" : null } }, "collation": { "locale": "en", "strength" : 1} }'); END; SELECT documentdb_api.shard_collection('db', 'ci_search4', '{ "_id": "hashed" }', false); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search4", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; -- (13) Check index behavior with collation (TODO: update when index pushdown of collation is supported) SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 1, "a" : { "b" : "DOG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 2, "a" : { "b" : "dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 3, "a" : { "b" : "Cat" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 4, "a" : { "b" : "Dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 5, "a" : { "b" : "cAT" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 6, "a" : { "b" : "DoG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search5', '{"_id": 7, "a" : { "b" : "DOG" }}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search5", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "collation" : {"locale" : "en", "strength" : 2} } ] }', TRUE ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ci_search5", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1" } ] }', TRUE ); BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query pushed to the index when no collattion SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); ROLLBACK; BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- query not pushed to the index when collation is specified SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; -- range query with index on path "a.b" SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "a.b": { "$gt": "CAT" }, "a.b" : {"$lte" : "DOG"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN(VERBOSE ON, COSTS OFF)SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "a.b": { "$gt": "CAT" }, "a.b" : {"$lte" : "DOG"} }, "collation": { "locale": "en", "strength" : 1.93 } }'); END; SELECT documentdb_api.shard_collection('db', 'ci_search5', '{ "_id": "hashed" }', false); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "ci_search5", "filter": { "$or" : [{ "a.b": { "$eq": "cat" } }, { "a.b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); END; -- nested pipleline tests SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "DOG", "a" : { "b" : "DOG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "dog", "a" : { "b" : "dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "Cat", "a" : { "b" : "Cat" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "Dog", "a" : { "b" : "Dog" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "cAT", "a" : { "b" : "cAT" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "DoG", "a" : { "b" : "DoG" }}', NULL); SELECT documentdb_api.insert_one('db','ci_search6', '{"_id": "dOg", "a" : { "b" : "dOg" }}', NULL); -- lookup with id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- lookup with id join optimized (explicitly asked to make _id join collation agnostic) BEGIN; SET LOCAL documentdb.enableLookupIdJoinOptimizationOnCollation to true; SET LOCAL documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- lookup with non-id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); -- lookup with non-id join (collation aware - explain) BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- $facet and $unionwith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$facet": { "a" : [ { "$match": { "a.b": "cat" } }, { "$count": "catCount" } ], "b" : [ { "$match": { "a.b": "dog" } }, { "$count": "dogCount" } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$unionWith": { "coll": "ci_search6", "pipeline" : [ { "$match": { "a.b": "cat" }}] } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); -- $graphLookup SELECT documentdb_api.insert_one('db','ci_search7', '{"_id": "alice", "pet" : "dog" }', NULL); SELECT documentdb_api.insert_one('db','ci_search7', '{"_id": "bob", "pet" : "cat" }', NULL); SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "DOG", "name" : "DOG" }', NULL); SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "dog", "name" : "dog" }', NULL); SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "CAT", "name" : "CAT" }', NULL); SELECT documentdb_api.insert_one('db','ci_search8', '{"_id": "cAT", "name" : "cAT" }', NULL); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); END; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$graphLookup": { "from": "ci_search6", "startWith": "$a.b", "connectFromField": "a.b", "connectToField": "a.b", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "fr", "strength" : 1, "alternate": "shifted" } }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "hi", "strength" : 2, "caseFirst": "lower" } }'); -- test $graphlookup without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "en", "strength" : 3} }'); END; --- $graphLookup on sharded collection: unsupported SELECT documentdb_api.shard_collection('db', 'ci_search7', '{ "_id": "hashed" }', false); SELECT documentdb_api.shard_collection('db', 'ci_search8', '{ "_id": "hashed" }', false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search7", "pipeline": [ { "$graphLookup": { "from": "ci_search8", "startWith": "$pet", "connectFromField": "name", "connectToField": "_id", "as": "destinations", "depthField": "depth" } } ], "collation": { "locale": "fr", "strength" : 1, "alternate": "shifted" } }'); -- unsupported $merge SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [{"$merge" : { "into": "ci_search9", "whenMatched" : "replace" }} ], "collation": { "locale": "en", "strength" : 1} }'); SELECT documentdb_api.shard_collection('db', 'ci_search6', '{ "_id": "hashed" }', false); -- lookup with id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "_id", "foreignField": "_id", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- lookup with non-id join (collation aware) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SET LOCAL documentdb_core.enablecollation TO on; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$lookup": { "from": "ci_search6", "as": "matched_docs", "localField": "a.b", "foreignField": "a.b", "pipeline": [ { "$match": { "$or" : [ { "a.b": "cat" }, { "a.b": "dog" } ] } } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); END; -- $facet and $unionwith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$facet": { "a" : [ { "$match": { "a.b": "cat" } }, { "$count": "catCount" } ], "b" : [ { "$match": { "a.b": "dog" } }, { "$count": "dogCount" } ] } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [ { "$unionWith": { "coll": "ci_search6", "pipeline" : [ { "$match": { "a.b": "cat" }}] } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); -- unsupported $merge SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "ci_search6", "pipeline": [{"$merge" : { "into": "ci_search7", "whenMatched" : "replace" }} ], "collation": { "locale": "en", "strength" : 1} }'); -- $expr SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 1, "a": "cat" }'); SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 2, "a": "dog" }'); SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 3, "a": "cAt" }'); SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": 4, "a": "dOg" }'); SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": "hen", "a": "hen" }'); SELECT documentdb_api.insert_one('db', 'coll_agg_proj', '{ "_id": "bat", "a": "bat" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "hi", "strength" : 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$ne": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fi", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$lte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr_CA", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gte": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "es@collation=search", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$gt": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$or": [{"$gte": [ "$a", "DOG" ]}, {"$gte": [ "$a", "CAT" ]}] } }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$and": [{"$lte": [ "$a", "DOG" ]}, {"$lte": [ "$a", "CAT" ]}] } }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 2 } }'); -- test $expr without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); ROLLBACK; -- en_US_POSIX uses a c-style comparison. POSIX locale ignores case insensitivity. This is the ICU semantics. SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en_US_POSIX", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en_US_POSIX", "strength" : 1 } }'); -- simple collation SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "CAT"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple"} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple"} }'); -- simple locale ignores other options SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "strength": 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "strength": 3} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "caseFirst": "upper"} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": ["$a", "cat"]} }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "simple", "caseFirst": "lower"} }'); -- support for $filter SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$eq": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$eq": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$ne": [ "$$item", "CAT" ] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$or": [{"$gte": [ "$$item", "DOG" ]}, {"$gte": [ "$$item", "CAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$a"], { "$filter": { "input": ["$a"], "as": "item", "cond": { "$and": [{"$gte": [ "$$item", "DOG" ]}, {"$gte": [ "$$item", "CAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": { "$eq": [["$_id"], { "$filter": { "input": ["$_id"], "as": "item", "cond": { "$and": [{"$gte": [ "$$item", "HEN" ]}, {"$gte": [ "$$item", "BAT" ]}] } } } ] } }, "sort": { "_id": 1 }, "collation": { "locale": "en", "strength": 1 } }'); -- support for $in SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "fr", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$a", ["CAT", "DOG"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$_id", ["HEN", "BAT"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$in": ["$_id", ["HEN", "BAT"]]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); -- support for $indexOfArray SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfArray": [ ["CAT", "DOG"], "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfArray": [ ["CAT", "DOG"], "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); -- support for $indexOfBytes (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "$a", "aT" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfBytes": [ "$a", "AT" ] }, -1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); -- support for $indexOfCP (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "cAtALoNa", "$a" ] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "$a", "at" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$indexOfCP": [ "$a", "AT" ] }, 1]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); -- support for $strcasecmp (doesn't respect collation) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 2 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "filter": { "$expr": {"$eq": [{ "$strcasecmp": ["$a", "CAT"] }, 0]} }, "sort": { "_id": 1 }, "skip": 0, "collation": { "locale": "en", "strength" : 3 } }'); -- $addFields SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); -- test $addFields auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$addFields": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); ROLLBACK; -- $set SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); -- test $set auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$set": { "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); ROLLBACK; -- project SELECT documentdb_api_internal.bson_dollar_project(document, '{ "newField": { "$eq": ["$a", "CAT"] } }', NULL, 'en-u-ks-level1') FROM documentdb_api.collection('db', 'coll_agg_proj'); SELECT documentdb_api_internal.bson_dollar_project(document, '{ "newField": { "$eq": ["$a", "DOG"] } }', NULL, 'en-u-ks-level1') FROM documentdb_api.collection('db', 'coll_agg_proj'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$lte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); -- test $project auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); ROLLBACK; -- $replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$eq": ["$a", "CAT"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$ne": ["$a", "CAT"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$lte": ["$a", "DoG"] } } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- test $replaceRoot auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); ROLLBACK; -- $replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$eq": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$ne": ["$a", "CAT"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$lte": ["$a", "DoG"] } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }'); -- test $replaceWith auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceWith": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); ROLLBACK; -- $documents SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- test $documents without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": 1, "pipeline": [ { "$documents": { "$cond": { "if": { "$eq": [ "CaT", "cAt" ] }, "then": [{"result": "case insensitive"}] , "else": [{"res": "case sensitive"}] }} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); ROLLBACK; -- $sortArray SELECT documentdb_api.insert_one('db', 'coll_sortArray', '{"_id":1,"a":"one", "b":["10","1"]}', NULL); SELECT documentdb_api.insert_one('db', 'coll_sortArray', '{"_id":2,"a":"two", "b":["2","020"]}', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sortArray", "pipeline": [ { "$project": { "sortedArray": { "$sortArray": { "input": ["cat", "dog", "DOG"], "sortBy": 1 } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sortArray", "pipeline": [ { "$project": { "sortedArray": { "$sortArray": { "input": ["cat", "dog", "DOG"], "sortBy": 1 } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sortArray", "filter": { "a": {"$lte": "two"} }, "projection": { "sortedArray": { "$sortArray": { "input": "$b", "sortBy": 1 } } }, "collation": { "locale": "en", "numericOrdering" : false }, "limit": 5 }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sortArray", "filter": { "a": {"$lte": "two"} }, "projection": { "sortedArray": { "$sortArray": { "input": "$b", "sortBy": 1 } } }, "collation": { "locale": "en", "numericOrdering" : true }, "limit": 5 }'); SELECT documentdb_api.drop_collection('db', 'coll_sortArray'); -- find SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); -- test $find auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }'); ROLLBACK; -- $redact SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 2, "level": "restricted", "content": "content 2", "details": { "level": "public", "value": "content 2.1", "moreDetails": { "level": "restricted", "info": "content 2.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 3, "level": "public", "content": "content 3", "details": { "level": "restricted", "value": "content 3.1", "moreDetails": { "level": "public", "info": "content 3.1.1" } } }', NULL); SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 4, "content": "content 4", "details": { "level": "public", "value": "content 4.1" } }', NULL); SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 5, "level": "public", "content": "content 5", "details": { "level": "public", "value": "content 5.1", "moreDetails": [{ "level": "restricted", "info": "content 5.1.1" }, { "level": "public", "info": "content 5.1.2" }] } }', NULL); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "PUBLIC"] }, "then": "$$KEEP", "else": "$$PRUNE" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$cond": { "if": { "$eq": ["$level", "puBliC"] }, "then": "$$DESCEND", "else": "$$PRUNE" } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); -- test $redact auto $$NOW generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_redact", "pipeline": [ { "$redact": { "$switch": { "branches": [ { "case": { "$eq": ["$level", "PUBLIC"] }, "then": "$$PRUNE" }, { "case": { "$eq": ["$classification", "RESTRICTED"] }, "then": { "$cond": { "if": { "$eq": ["$content", null] }, "then": "$$KEEP", "else": "$$PRUNE" } } }], "default": "$$KEEP" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; -- support for $setEquals SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setEquals": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support for $setIntersection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIntersection": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support for $setUnion SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setUnion": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support for $setDifference SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setDifference": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support for $setIsSubset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["CAT"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a"], ["DOG", "dOg"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": {"$setIsSubset": [["$a", "cAT", "dog"], ["CAT", "DOG"]]} } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support in $let SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$let": { "vars": { "var1": "$a" }, "in": { "$cond": { "if": { "$eq": ["$$var1", "CAT"] }, "then": 1, "else": 0 } } } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$let": { "vars": { "var1": "$a" }, "in": { "$cond": { "if": { "$eq": ["$$var1", "CAT"] }, "then": 1, "else": 0 } } } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- support for $zip SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$zip": { "inputs": [ {"$cond": [{"$eq": ["CAT", "$a"]}, ["$a"], ["null"]]}, ["$a"]] } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$project": { "a": 1, "newField": { "$zip": { "inputs": [ {"$cond": [{"$eq": ["CAT", "$a"]}, ["$a"], ["null"]]}, ["$a"]] } } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }'); -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; -- query match -- ignore collation (make sure all 3 GUCs are off) SET documentdb.enableLetAndCollationForQueryMatch TO off; SET documentdb.enableVariablesSupportForWriteCommands TO off; SET documentdb_core.enableCollation TO off; SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "CAT"}', NULL, 'en-u-ks-level1'); -- enforce collation SET documentdb_core.enableCollation TO on; SET documentdb.enableLetAndCollationForQueryMatch TO on; -- query match: _id tests SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-u-ks-level2'); SELECT documentdb_api_internal.bson_query_match('{"_id": "cat"}', '{"_id": "CAT"}', NULL, 'en-US-u-ks-level2'); -- query match: $eq SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{"a": "CAT"}', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$eq" : "CAT"} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$eq" : "càt"} }', NULL, 'fr-u-ks-level3'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'sv-u-ks-level1'); -- query match: $ne SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$ne" : "CAT"} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$ne" : "càt"} }', NULL, 'fr-u-ks-level3'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat", "b": "dog"}', '{"a": "CAT", "b": "DOG"}', NULL, 'sv-u-ks-level1'); -- query match: $gt/$gte SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$gt" : "CAT"} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$gte" : "CAT"} }', NULL, 'en-u-ks-level1'); -- query match: $lt/$lte SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "CAT"} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "càt"} }', NULL, 'fr-u-ks-level3'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$lte" : "càt"} }', NULL, 'fr-CA-u-ks-level3'); -- query match: $in SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$in" : ["CAT", "DOG"]} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$in" : ["càt", "dòg"]} }', NULL, 'fr-u-ks-level3'); -- query match: $nin SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$nin" : ["CAT", "DOG"]} }', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": "cat"}', '{ "a": {"$nin" : ["càt", "dòg"]} }', NULL, 'fr-u-ks-level3'); -- query match: sharded collection ALTER SYSTEM SET documentdb_core.enablecollation='on'; SELECT pg_reload_conf(); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "cat", "a": "cat" }'); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "dog", "a": "dog" }'); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": 3, "a": "peacock" }'); -- query match: single shard key SELECT documentdb_api.shard_collection('db', 'coll_qm_sharded', '{ "_id": "hashed" }', false); -- we expect the query to be distributed: shard key value is collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT" }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT" }', NULL, 'en-u-ks-level1'); ROLLBACK; -- we do not expect the query to be distributed: shard key value is not collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3 }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3 }', NULL, 'en-u-ks-level1'); ROLLBACK; -- query match: compound shard key SELECT documentdb_api.drop_collection('db', 'coll_qm_sharded'); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "cAt", "a": "cAt" }'); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": "doG", "a": "DOg" }'); SELECT documentdb_api.insert_one('db', 'coll_qm_sharded', '{ "_id": 3, "a": "doG" }'); SELECT documentdb_api.shard_collection('db', 'coll_qm_sharded', '{ "_id": "hashed", "a": "hashed" }', false); -- we expect the query to be distributed: shard key filter values is collation-aware BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT", "a": "CAT" }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": "CAT", "a": "CAT" }', NULL, 'en-u-ks-level1'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$and": [{"_id": "cat", "a": "1"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$and": [{"_id": "cat", "a": "1"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": "cat", "a": "CAT"}, {"_id": 3, "a": "dog"}] }', NULL, 'en-u-ks-level1'); ROLLBACK; -- we do not expect the query to be distributed BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 1, "a": "CAT" }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 1, "a": "CAT" }', NULL, 'en-u-ks-level1'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3, "a": 4 }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{ "_id": 3, "a": 4 }', NULL, 'en-u-ks-level1'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": 3, "a": "dog"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); EXPLAIN (COSTS OFF) SELECT document from documentdb_api.collection('db', 'coll_qm_sharded') WHERE documentdb_api_internal.bson_query_match(document, '{"$or": [{"_id": 3, "a": "dog"}, {"_id": 3, "a": 3}] }', NULL, 'en-u-ks-level1'); ROLLBACK; -- collation on sharded collections: aggregation SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cat", "a": "cat" }'); SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cAt", "a": "cAt" }'); SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "dog", "a": "dog" }'); SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "dOg", "a": "dOg" }'); -- simple shard key SELECT documentdb_api.shard_collection('db', 'coll_sharded_agg', '{ "_id": "hashed" }', false); -- query is distributed to all shards SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": "cat" } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": "CAT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": "CAT" } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); -- query is not distributed to all shards (shard key value is not collation-aware) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": 2 } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "_id": { "$eq": 2 } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": 1 } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match": { "_id": { "$eq": 1 } } }], "cursor": {}, "collation": { "locale": "en", "strength" : 2} }'); -- compound shard key SELECT documentdb_api.drop_collection('db', 'coll_sharded_agg'); SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "cAt", "a": "cAt" }'); SELECT documentdb_api.insert_one('db', 'coll_sharded_agg', '{ "_id": "doG", "a": "Dog" }'); SELECT documentdb_api.shard_collection('db', 'coll_sharded_agg', '{ "_id": "hashed", "a": "hashed" }', false); -- query is distributed to all shards (filter by shard_key_value is omitted) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "a": { "$eq": "Cat" }, "_id": "caT" }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "a": { "$eq": "Cat" }, "_id": "caT" }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": "CAT", "a": "CAT"} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": "CAT", "a": "CAT"} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$or": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "1", "a": "CaT"}, {"_id": "DOG"}]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "1", "a": "CaT"}, {"_id": "DOG"}]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$and": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_sharded_agg", "filter": { "$and": [{"_id": "CAT", "a": "CAT"}, {"_id": 3, "a": "dog"}] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "cat", "a": 2 }, {"_id": 1, "a": 1 }]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"$or": [{"_id": "cat", "a": 2 }, {"_id": 1, "a": 1 }]} } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; -- query is not distributed to all shards BEGIN; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": 1, "a": 1 } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_sharded_agg", "pipeline": [ { "$match":{"_id": 1, "a": 1 } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; -- nested arrays SELECT documentdb_api_internal.bson_query_match('{"a": ["cat"]}', '{ "a": {"$in" : [["CAT"], "DOG"]} }', NULL, 'de-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": ["cat"]}', '{ "a": {"$in" : [["CAT"], ["DOG"]] } }', NULL, 'de-u-ks-level3'); SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 1, "a": ["dog"] }'); SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 2, "a": ["cat", "dog"] }'); SELECT documentdb_api.insert_one('db', 'nested_arrays', '{ "_id": 3, "a": [[["cat"]]] }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [ ["dOG"] ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [ [["CAT"]] ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays", "filter": { "a" : {"$in" : [["CAT"], ["DOG"]] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); -- nested documents SELECT documentdb_api_internal.bson_query_match('{"a": {"b": "cat"}}', '{ "a": {"b": "CAT"} }', NULL, 'en-u-ks-level1'); SELECT documentdb_api_internal.bson_query_match('{"a": {"b": {"c": "cat"}}}', '{ "a": {"b": {"c": "CAT"}} }', NULL, 'en-u-ks-level2'); SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 1, "a": { "b": "cat" } }'); SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 2, "a": { "b": "dog" } }'); SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 3, "a": { "b": { "c": "cat" } } }'); SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 4, "a": { "b": { "c": "dog" } } }'); SELECT documentdb_api.insert_one('db', 'nested_docs', '{ "_id": 5, "a": { "b": { "c": { "d": "cat" } } } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": "dOG"} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": { "c": "dOg" }} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"b": { "c": { "d": "dOg" }}} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); -- nested documents: keys are collation-agnostic SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_docs", "filter": { "a" : {"$in" : [ {"B": "dOG"} ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); -- nested arrays and documents SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 1, "a": { "b": ["cat"] } }'); SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 2, "a": { "b": ["dog"] } }'); SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 3, "a": { "b": ["cat", "dog"] } }'); SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 4, "a": {"b": [["dog"]] } }'); SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 5, "a": { "b": [[["cat"]]] } }'); SELECT documentdb_api.insert_one('db', 'nested_arrays_docs', '{ "_id": 6, "a": "cat" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": [["dOg"]] } ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "nested_arrays_docs", "filter": { "a" : {"$in" : [ {"b": ["dOG"]}, "CAT" ] }}, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); ROLLBACK; SET documentdb.enableLetAndCollationForQueryMatch to off; -- delete SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "dog", "a":"dog"}'); SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "DOG", "a":"DOG"}'); SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "cat", "a":"cat"}'); SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": "CAT", "a":"CAT"}'); -- GUC off: collation ignored SET documentdb_core.enableCollation TO off; BEGIN; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "DoG" }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); ROLLBACK; -- enable GUC SET documentdb_core.enableCollation TO on; BEGIN; -- query on _id SET citus.log_remote_commands TO ON; -- _id is not collation-aware SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": 1 }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "DoG" }, "limit": 0, "collation": { "locale": "fr", "strength" : 2}} ]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"_id": "cAT" }, "limit": 0, "collation": { "locale": "fr", "strength" : 3}} ]}'); ROLLBACK; BEGIN; --- deleteMany SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; -- more operators in query SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": {"$lt": "DeG"} },"limit": 1, "collation": { "locale": "fr", "strength" : 1} }] }'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": {"$lt": "DoG"}, "a": {"$lt": "Goat"} },"limit": 1, "collation": { "locale": "fr", "strength" : 2} }] }'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ {"q": {"a": { "$exists": true }, "a": {"$gt": "DoG"}, "a": {"$lt": "goat"} },"limit": 1, "collation": { "locale": "fr", "strength" : 1 } }] }'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); ROLLBACK; BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); ROLLBACK; -- delete with sort obeys collation SELECT documentdb_api.insert_one('db', 'coll_delete_sort', '{"_id": "dog", "a": "dog"}'); SELECT documentdb_api.insert_one('db', 'coll_delete_sort', '{"_id": "DOG", "a": "dog"}'); BEGIN; -- sort respects collation: ASC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); ROLLBACK; BEGIN; -- sort respects collation: DESC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); ROLLBACK; -- delete on sharded collection SELECT documentdb_api.shard_collection('db', 'coll_delete', '{ "a": "hashed" }', false); BEGIN; --- deleteMany SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "DoG" }, "limit": 0, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; -- deleteOne: error: no _id filter and no shard key value filter SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"b": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); -- deleteOne: error: no _id filter and collation-aware shard key value filter SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT", "a": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "dog", "a": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; --- deleteOne SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "CaT" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 1}}]}'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; SELECT documentdb_api.shard_collection('db', 'coll_delete_sort', '{ "a": "hashed" }', false); BEGIN; -- sort respects collation: ASC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "_id": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); ROLLBACK; BEGIN; -- sort respects collation: DESC SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); SELECT collection_id AS coll_delete_sort FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'coll_delete_sort' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:coll_delete_sort, p_shard_key_value=>:coll_delete_sort, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": "dog" }, "collation": "en-u-ks-level3", "sort": { "_id": -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('db', 'coll_delete_sort'); SELECT document from documentdb_api.collection('db', 'coll_delete_sort'); ROLLBACK; -- test without auto variables ($$NOW) generation BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"a": "CaT" }, "limit": 0, "collation": { "locale": "en", "strength" : 3}}]}'); ROLLBACK; BEGIN; SET LOCAL documentdb.enableNowSystemVariable='off'; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "DoG" }, "limit": 1, "collation": { "locale": "en", "strength" : 3}}]}'); ROLLBACK; SELECT documentdb_api.drop_collection('db', 'coll_delete'); SELECT documentdb_api.drop_collection('db', 'coll_delete_sort'); ALTER SYSTEM SET documentdb_core.enablecollation='off'; SELECT pg_reload_conf();bson_dollar_ops_expr_tests.sql000066400000000000000000000027741507310017400351630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7500000; SET documentdb.next_collection_id TO 7500; SET documentdb.next_collection_index_id TO 7500; SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 1, "a": [ 1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 2, "a": 5 }'); SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 3, "a": "someValue" }'); SELECT documentdb_api.insert_one('db', 'bsonexprtests', '{ "_id": 4, "a": 2 }'); SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$in": [ "$a", [ 2, "someValue" ] ] } }'; SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$gte": [ "$a", 3 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": { "$isArray": "$a" } }'; SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": "$a.0" }'; -- invalid scenarios SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "a": { "$elemMatch": { "$expr": { "$isArray": "$a" } } } }'; SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$expr": "$a" } } } }', '{}'); SELECT document FROM documentdb_api.collection('db', 'bsonexprtests') WHERE document @@ '{ "$expr": "$$a" }';bson_dollar_ops_json_schema_build_tree_tests.sql000066400000000000000000000527431507310017400406750ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7600000; SET documentdb.next_collection_id TO 7600; SET documentdb.next_collection_index_id TO 7600; -- The tests in this file ensure that schema provided is valid, and throws error on all invalid scenarios. -- Test for validating documents against valid json schema is provided in separate test file. ------------------------------------------------------------------------------- -- Object Validators -- ------------------------------------------------------------------------------- ------------------------ properties ------------------------------------------- -- Must be an object SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": "name" } }'); -- Each property must be an object SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": { "name":"pazu" } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "properties": { "name" : { } } } }'); ------------------------ required --------------------------------------------- -- Must be an array SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": "name" } }'); -- duplicated fields SELECT bson_dollar_json_schema('{ "name":"pazu", "name":"tst" }','{ "$jsonSchema": { "required": ["name", "age" ] } }'); -- Must be unique SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name", "name" ] } }'); -- Each element must be a string SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ 1 ] } }'); SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name",1,"age" ] } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": ["name", ["a","b","c"], "age" ] } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name" ] } }'); SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name" ] } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }','{ "$jsonSchema": { "required": [ "name","age" ] } }'); SELECT bson_dollar_json_schema('{ "name":"pazu", "age":10 }','{ "$jsonSchema": { "required": [ "name","age" ] } }'); SELECT bson_dollar_json_schema('{ "":1 }','{ "$jsonSchema": { "required": [ "" ] } }'); SELECT bson_dollar_json_schema('{ "a":1 }','{ "$jsonSchema": { "required": [ "" ] } }'); SELECT bson_dollar_json_schema('{ "":1, "name":"pazu","age":10 }','{ "$jsonSchema": { "required": [ "","name","age" ] } }'); SELECT bson_dollar_json_schema('{ "":1, "age":10 }','{ "$jsonSchema": { "required": [ "","name","age" ] } }'); ------------------------------------------------------------------------------- -- Common Validators -- ------------------------------------------------------------------------------- ------------------------ type ------------------------------------------------- -- Must be a string or array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": 1 } } } }'); -- Must be a valid json type SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "hello" } } } }'); -- Json type "integer" not supported SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "integer" } } } }'); -- Array must not be empty SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ ] } } } }'); -- Array elements must be strings SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ 2 ] } } } }'); -- Array elements must not contain duplicate values SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": [ "string", "string" ] } } } }'); -- Valid case - string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": "string" } } } }'); -- Valid case - array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "type": ["string", "object"] } } } }'); ------------------------ bsonType --------------------------------------------- -- Must be a string or array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": 1 } } } }'); -- Must be a valid json type SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "hello" } } } }'); -- Bson type "integer" not supported. "int" is supported SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "integer" } } } }'); -- Array must not be empty SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ ] } } } }'); -- Array elements must be strings SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ 2 ] } } } }'); -- Array elements must not contain duplicate values SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": [ "string", "string" ] } } } }'); -- Valid case - string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": "string" } } } }'); -- Valid case - array SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "bsonType": ["string", "object"] } } } }'); ------------------------------------------------------------------------------- -- Numeric Validators -- ------------------------------------------------------------------------------- ------------------------ multipleOf ------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": null } } } }'); -- Must be a non-zero SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": 0 } } } }'); -- Must not be NaN SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "NaN"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "-NaN"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "NaN"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "-NaN"} } } } }'); -- Must not be INF SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble" : "-INF"} } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberInt": "1"} } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "multipleOf": {"$numberDouble": "2.2"} } } } }'); ------------------------ maximum ---------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": null } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "maximum": {"$numberDouble": "99.9"} } } } }'); ------------------------ exclusiveMaximum ------------------------------------- -- Must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": null } } } }'); -- if exclusiveMaximum is present, maximum must be present too SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": true } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMaximum": true, "maximum" : 99 } } } }'); ------------------------ minimum ---------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": null } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "minimum": {"$numberDouble": "4.0"} } } } }'); ------------------------ exclusiveMinimum ------------------------------------- -- Must be a boolean SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": null } } } }'); -- if exclusiveMaximum is present, maximum must be present too SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": true } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "age": 6 }', '{ "$jsonSchema": { "properties" : { "age" : { "exclusiveMinimum": true, "minimum" : 5 } } } }'); ------------------------------------------------------------------------------- -- String Validators -- ------------------------------------------------------------------------------- ------------------------ maxLength -------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": null } } } }'); -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "9223372036854775809"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "NaN"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDecimal": "-INF"} } } } }'); -- Must be integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "10.3"} } } } }'); -- Must be positive integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "-10"} } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "maxLength": {"$numberDouble": "10"} } } } }'); ------------------------ minLength -------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": null } } } }'); -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "9223372036854775809"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "NaN"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDecimal": "-INF"} } } } }'); -- Must be integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "1.3"} } } } }'); -- Must be positive integer SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "-1"} } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "minLength": {"$numberDouble": "1"} } } } }'); ------------------------ pattern ---------------------------------------------- -- Must be a string SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": 1 } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": null} } } }'); -- Must be a valid regex SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "\\" } } } }'); -- Valid Schemas SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "" } } } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "properties" : { "name" : { "pattern": "^[a-zA-Z_]*$" } } } }'); ------------------------------------------------------------------------------- -- Array Validators -- ------------------------------------------------------------------------------- ------------------------ items ------------------------------------------------ -- Must be an object or an array of objects SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": 1 } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": null } } } }'); -- if its an array, it must contain all objects SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [{ }, 1] } } } }'); -- Valid Schemas SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [{ }, {"bsonType":"int"} ] } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": [] } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "items": { } } } } }'); ------------------------ additionalItems -------------------------------------- -- Must be an object/bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": 1 } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": null } } } }'); -- Valid Schema - Object SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": { } } } } }'); -- Valid Schema - Bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "additionalItems": true } } } }'); ------------------------ maxItems --------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": null } } } }'); -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "9223372036854775809"} } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "NaN"} } } } }'); -- Must be integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "10.3"} } } } }'); -- Must be positive integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "-10"} } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "maxItems": {"$numberDouble": "10"} } } } }'); ------------------------ minItems --------------------------------------------- -- Must be a number SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": null } } } }'); -- Must be representable in 64 bits integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "9223372036854775809"} } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "INF"} } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "NaN"} } } } }'); -- Must be integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "1.3"} } } } }'); -- Must be positive integer SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "-1"} } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "minItems": {"$numberDouble": "1"} } } } }'); ------------------------ uniqueItems ------------------------------------------ -- Must be a bool SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": "hello" } } } }'); SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": null } } } }'); -- Valid Schema SELECT bson_dollar_json_schema('{ "hobbies" : ["run", 1, {"eat" : "treats"} ] }', '{ "$jsonSchema": { "properties" : { "hobbies" : { "uniqueItems": true } } } }'); ------------------------------------------------------------------------------- -- Unsupported Keywords -- ------------------------------------------------------------------------------- SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "$ref" : "hello", "$id" : 2 } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "$schema" : "hello" } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "default" : "hello" } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "definitions" : "hello" } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "format" : "hello" } }'); SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "id" : "hello" } }'); ------------------------------------------------------------------------------- -- Unknown Keywords -- ------------------------------------------------------------------------------- SELECT bson_dollar_json_schema('{ "name":"pazu" }', '{ "$jsonSchema": { "hello" : "hello" } }'); bson_dollar_ops_json_schema_query_tests.sql000066400000000000000000001324121507310017400377140ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7700000; SET documentdb.next_collection_id TO 7700; SET documentdb.next_collection_index_id TO 7700; SELECT documentdb_api.insert_one('db', 'col_bson_dollar_ops_json_schema_query', '{ "_id": 0, "itemType": "alpha", "count" : 4, "flag" : true, "height" : 5.8, "width" : { "$numberDecimal": "4.2" }, "details" : { "year" : 2020, "shade" : "black" }, "features": ["optionA", {"drive": "front"}, {"extra": true, "free": true} ], "engine": { "cc": 1500, "fuel": "petrol" } }'); SELECT documentdb_api.insert_one('db', 'col_bson_dollar_ops_json_schema_query', '{ "_id": 1, "itemType": 20, "count" : "many", "flag" : "1 ton", "height" : "very high", "width" : { "upper" : 10, "lower" : 20 }, "details" : 2010, "features": null, "engine": 1500 }'); ------------------------------------------------------------------------------- -- Common Validations -- ------------------------------------------------------------------------------- ---------------------------- "type" ------------------------------------------- -- All docs Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { } } }'); -- All docs Match, as none of docs have given field SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "cosmosdb" : { "type" : "string" } } } }'); -- No Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "boolean" } } } }'); -- Matches where "itemType" is "string" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "string" } } } }'); -- Matches where "count" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "number" } } } }'); -- Matches where "height" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "height" : { "type" : "number" } } } }'); -- Matches where "width" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "width" : { "type" : "number" } } } }'); -- Matches where "details" is "object" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "details" : { "type" : "object" } } } }'); -- Matches where "features" is "array" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "features" : { "type" : "array" } } } }'); -- Matches where "flag" is "boolean" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "flag" : { "type" : "boolean" } } } }'); -- Matches where "itemType" is "string" and "count" is "number" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "type" : "string" }, "count" : { "type" : "number" } } } }'); -- Unsupported: "integer" type SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "integer" } } } }'); ---------------------------- "bsonType" ------------------------------------------- -- All docs Match, as none of docs have given field SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "cosmosdb" : { "bsonType" : "string" } } } }'); -- No Match SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "bool" } } } }'); -- Matches where "itemType" is "string" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "string" } } } }'); -- Matches where "count" is "int" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "bsonType" : "int" } } } }'); -- Matches where "height" is "double" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "height" : { "bsonType" : "double" } } } }'); -- Matches where "width" is "decimal" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "width" : { "bsonType" : "decimal" } } } }'); -- Matches where "details" is "object" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "details" : { "bsonType" : "object" } } } }'); -- Matches where "features" is "array" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "features" : { "bsonType" : "array" } } } }'); -- Matches where "flag" is "boolean" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "flag" : { "bsonType" : "bool" } } } }'); -- Matches where "itemType" is "string" and "count" is "int" SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "itemType" : { "bsonType" : "string" }, "count" : { "bsonType" : "int" } } } }'); -- Unsupported: "integer" type SELECT document FROM documentdb_api.collection('db', 'col_bson_dollar_ops_json_schema_query') WHERE documentdb_api_catalog.bson_dollar_json_schema(document,'{ "$jsonSchema": { "properties": { "count" : { "type" : "integer" } } } }'); ------------------------------------------------------------------------------- -- Numeric Validations -- ------------------------------------------------------------------------------- --------------------------- multipleOf ---------------------------------------- -- Doc is valid as field's value is a multiple of "multipleOf" SELECT bson_dollar_json_schema('{"size": 0}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2.2 } } } }'); --In the following test doc is evaluated as invalid, because psql converts double value of 1.1 to 1.1000000000000001, which is not a multiple of 11 --This would not happen when req comes from gateway. So commenting out this test in psql, but will add this test as JS test in Gateway --SELECT bson_dollar_json_schema('{"size": 11}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : {"$numberDouble" : "1.1"} } } } }'); -- Doc is invalid as field's value is not a multiple of "multipleOf" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 3 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.4}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2.1 } } } }'); -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "multipleOf" : 2 } } } }'); --------------------------- maximum ---------------------------------------- -- Doc is valid as field's value is less than or equal to given value of "maximum" SELECT bson_dollar_json_schema('{"size": 2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); -- Doc is invalid as field's value is more than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"} } } } }'); -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4 } } } }'); --------------------------- exclusiveMaximum ------------------------------- -- When "exclusiveMaximum" is true, these doc are valid as field's value is strictly less than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); -- When "exclusiveMaximum" is true, these doc are invalid as field's value is more than or equal to the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : true } } } }'); -- When "exclusiveMaximum" is false, these doc are valid as field's value is less than or equal to the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); -- When "exclusiveMaximum" is false, these doc are invalid as field's value is more than the given value of "maximum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4.1, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "-INF"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "NaN"}, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : {"$numberDecimal" : "INF"}, "exclusiveMaximum" : false } } } }'); -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "maximum" : 4, "exclusiveMaximum" : true } } } }'); --------------------------- minimum ---------------------------------------- -- Doc is valid as field's value is more than or equal to given value of "minimum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"} } } } }'); -- Doc is invalid as field's value is less than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 3.9}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1 } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.11 } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"} } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"} } } } }'); -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); SELECT bson_dollar_json_schema('{"size": [5]}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4 } } } }'); --------------------------- exclusiveMinimum ------------------------------- -- When "exclusiveMinimum" is true, these doc are valid as field's value is strictly more than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4.11}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : true } } } }'); -- When "exclusiveMinimum" is true, these doc are invalid as field's value is less than or equal to the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 3.99}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : true } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"}, "exclusiveMinimum" : true } } } }'); -- When "exclusiveMinimum" is false, these doc are valid as field's value is more than or equal to the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.2}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 5}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "NaN"}, "exclusiveMinimum" : false } } } }'); -- When "exclusiveMinimum" is false, these doc are invalid as field's value is less than the given value of "minimum" SELECT bson_dollar_json_schema('{"size": 3}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 3.9}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.1, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": 4.1}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4.11, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "-INF"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "INF"}, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": {"$numberDecimal" : "NaN"}}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : {"$numberDecimal" : "-INF"}, "exclusiveMinimum" : false } } } }'); -- Doc is valid if field is not numeric SELECT bson_dollar_json_schema('{"size": "hello"}','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : false } } } }'); SELECT bson_dollar_json_schema('{"size": [3] }','{ "$jsonSchema": { "properties": { "size" : { "minimum" : 4, "exclusiveMinimum" : true } } } }'); ------------------------------------------------------------------------------- -- String Validations -- ------------------------------------------------------------------------------- --------------------------- maxLength ---------------------------------------- -- Doc is valid as length of string is less than or eq to maxLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 10 } } } }'); SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 4 } } } }'); -- Doc is invalid as length of string is less than or eq to maxLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 2 } } } }'); -- Doc is valid if property is not a string SELECT bson_dollar_json_schema('{"name": 2}','{ "$jsonSchema": { "properties": { "name" : { "maxLength" : 4 } } } }'); --------------------------- minLength ---------------------------------------- -- Doc is valid as length of string is more than or eq to minLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 2 } } } }'); SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 4 } } } }'); -- Doc is invalid as length of string is more than the minLength SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 10 } } } }'); -- Doc is valid if property is not a string SELECT bson_dollar_json_schema('{"name": 2}','{ "$jsonSchema": { "properties": { "name" : { "minLength" : 4 } } } }'); ---------------------------- pattern ----------------------------------------- -- Doc is valid as given pattern matches the string SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "^P" } } } }'); SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "[auzP]" } } } }'); -- Doc is invalid as given pattern does not matches the string SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "^a" } } } }'); SELECT bson_dollar_json_schema('{"name":"Pazu"}','{ "$jsonSchema": { "properties": { "name" : { "pattern" : "$z" } } } }'); ------------------------------------------------------------------------------- -- Array Validations -- ------------------------------------------------------------------------------- ---------------------------- items -------------------------------------------- -- Doc is valid as "data" array's each value matches the schema given in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" } ] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }] } } } }'); -- Doc is invalid as "data" array's each value does matches the schema given in "items" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "object" }] } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"number" }] } } } }'); -- Doc is valid when "items" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" } ] } } } }'); SELECT bson_dollar_json_schema('{"data" : "Hello" }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "number" } ] } } } }'); ---------------------------- additionalItems ---------------------------------- -- Doc is valid as "data" array values matches the schema given in "items", and data array has no more members than the number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}], "additionalItems" : false } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }], "additionalItems" : false } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }], "additionalItems" : false } } } }'); -- Doc is invalid as "data" array has more members than the number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }], "additionalItems" : false } } } }'); -- Doc is valid as "data" array values matches the schema given in "items", while data array can have more members than number of members listed in "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }, { "type":"object" }, { "type": "number"}, { "type" : "boolean" }], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "minLength" : 1, "maxLength" : 10 }, { "type":"object" }, { "minimum" : 1, "maximum": 5 }], "additionalItems" : true } } } }'); -- Doc is valid, if "items" keyword is not provided, since "additionalItems" has no effect without "items" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : false } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "additionalItems" : false } } } }'); -- Doc is valid, if "additionalItems" is provided for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "items" : [{ "type" : "string" }], "additionalItems" : false } } } }'); ---------------------------- maxItems ----------------------------------------- -- Doc is valid as "data" array members are less than or equal to given "maxItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 0 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); -- Doc is invalid as "data" array members are more than the given "maxItems" SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); -- Doc is valid when "maxItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "maxItems" : 2 } } } }'); ---------------------------- minItems ----------------------------------------- -- Doc is valid as "data" array members are more than or equal to given "minItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 0 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello", {"a":1}, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); -- Doc is invalid as "data" array members are less than the given "minItems" SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hello" ] }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 2 } } } }'); -- Doc is valid when "minItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 2 }','{ "$jsonSchema": { "properties": { "data" : { "minItems" : 1 } } } }'); ---------------------------- uniqueItems -------------------------------------- -- Doc is valid as all items in the given array are unique SELECT bson_dollar_json_schema('{"data" : [ ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, 2 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, 1.1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"1":1}, "1" ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"1":1}, "1", true ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1}, {"b":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":1}, {"a":2, "b":2} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":1}, {"a":2, "b":2} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); -- Doc is invalid as all items in the given array are not unique SELECT bson_dollar_json_schema('{"data" : [ 1, 1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, 1.0 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, true, true ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ false, 1, false ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ "Hi", "Hi", 1 ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); -- Doc is invalid, as objects that have same key-value pairs, even in different orders, are not unique. Applicable to objects recursively (i.e. objects in objects) SELECT bson_dollar_json_schema('{"data" : [ 1, {"a":1, "b":2}, {"b":2, "a":1} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); SELECT bson_dollar_json_schema('{"data" : [ 1, {"a": {"x":5, "y": 6}, "b":2}, {"b":2, "a": {"y":6, "x":5}} ] }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); -- Doc is valid when "uniqueItems" is given for Non-Array fields SELECT bson_dollar_json_schema('{"data" : 1 }','{ "$jsonSchema": { "properties": { "data" : { "uniqueItems" : true } } } }'); ------------------------------------------------------------------------------- -- Binary Validations -- ------------------------------------------------------------------------------- SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); SELECT bson_dollar_json_schema('{"data" : 1}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"keyId": ["9e4cfa3e-2b56-4e20-9fd3-3c3708056a18"], "algorithm":"AEAD_AES_256_CBC_HMAC_SHA_512-Random", "bsonType":"string"} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": {"encryptMetadata": {"keyId": ["9e4cfa3e-2b56-4e20-9fd3-3c3708056a18"], "algorithm":"AEAD_AES_256_CBC_HMAC_SHA_512-Random"} } }'); -- negative test cases SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": "test"} }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {}} }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"unknown":"hello"}} }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"keyId":1}} }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": {"encryptMetadata": {"algorithm":[]}} }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"a":1} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"keyId":1} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"algorithm":[]} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {"bsonType": 123} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : "" } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {}, "type":"string" } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {}, "bsonType":"string" } } } }'); -- guc test cases set documentdb.enableSchemaEnforcementForCSFLE = false; SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "06" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); SELECT bson_dollar_json_schema('{"data" : 1}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); SELECT bson_dollar_json_schema('{"data" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType" : "01" }}}','{ "$jsonSchema": { "properties": { "data" : { "encrypt" : {} } } } }'); -- $jsonSchema will be supported in query condition later ------------------------------------------------------------------------------- -- $jsonSchema in query condition -- ------------------------------------------------------------------------------- -- All docs Match SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { } } }, "$db" : "db" }'); -- -- No Match SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { "itemType" : { "type" : "boolean" } } } }, "$db" : "db" }'); -- -- Matches where "vehicle" is "string" SELECT cursorPage FROM documentdb_api.find_cursor_first_page('db', '{ "find" : "col_bson_dollar_ops_json_schema_query", "filter" : { "$jsonSchema": { "properties": { "itemType" : { "type" : "string" } } } }, "$db" : "db" }'); bson_dollar_ops_query_all_tests_core.sql000066400000000000000000000244721507310017400372110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- top level SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 1, "a": "b"}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 2, "a": ["a", "b"]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 3, "a": ["a", "b", "c"]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 4, "a": ["y", "z", "a"]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 5, "a": ["y", "z", "a", { "d": 1 }, 2]}', NULL); -- nested and empty arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 6, "a": [[["x", "y"], ["z"]]]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 7, "a": []}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 8, "a": [[]]}', NULL); -- nested objects SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 9, "a": {"b": [ ["a", "z", "b"] ]}}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 10, "a": {"b": [ ["a", "z", "b"], ["x", "y"] ]}}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 11, "a": {"b": [ ["a", "z", "b"], ["x", "y"], ["c"] ]}}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 12, "a": {"b": { "c": ["d"] }}}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 13, "a": {"b": { "c": { "d": 1 }}}}', NULL); -- objects with elements that sort after arrays SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 14, "foo": true}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 15, "foo": false}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 16, "foo": [ 1, "a", true]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 17, "foo": [true]}', NULL); -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 18, "other": [ 1, null]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 19, "other": [null]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 20, "other": [1, NaN]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 21, "other": [1, 0.0]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 22, "other": [1, 0.0, NaN]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 23, "other": [null, NaN]}', NULL); -- documents inside array SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 24, "array": [ {"x": 1}, {"x": 2}]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 25, "array": [ {"x": 2}, {"x": 3}]}', NULL); SELECT documentdb_api.insert_one('db','dollaralltests','{"_id": 26, "array": [ {"x": 3}, {"x": 4}]}', NULL); -- top level simple SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "a"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["b", "c"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "z"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : ["a", "y", "z"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }, "a", "y", "z"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 1 }]}'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [{ "d": 2 }]}'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [2]}'; -- array indexes selector SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0" : ["b"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.1" : ["b"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["x"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : ["y", "x"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0" : [ ["x", "y"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.1" : [ ["z"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.0.0.0" : ["x"] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.3" : [{ "d": 1 }] }'; -- top level nested arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["z"]]] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"]]] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [[["x", "y"], ["z"]]] }'; -- empty arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [] ]}'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ [ [] ] ]}'; -- nested objects and arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["x", "y"], ["c"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["a", "z", "b"], ["c"] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b" : [ ["x", "y"] ] }'; -- nested objects and arrays with objects SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ "d" ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ [ "d" ] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [ { "d": 1 } ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c" : [{ }] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a.b.c.d" : [ 1, 2 ] }'; -- objects with elements that sort after arrays SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a" ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, true ] }'; -- null and NaN SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ null, null, null, null, "foo" ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "a" : [ "foo", null, null, null ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ [ null ], [null] ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ null, NaN ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ 0.0, NaN ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "other" : [ NaN ] }'; -- all with repeated elements SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, true, true, true, false ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [[true], [true], [true], [true]] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ false, false, false, false ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ true, false, true, false, true ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, "a", "a", "a", "a", "a", 1 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "foo" : [ 1, 1, 1, 1, 1, true ] }'; -- query for path inside array SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 2 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 2, 3 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 3 ] }'; SELECT document FROM documentdb_api.collection('db', 'dollaralltests') where document @&= '{ "array.x" : [ 1, 3 ] }'; bson_dollar_ops_query_all_tests_index.sql000066400000000000000000000022241507310017400373570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'dollaralltests') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'dollaralltests') IS NOT NULL; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api_internal.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollaralltests', 'index_2', '{"$**": 1}'), TRUE); \o \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_all_tests_core.sql ROLLBACK; \set QUIET offbson_dollar_ops_query_all_tests_index_backcompat.sql000066400000000000000000000023151507310017400415440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'dollaralltests') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'dollaralltests') IS NOT NULL; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api_internal.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollaralltests', 'index_2', '{"$**": 1}'), TRUE); \o \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_all_tests_core.sql ROLLBACK; \set QUIET offbson_dollar_ops_query_all_tests_runtime.sql000066400000000000000000000012731507310017400377360ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 440000; SET documentdb.next_collection_id TO 4400; SET documentdb.next_collection_index_id TO 4400; \set QUIET on \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'dollaralltests') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'dollaralltests') IS NOT NULL; \o \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollaralltests'); BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_all_tests_core.sql ROLLBACK; \set QUIET offbson_dollar_ops_query_array_size_tests_core.sql000066400000000000000000000040041507310017400405760ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql -- top level SELECT documentdb_api.insert_one('db','arraysize','{"_id": 1, "a": []}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 2, "a": [1, 2]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 3, "a": ["a", "a"]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 4, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 5, "b": [1, 2]}', NULL); -- nested object SELECT documentdb_api.insert_one('db','arraysize','{"_id": 6, "a": {"b":[]}}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 7, "a": {"b":[1, 2]}}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 8, "a": {"b":["a", "a"]}}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 9, "a": {"b":1}}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 10, "b": {"b":[1, 2]}}', NULL); -- nested array SELECT documentdb_api.insert_one('db','arraysize','{"_id": 11, "c": [{"b":[]}]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 12, "c": [{"b":[1, 2]}]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 13, "c": [{"b":["a", "a"]}]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 14, "c": [{"b":1}]}', NULL); SELECT documentdb_api.insert_one('db','arraysize','{"_id": 15, "b": [{"b":[1, 2]}]}', NULL); -- assert that size returns the correct number of rows. SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a" : 2 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "a.b" : 2 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 0 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'arraysize') where document @@# '{ "c.b" : 2 }'; bson_dollar_ops_query_array_size_tests_index.sql000066400000000000000000000016451507310017400407650ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 430000; SET documentdb.next_collection_id TO 4300; SET documentdb.next_collection_index_id TO 4300; \set QUIET on \set prevEcho :ECHO \set ECHO none SELECT documentdb_api.drop_collection('db', 'arraysize') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'arraysize') IS NOT NULL; \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('arraysize', 'testgin_arraysize', '{"$**": 1}'), TRUE); \o \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','arraysize'); BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_array_size_tests_core.sql ROLLBACK; \set QUIET offbson_dollar_ops_query_array_size_tests_runtime.sql000066400000000000000000000012431507310017400413330ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 430000; SET documentdb.next_collection_id TO 4300; SET documentdb.next_collection_index_id TO 4300; \set QUIET on \set prevEcho :ECHO \set ECHO none SELECT documentdb_api.drop_collection('db', 'arraysize') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'arraysize') IS NOT NULL; \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','arraysize'); BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_array_size_tests_core.sql ROLLBACK; \set QUIET offbson_dollar_ops_query_bits_tests_core.sql000066400000000000000000001206571507310017400374040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Tests on numbers. SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 54}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 88}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 255}', NULL); --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 16 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 129 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 255 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 12984 } }'; --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 18 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 24 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 255 } }'; --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 16 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 54 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 55 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 88 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 255 } }'; --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 9 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 255 } }'; --Test with bit position $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 4 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1, 7 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test with bit position $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1, 4 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 3, 4 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test with bit position $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 4 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1, 2, 4, 5 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 4, 5 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 3, 4, 6 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test with bit position $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1, 3 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test On negative Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -0}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": -1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -54}', NULL); --Test With BitMask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 53 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 127 } }'; --Test With BitMask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 53 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 127 } }'; --Test With BitMask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 127 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 74 } }'; --Test With BitMask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 127 } }'; --Test With bit positions $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 5, 4, 2, 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test With bit positions $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2, 4, 5, 100 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test With bit positions $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 7, 6, 3 ,100 ] } }'; --Test With bit positions $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7 ] } }'; --Test With bit positions with not int32 Type $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; --Test With bit positions with not int32 Type $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; --Test With bit positions with not int32 Type $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; --Test With bit positions with not int32 Type $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberLong" : "5"}, { "$numberLong" : "4"}, { "$numberLong" : "2"}, { "$numberLong" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDouble" : "5"}, { "$numberDouble" : "4"}, { "$numberDouble" : "2"}, { "$numberDouble" : "0"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ { "$numberDecimal" : "5"}, { "$numberDecimal" : "4"}, { "$numberDecimal" : "2"}, { "$numberDecimal" : "0"} ] } }'; --Test On BinData with different subtypes SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"9", "a": {"$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"10", "a": {"$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"11", "a": {"$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"12", "a": {"$binary": { "base64": "////////////////////////////", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"13", "a": {"$binary": { "base64": "////////////////////////////", "subType": "02"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"14", "a": {"$binary": { "base64": "////////////////////////////", "subType": "03"}}}', NULL); --Test with bin data $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; --Test with bin data $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; --Test with bin data $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "JANgqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; --Test with bin data $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "JAyfqwetkqwklEWRbWERKKJREtbq", "subType": "02"} } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "////////////////////////////", "subType": "03"} } } }'; --Sign Extension Check SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": -2}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 2}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": -1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": -8}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 5}', NULL); --Sign Extension check with $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 2000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; --Sign Extension check with $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 2000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; --Sign Extension check with $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 2000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; --Sign Extension check with $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 2000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70] } }'; --Test when Document has neither bindata nor Number SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": "B"}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 1.2832}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": "apple"}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": "A"}', NULL); SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 10 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 10 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 10 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 10 } }'; --Test on Double , Int64, Decimal128 SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": {"$numberDouble" : "1.00000000"}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": {"$numberDouble" : "2.00000000"}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": {"$numberLong" : "6"}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": {"$numberLong" : "9999999999999999"}}', NULL); --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 3 } }'; --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 3 } }'; --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 3 } }'; --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3 } }'; -- Tests on array. SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [10,12,14,16]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [10,12,14,16,1]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [1,3,5,7]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": [1,3,4]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": [10.01, "hello", "Test", 11, 2]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": [10.01, "hello", "Test"]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": ["hello", "Test"]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": [10.11, 11.12, 13.24]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": [10.0, 11.0, 13.0]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": [1, 1, 1, 1]}', NULL); --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$gt" : 5 } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllClear" : 1, "$lte" : 5 } } }'; --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$gt" : 5 } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnyClear" : 1, "$lte" : 5 } } }'; --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$gt" : 5 } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAllSet" : 1, "$lte" : 5 } } }'; --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$gt" : 5 } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a":{ "$elemMatch" : { "$bitsAnySet" : 1, "$lte" : 5 } } }'; --insert multiple field in document SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0, "b":3}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1, "b":2}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2, "b":1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 3, "b":0}', NULL); --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllClear" : 2 } }'; --Test with non exist field or on multi field document $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnyClear" : 2 } }'; --Test with non exist field or on multi field document $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAllSet" : 2 } }'; --Test with non exist field or on multi field document $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "c": { "$bitsAnySet" : 2 } }'; --Test on array of array SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": [[1,2,3],[3,2,1]]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": [[1,3,5],[5,3,1]]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,2,4],[4,2,0]]}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": [[0,0,0],[0,0,0]]}', NULL); --Test with bitmask $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 2 } }'; --Test with bitmask $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; --Test with bitmask $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 2 } }'; --Test with bitmask $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 2 } }'; --Multiple Bits Operator Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 2}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 3}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 4}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": 5}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": 6}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 8, "a": 7}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 9, "a": 8}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 10, "a": 9}', NULL); SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$bitsAllSet" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$bitsAllClear" : 1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 3, "$bitsAnyClear" : 3 } }'; --Decimal 128 Test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 0, "a": { "$numberDecimal" : "0" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": { "$numberDecimal" : "1" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": { "$numberDecimal" : "1.1234" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": { "$numberDecimal" : "1.0000" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": { "$numberDecimal" : "2.0020" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": { "$numberDecimal" : "3.0000" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 6, "a": { "$numberDecimal" : "NaN" }}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 7, "a": { "$numberDecimal" : "Infinity" }}', NULL); SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0" }, { "$numberDecimal" : "1" }] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ { "$numberDecimal" : "0.112"}, { "$numberDecimal" : "1.321" }] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1"} } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.000"} } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.000"} } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "0"} } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "0.000"} } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "0.000"} } }'; -- double range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-whole", "a" : { "$numberDouble" : "42.0" } }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-zero", "a" : { "$numberDouble" : "0.0"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-big", "a" : { "$numberDouble" : "2305843009213693952.0"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-1", "a" : { "$numberDouble" : "-9223372036854775808"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-2", "a" : { "$numberDouble" : "-123456789"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-3", "a" : { "$numberDouble" : "123456789"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-4", "a" : { "$numberDouble" : "9223372036854775807"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDouble" : "9223372036854775807"}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDouble" : "1.7976931348623157e+308"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDouble" : "5e-324"} }', NULL); SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; -- decimal range test SELECT documentdb_api.delete('db', '{"delete":"bitwiseOperators", "deletes":[{"q":{},"limit":0}]}'); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-whole", "a" : { "$numberDecimal" : "42.0" } }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-zero", "a" : { "$numberDecimal" : "0.0"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-big", "a" : { "$numberDecimal" : "2305843009213693952.0"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-1", "a" : { "$numberDecimal" : "-9223372036854775808"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-2", "a" : { "$numberDecimal" : "-123456789"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-3", "a" : { "$numberDecimal" : "123456789"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "decimal-4", "a" : { "$numberDecimal" : "9223372036854775807"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "int64-max", "a" : { "$numberDecimal" : "9223372036854775807"}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-max", "a" : { "$numberDecimal" : "1.7976931348623157e+308"} }', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{ "_id": "double-smallest", "a" : { "$numberDecimal" : "5e-324"} }', NULL); SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "0" } } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5] } }'; bson_dollar_ops_query_bits_tests_explain.sql000066400000000000000000000213661507310017400401110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 9500000; SET documentdb.next_collection_id TO 9500; SET documentdb.next_collection_index_id TO 9500; SELECT documentdb_api.create_collection('db', 'bitwiseOperators'); --insert data SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 1, "a": 0}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 2, "a": 1}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 3, "a": 54}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 4, "a": 88}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id": 5, "a": 255}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"9", "a": {"$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','bitwiseOperators','{"_id":"10", "a": {"$binary": { "base64": "AANgAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"}}}', NULL); -- Explain Plan on runtime SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bitwiseOperators'); BEGIN; set local enable_seqscan TO ON; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; --$bitsAllClear runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAnyClear runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAllSet runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAnySet runtime EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; END; -- Explain Plan on Index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bitwiseOperators', 'index_1', '{"a": 1}'), TRUE); BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; --$bitsAllClear Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAnyClear Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAllSet Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; --$bitsAnySet Index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 0} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 1, "$lt": 10} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [1,5,7]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$binary": { "base64": "AAyfAAAAAAAAAAAAAAAAAAAAAAAA", "subType": "01"} } } }'; END;bson_dollar_ops_query_bits_tests_index.sql000066400000000000000000000176301507310017400375570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 420000; SET documentdb.next_collection_id TO 4200; SET documentdb.next_collection_index_id TO 4200; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.create_collection('db', 'bitwiseOperators'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bitwiseOperators', 'index_1', '{"a": 1}'), TRUE); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bitwiseOperators'); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_bits_tests_core.sql; ROLLBACK; --Negative Test Cases $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllClear": 1}} } ] }', TRUE); --Negative Test Cases $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnyClear": 1}} } ] }', TRUE); --Negative Test Cases $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllSet": 1}} } ] }', TRUE); --Negative Test Cases $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "-1" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "NaN" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "Infinity" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnySet": 1}} } ] }', TRUE); --drop collection SELECT drop_collection('db','bitwiseOperators'); bson_dollar_ops_query_bits_tests_runtime.sql000066400000000000000000000172501507310017400401310ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 420000; SET documentdb.next_collection_id TO 4200; SET documentdb.next_collection_index_id TO 4200; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.create_collection('db', 'bitwiseOperators'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','bitwiseOperators'); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO on; \i sql/bson_dollar_ops_query_bits_tests_core.sql; ROLLBACK; --Negative Test Cases $bitsAllClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllClear" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllClear": 1}} } ] }', TRUE); --Negative Test Cases $bitsAnyClear SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnyClear" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnyClear": 1}} } ] }', TRUE); --Negative Test Cases $bitsAllSet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "-1" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAllSet": 1}} } ] }', TRUE); --Negative Test Cases $bitsAnySet SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : -1 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 23.04 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : "NegTest" } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : 99999999999 } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ 99999999999 ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : [ "NegTest" ] } }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "99999999999" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "1.0232" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "-1" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAnySet" : { "$numberDecimal" : "NaN" }} }'; SELECT document FROM documentdb_api.collection('db', 'bitwiseOperators') WHERE document @@ '{ "a": { "$bitsAllSet" : { "$numberDecimal" : "Infinity" }} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bitwiseOperators", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": {"a": {"$bitsAnySet": 1}} } ] }', TRUE); --drop collection SELECT drop_collection('db','bitwiseOperators');bson_dollar_ops_query_mod_tests_core.sql000066400000000000000000000317071507310017400372170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; -- Basic SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 100, "a": 10}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 101, "a": [10, 11]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 200, "a": -10}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 201, "a": [-10, -11]}', NULL); -- nested and empty arrays. These docs should not be in result set as $mod can not be applied on arr of arr SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 300, "a": []}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 301, "a": [[]]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 302, "a": [[[10, 11], [5]]]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 303, "a": [[[-10, -11], [-5]]]}', NULL); -- nested objects SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 102, "a": {"b": 10}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 103, "a": {"b": [10, 11]}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 104, "a": {"b": [10, 11], "c": 11}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 105, "a": {"b": { "c": [10, 11] }}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 202, "a": {"b": -10}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 203, "a": {"b": [-10, -11]}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 204, "a": {"b": [-10, -11], "c": -11}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 205, "a": {"b": { "c": [-10, -11] }}}', NULL); -- documents inside array SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 106, "a": [ {"b": 10}, {"c": 11}]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 206, "a": [ {"b": -10}, {"c": -11}]}', NULL); --various numeric types SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 107, "a": {"$numberInt" : "10"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 108, "a": {"$numberLong" : "10"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 109, "a": {"$numberDouble" : "10.4"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 110, "a": {"$numberDecimal" : "10.6"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 207, "a": {"$numberInt" : "-10"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 208, "a": {"$numberLong" : "-10"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 209, "a": {"$numberDouble" : "-10.4"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 210, "a": {"$numberDecimal" : "-10.6"}}', NULL); -- Min Max Boundary -- Int32 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 130, "a": {"$numberInt" : "2147483647"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 131, "a": {"$numberInt" : "-2147483648"}}', NULL); -- Int64 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 132, "a": {"$numberLong" : "9223372036854775807"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 133, "a": {"$numberLong" : "-9223372036854775808"}}', NULL); -- Double - (double only takes 15 significand digits) SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 134, "a": {"$numberDouble" : "922337203685477e4"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 135, "a": {"$numberDouble" : "-922337203685477e4"}}', NULL); -- Decimal128 SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 136, "a": {"$numberDecimal" : "9223372036854775807"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 137, "a": {"$numberDecimal" : "-9223372036854775808"}}', NULL); -- Decimal128 - values that are more than 64 bits SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 140, "a": {"$numberDecimal" : "9223372036854775807.5"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 141, "a": {"$numberDecimal" : "9223372036854775808"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 142, "a": {"$numberDecimal" : "-9223372036854775808.5"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 143, "a": {"$numberDecimal" : "-9223372036854775809"}}', NULL); -- non-numeric fields SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 310, "a": true}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 311, "a": false}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 312, "a": "Hello"}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 313, "a": ["Hello", "World"]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 314, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 315, "a": { "$date": { "$numberLong" : "1234567890000" }}}', NULL); -- objects with null and NaN SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 121, "a": 0}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 122, "a": null}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 123, "a": NaN}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 124, "a": [10, null]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 125, "a": [null]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 126, "a": [null, NaN]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 127, "a": {"$numberDecimal" : "NaN"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 221, "a": [-10, NaN]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests','{"_id": 222, "a": [-0, -0.0]}', NULL); -- Test for $mod with positive divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; -- Test for $mod with negative divisor and 0 remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-5,0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-5,0]} }'; -- Test for $mod with positive divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,2]} }'; -- Test for $mod with positive divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; -- Test for $mod with negative divisor and positive remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,2]} }'; -- Test for $mod with negative divisor and negative remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [-3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b" : {"$mod" : [-3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.c" : {"$mod" : [-3,-2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a.b.c" : {"$mod" : [-3,-2]} }'; -- Tests where Positive Divisor is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "5"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-5"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.0"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-5.0"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "3"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-3"}, -2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.0"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-3.0"}, -2]} }'; -- Tests where remainder is different types of numeric SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberInt" : "-2"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberLong" : "2"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "-2.0"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "2.0"}]} }'; -- Tests where Divisor is not a decimal number SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "5.2"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-3.5"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "3.9"}, {"$numberDouble" : "-2.0"}]} }'; -- Tests for overflow check. If Dividend is INT_MAX and divisor is -1, mod operation should not overflow SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "1"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-1"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-1"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-1.0"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-1.0"}, 0]} }'; -- Tests for overflow check. Divison if INT_MIN/MAX value SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "2147483647"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberInt" : "-2147483648"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "9223372036854775807"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') where document @@ '{ "a" : {"$mod" : [{"$numberLong" : "-9223372036854775808"}, 0]} }'; bson_dollar_ops_query_mod_tests_explain.sql000066400000000000000000000132231507310017400377200ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 9600000; SET documentdb.next_collection_id TO 9600; SET documentdb.next_collection_index_id TO 9600; --insert data SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 100, "a": 10}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 201, "a": [-10, -11]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 302, "a": [[[10, 11], [5]]]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 104, "a": {"b": [10, 11], "c": 11}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 105, "a": {"b": { "c": [10, 11] }}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 202, "a": {"b": -10}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 204, "a": {"b": [-10, -11], "c": -11}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 106, "a": [ {"b": 10}, {"c": 11}]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 110, "a": {"$numberDecimal" : "10.6"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 207, "a": {"$numberInt" : "-10"}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 311, "a": false}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 313, "a": ["Hello", "World"]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 314, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 315, "a": { "$date": { "$numberLong" : "1234567890000" }}}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 123, "a": NaN}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 126, "a": [null, NaN]}', NULL); SELECT documentdb_api.insert_one('db','dollarmodtests_explain','{"_id": 127, "a": {"$numberDecimal" : "NaN"}}', NULL); -- Explain Plan on runtime SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'dollarmodtests_explain'); BEGIN; set local enable_seqscan TO ON; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; END; -- Explain Plan on Index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_a1', '{"a": 1}'), TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_ab1', '{"a.b": -1}'), TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_ac1', '{"a.c": 1}'), TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests_explain', 'index_mod_abc1', '{"a.b.c": -1}'), TRUE); BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [5,0]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.c" : {"$mod" : [3,-2]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'dollarmodtests_explain') where document @@ '{ "a.b.c" : {"$mod" : [3,-2]} }'; END;bson_dollar_ops_query_mod_tests_index.sql000066400000000000000000000100121507310017400373600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 410000; SET documentdb.next_collection_id TO 4100; SET documentdb.next_collection_index_id TO 4100; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'dollarmodtests'); SELECT documentdb_api.create_collection('db', 'dollarmodtests'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('dollarmodtests', 'index_mod_a1', '{"a": 1}'), TRUE); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollarmodtests'); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_dollar_ops_query_mod_tests_core.sql ROLLBACK; -- Error case : Divisor Zero SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [0,2]} }'; -- Error case : Less than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : []} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [2]} }'; -- Error case : More than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [1,2,3]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-1,-2,3,4]} }'; -- Error case : NaN, Inf and overflow (Double & Decimal128) in Divisor SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "9223372036854775808"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "NaN"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "Inf"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-Inf"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "9223372036854775808"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "NaN"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "Inf"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-Inf"}, 1]} }'; -- Error case : NaN, Inf and overflow (Double & Decimal128) in Remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "9223372036854775808"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "NaN"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "-Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "9223372036854775808"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "NaN"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "-Inf"}]} }'; bson_dollar_ops_query_mod_tests_runtime.sql000066400000000000000000000074321507310017400377500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 410000; SET documentdb.next_collection_id TO 4100; SET documentdb.next_collection_index_id TO 4100; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'dollarmodtests'); SELECT documentdb_api.create_collection('db', 'dollarmodtests'); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','dollarmodtests'); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO ON; \i sql/bson_dollar_ops_query_mod_tests_core.sql ROLLBACK; -- Error case : Divisor Zero SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [0,2]} }'; -- Error case : Less than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : []} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [2]} }'; -- Error case : More than 2 args SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [1,2,3]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-1,-2,3,4]} }'; -- Error case : NaN, Inf and overflow (Double & Decimal128) in Divisor SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "9223372036854775808"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "NaN"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "Inf"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDecimal" : "-Inf"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "9223372036854775808"}, 2]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "NaN"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "Inf"}, 0]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [{"$numberDouble" : "-Inf"}, 1]} }'; -- Error case : NaN, Inf and overflow (Double & Decimal128) in Remainder SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "9223372036854775808"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDecimal" : "NaN"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDecimal" : "-Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "9223372036854775808"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [3, {"$numberDouble" : "NaN"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "Inf"}]} }'; SELECT document FROM documentdb_api.collection('db', 'dollarmodtests') WHERE document @@ '{ "a" : {"$mod" : [-3, {"$numberDouble" : "-Inf"}]} }'; bson_dollar_ops_text_search_tests.sql000066400000000000000000000460001507310017400365040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlset search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 7980000; SET documentdb.next_collection_id TO 7980; SET documentdb.next_collection_index_id TO 7980; -- insert some docs SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 1, "a": "this is a cat" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 2, "a": "this is a dog" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 3, "a": "these are dogs" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 4, "a": "these are cats" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 5, "a": "these are catatonic" }'); -- do a $text query. Should fail (there's no index) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; -- create a text index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', TRUE); -- now do a $text query. Should succeed. SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "dog" } }'; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat | dog" } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "cat" } }'; -- invalid queries -- $text on subsequent stages should fail. WITH r1 AS (SELECT bson_dollar_project(document, '{ "a": 1 }') AS document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search')) SELECT document FROM r1 WHERE document @@ '{ "$text": { "$search": "cat" } }'; -- no more than 1 $text: SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$and": [ { "$text": { "$search": "cat" } }, { "$text": { "$search": "dogs" } }] }'; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "a_text" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 11, "topic": "apple", "writer": "Carol", "score": 50, "location": "New York", "published": true }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 12, "topic": "Apple Store", "writer": "Bob", "score": 5, "location": "San Francisco", "published": false }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 13, "topic": "Picking a berry", "writer": "Alice", "score": 90, "location": "London", "published": true }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 14, "topic": "picking", "writer": "Carol", "score": 100, "location": "Berlin", "published": false }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 15, "topic": "apple and berry", "writer": "Alice", "score": 200, "location": "Paris", "published": true }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 16, "topic": "Яблоко", "writer": "David", "score": 80, "location": "Moscow", "published": false }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 17, "topic": "pear and berry", "writer": "Bob", "score": 10, "location": "Madrid", "published": true }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 18, "topic": "Pear with Berry", "writer": "Carol", "score": 10, "location": "Rome", "published": false }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 30, "topic": "Me encanta la miel natural", "writer": "Alice", "score": 10, "location": "Barcelona", "published": true }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "topic": "text" }, "name": "topic_text" } ] }', TRUE); SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "pick apple" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "\"apple store\"" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple -store" } }' ORDER BY object_id; -- TODO: this is incorrect, we aren’t diacritic insensitive by default, it should return more documents. -- See: https://www.postgresql.org/docs/current/unaccent.html SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Ñблоко" } }'; -- this partially works: SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "miel", "$language": "es" } }'; -- invalid language SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "miel", "$language": "xx" } }'; -- try these with the function. SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "apple" } }') ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "pick apple" } }') ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE documentdb_api_internal.bson_dollar_text(document, '{ "": { "$search": "\"apple store\"" } }') ORDER BY object_id; -- shard collection & try the query again SELECT documentdb_api.shard_collection('db', 'bson_dollar_ops_text_search', '{ "_id": "hashed" }', false); SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "pick apple" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "\"apple store\"" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "apple -store" } }' ORDER BY object_id; -- now repeat the above with default_languages. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "topic_text" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 21, "titular": "Manzana", "writer": "xyz", "score": 50 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 22, "titular": "Comprar Manzana", "writer": "efg", "score": 5 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 23, "titular": "Cosechando una baya", "writer": "abc", "score": 90 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 24, "titular": "Cosechar", "writer": "xyz", "score": 100 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 25, "titular": "Manzana con baya", "writer": "abc", "score": 200 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 27, "titular": "Manzana con pera", "writer": "efg", "score": 10 }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 28, "titular": "Manzana con pera y baya", "writer": "xyz", "score": 10 }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "titular": "text" }, "name": "titular_text", "default_language": "es" } ] }', TRUE); SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Cosechar" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Comprando Manzana" } }' ORDER BY object_id; -- now add projection. SELECT bson_dollar_project(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; SELECT bson_dollar_project_find(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana baya cosechar" } }'; SELECT cursorPage, continuation, persistConnection FROM documentdb_api.find_cursor_first_page('db', '{ "find": "bson_dollar_ops_text_search", "filter": { "$text": { "$search": "Manzana baya cosechar" } }, "projection": { "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }} }'); -- pipeline cases SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$project": { "_id": 1 } }, { "$match": { "$text": { "$search": "Manzana baya cosechar" } } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$match": { "$text": { "$search": "Manzana baya cosechar" } } }, { "$sort": { "_id": 1 } } ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "bson_dollar_ops_text_search", "cursor": {}, "pipeline": [ { "$match": { "$text": { "$search": "Manzana baya cosechar" } } }, { "$project": { "_id": 1, "titular": 1, "rank": { "$meta": "textScore" } } } ] }'); -- now add sort SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana Cosechando" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; -- now add project & sort SELECT bson_dollar_project(document, '{ "_id": 1, "titular": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana Comprando baya" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; -- now do group WITH r1 AS (SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "Manzana" } }' ) SELECT BSONMAX(bson_expression_get(document, '{ "": "$score" }')), bson_expression_get(document, '{ "": { "$meta": "textScore" } }') FROM r1 GROUP BY bson_expression_get(document, '{ "": { "$meta": "textScore" } }'); -- scenarios without $text should return 'query requires text score metadata, but it is not available' SELECT bson_dollar_project(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; SELECT bson_dollar_add_fields(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; SELECT bson_dollar_project_find(document, '{ "_id": 1, "headline": 1, "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }'; SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; WITH r1 AS (SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "score": { "$exists": true } }' ) SELECT BSONMAX(bson_expression_get(document, '{ "": "$score" }')) FROM r1 GROUP BY bson_expression_get(document, '{ "": { "$meta": "textScore" } }'); -- test with custom weights. CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "titular_text" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 31, "alpha": "red blue green", "beta": "yellow orange" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 32, "alpha": "yellow orange blue", "beta": "red blue purple" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "alpha": "text" }, "name": "alpha_1", "weights": { "alpha": 10, "beta": 1 } } ] }', TRUE); -- returns 31, 32 SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "red" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; -- Returns 32, 31 SELECT bson_dollar_add_fields(document, '{ "rank": { "$meta": "textScore" }}') FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "orange" } }' ORDER BY bson_orderby(document, '{ "score": {"$meta": "textScore"} }') DESC; -- test wildcard handling -- this is a variant of the JS test: blog_textwild.js CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "alpha_1" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 33, "heading": "my travel story", "content": "this is a new travel blog I am writing. cheers sam" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 34, "heading": "my 2nd story", "content": "this is a new travel blog I am writing. cheers" }'); SELECT documentdb_api.insert_one('db', 'bson_dollar_ops_text_search', '{ "_id": 35, "heading": "mountains are Beautiful for writing sam", "content": "this is a new travel blog I am writing. cheers" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "dummy": "text", "$**": "text" }, "name": "alpha_1" } ] }', TRUE); SELECT document FROM documentdb_api.collection('db', 'bson_dollar_ops_text_search') WHERE document @@ '{ "$text": { "$search": "travel" } }' ORDER BY object_id; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "bson_dollar_ops_text_search", "index": "alpha_1" }'); -- recreate this so that test output for further tests does not change SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "alpha": "text" }, "name": "alpha_1", "weights": { "alpha": 10, "beta": 1 } } ] }', TRUE); -- Test TSQuery generation. SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"mental health\"" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"mental health\" wellbeing nutrition" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "hydrate stretch recover" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\"" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "cardio -training" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "cardio -training -burnout" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" -fatigue -burnout" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout" }'::documentdb_core.bson); SELECT documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); -- this matches SELECT to_tsvector('consistent cardio training with a diet plan improves wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); -- this shouldn't match SELECT to_tsvector('cardio training with a diet plan can lead to fatigue') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); SELECT to_tsvector('stretching improves general wellbeing and focus') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); SELECT to_tsvector('burnout is a risk when doing cardio training without breaks') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); -- Phrase: First one doesn't match, second one does. SELECT to_tsvector('consistent stretching is the cornerstone of wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "\"cardio training\" diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); SELECT to_tsvector('a good diet plan improves long-term wellbeing') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "diet plan -fatigue -burnout wellbeing" }'::documentdb_core.bson); -- Use language check -- synonyms within a language work. SELECT to_tsvector('portuguese', 'Em atualidade, sempre é possível manter-se saudável') @@ documentdb_api_internal.bson_query_to_tsquery('{ "$search": "atualmente", "$language": "pt" }'::documentdb_core.bson); -- Only one text index allowed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search2", "indexes": [ { "key": { "gamma": "text" }, "name": "gamma_text" } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search2", "indexes": [ { "key": { "gamma": "text" }, "name": "gamma_text" } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "bson_dollar_ops_text_search", "indexes": [ { "key": { "desc": "text", "extra": "text" }, "name": "desc_text" } ] }', TRUE); documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_expr_eval_tests.sql000066400000000000000000000334731507310017400340330ustar00rootroot00000000000000set search_path to documentdb_core,documentdb_api,documentdb_api_catalog,pg_catalog; SET citus.next_shard_id TO 400000; SET documentdb.next_collection_id TO 4000; SET documentdb.next_collection_index_id TO 4000; -- test explicit equality operator SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$eq": 2 }', '{ "": 3 }'); -- test $in/$nin SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$in": [ 2, 3, 4] }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$in": [ 2, 3, 4] }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nin": [ 2, 3, 4] }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nin": [ 2, 3, 4] }', '{ "": 3 }'); -- test $gte/$lte SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gte": 4 }', '{ "": 5 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$gt": 4 }', '{ "": 5 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lte": 4 }', '{ "": 5 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$lt": 4 }', '{ "": 5 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$type": "string" }', '{ "": 5 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$type": "string" }', '{ "": "hello" }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": "hello" }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": [ 1, 2 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$size": 3 }', '{ "": [ 1, 2, 3 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$ne": 4 }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$ne": 4 }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$exists": false }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$exists": true }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "someString" }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "aaab" }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": "asomethingb" }'); -- negative test to validate options SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "g" }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "hw" }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": {"$regex": "\\d[3]", "$options": "s"} }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": {"$regex": "\\d[3]", "$options": "x"} }', '{ "": 4 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$regex": "a.*b", "$options": "" }', '{ "": [ "asomethingb" ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": [ "asomethingb" ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "c": "asomethingb" } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "b": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$regex": "a.*b", "$options": "" } }', '{ "": { "b": "asomethingb" } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 7 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 8 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllClear": [ 0, 1, 2 ] }', '{ "": 9 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 7 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 8 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnyClear": [ 0, 1, 2 ] }', '{ "": 9 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 7 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 8 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAllSet": [ 0, 1, 2 ] }', '{ "": 9 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 7 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 8 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$bitsAnySet": [ 0, 1, 2 ] }', '{ "": 9 }'); -- test $and/$or/$nor SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 0 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$or": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 0 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "a": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$and": [{ "b": {"$gte": 1} }, { "b": { "$lte": 2 }}] }', '{ "": { "b": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 0 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": 3 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "a": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 3 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$nor": [{ "b": {"$lt": 1} }, { "b": { "$gt": 2 }}] }', '{ "": { "b": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": 0 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": { "a": 0 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$not": { "$eq": 2 } }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": { "b": 2 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$not": { "$eq": 2 } } }', '{ "": { "b": 1 } }'); -- $elemMatch SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": 1 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": 2 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ 1 ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ [ 2 ] ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$elemMatch": { "$gte": 2 } } }', '{ "": { "b": [ 2 ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": 1 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": 2 }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ 1 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ [ 2 ] ] }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "$elemMatch": { "$gte": 2 } }', '{ "": [ 2 ] }'); -- $all SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 2 ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": 2 } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 3, 7 ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 3, 5, 8 ] } }'); SELECT documentdb_distributed_test_helpers.evaluate_query_expression('{ "b": { "$all": [ 1, 3, 5 ] } }', '{ "": { "b": [ 1, 1, 3, 5 ] } }'); -- projection of the value SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$gt": 2 }', '{ "": [ 0, 1, 2 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$gt": 2 }', '{ "": [ 0, 5, 3, 8 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$in": [ 6, 7, 8] }', '{ "": [ 0, 5, 3, 8 ] }'); SELECT documentdb_distributed_test_helpers.evaluate_expression_get_first_match('{ "$in": [ 6, 7, 8] }', '{ "": [ 0, 5, 3, 1 ] }');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_get_indexes_a.sql000066400000000000000000000102401507310017400334050ustar00rootroot00000000000000set search_path to documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 2100000; SET documentdb.next_collection_id TO 21000; SET documentdb.next_collection_index_id TO 21000; --Test 1 Collection exist with only one Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'total_price_idx', '{"total_price": 1}'), true); SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "order_data" }') ORDER BY 1; --Test 2 Collection exist with multiple Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'shipping_distance_idx', '{"shipping_distance": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'delivery_hours_idx', '{"delivery_hours": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'customer_rating_idx', '{"customer_rating": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'item_count_idx', '{"item_count": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_data', 'to_city_idx', '{"to_city": 1}'), true); SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "order_data" }') ORDER BY 1; --Test 3: Collection not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('orderdb','{ "listIndexes": "nonexistent_collection" }') ORDER BY 1; --Test 4: DB not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('db_not_exist','{ "listIndexes": "order_data" }') ORDER BY 1; --Test 5: DB and collection both does not exist -- SELECT documentdb_api.list_indexes_cursor_first_page('db_not_exist','{ "listIndexes": "nonexistent_collection" }') ORDER BY 1; -- Test 6: Sparse is included in result only when specified: SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"promo_code": 1}, "name": "promo_sparse_idx1", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"order_status": 1}, "name": "status_non_sparse_idx1", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"payment_method": 1}, "name": "payment_idx1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"gift_message": 1}, "name": "gift_idx2", "sparse": 1.0}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"gift_message": 1}, "name": "gift_idx3", "sparse": 0.0}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('sparsedb', '{"createIndexes": "sparse_orders", "indexes": [{"key": {"coupon_code": 1}, "name": "coupon_idx4", "sparse": 0.0, "expireAfterSeconds" : 3600}]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('sparsedb','{ "listIndexes": "sparse_orders" }') ORDER BY 1; -- Test 7: Unique indexes is included if it is specified and true. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "unique_orders", "indexes": [{"key": {"order_number": 1}, "name": "order_idx3", "unique": 0.0}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "unique_orders", "indexes": [{"key": {"tracking_number": 1}, "name": "tracking_idx4", "unique": 1.0, "sparse": 1.0, "expireAfterSeconds" : 5400}]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('uniquedb','{ "listIndexes": "unique_orders" }') ORDER BY 1;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_get_indexes_b.sql000066400000000000000000000035411507310017400334140ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2200000; SET documentdb.next_collection_id TO 22000; SET documentdb.next_collection_index_id TO 22000; -- --Test 1 Compound index test -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('compound_orders', 'comp_index', '{"total_price": 1,"shipping_distance":1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('compound_orders', 'comp_index1', '{"delivery_hours": 1,"customer_rating":1}'), true); select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "compound_orders" }') ORDER BY 1; --Test 2 Descending Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_items', 'test1', '{"item_count": -1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_items', 'test2', '{"to_city": -1}'), true); select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "order_items" }') ORDER BY 1; --Test 3 Ascending Descending Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_shipments', 'test1', '{"promo_code": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('orderdb', documentdb_distributed_test_helpers.generate_create_index_arg('order_shipments', 'test2', '{"order_status": -1}'), true); select documentdb_api.list_indexes_cursor_first_page('orderdb', '{ "listIndexes": "order_shipments" }') ORDER BY 1; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_hash_indexes.sql000066400000000000000000000072241507310017400332610ustar00rootroot00000000000000 SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 530000; SET documentdb.next_collection_id TO 5300; SET documentdb.next_collection_index_id TO 5300; -- insert a document SELECT documentdb_api.create_collection('db', 'queryhashindex'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','queryhashindex'); -- Create a hash index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryhashindex", "indexes": [ { "key" : { "a.b": "hashed" }, "name": "hashIndex" }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryhashindex') ORDER BY collection_id, index_id; SELECT documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "queryhashindex" }') ORDER BY 1; -- Explain various hash index scenarios. BEGIN; set local enable_seqscan to off; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, true ]}'::bson); -- these should not use the index. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_ne(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_gt(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_gte(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_lt(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_lte(document, '{ "a.b": 1 }'); -- null can be pushed down. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": null }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, null ]}'::bson); -- now insert some documents and run the queries above. SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 1 } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 2 } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": 3 } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": "string" } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": null } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": false } }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "c": 1, "a": "c only field" }'); SELECT documentdb_api.insert_one('db', 'queryhashindex', '{ "a": { "b": {"$undefined" : true } } }'); -- null should also get undefined values SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": 1 }'); SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, true ]}'::bson); SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_eq(document, '{ "a.b": null }'); SELECT document -> 'a' FROM documentdb_api.collection('db', 'queryhashindex') WHERE bson_dollar_in(document, '{ "a.b": [ 1, 2, null ]}'::bson); ROLLBACK; bson_index_hints_pushdown_tests.sql000066400000000000000000000216631507310017400362300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 695000; SET documentdb.next_collection_id TO 69500; SET documentdb.next_collection_index_id TO 69500; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('hint_db', 'query_index_hints') IS NOT NULL; SELECT documentdb_api.create_collection('hint_db', 'query_index_hints'); -- create various kinds of indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "name": "a_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "b": 1, "c": 1 }, "name": "b_1_c_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "d": "hashed" }, "name": "d_hashed" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "$**": "text" }, "name": "e_text" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "f": 1 }, "name": "f_1", "sparse": true }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "g.$**": 1 }, "name": "g_1" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "h": 1 }, "name": "h_1", "sparse": true }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "i": 1, "j": 1 }, "name": "i_1_j_1", "unique": true }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "k": 1, "l": 1 }, "name": "k_1_l_1", "sparse": true, "unique": true }] }', true); \d documentdb_data.documents_69501 -- now insert some sample docs SELECT documentdb_api.insert_one('hint_db', 'query_index_hints', '{ "_id": 1, "a": 1, "c": 1 }'); -- query index hints by name - every index works except text index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_1" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "b_1_c_1" }'); -- this pushes to a seqscan because the index is hashed EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "d_hashed" }'); -- this should fail. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "e_text" }'); -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "f_1" }'); -- cannot push to wildcard index since it is a wildcard index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "g_1" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "i_1_j_1" }'); -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "h_1" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "k_1_l_1" }'); -- query index hint by key - works the same as name EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "a": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "b": 1, "c": 1 } }'); -- this pushes to a seqscan because the index is hashed EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "d": "hashed" } }'); -- this should fail. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$**": "text" } }'); -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "f": 1 } }'); -- cannot push to wildcard index since it is a wildcard index EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "g.$**": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "i": 1, "j": 1 } }'); -- pushes as an exists true query since the index is sparse EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "h": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "k": 1, "l": 1 } }'); -- hints when no index exists EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "nonexistent" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "nonexistent": 1 } }'); -- natural hint picks _id index. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$natural": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "$natural": -1 } }'); -- more error cases SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "sparse": true, "name": "a_2" }] }', true); -- fails due to multiple indexes matching. EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": { "a": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_2" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_1" }'); -- try with composite indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_3" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('hint_db', '{ "createIndexes": "query_index_hints", "indexes": [ { "key": { "k": 1, "l": 1 }, "enableCompositeTerm": true, "name": "k_1_l_1-2" }] }', true); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "a_3" }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { "x": 1 }, "hint": "k_1_l_1-2" }'); -- try natural and id hint with no filters on sharded collections. SELECT documentdb_api.shard_collection('hint_db', 'query_index_hints', '{"_id": "hashed"}', FALSE); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { }, "hint": { "$natural": 1 } }'); EXPLAIN (COSTS OFF, VERBOSE OFF, TIMING OFF) SELECT document from bson_aggregation_find('hint_db', '{ "find": "query_index_hints", "filter": { }, "hint": { "_id": 1 } }'); bson_index_rum_index_scan_to_bitmap_heap_scan.sql000066400000000000000000000130071507310017400407600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 50100; SET documentdb.next_collection_id TO 5010; SET documentdb.next_collection_index_id TO 5010; SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 1, "order_id" : "ORD1", "price" : 12, "quantity" : 2 }', NULL); SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan','{ "_id" : 2, "order_id" : "ORD1", "fruit" : "apple", "price" : 20, "quantity" : 1 }', NULL); SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 3, "order_id" : "ORD1", "fruit" : "banana", "price" : 10, "quantity" : 5 }', NULL); SELECT documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "_id" : 4, "order_id" : "ORD1", "fruit" : ["orange", "banana", "apple"], "price" : 10, "quantity" : 5 }', NULL); do $$ begin for r in 1..500 loop PERFORM documentdb_api.insert_one('db','bson_index_rum_index_scan_to_bitmap_heap_scan',' { "order_id" : "ORD1", "fruit" : ["orange", "banana", "apple"], "price" : 10, "quantity" : 5 }', NULL); end loop; end; $$; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','bson_index_rum_index_scan_to_bitmap_heap_scan'); EXPLAIN(costs off) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bson_index_rum_index_scan_to_bitmap_heap_scan", "indexes": [{"key": {"order_id": 1}, "name": "order_id_1"}]}', true); -- Even if there is an index order_id_1, performs BitmapHeapScan instead of Index Scan BEGIN; set local enable_seqscan TO off; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; -- Tets for paralell BitmapHeapScan. Needs all the 5 config and at 500 docs in the collection to enable parallel bitmap scan. BEGIN; set local parallel_tuple_cost TO 0.00001; set local parallel_setup_cost TO 0; set local min_parallel_table_scan_size TO 0; set local min_parallel_index_scan_size TO 0; SET local enable_seqscan to OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) WITH t1 as (SELECT document FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD2" , "$and": [{"timestamp" : { "$lte":2000000}}]}'::bson ) SELECT bson_repath_and_build('rxCount'::text, BSONAVERAGE(document -> 'month')) from t1 group by bson_expression_get(document, '{ "": "$product_name" }'); ROLLBACK; -- IndexScan is overritten by BitmapHeapScan when documentdb_api.forceRumIndexScantoBitmapHeapScan is toggled to off and then to on BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO true; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO off BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO off; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO "off" BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO off; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO false BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO false; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; -- IndexScan is preferred when is turned off via setting documentdb_api.forceRumIndexScantoBitmapHeapScan TO "false" BEGIN; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO "false"; set local enable_bitmapscan TO OFF; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT count(*) FROM documentdb_api.collection('db', 'bson_index_rum_index_scan_to_bitmap_heap_scan') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"order_id": "ORD1" }'::bson LIMIT 10; END; bson_index_selection_tests.sql000066400000000000000000000155171507310017400351420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 50000; SET documentdb.next_collection_id TO 5000; SET documentdb.next_collection_index_id TO 5000; SELECT documentdb_api.create_collection('db', 'indexselection'); -- create a wildcard index on path a.b. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_a_b', '{"a.b.$**": 1}'), true); -- create a non wildcard index on path 'b.c' SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_b_c', '{"b.c": 1}'), true); -- create a wildcard projection index with include paths at specific trees 'd.e.f' and 'g.h' SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexselection", "indexes": [ { "key": { "$**": 1 }, "name": "indexsel_path_wild_def_gh", "wildcardProjection": { "d.e.f": 1, "g.h": 1 } }]}', true); -- create two overlapping indexes. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_overl_2', '{"r.s.$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'indexsel_path_overl_1', '{"r.s.t": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indexselection', 'some_long_index_name_that_is_definitely_over_64_characters_to_test_explain_index_name_length', '{"randomPath": 1}'), true); -- create a wildcard projection index that excludes all the above paths. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexselection", "indexes": [ { "key": { "$**": 1 }, "name": "indexsel_path_wild_excl_1", "wildcardProjection": { "d": 0, "g": 0, "a": 0, "b": 0, "r": 0, "randomPath": 0 } }]}', true); \d documentdb_data.documents_5000 BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; -- now explain queries -- filter on a.b - should select indexsel_path_a_b EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b.c.d": { "$gte" : 1 }}'; -- does not match a_b (sequential scan) EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.bar": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a": { "$gte" : 1 }}'; -- path root at is not exactly 'a' - matches excl_1. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "abc": { "$gte" : 1 }}'; -- filter on b.c - should select indexsel_path_b_c EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c": { "$gte" : 1 }}'; -- not a wildcard - does not match. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.car": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c.d": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b": { "$gte" : 1 }}'; -- wildcard matches a projection EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "d.e.f.g": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g.1": { "$gte" : 1 }}'; -- any other root paths or nested paths match the wildcard projection index. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "e": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "k.l.m": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "graph": { "$gte" : 1 }}'; -- on the overlapping indexes, last path wins. EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "r.s.t": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "r.s.u.1": { "$gte" : 1 }}'; -- intersect two indexes EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "$and": [ { "a.b.c.d": { "$gte" : 1 } }, { "b.c": 2 } ]}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "$or": [ { "a.b.c.d": { "$gte" : 1 } }, { "b.c": 2 } ]}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "randomPath": 1 }'; -- now insert documents that match each of the filters -- matches a.b SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 1, "a" : { "b" : { "c": 1 } } }', NULL); -- matches b.c SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 2, "b" : { "c" : 0 }}', NULL); -- matches g.h SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 3, "g" : { "h" : { "i" : 0 } } }', NULL); -- matches wildcard SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 4, "k" : { "l" : { "m" : 0 } } }', NULL); -- matches none. SELECT documentdb_api.insert_one('db','indexselection', '{"_id": 5, "g" : 2 }', NULL); -- now query each one to see documents being returned. SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "a.b.c" : 1 }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "b.c" : { "$eq": 0 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g.h.i" : { "$gt": -1 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "k.l.m" : { "$lt": 1 } }'; SELECT COUNT(*) FROM documentdb_api.collection('db', 'indexselection') WHERE document @@ '{ "g" : { "$exists": 1 } }'; ROLLBACK; bson_index_term_generation.sql000066400000000000000000001321311507310017400351050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 370000; SET documentdb.next_collection_id TO 3700; SET documentdb.next_collection_index_id TO 3700; -- now get terms for a simple document ( { a: { b : 1 }}) -- test root, 'a', 'a.b', 'a.b.1' with wildcard/non-wildcard SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b.1', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b.1', false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '[ "a", "d" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 8, "a" : [0, 1, 2]}', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', '[ "a.b" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', '[ "a.b" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', '[ "a.b.0", "a.b.1" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', '[ "a.b.0", "a.b.1" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', '[ "a.b.0", "a.b.1" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a" ]', true, false); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, false); --Nested Array or Array has document SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [{"b" : "old"}] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [[{"b" : "old"}]] }', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 10, "a" : [[1,{"b" : "old"},3]] }', '', true); -- generate terms with and without truncation -- string SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 1000); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ33"}', '', true, true, false, 2500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdLdlmMgxCMBE7wYDrvtfhGZymTmmjdCJ28ka0fnN47BeKymTmmjdCJ28ka0CPRgeDPGOR4FTVP0521ulBAnAdoxuboxub63"}', '', true, true, false, 45); -- binary SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 45); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 100); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 20); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$binary": { "base64": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "subType": "00" } } }', '', true, true, false, 500); -- code SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 40); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 20); -- symbol SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 40); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$symbol": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=" } }', '', true, true, false, 20); -- regex SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 50); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "" } } }', '', true, true, false, 20); -- regex with options SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "imxs" } } }', '', true, true, false, 500); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$regularExpression": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "options": "imxs" } } }', '', true, true, false, 50); -- codewscope SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$code": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "$scope": { "a": "b" } } }', '', true, true, false, 50); -- dbref SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "$ref": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "$id": { "a": "b" } } }', '', true, true, false, 50); -- object SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : { "field": { "pattern": "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "field2": "short field" } } }', '', true, true, false, 50); -- array SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "a" : [ "cDg2UFhxR3B5a2dGNHByRjlYMG91R1ZHN21rUkdnOVp5WFp3dDI1TDQ5dHJHNUlRWGdySGRrUjAxWktTQmxadjhTSDA0WFV5Y2g2YzBITnZTNkRuMTdSeDNKZ0tZTUZxeFNUeWhSWkxkbG1NZ3hDTUJFN3dZRHJ2dGZDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZExkbG1NZ3hDTUJFN3dZRHJ2dGZoR1p5bVRtbWpkQ0oyOGthMGZuTjQ3QmVLeW1UbW1qZENKMjhrYTBDUFJnZURQR09SNEZUVlAwNTIxdWxCQW5BZG94dWJveHViNjM=", "short field" ] }', '', true, true, false, 50); -- Section for unique index terms SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', 'a.b', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "c" : 2 } ] }', 'a.b', false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : null } ] }', 'a.b', false, true); -- addMetadata true SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '', true, false, true); SELECT documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', '[ "a.b" ]', true, false, true); -- add array ancestor for wildcard SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id":"7", "a" : [ { "b": { "c": 1 } } ] }', 'a', true); -- test when non exists term generation is off should generate min key root term BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "a" : 1 }', 'b', true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "a" : 1 }', 'b', false); COMMIT; SELECT documentdb_api.create_collection('db', 'indextermgeneration'); -- create all of these indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_1', '{"$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_2', '{"a.b.$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_path_3', '{"a.b": 1}'), true); -- create a compound index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('indextermgeneration', 'indexgen_comp_path_1', '{"a.b": 1, "a.c": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indextermgeneration", "indexes": [ { "key": { "$**": 1 }, "name": "indexgen_wildcard_1", "wildcardProjection": { "a.b": 1 } }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indextermgeneration", "indexes": [ { "key": { "$**": 1 }, "name": "indexgen_wildcard_2", "wildcardProjection": { "a.b": 0, "a.c": 0 } }]}', true); \d documentdb_data.documents_3700 -- now insert some documents - we still can't query it at this point but this is a sanity validation. SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','indextermgeneration', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); bson_index_truncation_binary_tests.sql000066400000000000000000000666241507310017400367140ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, documentdb_core; SET citus.next_shard_id TO 1150000; SET documentdb.next_collection_id TO 11500; SET documentdb.next_collection_index_id TO 11500; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_binary_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11500 -- Insert binary BSON data with all subtypes SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 1, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 2, "ikey": { "$binary" : { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 3, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 4, "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 5, "ikey": { "$binary" : { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 6, "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } }, "item": "F", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 7, "ikey": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } }, "item": "G", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 8, "ikey": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "00" } } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 9, "ikey": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "04" } }, "item": "H", "customKey": 8 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests', '{ "_id": 10, "ikey": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, "item": "H", "customKey": 9 }'); /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11500) docs; /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11500) docs; /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "04" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "07" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "01" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary": { "base64": "eyAiYSI6IDEsICJiIjogMyB9", "subType" : "06" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } }'; /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "00" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$gte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lt": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$lte": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; /* $in/$nin/$ne/$all (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$ne": { "$binary" : { "base64": "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } }, { "$binary" : { "base64": "MTIzNDUxMjM0NQ==", "subType" : "07" } }] } }'; /* $bitsAllClear (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 0 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 1 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 32 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 54 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 0 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 1 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 32 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": 54 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllClear": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; /* $bitsAllClear (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnyClear": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; /* $bitsAllSet (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "YWJvYm9yYQ==", "subType": "05"}} } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 1 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 32 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 54 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "YWJvYm9yYQ==", "subType": "05"}} } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 1 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 32 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": 54 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAllSet": { "$binary": { "base64": "////////////////////////////", "subType": "02"} } } }'; /* $bitsAnySet (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": 0 } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n", "subType" : "01" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "YWJvYm9yYQ==", "subType" : "05" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": { "$binary" : { "base64": "////////////////////////////", "subType" : "02" } } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests') WHERE document @@ '{ "ikey": { "$bitsAnySet": 0 } }'; -- insert binary BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_binary_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11501 SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_binary_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'); /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11501) docs; /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } }]]] } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_binary_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$binary" : { "base64": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=", "subType" : "00" } } } } } ]]]]]], "item": "A" }'; bson_index_truncation_code_tests.sql000066400000000000000000000422561507310017400363350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1160000; SET documentdb.next_collection_id TO 11600; SET documentdb.next_collection_index_id TO 11600; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_code_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11600 -- Insert code BSON data SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 1, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 2, "ikey": { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 3, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 4, "ikey": { "$code" : "YWJvYm9yYQ==" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 5, "ikey": { "$code" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 6, "ikey": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "F", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 7, "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 8, "ikey": { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 9, "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "H", "customKey": 8 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests', '{ "_id": 10, "ikey": { "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item": "H", "customKey": 9 }'); /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11600) docs; /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11600) docs; /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiYSI6IDEsICJiIjogMyB9" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "YWJvYm9yYQ==" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "eyAiYSI6IDEsICJiIjogMyB9" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$code" : "YWJvYm9yYQ==" } }'; /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "YWJvYm9yYQ==" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gt": { "$code" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$gte": { "$code" : "YWJvYm9yYQ==" } } }'; /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "YWJvYm9yYQ==" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lt": { "$code" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$lte": { "$code" : "YWJvYm9yYQ==" } } }'; /* $in/$nin/$ne/$all (all terms truncated) */ -- TODO upgrade libbson to fix seg fault errors -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "YWJvYm9yYQ==" } } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; -- SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "YWJvYm9yYQ==" } } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$ne": { "$code" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; -- EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$code" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$code" : "MTIzNDUxMjM0NQ==" }] } }'; -- insert $code BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_code_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11601 SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_code_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'); /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11601) docs; /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "a": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }]]] } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_code_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$code" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; bson_index_truncation_index_tests.sql000066400000000000000000002434211507310017400365270ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 640000; SET documentdb.next_collection_id TO 6400; SET documentdb.next_collection_index_id TO 6400; -- Set configs to something reasonable for testing. set documentdb.indexTermLimitOverride to 100; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); -- now we have an index with truncation enabled and 100 chars. \d documentdb_data.documents_6400; -------------------------- ---- DATA TYPE: UTF8 -------------------------- SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end"}', '', true, true, false, 100) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end"}', 'ikey', false, true, false, 100) term; -- now insert some documents that don't exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 1, "ikey": "this is a string that does not violate the index term limit" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 2, "ikey": "this is another string that doesnt violate the index term limit" }'); -- now insert some documents that technically do violate the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 3, "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 4, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); -- only changes beyond the index term limit SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 5, "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 6, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'); -- this is less than _id: 6 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 7, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" }'); -- this is less than _id: 7 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 8, "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" }'); -- now that they've succeeded query all of them. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does not violate the index term limit" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that doesnt violate the index term limit" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit in strings and changes the end" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" }'; -- test $gt -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a" } }'; -- all "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is aa" } }'; -- no strings SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that doesnt violate the index term limit" } }'; -- all long strings with 'another' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit" } }'; -- only the string that has the change in the end & the one that doesnt' violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; -- only the one with 'in' and 'of' in the suffix & the one that doesn't violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; -- test $gte -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is a" } }'; -- all "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is aa" } }'; -- unlike $gt with no strings - this returns the equality on that exact string. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that doesnt violate the index term limit" } }'; -- all strings with 'another' (unlike $gt since we have $eq as well) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit" } }'; -- all strings but this one SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; -- all but 'in' and 'of' in the suffix & the one that doesn't violate the index term limit. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; -- test $lt -- no records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is a" } }'; -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is b" } }'; -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is aa" } }'; -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit" } }'; -- Matches all that are "this is a string". Also matches all the 'another' strings that are 'after', 'in', but not 'of' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; -- Matches all that are "this is a string". SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; -- test $lte -- no records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is a" } }'; -- all records SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is b" } }'; -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is aa" } }'; -- all that are not "this is another string ..." SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit" } }'; -- All strings except 'this is another string that doesnt' SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; -- Matches all that are "this is a string" & equality on exact match on the string. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; -- $range -- repeat checks with $gt/$lt SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lt": "this is an" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is a string that does not violate the index term limit" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is another string that does not violate the index term limit" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": "this is a", "$lte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end", "$lt": "this is another string that does violate the index term limit as it goes much over the 100 character limit of strings and changes the end" } }'; -- $in SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" ] } }'; -- $ne SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" } }'; -- $nin SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ "this is a string that does not violate the index term limit", "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "this is another string that does violate the index term limit as it goes much over the 100 character limit after strings and changes the end" ] } }'; -- $regex scenarios SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ "this is a string that does not violate the index term limit", { "$regex": "the end$", "$options": "" } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$regex": "the end$", "$options": "" } }'; -- $all scenarios SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ "this is a string that does not violate the index term limit", { "$regex": "\\s+", "$options": "" } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ { "$regex": "\\d+", "$options": "" }, { "$regex": "\\s+another\\s+", "$options": "" } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ "this is a string that does not violate the index term limit" ] } }'; -------------------------- ---- DATA TYPE: Array -------------------------- -- with 60 byte truncation limit, the real limit is 60-21 = 39 bytes. We can tolerate any entries over 39 bytes as long as they're also marked truncated. -- the base structural overhead for an array is 5 (bson Doc) + 2 (path) + 1 (typecode) + 5 (array header) = 13 bytes -- each path takes 2-4 characters (index as a string), 1 byte (type code) + path Value (variable) = 3-5 bytes + valueLength -- track truncation with simple int4 -- empty array (13 bytes) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ ]}'::bson, 'ikey', false, true, true, 60) term; -- int array: int overhead = 3 + sizeof(int) = 7 -- Expectation is 13 bytes of overhead + (2 * 7) = 27 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 1))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (3 * 7) = 34 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 2))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (4 * 7) = 41 bytes -> 41 bytes and truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 3))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (5 * 7) = 51 bytes -> 41 bytes and truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s ]}', repeat(', 1234', 4))::bson, 'ikey', false, true, true, 60) term; -- track truncation with bools: size overhead = 3 + sizeof(bool) = 4 -- Expectation is 13 bytes of overhead + (4 * 4) = 29 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 3))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (5 * 4) = 33 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', false', 4))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (6 * 4) = 37 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 5))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (7 * 4) = 41 bytes -> 41 bytes (truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 6))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (8 * 4) = 45 bytes -> 41 bytes (truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s ]}', repeat(', true', 7))::bson, 'ikey', false, true, true, 60) term; -- decimal128 overhead = 3 + sizeof(decimal128) = 19 bytes -- Expectation is 13 bytes of overhead + (1 * 19) = 32 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; -- 2 decimal128 : 13 + 38 = 51 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; -- 3 decimal128 : 13 + 57 = 70 bytes-> 51 bytes SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; -- decimal 127 + bool (truncated at decimal128) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }, false]}'::bson, 'ikey', false, true, true, 60) term; -- bool + decimal128 (truncated but has all values) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : [ false, { "$numberDecimal": "129e400" }, { "$numberDecimal": "129e400" }]}'::bson, 'ikey', false, true, true, 60) term; -- 5 bool + int: Expected is 13 + (5 * 4) + 7 = 33 + 7 = 40 -> Truncated with all values SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s, 1234 ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; -- 5 bool + decimal128: Expected is 13 + (5 * 4) + 19 = 33 + 19 = 52 -> Truncated with all values SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ false %s, { "$numberDecimal": "129e400" } ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; -- array with mixed fixed + variable. SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberDecimal": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberInt": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ { "$numberLong": "1234" }, "This is a string that needs to be truncated after an integer term in an array" ]}', repeat(', true', 4))::bson, 'ikey', false, true, true, 60) term; -- Expectation is 13 bytes of overhead + (3 * 7) = 34 bytes + 1 bools == 38 bytes. Now add a string - it shouldn't fail since it will still go over the soft limit of 39 SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : [ 1234 %s, true, "abcde" ]}', repeat(', 1234', 2))::bson, 'ikey', false, true, true, 60) term; -- start fresh with arrays SELECT documentdb_api.drop_collection('db','index_truncation_tests'); set documentdb.indexTermLimitOverride to 60; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_6401 -- empty array SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 1, "ikey": [] }'); -- bool arrays SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{ "_id": 2, "ikey": [ false ] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 3, "ikey": [ false %s ] }', repeat(', true', 3))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 4, "ikey": [ false %s ] }', repeat(', true', 4))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 5, "ikey": [ false %s ] }', repeat(', true', 5))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{ "_id": 6, "ikey": [ false %s ] }', repeat(', true', 6))::bson); -- int arrays SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 7, "ikey" : [ 1234 %s ]}', repeat(', 1234', 1))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 8, "ikey" : [ 1234 %s ]}', repeat(', 1234', 2))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 9, "ikey" : [ 1234 %s ]}', repeat(', 1234', 3))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 10, "ikey" : [ 1234 %s ]}', repeat(', 1234', 4))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 21, "ikey" : [ 1234 %s, 3457 ]}', repeat(', 1234', 4))::bson); -- decimal array SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 11, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 1))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 12, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 2))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 13, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 3))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 14, "ikey" : [ { "$numberDecimal": "1234" } %s ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 15, "ikey" : [ { "$numberDecimal": "1234" } %s, 2345 ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 16, "ikey" : [ { "$numberDecimal": "1234" } %s, 3456 ]}', repeat(', { "$numberDecimal": "1234" }', 4))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 17, "ikey" : [ { "$numberDecimal": "1e406" } %s ]}', repeat(', { "$numberDecimal": "1e406" }', 1))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 18, "ikey" : [ { "$numberDecimal": "1e406" } %s ]}', repeat(', { "$numberDecimal": "1e406" }', 2))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 19, "ikey" : [ { "$numberDecimal": "1e406" } %s, 1 ]}', repeat(', { "$numberDecimal": "1e406" }', 3))::bson); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', FORMAT('{"_id": 20, "ikey" : [ { "$numberDecimal": "1e406" } %s, 5 ]}', repeat(', { "$numberDecimal": "1e406" }', 4))::bson); -- mixed types SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 22, "ikey" : [ 1234, 1234, "This is a string after the numbers" ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 23, "ikey" : [ { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" }, "This is a string after the numbers" ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 24, "ikey" : [ "String before", 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 25, "ikey" : [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 26, "ikey" : [ "String before", 1234, 1234, "This is a string after the numbers" ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 27, "ikey" : [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" }, "This is a string after the numbers" ]}'); -- test $eq SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false, true, true, true, true, true, false ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ false, true, true, true, true, true, true ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234 ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234, 1234 ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, 1234, 1234, 1234, 3457 ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, 1 ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, { "$numberDecimal": "1e406" }, 2 ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ 1234, 1234, "This is a string after the numbers" ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ "String before", { "$numberDecimal": "1234" }, { "$numberDecimal": "1234" } ] }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": [ "String before", { "$numberLong": "1234" }, { "$numberLong": "1234" }, "This is a string after the numbers" ] }'; -- test $gt/$gte SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ false, true, true, true, true, true, false ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ false, true, true, true, true, true, true ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 1233 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 1234, 1234, 1234, 1234, 1234, 3000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, 1234, 1234, 1234, 3457 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, "This is a string after the numbers greater" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 1234, 1234, "This is a string after the number" ] } }'; -- $size SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 1 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 2 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 3 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 4 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 5 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 6 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 7 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$size": 8 } }'; -- $all SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, 3457 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, "This is a string after the numbers" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ 1234, { "$regex": ".+string.+numbers", "$options": "" } ] } }'; -- $all with $elemMatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$elemMatch": { "$gt": 1000, "$lt": 2000 } }, { "$elemMatch": { "$gt": 2000, "$lt": 3000 } } ] } }'; -- $elemMatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$gt": 3000, "$lt": 4000 }} }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$all": [ 2345 ] }} }'; DELETE FROM documentdb_data.documents_6401; -- Specific operator tests. -- $gt BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ null, 2345 ] } }'; -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2340, 2345 ] } }'; -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2344, 1235 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234 ] } }'; ROLLBACk; BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ null, 2345 ] } }'; -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2340, 2345 ] } }'; -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2344, 1235 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234 ] } }'; ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); -- 31, 32, 34, 35 have values in position 4 that would be > and match, 36 matches on the last index. Only 33 is a mismatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; -- Now only 31, 32, 34, 35 match SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 2 ] } }'; ROLLBACK; -- integer + string + integer. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars", 2 ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, { "$maxKey": 1 } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, { "$maxKey": 1 } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some maximal string" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some large string that should theoretically" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then less", -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 1 ] } }'; ROLLBACK; -- $lt BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ true, 2345 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2340, 2345 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2346, 2345 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2344, 1235 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, 1234, 1234 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234 ] } }'; ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1449" } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": [ 2345, 1234, 1234, { "$numberInt": "1450" }, 0 ] } }'; ROLLBACK; -- $gte BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ null, 2345 ] } }'; -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2340, 2345 ] } }'; -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2344, 1235 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234 ] } }'; ROLLBACk; BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2344" }, 1234, 1234, 1234, 1234 ]}'); -- both are greater (null < numbers) SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ null, 2345 ] } }'; -- both are bigger than 2340 SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2340, 2345 ] } }'; -- only the 1st doc matches SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2344, 1235 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234 ] } }'; ROLLBACk; -- from above, for int arrays, the 5th integer is lost in truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); -- now insert some via Decimal128 - 37 matches 36, 38 matches 32 SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ { "$numberDecimal": "2345" }, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ { "$numberDecimal": "2345" }, 1234, { "$numerDouble": "1234" }, { "$numberDecimal": "1451" } ]}'); -- 31, 32, 34, 35 have values in position 4 that would be > and match, 36 matches on the last index. Only 33 is a mismatch SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 0 ] } }'; -- Now only 31, 32, 34, 35 match SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 2 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, 1234, 1234, { "$numberInt": "1449" }, 1 ] } }'; ROLLBACK; -- integer + string + integer. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars", 2 ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345, { "$maxKey": 1 } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, { "$maxKey": 1 } ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some maximal string" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some large string that should theoretically" ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ 2345.1, "Some large string that should theoretically go over 60 chars", 1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then less", -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", -1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 0 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": [ { "$numberDecimal": "2345.1" }, "Some large string that should theoretically go over 60 chars and then some", 1 ] } }'; ROLLBACK; -- $in/$nin/$ne/$all(eq) BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" } ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" } ]}'); -- the "1" would not be in the index term. SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, { "$numberInt": "1450" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, { "$numberDecimal": "1451" }, 1 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ [ 2345, 1234, 1234, { "$numberInt": "1450" } ], [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ [ 2345, 1234, 1234, { "$numberInt": "1450" } ], [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ [ 2345, 1234, 1234, { "$numberDouble": "1449" }, 1 ] ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$all": [ { "$elemMatch": { "$eq": 1 }}, { "$elemMatch": { "$eq": 1451 } } ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$eq": 1 } }}'; ROLLBACK; -- $elemMatch (regex) BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, "This is a string that goes over the index truncation limit" ]}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$elemMatch": { "$all": [ { "$regex": "limit$", "$options": "" } ] }}}'; ROLLBACK; -- $range BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1235 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1237 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1238 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1239 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1242 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 39, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1243 ]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 40, "ikey" : [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1244 ]}'); -- matches nothing. SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, 1234, 1234, 1235 ], "$lt": [ 2346, 1234, 1234, 1234, 1234, 1234, 1234 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lte": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte":[ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lte": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey": 1 } , "$lt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1241 ] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": [ 2345, 1234, 1234, 1234, 1234, 1234, 1234, 1236 ], "$lt": { "$maxKey": 1 } } }'; ROLLBACK; -------------------------- ---- DATA TYPE: Document -------------------------- -- with 60 byte truncation limit, the real limit is 60-18 = 42 bytes. We can tolerate any entries over 42 bytes as long as they're also marked truncated. -- the base structural overhead for an array is 5 (bson Doc) + 2 (path) + 1 (typecode) + 5 (doc header) = 13 bytes -- each path takes some characters (string), 1 byte (type code) + path Value (variable) = 1+ bytes + valueLength -- empty doc (13 bytes) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : {} }'::bson, 'ikey', false, true, true, 60) term; -- single path (13 bytes + 4 bytes (path) + 1 byte type Code, 9 byte string, 1 for the \0, 4 byte string length) = 32 bytes (not truncated) SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 13, "ikey" : { "abc": "123456789" } }'::bson, 'ikey', false, true, true, 60) term; -- single path truncated on path - path should be truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('abcdefg', 10))::bson, 'ikey', false, true, true, 60) term; -- single path truncated on path since path is greater than soft limit less than hard limit - path should not be truncated SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('abcdefg', 6))::bson, 'ikey', false, true, true, 60) term; -- value doesn't show up until we're under the soft limit. -- overhead: 13 bytes, 1 byte type code: for a 42 byte soft limit we're looking at a 28 byte path: from paths >= 29 bytes values Must be maxkey SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 41))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 30))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 29))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789", "b": 1, "c": 1 } }', repeat('a', 27))::bson, 'ikey', false, true, true, 60) term; -- value gets truncated when it appears SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "123456789123451234512345", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "%s": "%s", "b": 1, "c": 1 } }', repeat('a', 5), repeat('b', 40))::bson, 'ikey', false, true, true, 60) term; -- truncation with object + string after works SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(FORMAT('{"_id": 13, "ikey" : { "a": { "b": 1 }, "%s": "123456789123451234512345", "b": 1, "c": 1 } }', repeat('a', 28))::bson, 'ikey', false, true, true, 60) term; -- sample docs from subsequent stages SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'::bson, 'ikey', false, true, true, 60) term; -- start fresh with documents DELETE FROM documentdb_data.documents_6401; -- $eq on something that's past truncation. BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$ne": { "userName": "myFirstUserName", "address": { "$maxKey": 1 } } }}'; ROLLBACK; -- $gt/$lt/$gte/$gt/$range on something past truncation BEGIN; SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 31, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 32, "ikey" : { "userName": "myFirstUserName", "address": "2nd avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 33, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 34, "ikey" : { "userName": "myFirstUserName", "address": { "$maxKey": 1 } }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 35, "ikey" : { "userName": "myFirstUserName", "address1": { "$maxKey": 1 } }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 36, "ikey" : { "userName": "myFirstUserName", "address": "0th avenue, Rua Amalho", "MaxField": { "$maxKey": 1 } }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 37, "ikey" : { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 38, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "0th avenue, Rua Amalho", "apartment": "compartamento" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 39, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" }}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests', '{"_id": 40, "ikey" : { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "2nd avenue, Rua Amalho", "apartment": "compartamento" }}'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lt": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gt": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$lte": { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, "$gte": { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$in": [ { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } ] }}'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests') WHERE document @@ '{ "ikey": { "$nin": [ { "userName": "myFirstUserName", "address": "1st avenue, Rua Amalho" }, { "userName": "my0thUserNamethatgoespasttruncationlimitssothataddressdoesnotshowup", "address": "1st avenue, Rua Amalho", "apartment": "compartamento" } ] }}'; ROLLBACK; -- finally shard_collection and ensure it's Truncation limit is still there. SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6401 ORDER BY index_id; SELECT documentdb_api.shard_collection('db', 'index_truncation_tests', '{ "_id": "hashed" }', false); \d documentdb_data.documents_6401 /* testing wildcard indexes */ SET documentdb.indexTermLimitOverride TO 100; SET documentdb.maxWildcardIndexKeySize TO 50; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests", "indexes": [ { "key": { "$**": 1 }, "name": "wkey_1", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_6402 /* should fail fue to maximum size exceeded */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{"_id": 1, "thiskeyislargerthanthemaximumallowedsizeof50characters" : "sample_value"}'); /* should succeed due to maximum size not exceeded */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{"_id": 1, "ikey1" : "this is a string that does not violate the index term limit"}'); /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests', '{ "_id": 2, "ikey2": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); /* query all and check if same index is used for both */ SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey1": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey1": { "$gt": "this is a" } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey2": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests') WHERE document @@ '{ "ikey2": { "$gt": "this is a" } }'; /* create collection again and test with single field wildcard. */ set documentdb.indexTermLimitOverride to 60; /* should create wildcard for single path */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests_single_field", "indexes": [ { "key": { "a.b.$**": 1 }, "name": "wkey_2", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_6403 /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{ "_id": 1, "a": { "b": { "c": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } }'); SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{ "_id": 2, "a": { "d": { "c": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" } } }'); SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{"_id": 3, "a" : { "b": { "c": [ 2345, 1234, 1234, 1234, 1234 ] } } }'); /* making sure the array is being truncated */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "a.b.c": [ 2345, 1234, 1234, 1234, 1234 ] }', '', true, true, false, 60) term; /* making sure the wildcard index terms are being generated correctly for a truncated value */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 3, "a.b.c": [ 2345, 1234, 1234, 1234, 1234, 76, 85 ] }', '["a"]', false, true, false, 60) term; SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_single_field', '{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }'); /* making sure the document is being truncated */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }', '', true, true, false, 60) term; /* making sure the wildcard index terms are being generated correctly for a truncated value */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 4, "a": { "b": { "c": 1, "d": 2, "e": "12334141424124" } } }', '["a"]', false, true, false, 60) term; /* second element in array shouldn't appear as a term */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a": [{ "b": { "c": 1, "d": 2, "e": "1" } }, { "oi": 2} ], "c": 1}', '["a.0"]', false, true, false, 60) term; /* term key "c" shouldn't appear as a term */ SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 6, "a": [{ "b": { "c": 1, "d": 2, "e": "1" } }, { "oi": 2} ], "c": 1}', '["a"]', false, true, false, 60) term; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gt": "this is a" } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.d.c": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.d.c": { "$gt": "this is a" } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": 1 }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": 1 }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$elemMatch": { "$eq": 2345 } } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_single_field') WHERE document @@ '{ "a.b.c": { "$elemMatch": { "$eq": 2345 } } }'; /* create collection again and test with wildcard projection. */ set documentdb.indexTermLimitOverride to 60; /* should create wildcard index with projection */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcard_index_truncation_tests_wildcard_projection", "indexes": [ { "key": { "$**": 1 }, "name": "wkey_3", "enableLargeIndexKeys": true , "wildcardProjection": { "a": 1, "b": 1 } } ] }'); \d documentdb_data.documents_6404 /* should succeed and truncate index term with wildcard index */ SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{ "_id": 1, "a": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c": 2 }'); SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{ "_id": 2, "b": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings", "c": 2 }'); SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{"_id": 3, "a" : [ 2345, 1234, 1234, 1234, 1234 ], "b": "this is a string that does violate the index term limit as it goes much over the 100 character limit of strings" }'); SELECT documentdb_api.insert_one('db', 'wildcard_index_truncation_tests_wildcard_projection', '{"_id": 4, "a": { "l": { "j": 1 } }, "d": 2 }'); SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gt": "this is a" } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "b": { "$gt": "this is a" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "b": { "$gt": "this is a" } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$gte": [ 2345, 1234, 1234, 1234, 1230 ] , "$lte": [ 2345, 1234, 1234, 1234, 1240 ] } }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a.l.j": 1 }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a.l.j": 1 }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$elemMatch": { "$eq": 2345 } } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "a": { "$elemMatch": { "$eq": 2345 } } }'; /* should not use index when query uses key not specified in the projection */ SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "c": 1 }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "c": 1 }'; SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "d": 2 }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'wildcard_index_truncation_tests_wildcard_projection') WHERE document @@ '{ "d": 2 }'; /* test that term truncation is enabled by default if user doesn't explicitly disable it. */ set documentdb.indexTermLimitOverride to 60; /* enableLargeIndexKeys should be false because it was explicitly set to false */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc1", "indexes": [ { "key": { "a.b": 1 }, "name": "key" } ] }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6405 ORDER BY index_id; /* enableLargeIndexKeys should be true because it was not explicitly set to false */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc2", "indexes": [ { "key": { "a.b": 1 }, "name": "key" } ] }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6406 ORDER BY index_id; /* enableLargeIndexKeys should be false because index does not support it (ttl index) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc3", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6407 ORDER BY index_id; /* enableLargeIndexKeys should be false because index does not support it (hashed) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc4", "indexes": [ { "key": { "a.b": "hashed" }, "name": "key" } ] }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6408 ORDER BY index_id; /* enableLargeIndexKeys should be false because index does not support it (text) */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_default_trunc5", "indexes": [ { "key": { "a.b": "text" }, "name": "key" } ] }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6409 ORDER BY index_id; -- Additional tests for bug where index term length optimization with '$' was not consistent, i.e., we would generate prefix like 'ikey' and '$.0' SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', false, true , true, 500) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', false, true , true) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', true, true , true, 500) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey.a', true, true , true) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '', true, true , true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '', true, true , true) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', '["ikey"]', false, true , true, 60) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey', true, true, true, 500) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a": ["abcdefgh"]}}', 'ikey', true, true, true) term; SELECT FORMAT('{ "visits": [ "1" %s ] }', repeat(', { "estimatedTimeOfArrival": { "$date": 101010 }, "estimatedTimeOfDeparture": { "$date": 101010 }, "visitId": "someVisitIdValueString", "visitDocuments": { } } ', 5)) AS documentvalue \gset SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(:'documentvalue'::bson, '', true, true, true, 500) term; bson_index_truncation_nested_objects_tests.sql000066400000000000000000001175751507310017400404250ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1040000; SET documentdb.next_collection_id TO 10400; SET documentdb.next_collection_index_id TO 10400; -- Set configs to something reasonable for testing. set documentdb.indexTermLimitOverride to 50; -------------------------- ---- Nested Array -------------------------- -- gin_bson_get_single_path_generated_terms( -- document bson, -- path text, -- isWildcard bool, -- generateNotFoundTerm bool default false, -- addMetadata bool default false, -- termLength int) -- non wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', false, true, true, 35) term; -- wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : [[1]]}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[{ "$numberDecimal" : "1234567891011" }]]}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : [[true]]}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : [["abcdefghijklmonpqrstuvwsyz"]]}', 'ikey', false, true, true, 50) term; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested_array", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); -- now we have an index with truncation enabled and 50 chars. \d documentdb_data.documents_10400; -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 1, "ikey": [["abcdefghijklmonpqrstuvwsyz"]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 2, "ikey": [[1]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 3, "ikey": [[{ "$numberDecimal" : "1234567891011" }]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 4, "ikey": [[true]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 5, "ikey": [[[]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 6, "ikey": [[{}]] }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[1]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[false]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[]]] } }'; -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 7, "ikey": [[["abcdefghijklmonpqrstuvwsyz"]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 8, "ikey": [[[1]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 9, "ikey": [[[{ "$numberDecimal" : "1234567891011" }]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 10, "ikey": [[[true]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 11, "ikey": [[[[]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 12, "ikey": [[[{}]]] }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[1]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[{ "$numberDecimal" : "1234567891011" }]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[false]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [[[[]]]] } }'; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 13, "ikey": "abcdefghijklmonpqrstuvwsyz" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 14, "ikey": 1 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 15, "ikey": { "$numberDecimal" : "1234567891011" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 16, "ikey": true }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 17, "ikey": [] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_array', '{ "_id": 18, "ikey": {} }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": 1 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": { "$numberDecimal" : "1234567891011" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": false } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$gt": [] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$in": [1, true] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$nin": [1, true] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [1, true] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [[[1]], [[true]]] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$elemMatch": { "$in": [[[1]], [[true]]], "$gt": [[{ "$numberDecimal" : "1234567891011" }]] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$all": [[[1]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$all": [[[[]]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$ne": { "$numberDecimal" : "1234567891011" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$in": [[[1]], [[true]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$nin": [[[1]], [[true]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_array') WHERE document @@ '{ "ikey": { "$ne": [[{ "$numberDecimal" : "1234567891011" }]] } }'; -------------------------- ---- Nested Documents -------------------------- -- gin_bson_get_single_path_generated_terms( -- document bson, -- path text, -- isWildcard bool, -- generateNotFoundTerm bool default false, -- addMetadata bool default false, -- termLength int) -- non wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', false, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', false, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', false, true, true, 35) term; -- wild card SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]]}}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', true, true, true, 50) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 2, "ikey" : { "a" : [1]}}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [{ "$numberDecimal" : "1234567891011" }]}}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 3, "ikey" : { "a" : [true]}}', 'ikey', true, true, true, 35) term; SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 1, "ikey" : { "a" : ["abcdefghijklmonpqrstuvwsyz"]}}', 'ikey', false, true, true, 50) term; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested_documents", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); -- now we have an index with truncation enabled and 100 chars. \d documentdb_data.documents_10401; -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 1, "ikey": { "a" : ["abcdefghijklmonpqrstuvwsyz"]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 2, "ikey": { "a" : [1]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 3, "ikey": { "a" : [{ "$numberDecimal" : "1234567891011" }]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 4, "ikey": { "a" : [true]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 5, "ikey": { "a" : [[]}] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 6, "ikey": { "a" : [{}]} }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [1] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [false] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[]] } }'; -- now insert some documents that does exceed the index term limit. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 7, "ikey": { "a" : [["abcdefghijklmonpqrstuvwsyz"]]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 8, "ikey": { "a" : [[1]]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 9, "ikey": { "a" : [[{ "$numberDecimal" : "1234567891011" }]]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 10, "ikey": { "a" : [[true]]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 11, "ikey": { "a" : [[[]]]} }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 12, "ikey": { "a" : [[{}]]} }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[1]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[{ "$numberDecimal" : "1234567891011" }]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[false]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [[[]]] } }'; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 13, "ikey": "abcdefghijklmonpqrstuvwsyz" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 14, "ikey": 1 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 15, "ikey": { "$numberDecimal" : "1234567891011" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 16, "ikey": true }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 17, "ikey": [] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_documents', '{ "_id": 18, "ikey": {} }'); SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": 1 } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": { "$numberDecimal" : "1234567891011" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": false } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$gt": [] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$in": [1, true] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$nin": [1, true] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [1, true] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], [true]] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [1, "abcdefghijklmonpqrstuvwsyz"] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], ["abcdefghijklmonpqrstuvwsyz"]] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$elemMatch": { "$in": [[1], [true]], "$gt": [{ "$numberDecimal" : "1234567891011" }] } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$all": [[1]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$all": [[[]]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$ne": { "$numberDecimal" : "1234567891011" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$in": [[1], [true]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$nin": [[1], [true]] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_tests_nested_documents') WHERE document @@ '{ "ikey.a": { "$ne": [{ "$numberDecimal" : "1234567891011" }] } }'; -- term generation tests set documentdb.indexTermLimitOverride to 100; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 19, "ikey": [[[[[[[[[[1]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 20, "ikey": [[[[[[[[[[true]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 21, "ikey": [[[[[[[[[[{ "$numberDecimal" : "1234567891011" }]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 22, "ikey": [[[[[[[[[[{ "$maxKey": 1 }]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 23, "ikey": [[[[[[[[[[{ "$minKey": 1 }]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 24, "ikey": [[[[[[[[[[{ "$numberDouble" : "1234567891011" }]]]]]]]]]] }'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects', '{ "_id": 25, "ikey": [[[[[[[[[[ "abcdefghijklmopqrstuvwxyz" ]]]]]]]]]] }'); SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 115) term, document-> '_id' as did from documentdb_data.documents_10402) docs; SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 120) term, document-> '_id' as did from documentdb_data.documents_10402) docs; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 26, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": 1}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 27, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": true}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 28, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$maxKey": 1 }}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 29, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$minKey": 1 }}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 30, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$numberDouble" : "1234567891011" }}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 31, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": { "$numberDecimal" : "1234567891011" }}}}}}}}}}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_2', '{ "_id": 32, "ikey": { "a" : {"b" : { "c": { "d": { "e": { "f" : { "g" : { "h": "abcdefghijklmopqrstuvwxyz"}}}}}}}}}'); SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_10403) docs; SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 105) term, document-> '_id' as did from documentdb_data.documents_10403) docs; SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 33, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": 1}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 34, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": true}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 35, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$numberDecimal" : "1234567891011" }}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 36, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$maxKey": 1 }}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 37, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$minKey": 1 }}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 38, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": { "$numberDouble" : "1234567891011" }}]}]}]}]}]}]}]}]}'); SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested_objects_3', '{ "_id": 39, "ikey": [{ "a" : [{"b" : [{ "c": [{ "d": [{ "e": [{ "f" : [{ "g" : [{ "h": "abcdefghijklmopqrstuvwxyz"}]}]}]}]}]}]}]}]}'); SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 165) term, document-> '_id' as did from documentdb_data.documents_10404) docs; SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 170) term, document-> '_id' as did from documentdb_data.documents_10404) docs; SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', true, true, true, 165) term, document-> '_id' as did from documentdb_data.documents_10404) docs; SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', true, true, true, 170) term, document-> '_id' as did from documentdb_data.documents_10404) docs; -- specific tests set documentdb.indexTermLimitOverride to 200; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_tests_nested", "indexes": [ { "key": { "$**" : 1 }, "name": "wildcardIndex", "enableLargeIndexKeys": true } ] }', true); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'index_truncation_tests_nested'); -- 1. does not fail. SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested','{ "_id" : 1, "data": { "$binary": { "base64": "ewogICAgIl9pZCI6ICI2NzY5ZGI2NmExZGIyMDA4NTczOTdiNjAiLAogICAgImluZGV4IjogMCwKICAgICJndWlkIjogIjMzZjk1N2QwLWU0M2MtNDYyNi1iOGJjLTFkODE0ODE3MmZkNyIsCiAgICAiaXNBY3RpdmUiOiB0cnVlLAogICAgImJhbGFuY2UiOiAiJDMsOTMwLjI4IiwKICAgICJwaWN0dXJlIjogImh0dHA6Ly9wbGFjZWhvbGQuaXQvMzJ4MzIiLAogICAgImFnZSI6IDI3LAogICAgImV5ZUNvbG9yIjogImdyZWVuIiwKICAgICJuYW1lIjogIkxpbGEgVmFsZW56dWVsYSIsCiAgICAiZ2VuZGVyIjogImZlbWFsZSIsCiAgICAiY29tcGFueSI6ICJBUFBMSURFQyIsCiAgICAiZW1haWwiOiAibGlsYXZhbGVuenVlbGFAYXBwbGlkZWMuY29tIiwKICAgICJwaG9uZSI6ICIrMSAoODIyKSA1NDItMjQ1MCIsCiAgICAiYWRkcmVzcyI6ICI2NjcgT3hmb3JkIFdhbGssIENhc2h0b3duLCBBcmthbnNhcywgMjYyMyIsCiAgICAiYWJvdXQiOiAiSW4gYWxpcXVpcCBub24gZXN0IHNpdCBlc3QgTG9yZW0gcXVpIG9jY2FlY2F0IGZ1Z2lhdCBleC4gRG9sb3IgbGFib3JlIG1vbGxpdCBjb25zZXF1YXQgaXBzdW0uIFF1aXMgY29uc2VxdWF0IGRlc2VydW50IGVpdXNtb2QgcHJvaWRlbnQgZHVpcyBvY2NhZWNhdCBldSBlbGl0IG5vbiBhZCBleCBkZXNlcnVudCBwcm9pZGVudCBMb3JlbS4gSWQgbW9sbGl0IGNpbGx1bSBpcHN1bSB2b2x1cHRhdGUgYXV0ZSBsYWJvcmlzIGVzc2UgYW5pbS5cclxuIiwKICAgICJyZWdpc3RlcmVkIjogIjIwMjAtMDktMDRUMDM6MDA6MTggKzAzOjAwIiwKICAgICJsYXRpdHVkZSI6IDguMTI4MTI0LAogICAgImxvbmdpdHVkZSI6IC0zNy4zMjY4MDMsCiAgICAidGFncyI6IFsKICAgICAgImV0IiwKICAgICAgInN1bnQiLAogICAgICAibW9sbGl0IiwKICAgICAgImFuaW0iLAogICAgICAibW9sbGl0IiwKICAgICAgImRvIiwKICAgICAgIm5vbiIKICAgIF0sCiAgICAiZnJpZW5kcyI6IFsKICAgICAgewogICAgICAgICJpZCI6IDAsCiAgICAgICAgIm5hbWUiOiAiTGVuYSBIdWZmbWFuIgogICAgICB9LAogICAgICB7CiAgICAgICAgImlkIjogMSwKICAgICAgICAibmFtZSI6ICJWaWNreSBMdWNhcyIKICAgICAgfSwKICAgICAgewogICAgICAgICJpZCI6IDIsCiAgICAgICAgIm5hbWUiOiAiSm9zZXBoIEdhcmRuZXIiCiAgICAgIH0KICAgIF0sCiAgICAiZ3JlZXRpbmciOiAiSGVsbG8sIExpbGEgVmFsZW56dWVsYSEgWW91IGhhdmUgMTAgdW5yZWFkIG1lc3NhZ2VzLiIsCiAgICAiZmF2b3JpdGVGcnVpdCI6ICJiYW5hbmEiCiAgfQ==", "subType": "01" } }, "updatedAt": { "$date": 101010 }, "estimatedTimeOfArrival": { "$date": 101010 }, "isSomething": false, "createdAt": { "$date": 101010 }, "itemData": [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ], "employeeCode": "LBF" }'); -- 2 a. Terms generated with nested object index term truncation support SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( '{ "_id": 1, "itemData" : [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ] }' , 'itemData', true, true, true, 1000) term; -- 2 b. Terms generated with nested object index term truncation support SELECT length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( '{ "_id": 1, "itemData" : [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ] }' , 'itemData', true, true, true, 60) term; -- 3. Now insert the document with nested object index term truncation support SELECT documentdb_api.insert_one('db', 'index_truncation_tests_nested', ' { "_id" : 2, "data": { "$binary": { "base64": "ewogICAgIl9pZCI6ICI2NzY5ZGI2NmExZGIyMDA4NTczOTdiNjAiLAogICAgImluZGV4IjogMCwKICAgICJndWlkIjogIjMzZjk1N2QwLWU0M2MtNDYyNi1iOGJjLTFkODE0ODE3MmZkNyIsCiAgICAiaXNBY3RpdmUiOiB0cnVlLAogICAgImJhbGFuY2UiOiAiJDMsOTMwLjI4IiwKICAgICJwaWN0dXJlIjogImh0dHA6Ly9wbGFjZWhvbGQuaXQvMzJ4MzIiLAogICAgImFnZSI6IDI3LAogICAgImV5ZUNvbG9yIjogImdyZWVuIiwKICAgICJuYW1lIjogIkxpbGEgVmFsZW56dWVsYSIsCiAgICAiZ2VuZGVyIjogImZlbWFsZSIsCiAgICAiY29tcGFueSI6ICJBUFBMSURFQyIsCiAgICAiZW1haWwiOiAibGlsYXZhbGVuenVlbGFAYXBwbGlkZWMuY29tIiwKICAgICJwaG9uZSI6ICIrMSAoODIyKSA1NDItMjQ1MCIsCiAgICAiYWRkcmVzcyI6ICI2NjcgT3hmb3JkIFdhbGssIENhc2h0b3duLCBBcmthbnNhcywgMjYyMyIsCiAgICAiYWJvdXQiOiAiSW4gYWxpcXVpcCBub24gZXN0IHNpdCBlc3QgTG9yZW0gcXVpIG9jY2FlY2F0IGZ1Z2lhdCBleC4gRG9sb3IgbGFib3JlIG1vbGxpdCBjb25zZXF1YXQgaXBzdW0uIFF1aXMgY29uc2VxdWF0IGRlc2VydW50IGVpdXNtb2QgcHJvaWRlbnQgZHVpcyBvY2NhZWNhdCBldSBlbGl0IG5vbiBhZCBleCBkZXNlcnVudCBwcm9pZGVudCBMb3JlbS4gSWQgbW9sbGl0IGNpbGx1bSBpcHN1bSB2b2x1cHRhdGUgYXV0ZSBsYWJvcmlzIGVzc2UgYW5pbS5cclxuIiwKICAgICJyZWdpc3RlcmVkIjogIjIwMjAtMDktMDRUMDM6MDA6MTggKzAzOjAwIiwKICAgICJsYXRpdHVkZSI6IDguMTI4MTI0LAogICAgImxvbmdpdHVkZSI6IC0zNy4zMjY4MDMsCiAgICAidGFncyI6IFsKICAgICAgImV0IiwKICAgICAgInN1bnQiLAogICAgICAibW9sbGl0IiwKICAgICAgImFuaW0iLAogICAgICAibW9sbGl0IiwKICAgICAgImRvIiwKICAgICAgIm5vbiIKICAgIF0sCiAgICAiZnJpZW5kcyI6IFsKICAgICAgewogICAgICAgICJpZCI6IDAsCiAgICAgICAgIm5hbWUiOiAiTGVuYSBIdWZmbWFuIgogICAgICB9LAogICAgICB7CiAgICAgICAgImlkIjogMSwKICAgICAgICAibmFtZSI6ICJWaWNreSBMdWNhcyIKICAgICAgfSwKICAgICAgewogICAgICAgICJpZCI6IDIsCiAgICAgICAgIm5hbWUiOiAiSm9zZXBoIEdhcmRuZXIiCiAgICAgIH0KICAgIF0sCiAgICAiZ3JlZXRpbmciOiAiSGVsbG8sIExpbGEgVmFsZW56dWVsYSEgWW91IGhhdmUgMTAgdW5yZWFkIG1lc3NhZ2VzLiIsCiAgICAiZmF2b3JpdGVGcnVpdCI6ICJiYW5hbmEiCiAgfQ==", "subType": "01" } }, "updatedAt": { "$date": 101010 }, "estimatedTimeOfArrival": { "$date": 101010 }, "isSomething": false, "createdAt": { "$date": 101010 }, "itemData": [ { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } }, { "attribute": "xpto", "ccb": 34354, "dx": 0, "el": null, "first": null, "greaterThan": null, "shortPath": null, "i": null, "largePathWithObject": { "option1": null, "option2": "small-string2", "option3": null, "option4": 122121, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string2", "prior": 1111111111111111 } } ], "employeeCode": "LBF" }'); -- 4. Now issue a find query SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData": { "$eq": { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } } } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); -- 5. Index usage explain EXPLAIN(ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData": { "$eq": { "attribute": "1234", "cb": 12431, "dx": "test", "el": { "$code": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "first": null, "greaterThan": null, "shortPath": "aas", "i": null, "largePathWithObject": { "option1": null, "option2": "small-string1", "option3": null, "option4": 123, "onlyPathWithLargeString": "aassadasdasdsdasdasdsadsa-test-data-with-large-string", "prior": 123123213213 } } } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData.largePathWithObject.option2": { "$eq": "small-string1" } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); EXPLAIN(ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "index_truncation_tests_nested", "filter": { "itemData.largePathWithObject.option2": { "$eq": "small-string1" } }, "projection": { "_id": 1 }, "sort": { "_id": 1 }, "skip": 0, "limit": 5 }'); bson_index_truncation_symbol_tests.sql000066400000000000000000000425021507310017400367220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1170000; SET documentdb.next_collection_id TO 11700; SET documentdb.next_collection_index_id TO 11700; -- Set configs to something reasonable for testing. SET documentdb.indexTermLimitOverride to 20; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_symbol_tests", "indexes": [ { "key": { "ikey": 1 }, "name": "ikey_1", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11700 -- Insert symbol BSON data SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 1, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 2, "ikey": { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 3, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 4, "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 5, "ikey": { "$symbol" : "eyAiYSI6IDEsICJiIjogMyB9" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 6, "ikey": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }, "item": "F", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 7, "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G", "customKey": 6 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 8, "ikey": { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 9, "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "H", "customKey": 8 }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests', '{ "_id": 10, "ikey": { "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, "item": "H", "customKey": 9 }'); /* All terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 20) term, document-> '_id' as did from documentdb_data.documents_11700) docs; /* Only a subset of the terms should be truncated */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey', false, true, true, 40) term, document-> '_id' as did from documentdb_data.documents_11700) docs; /* $eq (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiYSI6IDEsICJiIjogMyB9" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" }, "item": "G" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "eyAiYSI6IDEsICJiIjogMyB9" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol": "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$symbol" : "YWJvYm9yYQ==" } }'; /* $gt/$gte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "YWJvYm9yYQ==" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$minKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gt": { "$symbol" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$gte": { "$symbol" : "YWJvYm9yYQ==" } } }'; /* $lt/$lte (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "YWJvYm9yYQ==" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$maxKey" : 1 } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lt": { "$symbol" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$lte": { "$symbol" : "YWJvYm9yYQ==" } } }'; /* $in/$nin/$ne/$all (all terms truncated) */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "YWJvYm9yYQ==" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$in": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$nin": [{ "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "YWJvYm9yYQ==" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$ne": { "$symbol" : "eyAiYSI6ICIxMjM0NSIsICJiIjogMTIzMTIzMTIzMjExMjMxIH0=" } } }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests') WHERE document @@ '{ "ikey": { "$all": [{ "$symbol" : "dGhpcyBpcyBhIHRlc3Qgc3RyaW5n" }, { "$symbol" : "MTIzNDUxMjM0NQ==" }] } }'; -- insert $symbol BSON data in nested documents/arrays with different leaf types SET documentdb.indexTermLimitOverride to 100; /* create index on key 'ikey2' */ SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "index_truncation_symbol_tests_2", "indexes": [ { "key": { "ikey2" : 1 }, "name": "ikey_2", "enableLargeIndexKeys": true } ] }'); \d documentdb_data.documents_11701 SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 1, "test": "a", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 2, "test": "b", "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 3, "test": "c", "ikey2": [["a"]], "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 4, "test": "d", "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 5, "test": "e", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 6, "test": "f", "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'); SELECT documentdb_api.insert_one('db', 'index_truncation_symbol_tests_2', '{ "_id": 7, "test": "g", "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'); /* check for index terms */ SELECT did, length(bson_dollar_project(term, '{ "t": 0 }')::bytea), term FROM ( SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms(document, 'ikey2', false, true, true, 100) term, document-> '_id' as did from documentdb_data.documents_11701) docs; /* testing for equality and index usage */ SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'; SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]]]]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [["a"]], "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdefg": { "bcdef": { "cdefg": { "dhig": { "f": { "d": "abcdefghijklmnoasadasdsadasdsadsadasdsadasdaspqrstuvxzabcdefghzasaasaasaasasasasas" } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "csssss": 2 } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": { "abcdeasasfg": { "bcassasdef": { "cdefsssg": { "dhsssig": { "ssssb": { "c": [[[{ "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" }]]] } } } } } }, "item": "A" }'; EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM documentdb_api.collection('db', 'index_truncation_symbol_tests_2') WHERE document @@ '{ "ikey2": [[[[[[{ "a": { "b": { "c": { "$symbol" : "eyAiZXhhbXBsZSI6IDEyMywgInZhbHVlIjogImFib2JvcmEiIH0=" } } } } ]]]]]], "item": "A" }'; bson_insert_basic_types.sql000066400000000000000000000122471507310017400344320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 300000; SET documentdb.next_collection_id TO 3000; SET documentdb.next_collection_index_id TO 3000; -- insert int32 SELECT documentdb_api.insert_one('db','collection','{"_id":"1", "value": { "$numberInt" : "11" }, "valueMax": { "$numberInt" : "2147483647" }, "valueMin": { "$numberInt" : "-2147483648" }}', NULL); -- insert int64 SELECT documentdb_api.insert_one('db','collection','{"_id":"2", "value":{"$numberLong" : "134311"}, "valueMax": { "$numberLong" : "9223372036854775807" }, "valueMin": { "$numberLong" : "-9223372036854775808" }}', NULL); -- insert double SELECT documentdb_api.insert_one('db','collection','{"_id":"3", "value":{"$numberDouble" : "0"}, "valueMax": { "$numberDouble" : "1.7976931348623157E+308" }, "valueMin": { "$numberDouble" : "-1.7976931348623157E+308" }, "valueEpsilon": { "$numberDouble": "4.94065645841247E-324"}, "valueinfinity": {"$numberDouble":"Infinity"}}', NULL); -- insert string SELECT documentdb_api.insert_one('db','collection','{"_id":"4", "value": "Today is a very good day and I am happy."}', NULL); -- insert binary SELECT documentdb_api.insert_one('db','collection','{"_id":"5", "value": {"$binary": { "base64": "SSBsb3ZlIE1pY3Jvc29mdA==", "subType": "02"}}}', NULL); -- minKey/maxKey SELECT documentdb_api.insert_one('db','collection','{"_id":"6", "valueMin": { "$minKey": 1 }, "valueMax": { "$maxKey": 1 }}', NULL); -- oid, date, time SELECT documentdb_api.insert_one('db','collection','{"_id":"7", "tsField": {"$timestamp":{"t":1565545664,"i":1}}, "dateBefore1970": {"$date":{"$numberLong":"-1577923200000"}}, "dateField": {"$date":{"$numberLong":"1565546054692"}}, "oidField": {"$oid":"5d505646cf6d4fe581014ab2"}}', NULL); -- array & nested object SELECT documentdb_api.insert_one('db','collection','{"_id":"8","arrayOfObject":[{"bonjour":"bonjour"},{"ça va ?":"ça va !"},{"Qu''est-ce que tu as fait cette semaine ?":"rien"}]}', NULL); -- fetch all rows SELECT shard_key_value, object_id, document FROM documentdb_api.collection('db', 'collection') ORDER BY 1,2,3; -- project two fields out. SELECT document->'_id', document->'value' FROM documentdb_api.collection('db', 'collection') ORDER BY object_id; -- insert document with $ or . in the field path SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 9, "$field": 1}'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 10, "field": { "$subField": 1 } }'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 11, "field": [ { "$subField": 1 } ] }'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 12, ".field": 1}'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 13, "fie.ld": 1}'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 14, "field": { ".subField": 1 } }'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 15, "field": { "sub.Field": 1 } }'); SELECT documentdb_api.insert_one('db', 'collection', '{ "_id": 16, "field": [ { "sub.Field": 1 } ] }'); /* Test to validate that _id field cannot have regex as it's value */ select documentdb_api.insert_one('db', 'bsontypetests', '{"_id": {"$regex": "^A", "$options": ""}}'); /* Test _id cannot have nested paths with $ */ SELECT documentdb_api.insert_one('db', 'bsontypetests', '{ "_id": { "a": 2, "$c": 3 } }'); /* Test to validate that _id field cannot have array as it's value */ select documentdb_api.insert_one('db', 'bsontypetests', '{"_id": [1]}'); -- assert object_id matches the '_id' from the content - should be numRows. SELECT COUNT(*) FROM documentdb_api.collection('db', 'collection') where object_id::bson = bson_get_value(document, '_id'); \copy documentdb_data.documents_3000 to 'test.bin' with (format 'binary') CREATE TABLE tmp_documentdb_data_documents_3000 (LIKE documentdb_data.documents_3000); \copy tmp_documentdb_data_documents_3000 from 'test.bin' with (format 'binary') -- verify that all records are same after serialization/deserialization SELECT COUNT(*)=0 FROM ( (TABLE documentdb_data.documents_3000 EXCEPT TABLE tmp_documentdb_data_documents_3000) UNION (TABLE tmp_documentdb_data_documents_3000 EXCEPT TABLE documentdb_data.documents_3000) ) q; -- verify output via hex strings and json BEGIN; set local documentdb_core.bsonUseEJson TO true; SELECT document FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO false; SELECT document FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO true; SELECT bson_hex_to_bson(bson_to_bson_hex(document)) FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; ROLLBACK; BEGIN; -- test that hex strings can be coerced to bson (bson_in accepts both) set local documentdb_core.bsonUseEJson TO true; SELECT bson_to_bson_hex(document)::text::bson FROM documentdb_api.collection('db', 'collection') ORDER BY document -> '_id'; ROLLBACK; BEGIN; set local documentdb_core.bsonUseEJson TO false; SELECT COUNT(1) FROM documentdb_api.collection('db', 'collection') WHERE bson_hex_to_bson(bson_out(document)) != document; ROLLBACK;bson_order_aggregates_tests.sql000066400000000000000000001017711507310017400352700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 71000; SET documentdb.next_collection_id TO 7100; SET documentdb.next_collection_index_id TO 7100; -- Insert an a.b, a.c matrix SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 1, "a" : { "b" : 1, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 2, "a" : { "b" : 1, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 3, "a" : { "b" : 1, "c" : 3 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 4, "a" : { "b" : 2, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 5, "a" : { "b" : 2, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 6, "a" : { "b" : 2, "c" : 3 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 7, "a" : { "b" : 3, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 8, "a" : { "b" : 3, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 9, "a" : { "b" : 3, "c" : 3 } }', NULL); SELECT BSONLAST(document, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTONSORTED(bson_expression_get(document, '{ "": "$a.f" }'))) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build('last'::text, BSONLAST(bson_expression_get(document, '{ "": "$a.f" }'), ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); -- Test the different order combinations SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); -- Test with null results from the sort spec SELECT BSONFIRST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); -- Test null ordering SELECT documentdb_api.insert_one('db','bsonorderaggregates', '{"_id": 11, "a" : { "c" : 3 } }', NULL); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONFIRST(document, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); SELECT BSONLAST(document, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLAST(document, ARRAY['{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); $Q$); END; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bsonorderaggregates", "indexes": [{"key": {"a.b": 1}, "name": "a_dot_b"}]}', true); BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLAST(document, ARRAY['{"a.b":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates'); $Q$); END; -- Shard the collection SELECT documentdb_api.shard_collection('db','bsonorderaggregates', '{"_id":"hashed"}', false); SELECT BSONLAST(document, ARRAY['{ "a.b":1}'::bson,'{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRSTONSORTED(document) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTONSORTED(bson_expression_get(document, '{ "": "$a.f" }'))) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build('last'::text, BSONLAST(bson_expression_get(document, '{ "": "$a.f" }'), ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build( 'lastNull'::text, bson_expression_get(BSONLAST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.f" }', true), 'first'::text, bson_expression_get(BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.b" }', true), 'firstNull'::text, bson_expression_get(BSONFIRST(document, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), '{ "": "$a.x" }', true) ) FROM documentdb_api.collection('db', 'bsonorderaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); -- regression test for crash in BSONFIRST/BSONLAST when the first documents are small and we need to choose a larger document in byte size SELECT documentdb_api.insert_one('db', 'bsonFirstLastCrash', '{"_id": 1, "a": "z", "b": "z", "c": "z"}'); SELECT documentdb_api.insert_one('db', 'bsonFirstLastCrash', FORMAT('{"_id": 2, "a": "%s", "b": "%s", "c": "%s"}', repeat('aaa', 10), repeat('bbb', 10), repeat('dd', 10))::bson); SELECT BSONFIRST(document, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstLastCrash'); SELECT BSONLAST(document, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstLastCrash'); -- -- BEGIN FIRSTN/LASTN Testing -- -- Insert an a.b, a.c matrix SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 1, "a" : { "b" : 1, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 2, "a" : { "b" : 1, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 3, "a" : { "b" : 1, "c" : 3 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 4, "a" : { "b" : 2, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 5, "a" : { "b" : 2, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 6, "a" : { "b" : 2, "c" : 3 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 7, "a" : { "b" : 3, "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 8, "a" : { "b" : 3, "c" : 2 } }', NULL); SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 9, "a" : { "b" : 3, "c" : 3 } }', NULL); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRSTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTNONSORTED(bson_expression_get(document, '{ "": "$a.f" }'), 1)) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build('last'::text, BSONLASTN(bson_expression_get(document, '{ "": "$a.f" }'), 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); -- Test the different order combinations SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); -- Test with null results from the sort spec SELECT BSONFIRSTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "f":1}', '{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{ "f":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}', '{ "f":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); -- Test null ordering SELECT documentdb_api.insert_one('db','bsonordernaggregates', '{"_id": 11, "a" : { "c" : 3 } }', NULL); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.c":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLASTN(document, 1, ARRAY['{"a.b":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); $Q$); END; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "bsonordernaggregates", "indexes": [{"key": {"a.b": 1}, "name": "a_dot_b"}]}', true); BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT BSONLASTN(document, 1, ARRAY['{"a.b":-1}', '{"a.b":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates'); $Q$); END; -- Shard the collection SELECT documentdb_api.shard_collection('db','bsonordernaggregates', '{"_id":"hashed"}', false); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}'::bson, '{"a.c":1}'::bson]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 3, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTN(document, 4, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONLASTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT BSONFIRSTNONSORTED(document, 2) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONLASTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); SELECT BSONFIRSTNONSORTED(document, 4) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.b" }'); -- last/first field not present SELECT bson_repath_and_build('firstonsorted'::text, BSONFIRSTNONSORTED(bson_expression_get(document, '{ "": "$a.f" }'), 1)) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build('last'::text, BSONLASTN(bson_expression_get(document, '{ "": "$a.f" }'), 1, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[])) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); SELECT bson_repath_and_build( 'lastNull'::text, BSONLASTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), 'first'::text, BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]), 'firstNull'::text, BSONFIRSTN(document, 2, ARRAY['{ "a.b":-1}', '{"a.c":-1}']::bson[]) ) FROM documentdb_api.collection('db', 'bsonordernaggregates') GROUP BY bson_expression_get(document, '{ "": "$a.c" }'); -- regression test for crash in BSONFIRSTN/BSONLASTN when the first documents are small and we need to choose a larger document in byte size SELECT documentdb_api.insert_one('db', 'bsonFirstNLastNCrash', '{"_id": 1, "a": "z", "b": "z", "c": "z"}'); SELECT documentdb_api.insert_one('db', 'bsonFirstNLastNCrash', FORMAT('{"_id": 2, "a": "%s", "b": "%s", "c": "%s"}', repeat('aaa', 10), repeat('bbb', 10), repeat('dd', 10))::bson); SELECT BSONFIRSTN(document, 1, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); SELECT BSONLASTN(document, 1, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); -- regression test for allocating too much memory SELECT BSONFIRSTN(document, 9999999999999, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); SELECT BSONLASTN(document, 9999999999999, ARRAY['{ "a": -1}', '{"c": -1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); -- regression test for NULL pointer SELECT BSONFIRSTN(NULL, 1, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]); SELECT BSONFIRSTNONSORTED(NULL, 1); SELECT BSONLASTN(NULL, 3, ARRAY['{ "a": 1}', '{"c": 1}']::bson[]) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); SELECT BSONLASTNONSORTED(NULL, 3) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); bson_projection_operator_dollar_slice_test.sql000066400000000000000000000375261507310017400404120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 290000; SET documentdb.next_collection_id TO 2900; SET documentdb.next_collection_index_id TO 2900; --Input type positive number select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 0} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 2} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 8} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberLong" : "2"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "2.1234"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "2.1234"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : []}', '{"a" : { "$slice" : 1} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1]}', '{"a" : { "$slice" : 1} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [{"x":[1,2,3]}, {"x":[4,5,6]}]}', '{"a.x" : { "$slice" : 2} }',NULL); --Input type is Negative number select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -0} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -1} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -2} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : -4} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5,6,7,8,9,10,11] }', '{"a" : { "$slice" : -13} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : -8} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberLong" : "-2"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "-2.1234"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "-2.1234"}} }',NULL); --Input type is array with postive number fields select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0,0]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0,2]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [2,3]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [3,1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [3,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [4,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [5,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberLong" : "1"}, { "$numberLong" : "3"} ] }}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDouble" : "2.1234"}, { "$numberDouble" : "3.1234"} ] }}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "1.1234"}, { "$numberDecimal" : "3.1234"}] }}',NULL); --Input type is array with negative number fields select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-0,0]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-1,2]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-2,3]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-3,1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [-3,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-4,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-5,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3] }', '{"a" : { "$slice" : [-10,10]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberLong" : "-1"}, { "$numberLong" : "3"} ] }}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDouble" : "-2.1234"}, { "$numberDouble" : "3.1234"} ] }}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3,4,5], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "-1.1234"}, { "$numberDecimal" : "3.1234"}] }}',NULL); --Input is NaN or Infinity select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "NaN"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "Infinity"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "NaN"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDouble" : "Infinity"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, { "$numberDecimal" : "NaN"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, { "$numberDecimal" : "Infinity"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, { "$numberDecimal" : "NaN"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, { "$numberDecimal" : "Infinity"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0, { "$numberDecimal" : "Infinity"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "Infinity"}, 1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [0, { "$numberDecimal" : "NaN"}]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "NaN"}, 1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : { "$numberDecimal" : "-Infinity"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$numberDecimal" : "-Infinity"}, 1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1, { "$numberDecimal" : "-Infinity"}]} }',NULL); --large values $slice select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : { "$numberDecimal" : "999999999999999999999999999999"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "999999999999999999999999999999"}, { "$numberDecimal" : "999999999999999999999999999999"}] } }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : [{ "$numberDecimal" : "0"}, { "$numberDecimal" : "999999999999999999999999999999"}] } }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : {"$numberDecimal" : "123123123123123121231"}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : [ {"$numberDecimal" : "123123123123123121231"}, {"$numberDecimal" : "123123123123123121231"} ]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22}', '{"a" : { "$slice" : [1,{"$numberDecimal" : "123123123123123121231"}]} }',NULL); --inclusion Exclusion check select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b" :0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b" :1 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "b":0, "c":0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c": 1, "d" : 0 }',NULL); --Nested array inside document & array select bson_dollar_project_find('{"_id":"1", "a" : {"x": [1,2,3], "y":5 }, "b":10}', '{"a.x" : { "$slice" : 1}, "b" :0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : {"x": [1,2,3], "y":5 }, "b":10}', '{"a.x" : { "$slice" : 1}, "b" :1 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3]], "b":10}', '{"a.0" : { "$slice" : 1}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3], {"y": 5}], "b":10}', '{"a.0" : { "$slice" : 1}, "b" :1 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3],4,5]}', '{"a.0" : { "$slice" : 1}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[1,2,3], {"y": 5}], "b":10}', '{"a.0" : { "$slice" : 1}, "b" :0 }',NULL); --multiple Slice select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1}, "b" :0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$slice" : 1}, "b" :1 }',NULL); --$slice with other operators select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}}, "b" : 1 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}, "b" :0}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}}, "b" : 0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}, "b" :1}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"b" : 0 , "a" : { "$slice" : 1}, "c" : { "$elemMatch" : {"$gt":1}} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3], "b" : 22, "c" : [1,2,3], "d":4 }', '{"b" : 1 , "a" : { "$elemMatch" : {"$gt":1}}, "c" : { "$slice" : 1}}',NULL); select bson_dollar_project_find('{"a": [ {"b" : [10]}, { "b" : [20]}]}', '{ "a.b": {"$slice":1}, "a.b": {"$add":[1,5]} }','{}'); select bson_dollar_project_find('{"a": [ {"b" : [10]}, { "b" : [20]}]}', '{ "a.b": {"$add":[1,10]}, "a.b": {"$slice":1} }','{}'); select bson_dollar_project_find('{"b": [[1,2,3,4]], "a": [10,20,30,40]}', '{ "a.$": 1, "b" : {"$slice" : 1} }','{"a" : {"$gt" :1}}'); select bson_dollar_project_find('{"_id":"1", "a" : {"b": {"c":[1,2,3], "d":10},"f":10 } }', '{"a.b.c" : {"$slice": 1}, "a.b.d": {"field":"$a.f"} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : {"b": {"c":[1,2,3], "d":10},"f":10 } }', '{"a.b.c" : {"$slice": 1}, "a.b.d": {"$isArray":"$a.c"} }',NULL); --Path Collision select bson_dollar_project_find('{"_id":"1", "a" : [{"x":1, "y":2}]}', '{"a" : { "$slice" : 1}, "a.x":0 }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [{"x":1, "y":2}]}', '{"a" : { "$slice" : 1}, "a.x":1 }',NULL); --array of array select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3]}]]}', '{"a.b" : { "$slice" : 2}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3]}], { "b": [1,2,3]}]}', '{"a.b" : { "$slice" : 2}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [[{"b": [1,2,3], "c":{ "d": [1,2,3] } }], { "e": [1,2,3] , "f": [[{"g": [1,2,3]}]] }]}', '{"a.b" : { "$slice" : 2}, "a.c.d" : { "$slice" : 2}, "a.e" : { "$slice" : 2},"a.f.g" : { "$slice" : 2}}',NULL); --Null and undefined input select bson_dollar_project_find('{"_id":"1", "a" : null}', '{"a" : { "$slice" : [1,2]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,null]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [null,1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [null,null]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : { "$undefined" : true }}', '{"a" : { "$slice" : [1,2]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,{ "$undefined" : true }]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$undefined" : true },1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [{ "$undefined" : true },{ "$undefined" : true }]} }',NULL); --Invalid Input Negative cases find slice projection select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : "str"} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : ["str"]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,2,3]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,"str"]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,-1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1,0]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : [1]} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : null} }',NULL); select bson_dollar_project_find('{"_id":"1", "a" : [1,2,3]}', '{"a" : { "$slice" : { "$undefined" : true }} }',NULL); bson_projection_operator_elemmatch_tests_core.sql000066400000000000000000000142321507310017400410750ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- Test $elemMatch projection operator SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 280000; SET documentdb.next_collection_id TO 2800; SET documentdb.next_collection_index_id TO 2800; SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": [ 11, 21, 31, 41 ], "z": "World" }', '{ "a":{ "$elemMatch":{ "$gt":25 }} }', '{}'); SELECT * FROM bson_dollar_project_find('{ "_id": 2, "a": [ 11, 21, 31, 41 ], "f": [ { "g": [ 14, 24, 34, 44 ], "h": "Hello" }, { "g": [ 15, 25, 35, 45 ], "h": "world" }], "z": "World" }', '{ "f": {"$elemMatch": {"g": {"$elemMatch": {"$gt":25 }}}} }', '{}'); -- Empty $elemMatch Predicate should match the first array or object value SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, {"b": 51}, 61 ] }', '{ "a": {"$elemMatch": {} } }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {} } }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$or": [{}, {}]} } }', '{}' ); -- this is negation so won't match any SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$nor": [{}, {}]} } }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ] }', '{ "a": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); -- $elemMatch on non array fields are skipped SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ], "b": {"c": 2}, "d": 71 }', '{ "b": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31, 41, [51,52,53], 61 ], "b": {"c": 2}, "d": 71 }', '{ "d": {"$elemMatch": {"$and": [{}, {}]} } }', '{}' ); -- Testing order of $elemMatch projection for inclusion and exclusion projections -- Inclusion projection - elemMatch is projected at the end & multiple elemMatch projections are projected based on projection spec order SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "e": 1, "d": 1 }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "d": 1, "e": {"$add": [2,3]} }', '{}' ); SELECT * FROM bson_dollar_project_find( '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}', '{"z": {"$elemMatch": {"$eq": 8} }, "x": {"$elemMatch": {"$eq": 3} }, "y": {"$elemMatch": {"$eq": 4} }}', '{}' ); -- Exclusions projection - elemMatch follows document order SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "e": 0, "d": 0 }', '{}' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b": {"$elemMatch": {"$gt": 45} }, "e": 0}', '{}' ); -- should error SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "e": 1, "b": {"$elemMatch": {"$gt": 45} }, "a": {"$elemMatch": {"$lt": 25}}, "d": 0 }', '{}' ); -- various predicates SELECT * FROM bson_dollar_project_find( '{"x": [{"a": 1}, {"a": 180}, {"a": 4}]}', '{"x": {"$elemMatch": {"$or": [{"a": {"$eq": 4}}, {"$and": [{"a": {"$mod": [12, 0]}}, {"a": {"$mod": [15, 0]}}]}]}}}', '{}' ); SELECT * FROM bson_dollar_project_find( '{"x": [{"a": 1, "b": 2}, {"a": 2, "c": 3}, {"a": 1, "d": 5}], "y": [{"aa": 1, "bb": 2}, {"aa": 2, "cc": 3}, {"aa": 1, "dd": 5}]}', '{"x": {"$elemMatch": {"d": {"$exists": true}}}}', '{}' ); SELECT * FROM bson_dollar_project_find( '{"x": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}', '{"x": {"$elemMatch": {"$elemMatch": {"$gt": 5, "$lt": 7}}}}', '{}' ); -- Multiple elemMatch projections SELECT * FROM bson_dollar_project_find( '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}', '{"z": {"$elemMatch": {"$eq": 8} }, "x": {"$elemMatch": {"$eq": 3} }, "y": {"$elemMatch": {"$eq": 4} }}', '{}' ); -- -- Error Cases -- $elemMatch on nested fields SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": {"b" : [ 11, 21, 31, 41 ], "z": "World" }}', '{"a.b": {"$elemMatch": {"$gt":25} } }', '{}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a": {"b" : [ 11, 21, 31, 41 ], "z": "World" }}', '{"a": {"b": {"$elemMatch": {"$gt":25} } } }', '{}'); -- When positional and elemMatch projection are given together SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"$gt": 15} }, "b.$": 1 }', '{ "a": {"$elemMatch": {"$gt": 15} } }' ); SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "b.$": 1, "a": {"$elemMatch": {"$gt": 15} } }', '{ "a": {"$elemMatch": {"$gt": 15} } }' ); -- $jsonSchema doesn't work with projection $elemMatch SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"$jsonSchema": {}} } }', '{ }' ); -- This is a bad place for jsonSchema spec, because $jsonSchema comes at top level field SELECT * FROM bson_dollar_project_find( '{ "_id": 2, "a": [ 11, 21, 31 ], "b": [41, 51, 61], "d": 71, "e": {"f": "good"} }', '{ "a": {"$elemMatch": {"b" : {"$jsonSchema": {}} } } }', '{ }' ); --unresolved fields select bson_dollar_project_find('{"_id":"1", "a" :[[1],[2],[3],[4]]}', '{"c" : { "$elemMatch" : {}}}',NULL); select bson_dollar_project_find('{"_id":"1", "a" :[1,2,3,4]}', '{"a" : { "$elemMatch" : {"$gt" : 1}}, "c" : { "$elemMatch" : {}}}',NULL); bson_projection_operator_positional_tests_core.sql000066400000000000000000000244611507310017400413240ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 270000; SET documentdb.next_collection_id TO 2700; SET documentdb.next_collection_index_id TO 2700; -- Invalid scenarios SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 1, "b.$": 1}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a..$": 1}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$slice": 1}}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 0}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": [1,2,3]}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": "Hello"}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "0"}}', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a": 1, "a.$": 1 }', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b": 1, "a.b.$": 1 }', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a": 1, "a.b.$": 1 }', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": 1, "a": 1 }', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b.$": 1, "a.b": 1 }', '{}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.b": 1, "a.$": 1 }', '{}'); -- some basic positional projection test SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "Infinity"}}', '{"a": 1}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3] }', '{ "a.$": {"$numberDecimal": "NaN"}}', '{"a": 2}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 1}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 2}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3] }', '{ "a.$": 1}', '{"a": 3}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [6,5,4] }', '{ "a.$": 1}', '{"b": 6}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": 1, "c": 8, "b": 5}'); -- with $and SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$and": [{"a": 1}, {"c": 8}, {"b": 5}]}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$and": [{"a": 2}, {"a": 3}, {"a": 1}]}'); -- with $nor and $not and complex $or - Error SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$nor": [{"a": 1}, {"c": 8}, {"b": 5}]}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$not": {"$eq": 3}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": 3}, {"b": 6}]}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": {"$gte": 1}}, {"a": {"$lt": 3}}]}'); -- with $in SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$in": [1,2,3]}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$in": [4,5,3]}}'); -- $or with simple expressions converted to $in SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": 2}, {"a": 3}, {"a": 1}]}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"$or": [{"a": {"$in": [3]}}, {"a": {"$in": [2]}}, {"a": {"$in": [1]}}]}'); -- positional with various conditions SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$eq": 2}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[[1],[2],[3]], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$elemMatch": {"$eq": 3}}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[[1,2], [3,4]], "b": [[5,6], [7,8]], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$elemMatch": {"$elemMatch": {"$eq": 3}}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[{"b": [1,2,3]}, {"b": [4,5,6]}, {"b": [7,8,9]}], "c": [10, 11, 12] }', '{ "c.$": 1}', '{"a": {"$elemMatch": {"b": {"$elemMatch": {"$eq": 6}}}}}'); SELECT * FROM bson_dollar_project_find('{ "x": [{"y": 1}, {"y": 2}, {"y": 3}] }', '{ "x.$": 1}', '{"x": {"$elemMatch": {"y": {"$gt": 1}}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1, {"b": [4,5,6]}, {"b": [7,8,9]}], "c": [10, 11, 12] }', '{ "c.$": 1}', '{"a": {"$elemMatch": {}}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,3], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$type": "int"}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[1,2,"string"], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a": {"$type": "string"}}'); SELECT * FROM bson_dollar_project_find('{ "a" :[{"c": 1}, {"c": 2}, {"b": 3}], "b": [6,5,4], "c": [7,8,9] }', '{ "b.$": 1}', '{"a.b": {"$exists": true}}'); -- non existent fields SELECT * FROM bson_dollar_project_find('{"x": [{"a": 1, "b": 2}, {"a": 2, "c": 3}, {"a": 1, "d": 5}], "y": [{"aa": 1, "bb": 2}, {"aa": 2, "cc": 3}, {"aa": 1, "dd": 5}]}', '{"g.$": 1}', '{}'); -- positional on non array fields SELECT * FROM bson_dollar_project_find('{ "a" :[{"c": 1}, {"c": 2}, {"b": 3}], "b": 25, "c": [7,8,9] }', '{ "b.$": 1}', '{"a.b": {"$exists": true}}'); -- on nested path SELECT * FROM bson_dollar_project_find('{"x": [-1, 1, 2], "a": {"b": {"d": [1,2,3]}, "f": 456}, "e": 123}', '{"a.b.c.$": 1}', '{"x": {"$gt": 0}}'); SELECT * FROM bson_dollar_project_find('{"x": {"y": [{"a": 1, "b": 1}, {"a": 1, "b": 2}]}}', '{"x.y.$": 1}', '{"x.y.a": 1}'); SELECT * FROM bson_dollar_project_find('{"x": [1], "a": [{"b":[[[{"c": 1, "d": 2}]]]}]}', '{"a.b.c.$": 1}', '{"x": 1}'); -- Only relevant path is included -- in a nested path match the query on the first array and include only the fields requested in positional SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": [{"b": {"c": [1,2,3]}}, {"b": {"c": [4,5,6]}}, {"b": {"c": [7,8,9]}}]}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": {"b": [{"c": [1,2,3]}, {"c": [4,5,6]}, {"c": [7,8,9]}]}}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); SELECT * FROM bson_dollar_project_find('{"x": {"y": {"z": [0,1,2]}}, "a": {"b": {"c": [1,2,3]}}}', '{"a.b.c.$": 1}', '{"x.y.z": 1}'); -- errors if no match found or matched index is greater than size of array SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [4,5,6,7] }', '{ "a.$": 1}', '{"b": 2}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": [4,5,6,7] }', '{ "a.$": 1}', '{"b": 7}'); -- Test with multiple docs BEGIN; SELECT documentdb_api.insert_one('db','positionalProjection', '{"_id": 1, "a" : { "b" : [{"c": 1, "d": 1}, {"c": 2, "d": 2}]}, "x": [1,2]}', NULL); SELECT documentdb_api.insert_one('db','positionalProjection', '{"_id": 2, "a" : { "b" : {"c": [11, 12], "d": [13, 14]} }, "x": [1,2]}', NULL); SELECT bson_dollar_project_find(document, '{"a.b.c.$": 1}', '{"x": 2}') FROM documentdb_api.collection('db', 'positionalProjection') WHERE document @@ '{ "x": 2}' ORDER BY object_id; ROLLBACK; -- Empty or null query Spec SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "a.$": 1}', NULL); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "a.$": 1}', '{}'); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.c.d.$": 1}', NULL); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.c.d.$": 1}', '{}'); -- Empty or null with non array spec field works SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": [{"d": 1, "e": 2}]} }', '{ "b.$": 1}', NULL); SELECT * FROM bson_dollar_project_find('{ "_id": 1, "a" :[1,2,3], "b": {"c": {"d": 1, "e": 2}} }', '{ "b.c.d.$": 1}', '{}'); -- $project and $addFields doesn't support positional, TODO throw native mongo error for $project SELECT * FROM bson_dollar_project('{ "_id": 1, "a" :[{ "b": {"c": [1,3,2]}, "d": {"e": [4,5,6]}}]} ', '{"a.b.c.$": 1 }'); SELECT bson_dollar_add_fields('{"a": {"b": [1,2,3]}}', '{ "a.b.$" : "1", "a.y": ["p", "q"]}'); --sharded collection tests BEGIN; -- Insert data into a new collection to be sharded SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 0, "key": {"a": "b"}, "a" : [{"b": 1, "c": 1}, {"b": 1, "c": 2}], "x":[11,12,13] }', NULL); SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 1, "key": {"a": "b"}, "a" : [{"b": {"c": 1}}, {"b": {"c": 2}}], "x":[11,12,13] }', NULL); SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 2, "key": {"b": "c"}, "a" : { "b": [{"c": 1, "d": 1}, {"c": 2, "d": 2}] }, "x":[11,12,13] }', NULL); SELECT documentdb_api.insert_one('db','positional_sharded',' { "_id" : 3, "key": {"c": "d"}, "a" : { "b": {"c": [{"d": 1, "d": 2}], "e": [1,2,3]} }, "x":[11,12,13] }', NULL); -- Shard orders collection on key SELECT documentdb_api.shard_collection('db','positional_sharded', '{"key":"hashed"}', false); SELECT bson_dollar_project_find(document, '{"a.b.c.$": 1}', '{"x": 11}') FROM documentdb_api.collection('db', 'positional_sharded') WHERE document @@ '{ "x": 11}' ORDER BY object_id; ROLLBACK; bson_query_disable_seqscan_tests.sql000066400000000000000000000033751507310017400363320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 730000; SET documentdb.next_collection_id TO 7300; SET documentdb.next_collection_index_id TO 7300; SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 1, "a": 1 }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 2, "a": -500 }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 3, "a": { "$numberLong": "1000" } }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 4, "a": true }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 5, "a": "some string" }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 6, "a": { "b": 1 } }'); SELECT documentdb_api.insert_one('seqscandb', 'seqscandistest', '{ "_id": 7, "a": { "$date": {"$numberLong": "123456"} } }'); set documentdb.forceDisableSeqScan to on; -- should fail SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "a": { "$eq": 1 } } }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('seqscandb', '{ "createIndexes": "seqscandistest", "indexes": [ { "key": { "a": 1 }, "name": "idx_a" }] }', true); -- fail to push down SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "b": { "$eq": 1 } } }'); SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest" }'); -- passes SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "a": { "$eq": 1 } } }'); SELECT document FROM bson_aggregation_find('seqscandb', '{ "find": "seqscandistest", "filter": { "_id": { "$gt": 4 } } }');bson_query_index_selection_sharded_tests.sql000066400000000000000000000042671507310017400400610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3610000; SET documentdb.next_collection_id TO 3610; SET documentdb.next_collection_index_id TO 3610; -- insert 10K documents SELECT COUNT (*) FROM ( SELECT documentdb_api.insert_one('db', 'test_index_selection_sharded', FORMAT('{ "a": { "b": %s, "c": %s } }', i, i)::bson) FROM generate_series(1, 10000) i) r1; SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'test_index_selection_sharded'); -- create indexes on a.b, and a.c SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_index_selection_sharded", "indexes": [ { "name": "a_b_1", "key": { "a.b": 1 } }, { "name": "a_c_1", "key": { "a.c": 1 }}] }', true); -- Now, do an explain with an OR query that each uses 1 of the indexes. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$and": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; BEGIN; set local citus.enable_local_execution to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; ROLLBACK; -- Now shard the collection SELECT documentdb_api.shard_collection('db', 'test_index_selection_sharded', '{ "_id": "hashed" }', false); -- rerun the query BEGIN; set local enable_seqscan to off; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$or": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_index_selection_sharded') WHERE document @@ '{ "$and": [ { "a.b": { "$gt": 500 } }, { "a.c": { "$lt": 10 } } ] }'; ROLLBACK; bson_query_modifier_orderby_tests_core.sql000066400000000000000000000146021507310017400375410ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }') ASC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": 1 }') ASC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }') ASC, bson_orderby(document, '{ "a.b.0": -1 }') DESC; SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') WHERE document @@ '{ "a.b": { "$in": [ 0, 1, 2, 3 ] } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); PREPARE q1(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1); PREPARE q1desc(bson) AS SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, $1) DESC; EXECUTE q1('{ "a.b.0": 1 }'); EXECUTE q1desc('{ "a.b.0": -1 }'); EXECUTE q1('{ "a.b.0": 1 }'); EXECUTE q1desc('{ "a.b.0": -1 }'); EXECUTE q1('{ "a.b.0": 1 }'); EXECUTE q1desc('{ "a.b.0": -1 }'); EXECUTE q1('{ "a.b.0": 1 }'); -- now insert items that are sorted "After" arrays (e.g. boolean) SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 14, "a" : [ { "b": [ true, false ] }, { "b": [ true ] } ] }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 15, "a" : { "b": [ [ true, false], [ false, true ] ] } }', NULL); SELECT documentdb_api.insert_one('db','bsonorderby', '{"_id": 16, "a" : { "b": true } }', NULL); -- doesn't consider the array itself but considers nested arrays. SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); SELECT object_id, document FROM documentdb_api.collection('db', 'bsonorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; -- sort order across types (see sorta.js). SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 0, "a": { "$minKey": 1 } }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 3, "a": null }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 1, "a": [] }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 7, "a": [ 2 ] }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 4 }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 5, "a": null }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 2, "a": [] }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 6, "a": 1 }'); SELECT documentdb_api.insert_one('db', 'sortordertests', '{ "_id": 8, "a": { "$maxKey": 1 } }'); SELECT object_id, document FROM documentdb_api.collection('db', 'sortordertests') ORDER BY bson_orderby(document, '{ "a": 1 }'), object_id; SELECT bson_orderby('{ "b": 1 }', '{ "b": -1 }') = '{ "b": 1 }'; SELECT bson_orderby('{ "b": 1 }', '{ "b": 1 }') = '{ "b": 1 }'; SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": -1 }') = '{ "b": { "c": 1 } }'; SELECT bson_orderby('{ "b": { "c" : 1 } }', '{ "b": 1 }') = '{ "b": { "c": 1 } }'; SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 1 } }'; SELECT bson_orderby('{ "b": [ { "c" : 1 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": -1 }') = '{ "b" : { "c": 2 } }'; SELECT bson_orderby('{ "b": [ { "c" : 1 }, { "c": 2 } ] }', '{ "b": 1 }') = '{ "b" : { "c": 1 } }'; SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": -1 }') = '{ "b": 3 }'; SELECT bson_orderby('{ "b": [ 1, 2, 3 ] }', '{ "b": 1 }') = '{ "b": 1 }'; SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": -1 }') = '{ "b": true }'; SELECT bson_orderby('{ "b": [ true, false, false ] }', '{ "b": 1 }') = '{ "b": false }'; SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": -1 }') = '{ "b": [3] }'; SELECT bson_orderby('{ "b": [ [1], [2], [3] ] }', '{ "b": 1 }') = '{ "b": [1] }'; SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": -1 }') = '{ "b": true }'; SELECT bson_orderby('{ "b": [ 1, true, "someString" ] }', '{ "b": 1 }') = '{ "b": 1 }'; SELECT bson_orderby('{ "b": [ 1, { "c": 2 }, "someString" ] }', '{ "b.c": -1 }') = '{ "b.c": 2 }'; bson_query_modifier_orderby_tests_explain_core.sql000066400000000000000000000061501507310017400412600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_api_catalog, documentdb_core, documentdb_api_internal; /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 9, "a" : { "b" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','bsoexplainnorderby', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": -1 }') DESC; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.0": -1 }') DESC; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b.1": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": -1 }') DESC; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gt": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.0": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b.0": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a.b": { "$gte": 0 } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'), bson_orderby(document, '{ "a.b.1": 1 }'); EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'bsoexplainnorderby') WHERE document @@ '{ "a": { "$gte": { "b": 0 } } }' ORDER BY bson_orderby(document, '{ "a.b": 1 }'); bson_query_modifier_orderby_tests_explain_index.sql000066400000000000000000000020761507310017400414420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_api_catalog; SET citus.next_shard_id TO 3400000; SET documentdb.next_collection_id TO 3400; SET documentdb.next_collection_index_id TO 3400; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsoexplainnorderby'); SELECT documentdb_api.create_collection('db', 'bsoexplainnorderby'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsoexplainnorderby'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsoexplainnorderby', 'index_2', '{"a.b": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsoexplainnorderby', 'index_3', '{"a.b.1": 1}'), true); BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; set local citus.enable_local_execution TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_modifier_orderby_tests_explain_core.sql ROLLBACK;bson_query_modifier_orderby_tests_explain_runtime.sql000066400000000000000000000007201507310017400420100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql set search_path to documentdb_api_catalog; SET citus.next_shard_id TO 3400000; SET documentdb.next_collection_id TO 3400; SET documentdb.next_collection_index_id TO 3400; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsoexplainnorderby'); SELECT documentdb_api.create_collection('db', 'bsoexplainnorderby'); BEGIN; set enable_seqscan to on; set local citus.enable_local_execution TO OFF; \i sql/bson_query_modifier_orderby_tests_explain_core.sql ROLLBACK;bson_query_modifier_orderby_tests_index.sql000066400000000000000000000020451507310017400377160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3500000; SET documentdb.next_collection_id TO 3500; SET documentdb.next_collection_index_id TO 3500; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsonorderby'); SELECT documentdb_api.create_collection('db', 'bsonorderby'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsonorderby'); \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsonorderby', 'index_2', '{"a.b": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('bsonorderby', 'index_3', '{"a.b.1": 1}'), true); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan to off; set local enable_bitmapscan to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_modifier_orderby_tests_core.sql ROLLBACK; bson_query_modifier_orderby_tests_runtime.sql000066400000000000000000000010261507310017400402700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 3500000; SET documentdb.next_collection_id TO 3500; SET documentdb.next_collection_index_id TO 3500; SELECT 1 FROM documentdb_api.drop_collection('db', 'bsonorderby'); SELECT documentdb_api.create_collection('db', 'bsonorderby'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'bsonorderby'); BEGIN; set enable_seqscan to off; \i sql/bson_query_modifier_orderby_tests_core.sql ROLLBACK; bson_query_operator_array_tests_core.sql000066400000000000000000000126671507310017400372570ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql -- some documents with mixed types SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 1, "value": 42 }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 2, "value": -999 }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 3, "value": { "longNum": "2048" } }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 4, "value": false }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 5, "value": "alpha beta" }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 6, "value": { "subfield": 7 } }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 7, "value": { "dateField": { "longNum": "654321" } } }'); -- now insert some documents with arrays with those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 100, "value": [ 42, "bravo charlie", false ] }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 101, "value": [ false, -999, { "subfield": 7 }, 8, 9, 10 ] }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 102, "value": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] }'); -- now insert some documents with arrays of arrays of those terms SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 200, "value": [ 42, [ false, "alpha beta" ] ] }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 201, "value": [ false, -999, { "subfield": 7 }, [ 42, "bravo charlie", false ] ] }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 202, "value": [ [ false, -999, { "subfield": 7 }, 8, 9, 10 ] ] }'); -- insert empty arrays SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 300, "value": [ ] }'); SELECT documentdb_api.insert_one('array_query_db', 'array_operator_tests', '{ "_id": 301, "value": [ [], "zuluValue" ] }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ 42, "bravo charlie", false ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ 42, "bravo charlie", false ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ 42, "bravo charlie", false ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gt": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$gte": [ false, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lt": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$lte": [ true, -999, { "subfield": 7 }, 42, 99, { "dateField": { "longNum": "654321" } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$eq": [ ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ 42, [ false, "alpha beta" ] ] ]} } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$in": [ [ 42, "bravo charlie", false ], [ ] ]} } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 3 } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 2 } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$size": 0 } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42, false ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ 42 ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 0 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$all": [ { "$elemMatch": { "$gt": 8, "$lt": 10 } }, { "$elemMatch": { "subfield": 7 } } ] } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "$gt": 8, "$lt": 10 } } } }'); SELECT document FROM bson_aggregation_find('array_query_db', '{ "find": "array_operator_tests", "filter": { "value": { "$elemMatch": { "subfield": { "$gt": 0 } } } } }');bson_query_operator_array_tests_index_composite.sql000066400000000000000000000015071507310017400415070ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 380000; SET documentdb.next_collection_id TO 3800; SET documentdb.next_collection_index_id TO 3800; set enable_seqscan TO off; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to on; SELECT documentdb_api.drop_collection('array_query_db', 'array_operator_tests') IS NOT NULL; SELECT documentdb_api_internal.create_indexes_non_concurrently('array_query_db', '{ "createIndexes": "array_operator_tests", "indexes": [ { "key": { "value": 1 }, "enableCompositeTerm": true, "name": "queryoperator_value" }, { "key": { "value.subfield": 1 }, "enableCompositeTerm": true, "name": "queryoperator_value_subfield" }] }', true) IS NOT NULL; \i sql/bson_query_operator_array_tests_core.sqlbson_query_operator_array_tests_runtime.sql000066400000000000000000000011051507310017400377730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 661000; SET documentdb.next_collection_id TO 6610; SET documentdb.next_collection_index_id TO 6610; set enable_seqscan TO on; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to off; SELECT documentdb_api.drop_collection('array_query_db', 'array_operator_tests') IS NOT NULL; SELECT documentdb_api.create_collection('array_query_db', 'array_operator_tests') IS NOT NULL; \i sql/bson_query_operator_array_tests_core.sqlbson_query_operator_elemmatch_explain_composite.sql000066400000000000000000000120371507310017400414370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1064000; SET documentdb.next_collection_id TO 10640; SET documentdb.next_collection_index_id TO 10640; set enable_seqscan TO on; set documentdb.forceUseIndexIfAvailable to on; set documentdb.forceDisableSeqScan to off; SELECT documentdb_api.drop_collection('comp_elmdb', 'cmp_elemmatch_ops') IS NOT NULL; SELECT documentdb_api.create_collection('comp_elmdb', 'cmp_elemmatch_ops') IS NOT NULL; SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_elmdb', '{ "createIndexes": "cmp_elemmatch_ops", "indexes": [ { "key": { "price": 1 }, "name": "price_1", "enableCompositeTerm": true }, { "key": { "brands": 1 }, "name": "brands_1", "enableCompositeTerm": true } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('comp_elmdb', '{ "createIndexes": "cmp_elemmatch_ops", "indexes": [ { "key": { "brands.name": 1 }, "name": "brands.name_1", "enableCompositeTerm": true }, { "key": { "brands.rating": 1 }, "name": "brands.rating_1", "enableCompositeTerm": true } ] }', TRUE); SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 1, "price": [ 120, 150, 100 ] }'); SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 2, "price": [ 110, 140, 160 ] }'); -- pushes to the price index set documentdb.enableExtendedExplainPlans to on; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$gt": 120, "$lt": 150 } } } }'); -- without the GUC becomes a disjoint index filter set documentdb.useNewElemMatchIndexOperatorOnPushdown to off; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$gt": 120, "$lt": 150 } } } }'); reset documentdb.useNewElemMatchIndexOperatorOnPushdown; EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$in": [ 120, 140 ], "$gt": 121 } } } }'); EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$type": "number" } } } }'); EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$ne": 160 } } } }'); EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$elemMatch": { "$nin": [ 160, 110, 140] } } } }'); -- now test some with nested objects SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 3, "brands": [ { "name" : "alpha", "rating" : 5 }, { "name" : "beta", "rating" : 3 } ] }'); SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 4, "brands": [ { "name" : "alpha", "rating" : 4 }, { "name" : "beta", "rating" : 2 } ] }'); SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 5, "brands": [ { "name" : "alpha", "rating" : 2 }, { "name" : "beta", "rating" : 4 } ] }'); EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": "alpha", "rating": 2 } } } }'); EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": "alpha" } } } }'); -- test elemMatch behavior when confronted with multiple arrays SELECT documentdb_api.insert_one('comp_elmdb', 'cmp_elemmatch_ops', '{ "_id": 6, "brands": [ { "name": [ "gurci", "dolte" ], "rating": 5 } ]}'); -- this technically matches the doc 6 above and the elemMatches don't get joined. EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands": { "$elemMatch": { "name": { "$gt": "gabba", "$lt": "ergo" } } } } }'); -- this can now join the elemMatch filters EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "brands.name": { "$elemMatch": { "$gt": "gabba", "$lt": "ergo" } } } }'); -- disjoint filter handling for elemMatch and non elemMatch: this matches a document since these are matching different elements of the array. EXPLAIN (COSTS OFF, ANALYZE ON, TIMING OFF, SUMMARY OFF) SELECT document FROM bson_aggregation_find('comp_elmdb', '{ "find": "cmp_elemmatch_ops", "filter": { "price": { "$eq": 110, "$elemMatch": { "$gt": 155, "$lt": 165 } } } }'); bson_query_operator_elemmatch_tests_core.sql000066400000000000000000000230541507310017400400700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- Test $elemMatch query operator /* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); /* Simple comparison */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {} } }'; /* Comparison operator in elemMatch */ -- Comparison ops on same paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gte" : 1, "$lt" : 2} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$gt" : 1, "$lte" : 2} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": null} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : [18]} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : 18} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : 18} } } }'; -- Comparison ops on different paths inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 1}, "c": 3} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$gte": 1, "$lte": 1 }, "c": 2} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$not": {"$elemMatch": {"b": 1, "c": 2} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$ne": 2}, "c": 2} } }'; /* Logical operator in elemMatch */ -- Logical ops on same path inside array SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$or": [{"b": "1"}, {"c": 2}] } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$and" : [ { "a" : { "$elemMatch" : { "$gt" : 1, "$not" : { "$gt" : 2 } } } }]}'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"$or" : [ {"a.b": {"$elemMatch": {"$eq": 10}}}, {"a.b": {"$elemMatch": {"$eq": 7}}}]}'; -- elemMatch with Logical ops and non-logical op SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 21, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 22, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 23, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); /* Nested elemMatch */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$in": [3] } } } } } }'; -- d.e being the path in nested elemMatch SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d.e": { "$elemMatch": { "$gte": 2, "$lte": 2 } } } } }'; /* Non $elemMatch expression and a nested $elemMatch. */ SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ [ { "b" : 1 } ] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": [ [ { "b" : [1] } ] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": [ 100 ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": { "0" : 100 } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": { "0" : [ 100 ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "0" : 100 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 38, "a": [ { "0" : [ 100 ] } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 39, "a": [ { "-1" : 100 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 40, "a": { "b" : [ [ 100, 200, 300 ] ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 41, "a": { "b" : [ { "c" : [100] } ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 42, "a": { "b" : [ { "c" : [[100]] } ] } }', NULL); SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "b" : { "$eq" : 1 } } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0" : { "$elemMatch": {"$eq": 100 } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c" : { "$elemMatch": {"$eq": 100 } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b.0.c.0" : { "$elemMatch": {"$eq": 100 } } }'; bson_query_operator_elemmatch_tests_explain_core.sql000066400000000000000000000163661507310017400416200ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/* Insert with a being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 1, "a" : [ 1, 2 ] }', NULL); /* Insert with a.b being an array of elements*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 2, "a" : { "b" : [ 10, 15, 18 ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 3, "a" : { "b" : [ 7, 18, 19 ] } }', NULL); /* Insert with a being an array of objects*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 4, "a" : [ {"b" : 1 }, {"b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 5, "a" : [ {"b" : 3 }, {"b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 6, "a": [ {}, {"b": 2} ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 7, "a": [ {"b": 1, "c": 2}, {"b": 2, "c": 2} ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 8, "a": [ 1, 15, [18] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 9, "a": [ 1, 15, {"b" : [18]} ] }', NULL); /* Insert with a being an array of objects and a.b is also an array*/ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 10, "a": [{ "b": [ 10, 15, 18 ], "d": [ {"e": 2} ] }] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 12, "a": [{ "b": [ 7, 18, 19 ], "d": [ {"e": 3} ], "f" : 1 }] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 13, "a": [{ "d": [ {"e": [2] } ] }] }', NULL); -- run an explain analyze EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$in": [3]} } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$nin": [1, 2, 3]} } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"$eq" : {"b" : [18]} } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": {"$exists" : false} } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": 1, "c": 2} } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$and": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$nor": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": { "$not": {"$gt" : 18, "$lte" : 19} } } }'; -- elemMatch with Logical ops and non-logical op EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}], "b" : 3 } } }'; /* Nested elemMatch */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"b": { "$elemMatch" : { "$gte": 10, "$lt": 15 } } } } }'; -- NOTE: The explain plan can be confusin while printing for alias name for two adjacent elemMatch. In SubPlan 2, you will see it has alias elemmatchd2_1 created but using elemmatchd2 in filters. As per the query plan, filter qual is using attNumber=1 which is expected to refer its immediate RTE that will have :colnames ("elemmatchd2"). I have also tested using query: it is not possible that alias defined inside one EXISTS() be used outside of it and inside any other EXISTS(). EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2, "$lte": 2 } } }, "b": { "$elemMatch": { "$gte": 10, "$lt": 55 } } } } }'; /* Non $elemMatch expression and a nested $elemMatch. */ EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.f": 1, "a" : { "$elemMatch": {"d": { "$elemMatch": { "e": { "$gte": 2 } } } } } }'; /* Insert with a being an array of array or fieldPath contains number */ SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 31, "a": [ [ 100, 200, 300 ] ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 32, "a": [ 100 ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 33, "a": { "0" : 100 } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 34, "a": { "0" : [ 100 ] } }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 35, "a": [ { "0" : 100 } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 36, "a": [ { "0" : [ 100 ] } ] }', NULL); SELECT documentdb_api.insert_one('db','elemmatchtest', '{"_id": 37, "a": [ { "-1" : 100 } ] }', NULL); -- below queries will use $type:array internally as first filter EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$elemMatch" : { "$in":[ 100 ] } } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : 100 } } }'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "0" : {"$gte" : 100 } } } }'; -- below query will not use $type internally EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "-1" : {"$gte" : 100 } } } }'; bson_query_operator_elemmatch_tests_explain_index.sql000066400000000000000000000037151507310017400417710ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 720000; SET documentdb.next_collection_id TO 7200; SET documentdb.next_collection_index_id TO 7200; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('elemmatchtest', 'index_2', '{"$**": 1}'), true); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); BEGIN; set local enable_seqscan TO off; set local citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_elemmatch_tests_explain_core.sql ROLLBACK; -- Shard the collection and run an explain analyze SELECT documentdb_api.shard_collection('db','elemmatchtest', '{"_id":"hashed"}', false); BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; $Q$); SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; $Q$); ROLLBACK; bson_query_operator_elemmatch_tests_explain_runtime.sql000066400000000000000000000027101507310017400423370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 720000; SET documentdb.next_collection_id TO 7200; SET documentdb.next_collection_index_id TO 7200; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); BEGIN; set local enable_seqscan TO on; set local citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; \i sql/bson_query_operator_elemmatch_tests_explain_core.sql ROLLBACK; -- Shard the collection and run an explain analyze SELECT documentdb_api.shard_collection('db','elemmatchtest', '{"_id":"hashed"}', false); BEGIN; set local enable_seqscan TO on; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a.b" : { "$elemMatch": {"$gte" : 10, "$lte" : 15} }}'; $Q$); SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": { "$or": [{ "b": {"$gte": 1} }, { "b": { "$lt": 2 }}] } } }'; $Q$); ROLLBACK; bson_query_operator_elemmatch_tests_index.sql000066400000000000000000000024221507310017400402430ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 260000; SET documentdb.next_collection_id TO 2600; SET documentdb.next_collection_index_id TO 2600; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; \set prevEcho :ECHO \set ECHO none \o /dev/null -- Create a wildcard index by using CREATE INDEX command instead of -- using documentdb_api.create_indexes. This is because, we will use -- that index to test whether we can use the index via query operators -- other than "@@". SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('elemmatchtest', 'index_2', '{"$**": 1}'), true); \o \set ECHO :prevEcho -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_elemmatch_tests_core.sql ROLLBACK; -- Invalid Arguments SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": [] }}'; bson_query_operator_elemmatch_tests_runtime.sql000066400000000000000000000013721507310017400406220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 260000; SET documentdb.next_collection_id TO 2600; SET documentdb.next_collection_index_id TO 2600; SELECT documentdb_api.drop_collection('db', 'elemmatchtest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'elemmatchtest') IS NOT NULL; -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','elemmatchtest'); BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_elemmatch_tests_core.sql ROLLBACK; -- Invalid Arguments SELECT object_id, document FROM documentdb_api.collection('db', 'elemmatchtest') where document @@ '{"a" : { "$elemMatch": [] }}'; bson_query_operator_error_tests.sql000066400000000000000000000206161507310017400362530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 30000; SET documentdb.next_collection_id TO 300; SET documentdb.next_collection_index_id TO 300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn'); SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield'); SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); \i sql/bson_query_operator_tests_insert.sql -- these queries are negative tests for $size operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : -3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : -3.4 }}' ORDER BY object_id; -- These can't be tested since the extended json syntax treats $type as an extended json operator and not a call to actual $type function. -- SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : 123.56 }}' ORDER BY object_id; -- SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : [] }}' ORDER BY object_id; -- these queries are negative tests for $all operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, 1 ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ 1, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, {"$all" : [0]} ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$all" : [0]}, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, {} ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {}, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, { "b" : 1 } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ { "b" : 1 }, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$elemMatch" : {"b" : {"$gt" : 1} } }, { "$or" : [ {"b":1} ] } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ { "$or" : [ {"b":1} ] }, {"$elemMatch" : {"b" : {"$gt" : 1} } } ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [ {"$all" : [1] } ] } }' ORDER BY object_id; -- negative tests for $not operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$not" : {} } }'; -- negative tests for comp operators with regex SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$ne" : {"$regex" : "hello", "$options" : ""} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$gt" : {"$regex" : "hello", "$options" : ""} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$gte" : {"$regex" : "hello", "$options" : ""} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$lt" : {"$regex" : "hello", "$options" : ""} } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$lte" : {"$regex" : "hello", "$options" : ""} } }'; -- type undefined, no-operator SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$undefined" : true } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : 1, "b" : { "$undefined" : true } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : { "$undefined" : true } }'; -- type undefined, comparison query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$gt" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$gte" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$lt" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$lte" : { "$undefined" : true } } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in" : [ { "$undefined" : true } ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in" : [ { "$undefined" : true }, 2, 3, 4 ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin" : [ { "$undefined" : true } ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin" : [ { "$undefined" : true }, 6, 7, 8] } }'; -- type undefined, array query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$all" : [ { "$undefined" : true } ] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$all" : [ { "$undefined" : true }, 2 ] } }'; --type undefined, bitwise query operators SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllClear": {"$undefined": true}}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllClear": [1, {"$undefined": true}]}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllSet": {"$undefined": true}}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAllSet":[1, {"$undefined": true}]}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnyClear": {"$undefined": true}}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnyClear": [1, {"$undefined": true}]}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnySet": {"$undefined": true}}}'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a": {"$bitsAnySet": [1, {"$undefined": true}]}}'; bson_query_operator_geospatial_core.sql000066400000000000000000000303651507310017400370420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- Insert multiple items SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); -- Insert items for $center corner case test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geo" : { "loc": [ 2, 5 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geo" : { "loc": [ 5, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geo" : { "loc": [ 5, 8 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 204, "geo" : { "loc": [ 4, 5 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 205, "geo" : { "loc": [ 5, 4 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 206, "geo" : { "loc": [ 5, 6 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 207, "geo" : { "loc": [ 6, 5 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 208, "geo" : { "loc": [ 0, 0 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 209, "geo" : { "loc": [ 0, 10 ] } }', NULL); -- $geoWithin / $within => $box shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[19.00001, 19.00002], [29.9999, 29.9999]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [64, 64]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [65, 65]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10}, "bottomRight": {"x": 10, "y": 10}} }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": {"bottomLeft": {"x": 10, "y": 10, "z": 20}, "bottomRight": {"x": 10, "y": 10, "z": 20 }}}}}' ORDER BY object_id; -- $geoWithin / $within => $center shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[5, 10], 5]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[15, 14], 10]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 50]}}}' ORDER BY object_id; -- This will not include [10, 10] SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[50, 50], 60]}}}' ORDER BY object_id; -- The radius is enough to include [10, 10] now SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [ { "x": 5, "y": 10 }, 5]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$center": [[0,0], { "$numberDecimal" : "Infinity" }]}}}' ORDER BY object_id; -- infinite radius SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 3]}}}' ORDER BY object_id; -- _id 201,202,203 on boundary SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[5, 5], 1]}}}' ORDER BY object_id; -- _id 204,205,206 on boundary SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[0, 5], 5]}}}' ORDER BY object_id; -- _id 208,209 on boundary -- $geoWithin / $within => $polygon shape operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}' ORDER BY object_id; -- [10, 10] included SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 10], [10, 10]]}}}' ORDER BY object_id; -- boundary check SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [10, 12], [11, 11], [9, 11]]}}}' ORDER BY object_id; -- Invalid polygon with self intersection SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [20, 20], [26, 26], [25, 12]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[10, 10], [80, 80], [60, 60], [20, 20]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], {"x": 11, "y": 11}, [12, 5]]}}}' ORDER BY object_id; -- Validate non-geo query operator are not pushed to geo indexes but regular indexes and works fine SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}' ORDER BY object_id; -- Test valid polygons in query SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]]}}}}'; -- Polygon with points on a great circle of earth SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]]}}}}'; -- Polygon with points on the same longitude SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]]}}}}'; -- Polygon with points on a single latitude, appear as straight line in 2d SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89], [-60, 89], [0, 89], [120, 89], [-120.0, 89]]]}}}}'; -- Polygon with points on a single latitude close to north pole SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]]}}}}'; -- Polygon with points on a single latitude, points going around the earth with similar hole -- Special case for array of legacy pairs SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "c" : { "d": [ [10, 10], [100, 100] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "c" : { "d": [ [100, 100], [10, 10] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "c" : [{ "d": [100, 100]}, { "d": [10, 10]}] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "c" : [{ "d": [10, 10]}, { "d": [100, 100]}] }', NULL); -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[0, 0], 20]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"c.d": {"$geoWithin": {"$center": [[90, 90], 20]}}}' ORDER BY object_id;bson_query_operator_geospatial_explain_core.sql000066400000000000000000000361241507310017400405610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- Insert multiple items - 2d index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "a" : { "b": [10, 10] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "a" : { "b": { "long": { "$numberLong": "20" }, "lat": { "$numberInt": "20" } } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "a" : [ {"b": { "long": 25, "lat": 25 }}, [ { "$numberDouble": "30" }, { "$numberDecimal": "30" }], [35, 35]] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); -- Insert multiple items - 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "geo" : { "loc": [2.1, 2.2] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 103, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 104, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 105, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 106, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 107, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 108, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 109, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 110, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 111, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 112, "geo" : { "loc": [120, 89.1 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 113, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 114, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format -- Insert couple of items for testing index usage with partial filter expression SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "d" : [15, 15], "e": 1 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "d" : [16, 16], "e": 2 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "d" : [17, 17], "e": 3 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "d" : [18, 18], "e": 4 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "d" : [19, 19], "e": 5 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "d" : [20, 20], "e": 6 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "d" : [21, 21], "e": 7 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "d" : [22, 22], "e": 8 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "d" : [23, 23], "e": 9 }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "d" : [24, 24], "e": 10 }', NULL); -- Insert couple of items for composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 500, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 501, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); -- 2d index explain -- $geoWithin / $within => $box shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [10, 10]]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$box": [[10, 10], [10, 10]]}}}'; -- $geoWithin / $within => Hashes of $center/$centerSphere may vary so skipping those here to avoid flakiness -- $geoWithin / $within => $polygon shape operator EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$within": {"$polygon": [[5, 10], [11, 11], [12, 5]]}}}'; -- Explain plan with partial filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$gte": 5}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 5}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoWithin": {"$box": [[10, 10], [30, 30]]}}, "e": {"$eq": 3}}'; -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$eq": [10, 10]}}'; -- 2dSphere index explains -- $geoIntersects explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; -- With pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$gte": 5}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 5}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"d": {"$geoIntersects": {"$geometry": {"type": "Polygon", "coordinates": [[[10, 10], [10, 30], [30, 30], [30, 10], [10, 10]]]} }}, "e": {"$eq": 3}}'; -- Check Explain for other non-geo operators are not pushed to geo index but regular index if available EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$eq": [2.1, 2.2]}}'; -- $geoWithin explain and index pushdown on 2dsphere EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}'; -- EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}'; -- $geometry with legacy formats EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}'; -- Testing composite 2dsphere index EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}'; -- Testing composite 2dsphere with pfe EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index but should return same values bson_query_operator_geospatial_geography_core.sql000066400000000000000000000543431507310017400411110ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- Insert multiple items -- Old format legacy points are valid for geography SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 1, "geo" : { "loc": [2.1, 2.2] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 2, "geo" : [ { "loc": [3.1, 3.2] }, { "loc": [4.1, 4.2] } ] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 3, "geo" : { "loc": {"type": "Point", "coordinates": [5.1, 5.2] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 4, "geo" : [ { "loc": {"type": "Point", "coordinates": [6.1, 6.2] } }, { "loc": { "type": "Point", "coordinates": [6.3, 6.4]} }] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 5, "geo" : { "loc": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [7.3, 7.4]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 6, "geo" : { "loc": { "type": "LineString", "coordinates": [[8.1, 8.2], [8.3, 8.4]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 7, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]]] } } }', NULL); -- SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 8, "geo" : { "loc": { "type": "Polygon", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 9, "geo" : { "loc": { "type": "MultiLineString", "coordinates": [[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 10, "geo" : { "loc": { "type": "MultiPolygon", "coordinates": [[[[10, 10], [10, -10], [-10, -10], [-10, 10], [10, 10]], [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 11, "geo" : { "loc": { "type": "GeometryCollection", "geometries": [ {"type": "Point", "coordinates": [11.1, 11.2]}, {"type": "LineString", "coordinates": [[11.3, 11.4], [11.5, 11.6]]}, {"type": "Polygon", "coordinates": [[[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 5]]]} ] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 12, "geo" : { "loc": [120, 89.1 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 13, "geo" : { "loc": { "x": 50, "y": 50, "z": 51 } } }', NULL); -- Legacy object format SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 14, "geo" : { "loc": [51, 51, 52] } }', NULL); -- Legacy array format SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 15, "geo" : { "loc": [ -46.67527188, -23.60076866 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 16, "geo" : { "loc": [ -46.67354611, -23.60337759 ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 50, "a" : { "b": [ [40, 40], [45, 45], [50, 50], [55, 55] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 51, "a" : { "b": [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 52, "a" : { "b": [ ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 53, "a" : { "b": { } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 54, "a" : { "b": [ [], [] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 55, "a" : { "b": [ [10, 10], [120, 80] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 56, "a" : { "b": [ [120, 80], [10, 10] ] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 57, "a" : [{ "b": [120, 80]}, { "b": [10, 10]}] }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 58, "a" : [{ "b": [10, 10]}, { "b": [120, 80]}] }', NULL); -- for $centerSphere edge test SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 17, "geo" : { "loc": [4.9757, 2.66966] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 18, "geo" : { "loc": [-4.9757, -2.66966] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 19, "geoPrec" : { "loc": [1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 20, "geoPrec" : { "loc": [-1, 0], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 21, "geoPrec" : { "loc": [0, 1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 22, "geoPrec" : { "loc": [0, -1], "d": {"$numberDouble": "0.017453292519943295"} } }', NULL); -- Insert some items for testing composite 2dsphere index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 200, "geoA" : { "type" : "Point", "coordinates": [ 10, 10] }, "geoB": { "type": "Point", "coordinates": [20, 20] } }', NULL); -- Both geoA and geoB SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 201, "geoA" : { "type" : "Point", "coordinates": [ 11, 11] } }', NULL); -- Only geoA SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 202, "geoB" : { "type" : "Point", "coordinates": [ 21, 21] } }', NULL); -- Only geoB SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 203, "geoC" : { "type" : "Point", "coordinates": [ 30, 30] } }', NULL); -- No geoA, no geoB -- Insert some items for composited 2dsphere index with pfe SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 300, "geo1" : { "type" : "Point", "coordinates": [ 10, 10] }, "geo2": { "type": "Point", "coordinates": [20, 20] }, "region": "USA" }', NULL); -- Both geo1 and geo2 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 301, "geo1" : { "type" : "Point", "coordinates": [ 11, 11] }, "region": "USA" }', NULL); -- Only geo1 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 302, "geo2" : { "type" : "Point", "coordinates": [ 21, 21] }, "region": "USA" }', NULL); -- Only geo2 SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 303, "geo3" : { "type" : "Point", "coordinates": [ 30, 30] }, "region": "USA" }', NULL); -- No geo1, no geo2 -- Insert for large query cap containing all of shapes vertices but not the shape itself. SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 400, "largeGeo" : { "type" : "LineString", "coordinates": [[96.328125, 5.61598581915534], [153.984375, -6.315298538330033]] }}', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "largeGeo" : { "type" : "Polygon", "coordinates": [[ [98.96484375, -11.350796722383672], [135.35156249999997, -11.350796722383672], [135.35156249999997, 0.8788717828324276], [98.96484375, 0.8788717828324276], [98.96484375, -11.350796722383672] ]] }}', NULL); -- Valid polygon inserts SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 601, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } } }', NULL); -- all points on equator SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 602, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } } }', NULL); -- all points on same latitude SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 603, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } } }', NULL); -- all points on same longitude --$geoIntersects operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[1.1, 1.2], [2.1, 2.2], [3.1, 3.2]] } }}}' ORDER BY object_id; -- Validate legacy format works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": {"lon": 3.1, "lat": 3.2} } }}}' ORDER BY object_id; -- this weird GeoJson mongo native syntax is also supported SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "MultiPoint", "coordinates": [[7.1, 7.2], [4.1, 4.2]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; -- with holes, should not include document with _id 4 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "LineString", "coordinates": [ [25, 25], [-25, -25] ] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}' ORDER BY object_id; -- Legacy formats with $geometry works SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "lon": 50, "lat": 50 } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": [51, 51] }}}' ORDER BY object_id; -- Check if a north pole region geography finds a point with _id 12, this is invalid polygon in 2d but valid as a spherical geometry SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; -- $geoWithin operator works with spherical queries with $geometry (Polygon and Multipolygons only) and $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ]] } }}}' ORDER BY object_id; -- SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0] ], [ [4, 4], [4, 7], [7, 7], [7, 4], [4, 4] ]] } }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[-120.0, 89.0], [0.0, 89.0], [120.0, 89.0], [-120.0, 89.0]]] } }}}' ORDER BY object_id; -- $centerSphere operator SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 1] }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 4] }}}' ORDER BY object_id; -- still returns results with bigger buffer SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.0984] }}}' ORDER BY object_id; -- edge test for $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], 0.21] }}}' ORDER BY object_id; -- 0.21 is enough to include Point(5 5) and not Point(10 10) so shouldn't include some docs SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0,0], { "$numberDecimal" : "Infinity" }] }}}' ORDER BY object_id; -- infinite radius should include all docs SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result -- Testing composite 2dsphere index SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoA": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geoB": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- Testing composite 2dsphere with pfe SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "region": {"$eq": "USA" }}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }} , "region": { "$eq": "USA" } }' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo1": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}, "geo2": {"$geoIntersects": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 50], [50, 50], [50, 0], [0, 0]]]} }}}' ORDER BY object_id; -- This one should not use index because pfe doesn't match but should return same values -- Make sure a really big query that requires buffer reallocs don't mess up geometry/geography and return the result SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoIntersects" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{ "geo.loc" : { "$geoWithin" : { "$geometry" : ' '{ "type" : "MultiPolygon", "coordinates" : [[[[-46.67914894304542, -23.39591591], [-46.69148969424672, -23.39647184], [-46.70371190620094, -23.39813429], ' '[-46.7156981694656, -23.40088729], [-46.72733332377327, -23.40470439], [-46.7385055566174, -23.40954892], [-46.749107470871145, -23.41537434], ' '[-46.75903711150689, -23.42212468], [-46.768198941818476, -23.42973505], [-46.77650475996186, -23.43813231], [-46.78387454712577, -23.44723573], ' '[-46.79023723921629, -23.45695777], [-46.7955314145885, -23.46720494], [-46.79970589107978, -23.47787865], [-46.80272022639018, -23.48887621], ' '[-46.80454511671058, -23.50009177], [-46.805162689414196, -23.51141736], [-46.804566686594455, -23.52274393], [-46.80276253724614, -23.53396238], ' '[-46.79976731693784, -23.54496462], [-46.79560959490368, -23.55564464], [-46.79032916958054, -23.56589949], [-46.783976694723066, -23.5756303], ' '[-46.77661319932978, -23.58474322], [-46.76830950569968, -23.59315037], [-46.75914555099343, -23.60077063], [-46.74920961868761, -23.60753048], [-46.73859748726804, -23.61336466], ' '[-46.727411504398404, -23.61821688], [-46.71575959561004, -23.62204028], [-46.703754217276085, -23.62479797], [-46.691511264249215, -23.6264633], ' '[-46.67914894304542, -23.6270202], [-46.66678662184163, -23.6264633], [-46.65454366881477, -23.62479797], [-46.642538290480815, -23.62204028], ' '[-46.63088638169245, -23.61821688], [-46.619700398822815, -23.61336466], [-46.60908826740324, -23.60753048], [-46.59915233509742, -23.60077063], ' '[-46.589988380391155, -23.59315037], [-46.58168468676106, -23.58474322], [-46.57432119136778, -23.5756303], [-46.56796871651031, -23.56589949], ' '[-46.56268829118717, -23.55564464], [-46.558530569153, -23.54496462], [-46.5555353488447, -23.53396238], [-46.55373119949638, -23.52274393], ' '[-46.55313519667665, -23.51141736], [-46.55375276938027, -23.50009177], [-46.55557765970067, -23.48887621], [-46.55859199501106, -23.47787865], ' '[-46.56276647150235, -23.46720494], [-46.56806064687455, -23.45695777], [-46.57442333896507, -23.44723573], [-46.58179312612898, -23.43813231], ' '[-46.59009894427236, -23.42973505], [-46.59926077458395, -23.42212468], [-46.60919041521971, -23.41537434], [-46.61979232947344, -23.40954892], ' '[-46.63096456231758, -23.40470439], [-46.64259971662524, -23.40088729], [-46.65458597988991, -23.39813429], [-46.66680819184413, -23.39647184], ' '[-46.67914894304542, -23.39591591]]]]}}}}' ORDER BY object_id; -- $centerSphere precision test SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geoPrec.loc": {"$geoWithin": {"$centerSphere": [[0,0], {"$numberDouble": "0.017453292519943295"}] }}}' ORDER BY object_id; -- $centerSphere test with array of legacy coordinates in document SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0,0], 2] }}}' ORDER BY object_id; -- Test that no matter the order of legacy pairs in the array, if 1 matches the document is returned SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$centerSphere": [[90, 90], 1]}}}' ORDER BY object_id;bson_query_operator_geospatial_multi_tests.sql000066400000000000000000000233611507310017400404640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 567100; SET documentdb.next_collection_id TO 56710; SET documentdb.next_collection_index_id TO 56710; SELECT documentdb_api.drop_collection('db', 'geo_multi') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geo_multi') IS NOT NULL; -- Insert multiple items SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 1, "name": "PointA", "geo": { "type": "Point", "coordinates": [100, 0] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 2, "name": "PointB", "geo": { "type": "Point", "coordinates": [102, 2] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 3, "name": "MultiPointAB", "geo": { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 4, "name": "LineStringA", "geo": { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 5, "name": "LineStringB", "geo": { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 6, "name": "MultiLineStringAB", "geo": { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 7, "name": "PolygonA", "geo": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 8, "name": "PolygonB", "geo": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } }', NULL); -- commenting out the polygon with holes for now -- SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 9, "name": "PolygonA_WithHole", "geo": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 10, "name": "MultiPolygonAB", "geo": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]} }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 11, "name": "GeometryCollectionAll_Withouthole", "geo": { "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [100, 0] }, { "type": "Point", "coordinates": [102, 2] }, { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] }, { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] }, { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] }, { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] }, { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] }, { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]}] } }', NULL); -- commenting out the polygon with holes for now -- SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 12, "name": "GeometryCollectionAll_Withhole", "geo": { "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [100, 0] }, { "type": "Point", "coordinates": [102, 2] }, { "type": "MultiPoint", "coordinates": [[100, 0], [101, 1], [102, 2], [103, 3]] }, { "type": "LineString", "coordinates": [[100, 0], [100.5, 0.5], [101, 1]] }, { "type": "LineString", "coordinates": [[102, 2], [102.5, 2.5], [103, 3]] }, { "type": "MultiLineString", "coordinates": [ [[100, 0], [100.5, 0.5], [101, 1]], [[102, 2], [102.5, 2.5], [103, 3]] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] }, { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] }, { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] }, { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ]}] } }', NULL); SELECT documentdb_api.insert_one('db','geo_multi','{ "_id" : 13, "name": "Polygon_Exterior", "geo": { "type": "Polygon", "coordinates": [ [ [0, 0], [1, 0], [1, 1], [0, 1], [0, 0] ] ] } }', NULL); -- Big enough single polygon to match all the documents except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [103, 0], [103, 3], [100, 3], [100, 0] ] ] } } }}'; -- PolygonA matches PointA, LineStringA, PolygonA, LineStringA SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } } }}'; -- PolygonB matches PointB, LineStringB, PolygonB, SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } } }}'; -- MultiPolygonAB creates a covered region that matches all except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; -- PolygonA_WithHole matches PointA and PolygonA (Bug) and doesn't match itself -- Limitation1: Matching itself is different behavior in mongo and postgis doesn't behave same out of the box for 2 identical polygons with holes. -- Limitation2: PolygonA is matched because of this limitation that the outer ring of polygon with hole covers the polygonB and in this case the hole is not considered SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ], [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] } } }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; -- Create Index and should get the same result SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geo_multi", "indexes": [{"key": {"geo": "2dsphere"}, "name": "my_geo_indx" }]}', true); BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; -- Big enough single polygon to match all the documents except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [103, 0], [103, 3], [100, 3], [100, 0] ] ] } } }}'; -- PolygonA matches PointA, LineStringA, PolygonA, LineStringA SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] } } }}'; -- PolygonB matches PointB, LineStringB, PolygonB, SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "Polygon", "coordinates": [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ] } } }}'; -- MultiPolygonAB creates a covered region that matches all except Polygon_Exterior SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'geo_multi', '{"_id": "hashed"}', false); BEGIN; set local enable_seqscan TO off; set local citus.enable_local_execution TO OFF; set local documentdb.forceUseIndexIfAvailable to on; SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}' ORDER BY object_id; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geo_multi') WHERE document @@ '{"geo": {"$geoWithin": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [102, 2], [103, 2], [103, 3], [102, 3], [102, 2] ] ], [ [ [100, 0], [101, 0], [101, 1], [100, 1], [100, 0] ] ] ] } } }}'; ROLLBACK; bson_query_operator_geospatial_runtime_validation.sql000066400000000000000000001610331507310017400420040ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1605000; SET documentdb.next_collection_id TO 160500; SET documentdb.next_collection_index_id TO 160500; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); -- Top level validations -- Insert so that validations kick in SELECT documentdb_api.insert_one('db','geoquerytest','{ "z" : { "y": [10, 10] } }', NULL); SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": 1 }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberInt": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberLong": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberDouble": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$numberDecimal": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": [10, 10] }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": true }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": false }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$undefined": true } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": "Geometry" }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"a": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"box": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"center": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"polygon": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": 1 }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberInt": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberLong": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberDouble": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$numberDecimal": "1" } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": [10, 10] }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": true }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": false }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { "$undefined": true } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": "Geometry" }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"a": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"box": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"center": [10, 20]}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"polygon": [10, 20]}}}'; -- Valid Shape operator validations -- $box SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"w": 10, "x": 10, "y": 11, "z": 12}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeftX": 10, "bottomLeftY": 10, "topRightX": 11, "topRightY": 12}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": [10], "y": 10 }, "topRight": { "x": 11, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": "10" }, "topRight": { "x": 11, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": true, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": 11, "y": {"y": 10}}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [10, 11, 12, 13] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[[10], 10], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, "10"], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10], [true, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10], [11, {"y": 11}]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, 10]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": { }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"w": 10, "x": 10, "y": 11, "z": 12}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeftX": 10, "bottomLeftY": 10, "topRightX": 11, "topRightY": 12}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": [10], "y": 10 }, "topRight": { "x": 11, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": "10" }, "topRight": { "x": 11, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": true, "y": 11}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": {"bottomLeft": { "x": 10, "y": 10 }, "topRight": { "x": 11, "y": {"y": 10}}}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [10, 11, 12, 13] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[[10], 10], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, "10"], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10], [true, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10], [11, {"y": 11}]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, 10]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$box": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf -- $center SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": [10], "y": 10 }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": "10" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": -10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": true } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [ [10], 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, "10"], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [ {"x": 10 } , 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], "10" ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], -10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], true ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10], 10, 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": { "center": { "x": 10, "y": 10 }}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [ [10, 10] ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": {} }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$center": [] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": [10], "y": 10 }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": "10" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": -10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": true } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [ [10], 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, "10"], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [ {"x": 10 } , 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], "10" ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], -10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], true ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10], 10, 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": { "center": { "x": 10, "y": 10 }}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [ [10, 10] ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$center": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "NaN" }] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "-NaN" }] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$center": [[10, 10], { "$numberDecimal": "-Infinity" }] }}}'; -- $centerSphere SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": [10], "y": 10 }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": "10" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": -10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": true } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [ [10], 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, "10"], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [ {"x": 10 } , 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], "10" ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], -10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], true ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10], 10, 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [ [10, 10] ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": [] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$centerSphere": {} }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": [10], "y": 10 }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": { "xx": 10 }, "y": "10" }, "radius": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": "10" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": -10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": true } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [ [10], 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, "10"], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [ {"x": 10 } , 10], 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], "10" ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], -10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], true ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }, "radius": 10, "extra": 10 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10], 10, 10 ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": { "centerSphere": { "x": 10, "y": 10 }}}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [ [10, 10] ] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$centerSphere": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "NaN" }] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "-NaN" }] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$within": {"$centerSphere": [[10, 10], { "$numberDecimal": "-Infinity" }] }}}'; -- $polygon SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": [10], "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": "10"}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": { "xx" : 10 }, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": true, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": false} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[[10], 10], [11, 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, {"y": 10}], [11, 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], ["11", 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11], [true, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, 10], [11, 11], [12, false]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": "Points" }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": true }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": [10], "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": "10"}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": { "xx" : 10 }, "y": 10}, "third": {"x": 10, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": true, "y": 10} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": { "first": {"x": 10, "y": 10}, "second": {"x": 10, "y": 10}, "third": {"x": 10, "y": false} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[[10], 10], [11, 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, {"y": 10}], [11, 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], ["11", 11], [12, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11], [true, 12]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, 10], [11, 11], [12, false]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDouble": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDouble": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "-inf" }]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$within": {"$polygon": [[10, { "$numberDecimal": "1e309" }]] }}}'; -- This is overflow and hence inf -- $geoIntersects operator validations SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": 1 }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { } }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": [{ "$geometry": {} }] }}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$box": [[10, 20], [30, 40]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$polygon": [[10, 20], [30, 40]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": {"$centerSphere": [[10, 20], [30, 40]] }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": 1 }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": {} }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "point" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "linestring" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "polygon" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multipoint" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multilinestring" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "multipolygon" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "geometrycollection" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "invalidGeoJsonType" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiLineString" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection" } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "Coordinates": [10, 10] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": {"x": 10, "y": "Text"} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [[1, 2], [3, 4]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [1, "text"] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "coordinates": [{"x": 10, "y": 10}] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2], [3, "text"]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "LineString", "coordinates": [[1, 2], {"x": 10, "y": 10}] } }}}'; -- Polygon extra validations SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[1, 2], [3, 4]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [1, 3]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [2, 1]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [3, 4], [1, 2]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] }}}}'; -- Edges of polygon intersect, 2d area is 0 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]]}}}}'; -- Edges of polygon intersect, 2d area is not 0 SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]]}}}}'; -- Polygon with hole edge part of (overlapping) outer ring SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]]}}}}'; -- Polygon with hole having 1 edge common with outer ring SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 2], [2, 0], [2, 2], [0, 0], [1, 2], [3, 2], [4, 2], [0, 2]]]}}}}'; -- Combination polygon - both intersection and overlap SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], []] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] }}}}'; --Holes covering the polygon SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [ [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0, 0], [0, 0.5], [1, 0.5], [1, 0], [0, 0]], [[0, 0.5], [0, 1], [1, 1], [1, 0.5], [0, 0.5]] ] }}}}'; -- Multi holes covering the polygon SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]] }}}}'; -- Duplicate non adjacent vertices SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": {} } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [[1, 2], [3, "text"]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPoint", "coordinates": [[[1, 2], [3, 4]]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 2], [3,4]]], [] ] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [], [] ] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 2], [3, 4], [1, 2]]], [] ] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], []], []] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiPolygon", "coordinates": [ [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]]], [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "MultiLineString", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]], [[1, 2]]] }}}}'; -- Geometry Collections SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": {} }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coords": [10, 10] }] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "unknownPoint", "coords": [10, 10] }] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coordinates": [10, "text"] }] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "Point", "coordinates": [10, 10] }, {"type": "LineString", "coordinates": [[1, 2], [2, 3]]}, {"type": "Polygon", "coordinates": [[[1, 1], [5, 5], [2, 6], [1, 1]]]}, {"type": "LineString", "coordinates": [[10, 10]]}] }}}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "GeometryCollection", "geometries": [{ "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [10, 10]}]}] }}}}'; --CRS checks SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": [], "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": 1, "name": 1}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name"}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {}}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": { "name": 2 }}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {"name": "UnknownCRS"}}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"type": "name", "properties": {"name": "urn:x-mongodb:crs:STRICTWINDING:EPSG:4326" } }, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": {"properties": {}, "type": "name"}, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Point", "crs": { "type": "name", "properties": { "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" } }, "coordinates": [1, 2] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[1, 1], [5, 5], [2, 6], [1, 1]]], "crs": { "type": "name", "properties": { "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" } }} }}}'; -- $geoWithin with non polygon GeoJSON don't work SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "Point", "coordinates": [10, 10] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "MultiPoint", "coordinates": [[10, 10], [20, 20]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "LineString", "coordinates": [[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "MultiLineString", "coordinates": [[[7.1, 7.2], [4.1, 4.2], [7.3, 7.4], [2.1, 2.2]]] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": { "$geometry": { "type": "GeometryCollection", "geometries": [ {"type": "LineString", "coordinates": [[-25, -25], [25, 25]]}, {"type": "Point", "coordinates": [2.1, 2.2]} ] } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": { "lon": 50, "lat": 50 } }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": [51, 51] }}}'; -- Out of bounds checks for GeoJSON SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "Point", "coordinates": [200, 200]} }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "LineString", "coordinates": [[-200, -200], [50, 50]]} }}}'; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a": {"$geoWithin": {"$geometry": {"type": "Polygon", "coordinates": [[[-200, -200], [50, 50], [30, 30], [-200, -200]]] } }}}'; -- Also check some cases which are specific to runtime -- e.g. GeoJson point type is matched only during runtime if there is no 2d index on the field -- If the index is created then it would simply error out as this is not a proper point format for the index SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 100, "a" : { "b": { "type": "Point", "coordinates": [60, 60] } } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 101, "a" : [{ "b": { "type": "Point", "coordinates": [65, 65] } }, { "b": { "type": "Point", "coordinates": [70, 70] } }, { "b": { "type": "Point", "coordinates": [75, 75] } }] }', NULL); -- This is Geojson Polygon which should not match for 2d planar calculations using $box, $polygon, $center in $geowithin SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 102, "a" : { "b": {"type": "Polygon", "coordinates": [[ [10, 10], [10, 10], [10, 10], [10, 10] ]] } } }', NULL); SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$box": [[10, 10], [100, 100]]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[10, 10], 100]}}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$polygon": [[10, 10], [10, 100], [100, 100], [100, 10]]}}}' ORDER BY object_id; -- insert some invalid polygons - don't error out on runtime as polygon validation during inserting happens only in index case SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 501, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] } } }', NULL); -- self intersecting polygon with 0 geometrical area SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 502, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]] } } }', NULL); -- self intersecting polygon with non-zero geometrical area SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 503, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]] } } }', NULL); -- hole edge lies on outer ring edge SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 504, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]] } } }', NULL); -- hole shares an edge with outer ring SELECT documentdb_api.insert_one('db','geoquerytest','{"_id": 505, "geo" : { "loc" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[10, 10], [10, 70], [75, 75], [75, 25], [10, 10]],[[10,20], [10,30], [50, 50], [10, 20]]] } } }', NULL); -- 3rd ring edge lies on 2nd ring edge bson_query_operator_geospatial_tests_explain_index.sql000066400000000000000000000170161507310017400421610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167400; SET documentdb.next_collection_id TO 16740; SET documentdb.next_collection_index_id TO 16740; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); -- 2d and 2d with pfe SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"d": "2d"}, "name": "my_2d_idx_pfe", "partialFilterExpression" : {"e": { "$gte": 5} } }]}', true); -- 2dsphere and 2dsphere with pfe SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": "2dsphere"}, "name": "my_2ds_geoloc_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"largeGeo": "2dsphere"}, "name": "my_2ds_largegeo_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"d": "2dsphere"}, "name": "my_2ds_idx_pfe", "partialFilterExpression" : {"e": { "$gte": 5} } }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geoA": "2dsphere", "geoB": "2dsphere"}, "name": "my_2dsgeo_a_or_b_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo1": "2dsphere", "geo2": "2dsphere"}, "name": "my_2ds_geo1_2_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } }]}', true); -- Multi 2dsphere index with pfe -- Also create a regular index on the same path, to validate that geo operators are never pushed to regular index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": 1}, "name": "my_regular_a_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": 1}, "name": "my_regular_geo.loc_idx" }]}', true); BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql COMMIT; -- few items for $center recheck condition SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "a" : { "b": [70, 70] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 402, "a" : { "b": [80, 80] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 403, "a" : { "b": [90, 90] } }', NULL); ANALYZE; BEGIN; set local enable_seqscan TO off; -- Testing $center and $centerSphere with infinite radius - gives no recheck condition EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; -- Testing $center and $centerSphere with non-infinite radius - gives rows removed by recheck EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result ROLLBACK; SELECT documentdb_api.delete('db', '{"delete":"geoquerytest", "deletes":[{"q":{}, "limit": 0}]}'); -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql COMMIT; -- few items for $center recheck condition SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 401, "a" : { "b": [70, 70] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 402, "a" : { "b": [80, 80] } }', NULL); SELECT documentdb_api.insert_one('db','geoquerytest','{ "_id" : 403, "a" : { "b": [90, 90] } }', NULL); ANALYZE; BEGIN; set local enable_seqscan TO off; -- Not running analyze on sharded collections as EXPLAIN returns task from only 1 of the 8 shards so the result can be flaky -- Testing $center and $centerSphere with infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result ROLLBACK; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL;bson_query_operator_geospatial_tests_explain_runtime.sql000066400000000000000000000114531507310017400425340ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167500; SET documentdb.next_collection_id TO 16750; SET documentdb.next_collection_index_id TO 16750; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','geoquerytest'); BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql COMMIT; ANALYZE; BEGIN; set local enable_seqscan TO off; -- Testing $center and $centerSphere with infinite radius EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon EXPLAIN (ANALYZE ON, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result ROLLBACK; SELECT documentdb_api.delete('db', '{"delete":"geoquerytest", "deletes":[{"q":{}, "limit": 0}]}'); -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_explain_core.sql COMMIT; ANALYZE; BEGIN; set local enable_seqscan TO off; -- Not running analyze on sharded collections as EXPLAIN returns task from only 1 of the 8 shards so the result can be flaky -- Testing $center and $centerSphere with infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[5, 10], {"$numberDecimal": "Infinity"}]}}}'; -- Testing $center and $centerSphere with non-infinite radius EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"a.b": {"$geoWithin": {"$center": [[0, 0], 100]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"geo.loc": {"$geoWithin": {"$centerSphere": [[0, 0], 1]}}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-59.80246852929814, -2.3633072488322853], 2.768403272464979]}}}' ORDER BY object_id; -- no result EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 2.9592242752161573]}}}' ORDER BY object_id; -- big enough for linestring but not for polygon EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'geoquerytest') WHERE document @@ '{"largeGeo": {"$geoWithin": {"$centerSphere": [[-61.52266094410311, 17.79937981451866], 3.15]}}}' ORDER BY object_id; -- radius > pi, both docs in result ROLLBACK; SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL;bson_query_operator_geospatial_tests_index.sql000066400000000000000000000051531507310017400404400ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 168300; SET documentdb.next_collection_id TO 16830; SET documentdb.next_collection_index_id TO 16830; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_a_idx" }]}', true); -- 2d index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"c.d": "2d"}, "name": "my_2d_c_idx" }]}', true); -- 2d index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": "2dsphere"}, "name": "my_2ds_geoloc_idx" }]}', true); -- 2dsphere index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geoA": "2dsphere", "geoB": "2dsphere"}, "name": "my_2dsgeo_a_or_b_idx" }]}', true); -- Composite 2dsphere index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo1": "2dsphere", "geo2": "2dsphere"}, "name": "my_2ds_geo1_2_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } }]}', true); -- Multi 2dsphere index with pfe -- Also create a regular index on the same path, to validate that geo operators are never pushed to regular index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"a.b": 1}, "name": "my_regular_a_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "geoquerytest", "indexes": [{"key": {"geo.loc": 1}, "name": "my_regular_geoloc_idx" }]}', true); \o \set ECHO :prevEcho -- Tests without sharding -- Geometries BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_core.sql ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql ROLLBACK; -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); -- Geometries BEGIN; set local enable_seqscan TO off; \i sql/bson_query_operator_geospatial_core.sql ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql ROLLBACK; bson_query_operator_geospatial_tests_runtime.sql000066400000000000000000000020551507310017400410120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 168300; SET documentdb.next_collection_id TO 16830; SET documentdb.next_collection_index_id TO 16830; \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api.drop_collection('db', 'geoquerytest') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'geoquerytest') IS NOT NULL; \o \set ECHO :prevEcho -- Tests without sharding -- Geometries BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_core.sql ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql ROLLBACK; -- Again testing with shards -- Shard the collection and run the tests SELECT documentdb_api.shard_collection('db', 'geoquerytest', '{ "_id": "hashed" }', false); -- Geometries BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_core.sql ROLLBACK; -- Geographies BEGIN; set local enable_seqscan TO on; \i sql/bson_query_operator_geospatial_geography_core.sql ROLLBACK;bson_query_operator_in_opt.sql000066400000000000000000000316251507310017400351720ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 330000; SET documentdb.next_collection_id TO 33000; SET documentdb.next_collection_index_id TO 33000; DO $$ BEGIN FOR i IN 1..10000 LOOP PERFORM documentdb_api.insert_one('db', 'in_opt_tests', '{ "accid": 1, "vid": 3, "val": [1, 2] }'); END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":1, "accid": 1, "vid": 1, "val": [1, 2]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":2, "accid": 1, "vid": 2, "val": [3, 4]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":3, "_id":1, "accid": 1, "vid": 1, "val": [3, 1]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":4, "accid": 1, "vid": 2, "val": {"test": 5}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":5, "accid": 1, "vid": 1, "val": [{"test": 7}]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":6, "accid": 1, "vid": 2, "val": [true, false]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":7, "accid": 1, "vid": 1, "val": 2}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":8, "accid": 1, "vid": 2, "val": 3}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":9, "accid": 1, "vid": 1, "val": 4}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":10, "accid": 1, "vid": 2, "val": [2]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":11, "accid": 1, "vid": 1, "val": [3]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":12, "accid": 1, "vid": 2, "val": [4]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":13, "accid": 1, "vid": 1, "val": [1, true]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":14, "accid": 1, "vid": 2, "val": [true, 1]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":15, "accid": 1, "vid": 1, "val": [1, 4]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":16, "accid": 1, "vid": 2, "val": [null]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":17, "accid": 1, "vid": 1, "val": null}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":18, "accid": 1, "vid": 2, "val": { "$minKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":19, "accid": 1, "vid": 1, "val": [{ "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":20, "accid": 1, "vid": 2, "val": [{ "$minKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":21, "accid": 1, "vid": 1, "val": [3, { "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":22, "accid": 1, "vid": 2, "val": { "$maxKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":23, "accid": 1, "vid": 1, "val": [{ "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":24, "accid": 1, "vid": 2, "val": [{ "$maxKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":25, "accid": 1, "vid": 1, "val": [3, { "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":26, "accid": 1, "vid": 2, "val": []}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":27, "accid": 1, "vid": 1, "a": {"val": [1, 2]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":28, "accid": 1, "vid": 2, "a": {"val": [3, 4]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":29, "accid": 1, "vid": 1, "a": {"val": [3, 1]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":30, "accid": 1, "vid": 2, "a": {"val": {"test": 5}}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":31, "accid": 1, "vid": 1, "a": {"val": [{"test": 7}]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":32, "accid": 1, "vid": 2, "a": {"val": [true, false]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":33, "accid": 1, "vid": 1, "a": {"val": 2}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":34, "accid": 1, "vid": 2, "a": {"val": 3}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":35, "accid": 1, "vid": 1, "a": {"val": 4}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":36, "accid": 1, "vid": 2, "a": {"val": [2]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":37, "accid": 1, "vid": 1, "a": {"val": [3]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":38, "accid": 1, "vid": 2, "a": {"val": [4]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":39, "accid": 1, "vid": 1, "a": {"val": [1, true]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":40, "accid": 1, "vid": 2, "a": {"val": [true, 1]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":41, "accid": 1, "vid": 1, "a": {"val": [1, 4]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":42, "accid": 1, "vid": 2, "a": {"val": [null]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":43, "accid": 1, "vid": 1, "a": {"val": null}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":44, "accid": 1, "vid": 2, "a": {"val": { "$minKey": 1 }}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":45, "accid": 1, "vid": 1, "a": {"val": [{ "$minKey": 1 }]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":46, "accid": 1, "vid": 2, "a": {"val": [{ "$minKey": 1 }, 3]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":47, "accid": 1, "vid": 1, "a": {"val": [3, { "$minKey": 1 }]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":48, "accid": 1, "vid": 2, "a": {"val": { "$maxKey": 1 }}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":49, "accid": 1, "vid": 1, "a": {"val": [{ "$maxKey": 1 }]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":50, "accid": 1, "vid": 2, "a": {"val": [{ "$maxKey": 1 }, 3]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":51, "accid": 1, "vid": 1, "a": {"val": [3, { "$maxKey": 1 }]}}', NULL); SELECT documentdb_api.insert_one('db', 'in_opt_tests', '{"_id":52, "accid": 1, "vid": 2, "a": {"val": []}}', NULL); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 2, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "in_opt_tests", "indexes": [ {"key": {"val": 1, "accid": 1, "vid": 1}, "name": "val_accid_vid"} ] }', true ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "in_opt_tests", "indexes": [ {"key": {"a.val": 1, "accid": 1, "vid": 1}, "name": "a_val_accid_vid"} ] }', true ); BEGIN; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); -- no optimization EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); -- no optimization SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); END; SELECT documentdb_api.shard_collection('db','in_opt_tests', '{"accid":"hashed"}', false); BEGIN; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); -- no optimization EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "$or": [{"val": { "$eq": 1}}, {"val": { "$eq": 3}}] } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": {"$or": [{"val": { "$eq": 1}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}, {"val": { "$eq": 3}, "accid":{ "$eq": 1}, "vid": { "$eq": 1}}] } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [1, 3]} } }'); -- no optimization SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": []} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "val": { "$in": [4, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "a.val": { "$in": [4, 3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [3]} } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "a.val": { "$in": [3]} } }'); END;bson_query_operator_near_nearsphere.sql000066400000000000000000001011301507310017400370300ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 523000; SET documentdb.next_collection_id TO 5230; SET documentdb.next_collection_index_id TO 5230; SET search_path to documentdb_api_catalog; SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 1, "a": { "b": [ 0, 0]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 2, "a": { "b": [ 1.1, 1.1]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 3, "a": { "b": [ 2.29, 2.29]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 4, "a": { "b": [ 3.31, 3.31]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 5, "a": { "b": [ 4.42, 4.42]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 6, "a": { "b": [ 5.5, 5.5]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 7, "a": { "b": [ 6.66, 6.66]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 8, "a": { "b": [ 7.74, 7.74]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 9, "a": { "b": [ 8.81, 8.81]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 10, "a": { "geo": {"type": "Point", "coordinates": [35.3, 35.4]}} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 11, "a": { "geo": {"type": "LineString", "coordinates": [[35.36, 35.42], [32.3, 30]]}} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 12, "a": { "geo": {"type": "Polygon", "coordinates": [[[35.73, 35.74], [38.6, 35.3], [38.7, 39.2], [35.73, 35.74]]]}} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 13, "a": { "geo": {"type": "MultiPoint", "coordinates": [[35.43, 35.44], [32.3, 30.3]]}} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 14, "a": { "geo": {"type": "MultiLineString", "coordinates": [[[35.83, 35.84], [32.3, 30.6]]]}} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere','{ "_id": 15, "a": { "geo": {"type": "MultiPolygon", "coordinates": [[[[35.312, 35.441], [38.644, 35.3231], [38.71, 39.32], [35.312, 35.441]]]]}} }', NULL); -- Test near and nearsphere with index and runtime flags -- Should fail SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); BEGIN; -- Should pass SET LOCAL documentdb.enable_force_push_geonear_index to off; SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); ROLLBACK; -- $near and $nearSphere enforce index usage SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere", "indexes": [{"key": {"a.b": "2d"}, "name": "my_2d_ab_idx" }, {"key": {"a.b": "2dsphere"}, "name": "my_2ds_ab_idx" }, {"key": {"a.geo": "2dsphere"}, "name": "my_2ds_ageo_idx" }]}', true); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','near_sphere'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'near_sphere') ORDER BY collection_id, index_id; -- validations -- $near/$nearSphere tests SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0] } }}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$hello": 1}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"tide": "Point", "coordintes": [1,1]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": []}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"tide": "Point", "coordintes": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 1, "coordinates": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": "a", "y": 1}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0] } }}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$hello": 1}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"tide": "Point", "coordintes": [1,1]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": []}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"tide": "Point", "coordintes": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 1, "coordinates": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": "a", "y": 1}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [1,1]}}, "b": { "$nearSphere": {"coordinates": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [1,1]}}, "b": { "$nearSphere": {"coordinates": [1,1]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [1,1]}}, "b": { "$near": {"coordinates": [1,1]}}}}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "near_sphere", "pipeline": [ { "$sort": { "a.b": 1 }}, { "$match": { "a.b": { "$near": {"coordinates": [1,1]}}}} ], "cursor": {} }'); -- $near/$nearSphere with invalid distance argument SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$minDistance": -1}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$minDistance": {"$numberDouble": "NaN"}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"coordinates": [1, 1]}, "$minDistance": {"$numberDouble": "Infinity"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"coordinates": [1, 1]}, "$maxDistance": {"$numberDouble": "Infinity"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$maxDistance": {"$numberDouble": "-Infinity"}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [1, 1], "$maxDistance": {"$numberDouble": "-NaN"}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$minDistance": -1}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$minDistance": {"$numberDouble": "NaN"}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"coordinates": [1, 1]}, "$minDistance": {"$numberDouble": "Infinity"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"coordinates": [1, 1]}, "$maxDistance": {"$numberDouble": "Infinity"}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$maxDistance": {"$numberDouble": "-Infinity"}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [1, 1], "$maxDistance": {"$numberDouble": "-NaN"}}}}'); -- invalid places to call $near/$nearSphere SELECT document FROM documentdb_api.collection('db','near_sphere') WHERE document @@ '{ "a.b": { "$elemMatch" : {"$near": [1,1] }}}'; SELECT document FROM documentdb_api.collection('db','near_sphere') WHERE document @@ '{ "$or": [{"a.b": {"$near": [1,1] }},{"t": 1}]}'; SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": {}, "projection": { "p" : {"$elemMatch": {"geo": {"$near": [1,1]}}}}}'); SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{},"u":{"$set": {"a.$[elem].b": 1}},"multi":false,"upsert":true, "arrayFilters": [{"elem.geo": {"$near": [1, 1]}}]}]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere", "indexes": [{"key": {"t": 1}, "name": "my_invalid_idx", "partialFilterExpression": {"geo": {"$near": [1,1]}} }]}', true); BEGIN; -- $near operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 6}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$maxDistance": 6}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0, "z": 6}}}}'); -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [5, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [5, 6]}}}}'); -- $nearSphere operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.1}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$maxDistance": 0.15}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.16, "$maxDistance": 0.2}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0, 0.15]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0, "z": 0.15}}}}'); -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [5, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [5, 6]}}}}'); -- Test with GeoJson objects in documents -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": { "type": "Point", "coordinates": [5, 6] }}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}}'); -- Verify that @@ operator handles the near / nearSphere operators SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.b": { "$near": [5, 6]}}'; SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.b": { "$near": [5, 6]}}'; SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.geo": { "$nearSphere": [5, 6]}}'; SELECT document FROM documentdb_api.collection('db', 'near_sphere') WHERE document @@ '{ "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}'; -- Explain tests to ensure index pushdown EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); ROLLBACK; SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0]}}}'); -- check update BEGIN; SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":false,"upsert":false}]}'); SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1.1,1.1]}} ,"u":{"$set": {"t": 1}},"multi":false,"upsert":false}]}'); SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":true,"upsert":false}]}'); ROLLBACK; -- Shard the collection SELECT documentdb_api.shard_collection('db', 'near_sphere', '{"_id": "hashed"}', false); BEGIN; SET LOCAL enable_seqscan to off; set local citus.enable_local_execution TO OFF; SET LOCAL seq_page_cost TO 9999999; -- $near operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 6}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$maxDistance": 6}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"x": 0, "y": 0, "z": 6}}}}'); -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [5, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"coordinates": [5, 6]}}}}'); -- $nearSphere operator -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.1}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$maxDistance": 0.15}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.16, "$maxDistance": 0.2}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"x": 0, "y": 0, "z": 0.15}}}}'); -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 700000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 1000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [5, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"coordinates": [5, 6]}}}}'); -- Test with GeoJson objects in documents -- Test with legacy coordinate pair SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$minDistance": 0.8}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$maxDistance": 0.8}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); -- Test with GeoJson point SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}'); -- Test with GeoJson point with $geometry SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 5000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$maxDistance": 5000000}}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 4500000, "$maxDistance": 5000000}}}}'); -- Test order of documents SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": [5, 6]}}}'); SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"coordinates": [5, 6]}}}}'); -- Explain tests to ensure index pushdown EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0]}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": [0, 0], "$minDistance": 5, "$maxDistance": 8}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$near": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0]}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": [0, 0], "$minDistance": 0.8, "$maxDistance": 1}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.geo": { "$nearSphere": {"type": "Point", "coordinates": [0, 0]}}}}'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM bson_aggregation_find('db', '{ "find": "near_sphere", "filter": { "a.b": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [0, 0]}, "$minDistance": 500000, "$maxDistance": 1500000}}}}'); ROLLBACK; -- update with sharded BEGIN; SELECT documentdb_api.update('db', '{"update":"near_sphere", "updates":[{"q":{"a.b": {"$near": [1,1]}} ,"u":{"$set": {"t": 1}},"multi":true,"upsert":false}]}'); ROLLBACK; -- Test near and nearsphere with different sorting features. SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 1, "zone": 1, "loc": { "type": "Point", "coordinates": [-20, -20]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 2, "zone": 2, "loc": { "type": "Point", "coordinates": [-10, -10]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 3, "zone": 3, "loc": { "type": "Point", "coordinates": [0, 0]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 4, "zone": 4, "loc": { "type": "Point", "coordinates": [10, 10]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 5, "zone": 5, "loc": { "type": "Point", "coordinates": [20, 20]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 6, "zone": 1, "loc": { "type": "Point", "coordinates": [-20, -20]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 7, "zone": 2, "loc": { "type": "Point", "coordinates": [-10, -10]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 8, "zone": 3, "loc": { "type": "Point", "coordinates": [0, 0]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 9, "zone": 4, "loc": { "type": "Point", "coordinates": [10, 10]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 10, "zone": 5, "loc": { "type": "Point", "coordinates": [20, 20]} }', NULL); SELECT documentdb_api.insert_one('db','near_sphere_distinct','{ "_id": 11, "zone": 6, "loc": { "type": "Point", "coordinates": [30, 30]} }', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "near_sphere_distinct", "indexes": [{"key": {"loc.coordinates": "2d"}, "name": "my_2d_loccoord_idx" }]}', true); SELECT document FROM bson_aggregation_distinct('db', '{ "distinct": "near_sphere_distinct", "key": "zone", "query": {"loc.coordinates": { "$near": [0, 0], "$maxDistance": 1}} }'); -- find and modify fails with geonear -- With sort on findAndModify with near, sort takes precedence SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "near_sphere_distinct", "query": { "loc.coordinates": { "$near": [0, 0], "$maxDistance": 1} }, "sort": {"_id": -1}, "update": {"a": 10}, "fields": {"_id": 1}}'); -- If no sort clause then near decides the ordering SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "near_sphere_distinct", "query": { "loc.coordinates": { "$near": [30, 30]} }, "update": {"a": 10}, "fields": {"_id": 1}}'); bson_query_operator_object_id_tests.sql000066400000000000000000000064511507310017400370450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 251000; SET documentdb.next_collection_id TO 2510; SET documentdb.next_collection_index_id TO 2510; SELECT COUNT(*) FROM (SELECT documentdb_api.insert_one('db', 'test_object_id_index', FORMAT('{ "_id": %s, "a": %s, "otherField": "aaaa" }', g, g)::bson) FROM generate_series(1, 10000) g) i; EXPLAIN (COSTS ON) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15 }'; EXPLAIN (COSTS ON) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 55, 90 ] } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gt": 50 } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gt": 50, "$lt": 60 } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$gte": 50, "$lte": 60 } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": 15 }, { "_id": 16 } ] }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": { "$in": [ 15, 16, 17] }}, { "_id": { "$in": [ 16, 17, 18 ] } } ] }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "$and": [ {"_id": { "$gt": 50 } }, { "_id": { "$lt": 60 } } ] }'; -- create a scenario where there's an alternate filter and that can be matched in the RUM index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_object_id_index", "indexes": [ { "key": { "otherField": 1 }, "name": "idx_1" } ]}', true); EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 20 ] }, "otherField": "aaaa" }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15 ] }, "otherField": "aaaa" }'; -- now shard the collection SELECT documentdb_api.shard_collection('db', 'test_object_id_index', '{ "a": "hashed" }', false); -- we shouldn't have object_id filters unless we also have shard key filters EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15 }'; BEGIN; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 55, 90 ] } }'; ROLLBACK; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15, "a": 15 }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": 15, "a": { "$gt": 15 } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'test_object_id_index') WHERE document @@ '{ "_id": { "$in": [ 15, 20 ] }, "otherField": "aaaa" }'; bson_query_operator_pfe_index_pushdown.sql000066400000000000000000000232451507310017400375710ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path to documentdb_api_catalog; SET citus.next_shard_id TO 10980000; SET documentdb.next_collection_id TO 10980; SET documentdb.next_collection_index_id TO 10980; SELECT documentdb_api.create_collection('db', 'bsonquery'); -- insert documents with different compositions of keys and types SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 1, "a" : { "c" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 2, "a" : { "d" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 3, "a" : { "b" : 1 }, "b": "xyz" }', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 4, "a" : { "b" : { "$undefined": true } }}', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 5, "a" : { "b" : "xxx" }}', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 6, "a" : { "c" : "xxx" }}', NULL); SELECT documentdb_api.insert_one('db','bsonquery', '{"_id": 7, "a" : { "e" : 1, "f": 1 }}', NULL); -- create indexes with partial filter expressions SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "bsonquery", "indexes": [ { "key": {"a.b": 1}, "name": "my_idx_1", "partialFilterExpression": { "a.b": {"$exists": true } } }, { "key": {"a.c": 1}, "name": "my_idx_2", "partialFilterExpression": { "a.c": {"$gte": "abc" } } }, { "key": {"a.e": 1, "a.f": 1}, "name": "my_idx_3", "partialFilterExpression": { "a.e": 1, "a.f": 1 } } ] }', true ); SELECT collection_id AS collid FROM documentdb_api_catalog.collections WHERE collection_name = 'bsonquery' AND database_name = 'db' \gset \d documentdb_data.documents_:collid SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "bsonquery" }') ORDER BY 1; SELECT documentdb_distributed_test_helpers.drop_primary_key('db','bsonquery');; BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- should push down to pfe index since types match EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; -- should not push to pfe index due to type mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; -- should push to $exists pfe index using minkey EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; -- should not push to $exists pfe index due to key mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; -- should push to pfe index when $ne is present EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; -- should not push to pfe index due to missing key EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; -- should not push to pfe index since $eq: null cannot match $exists: true EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": null }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$ne": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gt": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lt": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gte": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lte": null } }'; -- test PFE pushdown for $in -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$in" : [ 1, 2, 3 ] } }'; -- cannot push down (fails PFE) EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "aaa", "aa1" ] } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "aaa", "bbb" ] } }'; -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "ccc", "bbb" ] } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$in" : [ "abc", "bbb" ] } }'; -- cannot push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.f": { "$in": [ 3, 4 ]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.g": { "$in": [ 3, 4 ]} }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 2 ] }, "a.f": { "$in": [ 3, 1 ]} }'; -- can push down EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.e": { "$in" : [ 1, 1, 1 ] }, "a.f": { "$in": [ 1, 1 ]} }'; ROLLBACK; -- shard the collection SELECT documentdb_api.shard_collection('db', 'bsonquery', '{ "_id": "hashed" }', false); -- rerun the queries BEGIN; SET LOCAL seq_page_cost TO 100; SET LOCAL documentdb.forceUseIndexIfAvailable to true; -- should push down to pfe index since types match EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : "c" }}'; -- should not push to pfe index due to type mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.c": { "$gte" : 1 }}'; -- should push to $exists pfe index using minkey EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.b": { "$gte" : "a" }}'; -- should not push to $exists pfe index due to key mismatch EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a.d": { "$gte" : "a" }}'; -- should push to pfe index when $ne is present EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1, "a.f": 1}'; -- should not push to pfe index due to missing key EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.e": 1}'; -- should not push to pfe index since $eq: null cannot match $exists: true EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": null }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$ne": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gt": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lt": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$gte": null } }'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'bsonquery') WHERE document @@ '{ "a": { "$ne" : null }, "a.b": { "$lte": null } }'; ROLLBACK;bson_query_operator_range.sql000066400000000000000000000455561507310017400350060ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 492000; SET documentdb.next_collection_id TO 49200; SET documentdb.next_collection_index_id TO 49200; SET search_path TO documentdb_api_catalog; DO $$ BEGIN FOR i IN 1..10000 LOOP PERFORM documentdb_api.insert_one('db', 'range_query', '{ "a": 1 }'); END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 1, "a": 1 }', NULL); SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 2, "a": [1, 2, 3] }', NULL); SELECT documentdb_api.insert_one('db', 'range_query', '{ "_id": 3, "a": [{ "b" : 1}, 2, [4, 5]] }', NULL); BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging -- if there is no index we don't optimize the a > 1 & a < 5 to a <> {1, 5} (aka the range operator) SET local documentdb_core.enableCollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); END; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_query", "indexes": [ {"key": {"a": 1}, "name": "a_range"} ] }', true ); BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); -- when collation is present $push down of $range query is not done, and we use the unoptimized version (workitem=3423305) SET local documentdb_core.enableCollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} }, "collation" : {"locale" : "en", "strength" : 1} }'); ROLLBACK; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); SET local documentdb_core.enableCollation TO on; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } ,"collation" : {"locale" : "en", "strength" : 1} }'); END; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$in": [ 5, 6, 7] }, "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); END; -- Shard orders collection on item SELECT documentdb_api.shard_collection('db','range_query', '{"_id":"hashed"}', false); BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); END; BEGIN; SET local client_min_messages TO ERROR; set local citus.enable_local_execution to off; -- Simulate remote exection with a single nodes Set local citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set local citus.log_local_commands to on; -- Will print the local queries Set local log_statement to 'all'; -- Verbose logging EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_query", "filter": { "a": { "$gt": 1 }, "a" : {"$lt" : 5} } }'); END; SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, 2]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, 4]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, 1]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": {"test": 5}}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{"test": 7}]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [true, false]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 2}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 3}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": 4}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [2]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [4]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, true]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [true, 1]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [1, 4]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [null]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": null}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": { "$minKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$minKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, { "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": { "$maxKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [{ "$maxKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": [3, { "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests', '{"val": []}', NULL); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_js_tests", "indexes": [ {"key": {"val": 1}, "name": "a_range"} ] }', true ); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1 }, "val" : {"$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests", "filter": { "val": { "$gt": 1, "$lt" : 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); END; -- tests For Minkey() and MaxKey() along with numbers SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": { "$maxKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": { "$minKey": 1 }}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$minKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3, { "$minKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [{ "$maxKey": 1 }, 3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3, { "$maxKey": 1 }]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": [3]}', NULL); SELECT documentdb_api.insert_one('db', 'range_js_tests2', '{"val": 3}', NULL); -- Runtime tests SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lt": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": 100} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lt": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lte": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gt": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); -- Index tests SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_js_tests2", "indexes": [ {"key": {"val": 1}, "name": "a_range"} ] }', true ); BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lt": {"$minKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": 100} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 1, "$lt": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lte": 3} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gt": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": 3, "$lt": 5} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "range_js_tests2", "filter": { "val": { "$gte": {"$minKey" : 1}, "$lte": {"$maxKey" : 1}} }, "projection": { "_id": 0, "val": 1 }, "sort": { "val": 1 } }'); END; SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899731608" }} }', NULL); SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899831608" }} }', NULL); SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657899931608" }} }', NULL); SELECT documentdb_api.insert_one('db','daterangecoll', '{ "createdAt" : { "$date": { "$numberLong": "2657991031608" }} }', NULL); SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "daterangecoll", "indexes": [{"key": {"createdAt": 1}, "name": "created_at_index"}]}', true); BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); END; -- do not convert $gte/$lte null BEGIN; SET LOCAL enable_seqscan TO OFF; EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": null, "$lte": { "$date": { "$numberLong": "2657991031608" }} } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); EXPLAIN(costs off) SELECT document FROM bson_aggregation_find('db', '{ "find": "daterangecoll", "filter": { "createdAt": { "$gte": { "$date": { "$numberLong": "2657899731608" }}, "$lte": null } }, "projection": { "_id": 0, "createdAt": 1 }, "sort": { "createdAt": 1 } }'); END; -- A local repro that had run into segfault SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"idLinea": 1}, "name": "idLinea_1"} ] }', true ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"f_insercion": 1}, "name": "f_insercion_1"} ] }', true ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "range_and_aggregation", "indexes": [ {"key": {"idLinea": 1, "f_insercion": 1}, "name": "idLinea_1_f_insercion_1", "unique": true} ] }', true ); DO $$ BEGIN FOR i IN 1..1000 LOOP PERFORM documentdb_api.insert_one('db', 'range_and_aggregation', FORMAT('{ "f_insercion": { "$date" : { "$numberLong" : "%s" } }, "idLinea": 1, "n_18_velocidad": %s }', i, i)::documentdb_core.bson); END LOOP; END; $$ LANGUAGE plpgsql; BEGIN; ALTER FUNCTION documentdb_api_catalog.bson_dollar_project COST 20000; ANALYZE; -- full query 500K SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "range_and_aggregation", "pipeline": [ { "$match" : { "$and" : [ { "f_insercion" : { "$gte" : { "$date" : { "$numberLong" : "0" } }}, "f_insercion" : { "$lt" : { "$date" : { "$numberLong" : "500000" } }} } ] }}, {"$project" : { "f_insercion" : 1, "n_18_velocidad": 1, "_id": 0, "date" : { "$dateToParts" : { "date" : "$f_insercion" } }} }, { "$group" : { "_id" : { "year" : "$date.year", "month" : "$date.month", "day" : "$date.day", "hour" : "$date.hour" }, "speed_avg" : { "$avg" : "$n_18_velocidad" } , "speed_max" : { "$max" : "$n_18_velocidad" } , "speed_min" : { "$min" : "$n_18_velocidad" }} }], "cursor": {} }'); -- full query 500K ( "idLinea": 1 filter ) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "range_and_aggregation", "pipeline": [ { "$match" : { "idLinea": 1, "$and" : [ { "f_insercion" : { "$gte" : { "$date" : { "$numberLong" : "0" } }}, "f_insercion" : { "$lt" : { "$date" : { "$numberLong" : "500000" } }} } ] }}, {"$project" : { "f_insercion" : 1, "n_18_velocidad": 1, "_id": 0, "date" : { "$dateToParts" : { "date" : "$f_insercion" } }} }, { "$group" : { "_id" : { "year" : "$date.year", "month" : "$date.month", "day" : "$date.day", "hour" : "$date.hour" }, "speed_avg" : { "$avg" : "$n_18_velocidad" } , "speed_max" : { "$max" : "$n_18_velocidad" } , "speed_min" : { "$min" : "$n_18_velocidad" }} }], "cursor": {} }'); ROLLBACK;bson_query_operator_tests_core.sql000066400000000000000000000613341507310017400360540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql -- Check NULL filter for @@ should not seg fault SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ NULL ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : true }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : "c" }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : true }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : "c" }}' ORDER BY object_id; /* array index equality */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b.1": { "$ne" : 1 }}' ORDER BY object_id; /* ensure documents match if there's equality on the field exactly */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : 1 } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : 1 } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ 0, 1, 2 ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : [ { "b": 0 }, { "b": 1 }, { "b": 3 }] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$ne" : 1 }}' ORDER BY object_id; /* validation of query results for all operators */ SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 0, 1] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : [true, false] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 0, 1] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : [true, false] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 0, 1] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : [true, false] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : null }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 0, 1] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : [true, false] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 0, 1] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [0, 1, 2] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : [true, false] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : null }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : 0 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : "some" }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "int" }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$type" : "string" }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$size" : 3.0 }}' ORDER BY object_id; /* Run some exists query against a collection with a single path index */ SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : "some" }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : [1, 2, 3 ] }}' ORDER BY object_id; SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); -- These queries return the above document. SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}' ORDER BY object_id; -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db','queryoperator') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}' ORDER BY object_id; -- queries on the _id field SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; -- test specific scenarios for array of elements such as empty array, array of array SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [0, 1]}}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [[]] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [[-1, 1, 2]] } }' ORDER BY object_id; -- test empty document expression in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {} ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ 0, {} ] } }' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b" : {"$all" : [ {}, 0 ] } }' ORDER BY object_id; -- test non-elemMatch expression document in $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{ "b" : 0 }] } }' ORDER BY object_id; -- test $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$gt" : 1} } }]}}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; -- test nested $elemMatch inside $all SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } } } }] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') where document @@ '{"a" : {"$all" : [{"$elemMatch" : {"b" : {"$elemMatch": {"c" : {"$gt" : 1} } }, "d" : {"$elemMatch": {"e" : {"$lt" : 20} } } } }] } }'; SELECT object_id, document FROM documentdb_api.collection('db', 'nullfield') WHERE document @@ '{ "b": null}' ORDER BY object_id; -- $in with miscellaneous datatypes SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1, 10 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.0, 10 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDouble": "1.000000000000001"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ "first value", {"$numberDecimal": "1.000000000000000000000000000000001"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"b":1},[1,2,3,4,5,6], "Lets Optimize dollar In" ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, 1 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ null, {"$maxKey" : 1}, {"$minKey" : 1} ] }}'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$binary": { "base64": "ww==", "subType": "01"}}, {"$date": "2019-01-30T07:30:10.136Z"}, {"$oid": "639926cee6bda3127f153bf1"} ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 0, 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberDecimal": "0.0"}, 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ {"$regex": ".*y.*"}] } }'; -- test $nin SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1, 10 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ 1.0, 10 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ NaN, 1000 ] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$numberInt": "2147483647"}, {"$numberLong": "9223372036854775807"}, {"$numberLong": "2147483646"}] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*y.*"}] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}] } }'; SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$nin" : [ {"$regex": ".*a.*"}, {"$regex":"Lets.*"}, 1, 10] } }'; -- matches _id: 12 even though this condition should match none if applied per term. SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt": 3, "$lt": 5 }}'; SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt": 5, "$gt": 3 }}'; -- this should evaluate to _id 10/12 even though it should evaluate to false SELECT document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq": 2, "$lt": 1 }}'; -- test queries with NaN SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt": NaN }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte": NaN }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt": NaN }}' ORDER BY object_id; SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte": NaN, "$lte": Infinity }}' ORDER BY object_id; ROLLBACK;bson_query_operator_tests_explain_core.sql000066400000000000000000000317671507310017400376030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql \i sql/bson_query_operator_tests_insert.sql /* validate explain */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gt" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lt" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a.b": { "$lte" : 1 }}'; /* validate explain for single path index */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$lte" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 1 }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'singlepathindexexists') WHERE document @@ '{ "a": { "$exists" : 0 }}'; /* validate explain for the individual items as well */ EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gt" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$gte" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lt" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$lte" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$eq" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": 1 } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : { "b": [ true, false ] } }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a": { "$ne" : [ { "b": [ 2, 3, 4 ] } ] }}'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2 }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$ne" : null }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$in": [ 1, 2 ] }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$gt": 20, "$lt": 40 }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$in": [ 1, 2 ] } }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$all": [ 2 ], "$ne": 40 }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$eq" : 2, "$all" : [ 1, 2 ] }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "_id" : { "$gt" : 1, "$lte" : 5 }}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":1}]}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id":1},{"_id":2}]}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [{"_id": { "$gt": 1, "$lte" : 5 }}, {"_id":1}]}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [{"_id":1}, {"_id": { "$gte": 1, "$lte" : 5 }}]}' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : {"$all" : [{"$elemMatch" : {"b" : "M", "c" : {"$gt" : 50} } }, {"$elemMatch" : {"c" : 100, "d" : "Y" } }]}}' ORDER BY object_id; -- $or gets converted to $in for simple expressions. EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "b": 4 } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$gte": 4 } } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": 5 } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "$and": [ { "a": 5 } ] } ] }' ORDER BY object_id; -- $and/$or with a single element gets elided EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": { "$gt": 3 } } ] }' ORDER BY object_id; -- $or of $exists false/$eq: null simplifies EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": false }} ] } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "b": { "$exists": true }} ] } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF, VERBOSE ON) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$and" : [ { "a": 3 }, { "$or": [ { "b": null }, { "c": null }, { "c": { "$exists": false }} ] } ] }' ORDER BY object_id; -- $in with 1 element gets converted to $eq EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1 ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$in": [ 1, 2 ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1 ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "a" : { "$nin": [ 1, 2 ]} }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'queryoperator') WHERE document @@ '{ "$or" : [ { "a": 3 }, { "a": { "$in": [ 4 ] }} ] }' ORDER BY object_id; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ NaN, 1000 ] } }'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ Infinity, 1000 ] } }'; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM documentdb_api.collection('db', 'queryoperatorIn') WHERE document @@ '{ "a" : { "$in" : [ 1.01, 10 ] } }';bson_query_operator_tests_explain_index.sql000066400000000000000000000047501507310017400377520ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); -- create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('nullfield', 'nullfield_wildcard', '{"$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "name": "a_index" }] }', true); -- show the indexes \d documentdb_data.documents_1200 BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_explain_core.sql COMMIT; bson_query_operator_tests_explain_index_comp_desc.sql000066400000000000000000000055371507310017400417720ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": -1, "c": -1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": -1, "_id": -1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": -1, "a": -1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": -1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": -1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); -- show the indexes \d documentdb_data.documents_1200 BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql COMMIT; bson_query_operator_tests_explain_index_comp_unique.sql000066400000000000000000000057101507310017400423530ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "nullfield_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1, "_id": 1 }, "enableCompositeTerm": true, "unique": true, "name": "a_index" }] }', true); -- show the indexes \d documentdb_data.documents_1200 BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; \i sql/bson_query_operator_tests_explain_core.sql COMMIT; bson_query_operator_tests_explain_index_composite.sql000066400000000000000000000055251507310017400420350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; set documentdb.enableExtendedExplainPlans to on; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); -- create a composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "enableCompositeTerm": true, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "enableCompositeTerm": true, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "enableCompositeTerm": true, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "nullfield", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "nullfield_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "enableCompositeTerm": true, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "enableCompositeTerm": true, "name": "a_index" }] }', true); -- show the indexes \d documentdb_data.documents_1200 BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; set local documentdb.enableExtendedExplainPlans to on; set local documentdb.forceRumIndexScanToBitmapHeapScan to off; \i sql/bson_query_operator_tests_explain_core.sql COMMIT; bson_query_operator_tests_explain_runtime.sql000066400000000000000000000012321507310017400403160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1300000; SET documentdb.next_collection_id TO 1300; SET documentdb.next_collection_index_id TO 1300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'nullfield'); SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); \i sql/bson_query_operator_tests_explain_core.sql bson_query_operator_tests_index.sql000066400000000000000000000005521507310017400362260ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql bson_query_operator_tests_index_backcompat.sql000066400000000000000000000046251507310017400404170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; \set prevEcho :ECHO \set ECHO none \o /dev/null CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryoperator", "index": [ "queryoperator_a_c", "queryoperator_ab", "queryoperator_b_a" ] }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "nullfield", "index": "nullfield_wildcard" }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryoperatorIn", "index": [ "queryoperatorin_a", "queryoperatorin_ab" ] }'); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "singlepathindexexists", "index": "a_index" }'); -- recreate the indexes BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; -- create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('nullfield', 'nullfield_wildcard', '{"$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "name": "a_index" }] }', true); COMMIT; \o \set ECHO :prevEcho BEGIN; set local documentdb.enableGenerateNonExistsTerm to off; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql bson_query_operator_tests_index_comp_desc.sql000066400000000000000000000005521507310017400402420ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 940000; SET documentdb.next_collection_id TO 9400; SET documentdb.next_collection_index_id TO 9400; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql bson_query_operator_tests_index_comp_unique.sql000066400000000000000000000005521507310017400406320ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 915000; SET documentdb.next_collection_id TO 9150; SET documentdb.next_collection_index_id TO 9150; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql bson_query_operator_tests_index_composite.sql000066400000000000000000000005521507310017400403100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_core.sql bson_query_operator_tests_insert.sql000066400000000000000000000211251507310017400364220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 5, "a" : { "b" : true }}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_undefined", "a" : { "b" : {"$undefined": true }}}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": "ab_null", "a" : { "b" : null }}', NULL); /* Insert elements to a root path for single path index $exists */ SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 1, "a" : 0}', NULL); SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "b", "b" : 1}', NULL); SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a", "a": {"$undefined": true }}', NULL); SELECT documentdb_api.insert_one('db','singlepathindexexists', '{"_id": "a_null", "a" : null}', NULL); /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 6, "a" : 1}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 7, "a" : true}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 8, "a" : [0, 1, 2]}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 9, "a" : { "c": 1 }}', NULL); /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 1, "a" : 1}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 2, "a" : {"$numberDecimal": "1.0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 3, "a" : {"$numberDouble": "1.0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 4, "a" : {"$numberLong": "1"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 5, "a" : {"$numberDecimal": "1.0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 6, "a" : {"$numberDouble": "1.0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 7, "a" : {"$numberDecimal": "1.000000000000000000000000000000001"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 8, "a" : {"$numberDouble": "1.000000000000001"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 9, "a" : {"$binary": { "base64": "ww==", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 10, "a" : {"$binary": { "base64": "ww==", "subType": "02"}}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 11, "a" : {"$binary": { "base64": "zg==", "subType": "01"}}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 12, "a" : {"$binary": { "base64": "zg==", "subType": "02"}}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 13, "a" : {"$timestamp" : { "t": 1670981326, "i": 1 }}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 14, "a" : {"$date": "2019-01-30T07:30:10.136Z"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 15, "a" : {"$oid": "639926cee6bda3127f153bf1"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 18, "a" : {"$maxKey" : 1}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 19, "a" : {"$minKey" : 1}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 20, "a" : { "$undefined" : true }}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 21, "a" : null}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 22, "a" : {"b":1}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 23, "a" : {"b":2}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 24, "a" : [1,2,3,4,5]}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 25, "a" : [1,2,3,4,5,6]}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 26, "a" : "Lets Optimize dollar In"}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 27, "a" : "Lets Optimize dollar In again"}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 28, "a" : NaN}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 29, "a" : [1,2,3,NaN,4]}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 30, "a" : Infinity}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 31, "a" : [1,2,3,Infinity,4]}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 32, "a" : {"$numberDouble": "0.0000"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 33, "a" : {"$numberDecimal": "0.0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 34, "a" : {"$numberLong": "0"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 35, "a" : 0}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 36, "a" : {"$numberLong": "9223372036854775807"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 37, "a" : {"$numberLong": "9223372036854775806"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 38, "a" : {"$numberInt": "2147483647"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 39, "a" : {"$numberInt": "2147483646"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 40, "a" : {"$numberInt": "2147483645"}}', NULL); SELECT documentdb_api.insert_one('db','queryoperatorIn', '{"_id": 41, "a" : ["abc", "xyz1"]}', NULL); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 1, "a" : 1, "b": 1}'); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 2, "a" : 2, "b": null}'); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 3, "a" : 3}'); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 4, "a" : 10, "b": 1}'); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 5, "a" : 20, "b": null}'); SELECT 1 FROM documentdb_api.insert_one('db','nullfield', '{"_id": 6, "a" : 30}'); -- $all with $elemMatch queries SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 16, "a" : [{ "b" : {} }, { "b" : 0 }]}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 17, "a" : []}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 18, "a" : [{ "b" : "S", "c": 10, "d" : "X"}, { "b" : "M", "c": 100, "d" : "X"}, { "b" : "L", "c": 100, "d" : "Y"}]}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 19, "a" : [{ "b" : "1", "c": 100, "d" : "Y"}, { "b" : "2", "c": 50, "d" : "X"}, { "b" : "3", "c": 100, "d" : "Z"}]}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 20, "a" : [{ "b" : "M", "c": 100, "d" : "Y"}]}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 21, "a": [{ "b": [ { "c" : 10 }, { "c" : 15 }, {"c" : 18 } ], "d" : [ { "e" : 10 }, { "e" : 15 }, {"e" : 18 } ]}] }', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 22, "a": [{ "b": [ { "c" : 11 } ], "d" : [ { "e" : 20 }, { "e" : 25 } ]}] }', NULL); /* insert NaN and Infinity */ SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 23, "a" : NaN}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 24, "a" : Infinity}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 25, "a" : -Infinity}', NULL); SELECT documentdb_api.insert_one('db','queryoperator', '{"_id": 26, "a" : [NaN, Infinity]}', NULL);bson_query_operator_tests_parameterized.sql000066400000000000000000000130701507310017400377520ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 66400; SET documentdb.next_collection_id TO 6640; SET documentdb.next_collection_index_id TO 6640; /* Insert with a.b being an object with various types*/ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 1, "a" : { "b" : 0 }}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 2, "a" : { "b" : 1 }}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 3, "a" : { "b" : 2.0 }}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 4, "a" : { "b" : "someString" }}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 5, "a" : { "b" : true }}', NULL); /* insert some documents with a.{some other paths} */ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 6, "a" : 1}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 7, "a" : true}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 8, "a" : [0, 1, 2]}', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 9, "a" : { "c": 1 }}', NULL); /* insert paths with nested objects arrays */ SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 10, "a" : { "b" : [ 0, 1, 2 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 11, "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3.0 }] }', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 12, "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 13, "a" : [ { "b": [[-1, 1, 2]] }, { "b": [[0, 1, 2]] }, { "b": [[0, 1, 7]] }] }', NULL); SELECT documentdb_api.insert_one('db','queryOperatorParameterized', '{"_id": 14, "a" : { "b" : [ { "1" : [1, 2, 3 ] } ] } }', NULL); SET client_min_messages TO WARNING; DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'queryOperatorParameterized'; EXECUTE format('SELECT undistribute_table(''documentdb_data.documents_%s'')', v_collection_id); END $$; SET client_min_messages TO DEFAULT; PREPARE q1 (text, text, bson) AS SELECT object_id, document FROM documentdb_api.collection($1, $2) WHERE document @@ $3; -- valid queries EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$lte" : [true, false] }}'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.b": 2 } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.b": 2 } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.c": { "$exists": 1 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.c": { "$exists": 0 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": { "$gte": 1 } }, { "a.c": { "$exists": 0 } } ] }'); -- invalid queries. EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a": { "$invalid": 1 } }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a": { "$invalid": 2 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ ] }'); -- repeat the queries with remote execution on. BEGIN; set local citus.enable_local_execution to off; EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$lte" : [true, false] }}'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.b": 2 } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.b": 2 } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$or": [ { "a.b": 1 }, { "a.c": { "$exists": 1 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": 1 }, { "a.c": { "$exists": 0 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a.b": { "$gte": 1 } }, { "a.c": { "$exists": 0 } } ] }'); -- invalid queries. EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a": { "$invalid": 1 } }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ { "a": { "$invalid": 2 } } ] }'); EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "$and": [ ] }'); ROLLBACK; -- repeat the queries with remote execution on and hex output. BEGIN; set local citus.enable_local_execution to off; set local documentdb_core.bsonUseEJson to off; EXECUTE q1( 'db', 'queryOperatorParameterized', bson_json_to_bson('{ "a.b": { "$eq" : 1 }}')); EXPLAIN (COSTS OFF) EXECUTE q1( 'db', 'queryOperatorParameterized', bson_json_to_bson('{ "a.b": { "$eq" : 1 }}')); ROLLBACK; -- run an explain analyze EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) EXECUTE q1( 'db', 'queryOperatorParameterized', '{ "a.b": { "$eq" : 1 }}'); PREPARE q2(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE document OPERATOR(documentdb_api_catalog.@@) $3 ORDER BY documentdb_api_catalog.bson_orderby(document, $4) DESC; EXPLAIN (COSTS OFF) EXECUTE q2( 'db', 'queryOperatorParameterized', '{ "a.b" : { "$gt": 0 } }', '{ "a.b": -1 }'); BEGIN; set local citus.enable_local_execution to off; EXPLAIN (COSTS OFF) EXECUTE q2( 'db', 'queryOperatorParameterized', '{ "a.b" : { "$gt": 0 } }', '{ "a.b": -1 }'); ROLLBACK; bson_query_operator_tests_pg17_explain_index.sql000066400000000000000000000047501507310017400406100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; SELECT documentdb_api.drop_collection('db', 'queryoperator') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'queryoperatorIn') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'queryoperatorIn'); SELECT documentdb_api.drop_collection('db', 'nullfield') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); -- create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a": 1, "c": 1 }, "name": "queryoperator_a_c" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "a.b": 1, "_id": 1 }, "name": "queryoperator_ab" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperator", "indexes": [ { "key": { "b": 1, "a": 1 }, "name": "queryoperator_b_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('nullfield', 'nullfield_wildcard', '{"$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a": 1 }, "name": "queryoperatorin_a" }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryoperatorIn", "indexes": [ { "key": { "a.b": 1 }, "name": "queryoperatorin_ab" }] }', true); -- create single path index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "singlepathindexexists", "indexes": [ { "key": { "a": 1 }, "name": "a_index" }] }', true); -- show the indexes \d documentdb_data.documents_1200 BEGIN; SET LOCAL citus.enable_local_execution TO OFF; set local documentdb.useLocalExecutionShardQueries to off; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; \i sql/bson_query_operator_tests_explain_core.sql COMMIT; bson_query_operator_tests_pg17_explain_index_comp_desc.sql000066400000000000000000000004371507310017400426220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_comp_desc.sqlbson_query_operator_tests_pg17_explain_index_comp_unique.sql000066400000000000000000000004411507310017400432050ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_comp_unique.sqlbson_query_operator_tests_pg17_explain_index_composite.sql000066400000000000000000000004371507310017400426700ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1200000; SET documentdb.next_collection_id TO 1200; SET documentdb.next_collection_index_id TO 1200; \i sql/bson_query_operator_tests_explain_index_composite.sqlbson_query_operator_tests_pg17_explain_runtime.sql000066400000000000000000000012321507310017400411540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1300000; SET documentdb.next_collection_id TO 1300; SET documentdb.next_collection_index_id TO 1300; SELECT documentdb_api.drop_collection('db', 'queryoperator'); SELECT documentdb_api.create_collection('db', 'queryoperator'); SELECT documentdb_api.drop_collection('db', 'nullfield'); SELECT documentdb_api.create_collection('db', 'nullfield'); SELECT documentdb_api.drop_collection('db', 'singlepathindexexists'); SELECT documentdb_api.create_collection('db', 'singlepathindexexists'); \i sql/bson_query_operator_tests_explain_core.sql bson_query_operator_tests_runtime.sql000066400000000000000000000004241507310017400366000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 250000; SET documentdb.next_collection_id TO 2500; SET documentdb.next_collection_index_id TO 2500; BEGIN; \i sql/bson_query_operator_tests_core.sql bson_query_projection_operator_expressions_map_tests.sql000066400000000000000000000320301507310017400425660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 245000; SET documentdb.next_collection_id TO 2450; SET documentdb.next_collection_index_id TO 2450; SELECT documentdb_api.insert_one('db','mapprojectexprs','{"array": [{"_id":"1", "a" : { "b" : 1 } },{"_id":"2", "a" : { "b" : [ 0, 1, 2]} },{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] },{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] },{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } },{"_id":"6", "a" : [ { "c" : 0 }, 2 ] },{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] },{"_id":"8", "a" : { "c" : 1 } },{"_id":"9", "c" : { "d" : 1 } }]}', NULL); -- field path expressions SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- field path expressions on bson_expression_get() with nullOnEmpty = true SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }', true) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- field path expressions on bson_expression_get() with nullOnEmpty = false SELECT bson_expression_map(document, 'array', '{ "field" : "$a" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.b" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : "$a.c" }', false) FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- const value expressions SELECT bson_expression_map(document, 'array', '{ "field" : "someString" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : [ "1.0" ] }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$minKey": 1 } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "nestedField": "fieldValue" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "nestedField": "fieldValue", "nestedField2": "fieldValue2" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- literal expressions SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": [1, 2, 3] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$literal": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- isArray expressions: top level expression SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$literal": [ 1, 2, 3 ] } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$literal": "someLiteral" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "nestedObj": "someValue" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- project $a.b along with isArray to validate the values easily. SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": "$a.b" } }'), bson_expression_map(document, 'array', '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- test nested operator expansion (this should all be false since the inner operator returns true/false and is never an array) SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": { "$isArray": "$a.b" } } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- isArray expressions: array declaration. SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "some literal" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "$literal": [ 1, 2, 3 ] } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "$literal": "someLiteral" } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ { "nestedObj": "someValue" } ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ [1, 2, 3 ] ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- isArray expressions: array declaration invalid SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ 1, 2 ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- unsupported operators SELECT bson_expression_map(document, 'array', '{ "field" : { "$unknownop": "some literal" } }') FROM documentdb_api.collection('db', 'mapprojectexprs') ORDER BY object_id; -- Array Expression and Nested Expression evaluation tests SELECT bson_expression_map(document, 'array', '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", "$a.b"]}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", "$a.b"], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : { "$isArray": [ "$a.b" ] , "a": 1.0} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : { "first": 1.0, "$isArray": [ "$a.b" ]} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : ["$_id", ["$a", "$b"], { "arrayobj" : [{},"$_id"]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : [{"$literal" : 3.12}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : [{"$isArray" : [1,2]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : {"$literal" : 3.12} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : {"$isArray" : "$a.b"} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); -- Expressions with undefined paths. SELECT documentdb_api.insert_one('db', 'mapprojectexprwithundefined','{"array": [{"_id":"1", "a": [ 1, 2 ] },{"_id":"2", "a": { "b": 1 } },{"_id":"3", "a" : [ { "b": 1 }, 2, 3 ] },{"_id":"4", "a" : { "b": [ 1, 2 ] } } ] }', NULL); SELECT bson_expression_map(document, 'array', '{"field": "$z"}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": "$a.b.c"}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": ["$z", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": ["$a.b.c", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": ["$a.x.y", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": ["$z.x.y", 2]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, ["$z"]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 2]}]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); SELECT bson_expression_map(document, 'array', '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 0]}]]}') FROM documentdb_api.collection('db', 'mapprojectexprwithundefined'); -- Error cases when a field is an empty string SELECT bson_expression_map(document, 'array', '{ "field" : {"" : "$a.b"} }') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "new" : {"val": ["1", "2", {"": "hello"}], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'mapprojectexprs'); SELECT bson_expression_map(document, 'array', '{ "field" : [{"literal" : [2, {"" : "empty"}]}] }') FROM documentdb_api.collection('db', 'mapprojectexprs'); -- Field not present or null, NullOnEmpty = false SELECT bson_expression_map('{"array": [{}]}', 'array', '{ "": "$a" }', false), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": "$a" }', false), bson_expression_map('{"array": [{}]}', 'array', '{ "": { "a" : "$a" }}', false), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', false); -- Field not present or null, NullOnEmpty = true SELECT bson_expression_map('{"array": [{}]}', 'array', '{ "": "$a" }', true), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": "$a" }', true), bson_expression_map('{"array": [{}]}', 'array', '{ "": { "a" : "$a" }}', true), bson_expression_map('{"array": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', true); -- Array not present or null or not an array SELECT bson_expression_map('{"array": {}}', 'array', '{ "": "$a" }', true); SELECT bson_expression_map('{"array": null}', 'array', '{ "": "$a" }', true); SELECT bson_expression_map('{"array": []}', 'array', '{ "": { "a" : "$a" }}', true); SELECT bson_expression_map('{"notarray": [{"a" : null}]}', 'array', '{ "": { "a" : "$a" }}', true); -- Document and array expressions with nested expressions that should be converted to a constant at the tree parse stage SET client_min_messages TO DEBUG3; SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": {"a": [ { "$literal" : "foo" } ] }}'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$literal" : "foo" } ] }'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$undefined" : true } ] }'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": [ { "$literal" : "foo" }, {"$substr": ["wehello world", 2, -1]} ] }'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"result": {"a": [ { "$literal" : "foo" } ], "a": {"$const": "foo2"} }}'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": { "b" : {"a": "foo", "d": {"$substr": ["hello world", 6, -1]}} }, "c": {"$const": "c is 2"} }}'); SELECT bson_expression_map('{"array": [{}]}', 'array', '{"document": {"a": {"d": { "$literal" : {"a": "$$REMOVE" } }, "c": [{"$literal": "$$REMOVE"}, true, false]}, "b": {"$const": "b is 2"}}}'); SET client_min_messages TO DEFAULT; bson_query_projection_operator_expressions_tests.sql000066400000000000000000000315671507310017400417470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 240000; SET documentdb.next_collection_id TO 2400; SET documentdb.next_collection_index_id TO 2400; SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"1", "a" : { "b" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"2", "a" : { "b" : [ 0, 1, 2]} }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"3", "a" : [ { "b": 0 }, { "b": 1 }, { "b": 3}] }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"4", "a" : [ { "b": [-1, 1, 2] }, { "b": [0, 1, 2] }, { "b": [0, 1, 7] }] }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"5", "a" : { "b" : [ { "1" : [ 1, 2, 3 ] } ] } }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"6", "a" : [ { "c" : 0 }, 2 ] }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"7", "a" : [ { "c" : 0 }, { "c" : 1 }, { "b" : 2 } ] }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"8", "a" : { "c" : 1 } }', NULL); SELECT documentdb_api.insert_one('db','projectexprs','{"_id":"9", "c" : { "d" : 1 } }', NULL); -- field path expressions SELECT bson_expression_get(document, '{ "field" : "$a" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.c" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- field path expressions on bson_expression_get() with nullOnEmpty = true SELECT bson_expression_get(document, '{ "field" : "$a" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.b" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.c" }', true) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- field path expressions on bson_expression_get() with nullOnEmpty = false SELECT bson_expression_get(document, '{ "field" : "$a" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.b" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : "$a.c" }', false) FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- const value expressions SELECT bson_expression_get(document, '{ "field" : "someString" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : [ "1.0" ] }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$minKey": 1 } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "nestedField": "fieldValue" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "nestedField": "fieldValue", "nestedField2": "fieldValue2" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- literal expressions SELECT bson_expression_get(document, '{ "field" : { "$literal": 1.0 } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$literal": [1, 2, 3] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$literal": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- isArray expressions: top level expression SELECT bson_expression_get(document, '{ "field" : { "$isArray": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$literal": [ 1, 2, 3 ] } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$literal": "someLiteral" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "nestedObj": "someValue" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- project $a.b along with isArray to validate the values easily. SELECT bson_expression_get(document, '{ "field" : { "$isArray": "$a.b" } }'), bson_expression_get(document, '{ "field" : "$a.b" }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- test nested operator expansion (this should all be false since the inner operator returns true/false and is never an array) SELECT bson_expression_get(document, '{ "field" : { "$isArray": { "$isArray": "$a.b" } } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- isArray expressions: array declaration. SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "some literal" ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "$literal": [ 1, 2, 3 ] } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "$literal": "someLiteral" } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ { "nestedObj": "someValue" } ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ [1, 2, 3 ] ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- isArray expressions: array declaration invalid SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ 1, 2 ] } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- unsupported operators SELECT bson_expression_get(document, '{ "field" : { "$unknownop": "some literal" } }') FROM documentdb_api.collection('db', 'projectexprs') ORDER BY object_id; -- Array Expression and Nested Expression evaluation tests SELECT bson_expression_get(document, '{ "new" : ["$_id"]}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : ["$a"]}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : ["$a.b"]}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : {"val": ["$a.b"]}}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", "$a.b"]}}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", "$a.b"], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] } }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : { "$isArray": [ "$a.b" ] , "a": 1.0} }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : { "first": 1.0, "$isArray": [ "$a.b" ]} }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : ["$_id", ["$a", "$b"], { "arrayobj" : [{},"$_id"]}] }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : [{"$literal" : 3.12}] }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : [{"$isArray" : [1,2]}] }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : {"$literal" : 3.12} }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : {"$isArray" : "$a.b"} }') FROM documentdb_api.collection('db', 'projectexprs'); -- Expressions with undefined paths. SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"1", "a": [ 1, 2 ] }', NULL); SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"2", "a": { "b": 1 } }', NULL); SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"3", "a" : [ { "b": 1 }, 2, 3 ] }', NULL); SELECT documentdb_api.insert_one('db', 'projectexprwithundefined','{"_id":"4", "a" : { "b": [ 1, 2 ] } }', NULL); SELECT bson_expression_get(document, '{"field": "$z"}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": "$a.b.c"}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": ["$z", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": ["$a.b.c", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": ["$a.x.y", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": ["$z.x.y", 2]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, ["$z"]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 2]}]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); SELECT bson_expression_get(document, '{"field": [ ["$a.x.y"], 2, [{"$arrayElemAt": [[1], 0]}]]}') FROM documentdb_api.collection('db', 'projectexprwithundefined'); -- Error cases when a field is an empty string SELECT bson_expression_get(document, '{ "field" : {"" : "$a.b"} }') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "new" : {"val": ["1", "2", {"": "hello"}], "val2": "$_id"}}') FROM documentdb_api.collection('db', 'projectexprs'); SELECT bson_expression_get(document, '{ "field" : [{"literal" : [2, {"" : "empty"}]}] }') FROM documentdb_api.collection('db', 'projectexprs'); -- Field not present or null, NullOnEmpty = false SELECT bson_expression_get('{}', '{ "": "$a" }', false), bson_expression_get('{"a" : null}', '{ "": "$a" }', false), bson_expression_get('{}', '{ "": { "a" : "$a" }}', false), bson_expression_get('{"a" : null}', '{ "": { "a" : "$a" }}', false); -- Field not present or null, NullOnEmpty = true SELECT bson_expression_get('{}', '{ "": "$a" }', true), bson_expression_get('{"a" : null}', '{ "": "$a" }', true), bson_expression_get('{}', '{ "": { "a" : "$a" }}', true), bson_expression_get('{"a" : null}', '{ "": { "a" : "$a" }}', true); -- Document and array expressions with nested expressions that should be converted to a constant at the tree parse stage SET client_min_messages TO DEBUG3; SELECT bson_expression_get('{}', '{"result": {"a": [ { "$literal" : "foo" } ] }}'); SELECT bson_expression_get('{}', '{"result": [ { "$literal" : "foo" } ] }'); SELECT bson_expression_get('{}', '{"result": [ { "$undefined" : true } ] }'); SELECT bson_expression_get('{}', '{"result": [ { "$literal" : "foo" }, {"$substr": ["wehello world", 2, -1]} ] }'); SELECT bson_expression_get('{}', '{"result": {"a": [ { "$literal" : "foo" } ], "a": {"$const": "foo2"} }}'); SELECT bson_expression_get('{}', '{"document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); SELECT bson_expression_get('{}', '{"document": {"a": { "b" : {"a": "foo", "d": {"$substr": ["hello world", 6, -1]}} }, "c": {"$const": "c is 2"} }}'); SELECT bson_expression_get('{}', '{"document": {"a": {"d": { "$literal" : {"a": "$$REMOVE" } }, "c": [{"$literal": "$$REMOVE"}, true, false]}, "b": {"$const": "b is 2"}}}'); SELECT bson_dollar_project('{}', '{"array": [{"$substr": ["hello world", 0, -1]}, "1", 2, true, false, {"$literal": [{ "$add":[1, 2] }]}], "document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"} }}'); SELECT bson_dollar_project('{}', '{"array": [{"$substr": ["hello world", 0, -1]}, "1", 2, true, false, {"$literal": [{ "$add":[1, 2] }]}], "document": {"a": { "$literal" : {"a": "$$REMOVE" } }, "b": {"$const": "b is 2"}}, "array2": [{"$literal": "$$ROOT"}, {"$literal": "$$NOW"}, true], "document2": {"result": {"$substr": ["result is: blah", 11, -1]}}}'); SET client_min_messages TO DEFAULT; bson_query_shard_key_optimization_tests.sql000066400000000000000000000055711507310017400377710ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 170000; SET documentdb.next_collection_id TO 1700; SET documentdb.next_collection_index_id TO 1700; SELECT documentdb_api.drop_collection('db', 'shardkeyopt') IS NOT NULL; SELECT documentdb_api.create_collection('db', 'shardkeyopt'); -- create an index on a.b SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('shardkeyopt', 'a_b_1', '{"a.b": 1}'), true); BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "_id": { "$gt": { "$minKey": 1 } }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "_id": { "$gt": { "$minKey": 1 } }}'; ROLLBACK; -- shard the collection SELECT documentdb_api.shard_collection('db', 'shardkeyopt', '{ "c": "hashed" }', false); BEGIN; -- avoid sequential scan (likely to be preferred on small tables) set local enable_seqscan TO off; set local documentdb.forceUseIndexIfAvailable to on; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "_id": { "$gt": { "$minKey": 1 } }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "_id": { "$gt": { "$minKey": 1 } }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$eq" : 1 }, "c": 2 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "c": 2 }'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "a.b": { "$ne" : 1 }, "c": 2, "_id": { "$gt": { "$minKey": 1 } }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'shardkeyopt') WHERE document @@ '{ "c": 2, "_id": { "$gt": { "$minKey": 1 } }}'; ROLLBACK; bson_selectivity_index_tests.sql000066400000000000000000000121571507310017400355160ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1014000; SET documentdb.next_collection_id TO 10140; SET documentdb.next_collection_index_id TO 10140; -- Test Scenarios that cover the Bitmap Or selectivity - more selecitivity tests will be added here with r1 AS (SELECT FORMAT('{ "a": 1, "b": 2, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(1, 25000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; with r1 AS (SELECT FORMAT('{ "a": 1, "b": 3, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(25001, 50000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; with r1 AS (SELECT FORMAT('{ "a": 1, "b": 3, "c": %s, "d": %s }', ((s % 2) + 1), s)::json as textVal from generate_series(50001, 75000) s), r2 AS (SELECT json_build_object('insert', 'selectivity_index_tests', 'documents', json_agg(r1.textVal)) AS jsonObj FROM r1) SELECT documentdb_api.insert('db', (r2.jsonObj)::text::bson) FROM r2; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "selectivity_index_tests", "indexes": [ { "key": { "a": 1, "b": 1, "c": 1, "d": 1 }, "name": "idx_1" } ]}', true); ANALYZE documentdb_data.documents_10140; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'selectivity_index_tests') WHERE document @@ '{ "a": 1, "b": { "$in": [ 2, 3, 4, 5 ] }, "a": { "$in": [ 1, 5, 6, 7 ] }, "$or": [ { "c": 3, "d": { "$gt": 500 } }, { "c": { "$gt": 4 } }] }'; BEGIN; set local documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'selectivity_index_tests') WHERE document @@ '{ "a": 1, "b": { "$in": [ 2, 3, 4, 5 ] }, "a": { "$in": [ 1, 5, 6, 7 ] }, "$or": [ { "c": 3, "d": { "$gt": 500 } }, { "c": { "$gt": 4 } }] }'; ROLLBACK; -- test bitmap or pushdown SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A380", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 40); SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A350", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 50); SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A330", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 30); SELECT COUNT(documentdb_api.insert_one('seldb', 'bimap_or_selectivity', '{ "plane": "A340", "noticeDate": "2008-01-01", "stoppingDate": "2025-01-01", "productionDate": "2005-01-01" }')) FROM generate_series(1, 30); SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "productionDate": 1, "plane": 1 }, "name": "plane_productionDate_index" } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "stoppingDate": 1, "plane": 1 }, "name": "plane_stoppingDate_index" } ] }', TRUE); SELECT documentdb_api_internal.create_indexes_non_concurrently('seldb', '{ "createIndexes": "bimap_or_selectivity", "indexes": [ { "key": { "noticeDate": 1, "plane": 1 }, "name": "plane_noticeDate_index" } ] }', TRUE); ANALYZE documentdb_data.documents_10142; set documentdb.enableNewSelectivityMode to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); set documentdb.enableNewSelectivityMode to on; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); set documentdb.enableNewSelectivityMode to off; EXPLAIN (COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT document FROM bson_aggregation_find('seldb', '{ "find" : "bimap_or_selectivity", "filter" : { "plane" : { "$regularExpression" : { "pattern" : "A.+", "options" : "i" } }, "$and" : [ { "$or" : [ { "productionDate" : { "$exists" : false } }, { "stoppingDate" : { "$exists" : false } }, { "noticeDate" : { "$exists" : false } } ] } ] }, "limit" : { "$numberInt" : "10" } }'); documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_sequence_tests.sql000066400000000000000000000016351507310017400336510ustar00rootroot00000000000000SET search_path TO documentdb_api,documentdb_api_internal,documentdb_core; SET citus.next_shard_id TO 230000; SET documentdb.next_collection_id TO 2300; SET documentdb.next_collection_index_id TO 2300; SELECT '{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence; SELECT bsonsequence_get_bson('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence); SELECT bsonsequence_get_bson(bsonsequence_in(bsonsequence_out('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence))); PREPARE q1(bytea) AS SELECT bsonsequence_get_bson($1); EXECUTE q1('{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence::bytea); SELECT '{ "": [ { "a": 1 }, { "a": 2 } ] }'::bsonsequence::bytea::bsonsequence; SELECT bsonsequence_get_bson('{ "a": 1 }'::bson::bsonsequence); -- generate a long string and ensure we have the docs. SELECT COUNT(*) FROM bsonsequence_get_bson(('{ "": [ ' || rtrim(REPEAT('{ "a": 1, "b": 2 },', 100), ',') || ' ] }')::bsonsequence); bson_sort_index_pushdown.sql000066400000000000000000000160711507310017400346450ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- tests specific to pushing down to the right index the $sort -- at the moment $sort is not pushed down to index unless it is a $sort on the _id field -- on an unsharded collection or we have a shard key filter and all the filters can be pushed to the _id index. -- once we support sort pushdown to the index we need to revisit the strategy to push down sort on _id. SET search_path TO documentdb_api,documentdb_api_internal,documentdb_api_catalog,documentdb_core; SET citus.next_shard_id TO 9640000; SET documentdb.next_collection_id TO 964000; SET documentdb.next_collection_index_id TO 964000; SET documentdb.enableIndexOrderbyPushdown = 'on'; DO $$ DECLARE i int; DECLARE a int; DECLARE modres int; BEGIN FOR i IN 1..10000 LOOP SELECT MOD(i, 3) into modres; CASE WHEN modres = 0 THEN a:=12; WHEN modres = 1 THEN a:=14; ELSE a:=22; END CASE; PERFORM documentdb_api.insert_one('sort_pushdown', 'coll', FORMAT('{ "_id": %s, "a": %s}', i, a)::documentdb_core.bson); END LOOP; END; $$; SELECT 1 FROM documentdb_distributed_test_helpers.get_feature_counter_pretty(true); SELECT count(*) from documentdb_api.collection('sort_pushdown', 'coll'); -- force the analyzer to kick in to have real statistics after we did the insertion. ANALYZE documentdb_data.documents_964001; -- sort by id with no filters uses the _id_ index and returns the right results set enable_seqscan to off; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1} }'); SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": -1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": -1} }'); reset enable_seqscan; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- filter on _id_ SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": 1}, "limit":20 }'); SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": -1}, "limit":20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": 1} }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 5}}, "sort": {"_id": -1} }'); -- filter on a with no index SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 22}}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 22}}, "sort": {"_id": 1}, "limit": 20 }'); -- create compound index on a and _id and filter on a and on _id SELECT documentdb_api_internal.create_indexes_non_concurrently('sort_pushdown', '{ "createIndexes": "coll", "indexes": [ { "key": { "a": 1, "_id": 1 }, "name": "a_id" }]}', true); ANALYZE documentdb_data.documents_964001; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$in": [12, 14]}}, "sort": {"_id": 1}, "limit": 20 }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown = 'false'; ---- should not use Index Scan using _id_ EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); ---- should not use Index Scan using _id_ with $in EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$in": [12, 14]}}, "sort": {"_id": 1}, "limit": 20 }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); END; SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 100}}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"_id": {"$gt": 100}}, "sort": {"_id": 1}, "limit": 20 }'); -- no filter should still prefer the _id index EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); -- shard the collection on a, should sort on object_id only when there is a shard filter. SELECT documentdb_api.shard_collection('{ "shardCollection": "sort_pushdown.coll", "key": { "a": "hashed" }, "numInitialChunks": 2 }'); SET citus.explain_all_tasks to on; SET citus.max_adaptive_executor_pool_size to 1; EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$gt": 14}}, "sort": {"_id": 1}, "limit": 20 }'); -- no filter on sharded collection should not sort on object_id EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {}, "sort": {"_id": 1}, "limit": 20 }'); -- drop compound index, should use the _id index CALL documentdb_api.drop_indexes('sort_pushdown', '{ "dropIndexes": "coll", "index": "a_id"}'); ANALYZE documentdb_data.documents_964001; BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown = 'true'; EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"a": {"$eq": 14}}, "sort": {"_id": 1}, "limit": 20 }'); -- or should push down to the shards and use object_id EXPLAIN (COSTS OFF, TIMING OFF, ANALYZE ON, SUMMARY OFF) SELECT document FROM bson_aggregation_find('sort_pushdown', '{ "find": "coll", "filter": {"$or": [{"a": {"$eq": 14}}, {"a": {"$eq": 22}}]}, "sort": {"_id": 1}, "limit": 20 }'); ROLLBACK; RESET citus.explain_all_tasks; RESET citus.max_adaptive_executor_pool_size;bson_type_comparison_tests.sql000066400000000000000000000111001507310017400351610ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 66100; SET documentdb.next_collection_id TO 6610; SET documentdb.next_collection_index_id TO 6610; -- insert double SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : 3.0 }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : 5.0 }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : -1.0 }', NULL); -- string SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "Hell" }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "hell" }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "hello world" }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : "Actual string" }', NULL); -- object SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "a": 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "b": 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "ba": 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "c": 1 } }', NULL); -- array SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : [ 1, 2, 3 ] }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : [ true, "string", 2.0 ] }', NULL); -- binary SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$binary": { "base64": "VGhpcyBpcyBhIHN0cmluZw==", "subType": "00" }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$binary": { "base64": "QSBxdWljayBicm93biBmb3g=", "subType": "00" }} }', NULL); -- object_id SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$oid": "000102030405060708090A0B" } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$oid": "0102030405060708090A0B0C" } }', NULL); -- bool SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : true }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : false }', NULL); -- date SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "123" } } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "5192" } } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "-200" } } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$date": { "$numberLong": "1647277893736" } } }', NULL); -- null SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : null }', NULL); -- regex SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "^foo$", "options": "gi" }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "^foo$", "options": "" }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$regularExpression": { "pattern": "bar$", "options": "g" }} }', NULL); -- int32 SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "25" } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "13486" } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberInt": "-25" } }', NULL); -- int64 SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "25" } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "13486" } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$numberLong": "-25" } }', NULL); -- timestamp SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 256, "i": 1 }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 256, "i": 25 }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 200, "i": 10 }} }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$timestamp": { "t": 200, "i": 80 }} }', NULL); -- minkey, maxkey SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$minKey": 1 } }', NULL); SELECT documentdb_api.insert_one('db','bsontypetests', '{ "a" : { "$maxKey": 1 } }', NULL); -- These type comparison don't work. -- Decimal128 -- these types don't have an extended json representation -- Javascript -- Javascript with scope -- Symbol -- DBPointer SELECT document -> 'a' FROM documentdb_api.collection('db', 'bsontypetests') ORDER BY document -> 'a', object_id; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/bson_unique_index.sql000066400000000000000000000633441507310017400333210ustar00rootroot00000000000000 SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 560000; SET documentdb.next_collection_id TO 5600; SET documentdb.next_collection_index_id TO 5600; SET documentdb.enable_large_unique_index_keys TO false; -- insert a document SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"1", "a": { "b": 1 } }', NULL); -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1 }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; -- insert a value that doesn't collide with the unique index. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"2", "a": [ { "b": 2 }, { "b" : 3 }]}', NULL); -- insert a value that has duplicate values that do not collide with other values. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"3", "a": [ { "b": 4 }, { "b" : 4 }]}', NULL); -- insert a value that has duplicate values that collide wtih other values. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"4", "a": [ { "b": 5 }, { "b" : 3 }]}', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"5", "a": { "b": [ 5, 3 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"6", "a": { "b": 3 } }', NULL); -- valid scenarios again. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"4", "a": [ { "b": 5 }, { "b" : 6 }]}', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"5", "a": { "b": [ 7, 9 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"6", "a": { "b": 8 } }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"7", "a": { "b": true } }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"8", "a": { "b": "someValue" } }', NULL); -- we can use the unique index for queries BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueindex') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; ROLLBACK; -- insert a document that does not have an a.b (should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "c": "someValue" } }', NULL); -- insert another document that does not have an a.b (should fail) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "d": "someValue" } }', NULL); -- insert another document that has a.b = null (Should fail) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"a": { "b": null } }', NULL); -- insert a document that has constraint failure on _id SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id": "8", "a": { "b": 2055 } }', NULL); -- drop the unique index. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniqueindex", "index": ["rumConstraint1"]}'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; -- now we can violate the unique constraint SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"9", "a": { "b": 1 } }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"10", "a": { "b": [ 2, 1 ] } }', NULL); -- create an index when the collection violates unique. Should fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 }] }', true); -- create a unique index with the same name ( should be fine since we dropped it ) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "c": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; -- since this is sparse, we can create several documents without "c" on it. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"11", "d": "someValue" }', NULL); -- insert another document that does not have an c (should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"12", "e" : true }', NULL); -- insert another document that has a.b = null (Should succeed) SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"13", "c": null }', NULL); -- however, inserting 'c' again should fail. SELECT documentdb_api.insert_one('db','queryuniqueindex','{"_id":"14", "c": null }', NULL); -- drop the unique index by key. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniqueindex", "index": {"c": 1} }'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindex') ORDER BY collection_id, index_id; -- create unique index fails for wildcard. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"f.$**": 1}, "name": "my_idx3", "unique": 1.0}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"$**": 1}, "wildcardProjection": { "f.g": 0 }, "name": "my_idx3", "unique": 1.0}]}', true); -- test for sharded SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"1", "a": { "b": 1 }, "d": 1 }', NULL); SELECT documentdb_api.shard_collection('db', 'queryuniqueindexsharded', '{ "d": "hashed" }', false); -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindexsharded", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1 }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueindexsharded') ORDER BY collection_id, index_id; -- valid scenarios: SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"2", "a": { "b": [ 2, 2] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"3", "a": { "b": [ 3, 4 ] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"4", "a": { "b": 5 }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"5", "a": { "c": 5 }, "d": 1 }', NULL); -- now violate unique in shard key "d": 1 SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"6", "a": { "b": [ 3, 6 ] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"7", "a": { "b": null }, "d": 1 }', NULL); -- now insert something in a different shard - should not violate unique SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"8", "a": { "b": [ 3, 6 ] }, "d": 2 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueindexsharded','{"_id":"9", "a": { "b": null }, "d": 2 }', NULL); -- still can be used for query. BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueindexsharded') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; ROLLBACK; -- create unique index with truncation SELECT string_agg(md5(random()::text), '_') AS longstring1 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring2 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring3 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring4 FROM generate_series(1, 100) \gset SELECT length(:'longstring1'); -- create with truncation allowed and the new op-class enabled set documentdb.enable_large_unique_index_keys to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "e": 1 }, "name": "rumConstraint1", "unique": 1, "unique": 1, "sparse": 1 }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "e": 1, "f": 1 }, "name": "rumConstraint2", "unique": 1, "unique": 1, "sparse": 1 }] }', true); \d documentdb_data.documents_5600 -- succeeds SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 1, "e": "%s", "f": 1 }', :'longstring1')::bson); -- unique conflict SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 2, "e": [ "%s", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); -- create with suffix post truncation - succeeds SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 3, "e": [ "%s-withsuffix", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); -- this should also fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 4, "e": "%s-withsuffix", "f": 1 }', :'longstring1')::bson); -- this will work. SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 5, "e": "%s-withsuffix", "f": 1 }', :'longstring2')::bson); -- this will fail (suffix match of array and string). SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 6, "e": [ "%s", "%s-withsuffix" ], "f": 1 }', :'longstring3', :'longstring2')::bson); -- test truncated elements with numeric types of the same/different equivalent value. SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 7, "e": { "path1": "%s", "path2": 1.0 }, "f": 1 }', :'longstring3')::bson); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 8, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.0" }}, "f": 1 }', :'longstring3')::bson); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', FORMAT('{ "_id": 9, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.01" }}, "f": 1 }', :'longstring3')::bson); -- test composite sparse unique indexes: Should succeed since none of the documents have this path (sparse unique ignore) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "g": 1, "h": 1 }, "name": "rumConstraint3", "unique": 1, "sparse": 1 }] }', true); -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5, "h": 5 }'); -- fails (unique cosntraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5, "h": 5 }'); -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5 }'); -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "g": 5 }'); -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "h": 5 }'); -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "h": 5 }'); -- reset test data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "rumConstraint1", "rumConstraint2", "rumConstraint3" ] }'); \d documentdb_data.documents_5600 -- test unique sparse composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": 1, "sparse": 1 }] }', true); \d documentdb_data.documents_5600 -- should succeed and generate terms for all combinations on both arrays SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); -- should fail due to terms permutation on both arrays SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": 6 }'); -- now test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3, 4, 5] }'); -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5 }'); -- should succeed with null permutations on missing key (sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5, "key2": null }'); -- should succeed due to new combinations SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 6, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key2": 3 }'); -- should work because doesn't fall in unique constraint SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key3": [1, 2] }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key3": [1, 2] }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5600 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); \d documentdb_data.documents_5600 -- test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": [1, 2, 3, 4, 5] }'); -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5 }'); -- should fail with null permutations on missing key (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 1, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 2, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 3, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 4, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "key1": 5, "key2": null }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5600 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": true }] }', true); \d documentdb_data.documents_5600 -- should work SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "c": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "b": 1, "c": 1 }'); -- repeated documents won't matter because they don't fall in the index (sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5600 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); \d documentdb_data.documents_5600 -- should work SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "c": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "b": 1, "c": 1 }'); -- repeated documents will matter because they fall in the index (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "z": 1 }'); -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": 1, "b": 1 }'); -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5600 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); \d documentdb_data.documents_5600 -- insert data in a way that bson_rum_single_path_ops will match truncated and bson_rum_unique_shard_path_ops recheck won't set documentdb.defaultUniqueIndexKeyhashOverride to 1; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- should succeed with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); -- reset log level RESET client_min_messages; -- should fail even with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5600; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniqueindex", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5600 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueindex", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false }] }', true); \d documentdb_data.documents_5600 -- insert data in a way that bson_rum_single_path_ops will match truncated but unique shard uuid won't match set documentdb.defaultUniqueIndexKeyhashOverride to 0; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works - SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- should succeed without recheck logs SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); -- reset log level RESET client_min_messages; -- should fail SELECT documentdb_api.insert_one('db', 'queryuniqueindex', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- test new op class (generate_unique_shard_document) for composite sparse indexes SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key2": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": 3 }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": ["a"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": "abobora", "key2": ["jabuticaba"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, true); -- test new op class (generate_unique_shard_document) for composite not sparse indexes SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key2": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": 1, "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": 3 }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": [1, 2, 3, 4, 5], "key2": ["a"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key1": "abobora", "key2": ["jabuticaba"] }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false); SELECT documentdb_api_internal.generate_unique_shard_document('{ "key3": "b" }', 1, '{ "key1" : { "$numberInt" : "1" }, "key2" : { "$numberInt" : "1" } }'::bson, false);bson_unique_index_composite.sql000066400000000000000000000577461507310017400353350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 562000; SET documentdb.next_collection_id TO 5620; SET documentdb.next_collection_index_id TO 5620; SET documentdb.enable_large_unique_index_keys TO false; -- insert a document SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"1", "a": { "b": 1 } }', NULL); -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "enableCompositeTerm": true }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; -- insert a value that doesn't collide with the unique index. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"2", "a": [ { "b": 2 }, { "b" : 3 }]}', NULL); -- insert a value that has duplicate values that do not collide with other values. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"3", "a": [ { "b": 4 }, { "b" : 4 }]}', NULL); -- insert a value that has duplicate values that collide wtih other values. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"4", "a": [ { "b": 5 }, { "b" : 3 }]}', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"5", "a": { "b": [ 5, 3 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"6", "a": { "b": 3 } }', NULL); -- valid scenarios again. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"4", "a": [ { "b": 5 }, { "b" : 6 }]}', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"5", "a": { "b": [ 7, 9 ] } }', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"6", "a": { "b": 8 } }', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"7", "a": { "b": true } }', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"8", "a": { "b": "someValue" } }', NULL); -- we can use the unique index for queries BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniquecomposite') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; ROLLBACK; -- insert a document that does not have an a.b (should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "c": "someValue" } }', NULL); -- insert another document that does not have an a.b (should fail) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "d": "someValue" } }', NULL); -- insert another document that has a.b = null (Should fail) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"a": { "b": null } }', NULL); -- insert a document that has constraint failure on _id SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id": "8", "a": { "b": 2055 } }', NULL); -- drop the unique index. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniquecomposite", "index": ["rumConstraint1"]}'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; -- now we can violate the unique constraint SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"9", "a": { "b": 1 } }', NULL); SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"10", "a": { "b": [ 2, 1 ] } }', NULL); -- create an index when the collection violates unique. Should fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); -- create a unique index with the same name ( should be fine since we dropped it ) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "c": 1 }, "name": "rumConstraint1", "unique": 1, "sparse": 1 , "enableCompositeTerm": true}] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; -- since this is sparse, we can create several documents without "c" on it. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"11", "d": "someValue" }', NULL); -- insert another document that does not have an c (should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"12", "e" : true }', NULL); -- insert another document that has a.b = null (Should succeed) SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"13", "c": null }', NULL); -- however, inserting 'c' again should fail. SELECT documentdb_api.insert_one('db','queryuniquecomposite','{"_id":"14", "c": null }', NULL); -- drop the unique index by key. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "queryuniquecomposite", "index": {"c": 1} }'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniquecomposite') ORDER BY collection_id, index_id; -- create unique index fails for wildcard. SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"f.$**": 1}, "name": "my_idx3", "unique": 1.0 }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('uniquedb', '{"createIndexes": "collection1", "indexes": [{"key": {"$**": 1}, "wildcardProjection": { "f.g": 0 }, "name": "my_idx3", "unique": 1.0}]}', true); -- test for sharded SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"1", "a": { "b": 1 }, "d": 1 }', NULL); SELECT documentdb_api.shard_collection('db', 'queryuniqueshardedcomposite', '{ "d": "hashed" }', false); -- Create a unique index on the collection. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniqueshardedcomposite", "indexes": [ { "key" : { "a.b": 1 }, "name": "rumConstraint1", "unique": 1, "enableCompositeTerm": true }] }', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'queryuniqueshardedcomposite') ORDER BY collection_id, index_id; -- valid scenarios: SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"2", "a": { "b": [ 2, 2] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"3", "a": { "b": [ 3, 4 ] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"4", "a": { "b": 5 }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"5", "a": { "c": 5 }, "d": 1 }', NULL); -- now violate unique in shard key "d": 1 SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"6", "a": { "b": [ 3, 6 ] }, "d": 1 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"7", "a": { "b": null }, "d": 1 }', NULL); -- now insert something in a different shard - should not violate unique SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"8", "a": { "b": [ 3, 6 ] }, "d": 2 }', NULL); SELECT documentdb_api.insert_one('db','queryuniqueshardedcomposite','{"_id":"9", "a": { "b": null }, "d": 2 }', NULL); -- still can be used for query. BEGIN; set local documentdb.forceUseIndexIfAvailable to on; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'queryuniqueshardedcomposite') WHERE document @@ '{ "a.b": { "$gt": 5 } }'; ROLLBACK; -- create unique index with truncation SELECT string_agg(md5(random()::text), '_') AS longstring1 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring2 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring3 FROM generate_series(1, 100) \gset SELECT string_agg(md5(random()::text), '_') AS longstring4 FROM generate_series(1, 100) \gset SELECT length(:'longstring1'); -- create with truncation allowed and the new op-class enabled set documentdb.enable_large_unique_index_keys to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "e": 1 }, "name": "rumConstraint1", "unique": 1, "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "e": 1, "f": 1 }, "name": "rumConstraint2", "unique": 1, "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- succeeds SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 1, "e": "%s", "f": 1 }', :'longstring1')::bson); -- unique conflict SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 2, "e": [ "%s", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); -- create with suffix post truncation - succeeds SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 3, "e": [ "%s-withsuffix", "%s" ], "f": 1 }', :'longstring1', :'longstring2')::bson); -- this should also fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 4, "e": "%s-withsuffix", "f": 1 }', :'longstring1')::bson); -- this will work. SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 5, "e": "%s-withsuffix", "f": 1 }', :'longstring2')::bson); -- this will fail (suffix match of array and string). SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 6, "e": [ "%s", "%s-withsuffix" ], "f": 1 }', :'longstring3', :'longstring2')::bson); -- test truncated elements with numeric types of the same/different equivalent value. SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 7, "e": { "path1": "%s", "path2": 1.0 }, "f": 1 }', :'longstring3')::bson); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 8, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.0" }}, "f": 1 }', :'longstring3')::bson); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', FORMAT('{ "_id": 9, "e": { "path1": "%s", "path2": { "$numberDecimal": "1.01" }}, "f": 1 }', :'longstring3')::bson); -- test composite sparse unique indexes: Should succeed since none of the documents have this path (sparse unique ignore) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "g": 1, "h": 1 }, "name": "rumConstraint3", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5, "h": 5 }'); -- fails (unique cosntraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5, "h": 5 }'); -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5 }'); -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "g": 5 }'); -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "h": 5 }'); -- fails (unique constraint) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "h": 5 }'); -- reset test data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "rumConstraint1", "rumConstraint2", "rumConstraint3" ] }'); \d documentdb_data.documents_5620 -- test unique sparse composite index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": 1, "sparse": 1, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- should succeed and generate terms for all combinations on both arrays SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); -- should fail due to terms permutation on both arrays SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3], "key2": [4, 5, 6] }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 5 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": 6 }'); -- now test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3, 4, 5] }'); -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5 }'); -- should succeed with null permutations on missing key (sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5, "key2": null }'); -- should succeed due to new combinations SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 6, "key2": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key2": 3 }'); -- should work because doesn't fall in unique constraint SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key3": [1, 2] }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key3": [1, 2] }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5620 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "key1": 1, "key2": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); \d+ documentdb_data.documents_5620 \d+ documentdb_data.documents_rum_index_5631 -- test array permutations with missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": [1, 2, 3, 4, 5] }'); -- should fail with undefined permutations on missing key SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5 }'); -- should fail with null permutations on missing key (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 1, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 2, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 3, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 4, "key2": null }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "key1": 5, "key2": null }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5620 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": true, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- should work SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "c": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "b": 1, "c": 1 }'); -- repeated documents won't matter because they don't fall in the index (sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); -- reset data set documentdb.enable_large_unique_index_keys to on; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5620 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1, "c": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- should work SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "c": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "b": 1, "c": 1 }'); -- repeated documents will matter because they fall in the index (non-sparse) SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "z": 1 }'); -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1 }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": 1, "b": 1 }'); -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5620 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- insert data in a way that bson_rum_single_path_ops will match truncated and bson_rum_unique_shard_path_ops recheck won't set documentdb.defaultUniqueIndexKeyhashOverride to 1; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- should succeed with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); -- reset log level RESET client_min_messages; -- should fail even with hash collision and truncation SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- reset data set documentdb.enable_large_unique_index_keys to on; set documentdb.indexTermLimitOverride to 60; DELETE FROM documentdb_data.documents_5620; CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "queryuniquecomposite", "index": [ "constraint1" ] }'); \d documentdb_data.documents_5620 -- now test composite not-sparse unique index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "queryuniquecomposite", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "constraint1", "unique": true, "sparse": false, "enableCompositeTerm": true }] }', true); \d documentdb_data.documents_5620 -- insert data in a way that bson_rum_single_path_ops will match truncated but unique shard uuid won't match set documentdb.defaultUniqueIndexKeyhashOverride to 0; -- set log level in order to test hash collision flow SET client_min_messages TO DEBUG1; -- works - SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); -- should succeed without recheck logs SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters2", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters2" }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters3", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters3" }'); SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters4", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters4" }'); -- reset log level RESET client_min_messages; -- should fail SELECT documentdb_api.insert_one('db', 'queryuniquecomposite', '{ "a": "thiskeyisalittlelargerthanthemaximumallowedsizeof60characters", "b": "thiskeyisalotorinotherwordsmuchmuchlargerthanthemaximumallowedsizeof60characters" }'); bson_update_document_tests.sql000066400000000000000000003362561507310017400351540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 210000; SET documentdb.next_collection_id TO 2100; SET documentdb.next_collection_index_id TO 2100; -- replace document scenarios SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 1, "b": 2 } }', '{}'); -- allow updating ID if it's type compatible SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 1.0, "b": 2 } }', '{}'); -- ID mismatch not allowed: error SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "_id": 2.0, "b": 2 } }', '{}'); -- ID not specified - pick the ID from the source document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "b": 2 } }', '{}'); -- upsert case: Creates a new document. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 2.0, "b": 2 } }', '{}'); -- upsert case: no id specified creates a new ID SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{}')).newDocument @? '{ "_id" : 1 }'; -- upsert case: no id specified creates from filter SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": 2.0 }]}'); -- upsert case: no id specified autogenerates when _id filter is not $eq. SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": { "$gt": 2.0 } }]}')).newDocument @? '{ "_id" : 1 }'; SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$and": [ { "a": 1, "_id": { "$lt": 2.0 } }]}')).newDocument @? '{ "_id" : 1 }'; SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1, "_id": 2.0 } ]}')).newDocument @? '{ "_id" : 1 }'; SELECT (documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1 }, { "_id": 3 } ] }')).newDocument @? '{ "_id" : 1 }'; -- would be nice to use the $type function. SELECT bson_get_value((documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1, "_id": 2.0 } ]}')).newDocument, '_id') @= '{ "" : 2.0 }'; SELECT bson_get_value((documentdb_api_internal.bson_update_document('{}', '{ "": { "b": 2 } }', '{"$or": [ { "a": 1 }, { "_id": 3 } ] }')).newDocument, '_id') @!= '{ "" : 3 }'; -- upsert case: _id collision between query and replace; errors out SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 3, "b": 2 } }', '{"$and": [ { "a": 1, "_id": 2.0 }]}'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$setOnInsert": {"_id.b": 1}, "$set":{ "_id": 1 } } }', '{"_id.a": 4}'); -- _id specified twice, failure for update. SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id": 3, "b": 2 } }', '{"$and": [ { "a": 1 }, {"_id": 2.0 }, { "_id": 3.0 }]}'); -- update scenario tests: $set SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$set": { "a": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": "somePath" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 }, "$unset": { "a.b.6": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.1": { "sub": "1234" }, "a.b.5": [1, 2, 3 ] } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$set": { "b.c.d": { "sub": "1234" } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath", "a.b.c": false } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [] }', '{ "": { "$set": { "a.2.b": 1, "a.2.c": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [] }', '{ "": { "$set": { "a.1500001": 1 } } }', '{}'); -- update scenario tests: $inc SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$inc": { "a.b": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": { "c": 3 }} }', '{ "": { "$set": { "a.b.c": "somePath", "a.b.c": 10 }, "$inc": { "a.b.c": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$set": { "b.c": 10 }, "$inc": { "b.c": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 2 }', '{ "": { "$inc": { "b.c": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ 1, 2, 3 ] }', '{ "": { "$inc": { "a.2": 2, "a.6": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong": "-9223372036854775808"} }', '{ "": { "$inc": { "a": -1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":{"$oid":"5d505646cf6d4fe581014ab2"}, "a": {"$numberLong": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDouble": "9223372036854775807"} }', '{ "": { "$inc": { "a": 1 } } }', '{}'); -- update scenario tests: $min SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": true } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": null } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": [1, 2, 3 ] } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.c": [1, 2, 3 ] } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$min": { "a.1": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$min": { "a.1": 3 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": -1 }, "$min": { "a.1": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$min": { "a.b": {"$numberDecimal": "9.99e-100"} } } }', '{}'); -- update scenario tests: $max SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": 3 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": true } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": null } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": [1, 2, 3 ] } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.c": [1, 2, 3 ] } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$max": { "a.1": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$max": { "a.1": 3 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1, 2, 3 ] }', '{ "": { "$set": { "a.1": 3 }, "$max": { "a.1": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$max": { "a.b": {"$numberDecimal": "9.99e100"} } } }', '{}'); -- update scenario tests: $bit SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "and" : 10 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :3}', '{ "": { "$bit": { "expdata" : { "or" : 5 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :1}', '{ "": { "$bit": { "expdata" : { "xor" : 5 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :[13,3,1]}', '{ "": { "$bit": { "expdata.0" : { "and" :10 } } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "and" : 0, "or" : 10 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "or" : 10, "xor" : 10 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1}', '{ "": { "$bit": { "expdata" : { "or" : 10 }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": [ 100, 200 ]}}, "f": 12 }', '{ "": { "$bit": {"key.x.y.0": {"and": 10}, "f": {"and": 10 }}}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": 10 }}, "f": 1}', '{ "": { "$bit": { "key.x.y": { "xor": 10 } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200 ] } }, "f": 1 } ', '{ "": { "$bit": { "key.x.y.0": { "and": 10 } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "x": 1 , "f": 1 } ', '{ "": { "$bit": { "x": { "and": { "$numberLong": "1" } } } } }', '{}'); -- update scenario negative tests: $bit SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :"abc"}', '{ "": { "$bit": { "expdata" : { "or" :10 } } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "or" :10.0 } } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { "ors" :10 } } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :[1,2,3]}', '{ "": { "$bit": { "expdata" : { "or" :10 } } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "expdata" :13}', '{ "": { "$bit": { "expdata" : { }} }}', '{}'); /* TODO: Make the error compatible with mongo: "errmsg" : "Cannot create field 'y' in element {x: [ { y: 10 } ]}" */ SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [ { "y": 10 } ] }}', '{ "": { "$bit": { "key.x.y": { "and": 0 }}}}', '{}'); -- update scenario tests: $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1 }', '{ "": {"$addToSet": { "letters": "a" } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1 }', '{ "": {"$addToSet": { "letters": {"a":"b", "c":"d"} } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1 }', '{ "": {"$addToSet": { "letters": {"$each" : ["a", "b","c"]} } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": {"c":"d", "e":"f", "g":"h" }} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": "c" } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": ["c", "d"] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": "a" } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "letters": ["a", "b"] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a", "b"]}', '{ "": {"$addToSet": { "c":123456} }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": "blue, green, red" }', '{ "": { "$addToSet": { "newColors": "mauve" } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": ["blue, green, red"] }', '{ "": { "$addToSet": { "colors": {} } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "colors": ["blue, green, red", { }] }', '{ "": { "$addToSet": { "colors": {} } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": ["c", "d"]}}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": [ { } ]}}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "numbers": [44,78,80,80,80] }', '{ "": { "$addToSet": { "numbers": 80 }} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each" : ["c","d","c","d","c","e","d","e"] }}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b","e"] }', '{ "": { "$addToSet": { "letters": { "$each" : ["a","b","c","d","e"] }}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "numbers": [1,2,5] }', '{ "": { "$addToSet": { "numbers": { "$each" : [1,2,3,4,5,5,4,3,2,1] }}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200 ] } }, "f": 1 } ', '{ "": { "$addToSet": { "key.x.y": { "$each": [3, 5, 6] } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": { "y": [100 , 200, "a" ] } }, "f": 1 } ', '{ "": { "$addToSet": { "key.x.y": { "$each": [3, 5, 6, 7,8,9,"a","b","a",7,8] } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": { "x": { "y": [ 100,3,6 ]}}, "f": [1,3] }', '{ "": { "$addToSet": {"key.x.y": {"$each": [1, 3, 6, 9,"b","a"]}, "f": {"$each": [1,2,4] }}}}', '{}'); -- Update scenario for some complex items: $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters": { "$each": [1,3,4] } } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters": { "$each": [[1,3,4]] } } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$addToSet": { "letters.0": { "$each": [1,3,4] } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": {"$addToSet": { "letters.0": { "$each": [1,3,4, { "a":2}, {"a":3} ] } }}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": {"$addToSet": { "letters.0": { "$each": [4,{"a":3} ] }, "letters.1.a": { "$each": [4, {"a":2}] } } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$addToSet" : {"a.3": 4 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$addToSet" : {"a.7": 7 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$addToSet" : {"a.0.5": 7 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],3]}', '{ "": { "$addToSet" : {"a.2.5": 7 } } }', '{}'); -- update scenario negative tests: $inc SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": [1,2] }', '{ "": { "$inc": { "a": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": {"x":1} }', '{ "": { "$inc": { "a": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": "b" }', '{ "": { "$inc": { "a": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 5, "a": 5 }', '{ "": { "$inc": { "a": "strings" } } }', '{}'); -- update scenario negative tests: $addToSet SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "colors": "blue, green, red" }', '{ "": { "$addToSet": { "colors": "mauve" } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each": "c"}}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$each" : {} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "letters": ["a","b"] }', '{ "": { "$addToSet": { "letters": { "$ach": ["c"]}}} }', '{}'); -- update scenario tests: $unset SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$unset": { "a.b": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2, "c": 3 }, "d": 1 }', '{ "": { "$unset": { "a.b": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [ 1, 2, 3 ] } }', '{ "": { "$unset": { "a.b.1": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [ 1, 2, 3 ] } }', '{ "": { "$unset": { "a.b.5": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$unset": { "a": 1, "b.c": 1 } } }', '{}'); -- update scenario tests: $rename SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a.b": "c.d" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a.b": "a.c" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": { "a": "c" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1 }', '{ "" : { "$rename": { "b": "c" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "c": 4}', '{ "": { "$rename": { "b": "c.d" } } }', '{}'); -- $rename when rename source node doesn't exist but target node exist, this should be a no-op SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "c": 4}', '{ "": { "$rename": { "b": "a" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": {"b": 1, "d": 2}}', '{ "": { "$rename": { "a.b": "c" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": {"b": 1}}', '{ "": { "$rename": { "a.b": "d" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1}', '{ "": { "$rename": { "b": "a" }, "$set": {"x" : 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a": 1, "x": 1}', '{ "": { "$rename": { "b": "a" }, "$inc": {"x" : 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "b": 1, "x": 1}', '{ "": { "$rename": { "a": "b", "x": "y" } } }', '{}'); -- update scenario tests: $mul SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble" : "2.0"} } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt" : "2" } } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "2" } } }', '{ "": { "$mul": { "a.b": 0 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "9223372036854775807" } } }', '{ "": { "$mul": { "a.b": {"$numberLong": "0"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble" : "0.0"} } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt" : "0" } } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong" : "0" } } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": -10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "+1.0"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": 1.1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.b": -1.1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberInt": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberLong": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberDouble": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$mul": { "a.c": {"$numberDecimal": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "100"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "500"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2147483647"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2147483647"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "-2147483647"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "2147483647"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "-2147483647"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10.0"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2.0"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": NaN } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }','{ "": { "$mul": { "a.b": NaN } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberInt": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberLong": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDecimal": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDouble": "2"} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberDouble": "10"} } }', '{ "": { "$mul": { "a.b": {"$numberDecimal": "2"} } } }', '{}'); -- int64 overflow should coerce to double: $mul SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {"$numberLong": "-9223372036854775807"} } }', '{ "": { "$mul": { "a.b": {"$numberInt": "2"} } } }', '{}'); -- update scenario error tests: $mul SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }','{ "": { "$mul": { "a.b": "Hello" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": "Text" } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1,2,3] } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": {} } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": null } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": true } }','{ "": { "$mul": { "a.b": 2 } } }', '{}'); -- $pullAll operator- positive testcases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "scores": [0,5] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters": [1,3,4] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters.0": [1,3,4] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "score": [0,5] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "a.b": [0,5] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : {} }', '{ "": { "$pullAll": { "scores.top": [0,5] } }}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : {"top": [0,5,10,11]} }', '{ "": { "$pullAll": { "scores.top": [0,5] } }}', '{}'); -- $pullAll operator- negative testcases SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : [ 0, 2, 5, 5, 1, 0 ] }', '{ "": { "$pullAll": { "scores": 0 } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "scores" : "a" }', '{ "": { "$pullAll": { "scores": [0] } }}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "letters" : [ [ 1, { "a" : 2 } ], { "a" : [ 1, 2 ] } ] }', '{ "": { "$pullAll": { "letters.1": [1,3,4] } }}', '{}'); -- rename overwrites. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2, "c": 1 } }', '{ "": { "$rename": { "a.b": "a.c" } } }', '{}'); -- update scenario tests: $setOnInsert (non-upsert) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$setOnInsert": { "a.b": 1, "c": 2, "d": 4 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "double", "v": 42.13}', '{ "": { "$setOnInsert": {"v.foo": 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "double", "v": 42.13}', '{ "": { "$setOnInsert": {"v.-1.foo": 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "array", "v": [42]}', '{ "": { "$setOnInsert": {"v.array.0": 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": "array", "v": [42]}', '{ "": { "$setOnInsert": {"v.0.foo": 1} } }', '{}'); -- upsert: SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "_id": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2 } } }', '{ "_id": 1 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2 } } }', '{ "_id": { "$eq": 1 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "f": 3, "g": 4, "h": 5 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "$and": [ { "_id": { "$eq": 1 }}, {"f": 3 }, { "g": 4 }, { "h": 5 } ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "$or": [ { "_id": { "$eq": 1 }}, {"f": 3 }, { "g": 4 }, { "h": 5 } ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "$or": [ { "g": 4 } ] }'); --upsert querySpec has document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 5, "_id": 1 } } }', '{"a.x.y":10}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.y": 5, "_id": 1 } } }', '{"a.x":{"c":"d"}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.y": 10, "_id": 1 } } }', '{"a": {"x":5}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"b":5}, "_id": 1 } } }', '{"a.c":8}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"x":{"z":10}}, "_id": 1} }}', '{"a":{"x":{"y":5}}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.x.z": 10, "_id": 1 } } }', '{"a":{"x":{"y":5}}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": {"x":{"z":10}}, "_id": 1 } } }', '{"a.x.y":10}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.x.z":10, "_id": 1 } } }', '{"a.x.y":10}'); --upsert querySpec has array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.11":11, "_id": 1 } } }', '{"a":[0,1,2,3,4,5,6,7,8,9,10]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0":0, "a.6":6, "_id": 1 } } }', '{"a":[8,1,2,3]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0":1, "a.1":2, "_id": 1 } } }', '{"a":[{"x":1},{"x":2},{"x":3}]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0.1": 5 , "_id": 1} } }', '{"a":[[1,2],[3,4]]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a.0.x": 10 , "_id": 1} } }', '{"a":[{"x":1},{"x":2}]}'); --upsert $rename cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "b"}, "$set":{ "_id": 1 } } }', '{"b":1}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "b": "a"}, "$set":{ "_id": 1 } } }', '{"b":1}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.b": "a.c"}, "$set":{ "_id": 1 } } }', '{"a.b":10}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.b": "a.c"}, "$set":{ "_id": 1 } } }', '{"a":{"b":10}}'); --upsert querySpec with $gt, $lt, $gte, $lte SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.1":{"$gt": 100},"a.2":{"x":10}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$lt": 100},"a.y":{"x":10}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$gte": 100},"a.y":{"x":10}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id":1} } }', '{"a.x":{"$lte": 100},"a.y":{"x":10}}'); -- upsert querySpec with implicit AND - valid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$gt": 20, "$lt": 40 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2 ], "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2 ], "$ne": 40 } }'); -- upsert querySpec with implicit AND - Invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$all": [ 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$eq": 2, "$all": [ 2 ], "$in" : [ 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2, 1 ], "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": 1, "a": 1} } }', '{"b": { "$all": [ 2, 1 ], "$in": [ 2 ] } }'); -- upsert querySpec with implicit AND on "_id" - valid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$gt": 20, "$lt": 40 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2 ], "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2 ], "$ne": 40 } }'); -- upsert querySpec with implicit AND on "_id" - Invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$all": [ 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$eq": 2, "$all": [ 2 ], "$in" : [ 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2, 1 ], "$in": [ 1, 2 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 1} } }', '{"_id": { "$all": [ 2, 1 ], "$in": [ 2 ] } }'); -- cannot modify id cases SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "_id": 2 } } }', '{ "_id": 1 }'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$set": { "_id": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$inc": { "_id": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1 }', '{ "": { "$max": { "_id": 2 } } }', '{}'); -- Multiple operators: no-op SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {}, "x": 0 }', '{ "": { "$pullAll": { "a.b": [0] }, "$unset": { "d": 1 }, "$mul": { "x": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {}, "x": 0 }', '{ "": { "$pullAll": { "a.b": [0] }, "$unset": { "d": 1 }, "$bit": { "x": { "and": 0 } } } }', '{}'); -- Multiple operators at least one update SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [0,0,0,0,4], "x": 0 }', '{ "": { "$pullAll": { "a": [0] }, "$unset": { "d": 1 }, "$mul": { "x": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [0,0,0,0,4], "x": 10 }', '{ "": { "$pullAll": { "b": [0] }, "$unset": { "a": 1 }, "$mul": { "x": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": [0,0,0,0,0,1,1,1,2]}, "x": 10 }', '{ "": { "$pullAll": { "a.b": [0,1] }, "$set": { "d": 1 }, "$mul": { "x": 1 } } }', '{}'); -- aggregation pipeline: project & unset -- -- simple case for project SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "b": 0 } }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "x": 1, "y": [{ "z": 1, "foo": 1 }] }', '{ "": [ { "$unset": ["x", "y.z"] } ] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": [ { "$unset": "copies" } ] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 2, "title": "Bees Babble", "isbn": "999999999333", "author": { "last": "Bumble", "first": "Bee" }, "copies": [{ "warehouse": "A", "qty": 2 }, { "warehouse": "B", "qty": 5 }] }', '{ "": [ { "$unset": ["isbn", "author.first", "copies.warehouse"] } ] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$project": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); -- -- project with upsert uses fields from query SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$project": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); -- -- project and unset (shoudl just project _id ) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$project": { "b": 1 } }] }', '{}'); -- project and unset silently ignore removing the _id field. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "_id" }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$project": { "_id": 0 } } ] }', '{}'); -- -- simple case for addFields SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$addFields": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$addFields": { "b": 0 } }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 10, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": 30.5, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": false, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$addFields": { "_id": "someString", "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$addFields": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$addFields": { "b": 1 } }] }', '{}'); -- -- simple case for set SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$set": { "a": 1, "c": { "$literal": 2.0 }} }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$set": { "b": 0 } }] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 1, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 10, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": 30.5, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": false, "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 1, "name": "John Doe" }', '{ "": [ { "$set": { "_id": "someString", "name": 1 } }, { "$unset": "name" } ] }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$set": { "b": { "$literal": 2.0 }, "d": 1 } }] }', '{ "d" : 1, "_id": 2.0 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$unset": "b" }, { "$set": { "b": 1 } }] }', '{}'); -- simple case for replaceRoot SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_key" : "$a" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_b_key" : "$a.b" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": { "a_b_key" : "$a.b", "a_key" : "$a", "a_b_arr_key" : "$a.b.arr" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": "$a.b" }}]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceRoot" : { "newRoot": {"$mergeObjects": [ { "dogs": 0, "cats": 0, "birds": 0, "fish": 0 }, "$a.b" ] } }}]}', '{}'); -- simple case for replaceWith SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_key" : "$a" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b" : 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_b_key" : "$a.b" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": { "a_b_key" : "$a.b", "a_key" : "$a", "a_b_arr_key" : "$a.b.arr" }} }]}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "a": { "b": {"arr" : [1, 2, 3, {}], "a" : {"b": 1}, "int" : 1} }, "b": 2 }', '{ "": [ { "$replaceWith" : { "newRoot": "$a.b" }}]}', '{}'); -- update: Error cases: SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": [1, 2, 3 ]} }', '{ "": { "$set": { "a.b.7": 9, "a.b.10": 13 }, "$unset": { "a.b.7": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ { "b": 2 } ] }', '{ "": { "$rename": { "a.0": "b" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ { "b": 2 } ] }', '{ "": { "$rename": { "a.0.b": "a.1.c" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "a": 2, "h": 6 } } }', '{ "_id": { "$eq": 1 }, "c": 3, "$and": [ { "c": 4 } ] }'); SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"d.e"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"d.e"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"d.e":"d.c"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"a": [1], "b": {"c": [2]}, "d": [{"e": 3}], "f": 4}', '{ "": { "$rename" :{"f":"a.0"}} }', '{}'); -- $push top level input validation with all modifiers SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberInt" : "2"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberLong" : "2"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDouble" : "2.0"}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b" : [1,2,3]}}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": false}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": NaN}', '{ "": { "$push" :{"a":"0"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": "6" }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": 6 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": {"a": 6} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": 1.1 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": "2" }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": true }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$slice": [1,2,3] }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 0 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": -2 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 2 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": 1.1 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"a.b": -2} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"a.": -2} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {".b.c": -2} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {"": 1} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$sort": {} }}} }', '{}'); -- TODO: Make the error compatible with mongo: "errmsg" : "Cannot create field 'y' in element {x: [ { y: 1 } ]}" SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{"key.x.y": 1 }}}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{ "key.x": { "$each": [], "badplugin": 1} }}}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": -0.1 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": 1.1 }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": "start" }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": false }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": {"a.b": -2} }}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$each": [], "$position": [1,2,3] }}} }', '{}'); -- $push valid cases when modifiers are not persent SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" : {"a": 6} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" : {"a": {"another": 6}} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": false} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": [5,6,7]} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": 1.21} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": 1, "scores": [44,78,38,80], "a": {"scores": [1,2]}}', '{ "": { "$push" : {"scores": 1, "a.scores": 10} } }', '{}'); -- $push with $each modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": { "$each" : [1,2,"3", {"four": 4}] }} } }', '{}'); -- $push with array indices as dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a.3": 4 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a.7": 7 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$push" : {"a.0.5": 7 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3]]}', '{ "": { "$push" : {"a.0.5": { "$each": [10,9,8], "$sort" : 1 } } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],3]}', '{ "": { "$push" : {"a.2.5": 7 } } }', '{}'); -- $push with $each & $slice modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": 5 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": -6 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": 20 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [], "$slice": -11 }} } }', '{}'); -- $push with $each & $position modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": 20 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": -20 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": 6 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$push" : {"a": { "$each" : [-1, 0], "$position": -8 }} } }', '{}'); -- $push with $sort modifier in non-dotted path SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3]}', '{ "": { "$push" : {"a": { "$each" : [1,2,"3", {"four": 4}, false, [3,1,2]], "$sort": -1 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"wk": 1, "scores": 85}, {"wk": 3, "scores": 30}, {"wk": 2, "scores": 75}, {"wk": 5, "scores": 99}]}', '{ "": { "$push" : {"a": { "$each" : [{"wk": 2, "scores": 70}], "$sort": 1 }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"wk": 1, "scores": 85}, {"wk": 3, "scores": 30}, {"wk": 2, "scores": 75}, {"wk": 5, "scores": 99}]}', '{ "": { "$push" : {"a": { "$each" : [{"wk": 2, "scores": 70}], "$sort": { "scores" : -1 } }} } }', '{}'); -- Sort spec dotted path contains intermediate array, sort spec path not found so same sort order SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.c" : 1 } }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.c" : -1 } }} } }', '{}'); -- Sort spec dotted path doesn't exist, same sort order SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "c" : -1 } }} } }', '{}'); -- Sort spec with array and valid index element SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": [{"c": 5}]},{"b": [{"c": 10}]},{"b": [{"c": 3}]},{"b": [{"c": 2}]}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "b.0" : -1 } }} } }', '{}'); -- Multiple Sort spec with existing or non exisiting paths SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1, "b": -1 } }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1, "b": -1, "c": 1 } }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"key":1,"a":[{"a":5,"b":10},{"a":2,"b":2},{"a":8,"b":3},{"a":4,"b":1},{"a":2,"b":5},{"a":2,"b":1}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "d" : 1, "e": -1, "f": 1 } }} } }', '{}'); -- Sort spec with only some elements having sort path, other elements treat missing path as NULL SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": 1}, {"a": 10, "b": 0}, {"b": 5}, {"b": 3}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : 1 } }} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"key": 1,"a": [{"b": 1}, {"a": 10, "b": 0}, {"b": 5}, {"b": 3}]}', '{ "": { "$push" : {"a": { "$each" : [], "$sort": { "a" : -1 } }} } }', '{}'); -- $push with combinations of other modifiers e.g $slice, $sort SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [{"a": 1, "b": 10}, {"a": 2, "b": 8}, {"a": 3, "b": 5}, {"a": 4, "b": 6}]}', '{ "": { "$push" : {"arr": { "$each" : [{"a": 5, "b": 8}, {"a": 6, "b": 7}, {"a": 7, "b": 6}], "$sort": { "b" : -1 }, "$slice": 3 }} } }', '{}'); -- $push & modifiers with dotted paths SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": {"c": [1,2,3,4,5,6,7,8,9,10]}}}', '{"" : {"$push": {"a.b.c": 11}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": {"c": [1,2,3,4,5,6,7,8,9,10]}}}', '{"" : {"$push": {"a.b.c": {"$each": [11,12], "$slice": -6, "$sort": -1, "$position": 4}}} }', '{}'); -- $push with absent fields SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.c": {"x": [{"z": 1}]}}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.c": {"$each": [5,4,3,2,1], "$slice": 3, "$sort": 1}}} }', '{}'); -- $push with key having dots SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "scores": {"a": {"b": [1]}}, "key": 1}', '{"" : {"$push": {"scores.a.b": {"x": [{"z.a": 1}]}}} }', '{}'); -- $push with NaN and Infinity values SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "100"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "2"}, {"$numberDecimal": "NaN"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : 1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "Infinity"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "332"}, {"$numberDecimal": "NaN"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : -1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "NaN"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "Infinity"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : 1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"$numberDecimal": "NaN"}, {"$numberDouble": "NaN"}, {"$numberDecimal": "Infinity"}, {"$numberDecimal": "23"}]}', '{ "": { "$push" : {"a": { "$each": [], "$sort" : -1 } } } }', '{}'); -- $push without $each but with other modifiers works on mongo5.0, $ is now supported in key names. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "key": {"x": [{"y": [1]}, {"y": [2]}]}}', '{ "": { "$push" :{ "key.x": { "$eachh": [], "$position": 1, "$sort" : 1} }}}', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$push" :{"a": { "$position": 5, "$slice": 3, "$sort": -1 }}} }', '{}'); -- test conflicting update operator paths SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b.c": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$inc": {"a.b.c.d.e": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c.d.e": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c": 1} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b": 1} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": 1} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.k.d": 1} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d.e": 1} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e": 1 } } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e.f": 1 } } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "k.f": 1 } } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "f.k": 1 } } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a": {"b.c.d": { "e.f": {"g": 1} } } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c.d": { "e": 1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b.c": { "d.e": 1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b": {"c": { "d.e.f": "1"} } }, "$unset": {"a.b": { "c.d.e": 1 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$unset": {"a.b": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$unset": {"a.b.c.d.e.f": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"data": "data"}', '{ "": { "$set": { "a.b.c.d.e": 1 }, "$inc": {"a.b": 1 } } }', '{}'); -- update scenario tests: $currentDate -- -- Function that extracts date / timestamp value of a given key in a json obj, and returns the equivalent epoch in ms CREATE OR REPLACE FUNCTION get_epochms_from_key(obj json, qkey text, is_date bool) RETURNS bigint AS $$ DECLARE k text; qarr text[]; epoch_seconds bigint; nanoseconds_in_second bigint; epoch_milliseconds bigint; tmp bool; BEGIN SELECT string_to_array(qkey, '.') into qarr; -- convert the nested keys in keys array (e.g. "a.b.c" to [a,b,c] ) FOREACH k IN ARRAY qarr LOOP IF obj->k IS NULL THEN RETURN 0; END IF; SELECT obj->k into obj; END LOOP; IF is_date THEN IF (obj->'$date' IS NULL) OR (obj->'$date'->'$numberLong' IS NULL) THEN RETURN 0; END IF; SELECT obj->'$date'->>'$numberLong' into epoch_milliseconds; ELSE IF (obj->'$timestamp' IS NULL) OR (obj ->'$timestamp'->'t' IS NULL) OR (obj->'$timestamp'->'i' IS NULL) THEN RETURN 0; END IF; SELECT obj->'$timestamp'->>'t' into epoch_seconds; SELECT obj->'$timestamp'->>'i' into nanoseconds_in_second; epoch_milliseconds := (epoch_seconds * 1000) + ROUND(nanoseconds_in_second::float8 / (1000 * 1000)); END IF; RETURN epoch_milliseconds; END $$ LANGUAGE plpgsql; -- -- Function to test that on updating a doc with $currentDate, the date/timestamp value lies between the timestamp values of just before & after calling the update api CREATE OR REPLACE FUNCTION test_update_currentDate(doc bson, updateSpec bson, querySpec bson, qDates text[] DEFAULT '{}'::text[], qTimestamps text[] DEFAULT '{}'::text[]) RETURNS text AS $$ DECLARE obj json; bgn_epoch numeric; end_epoch numeric; qKey text; epoch_msec bigint; bgn_epoch_msec bigint; end_epoch_msec bigint; BEGIN SELECT extract(epoch from clock_timestamp()) into bgn_epoch; -- get time just before the $currentDate execution. (e.g 1709721220.205436) SELECT newDocument FROM documentdb_api_internal.bson_update_document(doc, updateSpec, querySpec) into obj; SELECT extract(epoch from clock_timestamp()) into end_epoch; -- get time just after the $currentDate execution. -- convert the epoch to milliseconds (e.g. 1709721220.205436 -> 1709721220205) -- Also adjust begin and end epochs by 1 ms to eliminate any rounding error and reduce flakyness. bgn_epoch_msec := FLOOR(bgn_epoch * 1000) - 1; end_epoch_msec := CEIL(end_epoch * 1000) + 1; IF array_length(qDates, 1) != 0 THEN FOREACH qKey IN ARRAY qDates LOOP SELECT get_epochms_from_key(obj, qKey, true) into epoch_msec; IF epoch_msec NOT BETWEEN bgn_epoch_msec AND end_epoch_msec THEN RETURN 'TEST FAILED : Updated date "' || qkey || '" : ' || epoch_msec || ' should be between ' || bgn_epoch_msec || ' and ' || end_epoch_msec; END IF; END LOOP; END IF; IF array_length(qTimestamps, 1) != 0 THEN FOREACH qKey IN ARRAY qTimestamps LOOP SELECT get_epochms_from_key(obj, qKey, false) into epoch_msec; IF epoch_msec NOT BETWEEN bgn_epoch_msec AND end_epoch_msec THEN RETURN 'TEST FAILED : Updated timestamp "' || qkey || '" : ' || epoch_msec || ' should be between ' || bgn_epoch_msec || ' and ' || end_epoch_msec; END IF; END LOOP; END IF; RETURN 'TEST PASSED'; END; $$ LANGUAGE plpgsql; -- -- tests to update existing field to current timestamp using { "$type" : "timestamp" } SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"} } } }', '{}', ARRAY[]::text[], ARRAY['a']::text[]); -- -- tests to update existing field to current date using { true } SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": true} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); -- -- tests to update existing field to current date using { false } SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": false} } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); -- -- tests to update existing field to current date using { "$$type" : "date" } -- -- Note: Due to a bug in libbson, parsing of { "$type" : "date" } fails. So temporarily the $currentDate impl also supports {"$$type" : "date" } -- -- Once the bug is fixed, these tests need to be updated from "$$type" to "$type" SELECT test_update_currentDate('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); SELECT test_update_currentDate('{"_id": 1, "a": 2 }', '{ "": { "$currentDate": { "a": { "$$type" : "date"} } } } ', '{}', ARRAY['a']::text[], ARRAY[]::text[]); -- -- tests to update existing field to timestamp, and add new fields with current date / timestamp SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : { "$type" : "timestamp"} } } } ', '{}', ARRAY[]::text[], ARRAY['a','b.c']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : { "$$type" : "date"} } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : true } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); SELECT test_update_currentDate('{"_id": 1, "a": "Hello" }', '{ "": { "$currentDate": { "a": { "$type" : "timestamp"}, "b.c" : false } } } ', '{}', ARRAY['b.c']::text[], ARRAY['a']::text[]); -- -- these tests should give error messages SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberInt" : "1"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberLong" : "1"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": {"$numberDouble" : "1.0"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": "Hello" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": NaN } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$type" : "Hello" } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : true } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$timestamp": { "t": 1234567890, "i": 1 }}}', '{ "": { "$currentDate": { "a": { "$$type" : 2 } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberInt" : "1"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberLong" : "1"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": {"$numberDouble" : "1.0"} } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": "Hello" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": NaN } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "Hello" } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : true } } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$$type" : 2 } } } }', '{}'); -- -- Note : This test intenionally provides { "$type" : "date" } instead of { "$$type" : "date" } -- -- The API call returns Error due to a Bug in libbson library that fails to parse { "$type" : "date" } -- -- If this test starts failing (i.e. api call does't return error), it may mean that the libbson bug has been fixed. -- -- In that case $currentDate implementation needs a fix as well (i.e. remove support for "$$type" since "$type" will work OK) SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$date": { "$numberLong" : "1234567890000" }}}', '{ "": { "$currentDate": { "a": { "$type" : "date" } } } }', '{}'); -- --Empty UpdateSpec check SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "": 11} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.": 11} } }', '{}'); -- update scenario tests: $pop -- -- $pop from begin of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": -1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1]}', '{ "": { "$pop" :{"a": -1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" :{"a": -1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [1,2,3,4,5] }} }', '{ "": { "$pop" :{"a.b.c": -1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": -1, "b": -1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": -1, "b": -1, "c" : -1}} }', '{}'); -- -- $pop from end of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [5]}', '{ "": { "$pop" :{"a": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" :{"a": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [1,2,3,4,5] }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": 1, "b": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9] }', '{ "": { "$pop" :{"a": 1, "b": 1, "c" : 1}} }', '{}'); -- -- $pop from begin and end of array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9]}', '{ "": { "$pop" :{"a": -1, "b": 1}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5], "b" : [6,7,8,9]}', '{ "": { "$pop" :{"z": 1, "a": -1, "b": 1}} }', '{}'); -- For below test, the spec parsing func (ParseDotPathAndGetTreeNode) throws error, but mongoDB 5.0 doesn't. TODO : Fix ParseDotPathAndGetTreeNode -- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" :{"a": -1, "a": 1}} }', '{}'); -- -- Empty $pop document. Should not pop anything SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {}} }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": []}', '{ "": { "$pop" : {}} }', '{}'); -- -- Error Cases : $pop on Non-Array Fields SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberInt" : "2"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberLong" : "2"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : {"$numberDouble" : "2.0"} }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : false }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : NaN }} }', '{ "": { "$pop" :{"a.b.c": 1}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1, "a.b.d": -1 }} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a" : {"b" : { "c": 1 , "d": -1} }} } }', '{}'); -- -- Error Cases : $pop's key's value is neither -1 nor 1 SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": "Hello"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": true}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": NaN}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": []}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {}}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {"$numberInt" : "2"}}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"a": {"$numberDouble" : "-1.5"}}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8]}} }', '{ "": { "$pop" : {"a.b.c": 2 }} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 25, "a.b.d": -1 }} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b" : { "c" : [5,6,7,8], "d" : "Hello" }} }', '{ "": { "$pop" :{"a.b.c": 1, "a.b.d": -25 }} }', '{}'); -- -- Error Cases : $pop is not a document SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : []} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : [{"a" : 1}]} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : "Hello"} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : false} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : NaN} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberInt" : "1"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberLong" : "-1"}} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pop" : {"$numberDouble" : "2.5"}} }', '{}'); -- --Update the Field with Periods (.) and Dollar Signs ($) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "$b": 2 } }', '{ "": { "$inc": { "a.$b": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "b": 2 } }', '{ "": { "$inc": { "$a.c": 2 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "$b": { "c" : 2 } } }', '{ "": { "$inc": { "$a.$b.c": 1 } } }', '{}'); -- --Negative scenarios for field names with Dollar Signs ($) SELECT documentdb_api_internal.bson_update_document('{"_id" : 1}', '{ "": { "$set": { "$a": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "_id" : 1, "$set": { "$a": 2 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id" : 1, "a" : 1 }', '{ "": { "_id" : 1, "$b" : 2} }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$a": { "$b": { "c" : 2 } } }', '{ "": { "$set": { "$a": { "$b" : { "$d": 1 } } } } } ', '{}'); -- more scenarios for update field names with $ signs -- $ paths not allowed when it's not an upsert SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": "1" }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$secret": { "agent": 1 } }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "$secret": { "agent": { "y": 1 } } }', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{ "_id": 5 }', '{ "": { "$set": { "$inc": 5 } } }', '{}'); -- allowed on upsert. SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1, "_id": 6 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{"_id": 2 }'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$secret.agent.x": 1 } } }', '{"a": 3, "_id": 4 }'); SELECT documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "$inc": 5 } } }', '{"_id": 5 }'); -- $pull invalid cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": "text"}', '{ "": { "$pull": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{ "": { "$pull": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": true}', '{ "": { "$pull": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"$numberDecimal": "1.23"}}', '{ "": { "$pull": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": {"b": 2}}', '{ "": { "$pull": { "a": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a.0": {"b": 2, "c":2} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": [1], "c": [1]}, {"b": [2], "c": [2]}, {"b": [3], "c": [3]}]}', '{ "": { "$pull": { "a.b": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$lte": 2, "b": 2} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"b": 2, "$lte": 2} } } }', '{}'); -- valid $pull without expressions in arrays and array of arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": 3 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a": {"b": 2, "c":2} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2,3,4,5], [6,7,8,9,10]]}', '{ "": { "$pull": { "a.0": 4 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}], [{"b": 4, "c": 4}, {"b": 5, "c": 5}, {"b": 6, "c": 6}]]}', '{ "": { "$pull": { "a.1": {"b": 4, "c": 4} } } }', '{}'); -- valid $pull with expressions in arrays and array of arrays SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$gte": 2, "$lte": 5} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": {"$gte": 5} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$gte": 5, "$ne": 8} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$in": [3,6,9]} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": {"$nin": [3,6,9]} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5,6,7,8,9,10]}', '{ "": { "$pull": { "a": { "$not": {"$gt": 5 } } } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":1,"fruits":[ "apples", "pears", "oranges", "grapes", "bananas" ],"vegetables":[ "carrots", "celery", "squash", "carrots" ]}', '{"":{"$pull":{"fruits":{"$in":["apples","oranges"]},"vegetables":"carrots"}}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id":2,"fruits":[ "plums", "kiwis", "oranges", "bananas", "apples" ],"vegetables":[ "broccoli", "zucchini", "carrots", "onions" ]}', '{"":{"$pull":{"fruits":{"$in":["apples","oranges"]},"vegetables":"carrots"}}}', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "item": "A", "score": 5 }, { "item": "B", "score": 8 }, { "item": "C", "score": 8 }, { "item": "B", "score": 4 }]}', '{ "": { "$pull": { "a": { "score": 8 , "item": "B" } } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "results": [{ "item": "A", "score": 5, "answers": [ { "q": 1, "a": 4 }, { "q": 2, "a": 6 } ] }, { "item": "B", "score": 8, "answers": [ { "q": 1, "a": 8 }, { "q": 2, "a": 9 } ]}, { "item": "C", "score": 8, "answers": [ { "q": 1, "a": 8 }, { "q": 2, "a": 7 } ] }, { "item": "B", "score": 4, "answers": [ { "q": 1, "a": 0 }, { "q": 2, "a": 8 } ] }]}', '{ "": { "$pull": { "results": { "answers": {"$elemMatch": { "q": 2, "a": { "$gte": 8 } } } } } } }', '{}'); -- First level of nested array is supported in native mongo only when pull spec value is expression SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": {"$gte": 5} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[{"a": 1, "b" : 1}], [{"a": 2, "b": 2}], [{"a": 3, "b": 3}]]}', '{ "": { "$pull": { "arr": {"$eq": {"a": 1, "b": 1} } } } }', '{}'); -- First level of nested array is not recursed if $pull spec value is plain value SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]}', '{ "": { "$pull": { "a": 5 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "arr": [[{"a": 1, "b" : 1}], [{"a": 2, "b": 2}], [{"a": 3, "b": 3}]]}', '{ "": { "$pull": { "arr": {"a": 1, "b": 1} } } }', '{}'); -- Second and more are not supported SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[[1,2]], [[3,4]]]}', '{ "": { "$pull": { "a": {"$gte": 3} } } }', '{}'); -- $pull no ops for no match SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}]}', '{ "": { "$pull": { "a": {"b": 2, "c":3} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "c": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4,5]}', '{ "": { "$pull": { "a": {"$gt": 5} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "item": "A", "score": 5 }, { "item": "B", "score": 8 }, { "item": "C", "score": 8 }, { "item": "B", "score": 4 }]}', '{ "": { "$pull": { "a": { "$elemMatch": { "score": 8 , "item": "B" } } } } }', '{}'); -- validate _id SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$set": { "_id": {"$b": 2, "c":3} } } }', '{}'); -- replaceRoot/replaceWith with dotted paths. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": [ { "$replaceWith": { "_id": 1, "a.b.c": 3 } } ] }', '{}'); --upsert when querySpec has $all SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }', '{"_id": 10, "x": { "$all" : {}}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }', '{"_id": 11, "x": { "$all" : [1]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":12}}}','{"x": { "$all" : [2]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":13}}}' ,'{"x": { "$all" : [[3]]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":14}}}','{"x": { "$all" : [{"x":11}]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":15}}}','{"_id": { "$all" : [15]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":16}}}','{"_id": { "$all" : [{"x": 16}]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":17}}}','{"_id": { "$all" : [[13]]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":18}}}','{"x": { "$all" : [1,2,3]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":19}}}','{"_id": { "$all" : [15,16,17]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {}}','{"_id": { "$all" : [[15]]}}'); --upsert when querySpec has $in SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": 21, "x": { "$in" : {}}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": 22, "x": { "$in" : [1]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":23}}}','{"x": { "$in" : [3423]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":24}}}','{"x": { "$in" : [[2]]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":25}}}','{"x": { "$in" : [{"y":2}]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":26}}}','{"x": { "$in" : [10,20,30]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":27}}}','{"_id": { "$in" : [25]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":28}}}','{"_id": { "$in" : [{"y":26}]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"x":29}}}','{"_id": { "$in" : [[26]]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":30}}}','{"_id": { "$in" : [27]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"_id":31}}}','{"_id": { "$in" : [27,28,29]}}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"_id": { "$in" : [[27]]}}'); SELECT bson_dollar_project(newDocument, '{ "_id": 0 }') as newDocument from documentdb_api_internal.bson_update_document('{}', '{ "": {"$set":{"y":31}}}','{"_id": { "$in" : [27,28,29]}}'); -- $nor operator in query spec SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"_id": 1, "b": 3} }', '{"$nor": [ { "_id": { "$eq" : 2}}]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"_id": 1, "b": 3} }', '{"$nor": [ { "a": { "$eq" : 2}}]}'); --miscellaneous tests with multiple fields in queySpec SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {} }','{"$and": [{"_id": 1}, {"_id": 1}]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"_id.x": 1 , "_id.y": 2}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"$and": [{"x": 1}, {"x": 1}]}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"x": 1, "x.x": 1}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": {"$set": {"a": 1}} }','{"x.x": 1, "x": 1}'); -- show that we never crash due to passing one of the arguments as NULL SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', null); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', null, '{"b": 1}'); SELECT documentdb_api_internal.bson_update_document(null, '{"": {"a": 1}}', '{"c": 1}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', '{"b": 1}', null, true); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1}', '{"": {"a": 2}}', '{"b": 1}', '{"a": 1}', true); -- $rename Negative/No-Op cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a.": "b"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "$.": "b"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "$[].0": "b"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "b."} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "$"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{}', '{ "": { "$rename": { "a": "$[]"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "a": "f.g"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "f.g": "a"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": 1, "f": 1}', '{ "": { "$rename": { "x": "f.g"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a" : 1, "f" : 1, "b" : { "c" : { "d" : 1 } }}', '{ "": { "$rename": { "b.c.d.f": "t.k"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"key": 1,"key2": 2,"f": {"g": 1, "h": 1},"j": 1,"k": 1}', '{ "": { "$rename": { "f.g": "k.m","f.h":"j.m"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"key": 1,"key2": 2,"f": {"g": 1, "h": 1},"j": {},"k": 1}', '{ "": { "$rename": { "f.g": "k.m","f.h":"j.m"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$rename": { "f.g": "a"}, "$setOnInsert": { "b": "f.g" } } }', '{}'); -- $rename with $setOnInsert SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"a": 1, "f": 1}', '{ "": { "$setOnInsert": { "f.g": "a" }, "$rename": { "f.g": "a"} } }', '{}'); --$rename working complex cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "key": 1,"key2": 2,"f": {"g": 1, "h": 1},"h":1}', '{ "": { "$rename": { "key": "f.g"} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 2, "key": 2,"x": {"y": 1, "z": 2}}', '{ "": { "$rename": { "key": "newName","x.y":"z","x.z":"k"} } }', '{}'); bson_update_positional_all.sql000066400000000000000000000320251507310017400351100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2300000; SET documentdb.next_collection_id TO 23000; SET documentdb.next_collection_index_id TO 23000; --Test Set1 : array of document Tests SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, { "c" : 5, "d" : 6 } ], "H" : { "c" : 10 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"c":5}] }', '{ "": { "$set": { "a.$[].c": 30 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "y": [1,2,3,4] } ] }}','{ "": { "$inc": { "a.b.0.x.$[]": 100 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "x": [1,2,3,4] } ] }}','{ "": { "$inc": { "a.b.$[].x.0": 100 } } }', '{}'); -- Test Set2 : Elements in updatespec is not present in Document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, { "d" : 6 } ], "H" : { "c" : 10 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "d" : 2 }, { "d" : 6 } ] }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "y": [1,2,3,4] } ] }}','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); --Test Set3 : $set Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$[]": 30 } } }', '{}'); --Test Set4 : $inc Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 30 } } }', '{}'); --Test Set5 : $min Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$[]": 3 } } }', '{}'); --Test Set6 : $max Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$max": { "a.$[]": 3 } } }', '{}'); --Test Set7 : $mul Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[]": 3 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1.0,2.2,3.2,4.3] }', '{ "": { "$mul": { "a.$[]": 3 } } }', '{}'); --Test Set8 : $bit Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [14,6] }', '{ "": { "$bit": { "a.$[]": {"or" : 1 } } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [14,6] }', '{ "": { "$bit": { "a.$[]": {"and" : 1 } } } }', '{}'); --Test Set9 : $unset Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$unset": { "a.$[]": 1 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4],[5,6]] }', '{ "": { "$unset": { "a.$[].$[]": 10} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"c":5}] }', '{ "": { "$unset": { "a.$[].c": 1 } } }', '{}'); --Test Set10 $addToSet SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[14],[6]] }', '{ "": { "$addToSet": { "a.$[]": "new" } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "x": {"myArray": [{"a": [[1],[1]],"b": [[1],[2]]},{"a": [[1],[2]],"b": [[1],[2]]}]} }', '{ "": { "$addToSet": {"x.myArray.$[].a.$[]": "new","x.myArray.$[].b.$[]": "new2" } } }', '{}'); --Test Set11 $push SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1],[2],[3],[4]] }', '{ "": { "$push": { "a.$[]": 30 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[40,8,5],[42,7,15],[55,42,0],[41,0]] }', '{ "": { "$push": { "a.$[]": { "$sort":-1, "$each" : [10,20,30], "$position":2, "$slice":2} } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[]abc.c": 11 } } }', '{}'); --Test Set12 : Update path not exist or cannot be created SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ 1 , 2 ], "H" : { "c" : 11 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 }, 2 ], "H" : { "c" : 11 } }},','{ "": { "$set": { "a.b.$[].c": 11 } } }', '{}'); --Test Set 13 : Positional all operator on non array element SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[].c": 11 } } }', '{}'); --Test Set 14 : Try with $ and $[] and Typo with $[] SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$.c": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "c" : 1, "d" : 2 } ] }},','{ "": { "$set": { "a.$[element].c": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1.0,2.2,3.2,4.3] }', '{ "": { "$mul": { "a.$[x]": 3 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[]abc": 3 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$[]":10} } }', '{}'); --Test Set 15 : Complex One SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4],[5,6]] }', '{ "": { "$inc": { "a.$[].$[]": 10 } } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1,"a" : { "b" : [ { "x":[1,2,3,4] }, { "x": [100,2,3,4] } ] }}','{ "": { "$inc": { "a.b.$[].x.0": 100 } } }', '{}'); --Test set 16: Large field SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":5},{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":6}] }', '{ "": { "$set": { "a.$[].aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 10 } } }', '{}'); --Test set 17: Multiple Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4], "b":10 }', '{ "": { "$set": { "a.$[]": 30 }, "$inc": {"b" : 1} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4], "b":{"x":10} }', '{ "": { "$set": { "b.x": 30 }, "$inc": {"a.$[]" : 1} } }', '{}'); --Test Set 18 : Path Conflicts SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].$[]": 10, "a.0": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0": 10, "a.$[].$[]": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0.1": 10, "a.$[].$[]": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].$[]": 11, "a.1.0": 10 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.b.$[]": 10, "a.b.0": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 11, "a.0": 10 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.0": 11, "a.$[]": 10 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.0": 11 }, "$set":{"a.$[]": 11} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[]": 11 }, "$set":{"a.0": 11} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{ "x": 10 }, {"x": 11}] }', '{ "": { "$inc": { "a.$[].x": 11 }, "$set":{"a.0": 11} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x":10},{"y":11}] }', '{ "": { "$set": { "a.$[]": 30 }, "$inc": {"a.1.y" : 1} } }', '{}'); --Test Set 19 : Multiple Spec One Operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.$[].0": 30 , "a.$[].1" : 10} } }', '{}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"b":1,"c":2,"x":{"y":3}}] }', '{ "": { "$inc": { "a.$[].b": 10 , "a.$[].c" : 20, "a.$[].x.y":30} } }', '{}'); ---Test Set 20 : $ Operator--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2],[3,4]] }', '{ "": { "$inc": { "a.0.$": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x": 5},{"y":10}] }', '{ "": { "$inc": { "a.$.c": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$":10} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"x":5},{"y":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$.y": 12 } } }', '{}'); ---Test Set 21 : $[] Operator--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$set": { "a.$[ele]": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$mul": { "a.$[ele]": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$inc": { "a.$[ele]": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [1,2,3,4] }', '{ "": { "$min": { "a.$[ele]": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [{"x": 5,"c" :11},{"y":10},{"x":10}] }', '{ "": { "$inc": { "a.$[ele].c": 30 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"$[]":10} } }', '{}'); ---Test Set 22 : Multiple positional operator on same level--- SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"a":[1,2,3],"b":[4,5,6]}] }', '{ "": { "$inc": {"a.$[].a.$[]": 10,"a.$[].b.$[x]": 11 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"x":5},{"y":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$[x].y": 12 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a":[{"y":5},{"x":10}] }', '{ "": { "$inc": {"a.$[].x": 10,"a.$[x].y": 12 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [[1,2,3],[4,5,6]] }', '{ "": { "$inc": { "a.$.$[]": 10} } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": [ {"a":[ {"x":1},{"y":2} ] ,"b": [ {"x":5},{"y":10} ] } ] }', '{ "": { "$inc": { "a.$[].b.$[].x": 10, "a.$[].b.$[x].y":12} } }', '{}'); -- Test Set 23: Rename with positional should not work. SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": {"a.$[]": "b.$[]" } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$rename": {"a.0": "b.$[]" } } }', '{}'); -- Test Set 24: $positional with adding new fields SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"a.c.$[]": 1 } } }', '{}'); SELECT documentdb_api_internal.bson_update_document('{"_id": 1, "a": { "b": 2 } }', '{ "": { "$set": {"c.$[]": 1 } } }', '{}'); bson_update_positional_arrayFilters.sql000066400000000000000000000236451507310017400370170ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 220000; SET documentdb.next_collection_id TO 2200; SET documentdb.next_collection_index_id TO 2200; -- arrayFilters with aggregation pipeline SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', '{ "": []}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', NULL); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": [ { "$addFields": { "fieldA.fieldB": 10 } }]}', '{}', '{ "": [ { "filterX": 30 }]}'); -- arrayFilters ignored on replace SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "fieldC": 40 } }', '{}', '{ "": [ { "filterX": 50 }]}'); -- arrayFilters with update fails - missing array filter SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 60 }}}', '{}', '{ "": [] }'); -- arrayFilters with update fails - invalid array filters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ 2 ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ {} ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "": 3} ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "itemA": 4, "itemB.itemC": 5 } ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "arrayA.$[itemA]": 70 }}}', '{}', '{ "": [ { "itemA": 6 }, { "itemA": 7 } ] }'); -- simple array update on equality SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1, "numbers": [ 100, 200 ] }','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{}', '{ "": [{ "numElem": 100 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{}','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{"_id": 1, "numbers": [ 100, 200 ] }', '{ "": [{ "numElem": 100 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{"_id": 1 }','{ "": { "$set": { "numbers.$[numElem]": 300 }}}', '{}', '{ "": [{ "numElem": 100 }] }'); -- updates on $gte condition SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "scores" : [ 150, 120, 110 ], "age": 15 }','{ "": { "$set": { "scores.$[scoreElem]": 200 }}}', '{}', '{ "": [{ "scoreElem": { "$gte": 200 } }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "scores" : [ 150, 210, 200, 180, 202 ], "age": 16 }','{ "": { "$set": { "scores.$[scoreElem]": 200 }}}', '{}', '{ "": [{ "scoreElem": { "$gte": 200 } }] }'); -- nested arrayFilters. SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75}, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$set": { "metrics.$[metricElem].avg": 100 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 } }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75 }, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$inc": { "metrics.$[metricElem].dev": -50 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 }, "metricElem.dev": { "$gte": 80 } }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 3, "metrics" : [ { "value": 58, "max": 136, "avg": 66, "dev": 88}, { "value": 96, "max": 176, "avg": 99, "dev": 75 }, { "value": 68, "max":168, "avg": 86, "dev": 83 } ] }', '{ "": { "$inc": { "metrics.$[metricElem].dev": -50 }}}', '{}', '{ "": [{ "metricElem.value": { "$gte": 60 }, "metricElem.dev": { "$gte": 75 } }] }'); -- negation operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "degreesList" : [ { "level": "PhD", "age": 28}, { "level": "Bachelor", "age": 22} ] }', '{ "": { "$set" : { "degreesList.$[deg].gradYear" : 2020 }} }', '{}', '{ "": [{ "deg.level": { "$ne": "Bachelor" } }] }'); -- multiple positional operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[typeElem].answers.$[ansScore]": 190 }} }', '{}', '{ "": [{ "typeElem.type": "quiz" }, { "ansScore": { "$gte": 18 } }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[].answers.$[ansScore]": 190 }} }', '{}', '{ "": [{ "ansScore": { "$gte": 18 } }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "results" : [ { "type": "quiz", "answers": [ 20, 18, 15 ] }, { "type": "quiz", "answers": [ 18, 19, 16 ] }, { "type": "hw", "answers": [ 15, 14, 13 ] }, { "type": "exam", "answers": [ 35, 20, 33, 10 ] }] }', '{ "": { "$inc": { "results.$[typeElem].answers.$[]": 190 }} }', '{}', '{ "": [{ "typeElem.type": "quiz" }] }'); -- arrayFilters for all Update operators should recurse if for a single level nested array -- array update operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$addToSet": { "matrix.$[row]": 2 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pop": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pull": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 2 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [1, 2] ] }', '{ "": { "$pull": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 2 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0, 1], [2, 3] ] }', '{ "": { "$push": { "matrix.$[row]": 1 }} }', '{}', '{ "": [{ "row": 1 }] }'); -- field update operators, should be able to match but apply update based on the type requirement SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$inc": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$min": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$max": { "matrix.$[row]": 10 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$mul": { "matrix.$[row]": 2 }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$rename": { "matrix.$[row]": "arrayA.3" }} }', '{}', '{ "": [{ "row": 0 }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$set": { "matrix.$[row]": "updatedValue" }} }', '{}', '{ "": [{ "row": 0 }] }'); -- bit operator SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [0], [1] ] }', '{ "": { "$bit": { "matrix.$[row]": {"or": 5} }} }', '{}', '{ "": [{ "row": 0 }] }'); -- Check array value should also match in arrayFilters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [11,12,13], [14,15,16] ] }', '{ "": { "$set": { "matrix.$[row]": [21,22,23] }} }', '{}', '{ "": [{ "row": [11,12,13] }] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "matrix" : [ [11,12,13], [14,15,16] ] }', '{ "": { "$set": { "matrix.$[row]": 33 }} }', '{}', '{ "": [{ "row": {"$size": 3} }] }'); bson_update_positional_queryFilters.sql000066400000000000000000000214241507310017400370370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 200000; SET documentdb.next_collection_id TO 2000; SET documentdb.next_collection_index_id TO 2000; -- simple array update on equality SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 1, "grades" : [ 85, 80, 80 ] }','{ "": { "$set": { "grades.$" : 82 } } }', '{ "_id": 1, "grades": 80 }', NULL); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 2, "grades" : [ 88, 90, 92 ] }','{ "": { "$set": { "grades.$" : 82 } } }', '{ "_id": 1, "grades": 80 }', NULL); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 4, "grades": [ { "grade": 80, "mean": 75, "std": 8 }, { "grade": 85, "mean": 90, "std": 5 }, { "grade": 85, "mean": 85, "std": 8 } ] }', '{ "": { "$set": { "grades.$.std" : 6 } } }', '{ "_id": 4, "grades.grade": 85 }', NULL); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id" : 4, "grades": [ { "grade": 80, "mean": 75, "std": 8 }, { "grade": 85, "mean": 90, "std": 5 }, { "grade": 85, "mean": 85, "std": 8 } ] }', '{ "": { "$set": { "grades.$.std" : 6 } } }', '{ "_id": 5, "grades": { "$elemMatch": { "grade": { "$lte": 90 }, "mean": { "$gt": 80 } } } }', NULL); -- positional on match that doesn't work SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "c": 8 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$or": [ { "b": 5 }, { "c": 8 } ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$nor": [ { "b": 5 }, { "c": 8 } ] }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$not": { "$eq": 8 } } }'); -- positional on alternate array (pick first match) SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$in": [ 5, 6 ]} }'); -- test $or with simple filters SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "$or": [ { "b": 5 }, { "b": 6 } ] }'); -- test various filter operators SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": 5 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$ne": 5 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$nin": [ 4, 5] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$gte": 5 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$lte": 5 } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$regularExpression": { "pattern": "^ba[rz]", "options": "" } } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$exists": true } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ "bat", "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$type": "number" } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ true, "bar", "baz" ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$type": "string" } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b.c": { "$elemMatch": { "$eq": 2 }} }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b.c": { "$elemMatch": { "$eq": 2 }} }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ 5, 6 ] } }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, 5, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$bitsAnySet": [ 0, 1 ]} }'); -- $elemMatch with empty document SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ 4, { "c": 5 }, 6 ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$elemMatch": {} }}'); -- $all with $elemmatch SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ { "$elemMatch": { "c": 2 } } ]} }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 1, "a": [ 1, 2, 3 ], "b": [ { "c": 1 }, { "c": 2 }, { "c": 3 } ], "c": 8 }', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": { "$all": [ { "$elemMatch": { "c": 2 } } , { "$elemMatch": { "c": 3 } } ]} }'); -- upsert cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{}', '{ "": { "$set": { "a.$": 100 } } }', '{ "b": [ 1, 2, 3 ], "a": [ 4, 5, 6 ] }'); -- simple example for non-array SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 3, "a": { "b": [ { "c": 1, "d": 2 } ] } }', '{ "": { "$set": { "a.$.c": 11 } }}', '{ "_id": 1 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document( '{ "_id": 3, "a": { "b": [ { "c": 1, "d": 2 } ] } }', '{ "": { "$set": { "a.$.c": 11 } }}', '{ "a.b.c": 1 }'); -- miscellenous cases SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8] }', '{ "": { "$set": { "a.$": "new" } }}', '{ "b": 6 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8] }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"a" : 3 ,"b": 6 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{"_id" : 1, "key":[{"id":1,"a":1},{"id":2,"a":1}],"key2":[{"id":1,"a":1}]}', '{ "": { "$set": { "key.$.a": 5 } }}', '{"key.id": 2, "key2.id" : 3}'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8], "c" : 1 }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"a" : 3 ,"b": 6, "c" : 1 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : [1,2,3,4], "b" : [5,6,7,8], "c" : 1 }', '{ "": { "$set": { "a.$": "new", "b.$" : "new" } }}', '{"c" : 1 }'); SELECT newDocument as bson_update_document FROM documentdb_api_internal.bson_update_document('{ "_id": 1, "a" : 1, "c" : 1 }', '{ "": { "$set": { "a.$": "new"} }}', '{"a" : 1}'); bson_wildcard_reduced_term_tests.sql000066400000000000000000000202101507310017400362630ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 5600000; SET documentdb.next_collection_id TO 56000; SET documentdb.next_collection_index_id TO 56000; -- test term generation SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": 1, "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : { "b": [ 1, 2 ], "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": 1, "c": 2 }, { "d": 1 } ] }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ 1, 2 ], "c": 2 }, { "d": 1 }, 3 ] }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ 1, 2 ], "c": 2 }, [ { "d": 1 }, 5 ], 3 ] }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ [ 1, 2 ] ] }', '', true, enableReducedWildcardTerms => true); SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ [ { "b": 1 } ] ] }', '', true, enableReducedWildcardTerms => true); -- objects with fields with numeric paths don't get skipped SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "0" : { "b": { "1": { "f": true }, "2": 2 }, "c": 2 }, "d": 1 }', '', true, enableReducedWildcardTerms => true); -- array paths *before* matches are fully considered SELECT documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms('{"_id": 6, "a" : [ { "b": [ { "c": 1 }]}] }', 'a.0.b', true, enableReducedWildcardTerms => true); -- create a root wildcard index with reduced terms SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "wildcardreducedterms", "indexes": [ { "key": { "$**": 1 }, "name": "my_idx", "enableReducedWildcardTerm": true }] }'); \d documentdb_data.documents_56000 -- now insert some convoluted document SELECT documentdb_api.insert_one('db','wildcardreducedterms', '{"_id": 15, "c" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }', NULL); -- these return the above document SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ -1, 1, 2 ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : [ -1, 1, 2 ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.0" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.1" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : [ -1, 1, 2 ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : [ -1, 1, 2 ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.0" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.1" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0.2" : { "$eq" : 2 }}'; -- these queries do not return the above document SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.1" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.2" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d.0.2" : { "$eq" : [ 2 ] }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : -1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.0" : { "$eq" : 2 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.1" : { "$eq" : 1 }}'; SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d.2" : { "$eq" : 2 }}'; -- EXPLAIN to show the plan with the paths EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; -- having numbers in fields is okay as long as it also has letters EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c01" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.d0af.e" : { "$eq" : [ { "d": [[-1, 1, 2]] }, { "d": [[0, 1, 2]] }, { "d": [[0, 1, 7]] }] }}'; -- these won't be pushed EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0.d" : { "$eq" : [ [ -1, 1, 2 ] ] }}'; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db','wildcardreducedterms') WHERE document @@ '{ "c.0" : { "$eq" : { "d" : [ [ -1, 1, 2 ] ] } }}';documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/collection_management.sql000066400000000000000000000133321507310017400341220ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_core; SET citus.next_shard_id TO 190000; SET documentdb.next_collection_id TO 1900; SET documentdb.next_collection_index_id TO 1900; -- create a collection and insert a document SELECT documentdb_api.create_collection('collection_management','originalname'); SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); SELECT documentdb_api.insert_one('collection_management','originalname','{"_id":"1", "a":1}'); -- query an existing collection SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); -- query a non-existing collection SELECT count(*) FROM documentdb_api.collection('collection_management','nonexistent'); -- SELECT * from a non-existing collection SELECT * FROM documentdb_api.collection('collection_management','nonexistent'); -- EXPLAIN of querying a non-existing collection EXPLAIN SELECT * FROM documentdb_api.collection('collection_management','nonexistent'); -- try to rename to an already existing name SELECT documentdb_api.create_collection('collection_management','newname'); SELECT documentdb_api.rename_collection('collection_management','originalname', 'newname'); -- Disallow system.views, system.profile etc as the target collection names SELECT documentdb_api.rename_collection('collection_management','originalname', 'system.views'); SELECT documentdb_api.rename_collection('collection_management','originalname', 'system.profile'); -- validate duplicate collections are not allowed SELECT documentdb_api.create_collection('collection_management','collection1'); SELECT documentdb_api.create_collection('collection_management','collection1'); -- try to rename to an already existing name, after dropping the old one SELECT documentdb_api.rename_collection('collection_management','originalname', 'newname', true); -- try to query the original name SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); -- try to query the new name SELECT count(*) FROM documentdb_api.collection('collection_management','newname'); -- drop the collection SELECT documentdb_api.drop_collection('collection_management','newname'); -- try to drop a non-existent collection SELECT documentdb_api.drop_collection('collection_management','originalname'); -- recreate a table that previously existed SELECT documentdb_api.create_collection('collection_management','originalname'); SELECT count(*) FROM documentdb_api.collection('collection_management','originalname'); SELECT documentdb_api_internal.create_indexes_non_concurrently('collection_management', '{"createIndexes": "drop_collection_test", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); -- store id of drop_collection_test before dropping it SELECT collection_id AS drop_collection_test_id FROM documentdb_api_catalog.collections WHERE collection_name = 'drop_collection_test' AND database_name = 'collection_management' \gset -- Insert a record into index metadata that indicates an invalid collection index -- to show that we delete records for invalid indexes too when dropping database. INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:drop_collection_test_id, 2020, ('invalid_index_2', '{"a": 1}', null, null, null, null, 2, null, null, null), false); -- drop the database SELECT documentdb_api.drop_database('collection_management'); SELECT count(*) FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management'; SELECT COUNT(*)=0 FROM documentdb_api_catalog.collection_indexes WHERE collection_id = :drop_collection_test_id; SELECT documentdb_api.create_collection('collection_management','testDropViaUuid'); SELECT documentdb_api.create_collection('collection_management','testDropViaUuid2'); SELECT collection_uuid::text AS drop_collection_uuid2 FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management' AND collection_name = 'testDropViaUuid2' \gset SELECT collection_uuid::text AS drop_collection_uuid FROM documentdb_api_catalog.collections WHERE database_name = 'collection_management' AND collection_name = 'testDropViaUuid' \gset SELECT documentdb_api.drop_collection('collection_management', 'testDropViaUuid', NULL, :'drop_collection_uuid2'::uuid); SELECT documentdb_api.drop_collection('collection_management', 'testDropViaUuid', NULL, :'drop_collection_uuid'::uuid); -- try to target a collection via a prepared statement. SELECT documentdb_api.create_collection('collection_management','testPrepared'); PREPARE collectionQuery1(text, text) AS SELECT document FROM documentdb_api.collection($1, $2); EXECUTE collectionQuery1('collection_management', 'testPrepared'); -- try to run the prepared statement many times against a non-existent collection PREPARE qcountNoneExistent(text, text, bson, text) AS WITH "stage0" as ( SELECT document FROM documentdb_api.collection($1, $2) WHERE document OPERATOR(documentdb_api_catalog.@@) $3 ) , "stage1" as ( SELECT documentdb_core.bson_repath_and_build($4, BSONSUM('{ "": 1 }'::bson)) as document FROM "stage0" ) SELECT * FROM "stage1"; EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count'); EXECUTE qcountNoneExistent('nonexistentdb', 'nonexistent', '{ "a": 1 }', 'count');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/command_compact.sql000066400000000000000000000076231507310017400327250ustar00rootroot00000000000000SET citus.next_shard_id TO 2432000; SET documentdb.next_collection_id TO 24320; SET documentdb.next_collection_index_id TO 24320; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SELECT documentdb_api.compact(NULL); SELECT documentdb_api.compact('{}'); SELECT documentdb_api.compact('{"noIdea": "collection1"}'); SELECT documentdb_api.compact('{"compact": "non_existing_collection"}'); SELECT documentdb_api.compact('{"compact": 1 }'); SELECT documentdb_api.compact('{"compact": true }'); SELECT documentdb_api.compact('{"compact": ["coll"]}'); SELECT documentdb_api.create_collection('commands_compact_db','compact_test'); SELECT documentdb_api.compact('{"compact": "compact_test", "dryRun": "invalid"}'); SELECT documentdb_api.compact('{"compact": "compact_test", "comment": "test comment"}'); SELECT documentdb_api.compact('{"compact": "compact_test", "force": false}'); -- Insert a single document SELECT documentdb_api.insert_one('commands_compact_db', 'compact_test', FORMAT('{ "_id": 1, "a": "%s", "c": [ %s "d" ] }', repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); -- Bloat the table DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..45 LOOP UPDATE documentdb_data.documents_24321 SET document = document::bytea::bson WHERE document @@ '{ "_id": 1 }'; COMMIT; END LOOP; END; $$; -- VALID, first need to analyze the table so that stats are up to date ANALYZE VERBOSE documentdb_data.documents_24321; SELECT documentdb_api.coll_stats('commands_compact_db','compact_test')->>'storageSize'; -- TODO: even after analyze it seems like pg_class stats for toast tables are not updated for test run. -- Need to investigate this further for test, for live servers this should be okay because the analyze thereshold is set to 0. SELECT documentdb_api.compact('{"compact": "compact_test", "$db": "commands_compact_db", "dryRun": true}'); SELECT documentdb_api.compact('{"compact": "compact_test", "$db": "commands_compact_db", "dryRun": false}'); SELECT documentdb_api.coll_stats('commands_compact_db','compact_test')->>'storageSize'; SELECT documentdb_api.drop_collection('commands_compact_db','compact_test'); -- sharded test SELECT documentdb_api.create_collection('commands_compact_db', 'compact_test_sharded'); SELECT documentdb_api.shard_collection('commands_compact_db', 'compact_test_sharded', '{"_id": "hashed"}', false); DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..51 LOOP PERFORM documentdb_api.insert_one('commands_compact_db', 'compact_test_sharded', FORMAT('{ "_id": %s, "a": "%s", "c": [ %s "d" ] }',i, repeat('Sample', 100000), repeat('"' || repeat('a', 1000) || '", ', 5000))::documentdb_core.bson); COMMIT; END LOOP; END; $$; DO $$ DECLARE i int; BEGIN -- each doc is "a": 500KB, "c": 5 MB - ~5.5 MB & there's 10 of them FOR i IN 1..45 LOOP UPDATE documentdb_data.documents_24322 SET document = document::bytea::bson WHERE document @@ '{ "_id": 1 }'; COMMIT; END LOOP; END; $$; -- VALID, first need to analyze the table so that stats are up to date ANALYZE VERBOSE documentdb_data.documents_24322; SELECT documentdb_api.coll_stats('commands_compact_db','compact_test_sharded')->>'storageSize'; -- TODO: even after analyze it seems like pg_class stats for toast tables are not updated for test run. -- Need to investigate this further for test, for live servers this should be okay because the analyze thereshold is set to 0. SELECT documentdb_api.compact('{"compact": "compact_test_sharded", "$db": "commands_compact_db", "dryRun": true}'); SELECT documentdb_api.compact('{"compact": "compact_test_sharded", "$db": "commands_compact_db", "dryRun": false}'); SELECT documentdb_api.coll_stats('commands_compact_db','compact_test_sharded')->>'storageSize'; SELECT documentdb_api.drop_collection('commands_compact_db','compact_test_sharded');command_insert_procedure.sql000066400000000000000000000224551507310017400345740ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 129000; SET documentdb.next_collection_id TO 1290; SET documentdb.next_collection_index_id TO 1290; -- Run inside transaction BEGIN; CALL documentdb_api.insert_bulk('db', '{"insert":"salaries", "documents":[{ "_id" : 1 }]}'); END; -- exercise invalid insert syntax errors CALL documentdb_api.insert_bulk('db', NULL); CALL documentdb_api.insert_bulk(NULL, '{"insert":"collection", "documents":[{"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"documents":[{"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection"}'); CALL documentdb_api.insert_bulk('db', '{"insert":["collection"], "documents":[{"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":{"a":1}}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[{"a":1}], "extra":1}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[4]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection", "documents":[{"a":1}],"ordered":1}'); -- Disallow system.views, system.profile writes CALL documentdb_api.insert_bulk('db', '{"insert":"system.views", "documents":[{"a":1}],"ordered":true}'); CALL documentdb_api.insert_bulk('db', '{"insert":"system.profile", "documents":[{"a":1}],"ordered":true}'); -- regular single-row insert CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":99,"a":99}]}'); select document from documentdb_api.collection('db','collection0') where document @@ '{}'; -- batch scenario set documentdb.batchWriteSubTransactionCount TO 5; -- when single batch has no issue CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl0", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}]}'); select document from documentdb_api.collection('batchDB','batchColl0') where document @@ '{}'; -- when multiple batches have no issue CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl1", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":7}]}'); select document from documentdb_api.collection('batchDB','batchColl1') where document @@ '{}'; -- when single batch has issue _id 2 is duplicated CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl2", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}]}'); select document from documentdb_api.collection('batchDB','batchColl2') where document @@ '{}'; -- when multiple batches have no _id 2 is duplicated and _id 6 is duplicated CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl3", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":6}]}'); select document from documentdb_api.collection('batchDB','batchColl3') where document @@ '{}'; -- when single batch has issue _id 2 is duplicated and ordered false CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl4", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}], "ordered":false}'); select document from documentdb_api.collection('batchDB','batchColl4') where document @@ '{}'; -- when multiple batches have no _id 2 is duplicated and _id 6 is duplicated and ordered false CALL documentdb_api.insert_bulk('batchDB', '{"insert":"batchColl5", "documents":[{"_id":1}, {"_id":2}, {"_id":2}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":6}], "ordered":false}'); select document from documentdb_api.collection('batchDB','batchColl5') where document @@ '{}'; -- end batch test rest GUC set documentdb.batchWriteSubTransactionCount TO 512; -- Insert collection a db with same name and different case and collection being same. Expect to error CALL documentdb_api.insert_bulk('dB', '{"insert":"collection0", "documents":[{"_id":99,"a":99}]}'); -- Insert collection a db with same name and different case and collection being different. Expect to error CALL documentdb_api.insert_bulk('dB', '{"insert":"collection9", "documents":[{"_id":99,"a":99}]}'); -- Insert collection same db and new collection. CALL documentdb_api.insert_bulk('db', '{"insert":"collection8", "documents":[{"_id":99,"a":99}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection0", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); select document from documentdb_api.collection('db','collection0') where document @@ '{}'; CALL documentdb_api.insert_bulk('db', '{"insert":"collection1", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','collection1') where document @@ '{}' order by document-> '_id'; CALL documentdb_api.insert_bulk('db', '{"insert":"collection2", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','collection2') where document @@ '{}' order by document-> '_id'; CALL documentdb_api.insert_bulk('db', '{"insert":"collection3", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}],"ordered":false}'); select document from documentdb_api.collection('db','collection3') where document @@ '{}' order by document-> '_id'; -- shard the collection by _id select documentdb_api.shard_collection('db', 'collection4', '{"_id":"hashed"}', false); CALL documentdb_api.insert_bulk('db', '{"insert":"collection4", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection4", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); select document from documentdb_api.collection('db','collection4') where document @@ '{}'; -- single-row insert with retry and auto-generated _id CALL documentdb_api.insert_bulk('db', '{"insert":"collection5", "documents":[{"a":1}]}',NULL,'insert-2'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection5", "documents":[{"a":1}]}',NULL,'insert-2'); select count(*) from documentdb_api.collection('db','collection5') where document @@ '{}'; -- multi-row insert collection different shards CALL documentdb_api.insert_bulk('db', '{"insert":"collection6", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','collection6') where document @@ '{}' order by document-> '_id'; select document from documentdb_api.collection('db','collection6') where document @@ '{"a":1}' order by document-> '_id'; select document from documentdb_api.collection('db','collection6') where document @@ '{"a":2}' order by document-> '_id'; -- insert with documents in special section CALL documentdb_api.insert_bulk('db', '{"insert":"collection7"}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); select document from documentdb_api.collection('db','collection7') where document @@ '{}' order by document-> '_id'; -- insert with both docs specified. CALL documentdb_api.insert_bulk('db', '{"insert":"collection9", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); -- insert with id undefined skips CALL documentdb_api.insert_bulk('db', '{"insert":"collection9", "documents":[{"_id":{ "$undefined": true } }]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"collection9"}', '{ "": [ {"_id":{ "$undefined": true } } ]}'); -- insert with invalid database CALL documentdb_api.insert_bulk('Invalid Database Name', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"system.othercoll", "documents":[{"_id":1,"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":"random$name", "documents":[{"_id":1,"a":1}]}'); CALL documentdb_api.insert_bulk('db', '{"insert":".randomname", "documents":[{"_id":1,"a":1}]}'); CALL documentdb_api.insert_bulk('verylongdatabasenameformeasuringthelimitsofdatabasenamesinmongodb', '{"insert":"coll", "documents":[{"_id":1,"a":1}]}'); CALL documentdb_api.insert_bulk('verylongdatabasenameformeasuringlimitsofdatabasenamesinmongoda', '{"insert":"verylongcollectionnameformeasuringthelimitsofcollectionnamesinmongodb", "documents":[{"_id":1,"a":1}]}'); -- when multiple batches and after multiple intermidate commits also things are fine SET documentdb.batchWriteSubTransactionCount TO 2; SELECT documentdb_api.create_collection('commitDb', 'commitColl'); -- insert 10 documents CALL documentdb_api.insert_bulk('commitDb', '{"insert":"commitColl", "documents":[{"_id":1}, {"_id":2}, {"_id":3}, {"_id":4}, {"_id":5}, {"_id":6}, {"_id":7}, {"_id":8}, {"_id":9}, {"_id":10}]}'); -- first one is duplicate and rest 9 are inserted CALL documentdb_api.insert_bulk('commitDb', '{"insert":"commitColl", "documents":[{"_id":1}, {"_id":12}, {"_id":13}, {"_id":14}, {"_id":15}, {"_id":16}, {"_id":17}, {"_id":18}, {"_id":19}, {"_id":20}], "ordered":false}'); -- total doc count should be 10+9 SELECT count(document) FROM documentdb_api.collection('commitDb','commitColl'); -- clean the collections SELECT documentdb_api.drop_collection('db', 'collection0'); SELECT documentdb_api.drop_collection('db', 'collection1'); SELECT documentdb_api.drop_collection('db', 'collection2'); SELECT documentdb_api.drop_collection('db', 'collection3'); SELECT documentdb_api.drop_collection('db', 'collection4'); SELECT documentdb_api.drop_collection('db', 'collection5'); SELECT documentdb_api.drop_collection('db', 'collection6'); SELECT documentdb_api.drop_collection('db', 'collection7'); SELECT documentdb_api.drop_collection('db', 'collection8');command_shard_commands.sql000066400000000000000000000155601507310017400342010ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 756000; SET documentdb.next_collection_id TO 7560; SET documentdb.next_collection_index_id TO 7560; ALTER SEQUENCE pg_dist_colocationid_seq RESTART WITH 7560; set documentdb.recreate_retry_table_on_shard to on; CREATE FUNCTION command_sharding_get_collectionInfo(dbname text DEFAULT 'comm_sh_coll', filterValue text DEFAULT '') RETURNS SETOF documentdb_core.bson AS $$ BEGIN RETURN QUERY WITH base AS (SELECT bson_dollar_project(bson_dollar_unwind(cursorpage, '$cursor.firstBatch'), '{ "cursor.firstBatch.idIndex": 0, "cursor.firstBatch.info.uuid": 0, "cursor.firstBatch.options": 0 }')::documentdb_core.bson AS doc FROM list_collections_cursor_first_page(dbname, FORMAT('{ "listCollections": 1, "filter": { %s }, "addDistributedMetadata": true }', filterValue)::documentdb_core.bson)) SELECT doc FROM base ORDER BY bson_orderby(doc, '{ "cursor.firstBatch.name": 1 }'); END; $$ LANGUAGE plpgsql; SELECT documentdb_api.insert_one('comm_sh_coll', 'single_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); SELECT documentdb_api.insert_one('comm_sh_coll', 'comp_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); -- test new shard collection API - invalid inputs SELECT documentdb_api.shard_collection('{ }'); SELECT documentdb_api.shard_collection('{ "key": { "_id": "hashed" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": 1 } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": 1 }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": -1 }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": 5678 }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "collation": { "a": "b" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "timeseries": { "a": "b" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.", "key": { "_id": "hashed" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": ".single_shard", "key": { "_id": "hashed" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": ".", "key": { "_id": "hashed" } }'); SELECT documentdb_api.shard_collection('{ "shardCollection": "admin.system.collections", "key": { "_id": "hashed" } }'); -- valid shard collection SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false }'); -- cannot shard a sharded collection SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false }'); -- shard collection creates a new collection. SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.new_coll", "key": { "_id": "hashed" }, "unique": false }'); -- call listCollections and validate state. SELECT command_sharding_get_collectionInfo(); SELECT * FROM public.citus_tables tbls JOIN (SELECT 'documentdb_data.documents_' || collection_id AS mongo_table_name FROM documentdb_api_catalog.collections WHERE database_name = 'comm_sh_coll' UNION ALL SELECT 'documentdb_data.retry_' || collection_id AS mongo_table_name FROM documentdb_api_catalog.collections WHERE database_name = 'comm_sh_coll') colls ON tbls.table_name::text = colls.mongo_table_name ORDER BY colocation_id ASC; -- shard with different shard count SELECT documentdb_api.shard_collection('{ "shardCollection": "comm_sh_coll.comp_shard", "key": { "_id": "hashed" }, "unique": false, "numInitialChunks": 3 }'); SELECT command_sharding_get_collectionInfo(); -- unshard - should return to the original colocationGroup. SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.comp_shard" }'); -- unsupported option SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.new_coll", "toShard": "shard2" }'); SELECT command_sharding_get_collectionInfo(); -- cannot unshard an unsharded collection. SELECT documentdb_api.unshard_collection('{ "unshardCollection": "comm_sh_coll.comp_shard" }'); -- reshardCollection invalid apis SELECT documentdb_api.reshard_collection('{ }'); SELECT documentdb_api.reshard_collection('{ "key": { "_id": "hashed" } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": 1 } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": 1 }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": 5678 }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "collation": { "a": "b" } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "numInitialChunks": -1 }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.", "key": { "_id": "hashed" } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": ".single_shard", "key": { "_id": "hashed" } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": ".", "key": { "_id": "hashed" } }'); SELECT documentdb_api.reshard_collection('{ "reshardCollection": "admin.system.collections", "key": { "_id": "hashed" } }'); -- cannot reshard unsharded collection SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.comp_shard", "key": { "_id": "hashed" }, "unique": false }'); -- should noop since options are the same SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false }'); SELECT command_sharding_get_collectionInfo(); -- with force, should redo SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "_id": "hashed" }, "unique": false, "forceRedistribution": true }'); SELECT command_sharding_get_collectionInfo(); -- reshard with new key allowed SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false, "numInitialChunks": 5 }'); SELECT command_sharding_get_collectionInfo(); -- reshard with same key and change chunks allowed SELECT documentdb_api.reshard_collection('{ "reshardCollection": "comm_sh_coll.single_shard", "key": { "a": "hashed" }, "unique": false, "numInitialChunks": 2, "forceRedistribution": true }'); SELECT command_sharding_get_collectionInfo();documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_coll_mod.sql000066400000000000000000000155231507310017400332500ustar00rootroot00000000000000SET citus.next_shard_id TO 2500000; SET documentdb.next_collection_id TO 25000; SET documentdb.next_collection_index_id TO 25000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- Create a collection SELECT documentdb_api.create_collection('commands','collModTest'); SELECT documentdb_api.insert_one('commands','collModTest','{"_id":"1", "a": 1 }'); -- Creating a regular and ttl index SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', documentdb_distributed_test_helpers.generate_create_index_arg('collModTest', 'a_1', '{"a": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', '{"createIndexes": "collModTest", "indexes": [{"key": {"b": 1}, "name": "b_ttl", "v" : 2, "expireAfterSeconds": 10000}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('commands', '{"createIndexes": "collModTest", "indexes": [{"key": {"z": 1}, "name": "z_ttl_should_be_dropped_parallely", "v" : 2, "expireAfterSeconds": 1000}]}', true); -- Top level validations for collMod index options SELECT documentdb_api.coll_mod(NULL, 'collModTest', '{"collMod": "collModTest", "index": {}}'); SELECT documentdb_api.coll_mod('commands', NULL, '{"collMod": "collModTest", "index": {}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "hello": 1}'); -- Unknown field SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": 1}'); -- Type mismatch SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": []}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "c_1"}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": 1}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "name": 1}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": 1, "name": "c_1"}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "name": "c_1"}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": true}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": {}}}'); SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": 1, "expireAfterSeconds": "expire"}}'); -- Inserting some documents SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 0, "b": { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 1, "b": { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 2, "b": { "$date": { "$numberLong": "100" } } }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 3, "b": { "$date": { "$numberLong": "1657900030774" } } }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 4, "b": { "$date": { "$numberLong": "2657899731608" } } }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 5, "b": [{ "$date": { "$numberLong": "100" }}] }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 6, "b": [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 7, "b": [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 8, "b": true }', NULL); SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id" : 9, "b": "would not expire" }', NULL); -- Insert a doc with current time when the test is running -- Function to insert a doc in collection with current time and given id CREATE OR REPLACE FUNCTION insert_doc_with_current_time(id numeric) RETURNS void AS $fn$ DECLARE epoch_bgn text; bgn_epoch_sec numeric; bgn_usec numeric; bgn_epoch_msec numeric; BEGIN SELECT extract(epoch from clock_timestamp()) into epoch_bgn; SELECT split_part(epoch_bgn, '.', 1)::numeric into bgn_epoch_sec; SELECT split_part(epoch_bgn, '.', 2)::numeric into bgn_usec; bgn_epoch_msec := bgn_epoch_sec * 1000 + ROUND(bgn_usec / 1000); EXECUTE format($$ SELECT documentdb_api.insert_one('commands','collModTest', '{ "_id": %s, "b": { "$date": { "$numberLong": "%s" } } }', NULL)$$, id, bgn_epoch_msec); END $fn$ LANGUAGE plpgsql; SELECT insert_doc_with_current_time(100); -- Test TTL deletion with current setting it should not delete the current timestamp doc with _id: 100 CALL documentdb_api_internal.delete_expired_rows(); SELECT object_id from documentdb_api.collection('commands', 'collModTest'); -- Updating ttl expiration time to 2 secs SELECT * FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'b_ttl' AND (index_spec).index_expire_after_seconds = 2; -- Before update SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "b_ttl", "expireAfterSeconds": 2}}'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'b_ttl' AND (index_spec).index_expire_after_seconds = 2; -- After update SELECT pg_sleep(2); -- Now even _id: 100 should get deleted CALL documentdb_api_internal.delete_expired_rows(); SELECT object_id from documentdb_api.collection('commands', 'collModTest'); -- Errors SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "a_1", "expireAfterSeconds": 2000}}'); -- Not a TTL index to be modified SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "a_1", "hidden": true}}'); -- Hidden is not supported yet SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"name": "c_1", "expireAfterSeconds": 1000}}'); -- index not found SELECT documentdb_api.coll_mod('commands', 'collModTest', '{"collMod": "collModTest", "index": {"keyPattern": {"c": 1}, "expireAfterSeconds": 1000}}'); -- index not found commands_collmod_tests_hidden.sql000066400000000000000000000126461507310017400355720ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog; SET citus.next_shard_id TO 920000; SET documentdb.next_collection_id TO 9200; SET documentdb.next_collection_index_id TO 9200; SELECT documentdb_api.create_collection('collmod','coll_mod_test_hidden'); SELECT COUNT(documentdb_api.insert_one('collmod','coll_mod_test_hidden', FORMAT('{"_id":"%s", "a": %s }', i, i )::documentdb_core.bson)) FROM generate_series(1, 100) i; -- cannot create an index as hidden SELECT documentdb_api_internal.create_indexes_non_concurrently('collmod', '{"createIndexes": "coll_mod_test_hidden", "indexes": [{"key": {"a": 1}, "name": "my_idx_1", "hidden": true }]}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('collmod', '{"createIndexes": "coll_mod_test_hidden", "indexes": [{"key": {"a": 1}, "name": "my_idx_1" }]}', TRUE); set citus.show_shards_for_app_name_prefixes to '*'; \d documentdb_data.documents_9201 \d documentdb_data.documents_9201_920002 ANALYZE documentdb_data.documents_9201; -- get list index output SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); -- the index is used for queries set enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); -- now hide the index SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": true } }'); -- print the status \d documentdb_data.documents_9201 \d documentdb_data.documents_9201_920002 SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); -- the index is not used for queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); -- cannot hide the primary key index (since it's unique) SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "_id_", "hidden": true } }'); -- now inserts done while the index is hidden do get factored into the final results. SELECT documentdb_api.insert_one('collmod','coll_mod_test_hidden', '{"_id":"101", "a": 101 }'::documentdb_core.bson); SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 101 } }'); -- unhide the index SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": false } }'); -- print the status: index is no longer invalid \d documentdb_data.documents_9201 \d documentdb_data.documents_9201_920002 -- hidden is no longer in the options SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); -- can use the index again EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); -- the row shows up from the index SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 101 } }'); -- shard the collection. SELECT documentdb_api.shard_collection('{ "shardCollection": "collmod.coll_mod_test_hidden", "key": { "_id": "hashed" }, "numInitialChunks": 3 }'); set citus.explain_all_tasks to on; BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); ROLLBACK; -- now hide the index again (with debug logs) set client_min_messages to debug1; SET citus.multi_shard_modify_mode TO 'sequential'; SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": true } }'); reset client_min_messages; reset citus.multi_shard_modify_mode; \d documentdb_data.documents_9201 \d documentdb_data.documents_9201_920003 \d documentdb_data.documents_9201_920004 \d documentdb_data.documents_9201_920005 SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); ROLLBACK; -- unhide the index again SELECT documentdb_api.coll_mod('collmod', 'coll_mod_test_hidden', '{ "collMod": "coll_mod_test_hidden", "index": { "name": "my_idx_1", "hidden": false } }'); \d documentdb_data.documents_9201 \d documentdb_data.documents_9201_920003 \d documentdb_data.documents_9201_920004 \d documentdb_data.documents_9201_920005 SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('collmod', '{ "listIndexes": "coll_mod_test_hidden" }'); BEGIN; set local enable_seqscan = off; EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_find('collmod', '{ "find": "coll_mod_test_hidden", "filter": { "a": 1 } }'); ROLLBACK; commands_create_drop_indexes_a.sql000066400000000000000000000150421507310017400357030ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 130000; SET documentdb.next_collection_id TO 13000; SET documentdb.next_collection_index_id TO 13000; set search_path to documentdb_core,documentdb_api,documentdb_api_catalog; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["*"]}'); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); -- Whatever rest of the arguments are, having "*" as the first one would drop -- all indexes. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["*", "_id_", "index_dne"]}'); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_all_test", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"}, {"key": {"b.$**": 1}, "name": "my_idx_2"} ] }', true ); -- Given that "*" is not the first item of the array, we should interpret it -- as a plain index name and throw an error complaining that index doesn't exist. CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["my_idx_1", "*"]}'); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; -- cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": "_id_"}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": ["_id_", "*"]}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_all_test", "index": "*"}'); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'drop_all_test') ORDER BY 1,2; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "drop_by_key", "indexes": [ {"key": {"a": 1, "c.e": 1}, "name": "idx_1"}, {"key": {"b.$**": 1}, "name": "idx_2"} ] }', true ); -- no such index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"c.d": 1}}'); -- cannot drop _id index CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"_id": 1}}'); -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'drop_by_key') ORDER BY indexrelid; -- invalid key spec document but would just complain "no such index" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"$**.c.d": 1}}'); -- only drops "idx_2" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": "*", "index": {"a": 1, "c.e": 1}, "index": {"b.$**": 1}}'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; -- incorrect ordering of the (compound) keys, so cannot match "idx_1" CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "drop_by_key", "index": {"c.e": 1, "a": 1}}'); -- now drop "idx_1" too, but specify collection name using "deleteIndexes" CALL documentdb_api.drop_indexes('db', '{"deleteIndexes": "drop_by_key", "index": {"a": 1, "c.e": 1}}'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'drop_by_key') ORDER BY collection_id, index_id; -- Show that having a record indicating an invalid collection index with the -- same index name wouldn't cause any problems when creating the index. SELECT documentdb_api.create_collection('db', 'collection_1000'); INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) SELECT collection_id, 1000, ('idx_1', '{}', null, null, null, null, 2, null, null, null)::documentdb_api_catalog.index_spec_type, false FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1000'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1000", "indexes": [{"key": {"a": 1}, "name": "idx_1"}]}', true); -- delete the fake invalid entry that we inserted above DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'idx_1' AND index_id = 1000 AND (index_spec).index_key operator(documentdb_core.=) '{}' AND index_is_valid = false AND collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1000'); -- Show that having a record indicating an invalid collection index with the -- same index key wouldn't cause any problems when creating the index. SELECT documentdb_api.create_collection('db', 'collection_1001'); INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) SELECT collection_id, 1000, ('idx_1', '{"a": 1}', null, null, null, null, 2, null, null, null)::documentdb_api_catalog.index_spec_type, false FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1001'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1001", "indexes": [{"key": {"a": 1}, "name": "idx_2"}]}', true); -- delete the fake invalid entry that we inserted above DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_name = 'idx_1' AND index_id = 1000 AND (index_spec).index_key operator(documentdb_core.=) '{"a": 1}' AND index_is_valid = false AND collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'collection_1001'); commands_create_drop_indexes_b.sql000066400000000000000000000124741507310017400357120ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 140000; SET documentdb.next_collection_id TO 14000; SET documentdb.next_collection_index_id TO 14000; ---- some other tests using createIndexes & dropIndexes ---- -- test 1 SELECT documentdb_api.create_collection('mydb', 'collection_2'); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.$**": 1}, "name": "my_idx_1"} ] }' ,true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', 'my_idx_1'); CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": "my_idx_1" }' ); SELECT count(*)=0 AS index_does_not_exist FROM documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', 'my_idx_1'); -- test 2 SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.b.$**": 1}, "name": "my_idx_1"}, {"key": {"$**": 1}, "name": "my_idx_2"}, {"key": {"c.d": 1}, "name": "my_idx_3"} ] }', true ); SELECT documentdb_indexes.index_name, documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', documentdb_indexes.index_name) FROM (VALUES ('my_idx_1'), ('my_idx_2'), ('my_idx_3')) documentdb_indexes(index_name) ORDER BY documentdb_indexes.index_name; -- not the same index since this specifies wildcardProjection SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"$**": 1}, "name": "my_idx_4", "wildcardProjection": {"a": 0}} ] }', true ); CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": ["my_idx_1"] }' ); CALL documentdb_api.drop_indexes( 'mydb', '{ "dropIndexes": "collection_2", "index": ["my_idx_2", "my_idx_3"] }' ); SELECT count(*)=0 AS index_does_not_exist FROM ( SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_2', documentdb_indexes.index_name) FROM (VALUES ('my_idx_1'), ('my_idx_2'), ('my_idx_3')) documentdb_indexes(index_name) ) q; -- Cannot SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if collection -- was created before and if we're really creating an index. BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"}, {"key": {"c.d": 1}, "name": "new_idx_2"} ] }', false ); ROLLBACK; -- would only create idx_2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_200", "indexes": [{"key": {"$**": 1}, "name": "idx_1"}], "indexes": [{"key": {"$**": 1}, "name": "idx_2"}]}', true); SELECT (index_spec).index_name FROM documentdb_api_catalog.collection_indexes WHERE collection_id = (SELECT collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'collection_200' AND database_name = 'db') ORDER BY 1; -- Can SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if we're not -- creating any indexes, even if we're in a xact block. BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_2", "indexes": [ {"key": {"$**": 1}, "name": "my_idx_4", "wildcardProjection": {"a": 0}} ] }', true ); ROLLBACK; -- Can SELECT documentdb_api_internal.create_indexes_non_concurrently() in a xact block if collection -- wasn't created before. -- i) using create_collection() BEGIN; SELECT documentdb_api.create_collection('mydb', 'collection_new'); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); ROLLBACK; -- ii) using a command that implicitly creates the collection -- if it doesn't exist, e.g.: insert() BEGIN; SELECT documentdb_api.insert_one('mydb','collection_new',' {"_id" : 1, "item" : "bread"}', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); ROLLBACK; -- iii) implicitly creating via create_indexes() BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); ROLLBACK; BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"a.$**": 1}, "name": "new_idx_1"} ] }', true ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_new", "indexes": [ {"key": {"c.d": 1}, "name": "new_idx_2"} ] }' ); ROLLBACK; commands_create_index_geospatial.sql000066400000000000000000000661131507310017400362440ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, postgis_public; SET citus.next_shard_id TO 167200; SET documentdb.next_collection_id TO 16720; SET documentdb.next_collection_index_id TO 16720; SELECT documentdb_api.create_collection('db', '2dindextest') IS NOT NULL; SELECT documentdb_api.create_collection('db', '2dsphereindextest') IS NOT NULL; -- Test invalid 2d index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "unique": true }]}', true); -- 2d with unique SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": "2d"}, "name": "my_2d_a_idx" }]}', true); -- Multi 2d SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": 1}, "name": "my_2d_a_idx" } ]}', true); -- Multi 2d SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"b": 1, "a": "2d"}, "name": "my_2d_a_idx" }]}', true); -- Multi 2d and 2d index is not the first one SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a.$**": "2d"}, "name": "my_2d_a_idx" }]}', true); -- 2d with wildcard SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "max": -190 } ]}', true); -- 2d with max -170 and min -180 (default) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "min": 190 } ]}', true); -- 2d with min 190 and max 180 (default) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "max": 180, "min": 180} ]}', true); -- 2d with min and max equal to 180 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "expireAfterSeconds": 20 } ]}', true); -- With TTL SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b": "text"}, "name": "my_2d_a_idx" } ]}', true); -- 2d with text SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d", "b.$**": 1}, "name": "my_2d_a_idx" } ]}', true); -- 2d followed by wildcard SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "bits": 0 } ]}', true); -- bits 0 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx", "bits": 33 } ]}', true); -- bits more than 32 -- Test invalid 2dsphere index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "unique": true }]}', true); -- 2dsphere with unique SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b": 1}, "name": "my_2ds_a_idx" } ]}', true); -- Compound 2dsphere SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"b": 1, "a": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); -- Compound 2dsphere with 1 being regular index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a.$**": "2dsphere"}, "name": "my_2ds_a_idx" }]}', true); -- 2dsphere with wildcard SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "coarsestIndexedLevel": -1 } ]}', true); -- 2dsphere with coarestIndexedLevel invalid value SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "finestIndexedLevel": 31 } ]}', true); -- 2dsphere with finestIndexedLevel invalid value SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "coarsestIndexedLevel": 32, "finestIndexedLevel": 30 } ]}', true); -- 2dsphere with finestIndexedLevel invalid value SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_a_idx", "expireAfterSeconds": 20 } ]}', true); -- With TTL SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b": "text"}, "name": "my_2ds_a_idx" } ]}', true); -- 2dsphere with different SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere", "b.$**": 1}, "name": "my_2ds_a_idx" } ]}', true); -- 2dsphere followed by wildcard -- Test valid 2d & 2dsphere index creation scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"a": "2d"}, "name": "my_2d_a_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"b.c": "2d"}, "name": "my_2d_b_c_idx" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"d": "2d"}, "name": "my_2d_d_idx", "min": -100, "max": 100 }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"e": "2d"}, "name": "my_2d_e_idx", "bits": 32 } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dindextest", "indexes": [{"key": {"pfe": "2d"}, "name": "my_2d_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"a": "2dsphere" }, "name": "my_2ds_a_idx" } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"b.c": "2dsphere" }, "name": "my_2ds_bc_idx", "coarsestIndexedLevel": 20 } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"c": "2dsphere" }, "name": "my_2ds_c_idx", "coarsestIndexedLevel": 5, "finestIndexedLevel": 25 } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"d": "2dsphere" }, "name": "my_2ds_d_idx", "finestIndexedLevel": 25 } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"e": "2dsphere", "f": "2dsphere" }, "name": "my_2ds_ef_idx" } ]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsphereindextest", "indexes": [{"key": {"g": "2dsphere", "h": "2dsphere" }, "name": "my_2ds_gh_pfe_idx", "partialFilterExpression": { "region": { "$eq": "USA" } } } ]}', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', '2dindextest') ORDER BY collection_id, index_id; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', '2dsphereindextest') ORDER BY collection_id, index_id; -- 2d index strict mode insert restrictions SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": "Hello" } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": true } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": false } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": null } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$undefined" : true } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberLong": "1" } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberDouble": "1" } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberDecimal": "1" } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": "Invalid" } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": true } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": false } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": null } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": { "$undefined": true } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"a" : { "x": { "$numberInt": "1" }, "y": "Invalid", "z": 10 } }', NULL); -- 2dsphere index strict mode insert restriction SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : "Hello" }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : true }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : false }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberInt": "1" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberLong": "1" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberDouble": "1" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "$numberDecimal": "1" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "x": 1 } }', NULL); -- Legacy object invalid format SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "x": 1, "y": "Text" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [1] }', NULL); -- Legacy array invalid format SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [1, "text"] }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "point"} }', NULL); -- Wrong type case-sensitive SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point"} }', NULL); -- coordinates missing SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coords": [1, 2]} }', NULL); -- Invalid 'coords' SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [1, "hello"]} }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [[1 , 2], [3, 4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Point", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multipoint", "coordinates": [[1 , 2], [3, 4]] } }', NULL); -- Wrong case sensitive type SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [3, 4] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [[1 , "Hello"], [3, 4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPoint", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Linestring", "coordinates": [[1,2], [3,4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": [[1, 2], [1, 2]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "LineString", "coordinates": [[1, 2], [1, 2]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multilinestring", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[1,2], [3,4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[[1, 2], [1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [[[1, 2], [1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiLineString", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "polygon", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [1, 2] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[1, 2]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3], [1,2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [-2, -1], [0, 0]]] } }', NULL); -- self intersecting polygon with 0 geometrical area SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 0], [0, 10], [10, 10], [0, 0], [1, 0]]] } }', NULL); -- self intersecting polygon with non-zero geometrical area SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 10], [0, 70], [75, 75], [75, 25], [0, 10]]] } }', NULL); -- hole edge lies on outer ring edge SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[0, 0], [0, 80], [75, 75], [75, 25], [0, 0]]] } }', NULL); -- hole shares an edge with outer ring SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[0, 0], [0, 80], [80, 80], [80, 0], [0, 0]],[[10, 10], [10, 70], [75, 75], [75, 25], [10, 10]],[[10,20], [10,30], [50, 50], [10, 20]]] } }', NULL); -- 3rd ring edge lies on 2nd ring edge SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Polygon", "coordinates": [[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "Multipolygon", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": "non-array" } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [1, 2] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[1, 2]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3], [1,2]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 1], [1, 5], [3, 4], [0, 3], [1, 1]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]], [[0, 0], [0, 6], [6, 6], [6, 0], [0, 0]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [2, 3], [1, 2], [3, 4], [1, 2]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": {} } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "coordinates": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [1, 2] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [1, 2]}, 2] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": ["Hello", 2]}] } }', NULL); -- Multi key failure cases SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], "Invalid point" ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, true] ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, false] ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, null] ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, "point"] ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : { "c": [ [10, 10], [20, { "$undefined": true }] ] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{"b" : [ { "c": [10, 20] }, { "c": { "long": "100", "lat": "100" } }, [ 30, "text"] ] }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [{"type": "Point", "coordinates": [10, 20]}, {"type": "Point", "coordinates": [10, 20]}] }', NULL); -- This is not supported as multi key SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [[10, 20], [20, 20]] }', NULL); -- This is not supported as multi key legacy SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "a" : [ { "x" : 1, "y" : 1 }, { "x" : 2, "y" : 2 }, { "x" : 3, "y" : 3 } ] }', NULL); -- This is not supported as multi key legacy SELECT documentdb_api.insert_one('db','2dsphereindextest','{"_id": 1, "b" : [ {"c" : {"type": "Point", "coordinates": [10, 20]} }, {"c" : {"type": "Point", "coordinates": ["Text", 20]} } ] }', NULL); -- Some case which are valid where the field is either empty object/document or not of type object/document -- These cases generate NULL geometries and are not indexed SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 1, "a" : "Hello" }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 2, "a" : true }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 3, "a" : false }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 4, "a" : 10 }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 5, "a" : [] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 6, "a" : { } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 7, "a" : { "$undefined": true } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 8, "a" : [ { }, [ ] ] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 9, "a" : { "field": [] } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 10, "a" : { "field": { } } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 101, "a" : null }', NULL); SELECT documentdb_api.insert_one('db', '2dindextest','{ "_id": 102, "b": [{"c": null}, {"c": {"$undefined": true}}]}'); -- Valid insertions where 2d geometery index terms are generated SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 11, "a" : [11, 11] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 12, "a" : { "long": 12, "lat": 12 } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 13, "a" : [13, 13, 11] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 14, "a" : { "long": 14, "lat": 14, "extra": 1414 } }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 15, "a" : [ [ 15.1, 15.1 ], [15.2, 15.2] ] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 16, "a" : [ [ 16.1, 16.1 ], [16.2, 16.2], { }, [16.3, 16.3], [16.4, 16.4] ] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "_id" : 18, "a" : [ [ { "$numberLong": "18" }, { "$numberInt": "18" } ], [ { "$numberDouble": "18.1" }, { "$numberDecimal": "18.2" }] ] }', NULL); -- Out of boundary check- errors SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [-120, 10] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [10, 120] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "-100.000001" }, 80] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "80" }, { "$numberDecimal": "100.000001" }] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "-inf" }, { "$numberDecimal": "20" }] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ { "$numberDouble": "20" }, { "$numberDecimal": "inf" }] }', NULL); SELECT documentdb_api.insert_one('db','2dindextest','{ "d" : [ [10, 20], [-200, 200]] }', NULL); -- NULL values for 2dsphere index SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : null }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "$undefined": true } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"b": [{"c": null}, {"c": {"$undefined": true}}]}'); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"z" : "Text" }', NULL); -- index field missing -- Valid GeoJson inserts for 2dsphere indexes SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : [ 5, 10] }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "x": 5 , "y": 10} }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Point", "coordinates": [5, 10] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Point", "coordinates": { "x": 5, "y": 10 } } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiPoint", "coordinates": [[1 , 2], [3, 4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "LineString", "coordinates": [[1,2], [3,4]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiLineString", "coordinates": [[[1,2], [3,4]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[1, 2], [1, 2], [1,3], [2, 3], [2, 2], [1, 2]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "MultiPolygon", "coordinates": [[[[1, 2], [1, 2], [1,3], [2, 3], [2, 2], [1, 2]]]] } }', NULL); SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : { "type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [1, 2]}] } }', NULL); -- Valid polygon inserts for 2dsphere index SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[0.0, 0.0], [60.0, 0.0], [90.0, 0.0], [0.0, 0.0]]] } }', NULL); -- all points on equator SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[0, 0], [0 ,4], [0, 6], [0, 8], [0, 0]]] } }', NULL); -- all points on the same longitude SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[-120, 60.0], [0.0, 60.0], [60.0, 60.0], [90.0, 60.0], [-120.0, 60.0]]] } }', NULL); -- all points on same latitude SELECT documentdb_api.insert_one('db','2dsphereindextest','{"a" : {"type": "Polygon", "coordinates": [[[-120.0, 60], [-60, 60], [0, 60], [120, 60], [-120.0, 60]], [[-120.0, 70], [-60, 70], [0, 70], [120, 70], [-120.0, 70]]] } }', NULL); -- points on a single latitude, polygon going around the earth with similar hole -- Test whether invalid document after valid documents are correctly errored out without OOM BEGIN; set local enable_seqscan TO on; -- Valid and then invalid doc for `a` 2dsphere field SELECT documentdb_api.insert_one('db','2dsOOMTest','{ "_id" : 1, "a": [2.1, 2.2] }', NULL); SELECT documentdb_api.insert_one('db','2dsOOMTest','{ "_id" : 2, "a": "Text" }', NULL); -- error while building the index and should not OOM SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "2dsOOMTest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds_oom_idx" }]}', true); ROLLBACK; commands_create_indexes.sql000066400000000000000000001132571507310017400343660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 110000; SET documentdb.next_collection_id TO 11000; SET documentdb.next_collection_index_id TO 11000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; ---- createIndexes - top level - parse error ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', NULL, true); SELECT documentdb_api_internal.create_indexes_non_concurrently(NULL, '{}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "unknown_field": []}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": null, "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": null}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": 5}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": []}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1"}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": 1}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": 1}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [1,2]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": 1}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": 1}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"unique": "1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"unknown_field": "111"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "_name_", "unknown_field": "111"}]}', true); ---- createIndexes - indexes.key - parse error ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"": 1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": 1, "b": -1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {".$**": 1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": "bad"}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": 0}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": ""}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**": {"a": 1}}, "name": "my_idx"}]}', true); -- note that those are valid .. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": 1}, "name": "my_idx_3"}]}', true); -- valid sparse index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse_num": 1}, "name": "my_sparse_num_idx1", "sparse": 1}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"asparse_num": 1}, "name": "my_non_sparse_num_idx1", "sparse": 0}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.double": 1}, "name": "my_sparse_double_idx1", "sparse": 0.2}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": null, "createIndexes": "collection_1", "indexes": [{"key": 0, "key": {"bsparse": 1}, "name": "my_non_sparse_idx1", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"cs.$**": 1}, "name": "my_wildcard_non_sparse_idx1", "sparse": false}]}', true); -- invalid sparse indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": "true"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"bs.a": 1}, "name": "my_sparse_with_pfe_idx", "sparse": true, "partialFilterExpression": { "rating": { "$gt": 5 } }}]}', true); -- sparse can create index for same key with different sparse options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_sparse_a_b_idx", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx", "sparse": false}]}', true); -- valid hash indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": "hashed"}, "name": "my_idx_hashed"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": "hashed", "b": 1 }, "name": "my_idx_hashed_compound"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1, "b": "hashed" }, "name": "my_idx_hashed_compound_hash"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "hashed"}, "name": "my_idx_dollar_name_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.c$": "hashed"}, "name": "my_idx_dollar_name_2"}]}', true); -- invalid hash indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed" }, "unique": 1, "name": "invalid_hashed"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed", "c": "hashed" }, "name": "invalid_hashed"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": "hashed", "c": 1, "d": "hashed" }, "name": "invalid_hashed"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b.$**": "hashed" }, "name": "invalid_hashed"}]}', true); -- can't create index on same key with same sparse options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx2", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx3", "sparse": true}]}', true); -- passing named args is also ok SELECT documentdb_api_internal.create_indexes_non_concurrently(p_database_name=>'db', p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"c.a$**": 1}, "name": "my_idx_4"}]}', p_skip_check_collection_create=>true); SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"d.a$**": 1}, "name": "my_idx_5"}]}', p_database_name=>'db', p_skip_check_collection_create=>true); -- invalid index names SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1 }, "name": "*"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1 }, "name": "name\u0000field"}]}', true); -- For the next test, show the commands that we internally execute to build -- & clean-up the collection indexes. SET client_min_messages TO DEBUG1; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5"}, {"key": {"x.y": 1}, "name": "valid_index_2"} ] }', p_skip_check_collection_create=>true ); RESET client_min_messages; -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') ORDER BY collection_id, index_id; -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'collection_1') ORDER BY indexrelid; -- .., but those are not SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**foo": 1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$**.foo": 1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": -1, "a.$**": 1}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {}, "name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"name": "my_idx"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**foo": 1}, "name": "my_idx_13"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"..": 1}, "name": "my_idx_12"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a..b.$**": 1}, "name": "my_idx_10"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a..b.foo": 1}, "name": "my_idx_11"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"$a": 1}, "name": "my_idx_12"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {".": 1}, "name": "my_idx_12"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$b": 1}, "name": "my_idx_12"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.$b.$**": 1}, "name": "my_idx_12"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a.": 1}, "name": "my_idx_12"}]}', true); -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') ORDER BY collection_id, index_id; -- also show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'collection_1') ORDER BY indexrelid; -- create a valid index. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') WHERE index_spec_as_bson OPERATOR(documentdb_api_catalog.@@) '{"name": "my_idx_14"}' ORDER BY collection_id, index_id; -- creating the same index should noop SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}', true); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'collection_1') WHERE index_spec_as_bson OPERATOR(documentdb_api_catalog.@@) '{"name": "my_idx_14"}' ORDER BY collection_id, index_id; -- not the same index since this specifies partialFilterExpression SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14", "partialFilterExpression": {"a": 1}}]}', true); -- valid index type in the reference implementation, which are not supported yet SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "2d"}, "name": "my_idx_2d"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "2dsphere"}, "name": "my_idx_2dsphere"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a$**": "text"}, "name": "my_idx_text"}]}', true); -- test "v" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2.1234, "name": "invalid_v"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 10000000000000000, "name": "invalid_v"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": -10000000000000000, "name": "invalid_v"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 100, "name": "invalid_v"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2.0, "name": "valid_v"}]}', true); -- same index since 2.0 == 2 SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": 1}, "v": 2, "name": "valid_v"}]}', true); -- following are assumed to be identical to built-in _id index even if their names are different than "_id_" SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1}, "name" : "_id_1"}, {"key": {"_id": 1.0}, "name" : "_id_2"}]}', true); -- but this is not identical to built-in _id index, so we will create it SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1.2}, "name" : "_id_3"}]}', true); -- and this conflicts with _id_3 since key != {"_id": 1}, so we will throw an error SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_1", "indexes" : [{"key": {"_id": 1.2}, "name" : "_id_4"}]}', true); -- background is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.a": 1}, "name": "my_idx_6", "background": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); -- hidden false is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.b": 1}, "name": "my_idx_7", "hidden": false }]}', p_database_name=>'db', p_skip_check_collection_create=>true); -- hidden true fails. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.c": 1}, "name": "my_idx_8", "hidden": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); -- ns is ignored. SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.f": 1}, "name": "my_idx_9", "ns": "foo.bar" }]}', p_database_name=>'db', p_skip_check_collection_create=>true); -- readPreference is ignored SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_1", "indexes": [{"key": {"e.g": 1}, "name": "my_idx_10" }], "$readPreference": { "mode": "secondary" }}', p_database_name=>'db', p_skip_check_collection_create=>true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); BEGIN; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); ROLLBACK; SELECT documentdb_api.create_collection('db', 'too_many_indexes'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "too_many_indexes", "indexes": [{"key": {"a0": 1}, "name": "a0"},{"key": {"a1": 1}, "name": "a1"},{"key": {"a2": 1}, "name": "a2"},{"key": {"a3": 1}, "name": "a3"},{"key": {"a4": 1}, "name": "a4"},{"key": {"a5": 1}, "name": "a5"},{"key": {"a6": 1}, "name": "a6"},{"key": {"a7": 1}, "name": "a7"},{"key": {"a8": 1}, "name": "a8"},{"key": {"a9": 1}, "name": "a9"},{"key": {"a10": 1}, "name": "a10"},{"key": {"a11": 1}, "name": "a11"},{"key": {"a12": 1}, "name": "a12"},{"key": {"a13": 1}, "name": "a13"},{"key": {"a14": 1}, "name": "a14"},{"key": {"a15": 1}, "name": "a15"},{"key": {"a16": 1}, "name": "a16"},{"key": {"a17": 1}, "name": "a17"},{"key": {"a18": 1}, "name": "a18"},{"key": {"a19": 1}, "name": "a19"},{"key": {"a20": 1}, "name": "a20"},{"key": {"a21": 1}, "name": "a21"},{"key": {"a22": 1}, "name": "a22"},{"key": {"a23": 1}, "name": "a23"},{"key": {"a24": 1}, "name": "a24"},{"key": {"a25": 1}, "name": "a25"},{"key": {"a26": 1}, "name": "a26"},{"key": {"a27": 1}, "name": "a27"},{"key": {"a28": 1}, "name": "a28"},{"key": {"a29": 1}, "name": "a29"},{"key": {"a30": 1}, "name": "a30"},{"key": {"a31": 1}, "name": "a31"},{"key": {"a32": 1}, "name": "a32"},{"key": {"a33": 1}, "name": "a33"},{"key": {"a34": 1}, "name": "a34"},{"key": {"a35": 1}, "name": "a35"},{"key": {"a36": 1}, "name": "a36"},{"key": {"a37": 1}, "name": "a37"},{"key": {"a38": 1}, "name": "a38"},{"key": {"a39": 1}, "name": "a39"},{"key": {"a40": 1}, "name": "a40"},{"key": {"a41": 1}, "name": "a41"},{"key": {"a42": 1}, "name": "a42"},{"key": {"a43": 1}, "name": "a43"},{"key": {"a44": 1}, "name": "a44"},{"key": {"a45": 1}, "name": "a45"},{"key": {"a46": 1}, "name": "a46"},{"key": {"a47": 1}, "name": "a47"},{"key": {"a48": 1}, "name": "a48"},{"key": {"a49": 1}, "name": "a49"},{"key": {"a50": 1}, "name": "a50"},{"key": {"a51": 1}, "name": "a51"},{"key": {"a52": 1}, "name": "a52"},{"key": {"a53": 1}, "name": "a53"},{"key": {"a54": 1}, "name": "a54"},{"key": {"a55": 1}, "name": "a55"},{"key": {"a56": 1}, "name": "a56"},{"key": {"a57": 1}, "name": "a57"},{"key": {"a58": 1}, "name": "a58"},{"key": {"a59": 1}, "name": "a59"},{"key": {"a60": 1}, "name": "a60"},{"key": {"a61": 1}, "name": "a61"},{"key": {"a62": 1}, "name": "a62"},{"key": {"a63": 1}, "name": "a63"}, {"key": {"a64": 1}, "name": "a64"}]}', true); SET documentdb.enable_large_unique_index_keys TO false; -- dropDups is ignored. SELECT documentdb_api.insert_one('db','dropdups_ignore','{"_id": "1", "a": "dup" }', NULL); SELECT documentdb_api.insert_one('db','dropdups_ignore','{"_id": "2", "a": "dup" }', NULL); SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "dropdups_ignore", "indexes": [{"key": {"a": 1}, "name": "dropdups_ignore_idx_1", "dropDups": true, "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); select documentdb_api.delete('db', '{"delete":"dropdups_ignore", "deletes":[{"q":{"_id": "2"}, "limit": 0 } ] }'); SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "dropdups_ignore", "indexes": [{"key": {"a": 1}, "name": "dropdups_ignore_idx_1", "dropDups": true, "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); SET documentdb.enable_large_unique_index_keys TO true; -- tests with ignoreUnknownIndexOptions -- -- invalid values of ignoreUnknownIndexOptions SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "ignoreUnknownIndexOptions": "hello" }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "ignoreUnknownIndexOptions": {"b":1} }', true); -- -- ignoreUnknownIndexOptions of false (default value) will trigger error if there is any unknown field in index options. (unknown field is "dog" in these examples) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": false }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 0.0 }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": null }', true); -- -- ignoreUnknownIndexOptions of true will ignore any unknown field in index options. (unknown field is "dog" in these examples) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"a": 1}, "name": "a_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": true }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"b": 1}, "name": "b_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 0.1 }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"c": 1}, "name": "c_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": -5.6 }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "indexColl_1", "indexes": [{"key": {"d": 1}, "name": "d_1", "dog": "pazu"}], "ignoreUnknownIndexOptions": 1 }', true); -- index term options -- we flow index term size option to the indexes that should truncate only SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "a": 1 }, "name": "indexa"}] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "$**": 1 }, "name": "indexwildcard"}] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "a": 1, "b": 1 }, "name": "indexcompound"}] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "indexTermSizeLimit", "indexes": [ { "key" : { "$**": 1 }, "wildcardProjection": {"a": 0}, "name": "index_wildcard_projection"}] }', true); WITH c1 AS (SELECT collection_id from documentdb_api_catalog.collections where collection_name = 'indexTermSizeLimit' and database_name = 'db') SELECT indexdef FROM pg_indexes, c1 where tablename = 'documents' || '_' || c1.collection_id and schemaname = 'documentdb_data' ORDER BY indexname ASC; SET documentdb.enable_large_unique_index_keys TO false; -- for hashed, unique and text indexes we should not see the limit as those shouldn't be truncated SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": "hashed" }, "name": "a_hashed" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "noIndexTermSizeLimit", "indexes": [ { "key": { "a": 1 }, "name": "a_unique", "unique": true } ] }', true); SET documentdb.enable_large_unique_index_keys TO true; WITH c1 AS (SELECT collection_id from documentdb_api_catalog.collections where collection_name = 'noIndexTermSizeLimit' and database_name = 'db') SELECT indexdef FROM pg_indexes, c1 where tablename = 'documents' || '_' || c1.collection_id and schemaname = 'documentdb_data' ORDER BY indexname ASC; SELECT ('{ "createIndexes": "indexColl_1", "indexes": [{ "key": { "description1": 1, "description2": 1, "description3": 1, "description4": 1, "description5": 1, "description6": 1, "description7": 1, "description8": 1, ' || ' "description9": 1, "description10": 1, "description11": 1, "description12": 1, "description13": 1, "description14": 1, "description15": 1, "description16": 1, "description17": 1, ' || ' "description18": 1, "description19": 1, "description20": 1 } ' || ', "name": "description1_1_description2_1_description3_1_description4_1_description5_1_description6_1_description7_1_description8_1_description9_1_description10_1' || '_description11_1_description12_1_description13_1_description14_1_description15_1_description16_1_description17_1_description18_1_description19_1_description20_1" } ]}')::bson; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "description1" : 1, "description2" : 1, "description3" : 1, "description4" : 1, "description5" : 1, "description6" : 1, "description7" : 1, "description8" : 1, "description9" : 1, "description10" : 1, "description11" : 1, "description12" : 1, "description13" : 1, "description14" : 1, "description15" : 1, "description16" : 1, "description17" : 1, "description18" : 1, "description19" : 1, "description20" : 1 }, "name" : "description1_1_description2_1_description3_1_description4_1_description5_1_description6_1_description7_1_description8_1_description9_1_description10_1_description11_1_description12_1_description13_1_description14_1_description15_1_description16_1_description17_1_description18_1_description19_1_description20_1" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "%s" : 1 }, "name" : "%s_1" } ] }', repeat('a', 1200), repeat('a', 1200))::bson, true); -- try 2 columns (super long) SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "%s" : 1, "b_%s": 1 }, "name" : "%s_1_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); -- 4/5 super long columns SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1, "c_%s": 1, "d_%s": 1 }, "name" : "a_b_c_d_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); -- 10 super long columns SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1, "c_%s": 1, "d_%s": 1, "e_%s": 1, "f_%s": 1, "g_%s": 1, "h_%s": 1, "i_%s": 1, "j_%s": 1 }, "name" : "a_b_c_d_e_f_g_h_i_j_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200), repeat('a', 1200))::bson, true); -- but 1 super long name fails SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1 }, "name" : "a_%s_1" } ] }', repeat('a', 1500), repeat('a', 1200))::bson, true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1500), repeat('a', 1500), repeat('a', 1200))::bson, true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1500), repeat('a', 1200))::bson, true); -- however the name can be however long we want SELECT documentdb_api_internal.create_indexes_non_concurrently('db', FORMAT('{ "createIndexes" : "indexColl_1", "indexes" : [ { "key" : { "a_%s" : 1, "b_%s": 1 }, "name" : "a_b_%s_1" } ] }', repeat('a', 1200), repeat('a', 1200), repeat('a', 9000))::bson, true); -- tests with blocking -- -- invalid values of blocking SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"a": 1}, "name": "a_1"}], "blocking": "hello" }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"b": 1}, "name": "b_1"}], "blocking": {"b":1} }', true); -- -- blocking of false (default value) will trigger create index concurrently. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"c": 1}, "name": "c_1"}] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"d": 1}, "name": "d_1"}], "blocking": false }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"e": 1}, "name": "e_1"}], "blocking": 0.0 }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"f": 1}, "name": "f_1"}], "blocking": null }', true); -- -- blocking of true will trigger create index non-concurrently. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"g": 1}, "name": "g_1"}], "blocking": true }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"h": 1}, "name": "h_1"}], "blocking": 1.0 }', true); -- Collection is not created in the same call ---- when blocking:true, we will let create index execute even if collection is not created in the call SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"i": 1}, "name": "i_1"}], "blocking": true }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "blocking_index", "indexes": [{"key": {"j": 1}, "name": "j_1"}], "blocking": false }'); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'blocking_index') ORDER BY collection_id, index_id; commands_create_indexes_background.sql000066400000000000000000000650031507310017400365600ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 320000; SET documentdb.next_collection_id TO 32000; SET documentdb.next_collection_index_id TO 32000; CREATE SCHEMA change_index_jobs_schema; CREATE OR REPLACE FUNCTION change_index_jobs_schema.change_index_jobs_status(active_status boolean) RETURNS void AS $$ DECLARE job_id integer; BEGIN FOR job_id IN (SELECT jobid FROM cron.job WHERE jobname LIKE 'documentdb_index_%' order by jobid) LOOP UPDATE cron.job SET active = active_status WHERE jobid = job_id; RAISE NOTICE 'Processing job_id: %', job_id; END LOOP; END; $$ LANGUAGE plpgsql; SET search_path to documentdb_core,documentdb_api,documentdb_api_catalog,change_index_jobs_schema; -- Delete all old create index requests from other tests DELETE from documentdb_api_catalog.documentdb_index_queue; ---- createIndexes - top level - parse error ---- SELECT * FROM documentdb_api.create_indexes_background('db', NULL); SELECT * FROM documentdb_api.create_indexes_background(NULL, '{}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "unknown_field": []}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": null, "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": null}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": 5}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": []}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6"}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": 1}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": 1}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [1,2]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": 1}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": 1}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"unique": "1"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1}}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"unknown_field": "111"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "_name_", "unknown_field": "111"}]}'); ---- createIndexes - indexes.key - parse error ---- SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"": 1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1, "": -1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": 1, "b": -1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {".$**": 1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": "bad"}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": 0}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": ""}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**": {"a": 1}}, "name": "my_idx"}]}'); SELECT index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt, user_oid FROM documentdb_api_catalog.documentdb_index_queue ORDER BY index_id; -- note that those are valid .. SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_1"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": 1}, "name": "my_idx_3"}]}'); -- valid sparse index SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse": 1}, "name": "my_sparse_idx1", "sparse": true}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse_num": 1}, "name": "my_sparse_num_idx1", "sparse": 1}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"asparse_num": 1}, "name": "my_non_sparse_num_idx1", "sparse": 0}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.double": 1}, "name": "my_sparse_double_idx1", "sparse": 0.2}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": null, "createIndexes": "collection_6", "indexes": [{"key": 0, "key": {"bsparse": 1}, "name": "my_non_sparse_idx1", "sparse": false}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"cs.$**": 1}, "name": "my_wildcard_non_sparse_idx1", "sparse": false}]}'); -- invalid sparse indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": true}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.$**": 1}, "name": "my_wildcard_sparse_idx1", "sparse": "true"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"bs.a": 1}, "name": "my_sparse_with_pfe_idx", "sparse": true, "partialFilterExpression": { "rating": { "$gt": 5 } }}]}'); -- sparse can create index for same key with different sparse options SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_sparse_a_b_idx", "sparse": true}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx", "sparse": false}]}'); -- valid hash indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": "hashed"}, "name": "my_idx_hashed"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": "hashed", "b": 1 }, "name": "my_idx_hashed_compound"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1, "b": "hashed" }, "name": "my_idx_hashed_compound_hash"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "hashed"}, "name": "my_idx_dollar_name_1"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.c$": "hashed"}, "name": "my_idx_dollar_name_2"}]}'); -- invalid hash indexes SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed" }, "unique": 1, "name": "invalid_hashed"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed", "c": "hashed" }, "name": "invalid_hashed"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": "hashed", "c": 1, "d": "hashed" }, "name": "invalid_hashed"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b.$**": "hashed" }, "name": "invalid_hashed"}]}'); -- can't create index on same key with same sparse options SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx1"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx2", "sparse": false}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.sparse.b": 1}, "name": "my_non_sparse_a_b_idx3", "sparse": true}]}'); -- passing named args is also ok SELECT * FROM documentdb_api.create_indexes_background(p_database_name=>'db', p_index_spec=>'{"createIndexes": "collection_6", "indexes": [{"key": {"c.a$**": 1}, "name": "my_idx_4"}]}'); SELECT * FROM documentdb_api.create_indexes_background(p_index_spec=>'{"createIndexes": "collection_6", "indexes": [{"key": {"d.a$**": 1}, "name": "my_idx_5"}]}', p_database_name=>'db'); -- invalid index names SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1 }, "name": "*"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a": 1 }, "name": "name\u0000field"}]}'); -- For the next test, show the commands that we internally execute to build -- & clean-up the collection indexes. SET client_min_messages TO DEBUG1; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT * FROM documentdb_api.create_indexes_background( p_database_name=>'db', p_index_spec=>'{ "createIndexes": "collection_6", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5"}, {"key": {"x.y": 1}, "name": "valid_index_2"} ] }'); RESET client_min_messages; -- SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**foo": 1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$**.foo": 1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"b": -1, "a.$**": 1}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {}, "name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"name": "my_idx"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"$**foo": 1}, "name": "my_idx_13"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"..": 1}, "name": "my_idx_12"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a..b.$**": 1}, "name": "my_idx_10"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a..b.foo": 1}, "name": "my_idx_11"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"$a": 1}, "name": "my_idx_12"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {".": 1}, "name": "my_idx_12"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$b": 1}, "name": "my_idx_12"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.$b.$**": 1}, "name": "my_idx_12"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a.": 1}, "name": "my_idx_12"}]}'); -- valid index type in the reference implementation, which are not supported yet SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "2d"}, "name": "my_idx_2d"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "2dsphere"}, "name": "my_idx_2dsphere"}]}'); SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"a$**": "text"}, "name": "my_idx_text"}]}'); -- create a valid index. SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}'); -- creating the same index should noop SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}]}'); -- two index spec one already exists and another is new SELECT * FROM documentdb_api.create_indexes_background('db', '{"createIndexes": "collection_6", "indexes": [{"key": {"start_path": 1}, "name": "my_idx_14"}, {"key": {"another_path": 1}, "name": "my_idx_15"}]}'); -- Delete all old create index requests submitted so far DELETE from documentdb_api_catalog.documentdb_index_queue; -- The create_indexes_background creates a remote connection via run_command_on_coordinator. Therefore, setting sequence instead of GUC. CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a"} ] }' ); CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"b": 1}, "name": "my_idx_b"} ], "blocking": true }', p_log_index_queue => true ); CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"block_c": 1}, "name": "my_idx_blocking_c", "storageEngine": { "blocking": true }} ] }', p_log_index_queue => true ); -- Queue should be empty SELECT index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt, user_oid FROM documentdb_api_catalog.documentdb_index_queue ORDER BY index_id; SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'createIndex_background_1') ORDER BY 1,2; -- Show that we didn't leave any invalid pg indexes behind SELECT indexrelid::regclass, indisvalid, indisready FROM documentdb_distributed_test_helpers.get_data_table_indexes('db', 'createIndex_background_1') ORDER BY indexrelid; CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"c": 1}, "name": "my_idx_c"}, {"key": {"d": 1}, "name": "my_idx_d"} ] }', p_log_index_queue => true ); -- Index request submission will fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"c": 1}, "name": "my_idx_c", "unique": true} ] }' ); -- create one concurrent and one blocking. CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "createIndex_background_1", "indexes": [ {"key": {"block_e": 1}, "name": "my_idx_block_e"}, {"key": {"block_f": 1}, "name": "my_idx_block_f", "storageEngine": { "blocking": true } } ] }', p_log_index_queue => true ); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'createIndex_background_1') ORDER BY 1,2; -- Test unique and non-unique index creation in same request ------ check the intermediate response SELECT documentdb_api_internal.create_indexes_background_internal( 'db', '{ "createIndexes": "intermediate", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true}, {"key": {"b": 1}, "name": "my_idx_b" } ] }' ); --- sleep for 2 seconds, so above request is processed by cron-job SELECT pg_sleep(2); ------ check the end-to-end success flow SELECT documentdb_api.insert_one('db','mycol', '{"_id": 1, "a" : 80, "b" : 10 }', NULL); SELECT documentdb_api.insert_one('db','mycol', '{"_id": 2, "a" : 90, "b" : 20 }', NULL); CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "mycol", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true}, {"key": {"b": 1}, "name": "my_idx_b" } ] }' ); SELECT * FROM documentdb_distributed_test_helpers.count_collection_indexes('db', 'mycol') ORDER BY 1,2; -- Test constraint violation for unique index, insert duplicate docs SELECT documentdb_api.insert_one('db','constraint', '{"_id": 1, "a" : 80 }', NULL); SELECT documentdb_api.insert_one('db','constraint', '{"_id": 2, "a" : 80 }', NULL); CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); -- try multiple such requests which are going to fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); -- try multiple such requests which are going to fail CALL documentdb_distributed_test_helpers.create_indexes_background( 'db', '{ "createIndexes": "constraint", "indexes": [ {"key": {"a": 1}, "name": "my_idx_a", "unique": true} ] }' ); -- test skippable error test CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "ValidateVectorSearchAsync", "indexes": [ { "name": "largeVectorIndex", "key": { "largevector": "cosmosSearch"}, "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 2001 } } ] }'); CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "ValidateVectorSearchAsync", "indexes": [ { "name": "largeVectorIndex", "key": { "largevector": "cosmosSearch"}, "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "COS", "dimensions": 2001 } } ] }'); -- test another skippable error SELECT documentdb_api.insert_one('db','LargeKeySize', '{"_id": 1, "a" : [ "p86PXqGpykgF4prF9X0ouGVG7mkRGg9ZyXZwt25L49trG5IQXgrHdkR01ZKSBlZv8SH04XUych6c0HNvS6Dn17Rx3JgKYMFqxSTyhRZLdlmMgxCMBE7wYDrvtfCPRgeDPGOR4FTVP0521ulBAnAdoxub6WndMqLhGZKymTmmjdCJ28ka0fnN47BeMPy9jqllCfuWh6MUg4bSRrvkopOHgkXx0Jdg7KwLsvfozsoVzKVI1BYlV6ruz1QipKZTRgAJVUYEzG9qA28ZBFu6ZLN0vzeXpPlxNbPu4pwLcPISxCNmgIeDm397Bs9krq0OCqhqhVJzYaLLmcTipuqi0mmPYNBF5RYfiEWeLmarJzW4oirL1s6d8EMGqvlRW5M6GY5OCUo5BfvADGpa8VQ3dGF1GKs05U7IWax6am9TOuq6hXWuhw3r8pmv0OvhqNmh0Wm9rAoK2zEHnuwoUqh57McwWx5gvouiZQdgDrRlU0IAvv4wpPwtgoAZpNje9ZPNywbrdYkKdy3CPGDf4bhreNvnOVx2aIfY3ZlQCL8RWXjIN1HWhb8nRTZuaqJVDh8lnB8kessHCrS0tTLEcnjZIRVPXge5F3AD2x4PYrP1jthursnY6XqqzZVvN2PEia9AXyqvAi8447AONDn27AqUEDRCVBg8l4DzbZ7O2OUOyG3nBE78xDdQMbpkhmPF0MPiihgZtcPLxB4E36I5Kr1g0ecmX6XsFN2FFDDHg0R8oi120fnm33UWWwpfM13czkJKzkGucSDv0NO0nrmd0yxlTwLCwYg3IOP62pyUFfZNj755sbXigEajKcypSgNdCcVJ8fak9xhe575FmcA1LSr8qOKKCyy3bZdyFKuwDtAtCOrlp2Ay5qtqIJhovZp3ek6U1ZKlLAXPf5Xk661XHOLuFNExn7vyMxeFKb9v2EWmdrO622ylfc0xnGnOc2yT7lAE7w1x4AGxBdgjI3q052o4gWfALRDjbhEK39sM2rpTIwMrvsSo35rsv5p9mQ2zQCL1OUBHQHmDFEzfH7zanSgISWGYjdbpGoyo3JxhcypqUxx7jB4DIe20i3fGbdpFOKVirFjZ4LyfaDgGWGaW6eD7XyAigTuajLe5NpXBJOAQr31C8YYl1XlWZSBv8jdOjpLE8BixgHsXTldxzh7QxPQH2eKO74FeDySOZCNlsHENbQHbwfQJRxz33oHpr0dsNRn2AYCP6mOFJ8G9AASMx6jSP5j2ZRZGFb6GKhG2FyiIklRTPvtu14aMPTgD0tPBlXEWwi6IuynzrXXzOY3BodDRk2EwkruuuuEwCuSd82HJDuChSWf2A9duqv9J0UrbYuXN9NWOVypBq4tlY6joGUPe509Z4EQEKAmFIUV0GBQixzt1tPVgBs9esNvNFSftzKgYBS4FJe489UWwaX3njm5uQYW7wFJuqcI4A0MrfOYJSgJwzvtfaKwu95yAtjW7QgLPG355RkKsjZDLZdjuNvjN17yYC0xchIaBGaK6cIGDjRV2mnmKHaaLRrEwjKqS1F1FCH19JnXSB1OoDdcoEYAbQwK2Kd0KWKh6tslohWoPWvFlOXBzZOEnPNENpU8xxD8mHxYDr8siiaknwRMvqf4yP2Oe4v7GFwOrMmR6UJknUu7xp2HvsjqceO5g7nkuUyiec4lk1sPraMygpBAboLCB3S4qSfNqtfJj0vwZVXmmK3lJyrh2dgJ7botypjDE1ENq6vovXKtZ7OYfE81V2ic5qnSKakbwmsiS3uywVjuvFtDBwgZQBhEMqcG6txa9qNINGA5Xbt1xnhJbFuxaykJpBTGtYAem00AX5ZRTVPy57WRue1aIvopDx92yL2Lw3eWSebATumO91PYlVDUhHzaQ232MS2hrHbKZYWguCb9UU3Wrsu9f5dybJDhJhE7jOnDb4hYJvdxQH8Ni7cELn4bf0AxXTQ74RJM2ZiPCAG8CYtpDcaHnU4BEfs5stjBOX1rWgQihsz5fbCEZOcDYJ5om5Gwk3R12Q49Ly3IARzsVTZnswxfpOfq6bIY9oKLpYanNDaf9ZhZEaa2MwOA9Ruiy4RmquYoJ92gBxS1l1FC8jYlCEfvSAkylhSA54TsWVVIwsOZd6Hj3RQQZtQcJEIMIHPxdTNUx1sSMCItVbTikTw8gviNtI1UM6VOJxiqBsdOmfy8WbfP7djRbRUBwCnCFoaEIFrAQfebevG6hxQ6MbeVP17ythvVUlDSJL2Bn7KmwNBj7Aido8RmBUPXuTxZzMpuLjn1q0Wm4FMz232XddybeBnELMMDkEWUqPL94xo1AdfhtXQ2WhpIJKHsSqj6vv51PnmfzmHZaqXkWIY6WhCf7SsBMojqBUEEI3VYKxcQ5IBzvX284CrH5x2M6AoGpANFp036l6cor9VBVYHyXODCBO1ACMDe9YENwatNgWhpiu2W6Ao1jE5vs00Vk9j4gY9NFPNrjpw5gFgRdinELZAyd2akBSoYdXxBt9NtfVJEYl2OiblplIOgB7fi4HEho4JtNhmyS3P3BdlQkRAciVHfHKAOdi2dBZxxVFJjqBuVW4Svv6XJuYYLPMJiPGrgV3rvlzlUdUAn0LKsga4BEn4cPoRnRPPYgj7L5bkqMxonzRiCBkMU4HTYBTrVfNqu7zHLcMQwc9lIEHYHDN2JyqEr0emG5B8NMqDJFwUHIILvA5pUuZQT5PV87QpLs8n24vV5YHqFDFm7KlGxan3Hdy5Zw4PaQsROlwIxFGFuHUXi6B4nn8KYZlULfAQ7stk4DDukrPmOXlbbDOhNHu2pXqejS12MTOYZ3" ] }'); CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "LargeKeySize", "indexes": [ { "key" : { "a": 1 }, "name": "rumConstraint1"}] }'); CALL documentdb_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "UnsupportedLanguage", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "ok" } ] }'); --Reset -- so that other tests do not get impacted SELECT change_index_jobs_schema.change_index_jobs_status(false); -- test CheckForIndexCmdToFinish DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- add dummy entries INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id, comment) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32101, 3, 32000, '{"err_msg" : "deadlock detected", "err_code" : { "$numberInt" : "16908292" }}'); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, global_pid, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 10015415, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'R', 32105, 2, 32000); -- this should return finish : 1, ok : 0 and error message due to index_id 32101 SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test failure but no comment. INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32102, 3, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32103, 4, 32000); INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32104, 4, 32000); -- this should return finish : 1, ok : 0 and error message due to empty comment of failed request SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test with failed global_pid, attempt is still 1 INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, global_pid, collection_id) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 10015415, 32000); -- this should return finish : 0, ok : 1, it should wait for cron job to pick request again for index_id 32005 and mark attempt = 2 SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); DELETE FROM documentdb_api_catalog.documentdb_index_queue; -- test with attempt > 1 INSERT INTO documentdb_api_catalog.documentdb_index_queue (index_cmd, cmd_type, index_id, index_cmd_status, collection_id, attempt) VALUES ('CREATE INDEX CONCURRENTLY', 'C', 32105, 2, 32000, 4); -- this should return finish : 1, ok : 0 and error message due to one attempt is failed "Index creation attempt failed" SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101,32102,32103,32104,32105,32106]}}'); DELETE FROM documentdb_api_catalog.documentdb_index_queue; SELECT * FROM documentdb_api_internal.check_build_index_status('{"indexRequest" : {"cmdType" : "C", "ids" :[32101]}}'); BEGIN; -- test config update, documentdb_api_internal.schedule_background_index_build_jobs reads default guc values SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; -- now set guc values and verify that they take effect SET LOCAL documentdb.maxNumActiveUsersIndexBuilds TO 1; -- default value for the indexBuildScheduleInSec SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; SET LOCAL documentdb.maxNumActiveUsersIndexBuilds TO 1; SET LOCAL documentdb.indexBuildScheduleInSec TO 3; SELECT FROM documentdb_api_internal.schedule_background_index_build_jobs(true); SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; ROLLBACK; SELECT schedule, jobname FROM cron.job WHERE jobname LIKE 'documentdb_index_build_task_%' ORDER BY jobId; commands_create_indexes_pfe_a.sql000066400000000000000000000171201507310017400355100ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 1600000; SET documentdb.next_collection_id TO 16000; SET documentdb.next_collection_index_id TO 16000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; -- supported "partialFilterExpression" operators -- SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "b": {"$gte": 10} } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_i', 'my_idx_1'); -- not the same index since this doesn't specify partialFilterExpression SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1" } ] }', true ); -- but this is the same index, so should not return an error SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "b": {"$gte": 10} } } ] }', true ); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_i", "indexes": [ { "key": {"z.$**": 1}, "name": "my_idx_3", "partialFilterExpression": { "c": {"$type": "number" } } } ] }', true ); SELECT documentdb_api.list_indexes_cursor_first_page('mydb','{ "listIndexes": "collection_i" }') ORDER BY 1; -- force using my_idx_1 when possible SELECT documentdb_distributed_test_helpers.drop_primary_key('mydb', 'collection_i'); SELECT SUM(1) FROM documentdb_api.insert_one('mydb','collection_i', '{"a":"foo"}'), generate_series(1, 10); BEGIN; set local enable_seqscan TO OFF; SET seq_page_cost TO 10000000; -- even if filter exactly matches the partialFilterExpression of my_idx_1, -- cannot use the index since the index key is "a.$**" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 10} } ] } '; -- can use the index since it filters on the index key as well EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 10} }, { "a": 4 } ] } '; EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gte": 11} }, { "a": 4 } ] } '; EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$gt": 12} }, { "a": 4 } ] } '; EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "b": {"$eq": 13} }, { "a": 4 } ] } '; -- cannot use index (no PFE) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "c": { "$type": "string" } } ] } '; EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "a": 4 } ] } '; -- can use index EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb', 'collection_i') WHERE document @@ ' { "$and": [ { "z": {"$eq": 13} }, { "c": { "$type": "number" } } ] } '; COMMIT; -- unsupported "partialFilterExpression" operators -- CREATE FUNCTION create_index_arg_using_pfe(p_pfe documentdb_core.bson) RETURNS documentdb_core.bson AS $$ BEGIN RETURN format( '{ "createIndexes": "collection_5", "indexes": [ { "key": {"c.d": 1}, "name": "new_idx", "partialFilterExpression": %s } ] }', p_pfe )::documentdb_core.bson; END; $$ LANGUAGE plpgsql; SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"$or": [{"a": 1}]} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$nor": [{"a": 1}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$nor": [{"a": 1}, {"b": 1}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": 3}, {"a": {"$in": [2]}}, {"c": 4} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$ne": 1 } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$ne": 1} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$nin": [1,2,3]} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": 3}, {"a": {"$in": 2}}, {"c": 4} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"$and": [{"a": 1}, {"b": 3}]} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": 1, "$and": [{"c": 1}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": 1, "b": {"$and": [{"d": 1}]} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$not": {"$eq": [1,2,3]}} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"a": {"$not": {"$eq": [1,2,3]}}}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"a": {"$exists": true}}, {"a": {"$size": 5}} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"b": 55}, {"a": {"$exists": false}}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": "b", "item": {"$exists": 1, "$text": {"$search": "coffee"}}, "c": "d" } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$and": [{"a": 1}, {"b": 3}]} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [{"p": 1}, {"q": 2}], "b": [{"z": 1}, {"t": 2}], "$and": [{"p": 1}, {"q": 2}] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$and": [ {"b": {"$gte": 1, "$lte": 3}} ] } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "a": {"$unknown_operator": 1} } '), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('my_db', create_index_arg_using_pfe(' { "$unknown_operator": [{"a": 1}] } '), true);commands_create_indexes_pfe_b.sql000066400000000000000000000155311507310017400355150ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 120000; SET documentdb.next_collection_id TO 12000; SET documentdb.next_collection_index_id TO 12000; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('compound_index_test', 'compound_index', '{"a.b": 1, "c.d": 1}'), true); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','compound_index_test'); BEGIN; set local enable_seqscan TO off; EXPLAIN (COSTS OFF) SELECT object_id, document FROM documentdb_api.collection('db', 'compound_index_test') WHERE document @@ '{ "a.b": { "$gte" : 1 }}'; ROLLBACK; -- supported "partialFilterExpression" operators -- -- note that inner $and is not an operator SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_1", "partialFilterExpression": { "$and": [ { "a": { "b": { "x": {"$and": [ {"$eq": 1} ] }, "y": [1]} , "c": 3} }, { "b": {"$gte": 10} } ] } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_1'); -- note that it's not the $regex operator SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"f.$**": 1}, "name": "my_idx_2", "partialFilterExpression": { "item": {"a": {"$regex": "^p.*", "$options": "si"}} } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_2'); -- $exists: true is supported SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"r.$**": 1}, "name": "my_idx_3", "partialFilterExpression": { "$and": [ {"b": 55}, {"a": {"$exists": true}}, {"c": {"$exists": 1}}, {"d": {"$exists": -1}} ] } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_3'); -- While the reference implementation throws an error for the following: -- -- "partialFilterExpression" { -- "$and": [{"p": 1}, {"q": 2}], -- "b": [{"z": 1}, {"t": 2}] -- } -- -- , doesn't throw an error for below by ignoring the first $and expression. SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"p.$**": 1}, "name": "my_idx_4", "partialFilterExpression": { "$and": [{"p": 1}, {"q": 2}], "$and": [{"z": 1}, {"t": 2}] } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_4'); SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb_4', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"a.$**": 1}, "name": "my_idx_5", "partialFilterExpression": { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} }, "c": {"$exists": 1} } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb_4', 'collection_10', 'my_idx_5'); -- force using my_idx_5 when possible SELECT documentdb_distributed_test_helpers.drop_primary_key('mydb_4', 'collection_10'); SELECT SUM(1) FROM documentdb_api.insert_one('mydb_4','collection_10', '{"c":"foo"}'), generate_series(1, 10); BEGIN; set local enable_seqscan TO OFF; SET seq_page_cost TO 10000000; -- uses my_idx_5 EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} }, "c": {"$exists": 1} } '; -- cannot use my_idx_5 since "b.e" is missing EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]} }, "c": {"$exists": 1} } '; -- cannot use my_idx_5 since the filter on "c" is missing EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "a": [ {"a": "b"}, "c", 1 ], "b": { "c": {"d": [1,2,3]}, "e": {"f": 0} } } '; -- uses my_idx_5 even if we added a filter on "another_field" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "c": { "d": [1,2,3] }, "e": { "f": 0 } } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; -- cannot use my_idx_5 due to order of the fields under "b" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "e": { "f": 0 } }, "c": { "d": [1,2,3] } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; -- cannot use my_idx_5 due to order of the elements in array "b.c.d" EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM documentdb_api.collection('mydb_4', 'collection_10') WHERE document @@ ' { "$and": [ { "b": { "e": { "f": 0 } }, "c": { "d": [1,3,2] } }, { "c": { "$exists": 1 } }, { "another_field" : 6}, { "a": [ { "a": "b" }, "c", 1 ] } ] } '; COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"h.$**": 1}, "name": "my_idx_6", "partialFilterExpression": {} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_6'); -- this is normally not supported due to $or SELECT documentdb_api_internal.create_indexes_non_concurrently( 'mydb', '{ "createIndexes": "collection_10", "indexes": [ { "key": {"z.$**": 1}, "name": "my_idx_7", "partialFilterExpression": { "$and": [ {"$or": [{"a": 1}]} ] } } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('mydb', 'collection_10', 'my_idx_7'); commands_create_indexes_text.sql000066400000000000000000000471551507310017400354350ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 6770000; SET documentdb.next_collection_id TO 6770; SET documentdb.next_collection_index_id TO 6770; -- cannot create indexes for cosmos_search without the flag enabled. SELECT documentdb_api.create_collection('db', 'create_indexes_text'); -- invalid scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": 1, "c": "text" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "hashed", "b": 1, "c": "text" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": "text" }, "name": "foo", "expireAfterSeconds": 10 } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": "text" }, "name": "foo", "unique": true } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c.$**": "text" }, "name": "foo" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "foo", "wildcardProjection": { "a": 1 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "ok" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "weights": { "a": 2, "b": 3, "c": 4, "d": 5 } } ] }', true); -- create a valid indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "a_text" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "b": "text", "c": 1 }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "b": "text", "c": "text" }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "idx1", "default_language": "es" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1", "weights": { "b": 100, "c": 200 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text", "b": "text", "c": 1 }, "name": "idx1", "weights": { "c": 200, "d": 10 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "$**": "text" }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text", "a": 1 }, "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "language_override": "idioma", "name": "idx1" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); -- more tests with wildcard text indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "$**": "text", "a": "text" }, "name": "idx1" }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text", "$**": "text" }, "name": "idx1" }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "$**": 1 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "$**": 1, "b": 2 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text" }, "name": "idx1", "weights": { "b": 2, "$**": 1 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "a": "text", "$**": "text" }, "name": "idx1", "weights": { "b": 2 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "default_language": "es" } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); -- more tests with wildcard text indexes -- this index spec corresponds to the index spec in the JS test: fts_blogwild.js SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text" }, "name": "idx1", "weights": { "$**": 1, "title": 2 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); -- test variations of the index spec - with the order of the weights, and with the wildcard -- being specified in the key document SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text" }, "name": "idx1", "weights": { "title": 2, "$**": 1 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [{ "key": { "dummy": "text", "$**": "text" }, "name": "idx1", "weights": { "title": 2 } }]}', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); -- we now create the same indexes as above, but with the metadata term `{ _fts: 'text', _ftsx: 1 }` SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "a_text", "weights": { "a": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); SELECT * FROM documentdb_api_catalog.collection_indexes WHERE collection_id = 6770 ORDER BY 1,2,3; \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "a_text" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "b": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "b": 1, "c": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "default_language": "es", "weights": { "a": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 100, "c": 200 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "c": 1 }, "name": "idx1", "weights": { "a": 1, "b": 1, "c": 200, "d": 10 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": 1, "_fts": "text", "_ftsx": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1, "a": 1 }, "name": "idx1", "weights": { "$**": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "language_override": "idioma", "name": "idx1", "weights": { "a": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "_fts": "text", "_ftsx": 1 }, "name": "idx1", "default_language": "es", "weights": { "$**": 1 } } ] }', true); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 -- shard and re-observe SELECT documentdb_api.shard_collection('db', 'create_indexes_text', '{ "_id" : "hashed" }', false); SELECT documentdb_api.list_indexes_cursor_first_page('db', '{ "listIndexes": "create_indexes_text" }'); \d documentdb_data.documents_6770 CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "create_indexes_text", "index": "idx1" }'); -- now create an index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "a": "text" }, "name": "a_text" } ] }', true); -- creating more text indexes should just fail. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "b": "text" }, "name": "b_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "b": "text" }, "name": "c_b_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "d": 1, "b": "text" }, "name": "c_b_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "c": 1, "d": "text", "b": "text" }, "name": "c_b_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "$**": "text" }, "name": "idx1", "weights": { "a": 2, "b": 3, "c": 4, "d": 5 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_text", "indexes": [ { "key": { "f": "text" }, "name": "idx2", "default_language": "de" } ] }', true); commands_create_indexes_wp.sql000066400000000000000000000357441507310017400351000ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 1700000; SET documentdb.next_collection_id TO 17000; SET documentdb.next_collection_index_id TO 17000; -- cannot specify wildcardProjection for a non-root wildcard index SELECT documentdb_api_internal.create_indexes_non_concurrently( 'wp_test', '{ "createIndexes": "fail_test", "indexes": [ { "key": {"a.$**": 1}, "name": "idx", "wildcardProjection": {"a": 1} } ] }', true ); -- cannot specify wildcardProjection for a non-wildcard index SELECT documentdb_api_internal.create_indexes_non_concurrently( 'wp_test', '{ "createIndexes": "fail_test", "indexes": [ { "key": {"a": 1}, "name": "idx", "wildcardProjection": {"a": 1} } ] }', true ); CREATE FUNCTION create_index_arg_using_wp(p_wp text) RETURNS documentdb_core.bson AS $$ BEGIN RETURN format( '{ "createIndexes": "fail_test", "indexes": [ { "key": {"$**": 1}, "name": "idx", "wildcardProjection": %s } ] }', p_wp )::documentdb_core.bson; END; $$ LANGUAGE plpgsql; -- all fields specified in wildcardProjection must be included or excluded, except _id field SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": 0}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b.c": 0}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"b.c": 1, "a": 0}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"x": 1, "y.t": 0}, "b.c": 0}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"x": 1, "y": 1}, "b.c": 0}'), true); -- wildcardProjection cannot be empty SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{}'), true); -- wildcardProjection must be document SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('5'), true); -- wildcardProjection cannot contain an empty document as an inner-level specification SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": {"c": 1, "d": {}, "e": 1}}'), true); -- and inner-level specification must be a document or a path string SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "b": {"c": 1, "d": [], "e": 1}}'), true); -- show that we throw an error for invalid paths used in wildcardProjection document SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a..b": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"a..b": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"a.b.": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": -1, "b": {"$aa": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"$a": -1, "b": {"aa": 1}}'), true); -- idx_1: for _id field, we will take the last inclusion specification into the account -- idx_2: not specifying inclusion for _id field would result in excluding _id field by default SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_1", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"_id": 0, "a": {"x": 10.5, "y": true}, "_id": false, "b.c": 1, "_id": -0.6} }, { "key": {"$**": -1}, "name": "idx_2", "wildcardProjection": {"a": {"x": 10.5, "y": true, "z.a.b": -100}, "b.c": 1, "k": {"z.a.b": -100}} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_1', 'idx_1'); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_1', 'idx_2'); SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_1" }') ORDER BY 1; -- using $ in a field path is ok unless it's the first character SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_2", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": -1, "b": {"b.a$a.k$": 1}} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'ok_test_2', 'idx_1'); SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_2" }') ORDER BY 1; SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_3", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 1, "b": {"c": 1, "d.e": 1}, "_id": 0} } ] }', true ); SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_3'); SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_3" }') ORDER BY 1; SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.b": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": {"b": 1}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"_id": 1}'; -- cannot use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b": {"d": 1}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_3') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"e": 1}'; COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_4", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 0, "b": {"c": 0, "d.e": 0}, "f.g.h": 0} } ] }', true ); SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_4'); SELECT documentdb_api.list_indexes_cursor_first_page('wp_test', '{ "listIndexes": "ok_test_4" }') ORDER BY 1; SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; -- cannot use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.b": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a": {"b": 1}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"_id": 1}'; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b": {"d": 1}}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"e": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"f.g": 1}'; COMMIT; SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 1}, "a": {"k": 1}}'); SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 1}, "a": {"k": 2}}'); SELECT 1 FROM documentdb_api.insert_one('wp_test', 'ok_test_4', '{"b": {"d": 2}, "a": {"k": 2}}'); BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1, "a.k": 1}'; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.k": 1, "b.d": 1}'; SELECT COUNT(*)=1 FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": 1, "a.k": 1}'; SELECT COUNT(*)=1 FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"a.k": 1, "b.d": 1}'; COMMIT; BEGIN; set local enable_seqscan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"b.d": {"$in": [1,2,3]}}'; -- cannot use idx_1 due to filter on "a.z.r" in "$or" EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"$or": [{"b.d": {"$eq": [1,2,3]}}, {"a.z": {"r": {"$gte": 5}}}]}'; -- can use idx_1 since none of the quals in "$or" are excluded EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_4') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"$or": [{"b.d": {"$eq": [1,2,3]}}, {"k": 5}]}'; COMMIT; SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_5", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 0, "b": {"c": {"p": 0, "r": false}, "d._id": 0}, "_id": 1} } ] }', true ); SELECT documentdb_api.list_indexes_cursor_first_page('wp_test','{ "listIndexes": "ok_test_5" }') ORDER BY 1; SELECT documentdb_distributed_test_helpers.drop_primary_key('wp_test', 'ok_test_5'); SET citus.propagate_set_commands TO 'local'; BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- can use idx_1 EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('wp_test', 'ok_test_5') WHERE document OPERATOR(documentdb_api_catalog.@@) '{"d.e.f": 1, "_id": 0}'; COMMIT; -- not the same index since this doesn't specify wildcardProjection SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "ok_test_5", "indexes": [ { "key": {"$**": 1}, "name": "idx_2" } ] }', true ); -- test path collision SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": 1, "a.b": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": 1, "a": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a.b.c": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c.d.e": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b": {"c.d": 1}, "a": {"b.c": {"d.e": 1}}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a.b.c": 1, "a.b": {"c.d": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c": 1}, "a.b": {"c.d": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c.d.e": 1}, "a.b": {"c.d": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', create_index_arg_using_wp('{"a": {"b.c": {"d.e": 1}}, "a.b": {"c.d": 1}}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_1", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": 1, "a": {"b": 1}} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_1', 'idx_1'); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_2", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a": {"b": 1}, "a": 1} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_2', 'idx_1'); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_3", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a.b": {"c.d": 1}, "a.b": 1} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_3', 'idx_1'); SELECT documentdb_api_internal.create_indexes_non_concurrently('wp_test', '{ "createIndexes": "no_path_collision_4", "indexes": [ { "key": {"$**": 1}, "name": "idx_1", "wildcardProjection": {"a.b": 1, "a.b": {"c.d": 1}} } ] }', true ); SELECT documentdb_distributed_test_helpers.documentdb_index_get_pg_def('wp_test', 'no_path_collision_4', 'idx_1'); commands_create_ttl_indexes.sql000066400000000000000000000762431507310017400352540ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 2000000; SET documentdb.next_collection_id TO 20000; SET documentdb.next_collection_index_id TO 20000; SET search_path TO documentdb_api_catalog, documentdb_core, documentdb_data, public; -- make sure jobs are scheduled and disable it to avoid flakiness on the test as it could run on its schedule and delete documents before we run our commands in the test select schedule, command, active from cron.job where jobname like '%ttl_task%'; select cron.unschedule(jobid) from cron.job where jobname like '%ttl_task%'; -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); -- Documents with date array SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 8, "ttl" : true }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); -- 1. Create TTL Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); -- 2. List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll') ORDER BY collection_id, index_id; -- 3. Call ttl purge procedure with a batch size of 10 CALL documentdb_api_internal.delete_expired_rows(10); -- 4.a. Check what documents are left after purging SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll') order by object_id; -- 5. TTL indexes behaves like normal indexes that are used in queries BEGIN; set local enable_seqscan TO off; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) SELECT object_id FROM documentdb_data.documents_20000 WHERE bson_dollar_eq(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) LIMIT 100; $Q$); END; -- 6. Explain of the SQL query that is used to delete documents BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) DELETE FROM documentdb_data.documents_20000_2000000 WHERE ctid IN ( SELECT ctid FROM documentdb_data.documents_20000_2000000 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) AND shard_key_value = 20000 LIMIT 100 ) $Q$); END; -- 7.a. Query to select all the shards corresponding to a ttl index that needs to be considered for purging -- ttlcoll is an unsharded collection SELECT idx.collection_id, idx.index_id, (index_spec).index_key as key, (index_spec).index_pfe as pfe, -- trunc(extract(epoch FROM now()) * 1000, 0)::int8 as currentDateTime, -- removed to reduce test flakiness (index_spec).index_expire_after_seconds as expiry, coll.shard_key, dist.shardid FROM documentdb_api_catalog.collection_indexes as idx, documentdb_api_catalog.collections as coll, pg_dist_shard as dist WHERE index_is_valid AND (index_spec).index_expire_after_seconds >= 0 AND idx.collection_id = coll.collection_id AND dist.logicalrelid = ('documentdb_data.documents_' || coll.collection_id)::regclass AND (dist.shardid = get_shard_id_for_distribution_column(logicalrelid, coll.collection_id) OR (coll.shard_key IS NOT NULL)) AND coll.collection_id >= 20000 AND coll.collection_id < 21000 -- added to reduce test flakiness ORDER BY shardid ASC; -- added to remove reduce flakiness -- 8. Shard collection SELECT documentdb_api.shard_collection('db','ttlcoll', '{"ttl":"hashed"}', false); -- 9. Add more records with previous deleted as well as new ids SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 100, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll', '{ "_id" : 200, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); -- 9.a. Query to select all the shards corresponding to a ttl index that needs to be considered for purging -- ttlcoll is an unsharded collection SELECT idx.collection_id, idx.index_id, (index_spec).index_key as key, (index_spec).index_pfe as pfe, -- trunc(extract(epoch FROM now()) * 1000, 0)::int8 as currentDateTime, -- removed to reduce test flakiness (index_spec).index_expire_after_seconds as expiry, coll.shard_key, dist.shardid FROM documentdb_api_catalog.collection_indexes as idx, documentdb_api_catalog.collections as coll, pg_dist_shard as dist WHERE index_is_valid AND (index_spec).index_expire_after_seconds >= 0 AND idx.collection_id = coll.collection_id AND dist.logicalrelid = ('documentdb_data.documents_' || coll.collection_id)::regclass AND (dist.shardid = get_shard_id_for_distribution_column(logicalrelid, coll.collection_id) OR (coll.shard_key IS NOT NULL)) AND coll.collection_id >= 20000 AND coll.collection_id < 21000 -- added to reduce test flakiness ORDER BY shardid ASC; -- added to reduce test flakiness -- Delete all other indexes from previous tests to reduce flakiness WITH deleted AS ( DELETE FROM documentdb_api_catalog.collection_indexes WHERE collection_id != 20000 RETURNING 1 ) SELECT true FROM deleted UNION ALL SELECT true LIMIT 1; SELECT collection_id, (index_spec).index_key, (index_spec).index_name, (index_spec).index_expire_after_seconds as ttl_expiry, (index_spec).index_is_sparse as is_sparse, (index_spec).index_name as index_name FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_expire_after_seconds > 0; -- 10.b. Call ttl task procedure with a batch size of 0 -- BEGIN; Set citus.log_remote_commands to on; -- Will print Citus rewrites of the queries Set citus.log_local_commands to on; -- Will print the local queries set local documentdb.SingleTTLTaskTimeBudget to 1; CALL documentdb_api_internal.delete_expired_rows(0); -- To test the sql query, it won't delete any data Set citus.log_remote_commands to off; Set citus.log_local_commands to off; END; -- 10.a. CALL documentdb_api_internal.delete_expired_rows(10); -- 11.a. Check what documents are left after purging SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll') order by object_id; -- 12. Explain of the SQL query that is used to delete documents after sharding BEGIN; SET LOCAL enable_seqscan TO OFF; SELECT documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan($Q$ EXPLAIN(costs off) DELETE FROM documentdb_data.documents_20000_2000016 WHERE ctid IN ( SELECT ctid FROM documentdb_data.documents_20000_2000016 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::bson) LIMIT 100 ) $Q$); END; -- 13. TTL index can be created SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl1": 1}, "name": "ttl_index1", "expireAfterSeconds": 100, "sparse" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl2": 1}, "name": "ttl_index2", "expireAfterSeconds": 100, "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl3": 1}, "name": "ttl_index3", "expireAfterSeconds": 100, "sparse" : true, "unique" : true}]}', true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; -- 14. TTL index creation restrictions SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": -1}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": "stringNotAllowed"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": 707992037530324174}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index2", "expireAfterSeconds": 100, "v" : 1}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1, "_id" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"_id": 1, "non_id" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"non_id1": 1, "non_id2" : 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"non_id1.$**": 1}, "name": "ttl_idx", "expireAfterSeconds": 100}]}', true); -- 15. Unsupported ttl index scenarios SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttl4": "hashed"}, "name": "ttl_index4", "expireAfterSeconds": 100}]}', true); -- 16. Behavioral difference with sharded reference implementation SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index1", "sparse" : true, "expireAfterSeconds" : 10}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index2", "sparse" : false, "expireAfterSeconds" : 10}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index3", "expireAfterSeconds": 100, "sparse" : true, "unique" : true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew": "hashed"}, "name": "ttl_new_index4", "expireAfterSeconds": 100}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew2": 5}, "name": "ttl_new_indexj", "sparse" : true, "expireAfterSeconds" : 10}]}', true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll" }') ORDER BY 1; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll", "indexes": [{"key": {"ttlnew3": "hashed"}, "name": "ttl_new_indexk", "unique" : true, "expireAfterSeconds" : 10}]}', true); -- 17. Partial filter expresson tests SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ttlcoll2", "indexes": [ { "key": {"ttl": 1}, "name": "ttl_pfe_index", "expireAfterSeconds" : 5, "partialFilterExpression": { "$and": [ {"b": 55}, {"a": {"$exists": true}}, {"c": {"$exists": 1}} ] } } ] }', true ); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll2" }') ORDER BY 1; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll2') ORDER BY collection_id, index_id; SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 0, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 1, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 2, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 3, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 4, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 5, "b": 55, "a" : 1, "c": 1, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 6, "b": 55, "a" : 1, "d": 1, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 7, "b": 55, "a" : 1, "c": 1, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 8, "b": 55, "a" : 1, "c": 1, "ttl" : true }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll2', '{ "_id" : 9, "b": 55, "a" : 1, "c": 1, "ttl" : "would not expire" }', NULL); CALL documentdb_api_internal.delete_expired_rows(10); SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll2') order by object_id; -- 18. Large TTL (expire after INT_MAX seconds aka 68 years) SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "ttlcoll3", "indexes": [ { "key": {"ttl": 1}, "name": "ttl_large_expireAfterSeconds", "expireAfterSeconds" : 2147483647 } ] }', true ); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll3" }') ORDER BY 1; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'ttlcoll3') ORDER BY collection_id, index_id; -- Timestamp: -623051866000 ( 4/4/1950 more than 68 years from 4/4/2024). So, with the ttl index index `ttl_large_expireAfterSeconds`, _id : [1, 6, 7] should be deleted. SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 0, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "-623051866000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 1, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 2, "b": 56, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "1712253575000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 3, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "4867927028000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 4, "b": 55, "a" : 1, "c": 1, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 5, "b": 55, "a" : 1, "c": 1, "ttl" : [{ "$date": { "$numberLong": "1697900030774" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 6, "b": 55, "a" : 1, "d": 1, "ttl" : [{ "$date": { "$numberLong": "-623051866000" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 7, "b": 55, "a" : 1, "c": 1, "ttl" : [true, { "$date": { "$numberLong": "-623051866000" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 8, "b": 55, "a" : 1, "c": 1, "ttl" : true }', NULL); SELECT documentdb_api.insert_one('db','ttlcoll3', '{ "_id" : 9, "b": 55, "a" : 1, "c": 1, "ttl" : "would not expire" }', NULL); CALL documentdb_api_internal.delete_expired_rows(10); SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlcoll3') order by object_id; -- 19 Float TTL SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll1", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index5", "sparse" : true, "expireAfterSeconds" : {"$numberDouble":"12345.12345"}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlcoll1", "indexes": [{"key": {"ttlnew": 1}, "name": "ttl_new_index6", "sparse" : false, "expireAfterSeconds" : {"$numberDouble":"12345.12345"}}]}', true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlcoll1" }') ORDER BY 1; -- 20 Repeated TTL deletes -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); -- Documents with date array SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 8, "ttl" : true }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlRepeatedDeletes', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); SELECT COUNT(documentdb_api.insert_one('db', 'ttlRepeatedDeletes', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; SELECT COUNT(documentdb_api.insert_one('db', 'ttlRepeatedDeletes2', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlRepeatedDeletes", "indexes": [{"key": {"ttl": 1}, "name": "ttl_repeat_1", "sparse" : true, "expireAfterSeconds" : 5}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlRepeatedDeletes2", "indexes": [{"key": {"ttl": 1}, "name": "ttl_repeat_2", "sparse" : false, "expireAfterSeconds" : 5}]}', true); SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes'); SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); BEGIN; SET LOCAL documentdb.TTLTaskMaxRunTimeInMS to 3000; SET LOCAL documentdb.SingleTTLTaskTimeBudget to 2000; CALL documentdb_api_internal.delete_expired_rows(11); -- With repeat mode off (by default), we should delete exactly 11 documents per collections (currently has 10001 and 9991 documents) SELECT count(*) = 9990 from documentdb_api.collection('db', 'ttlRepeatedDeletes'); SELECT count(*) = 9980 from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); END; BEGIN; SET LOCAL documentdb.TTLTaskMaxRunTimeInMS to 3000; SET LOCAL documentdb.SingleTTLTaskTimeBudget to 2000; SET LOCAL documentdb.RepeatPurgeIndexesForTTLTask to true; SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes'); SELECT count(*) from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); -- With repeat mode on, we should delete more than 10 documents per collections (currently has 9990 and 9980 documents) CALL documentdb_api_internal.delete_expired_rows(10); -- 3000 ms does 70 iterations locally. So document count should be well below 9900. SELECT count(*) < 9900 from documentdb_api.collection('db', 'ttlRepeatedDeletes'); SELECT count(*) < 9900 from documentdb_api.collection('db', 'ttlRepeatedDeletes2'); END; -- 21. TTL index with forced ordered scan via index hints set documentdb.enableExtendedExplainPlans to on; set documentdb_rum.preferOrderedIndexScan to on; -- if documentdb_extended_rum exists, set alternate index handler SELECT pg_catalog.set_config('documentdb.alternate_index_handler_name', 'extended_rum', false), extname FROM pg_extension WHERE extname = 'documentdb_extended_rum'; -- Delete all other indexes from previous tests to reduce flakiness SELECT documentdb_api.drop_collection('db', 'ttlcoll'), documentdb_api.drop_collection('db', 'ttlcoll1'), documentdb_api.drop_collection('db', 'ttlcoll2'), documentdb_api.drop_collection('db', 'ttlcoll3'),documentdb_api.drop_collection('db', 'ttlRepeatedDeletes'),documentdb_api.drop_collection('db', 'ttlRepeatedDeletes2'); -- make sure jobs are scheduled and disable it to avoid flakiness on the test as it could run on its schedule and delete documents before we run our commands in the test select cron.unschedule(jobid) from cron.job where jobname like '%ttl_task%'; -- 1. Populate collection with a set of documents with different combination of $date fields -- SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); -- Documents with date way in future SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); -- Documents with date array SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 8, "ttl" : true }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','ttlCompositeOrderedScan', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); SELECT COUNT(documentdb_api.insert_one('db', 'ttlCompositeOrderedScan', FORMAT('{ "_id": %s, "ttl": { "$date": { "$numberLong": "1657900030774" } } }', i, i)::documentdb_core.bson)) FROM generate_series(10, 10000) AS i; -- Create TTL Index -- SET documentdb.enableExtendedExplainPlans to on; SET documentdb.enableIndexOrderbyPushdown to on; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "ttlCompositeOrderedScan", "indexes": [{"key": {"ttl": 1}, "enableCompositeTerm": true, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5, "sparse": true}]}', true); select collection_id, (index_spec).index_key, (index_spec).index_name, (index_spec).index_expire_after_seconds as ttl_expiry, (index_spec).index_is_sparse as is_sparse, (index_spec).index_name as index_name from documentdb_api_catalog.collection_indexes where (index_spec).index_expire_after_seconds > 0; \d documentdb_data.documents_20006 -- List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "ttlCompositeOrderedScan" }') ORDER BY 1; SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; -- Call ttl purge procedure with a batch size of 100 BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.logTTLProgressActivity to on; CALL documentdb_api_internal.delete_expired_rows(100); RESET client_min_messages; END; BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.useIndexHintsForTTLTask to off; SET LOCAL documentdb.logTTLProgressActivity to on; CALL documentdb_api_internal.delete_expired_rows(100); RESET client_min_messages; END; -- Check what documents are left after purging SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; -- TTL indexes behaves like normal indexes that are used in queries (cx can provide .hint() to force) BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(costs off) SELECT object_id FROM documentdb_data.documents_20006 WHERE bson_dollar_eq(document, '{ "ttl" : { "$date" : { "$numberLong" : "100" } } }'::documentdb_core.bson) LIMIT 100; END; -- Check the query to fetch the eligible TTL indexes uses IndexScan. BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(analyze on, verbose on, costs off, timing off, summary off) SELECT ctid FROM documentdb_data.documents_20006_2000105 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1754515365000" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; END; -- Shard collection SELECT documentdb_api.shard_collection('db', 'ttlCompositeOrderedScan', '{ "_id": "hashed" }', false); -- Check TTL deletes work on sharded (should delete 800 docs, 100 for each shard) SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; CALL documentdb_api_internal.delete_expired_rows(100); SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; -- Check for Ordered Indes Scan on the ttl index BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; EXPLAIN(analyze on, verbose on, costs off, timing off, summary off) SELECT ctid FROM documentdb_data.documents_20006_2000124 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; END; BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; SET client_min_messages TO INFO; EXPLAIN(COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT ctid FROM documentdb_data.documents_20006_2000122 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) LIMIT 100; END; SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; -- Test with descending TTL ordering BEGIN; SET client_min_messages TO LOG; SET LOCAL documentdb.useIndexHintsForTTLTask to off; SET LOCAL documentdb.logTTLProgressActivity to on; SET LOCAL documentdb.enableTTLDescSort to on; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; CALL documentdb_api_internal.delete_expired_rows(100); RESET client_min_messages; END; SELECT count(*) from ( SELECT shard_key_value, object_id, document from documentdb_api.collection('db', 'ttlCompositeOrderedScan') order by object_id) as a; BEGIN; SET LOCAL documentdb.enableIndexOrderbyPushdown to on; set local enable_seqscan to off; set LOCAL enable_bitmapscan to off; SET client_min_messages TO INFO; -- Check ORDER BY uses index EXPLAIN(COSTS OFF, ANALYZE ON, SUMMARY OFF, TIMING OFF) SELECT ctid FROM documentdb_data.documents_20006_2000122 WHERE bson_dollar_lt(document, '{ "ttl" : { "$date" : { "$numberLong" : "1657900030775" } } }'::documentdb_core.bson) AND documentdb_api_internal.bson_dollar_index_hint(document, 'ttl_index'::text, '{"key": {"ttl": 1}}'::documentdb_core.bson, true) AND documentdb_api_internal.bson_dollar_fullscan(document, '{ "ttl" : -1 }'::documentdb_core.bson) ORDER BY documentdb_api_catalog.bson_orderby(document, '{ "ttl" : -1}'::documentdb_core.bson) LIMIT 100; END;commands_create_unique_index_stats.sql000066400000000000000000000077461507310017400366470ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 112000; SET documentdb.next_collection_id TO 11200; SET documentdb.next_collection_index_id TO 11200; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; -- Creating another index with the same name is not ok. -- Note that we won't create other indexes too, even if it would be ok to create them in a separate command. SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"x.y.z": 1}, "name": "valid_index_1"}, {"key": {"c.d.e": 1}, "name": "my_idx_5", "partialFilterExpression": { "a": { "$exists": true }}}, {"key": {"x.y": 1}, "name": "valid_index_2", "unique": true } ] }', p_skip_check_collection_create=>true ); -- show that we didn't leave any invalid collection indexes behind SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('ind_db', 'collection_1') ORDER BY collection_id, index_id; \d documentdb_data.documents_11201 \d+ documentdb_data.documents_rum_index_11202 \d+ documentdb_data.documents_rum_index_11203 -- stats target is 0 for the unique shard column \d+ documentdb_data.documents_rum_index_11204 -- some tests disable background index job, let's enable it to test background index build codepath UPDATE cron.job SET active = true WHERE jobname LIKE 'documentdb_index_%'; -- now repeat with background indexes CALL documentdb_distributed_test_helpers.create_indexes_background( 'ind_db', '{ "createIndexes": "collection_1", "indexes": [ {"key": {"back.y.z": 1}, "name": "background_valid_index_1"}, {"key": {"back.d.e": 1}, "name": "back_my_idx_5", "partialFilterExpression": { "a": { "$exists": true }}}, {"key": {"back.y": 1}, "name": "back_valid_index_2", "unique": true } ] }' ); SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('ind_db', 'collection_1') ORDER BY collection_id, index_id; \d documentdb_data.documents_11201 \d+ documentdb_data.documents_rum_index_11205 \d+ documentdb_data.documents_rum_index_11206 -- stats target is 0 for the unique shard column \d+ documentdb_data.documents_rum_index_11207 -- create a composite unique CALL documentdb_distributed_test_helpers.create_indexes_background( 'ind_db', '{ "createIndexes": "collection_1", "indexes": [ {"key": {"back.y": 1, "back.z": 1 }, "name": "back_valid_index_3", "unique": true } ] }' ); \d+ documentdb_data.documents_rum_index_11208 -- disable background index job UPDATE cron.job SET active = false WHERE jobname LIKE 'documentdb_index_%'; -- create with the new operator class set documentdb.enable_large_unique_index_keys to off; set documentdb.forceIndexTermTruncation to on; SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.y": 1, "fore.z": 1 }, "name": "fore_valid_index_3", "unique": true } ] }', p_skip_check_collection_create=>true ); \d+ documentdb_data.documents_rum_index_11209 -- disable the flag - and stats shouldn't be set set documentdb.disable_statistics_for_unique_columns to off; SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.yy": 1, "fore.zz": 1 }, "name": "fore_valid_index_4", "unique": true } ] }', p_skip_check_collection_create=>true ); \d+ documentdb_data.documents_rum_index_11210 set documentdb.enable_large_unique_index_keys to off; set documentdb.forceIndexTermTruncation to off; SELECT documentdb_api_internal.create_indexes_non_concurrently( p_database_name=>'ind_db', p_arg=>'{ "createIndexes": "collection_1", "indexes": [ {"key": {"fore.abc": 1, "fore.def": 1 }, "name": "fore_valid_index_no_trunc", "unique": true } ] }', p_skip_check_collection_create=>true ); \d+ documentdb_data.documents_rum_index_11211 commands_create_view_tests.sql000066400000000000000000000170451507310017400351210ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 111000; SET documentdb.next_collection_id TO 11100; SET documentdb.next_collection_index_id TO 11100; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; -- first create a collection (invalid) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": true }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": 1}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": 2.3}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": "true"}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "capped": "false"}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "timeseries": { "timeField": "a" } }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "clusteredIndex": { } }'); SELECT documentdb_api.create_collection_view('db', '{ "create": 2 }'); SELECT documentdb_api.create_collection_view('db', '{ "create": false }'); SELECT documentdb_api.create_collection_view('db', '{ "create": null }'); SELECT documentdb_api.create_collection_view('db', '{ "create": {"$undefined": true} }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "" }'); -- empty string not allowed -- create valid collections SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_not_capped1", "capped": false}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_not_capped2", "capped": 0}'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_emoji_👽" }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests" }'); -- noops SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests" }'); -- Views error out if the viewOn is not a string, or empty string SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": 2 }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": false }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view", "viewOn": "" }'); -- empty string not allowed -- viewOn can be null or undefined. It is treated as if it was not specified SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_n", "viewOn": null }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_np", "viewOn": null, "pipeline": [] }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_u", "viewOn": {"$undefined": true} }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_up", "viewOn": {"$undefined": true}, "pipeline": [] }'); -- create a view against it (no pipeline): succeeds SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_1", "viewOn": "create_view_tests" }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_emoji_👺", "viewOn": "create_view_tests_emoji_👽" }'); -- chain the view SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_2", "viewOn": "create_view_tests_view_1", "pipeline": [ { "$match": { "a": { "$gt": 5 } } } ] }'); -- chain one more view SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests_view_3", "viewOn": "create_view_tests_view_2", "pipeline": [ { "$sort": { "a": 1 } } ] }'); -- query all 4 SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_3" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_2" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests" }'); -- now insert 3 docs in the table SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 1, "a": 4 }'); SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 2, "a": 1 }'); SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 3, "a": 140 }'); SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 4, "a": 40 }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_3" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_2" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests" }'); -- create views with different options SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "viewOn": "create_view_tests_view_5", "pipeline": [ { "$sort": { "a": 1 } } ] }'); -- Can't write to views SELECT documentdb_api.insert_one('db', 'create_view_tests_view_1', '{ "_id": 5, "a": 60 }'); SELECT documentdb_api.update('db', '{ "update": "create_view_tests_view_1", "updates": [ { "q": {}, "u": {} } ] }'); SELECT documentdb_api.delete('db', '{ "delete": "create_view_tests_view_1", "deletes": [ { "q": {}, "limit": 1 } ] }'); SELECT documentdb_api.shard_collection('db', 'create_view_tests_view_1', '{ "_id": "hashed" }', false); SELECT documentdb_api.shard_collection('db', 'create_view_tests_view_1', '{ "_id": "hashed" }', true); -- can drop/rename a view SELECT documentdb_api.rename_collection('db', 'create_view_tests_view_1', 'create_view_tests_view_4'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); SELECT documentdb_api.drop_collection('db', 'create_view_tests_view_3'); -- drop the collection (view still works) SELECT documentdb_api.drop_collection('db', 'create_view_tests'); SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); -- create a view cycle (fails) SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_tests", "viewOn": "create_view_tests_view_1" }'); -- recreate a collection SELECT documentdb_api.insert_one('db', 'create_view_tests', '{ "_id": 3, "a": 140 }'); -- view works again SELECT document FROM bson_aggregation_find('db', '{ "find": "create_view_tests_view_1" }'); -- do a coll_mod SELECT database_name, collection_name, view_definition FROM documentdb_api_catalog.collections WHERE collection_name = 'create_view_tests_view_1'; SELECT documentdb_api.coll_mod('db', 'create_view_tests_view_1', '{ "collMod": "create_view_tests_view_1", "viewOn": "create_view_tests_view_4", "pipeline": [] }'); SELECT database_name, collection_name, view_definition FROM documentdb_api_catalog.collections WHERE collection_name = 'create_view_tests_view_1'; -- create a much longer cycle SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_1", "viewOn": "create_view_cycle_2" }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_2", "viewOn": "create_view_cycle_3" }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_3", "viewOn": "create_view_cycle_4" }'); SELECT documentdb_api.create_collection_view('db', '{ "create": "create_view_cycle_4", "viewOn": "create_view_cycle_1" }'); -- create with long name SELECT documentdb_api.create_collection_view('db', FORMAT('{ "create": "create_view_cycle_4_%s", "viewOn": "create_view_cycle_1" }', repeat('1bc', 80))::documentdb_core.bson); commands_crud_ignore_common_spec_fields.sql000066400000000000000000000037731507310017400376150ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql-- These tests make sure that we ignore the common spec fields/actions that are not implemented for various commands SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog; SET citus.next_shard_id TO 160000; SET documentdb.next_collection_id TO 1600; SET documentdb.next_collection_index_id TO 1600; -- insert tests select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":99,"a":99}], "ordered": false, "writeConcern": { "w": "majority", "wtimeout": 5000 }, "bypassDocumentValidation": true, "comment": "NoOp" }'); select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":21,"a":99}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp2", "apiVersion": 1 }'); -- insert again select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":1,"a":"id1"}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp1", "apiVersion": 1 }'); select documentdb_api.insert('db', '{ "insert":"ignoreCommonSpec", "documents":[{"_id":2,"a":"id2"}], "ordered": false, "bypassDocumentValidation": true, "comment": "NoOp2"}'); -- create index tests SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "ignoreCommonSpec", "indexes": [{"key": {"a$**foo": 1}, "name": "my_idx_ignore"}], "commitQuorum" : 100, "writeConcern": { "w": "majority", "wtimeout": 5000 }, "apiVersion": 1, "$db" : "tetsts", "db": "test2" }', true); -- quey SELECT bson_dollar_project(document, '{ "a" : 1 }') FROM documentdb_api.collection('db', 'ignoreCommonSpec') ORDER BY object_id; -- drop index tests CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "ignoreCommonSpec", "index":[], "writeConcern": { "w": "majority", "wtimeout": 5000 }, "comment": "NoOp1", "apiVersion": 1 }'); -- query SELECT bson_dollar_project(document, '{ "a" : 1 }') FROM documentdb_api.collection('db', 'ignoreCommonSpec') ORDER BY object_id; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_db_stats.sql000066400000000000000000000236351507310017400332660ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 630000; SET documentdb.next_collection_id TO 6300; SET documentdb.next_collection_index_id TO 6300; -- Utility function to add multiple documents to a collection. CREATE OR REPLACE FUNCTION insert_docs(p_db TEXT, p_coll TEXT, p_num INT, p_start INT default 0) RETURNS void AS $$ DECLARE num INTEGER := p_start; docText bson; BEGIN WHILE num < p_num + p_start LOOP docText := CONCAT('{ "a" : ', num, '}'); PERFORM documentdb_api.insert_one(p_db, p_coll, docText::documentdb_core.bson, NULL); num := num + 1; END LOOP; END; $$ LANGUAGE plpgsql; SELECT documentdb_api.drop_database('db1'); -- Non existing database should return zero values SELECT documentdb_api.db_stats('db1'); SELECT documentdb_api.db_stats('db1', 1); SELECT documentdb_api.db_stats('db1', 1024); --=============== Tests for "collections" & "objects" count ===============+=-- -- Create a Collection SELECT documentdb_api.create_collection('db1', 'col1'); -- db_stats with one empty collection SELECT documentdb_api.db_stats('db1'); SELECT documentdb_api.db_stats('db1', 1); SELECT documentdb_api.db_stats('db1', 1024); -- Add one doc SELECT documentdb_api.insert_one('db1','col1',' { "a" : 100 }', NULL); -- The AutoVacuum might still be napping so count in stats might still be 0, -- In this test we cannot wait till nap time is over, so we manually trigger the ANALYZE ANALYZE; -- db_stats with single collection and single document SELECT documentdb_api.db_stats('db1'); -- Insert few docs in the collection SELECT insert_docs('db1', 'col1', 20, 1); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" should be 21, "collections" should be 1, and fsStorageSize > fsUsedSize SELECT documentdb_api.db_stats('db1'); -- Create 4 more Collections SELECT documentdb_api.create_collection('db1', 'col2'); SELECT documentdb_api.create_collection('db1', 'col3'); SELECT documentdb_api.create_collection('db1', 'col4'); SELECT documentdb_api.create_collection('db1', 'col5'); -- "collections" and "indexes" count should increase to 5 SELECT documentdb_api.db_stats('db1'); -- Add one doc to each new collection SELECT documentdb_api.insert_one('db1','col2',' { "a" : 100 }', NULL); SELECT documentdb_api.insert_one('db1','col3',' { "a" : 100 }', NULL); SELECT documentdb_api.insert_one('db1','col4',' { "a" : 100 }', NULL); SELECT documentdb_api.insert_one('db1','col5',' { "a" : 100 }', NULL); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should increase to 25 SELECT documentdb_api.db_stats('db1'); -- Insert 20 more docs in each new collection SELECT insert_docs('db1', 'col2', 20, 1); SELECT insert_docs('db1', 'col3', 20, 1); SELECT insert_docs('db1', 'col4', 20, 1); SELECT insert_docs('db1', 'col5', 20, 1); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should increase to 105 SELECT documentdb_api.db_stats('db1'); -- Delete 1 document SELECT documentdb_api.delete('db1', '{"delete":"col1", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should reduce to 104 SELECT documentdb_api.db_stats('db1'); -- Delete 1 document from each remaining collections SELECT documentdb_api.delete('db1', '{"delete":"col2", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); SELECT documentdb_api.delete('db1', '{"delete":"col3", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); SELECT documentdb_api.delete('db1', '{"delete":"col4", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); SELECT documentdb_api.delete('db1', '{"delete":"col5", "deletes":[{"q":{"a":{"$gte": 100}},"limit":0}]}'); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "objects" count should reduce to 100 SELECT documentdb_api.db_stats('db1'); -- Now shard all collections SELECT documentdb_api.shard_collection('db1','col1', '{"a":"hashed"}', false); SELECT documentdb_api.shard_collection('db1','col2', '{"a":"hashed"}', false); SELECT documentdb_api.shard_collection('db1','col3', '{"a":"hashed"}', false); SELECT documentdb_api.shard_collection('db1','col4', '{"a":"hashed"}', false); SELECT documentdb_api.shard_collection('db1','col5', '{"a":"hashed"}', false); -- "objects" count should remain 100 SELECT documentdb_api.db_stats('db1'); --===================== Test for "indexes", "indexSize" =====================-- -- Create one more index SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col1', 'index_a_1', '{"a": 1}'), true); -- "indexes" count should increase to 6, "indexSize" should increase SELECT documentdb_api.db_stats('db1'); -- Create one more index in each remaining collections SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col2', 'index_a_1', '{"a": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col3', 'index_a_1', '{"a": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col4', 'index_a_1', '{"a": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db1', documentdb_distributed_test_helpers.generate_create_index_arg('col5', 'index_a_1', '{"a": 1}'), true); -- "indexes" count should increase to 10, "indexSize" should increase SELECT documentdb_api.db_stats('db1'); -- Drop one index CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col1", "index": "index_a_1"}'); -- "indexes" count should reduce to 9 SELECT documentdb_api.db_stats('db1'); -- Drop one index from each remaining collections CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col2", "index": "index_a_1"}'); CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col3", "index": "index_a_1"}'); CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col4", "index": "index_a_1"}'); CALL documentdb_api.drop_indexes('db1', '{"dropIndexes": "col5", "index": "index_a_1"}'); -- "indexes" count should be back to 5 (one default _id index in each collection), "indexSize" should decrease SELECT documentdb_api.db_stats('db1'); --===================== Test with Views =====================================-- -- create a view on a collection SELECT documentdb_api.create_collection_view('db1', '{ "create": "col1_view1", "viewOn": "col1" }'); -- "views" should be 1 SELECT documentdb_api.db_stats('db1'); -- create one view on each remaining collection SELECT documentdb_api.create_collection_view('db1', '{ "create": "col2_view1", "viewOn": "col2" }'); SELECT documentdb_api.create_collection_view('db1', '{ "create": "col3_view1", "viewOn": "col3" }'); SELECT documentdb_api.create_collection_view('db1', '{ "create": "col4_view1", "viewOn": "col4" }'); SELECT documentdb_api.create_collection_view('db1', '{ "create": "col5_view1", "viewOn": "col5" }'); -- "views" should be 5 SELECT documentdb_api.db_stats('db1'); -- Drop one collection (despite a view on it) SELECT documentdb_api.drop_collection('db1', 'col5'); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- "collections" should be 4, and "objects" will reduce SELECT documentdb_api.db_stats('db1'); -- Drop one view SELECT documentdb_api.drop_collection('db1', 'col5_view1'); -- "views" should be 4 SELECT documentdb_api.db_stats('db1'); -- Drop all remaining collections SELECT documentdb_api.drop_collection('db1', 'col1'); SELECT documentdb_api.drop_collection('db1', 'col2'); SELECT documentdb_api.drop_collection('db1', 'col3'); SELECT documentdb_api.drop_collection('db1', 'col4'); -- Only "views" and fs stats should be available, rest all should be zero values. SELECT documentdb_api.db_stats('db1'); --===================== Test with another database =============================-- -- Make sure this new database does not exist SELECT documentdb_api.drop_database('db2'); -- Add one document SELECT documentdb_api.insert_one('db2','col1',' { "a" : 100 }', NULL); -- In this test we cannot wait till Autovaccum nap time is over, so we manually trigger the ANALYZE ANALYZE; -- various stats should be available SELECT documentdb_api.db_stats('db2'); --===================== Test for "scale" Values =============================-- SELECT documentdb_api.db_stats('db2', 1); SELECT documentdb_api.db_stats('db2', 2); SELECT documentdb_api.db_stats('db2', 2.5); SELECT documentdb_api.db_stats('db2', 2.99); SELECT documentdb_api.db_stats('db2', 100); SELECT documentdb_api.db_stats('db2', 1024.99); SELECT documentdb_api.db_stats('db2', 2147483647); -- INT_MAX SELECT documentdb_api.db_stats('db2', 2147483647000); -- More than INT_MAX --===================== ERROR Cases =============================-- SELECT documentdb_api.db_stats('db2', 0); SELECT documentdb_api.db_stats('db2', 0.99); SELECT documentdb_api.db_stats('db2', -0.2); SELECT documentdb_api.db_stats('db2', -2); SELECT documentdb_api.db_stats('db2', -2147483648); -- INT_MIN SELECT documentdb_api.db_stats('db2', -2147483647000); -- Less than INT_MIN --======================== Clean Up =============================-- SET client_min_messages TO WARNING; -- Clean up SELECT documentdb_api.drop_database('db1'); -- Should return Zero values for non-existing collection (except of fs stats) SELECT documentdb_api.db_stats('db1'); -- Clean up SELECT documentdb_api.drop_database('db2'); -- Should return Zero values for non-existing collection (except of fs stats) SELECT documentdb_api.db_stats('db2'); SET client_min_messages TO DEFAULT; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_delete.sql000066400000000000000000000615411507310017400327230ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 639000; SET documentdb.next_collection_id TO 6390; SET documentdb.next_collection_index_id TO 6390; SET documentdb.EnableVariablesSupportForWriteCommands TO on; -- Call delete for a non existent collection. -- Note that this should not report any logs related to collection catalog lookup. SET citus.log_remote_commands TO ON; SELECT documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"limit":0}]}'); RESET citus.log_remote_commands; select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":1,"_id":1}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":2,"_id":2}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":3,"_id":3}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":4,"_id":4}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":5,"_id":5}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":6,"_id":6}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":7,"_id":7}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":8,"_id":8}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":9,"_id":9}'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":10,"_id":10}'); -- exercise invalid delete syntax errors select documentdb_api.delete('db', NULL); select documentdb_api.delete(NULL, '{"delete":"removeme", "deletes":[{"q":{},"limit":0}]}'); select documentdb_api.delete('db', '{"deletes":[{"q":{},"limit":0}]}'); select documentdb_api.delete('db', '{"delete":"removeme"}'); select documentdb_api.delete('db', '{"delete":["removeme"], "deletes":[{"q":{},"limit":0}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":{"q":{},"limit":0}}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}], "extra":1}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{}}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"limit":0}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":[],"limit":0}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"extra":1}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}],"ordered":1}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":5}]}'); -- Disallow writes to system.views select documentdb_api.delete('db', '{"delete":"system.views", "deletes":[{"q":{},"limit":0}]}'); -- delete all begin; SET LOCAL search_path TO ''; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0}]}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete some begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":0}]}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- arbitrary limit type works in Mongo begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":{"hello":"world"}}]}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete all from non-existent collection select documentdb_api.delete('db', '{"delete":"notexists", "deletes":[{"q":{},"limit":0}]}'); -- query syntax errors are added the response select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$ltr":5}},"limit":0}]}'); -- when ordered, expect only first delete to be executed begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}]}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}],"ordered":true}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- when not ordered, expect first and last delete to be executed begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":1},"limit":0},{"q":{"$a":2},"limit":0},{"q":{"a":3},"limit":0}],"ordered":false}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 without filters is supported for unsharded collections begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}', NULL, 'xact-1'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}', NULL, 'xact-1'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 is supported in the _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":6},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; rollback; -- delete 1 is supported in the multiple identical _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":6}]},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; rollback; -- delete 1 is supported in the multiple distinct _id case (but a noop) begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; rollback; -- validate _id extraction begin; set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":6},"limit":1}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); reset citus.log_remote_commands; rollback; -- shard the collection select documentdb_api.shard_collection('db', 'removeme', '{"a":"hashed"}', false); -- make sure we get the expected results after sharding a collection begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$lte":3}},"limit":0}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":1}'; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":10}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete with oject_id and no shard_key works BEGIN; select count(*) from documentdb_api.collection('db', 'removeme'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":{"$eq":5}},"limit":0}], "ordered": false }'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- test pruning logic in delete begin; select count(*) from documentdb_api.collection('db', 'removeme'); set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":0}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; begin; select count(*) from documentdb_api.collection('db', 'removeme'); set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"limit":0}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 without filters is unsupported for sharded collections select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":1}]}'); -- delete 1 with shard key filters is supported for sharded collections begin; select count(*) from documentdb_api.collection('db', 'removeme'); set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 with shard key filters is retryable begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}', NULL, 'xact-2'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":5}},"limit":1}]}', NULL, 'xact-2'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 that does not match any rows is still retryable begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":15}},"limit":1}]}', NULL, 'xact-3'); select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":15,"_id":15}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a":{"$eq":15}},"limit":1}]}', NULL, 'xact-3'); rollback; -- delete 1 is supported in the _id case even on sharded collections begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":11,"_id":10}'); -- delete first row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; -- delete second row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; -- no more row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":10}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 with with _id filter on a sharded collection is retryable begin; -- add an additional _id 10 (total to 11 rows) select 1 from documentdb_api.insert_one('db', 'removeme', '{"a":11,"_id":10}'); -- delete first row where _id = 10 select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}', NULL, 'xact-4'); -- second time is a noop select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"_id":10},"limit":1}]}', NULL, 'xact-4'); select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- delete 1 is supported in the multiple identical _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":6}]},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; rollback; -- delete 1 is unsupported in the multiple distinct _id case begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"_id":6},{"_id":5}]},"limit":1}]}'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"_id":6}'; rollback; -- validate _id extraction begin; set local citus.log_remote_commands to on; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"a": 11, "_id":6},"limit":0}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{"$and":[{"a": 11},{"_id":6},{"_id":5}]},"limit":0}]}'); reset citus.log_remote_commands; rollback; -- delete with spec in special section begin; select count(*) from documentdb_api.collection('db', 'removeme'); select documentdb_api.delete('db', '{"delete":"removeme"}', '{ "":[{"q":{"a":{"$eq":5}},"limit":1}] }'); select count(*) from documentdb_api.collection('db', 'removeme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'removeme'); rollback; -- deletes with both specs specified begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes": [{"q":{"a":{"$eq":5}},"limit":1}] }', '{ "":[{"q":{"a":{"$eq":5}},"limit":1}] }'); rollback; -- delete with index hint specified by name and by key object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "removeme", "indexes": [ { "key" : { "a": 1 }, "name": "validIndex"}] }', true); begin; select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"hint": "validIndex"}]}'); select documentdb_api.delete('db', '{"delete":"removeme", "deletes":[{"q":{},"limit":0,"hint": { "a": 1 }}]}'); rollback; select documentdb_api.drop_collection('db','removeme'); SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 1,"a":3,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 2,"a":2,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('delete', 'test_sort_returning', '{"_id": 3,"a":1,"b":6}'); -- sort in ascending order and project & return deleted document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "b": 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); -- sort by multiple fields (i) and return deleted document BEGIN; SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "b": -1, "a" : 1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); ROLLBACK; -- sort by multiple fields (ii) and return deleted document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'delete' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.delete_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "deleteOne": { "query": { "a": {"$gte": 1} }, "sort": { "a": 1, "b" : -1 }, "returnDocument": 1, "returnFields": { "a": 0} } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('delete', 'test_sort_returning'); SELECT document FROM documentdb_api.collection('delete', 'test_sort_returning') ORDER BY 1; -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.delete( 'delete', '{ "delete": "dne", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.delete( 'delete', '{ "delete": "dne", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": false }' ); SELECT documentdb_api.create_collection('delete', 'no_match'); -- show that we validate "query" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.delete( 'delete', '{ "delete": "no_match", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.delete( 'delete', '{ "delete": "no_match", "deletes": [ {"q": {"a": 1}, "limit": 0 }, {"q": {"$b": 1}, "limit": 0 }, {"q": {"c": 1}, "limit": 0 }, {"q": {"$d": 1}, "limit": 0 }, {"q": {"e": 1}, "limit": 0 } ], "ordered": false }' ); -- _id test using $in opearator with explain plan select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":1,"_id":1}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":2,"_id":2}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":3,"_id":3}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":4,"_id":4}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":5,"_id":5}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":6,"_id":6}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":7,"_id":7}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":8,"_id":8}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":9,"_id":9}'); select 1 from documentdb_api.insert_one('db', 'explainTest', '{"a":10,"_id":10}'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); SELECT documentdb_api.delete( 'db', '{ "delete": "explainTest", "deletes": [ {"q": {"_id": {"$in" : [2,4,6,8,10] } }, "limit": 0 } ], "ordered": true }' ); select document from documentdb_api.collection('db', 'explainTest') order by 1; -- let support SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 1, "a":"dog"}'); SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 2, "a":"cat"}'); SELECT documentdb_api.insert_one('db', 'coll_delete', '{"_id": 3, "a":"$$varRef"}'); -- enableVariablesSupportForWriteCommands GUC off: ignore variableSpec SET documentdb.enableVariablesSupportForWriteCommands TO off; SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "cat"} }'); -- enableVariablesSupportForWriteCommands GUC on: user variableSpec SET documentdb.enableVariablesSupportForWriteCommands TO on; -- variables accessed outside $expr will not evaluate to let variable value SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "$$varRef" }, "limit": 0}], "let": {"varRef": 2}} '); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": "$$varRef" }, "limit": 1}], "let": {"varRef": 2}} '); BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); ROLLBACK; BEGIN; --- deleteOne (1) SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$_id", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); ROLLBACK; BEGIN; --- deleteMany (2) SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lte": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "zebra"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; -- deleteMany: when ordered, expect only first delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; -- deleteOne: when ordered, expect only first delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$_id", "$$varRef1"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef2"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 1}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; -- deleteMany: when not ordered, expect first and last delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": false, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; -- deleteOne: when not ordered, expect first and last delete to be executed SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$_id", "$$varRef1"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef2"] } }, "limit": 1}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 1}], "ordered": false, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; -- sharded collection SELECT documentdb_api.shard_collection('db', 'coll_delete', '{ "a": "hashed" }', false); BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": 2} }'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "limit": 1}], "let": {"varRef": "cat"} }'); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lte": ["$a", "$$varRef"] } }, "limit": 0}], "let": {"varRef": "zebra"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; BEGIN; SELECT document from documentdb_api.collection('db', 'coll_delete'); SELECT documentdb_api.delete('db', '{ "delete": "coll_delete", "deletes": [ { "q": { "$expr": {"$lt": ["$a", "$$varRef1"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$a", "$$varRef2"] } }, "limit": 0}, { "q": { "$expr": {"$lte": ["$_id", "$$varRef1"] } }, "limit": 0}], "ordered": true, "let": {"varRef1": 2, "varRef2": "kangaroo"}} '); SELECT document from documentdb_api.collection('db', 'coll_delete'); ROLLBACK; RESET documentdb.enableVariablesSupportForWriteCommands;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_drop_indexes.sql000066400000000000000000000065741507310017400341510ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 150000; SET documentdb.next_collection_id TO 15000; SET documentdb.next_collection_index_id TO 15000; ---- dropIndexes - top level - parse error ---- SELECT documentdb_api.create_collection('db', 'collection_3'); CALL documentdb_api.drop_indexes('db', NULL); CALL documentdb_api.drop_indexes(NULL, '{}'); CALL documentdb_api.drop_indexes('db', '{}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": null, "index": ["my_idx_1", "does_not_exist"]}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "unknown_field": 1}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": null}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3"}'); -- this is ok CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index":[]}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": 1, "index":[]}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": 1}'); ---- dropIndexes - top level - not implemented yet ---- CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": {}}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "writeConcern": 1}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "comment": 1}'); ---- dropIndexes -- collection doesn't exist ---- CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_4"}'); ---- dropIndexes -- index doesn't exist ---- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "collection_3", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["my_idx_1", "does_not_exist"]}'); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["does_not_exist", "my_idx_1"]}'); ---- dropIndexes -- unique unidex should work (unique index alters the table to remove a constraint) SELECT documentdb_api_internal.create_indexes_non_concurrently(p_arg=>'{"createIndexes": "collection_3", "indexes": [{"key": {"a": 1}, "name": "idx_1", "unique": true }]}', p_database_name=>'db', p_skip_check_collection_create=>true); CALL documentdb_api.drop_indexes('db', '{"dropIndexes": "collection_3", "index": ["idx_1"]}'); -- test drop_collection SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "drop_collection_test", "indexes": [{"key": {"a": 1}, "name": "my_idx_1"}]}', true); -- store id of drop_collection_test before dropping it SELECT collection_id AS db_drop_collection_test_id FROM documentdb_api_catalog.collections WHERE collection_name = 'drop_collection_test' AND database_name = 'db' \gset -- Insert a record into index metadata that indicates an invalid collection index -- to show that we delete records for invalid indexes too when dropping collection. INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:db_drop_collection_test_id, 1010, ('invalid_index_1', '{"a": 1}', null, null, null, null, 2, null, null, null), false); SELECT documentdb_api.drop_collection('db', 'drop_collection_test'); SELECT COUNT(*)=0 FROM documentdb_api_catalog.collection_indexes WHERE collection_id = :db_drop_collection_test_id; commands_find_and_modify.sql000066400000000000000000000640701507310017400345130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET citus.next_shard_id TO 540000; SET documentdb.next_collection_id TO 5400; SET documentdb.next_collection_index_id TO 5400; -- null db name SELECT documentdb_api.find_and_modify(NULL, '{}'); -- null message SELECT documentdb_api.find_and_modify('db', NULL); -- missing params SELECT documentdb_api.find_and_modify('fam', '{}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "remove_or_update"}'); -- no such collection, upsert=false -- i) remove=true SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1000}, "remove": 0.1, "sort": {"b": -1}}'); -- ii) remove=false SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "upsert": false}'); -- no such collection, upsert=true -- i) query is given SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_1", "query": {"a": 1}, "update": {"_id": 1, "b": 1}, "upsert": 1.1}'); SELECT document FROM documentdb_api.collection('fam', 'create_on_fam_1') ORDER BY document; -- ii) query is not given, and the upserted document is requested SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_2", "update": {"_id": 1, "b": 1}, "upsert": true, "new": -1}'); SELECT document FROM documentdb_api.collection('fam', 'create_on_fam_2') ORDER BY document; -- iii) enable_create_collection_on_insert is disabled BEGIN; SET LOCAL documentdb.enable_create_collection_on_insert TO OFF; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "create_on_fam_3", "update": {"_id": 1, "b": 1}, "upsert": true}'); ROLLBACK; -- test conflicting options SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "update": {"b": 1}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "upsert": true}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "opts_conflict", "remove": true, "new": true}'); -- field type validations SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": []}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "query": 1}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "sort": "text"}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "remove": {}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "update": 1}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "new": []}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "fields": "text"}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "invalid_type", "upsert": []}'); -- hard errors for unsupported options SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "not_supported", "arrayFilters": 1}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "not_supported", "hint": 1}'); -- unknown option SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "unknown_option", "unknown_option": 1}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'collection', '{"a":5,"b":6}'); -- Disallow writes to system.views SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "system.views", "query": null, "remove": 0.0, "sort": {"b": -1}, "update": {"a": 10}, "fields": {"_id": 0}}'); BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": null, "remove": 0.0, "sort": {"b": -1}, "update": {"a": 10}, "fields": {"_id": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 5}, "sort": {"b": 1}, "update": 1, "update": {"a": 20}, "fields": {"_id": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"a": 1}, "fields": {"_id": 0, "b": 0}, "upsert": 0, "new": false}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": "", "sort": {"b": 1}, "update": {"a": 1}, "fields": {"_id": 0, "b": 0}, "upsert": false, "new": true}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"_id": 40, "a": 30}, "fields": {"b": 1, "_id": 0}, "upsert": true}'); -- using update operators / aggregation pipeline -- -- multiple $inc, so only takes the last one into the account SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": { "$gte": 15 } }, "sort": {"a": 1}, "update": {"$set": {"z": 5}, "$inc": {"z": 5}, "$inc": {"a": 10}}, "upsert": false, "new": true, "fields": {"_id": 0}}'); -- multiple $set/$inc but provided via a single document, so applies all SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 1000 }, "update": {"$set": {"_id": 1000, "p": 10, "r": 20}, "$inc": {"s": 30, "t": 40}}, "upsert": true, "new": true, "fields": {"_id": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"z": { "$exists": false } }, "sort": {"a": 1}, "update": [{"$set": {"a": -10}}, {"$addFields": {"z": 7}}], "upsert": false, "new": true, "fields": {"_id": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 2000 }, "update": [ {"$set": {"p": 40, "_id": 2000, "r": 50}}, {"$unset": "p"}, {"$set": {"r": 70}}], "new": true, "fields": {"_id": 0}, "upsert": 1}'); ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": {"_id": 40, "a": [ 30 ]}, "fields": {"b": 1, "_id": 0}, "upsert": true}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "sort": {"b": 1}, "update": { "$set": { "a.$[a]": 10 }}, "fields": {"b": 1, "_id": 0}, "upsert": true, "arrayFilters": [ { "a": 30 } ]}'); ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": { "$gte": 15 } }, "sort": {}, "update": {"$set": {"z": 5}, "$inc": {"z": 5}, "$inc": {"a": 10}}, "upsert": false, "new": true, "fields": {}}'); ROLLBACK; BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": null, "remove": true, "sort": {"b": -1}, "fields": {"_id": 0, "a": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 5}, "remove": true, "sort": {"b": 1}, "fields": {"_id": 0, "b": 1}, "upsert": null}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "remove": true, "sort": {"b": 1}, "fields": {"_id": 0}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"a": 100}, "remove": true, "sort": {}, "fields": {}}'); ROLLBACK; -- test a sharded collection SELECT documentdb_api.create_collection('fam','sharded_collection'); SELECT documentdb_api.shard_collection('fam','sharded_collection', '{"a":"hashed"}', false); SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a": 10,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a":20,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"a":30,"b":6}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"b":8}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'sharded_collection', '{"b":9,"a": null}'); -- update the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": 10}, "update": {"$set": {"a": 1000}}, "fields": {"_id": 0}, "new": true}'); -- update a field other than the shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": 20}, "update": {"$set": {"b": -1}}, "fields": {"_id": 0}, "new": true}'); -- test upsert SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": -1}, "update": {"$set": {"b": -2, "_id": 100}}, "new": true, "upsert": true}'); -- test "null" shard key: i) shard key is really equal to null SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"$set": {"b": -3}}, "fields": {"_id": 0}, "sort": {"b": -1}, "new": true}'); -- test "null" shard key: ii) shard key is not set -- should update the document having {"b": 8} even if it doesn't specify "a" field at all BEGIN; SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"$set": {"b": -4}}, "fields": {"_id": 0}, "sort": {"b": -1}, "new": false}'); ROLLBACK; -- test "null" shard key: iii) shard key is not set -- should update the document having {"b": -3} SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": null}, "update": {"b": -4}, "fields": {"_id": 0}, "sort": {"b": 1}, "new": false}'); -- missing shard key SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"a": { "$gte": 15 } }, "update": {"$set": {"z": 5}}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": null, "update": {"a": 10}}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -2}, "remove": true}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -2, "a": -1}, "remove": true}'); -- should match the document having {"b": -4} even if it doesn't specify "a" field at all SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "sharded_collection", "query": {"b": -4, "a": null}, "remove": true, "fields": {"_id": 0}}'); -- show that we validate "update" document even if collection doesn't exist or if we can't match any documents SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"a": 1}, "update": { "$set": { "a": 1 }, "$unset": {"a": 1 } } }'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "dne", "query": {"$a": 1}, "update": { "$set": { "a": 1 } } }'); SELECT documentdb_api.create_collection('fam', 'no_match'); \set VERBOSITY TERSE SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "no_match", "update": { "$set": { "a": 1 }, "$unset": {"a": 1 } }}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "no_match", "query": {"$a": 1}, "update": { "$set": { "a": 1 } } }'); \set VERBOSITY DEFAULT -- test retryable update SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_update', '{"_id": 1, "a": 1, "b": 1}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": false}', 'xact-1'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true}', 'xact-1'); SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-1'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"_id": 0}}', 'xact-1'); SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; SELECT documentdb_api.shard_collection('fam','retryable_update', '{"a":"hashed"}', false); -- test with upsert SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"a": 0}}', 'xact-1'); -- Note that specifying different values for "new"/"fields" fields doesn't -- have any effect on the response message. SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": false, "upsert": true, "fields": {"b": 0}}', 'xact-1'); SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; -- test with upsert, collection gets created automatically SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update_dne", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": false, "upsert": true}', 'xact-2'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update_dne", "query": {"_id": 2, "a": 100}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true}', 'xact-2'); SELECT document FROM documentdb_api.collection('fam', 'retryable_update_dne') ORDER BY document; -- test retryable delete SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete', '{"_id": 1, "a": 1, "b": 1}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete', '{"_id": 2, "a": 1, "b": 1}'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true}', 'xact-11'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true}', 'xact-11'); SELECT document FROM documentdb_api.collection('fam', 'retryable_delete') ORDER BY document; -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true, "fields": {"b": 0}}', 'xact-11'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 1}, "remove": true, "fields": {"a": 0}}', 'xact-11'); SELECT document FROM documentdb_api.collection('fam', 'retryable_delete') ORDER BY document; SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete_sharded', '{"_id": 1, "a": 1, "b": 1}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'retryable_delete_sharded', '{"_id": 2, "a": 1, "b": 1}'); SELECT documentdb_api.shard_collection('fam','retryable_delete_sharded', '{"a":"hashed"}', false); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true, "fields": {"b": 0}}', 'xact-14'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true, "fields": {"a": 0}}', 'xact-14'); SELECT document FROM documentdb_api.collection('fam', 'retryable_delete_sharded') ORDER BY document; -- third call is considered a new try SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true}', 'xact-14'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_sharded", "query": {"a": 1}, "remove": true}', 'xact-14'); SELECT document FROM documentdb_api.collection('fam', 'retryable_delete_sharded') ORDER BY document; -- test with a query that doesn't match any documents SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 100}, "remove": true}', 'xact-11'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete", "query": {"a": 100}, "remove": true}', 'xact-11'); -- test with a collection that doesn't exist SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_dne", "query": {"a": 100}, "remove": true}', 'xact-13'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_delete_dne", "query": {"a": 100}, "remove": true}', 'xact-13'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-20'); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "retryable_update", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "fields": {"a": 0}}', 'xact-20'); SELECT document FROM documentdb_api.collection('fam', 'retryable_update') ORDER BY document; -- unknown operator expressions in fields argument SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"_id": 1}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"foo": {"$pop": ["bar"]}}}'); -- test with operator expression in fields argument SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "collection", "query": {"_id": 1}, "update": {"$inc": {"b": 1}}, "new": true, "upsert": true, "fields": {"foo": {"$pow": [1, 2]}}}'); DO $$ begin for r in 1..1000 loop PERFORM documentdb_api.insert_one('db', 'findAndModify', FORMAT('{"_id": %s, "a": "%s", "b": "%s", "c": "%s_1"}', r, (select string_agg( substr(md5(random()::text), 1, 280), '') FROM generate_series(1, 50)), (select string_agg( substr(md5(random()::text), 1, 280), '') FROM generate_series(1, 80)),r)::documentdb_core.bson); end loop; end; $$; SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "findAndModify", "remove": false, "query": {"_id": 549}, "upsert": false, "update": {"$set": {"c": "foo"}}, "new": false, "fields": { "_id": 1 }}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "findAndModify", "remove": false, "query": {"_id": 549}, "upsert": false, "update": {"$set": {"c": "foo"}}, "new": false, "fields": { "_id": 1 }}'); -- delete toasted document -- the document size is larger than 2000, so the tuple is toasted SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 1000)), (select string_agg('b', '') FROM generate_series(1, 1000)))::documentdb_core.bson); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true, "fields": {"_id": 0, "a": 0}}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 1000)), (select string_agg('b', '') FROM generate_series(1, 1000)))::documentdb_core.bson); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true}'); -- delete non-toasted document SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 100)), (select string_agg('b', '') FROM generate_series(1, 100)))::documentdb_core.bson); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true, "fields": {"_id": 0, "a": 0}}'); SELECT 1 FROM documentdb_api.insert_one('fam', 'large_toasted_coll', FORMAT('{"_id": %s, "a": "%s", "b": "%s"}', 1, (select string_agg('a', '') FROM generate_series(1, 100)), (select string_agg('b', '') FROM generate_series(1, 100)))::documentdb_core.bson); SELECT documentdb_api.find_and_modify('fam', '{"findAndModify": "large_toasted_coll", "query": null, "remove": true}'); -- let support SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 1, "a":"akura"}'); SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 2, "a":"adanko"}'); SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 3, "a":"odwan"}'); SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 4, "a":"okra"}'); SELECT documentdb_api.insert_one('db', 'find_and_modify_let', '{"_id": 5, "a":"$$varRef"}'); -- disable let support: turn off GUC SET documentdb.enableVariablesSupportForWriteCommands TO OFF; SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "let_support", "query": {"a": 1}, "update": {"$inc": {"b": 1}}, "new": true, "let": {"x": 10}}'); -- enable let support: turn on GUC SET documentdb.enableVariablesSupportForWriteCommands TO ON; -- without $expr: variable won't evaluate to value SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": "$$varRef" }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "akura"}}'); BEGIN; -- update SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "akura"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$gt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "odwan"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lte": [{ "$toInt": "$$varRef" }, "$_id"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "4"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$eq": ["$c", "$$varRef2"]}]}}, "sort": {"a": 1}, "update": {"c": "peacock"}, "let": {"varRef1": 4, "varRef2": "camel"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; BEGIN; -- update with aggregation pipeline SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$set": {"c": "$$varRef"}}], "let": {"varRef": 1}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$addFields": {"c": "$$varRef"}}], "let": {"varRef": "adanko"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; BEGIN; --- delete SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$a", "$$varRef"]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef": "akura"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": 3}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$lte": ["$a", "$$varRef2"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef1": 4, "varRef2": "okra"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; BEGIN; --- delete (2) SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "remove": true, "let": {"varRef": "okra"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$gte": [{ "$toInt": "$$varRef" }, "$_id"] } }, "sort": {"a": 1}, "remove": true, "let": {"varRef": "4"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$eq": ["$_id", "$$varRef"] }}, "sort": {"a": 1}, "remove": true, "let": {"varRef": 2}}');; SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; -- undefined variables SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"$expr": {"$lt": ["$_id", "$$varRef2"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef1": 3}}'); --- sharded collection SELECT documentdb_api.shard_collection('db', 'find_and_modify_let', '{ "_id": "hashed" }', false); BEGIN; -- update SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": "3", "$expr": {"$eq": [{"$toInt": "$$varRef"}, "$_id"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": "3"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 4, "$expr": {"$lt": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "camel"}, "let": {"varRef": "odwan"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$eq": ["$c", "$$varRef2"]}]}}, "sort": {"a": 1}, "update": {"c": "peacock"}, "let": {"varRef1": 4, "varRef2": "ant"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; BEGIN; -- update with aggregation pipeline SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$set": {"c": "$$varRef"}}], "let": {"varRef": 1}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "sort": {"a": 1}, "update": [{"$addFields": {"c": "$$varRef"}}], "let": {"varRef": "adanko"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; BEGIN; --- delete SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 2, "$expr": {"$lt": ["$_id", "$$varRef"] } }, "sort": {"a": 1}, "update": {"c": "ant"}, "let": {"varRef": 3}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 1, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef"]}, {"$eq": ["$a", "akura"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef": "akura"}}'); SELECT documentdb_api.find_and_modify('db', '{"findAndModify": "find_and_modify_let", "query": {"_id": 4, "$expr": {"$and": [{"$eq": ["$_id", "$$varRef1"]}, {"$lte": ["$a", "$$varRef2"]}]}}, "sort": {"a": 1}, "remove": true, "let": {"varRef1": 4, "varRef2": "okra"}}'); SELECT document from documentdb_api.collection('db', 'find_and_modify_let') ORDER BY document; ROLLBACK; RESET documentdb.enableVariablesSupportForWriteCommands;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_insert.sql000066400000000000000000000163151507310017400327640ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 659000; SET documentdb.next_collection_id TO 6590; SET documentdb.next_collection_index_id TO 6590; -- exercise invalid insert syntax errors select documentdb_api.insert('db', NULL); select documentdb_api.insert(NULL, '{"insert":"into", "documents":[{"a":1}]}'); select documentdb_api.insert('db', '{"documents":[{"a":1}]}'); select documentdb_api.insert('db', '{"insert":"into"}'); select documentdb_api.insert('db', '{"insert":["into"], "documents":[{"a":1}]}'); select documentdb_api.insert('db', '{"insert":"into", "documents":{"a":1}}'); select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}], "extra":1}'); select documentdb_api.insert('db', '{"insert":"into", "documents":[4]}'); select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}],"ordered":1}'); -- Disallow system.views, system.profile writes select documentdb_api.insert('db', '{"insert":"system.views", "documents":[{"a":1}],"ordered":true}'); select documentdb_api.insert('db', '{"insert":"system.profile", "documents":[{"a":1}],"ordered":true}'); -- regular single-row insert select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":99,"a":99}]}'); select document from documentdb_api.collection('db','into') where document @@ '{}'; -- Insert into a db with same name and different case and collection being same. Expect to error select documentdb_api.insert('dB', '{"insert":"into", "documents":[{"_id":99,"a":99}]}'); -- Insert into a db with same name and different case and collection being different. Expect to error select documentdb_api.insert('dB', '{"insert":"intonew", "documents":[{"_id":99,"a":99}]}'); -- Insert into same db and new collection. select documentdb_api.insert('db', '{"insert":"intonew1", "documents":[{"_id":99,"a":99}]}'); -- keep the collection, but remove the rows select documentdb_api.delete('db', '{"delete":"into", "deletes":[{"q":{},"limit":0}]}'); -- single-row insert with retry begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-1'); select document from documentdb_api.collection('db','into') where document @@ '{}'; rollback; -- regular multi-row insert begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; rollback; -- multi-row insert with first document key starts with $ begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; rollback; -- multi-row insert with first document key starts with $ and ordered:false begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"$a":1},{"_id":2,"a":2}],"ordered":false}'); select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; rollback; -- shard the collection by _id select documentdb_api.shard_collection('db', 'into', '{"_id":"hashed"}', false); -- single-row insert with retry begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1}]}',NULL,'insert-2'); select document from documentdb_api.collection('db','into') where document @@ '{}'; rollback; -- single-row insert with retry and auto-generated _id begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}]}',NULL,'insert-2'); select documentdb_api.insert('db', '{"insert":"into", "documents":[{"a":1}]}',NULL,'insert-2'); select count(*) from documentdb_api.collection('db','into') where document @@ '{}'; rollback; -- multi-row insert into different shards begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}'); select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; select document from documentdb_api.collection('db','into') where document @@ '{"a":1}' order by document-> '_id'; select document from documentdb_api.collection('db','into') where document @@ '{"a":2}' order by document-> '_id'; rollback; -- insert with documents in special section begin; SELECT documentdb_api.insert('db', '{"insert":"into"}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); select document from documentdb_api.collection('db','into') where document @@ '{}' order by document-> '_id'; rollback; -- insert with both docs specified. begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":1,"a":1},{"_id":2,"a":2}]}', '{ "": [{"_id":1,"a":1},{"_id":2,"a":2}] }'); rollback; -- insert with id undefined skips begin; select documentdb_api.insert('db', '{"insert":"into", "documents":[{"_id":{ "$undefined": true } }]}'); rollback; begin; select documentdb_api.insert('db', '{"insert":"into"}', '{ "": [ {"_id":{ "$undefined": true } } ]}'); rollback; -- single-row insert into non-existent collection when auto-creation is disabled begin; set local documentdb.enable_create_collection_on_insert to off; select documentdb_api.insert('db', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); rollback; -- insert with invalid database begin; select documentdb_api.insert('Invalid Database Name', '{"insert":"notexists", "documents":[{"_id":1,"a":1}]}'); rollback; begin; select documentdb_api.insert('db', '{"insert":"system.othercoll", "documents":[{"_id":1,"a":1}]}'); rollback; begin; select documentdb_api.insert('db', '{"insert":"random$name", "documents":[{"_id":1,"a":1}]}'); rollback; begin; select documentdb_api.insert('db', '{"insert":".randomname", "documents":[{"_id":1,"a":1}]}'); rollback; begin; select documentdb_api.insert('verylongdatabasenameformeasuringthelimitsofdatabasenamesinmongodb', '{"insert":"coll", "documents":[{"_id":1,"a":1}]}'); rollback; begin; select documentdb_api.insert('verylongdatabasenameformeasuringlimitsofdatabasenamesinmongodb', '{"insert":"verylongcollectionnameformeasuringthelimitsofcollectionnamesinmongodb", "documents":[{"_id":1,"a":1}]}'); rollback; select documentdb_api.drop_collection('db','into'); select documentdb_api.drop_collection('db','intonew1'); -- Server contract - never attempt to deduplicate inserting documents, the clients may deduplicate them based on the handling of JSON/BSON data type. select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate1", "a": {"$numberInt": "1"}}'); select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate2", "a": {"$numberInt": "1"}, "a": {"$numberInt": "2"}}'); select documentdb_api.insert_one('db', 'duplicatetests', '{"_id": "duplicate3", "a": {"$numberInt": "1"}, "b": {"$numberInt": "2"}}'); -- storage size of duplicate2 and duplicate3 should be same. SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "duplicatetests", "pipeline": [{"$project": { "storageSize": {"$bsonSize": "$$ROOT"} } }] }');commands_shard_collection.sql000066400000000000000000000276061507310017400347220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2400000; SET documentdb.next_collection_id TO 24000; SET documentdb.next_collection_index_id TO 24000; -- before reshard SELECT documentdb_api.insert_one('db','reshard','{"_id":"1", "value": { "$numberInt" : "11" }}'); BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}'; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}'; ROLLBACK; -- invalid inputs SELECT documentdb_api.shard_collection('db','reshard', '{"value":1}'); SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hash"}'); -- create two indexes before re-sharding SELECT documentdb_api_internal.create_indexes_non_concurrently( 'db', '{ "createIndexes": "reshard", "indexes": [ {"key": {"a.b.c.$**": 1}, "name": "idx_1"}, {"key": {"z": 1}, "name": "idx_2"} ] }', true ); SELECT collection_id AS reshard_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'reshard' AND database_name = 'db' \gset \d documentdb_data.documents_:reshard_collection_id -- insert an invalid index metadata entry before re-sharding INSERT INTO documentdb_api_catalog.collection_indexes (collection_id, index_id, index_spec, index_is_valid) VALUES (:reshard_collection_id, 2020, ('invalid_index', '{"c": 1}', null, null, null, null, 2, null, null, null), false); -- shard based on value key SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hashed"}', false); \d documentdb_data.documents_:reshard_collection_id SELECT FORMAT('documentdb_data.documents_%s', :reshard_collection_id) AS db_shard_data_table_name \gset -- make plans (more) deterministic VACUUM (ANALYZE) :db_shard_data_table_name; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'reshard') ORDER BY index_id; SELECT documentdb_api.insert_one('db','reshard','{"value":{"$numberLong" : "134311"}, "_id":"2" }'); SELECT documentdb_api.insert_one('db','reshard','{"_id":"3", "value": 11}'); -- documents without a shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"4", "novalue": 0}'); SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$exists":false}}'; -- documents with an object shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"5", "value": {"hello":"world"}}'); SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"hello":"world"}}'; -- documents with an array shard key are not allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": ["hello","world"]}'); -- documents with regex shard key are not allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": {"$regularExpression":{"pattern":"foo","options":""}}}'); -- documents with double shard key are allowed SELECT documentdb_api.insert_one('db','reshard','{"_id":"6", "value": 15.0}'); -- after reshard BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; ROLLBACK; -- small longs have the same hash as ints BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberLong" : "134311"}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberLong" : "134311"}}' ORDER BY object_id; ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberInt" : "134311"}}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$numberInt" : "134311"}}' ORDER BY object_id; ROLLBACK; -- should find doubles too when looking for int BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":15}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":15}' ORDER BY object_id; ROLLBACK; -- reshard based on value and _id key SELECT documentdb_api.shard_collection('db','reshard', '{"value":"hashed","_id":"hashed"}', true); -- after reshard BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"$and":[{"value":{"$eq":11}},{"_id":{"$eq":"1"}}]}'; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"$and":[{"value":{"$eq":11}},{"_id":{"$eq":"1"}}]}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11,"_id":"1"}'; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11,"_id":"1"}'; ROLLBACK; -- should get same hash value SELECT documentdb_api_internal.get_shard_key_value('{"value":1,"_id":1}',1,'{"_id":"1","value":11}'); SELECT documentdb_api_internal.get_shard_key_value('{"value":1,"_id":1}',1,'{"value":11,"_id":"1"}'); SELECT collection_id AS collection_id, shard_key::text AS shard_key FROM documentdb_api_catalog.collections WHERE collection_name = 'reshard' AND database_name = 'db' \gset DO $$ DECLARE v_collection documentdb_api_catalog.collections; v_compute_shard_key bigint; BEGIN SELECT * INTO v_collection FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshard'; SELECT documentdb_api_internal.get_shard_key_value(v_collection.shard_key, v_collection.collection_id, '{"value":11,"_id":"1"}') INTO v_compute_shard_key; RAISE INFO 'Computed shard key: %', v_compute_shard_key; END; $$; -- different order of fields SELECT documentdb_api_internal.get_shard_key_value('{"_id":1,"value":1}', 1,'{"_id":"1","value":11}'); SELECT documentdb_api_internal.get_shard_key_value('{"_id":1,"value":1}', 1,'{"value":11,"_id":"1"}'); -- should produce different hash values because type is taken into account SELECT documentdb_api_internal.get_shard_key_value('{"a":1,"b":1}', 1,'{"_id":"1","a":1,"b":true}'); SELECT documentdb_api_internal.get_shard_key_value('{"a":1,"b":1}', 1,'{"_id":"1","a":true,"b":1}'); -- only 1 part of shard key specified, goes to multiple shards BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":11}' ORDER BY object_id; ROLLBACK; -- no shard key filter specified SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE true; SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE false; SELECT count(*) FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"value":{"$exists":1}}'; -- reshard based on nested path SELECT documentdb_api.shard_collection('db','reshard', '{"a.b":"hashed"}', true); -- we should not allow arrays in the path even if the value is not an array SELECT documentdb_api.insert_one('db','reshard','{"_id":"10", "a": [{"b":22}]}'); -- nested objects should be fine SELECT documentdb_api.insert_one('db','reshard','{"_id":"10", "a": {"b":22}}'); BEGIN; SET LOCAL enable_seqscan TO OFF; SET LOCAL seq_page_cost TO 9999999; EXPLAIN (COSTS OFF) SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"a.b":22}' ORDER BY object_id; SELECT document FROM documentdb_api.collection('db','reshard') WHERE document @@ '{"a.b":22}' ORDER BY object_id; ROLLBACK; -- try to shard a non-existent collection SELECT documentdb_api.shard_collection('db','not_exists', '{"value":"hashed"}', false); -- shard a collection that has no user-created indexes SELECT documentdb_api.insert_one('db','shard_collection_no_indexes','{"_id":"1", "value": { "$numberInt" : "11" }}'); BEGIN; -- Shard it twice within a xact block to test whether we drop the temp table -- (v_saved_index_entries) before completing documentdb_api.shard_collection(). SELECT documentdb_api.shard_collection('db','shard_collection_no_indexes', '{"value":"hashed"}', false); SELECT documentdb_api.shard_collection('db','shard_collection_no_indexes', '{"value":"hashed"}', false); COMMIT; -- shard creates a new collection. BEGIN; SELECT documentdb_api.shard_collection('db', 'newCollectionToCreate', '{ "value": "hashed" }', false); SELECT database_name, collection_name FROM documentdb_api_catalog.collections WHERE collection_name = 'newCollectionToCreate' ORDER BY database_name, collection_name; ROLLBACK; -- shard collection with indexes with bson text as hex binary still works. BEGIN; set local documentdb_core.bsonUseEJson to false; SELECT documentdb_api.insert_one('db','reshardwithindexes2','{"_id":"1", "value": 11, "otherValue": 15 }'); -- create some indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('reshardwithindexes2', 'idx1', '{ "value": 1 }'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('reshardwithindexes2', 'idx2', '{ "otherValue": 1 }'), true); -- now shard the collection SELECT documentdb_api.shard_collection('db', 'reshardwithindexes2', '{ "value": "hashed" }', false); SELECT collection_id AS reshard_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = 'reshardwithindexes2' AND database_name = 'db' \gset set local documentdb_core.bsonUseEJson to true; SELECT index_spec from documentdb_api_catalog.collection_indexes WHERE collection_id = :reshard_collection_id order by index_id ASC; SELECT database_name, collection_name, shard_key from documentdb_api_catalog.collections WHERE collection_id = :reshard_collection_id; ROLLBACK; -- create a new sharded collection SELECT documentdb_api.create_collection('db', 'reshardoptions'); -- now shard it. SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "a.b": "hashed" }', false); -- shard with the same key SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "a.b": "hashed" }'); -- shard with a new key with reshard:false (should fail) SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "c.d": "hashed" }', false); -- key should now be { "a.b": "hashed" } SELECT database_name, collection_name, shard_key FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshardoptions'; -- shard with a new key with reshard:true (should work) SELECT documentdb_api.shard_collection('db', 'reshardoptions', '{ "c.d": "hashed" }', true); -- key should now be { "c.d": "hashed" } SELECT database_name, collection_name, shard_key FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'reshardoptions'; -- reshard on non existing collections or non-sharded collections should fail SELECT documentdb_api.shard_collection('db', 'nonExistingCollection', '{ "a.b": "hashed" }', true); SELECT documentdb_api.create_collection('db', 'nonShardedCollection'); SELECT documentdb_api.shard_collection('db', 'nonShardedCollection', '{ "a.b": "hashed" }', true); documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_update.sql000066400000000000000000001657741507310017400327600ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 649000; SET documentdb.next_collection_id TO 6490; SET documentdb.next_collection_index_id TO 6490; SET documentdb.EnableVariablesSupportForWriteCommands TO on; select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":1,"_id":1,"b":1}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":2,"_id":2,"b":2}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":3,"_id":3,"b":3}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":4,"_id":4,"b":4}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":5,"_id":5,"b":5}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":6,"_id":6,"b":6}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":7,"_id":7,"b":7}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":8,"_id":8,"b":8}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":9,"_id":9,"b":9}'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":10,"_id":10,"b":10}'); -- exercise invalid update syntax errors select documentdb_api.update('db', NULL); select documentdb_api.update(NULL, '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); select documentdb_api.update('db', '{"updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme"}'); select documentdb_api.update('db', '{"update":["updateme"], "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":{"q":{},"u":{"$set":{"b":0}},"multi":true}}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}], "extra":1}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{}}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"u":{"$set":{"b":0}}}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":"text"}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":[],"u":{"$set":{"b":0}},"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":1}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"extra":1}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}],"ordered":1}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$bork":{"b":0}},"multi":true}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"upsert":[]}]}'); -- Disallow writes to system.views select documentdb_api.update('db', '{"update":"system.views", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); -- update all begin; SET LOCAL search_path TO ''; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document OPERATOR(documentdb_api_catalog.@@) '{"b":0}'; rollback; -- update some begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"$set":{"b":0}},"multi":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- update multi with a replace is not supported begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"b":0},"multi":true}]}'); rollback; -- update multi with an aggregation pipeline is supported begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":[{"$unset":["b"]}],"multi":true}]}'); rollback; -- update all from non-existent collection select documentdb_api.update('db', '{"update":"notexists", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); -- query syntax errors are added the response select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$ltr":5}},"u":{"$set":{"b":0}},"multi":true}]}'); -- when ordered, expect only first update to be executed begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":true}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- when not ordered, expect first and last update to be executed begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":false}'); select count(*) from documentdb_api.collection('db', 'updateme'); rollback; -- update 1 without filters is supported for unsharded collections begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- update 1 with a replace that preserves the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"b":0},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- update 1 with a replace that tries to change the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"_id":0,"b":0},"multi":false}]}'); rollback; -- update 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-1'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; rollback; -- update 1 is supported in the _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":6},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; rollback; -- update 1 is supported in the multiple identical _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; rollback; -- update 1 is supported in the multiple distinct _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; rollback; -- update some with range filter that excludes all rows begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":true,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- upsert 1 with range filter is supported for unsharded collections begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- upsert 1 with a replace that preserves the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":11},"u":{"b":0},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- upsert 1 with a replace that set the _id begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33},"u":{"_id":0,"b":0},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":0}'; rollback; -- upsert 1 is retryable on unsharded collection (second call is a noop) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; rollback; -- upsert 1 is supported in the _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33}'; rollback; -- test _id extraction from update begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":3}'; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":4}'; rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":0}'; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":1}},"multi":true,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":1}'; rollback; -- shard the collection select documentdb_api.shard_collection('db', 'updateme', '{"a":"hashed"}', false); -- make sure we get the expected results after sharding a collection begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":5}},"u":{"$set":{"b":0}},"multi":true}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":1}'; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":10}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- test pruning logic in update begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":true}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"u":{"$set":{"b":0}},"multi":true}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- update 1 without filters is unsupported for sharded collections select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); -- update 1 with shard key filters is supported for sharded collections begin; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":false}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; rollback; -- update 1 with shard key filters is retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"a":10}'; rollback; -- upsert 1 with shard key filters is retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; -- third call is considered a new try select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"c":66}'; rollback; -- update 1 that does not match any rows is still retryable begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":15,"_id":15}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); rollback; -- update 1 is supported in the _id case even on sharded collections begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":11,"_id":10}'); -- update first row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":10}'; -- update second row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":0}'; -- no more row where _id = 10 and b != 0 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); rollback; -- update 1 with with _id filter on a sharded collection is retryable begin; -- add an additional _id 10 select 1 from documentdb_api.insert_one('db', 'updateme', '{"a":11,"_id":10}'); -- update first row where _id = 10 select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); -- second time is a noop select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":10}' ORDER BY object_id; rollback; -- upsert on sharded collection with multi:true begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":33},"u":{"$set":{"b":33,"_id":11}},"multi":true,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"b":33}'; rollback; -- updating shard key is disallowed when using multi:true begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":true}]}'); rollback; -- updating shard key is disallowed when using multi:true, even with a shard key filter begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":true}]}'); rollback; -- updating shard key is disallowed without a shard key filter begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":false}]}'); rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":1},"u":{"$inc":{"a":1}},"multi":false}]}'); rollback; -- updating shard key is allowed when multi:false and shard key filter is specified begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":false}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"a":2}'; rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":10},"u":{"$set":{"a":20}},"multi":false}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"a":20}'; rollback; -- empty shard key value is allowed (hash becomes 0) begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$unset":{"a":1}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"b":1}'; rollback; -- update 1 is supported in the multiple identical _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; rollback; -- update 1 is unsupported in the multiple distinct _id case begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":6}'; rollback; -- test _id extraction from update begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":3 }'; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":4 }'; rollback; begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":1 }'; set local citus.log_remote_commands to on; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{"_id":33, "b":2 }'; rollback; -- update with docs specified on special section begin; select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":1 }'; select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":1 }'; select documentdb_api.update('db', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":2}},"multi":false }, {"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":2}},"multi":false}] }'); select count(*) from documentdb_api.collection('db', 'updateme') where document @@ '{ "bz":2 }'; rollback; -- update with docs specified on both begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}', '{ "":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}] }'); rollback; -- update with index hint specified by name and by key object SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "updateme", "indexes": [ { "key" : { "a": 1 }, "name": "validIndex"}] }', true); begin; select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"hint": "validIndex"}]}'); select documentdb_api.update('db', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"hint": { "a": 1 }}]}'); rollback; select documentdb_api.drop_collection('db','updateme'); SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":1,"a":3,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":2,"a":2,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('update', 'test_sort_returning', '{"_id":3,"a":1,"b":6}'); -- sort in ascending order and project & return old document SELECT collection_id AS test_sort_returning FROM documentdb_api_catalog.collections WHERE database_name = 'update' AND collection_name = 'test_sort_returning' \gset SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 3 } }, "isUpsert": false, "sort": { "b": 1 }, "returnDocument": 1, "returnFields": { "_id": 0, "b": 1 } } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); -- sort by multiple fields (i) and project & return new document BEGIN; SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 4 } }, "isUpsert": false, "sort": { "b": -1, "a": 1 }, "returnDocument": 2 } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); SELECT document FROM documentdb_api.collection('update', 'test_sort_returning') ORDER BY 1; ROLLBACK; SELECT documentdb_api_internal.update_worker( p_collection_id=>:test_sort_returning, p_shard_key_value=>:test_sort_returning, p_shard_oid => 0, p_update_internal_spec => '{ "updateOne": { "query": { "a": {"$gte": 1} }, "update": { "": { "c": 4 } }, "isUpsert": false, "sort": { "a": 1, "b": -1 }, "returnDocument": 2 } }'::bson, p_update_internal_docs=>null::bsonsequence, p_transaction_id=>null::text ) FROM documentdb_api.collection('update', 'test_sort_returning'); SELECT document FROM documentdb_api.collection('update', 'test_sort_returning') ORDER BY 1; -- show that we validate "update" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); SELECT documentdb_api.create_collection('update', 'no_match'); -- show that we validate "update" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- show that we validate "query" document even if we can't match any documents -- i) ordered=true SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false SELECT documentdb_api.update( 'update', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- Validate multi and single updates with no-op return matched and updated as expected SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":1,"a":1,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":2,"a":2,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":3,"a":3,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":4,"a":100,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":5,"a":200,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update', 'multi', '{"_id":6,"a":6,"b":1}'); select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":3}},"multi":true,"upsert":false}]}'); select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":7}},"multi":true,"upsert":false}]}'); select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":150}},"multi":true,"upsert":false}]}'); select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); -- no match select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 50 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); -- all updated select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":500}},"multi":true,"upsert":false}]}'); -- all match, no-op update select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":true,"upsert":false}]}'); -- single update SELECT 1 FROM documentdb_api.insert_one('update', 'single', '{"_id":1,"a":1,"b":1}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":false,"upsert":false}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); -- no-op update single select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); -- no match select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"b": 50 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); --upsert with same field in querySpec select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":1234, "$and" : [{"x" : {"$eq": 1}}, {"x": 2}]},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":2345, "x": 1, "x.x": 1},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":3456, "x": {}, "x.x": 1},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":4567, "x": {"x": 1}, "x.x": 1},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":5678, "x": {"x": 1}, "x.y": 1},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id":6789, "x": [1, {"x": 1}], "x.x": 1},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"x": 1, "x": 5},"u":{"$set" : {"x":10}},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_idab.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id.c": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"_id":3},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"$set" : {"_id":3} },"upsert":true}]}'); -- array filters sent to final update command. BEGIN; select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "arrayFilters": [ { "a": 2 } ]}]}'); SELECT documentdb_api.insert_one('update', 'multi', '{ "_id": 134112, "blah": [ 5, 1, 4 ] }'); SELECT documentdb_api.insert_one('update', 'multi', '{ "_id": 134113, "blah": [ 6, 3, 1 ] }'); select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":true,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); -- no match here. select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); -- updates one of the two. select documentdb_api.update('update', '{"update":"multi", "updates":[{"q":{"blah": 99 },"u":{"$max":{"blah.$[a]":109}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 99 } ]}]}'); ROLLBACK; -- test replace with upsert select documentdb_api.update('test@', '{ "update" : "shell_wc_a", "ordered" : true, "updates" : [ { "q" : { "_id" : 1.0 }, "u" : { "_id" : 1.0 }, "multi" : false, "upsert" : true } ] }'); --upsert with $expr select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"$expr" : {"$eq": ["$a",1]}}]},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gt": ["$b",1]}}, {"x": 2}]},"u":{"$set" : {"a": 10}},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$or" : [{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$expr": {"$gt" : ["$x",10]}},"u":{},"upsert":true}]}'); select documentdb_api.update('update', '{"update":"single", "updates":[{"q":{"$and" : [{"a": 10}, {"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}, {"b":11} ]},"u":{"$set": {"a" :10}},"upsert":true}]}'); -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. BEGIN; SELECT documentdb_api.insert_one('update','NonID',' { "_id" : 1, "b" : 1 }', NULL); set local citus.log_remote_commands to on; SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}, "_id" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}, "a" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$gt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$lt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": []}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2,3,4]}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$expr":{"$gt": ["$_id",1]}},"u":{"$set":{"b":0 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1},{"_id":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":2}, {"a" : 1}]},"u":{"$set":{"b":0}},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"b":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); SELECT document from documentdb_api.collection('update', 'NonID'); -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}},"u":{"$inc":{"b": 1 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}, {"b" : 1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); SELECT documentdb_api.update('update', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); SELECT document from documentdb_api.collection('update', 'NonID'); ROLLBACK; -- regex operator and update SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 1, "Login": "robert.bean@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 2, "Login": "peter.ramesh@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 3, "Login": "picop1@test.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('db', 'regexColl', '{ "_id" : 4, "Login": "peter.claxton@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.update('db', '{"update":"regexColl", "updates":[{ "q" : { "Login" : { "$regularExpression" : { "pattern" : "^picop1@test\\.co\\.uk$", "options" : "i" } } },"u":{"$addToSet": { "RefreshTokens": { "RefreshToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } }}}]}'); SELECT document from documentdb_api.collection('db', 'regexColl'); -- test update with upsert BEGIN; set documentdb.useLocalExecutionShardQueries to off; SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); SELECT documentdb_api.shard_collection('update', 'single', '{ "_id": "hashed" }', false); SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8011 }, "u": { "value": "1" }, "upsert": true }] }'); ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "value": "1123" }, "u": { "_id": 8010 }, "upsert": true }] }'); ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "value": "21020" }, "u": { "$set": { "_id": 8010 } }, "upsert": true, "multi": true }] }'); ROLLBACK; -- test update for upsert error cases BEGIN; -- this inserts the document SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. SELECT documentdb_api.update('update', '{ "update": "single", "updates": [ { "q": { "_id": 8010, "a": 5 }, "u": { "$set": { "c": 8010 } }, "upsert": true, "multi": true }] }'); ROLLBACK; -- test updateOne with sort select documentdb_api.create_collection('update', 'test_update_one_sort'); SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":1,"a":3,"b":7}'); SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":2,"a":3,"b":5}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":10}},"multi":false,"upsert":false, "sort": {"_id": 1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.insert_one('update', 'test_update_one_sort', '{"_id":3,"a":3,"b":3}'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-1}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-1}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"b":{"$lt":5}},"u":{"$set":{"text":"smaller than 5"}},"multi":false,"upsert":false, "sort": {"b": -1}}, {"q":{"b":{"$gte":5}},"u":{"$set":{"text":"large"}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); -- negative test case SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"b":{"$lt":5}},"u":{"$set":{"text":"tt"}},"multi":true,"sort": {"b": -1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); SELECT documentdb_api.insert('update', '{"insert":"test_update_one_sort_ex", "documents":[{"_id":-1,"a":1,"b":"string"}, {"_id":-2,"a":0,"b":1.2}, {"_id":-3,"a":1,"b":[1,2,3]}]}'); select documentdb_api.update('update', '{"update":"test_update_one_sort_ex", "updates":[{"q":{"a":{"$gte":0}},"u":{"$set":{"b":"exception"}},"multi":false,"sort": {"b": -1}},{"q":{"a":{"$gte":0}},"u":{"$set":{"b":[4,5]}},"multi":false,"sort": {"b": 1}}]}'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":"exception"}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":[4,5]}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); WITH generated_data AS ( SELECT row_number() OVER () AS _id, 1 AS a, CASE (random()*6)::int WHEN 0 THEN (random()*1000)::int::text WHEN 1 THEN to_char(random()*1000, 'FM999.9999') WHEN 2 THEN 'str_' || floor(random()*10000)::int WHEN 3 THEN (ARRAY['true','false'])[floor(random()*2)+1] WHEN 4 THEN to_char( now() - (floor(random()*3650)||' days')::interval, 'YYYY-MM-DD' ) WHEN 5 THEN gen_random_uuid()::text ELSE NULL::text END AS b FROM generate_series(1, 1000) ) SELECT documentdb_api.insert( 'update'::text, ('{"insert":"test_update_one_sort_ex", "documents":[' || (SELECT string_agg(row_to_json(g)::text, ',') FROM generated_data g) || ']}')::bson ); select documentdb_api.update('update', '{"update":"test_update_one_sort_ex", "updates":[{"q":{"a":{"$gte":0}},"u":{"$set":{"b":"exception"}},"multi":false,"sort": {"b": -1}},{"q":{"a":{"$gte":0}},"u":{"$set":{"b":[4,5]}},"multi":false,"sort": {"b": 1}}]}'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":"exception"}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); SELECT cursorPage FROM documentdb_api.find_cursor_first_page('update', '{ "find" : "test_update_one_sort_ex", "filter" : {"b":[4,5]}, "limit" : 10, "singleBatch" : true, "batchSize" : 10, "$db" : "update", "projection":{"_id":0} }'); -- sharded collection select documentdb_api.shard_collection('update', 'test_update_one_sort', '{"_id": "hashed"}', false); -- expect to fail as updateOne without id filter is not supported on sharded collection SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"a":3},"u":{"$set":{"b":-10}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); -- expect to succeed as updateOne with id filter is supported on sharded collection SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":1, "a":3},"u":{"$set":{"b":0}},"multi":false,"upsert":false, "sort": {"b": 1}}]}'); SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":2, "a":3},"u":{"$set":{"b":-10}},"multi":false,"upsert":false, "sort": {"_id": -1}}]}'); -- negative test case SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":3, "a":3},"u":{"$set":{"b":-1}},"multi":true,"upsert":false, "sort": {"_id": -1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); -- expect to throw error but the first one should succeed SELECT documentdb_api.update('update', '{"update":"test_update_one_sort", "updates":[{"q":{"_id":3, "a":3},"u":{"$set":{"b":-10}},"multi":true,"upsert":false},{"q":{"_id":3, "a":3},"u":{"$set":{"b":-2}},"multi":true,"upsert":false, "sort": {"_id": -1}}]}'); SELECT document FROM documentdb_api.collection('update', 'test_update_one_sort'); -- let support SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 1, "a":"kofi"}'); SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 2, "a":"ama"}'); SELECT documentdb_api.insert_one('db', 'coll_update', '{"_id": 3, "a":"$$varRef"}'); -- EnableVariablesSupportForWriteCommands GUC off: ignore variableSpec SET documentdb.EnableVariablesSupportForWriteCommands TO off; SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": "ama"} }'); -- EnableVariablesSupportForWriteCommands GUC on: user variableSpec SET documentdb.EnableVariablesSupportForWriteCommands TO on; -- variables accessed outside $expr will not evaluate to let variable value in 'q' SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": "$$varRef" }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": 2}} '); SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": "$$varRef" }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2}} '); BEGIN; -- updateMany SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": true}], "let": {"varRef": 2} }'); ROLLBACK; BEGIN; -- updateOne SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": "ama"} }'); EXPLAIN (VERBOSE ON, COSTS OFF) SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": {"$set": {"b": "zebra"}}, "multi": false}], "let": {"varRef": 2} }'); ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "kojo"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "kojo"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "kojo"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "kojo"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; -- let support: variables in 'u' BEGIN; -- variables are accessible in aggregation pipeline SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": {"$set": {"set": "$$varRef"}}, "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; -- updateMany: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": [{"$addFields": {"addFields": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gte": ["$_id", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; -- updateOne: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lt": ["$a", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$a", "$$varRef"] } }, "u": [{"$addFields": {"addField": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gt": ["$a", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; -- let support: sharded collection SELECT documentdb_api.shard_collection('db', 'coll_update', '{ "a": "hashed" }', false); BEGIN; -- updateMany SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"a": 1, "$expr": {"$eq": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "anomaa"}}, "multi": true}], "let": {"varRef": "kofi"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; -- updateOne SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"a": 2, "$expr": {"$lt": ["$a", "$$varRef"] } }, "u": {"$set": {"b": "ako"}}, "multi": false}], "let": {"varRef": "ama"} }'); ROLLBACK; BEGIN; SELECT document FROM documentdb_api.collection('db', 'coll_update'); SELECT documentdb_api.update( 'db', '{ "update": "coll_update", "updates": [ {"q": {"$expr": {"$eq": ["$a", "$$varRef2"]}}, "u": {"$set": {"b": "akua"}}, "multi": true}, {"q": {"_id": 1, "$expr": {"$eq": ["$_id", "$$varRef1"]}}, "u": {"$set": {"b": "abena"}}, "multi": false} ], "ordered": true, "let": {"varRef1": 1, "varRef2": "ama"} }' ); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; -- updateMany: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$lte": ["$_id", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef"] } }, "u": [{"$addFields": {"addFields": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$gte": ["$_id", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": true}], "let": {"varRef": 2} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateMany: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": true}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; BEGIN; -- updateOne: $set SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 3, "$expr": {"$lt": ["$a", "$$varRef"] } }, "u": [{"$set": {"set": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: addFields SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$a", "$$varRef"] } }, "u": [{"$addFields": {"addField": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $project SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 1, "$expr": {"$gt": ["$a", "$$varRef"] } }, "u": [{"$project": {"project": "$$varRef"}}], "multi": false}], "let": {"varRef": "ama"} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $replaceRoot SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceRoot": {"newRoot": "$$varRef2"}}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"newRoot": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); -- updateOne: $replaceWith SELECT documentdb_api.update('db', '{ "update": "coll_update", "updates": [ { "q": {"_id": 2, "$expr": {"$eq": ["$_id", "$$varRef1"] } }, "u": [{"$replaceWith": "$$varRef2"}], "multi": false}], "let": {"varRef1": 2, "varRef2": {"replaceWith": 1 }} }'); SELECT document FROM documentdb_api.collection('db', 'coll_update'); ROLLBACK; -- sharded collection shard on some other field and query on object_id SELECT 1 FROM documentdb_api.insert_one('db', 'upShardTest', '{"_id":1,"b":1}'); SELECT documentdb_api.shard_collection('db', 'upShardTest', '{"b": "hashed"}', false); select documentdb_api.update('db', '{"update":"upShardTest", "updates":[{"q":{"_id":1},"u":{"b":1},"multi":false}]}');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_update_bulk.sql000066400000000000000000001263511507310017400337610ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 849000; SET documentdb.next_collection_id TO 8490; SET documentdb.next_collection_index_id TO 8490; SET documentdb.EnableVariablesSupportForWriteCommands TO on; select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":1,"_id":1,"b":1}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":2,"_id":2,"b":2}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":3,"_id":3,"b":3}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":4,"_id":4,"b":4}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":5,"_id":5,"b":5}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":6,"_id":6,"b":6}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":7,"_id":7,"b":7}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":8,"_id":8,"b":8}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":9,"_id":9,"b":9}'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":10,"_id":10,"b":10}'); -- exercise invalid update syntax errors CALL documentdb_api.update_bulk('bulkdb', NULL); CALL documentdb_api.update_bulk(NULL, '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":["updateme"], "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":{"q":{},"u":{"$set":{"b":0}},"multi":true}}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}], "extra":1}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{}}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"u":{"$set":{"b":0}}}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":"text"}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":[],"u":{"$set":{"b":0}},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":1}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true,"extra":1}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}],"ordered":1}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$bork":{"b":0}},"multi":true}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"upsert":[]}]}'); -- Disallow writes to system.views CALL documentdb_api.update_bulk('bulkdb', '{"update":"system.views", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); -- update all set search_path TO ''; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":true}]}'); SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document OPERATOR(documentdb_api_catalog.@@) '{"b":0}'; -- update some CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"$set":{"b":1}},"multi":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":1}'; -- update multi with a replace is not supported CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":{"b":0},"multi":true}]}'); -- update multi with an aggregation pipeline is supported CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":3}},"u":[{"$unset":["b"]}],"multi":true}]}'); -- update all from non-existent collection CALL documentdb_api.update_bulk('bulkdb', '{"update":"notexists", "updates":[{"q":{},"u":{"$set":{"b":0}}}]}'); -- query syntax errors are added the response CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$ltr":5}},"u":{"$set":{"b":0}},"multi":true}]}'); -- when ordered, expect only first update to be executed CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":2}}},{"q":{"$a":2},"u":{"$set":{"b":2}}},{"q":{"a":3},"u":{"$set":{"b":2}}}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":2}'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":3}}},{"q":{"$a":2},"u":{"$set":{"b":3}}},{"q":{"a":3},"u":{"$set":{"b":3}}}],"ordered":true}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":3}'; -- when not ordered, expect first and last update to be executed CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$set":{"b":0}}},{"q":{"$a":2},"u":{"$set":{"b":0}}},{"q":{"a":3},"u":{"$set":{"b":0}}}],"ordered":false}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme'); -- update 1 without filters is supported for unsharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":5}},"multi":false}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":5}'; -- update 1 with a replace that preserves the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"b":6},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":6}'; -- update 1 with a replace that tries to change the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":3},"u":{"_id":0,"b":7},"multi":false}]}'); -- update 1 is retryable on unsharded collection (second call is a noop) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"b":8}},"multi":false}]}', NULL, 'xact-1'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; -- update 1 is supported in the _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":6},"u":{"$set":{"b":9}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; -- update 1 is supported in the multiple identical _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":10}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; -- update 1 is supported in the multiple distinct _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":11}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; -- update some with range filter that excludes all rows CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lt":0}},"u":{"$set":{"b":12,"_id":11}},"multi":true,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":12}'; -- upsert 1 with range filter is supported for unsharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":{"$lt":0}},"u":{"$set":{"b":0,"_id":11}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; -- upsert 1 with a replace that preserves the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":11},"u":{"b":13},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":13}'; -- upsert 1 with a replace that set the _id CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33},"u":{"_id":0,"b":14},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":0}'; -- upsert 1 is retryable on unsharded collection (second call is a noop) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; -- upsert 1 is supported in the _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33}'; -- test _id extraction from update CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":3}'; set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":4}'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":0}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":0}'; set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33},"u":{"$set":{"b":1}},"multi":true,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":1}'; -- shard the collection select documentdb_api.shard_collection('bulkdb', 'updateme', '{"a":"hashed"}', false); -- make sure we get the expected results after sharding a collection CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$lte":5}},"u":{"$set":{"b":0}},"multi":true}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":1}'; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":10}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; -- test pruning logic in update set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":true}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"a":5},{"a":{"$gt":0}}]},"u":{"$set":{"b":0}},"multi":true}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; -- update 1 without filters is unsupported for sharded collections CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{},"u":{"$set":{"b":0}},"multi":false}]}'); -- update 1 with shard key filters is supported for sharded collections set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":5}},"u":{"$set":{"b":0}},"multi":false}]}'); reset citus.log_remote_commands; select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":5}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; -- update 1 with shard key filters is retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":10}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-2'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":10}'; -- upsert 1 with shard key filters is retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; -- third call is considered a new try CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":33,"_id":11},"u":{"$inc":{"c":33}},"multi":false,"upsert":true}]}', NULL, 'xact-ups'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":33}'; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"c":66}'; -- update 1 that does not match any rows is still retryable CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":15,"_id":15}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":{"$eq":15}},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-3'); -- update 1 is supported in the _id case even on sharded collections -- add an additional _id 10 select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":11,"_id":10}'); -- update first row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":10}'; -- update second row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":0}'; -- no more row where _id = 10 and b != 0 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10,"b":{"$ne":0}},"u":{"$set":{"b":0}},"multi":false}]}'); -- update 1 with with _id filter on a sharded collection is retryable -- add an additional _id 10 select 1 from documentdb_api.insert_one('bulkdb', 'updateme', '{"a":11,"_id":10}'); -- update first row where _id = 10 CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); -- second time is a noop CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":10},"u":{"$inc":{"b":1}},"multi":false}]}', NULL, 'xact-4'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":10}' ORDER BY object_id; -- upsert on sharded collection with multi:true CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":33},"u":{"$set":{"b":33,"_id":11}},"multi":true,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":33}'; -- updating shard key is disallowed when using multi:true CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":true}]}'); -- updating shard key is disallowed when using multi:true, even with a shard key filter CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":true}]}'); -- updating shard key is disallowed without a shard key filter CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"b":1},"u":{"$inc":{"a":1}},"multi":false}]}'); CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":1},"u":{"$inc":{"a":1}},"multi":false}]}'); -- updating shard key is allowed when multi:false and shard key filter is specified CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$inc":{"a":1}},"multi":false}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":2}'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":10},"u":{"$set":{"a":20}},"multi":false}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"a":20}'; -- empty shard key value is allowed (hash becomes 0) CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"a":1},"u":{"$unset":{"a":1}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"b":1}'; -- update 1 is supported in the multiple identical _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":6}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; -- update 1 is unsupported in the multiple distinct _id case CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"$and":[{"_id":6},{"_id":5}]},"u":{"$set":{"b":0}},"multi":false}]}'); select document from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":6}'; -- test _id extraction from update CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":3}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":3 }'; set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":4}},"multi":false,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":4 }'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}]}'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":1 }'; set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}'); reset citus.log_remote_commands; select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{"_id":33, "b":2 }'; -- update with docs specified on special section CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":1 }'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":1}},"multi":false,"upsert":true}] }'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":1 }'; CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme"}', '{ "":[{"q":{"_id":36, "a": 10 },"u":{"$set":{"bz":2}},"multi":false }, {"q":{"_id":37, "a": 10 },"u":{"$set":{"bz":2}},"multi":false}] }'); select count(*) from documentdb_api.collection('bulkdb', 'updateme') where document @@ '{ "bz":2 }'; -- update with docs specified on both CALL documentdb_api.update_bulk('bulkdb', '{"update":"updateme", "updates":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":2}},"multi":true,"upsert":true}]}', '{ "":[{"q":{"_id":33, "a": 10 },"u":{"$set":{"b":1}},"multi":false,"upsert":true}] }'); select documentdb_api.drop_collection('bulkdb','updateme'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":1,"a":3,"b":7}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":2,"a":2,"b":5}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'test_sort_returning', '{"_id":3,"a":1,"b":6}'); -- show that we validate "update" document even if collection doesn't exist -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- show that we validate "query" document even if collection doesn't exist -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "dne", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); SELECT documentdb_api.create_collection('update_bulk', 'no_match'); -- show that we validate "update" document even if we can't match any documents -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"b": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"d": 1}, "u": { "$set": { "p": 1 }, "$unset": {"p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- show that we validate "query" document even if we can't match any documents -- i) ordered=true CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": true }' ); -- ii) ordered=false CALL documentdb_api.update_bulk( 'update_bulk', '{ "update": "no_match", "updates": [ {"q": {"a": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$b": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"c": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"$d": 1}, "u": { "$set": { "p": 1 } } }, {"q": {"e": 1}, "u": { "$set": { "p": 1 } } } ], "ordered": false }' ); -- Validate multi and single updates with no-op return matched and updated as expected SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":1,"a":1,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":2,"a":2,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":3,"a":3,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":4,"a":100,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":5,"a":200,"b":1}'); SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'multi', '{"_id":6,"a":6,"b":1}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":3}},"multi":true,"upsert":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":7}},"multi":true,"upsert":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":150}},"multi":true,"upsert":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); -- no match CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 50 },"u":{"$min":{"a":99}},"multi":true,"upsert":false}]}'); -- all updated CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":500}},"multi":true,"upsert":false}]}'); -- all match, no-op update CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":true,"upsert":false}]}'); -- single update SELECT 1 FROM documentdb_api.insert_one('update_bulk', 'single', '{"_id":1,"a":1,"b":1}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":100}},"multi":false,"upsert":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); -- no-op update single CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$min":{"a":50}},"multi":false,"upsert":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 1 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); -- no match CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"b": 50 },"u":{"$max":{"a":50}},"multi":false,"upsert":false}]}'); --upsert with same field in querySpec CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":1234, "$and" : [{"x" : {"$eq": 1}}, {"x": 2}]},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":2345, "x": 1, "x.x": 1},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":3456, "x": {}, "x.x": 1},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":4567, "x": {"x": 1}, "x.x": 1},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":5678, "x": {"x": 1}, "x.y": 1},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id":6789, "x": [1, {"x": 1}], "x.x": 1},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"x": 1, "x": 5},"u":{"$set" : {"x":10}},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_idab.b": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id.c": 2},"u":{"_id":3, "a":4},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"_id":3},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 1, "_id": 2},"u":{"$set" : {"_id":3} },"upsert":true}]}'); -- array filters sent to final update command. CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"_id": 134111, "b": [ 5, 2, 4 ] },"u":{"$set" : {"b.$[a]":3} },"upsert":true, "arrayFilters": [ { "a": 2 } ]}]}'); SELECT documentdb_api.insert_one('update_bulk', 'multi', '{ "_id": 134112, "blah": [ 5, 1, 4 ] }'); SELECT documentdb_api.insert_one('update_bulk', 'multi', '{ "_id": 134113, "blah": [ 6, 3, 1 ] }'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":true,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); -- no match here. CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 1 },"u":{"$max":{"blah.$[a]":99}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 1 } ]}]}'); -- updates one of the two. CALL documentdb_api.update_bulk('update_bulk', '{"update":"multi", "updates":[{"q":{"blah": 99 },"u":{"$max":{"blah.$[a]":109}},"multi":false,"upsert":false, "arrayFilters": [ { "a": 99 } ]}]}'); -- test replace with upsert CALL documentdb_api.update_bulk('bulktest@', '{ "update" : "shell_wc_a", "ordered" : true, "updates" : [ { "q" : { "_id" : 1.0 }, "u" : { "_id" : 1.0 }, "multi" : false, "upsert" : true } ] }'); --upsert with $expr CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"$expr" : {"$eq": ["$a",1]}}]},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gt": ["$b",1]}}, {"x": 2}]},"u":{"$set" : {"a": 10}},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$or" : [{"$or" : [{"$expr" : {"$gte": ["$c", 100]}}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}]},"u":{"$set": {"a" :10}},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$expr": {"$gt" : ["$x",10]}},"u":{},"upsert":true}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"single", "updates":[{"q":{"$and" : [{"a": 10}, {"$or" : [{"x": 10},{"$expr" : {"$gte": ["$c", 100]}}, {"y": 10}]}, {"b":11} ]},"u":{"$set": {"a" :10}},"upsert":true}]}'); -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. SELECT documentdb_api.insert_one('update_bulk','NonID',' { "_id" : 1, "b" : 1 }', NULL); set citus.log_remote_commands to on; CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"a":{"$eq":1}, "_id" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}, "a" : 1},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$gt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$lt":1}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": []}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$in": [2,3,4]}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,2]}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$expr":{"$gt": ["$_id",1]}},"u":{"$set":{"b":0 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1},{"_id":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":2}, {"a" : 1}]},"u":{"$set":{"b":0}},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"b":2}]},"u":{"$set":{"b":0}},"multi":false}]}'); SELECT document from documentdb_api.collection('update_bulk', 'NonID'); -- below query will be updating document although we don't have @@ in query match but for below query only object id filter is sufficient. CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$eq":1}},"u":{"$inc":{"b": 1 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$and":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}, {"b" : 1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"$or":[{"_id":1}]},"u":{"$inc":{"b":1}},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); CALL documentdb_api.update_bulk('update_bulk', '{"update":"NonID", "updates":[{"q":{"_id":{"$all": [1,1]}},"u":{"$inc":{"b":1 }},"multi":false}]}'); SELECT document from documentdb_api.collection('update_bulk', 'NonID'); -- regex operator and update RESET citus.log_remote_commands; RESET citus.log_local_commands; SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 1, "Login": "robert.bean@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 2, "Login": "peter.ramesh@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 3, "Login": "picop1@test.co.uk", "RefreshTokens": [ ] }', NULL); SELECT documentdb_api.insert_one('bulkdb', 'regexColl', '{ "_id" : 4, "Login": "peter.claxton@networkrail.co.uk", "RefreshTokens": [ ] }', NULL); CALL documentdb_api.update_bulk('bulkdb', '{"update":"regexColl", "updates":[{ "q" : { "Login" : { "$regularExpression" : { "pattern" : "^picop1@test\\.co\\.uk$", "options" : "i" } } },"u":{"$addToSet": { "RefreshTokens": { "RefreshToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYxNDNhY2ZmMzNjODQ" } }}}]}'); SELECT document from documentdb_api.collection('bulkdb', 'regexColl'); -- test update with upsert set documentdb.useLocalExecutionShardQueries to off; CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); SELECT documentdb_api.shard_collection('update_bulk', 'single', '{ "_id": "hashed" }', false); CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8011 }, "u": { "value": "1" }, "upsert": true }] }'); -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "value": "1123" }, "u": { "_id": 8010 }, "upsert": true }] }'); -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "value": "21020" }, "u": { "$set": { "_id": 8010 } }, "upsert": true, "multi": true }] }'); -- test update for upsert error cases -- this inserts the document CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id":8010 }, "u": { "value": "1" }, "upsert": true }] }'); -- this will collide and produce a unique conflict. CALL documentdb_api.update_bulk('update_bulk', '{ "update": "single", "updates": [ { "q": { "_id": 8010, "a": 5 }, "u": { "$set": { "c": 8010 } }, "upsert": true, "multi": true }] }'); reset documentdb.useLocalExecutionShardQueries; -- update bulk transaction testing SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 1, "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 2, "a": 1, "b": 1 }'); SELECT documentdb_api.insert_one('update_bulk', 'test_update_batch', '{ "_id": 3, "a": 1, "b": 1 }'); SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s ]}', string_agg('{ "q": { "_id": 1 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query FROM generate_series(1, 10) \gset -- update query with an invalid query in the middle SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s, { "q": { "$a": 1 }, "u": { "$inc": { "b": 1 } } }, %s ]}', string_agg('{ "q": { "_id": 2 }, "u": { "$inc": { "b": 1 } }}', ',' ), string_agg('{ "q": { "_id": 2 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query2 FROM generate_series(1, 5) \gset SELECT FORMAT('{ "update": "test_update_batch", "updates": [ %s, { "q": { "$a": 1 }, "u": { "$inc": { "b": 1 } } }, %s ], "ordered": false }', string_agg('{ "q": { "_id": 3 }, "u": { "$inc": { "b": 1 } }}', ',' ), string_agg('{ "q": { "_id": 3 }, "u": { "$inc": { "b": 1 } }}', ',' )) AS update_query3 FROM generate_series(1, 5) \gset SET client_min_messages TO DEBUG1; -- this one should have no commits logged here CALL documentdb_api.update_bulk('update_bulk', :'update_query'); -- this should have 5 messages (1 try for the batch + rollback, and then 5 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); -- This should have 10 messages (1 try for the batch + rollback, and retry 9 more) CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); -- should have updated 10 times SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; -- reduce batch to 8 set documentdb.batchWriteSubTransactionCount to 8; -- This should have 1 commit message (1 for batchsize of 8 ) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); -- this should have 5 messages (1 try for the batch + rollback, and then 5 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); -- This should have 9 messages (1 try for the batch + rollback, and retry 8 more) CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; -- now reduce to 3 set documentdb.batchWriteSubTransactionCount to 3; -- This should have 3 commit message (1 for each batchsize of 3) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); -- this should have 4 messages (1 for success, 1 try for the batch + rollback, and then 2 individual updates and stops). CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); -- this should have 7 messages (1 for success, 1 try for batch and rollback, and 5 more tries). CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; -- disable local writes set documentdb.useLocalExecutionShardQueries to off; -- These should all have 4 commit message (1 for each batchsize of 3, and 1 for the last one) CALL documentdb_api.update_bulk('update_bulk', :'update_query'); CALL documentdb_api.update_bulk('update_bulk', :'update_query2'); CALL documentdb_api.update_bulk('update_bulk', :'update_query3'); -- still increments SELECT document FROM documentdb_api.collection('update_bulk', 'test_update_batch') ORDER BY object_id; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/commands_validate.sql000066400000000000000000000060221507310017400332430ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 870000; SET documentdb.next_collection_id TO 8700; SET documentdb.next_collection_index_id TO 8700; SELECT documentdb_api.drop_collection('db', 'validatecoll'); -- Empty collection name SELECT documentdb_api.validate('db','{}'); SELECT documentdb_api.validate('db', '{"validate" : ""}'); -- Collection does not exist SELECT documentdb_api.validate('db', '{"validate" : "missingcoll"}'); -- Create Collection SELECT documentdb_api.create_collection('db', 'validatecoll'); -- Collection without docs and with only id index/no user defined indexes SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); -- Collection with id index and an additional index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('validatecoll', 'index_1', '{"a": 1}'), true); SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); -- Insert few docs SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 100 }'); SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 101, "b": 201 }'); SELECT documentdb_api.insert_one('db','validatecoll','{"_id":"1", "a": 102, "b": 202 }'); -- Collection with docs and user defined index SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); -- Valid input options -- -- only validate SELECT documentdb_api.validate('db', '{"validate" : "validatecoll"}'); -- validate with repair: true or repair: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : false}'); -- validate with full: true or full: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : false}'); SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true}'); -- validate with metadata: true or metadata: false remains same SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : null, "metadata" : false}'); SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : null, "repair" : null, "metadata" : true}'); -- Invalid input options -- --validate with repair: true SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "repair" : true}'); -- validate with repair and full SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "repair" : true}'); -- validate with repair and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "repair" : true, "metadata" : true}'); -- validate with full and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "metadata" : true}'); -- validate with repair, full and metadata SELECT documentdb_api.validate('db', '{"validate" : "validatecoll", "full" : true, "metadata" : true, "repair" : true}'); -- validate field is an object SELECT documentdb_api.validate('db','{"validate":{}}');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/conflicting_indexes.sql000066400000000000000000000271341507310017400336160ustar00rootroot00000000000000SET citus.next_shard_id TO 1800000; SET documentdb.next_collection_id TO 18000; SET documentdb.next_collection_index_id TO 18000; SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1.0}, "name": "idx_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1.1}, "name": "idx_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_1", "unique": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"b": 1, "a": -1}, "name": "idx_1", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"a": -1, "b": 1}, "name": "idx_2", "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "sparse": false, "wildcardProjection": {"a": 0, "b": {"c": false}}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "wildcardProjection": {"b.c": 0, "_id": 0, "a": false, "d": false}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "wildcardProjection": {"b.c": 0, "_id": 0, "d": false}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "unique": false, "wildcardProjection": {"b.c": 0, "_id": 0, "a": false}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "unique": false, "wildcardProjection": {"b.c": true, "a": 12}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_3", "partialFilterExpression": {}, "wildcardProjection": {"a": 0, "b": {"c": false}}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"a": true, "b": {"c": 1, "d": 1}, "b.e": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"b": {"e": 1, "d": 1, "c": 1}, "a": 5}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_5", "sparse": false, "wildcardProjection": {"a": true, "b": {"d": 1}, "b.e": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_6", "sparse": false, "wildcardProjection": {"b": {"e": 1, "d": 1, "c": 1}, "a": 5}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"$and": [{"a": 1}, {"b": {"c": 1, "d": 1}}]}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"c": 1, "d": 1}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_7", "partialFilterExpression": {"b": {"c": 1, "d": 1}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"c": 1, "d": {"$eq": 1}}, "a": {"$eq": 1}}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"d": 1, "c": 1}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b": {"d": 1}, "b": {"c": 1}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"b.d": 1, "b.c": 1, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_4", "partialFilterExpression": {"$and": [{"a": 1}, {"b": {"c": 1, "d": 2}}]}}]}', true); -- none of below pairs are treated as same indexes SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_8", "partialFilterExpression": {"$or": [{"b": {"$eq": 1}}, {"b": {"$gt": 1}}]}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_8", "partialFilterExpression": {"b": {"$gte": 1}}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_9", "partialFilterExpression": {"b": {"$in": [1,2,3]}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_9", "partialFilterExpression": {"b": {"$in": [2,1,3]}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_10", "partialFilterExpression": {"b": {"$not": {"$in": [1,2,3]}}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"$**": 1}, "name": "idx_10", "partialFilterExpression": {"b": {"$nin": [1,2,3]}, "a": 1}}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true, "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": false, "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true, "sparse": false}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "unique": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_11", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_1", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_11", "unique": true, "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_1"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_2", "unique": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_2", "indexes": [{"key": {"c": 1, "d": 2}, "name": "idx_3", "sparse": true}]}', true); CALL documentdb_api.drop_indexes('conflict_test', '{"dropIndexes": "collection_2", "index": {"c": 1, "d": 2}}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}, {"key": {"a": 1}, "name": "idx_2"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"b": 1}, "name": "idx_3"}, {"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}, {"key": {"a": 1}, "name": "idx_4"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_3", "indexes": [{"key": {"b": 1}, "name": "idx_4"}, {"key": {"c": 1, "d": 1}, "name": "idx_1", "sparse": true}]}', true); -- Creating identical indexes via the same command is not allowed. .. SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}, {"key": {"k": 1}, "name": "idx_1", "unique": false, "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}]}', true); -- .. However, if the index was created via a prior command; then -- Mongo skips creating the identical index, even if it's specified -- more than once. SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_1", "sparse": true}, {"key": {"k": 1}, "name": "idx_1", "unique": false, "sparse": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_2", "unique": true}, {"key": {"k": 1}, "name": "idx_3", "unique": true}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('conflict_test', '{"createIndexes": "collection_4", "indexes": [{"key": {"k": 1}, "name": "idx_2", "unique": true}, {"key": {"k": 1}, "name": "idx_2", "unique": false}]}', true); create_indexes_cosmos_vector.sql000066400000000000000000001033441507310017400354460ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core, documentdb_api_catalog, documentdb_api, documentdb_api_internal, public; SET citus.next_shard_id TO 91000000; SET documentdb.next_collection_id TO 91000; SET documentdb.next_collection_index_id TO 91000; SELECT documentdb_api.create_collection('db', 'create_indexes_vector'); -- now you get different errors SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch"}, "name": "foo_1" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": 1 }, "name": "foo_1", "cosmosSearchOptions": { } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 1 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "dimensions": 10 } } ] }', true); -- create a valid indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "b": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_indexes_vector", "indexes": [ { "key": { "c": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 300, "similarity": "L2", "dimensions": 3 } } ] }', true); RESET client_min_messages; \d documentdb_data.documents_91000 \d documentdb_api_catalog.index_spec_type_internal SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "create_indexes_vector" }') ORDER BY 1; SELECT documentdb_api.insert_one('db', 'create_indexes_vector', '{ "a": "some sentence", "elem": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'create_indexes_vector', '{ "a": "some other sentence", "elem": [8.0, 5.0, 0.1 ] }'); SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[3, 5, 2]' limit 1; SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[3, 5, 2]' DESC limit 1; SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'create_indexes_vector'); \d documentdb_data.documents_91000; begin; set local enable_seqscan to off; EXPLAIN(COSTS OFF) SELECT document -> 'a' FROM documentdb_api.collection('db', 'create_indexes_vector') ORDER BY (documentdb_api_internal.bson_extract_vector(document, 'elem'::text)::vector(3)) <=> '[10, 1, 2]'; ROLLBACK; -- Create an index -- Also create a geospatial index first so that we can test these are ignore for the sort clause and only vector index is considered SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "2dsphere" }, "name": "foo_1_2ds" } ] }', true); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence1", "myvector": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0, 1.1 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 9.0 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 8.0 ] }'); -- bad queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [ 8.0, 1.0 ], "limit": 1, "path": "myvector", "numCandidates": 10 } }]}'); -- correct queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 2, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 9, 1], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); -- Drop the geospatial index CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "vectorIndexColl", "index": "foo_1_2ds"}'); -- direct query that does not require rewrite SELECT document -> 'myvector' FROM documentdb_api.collection('db', 'vectorIndexColl') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'myvector') <=> documentdb_api_internal.bson_extract_vector('{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10 }', 'vector') LIMIT 1; -- same index with different dimensions CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "vectorIndexColl", "index": "foo_1"}'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 4 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 3 } } ] }', true); -- second index on a differet path SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector2": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "COS", "dimensions": 4 } } ] }', true); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0], "myvector2": [3.0, 5.0, 1.1, 4 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence2", "myvector": [3.0, 5.0, 1], "myvector2": [3.0, 5.0, 1.1] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence1", "myvector": [3.0, 5.0, 1.1 ], "myvector2": [3.0, 5.0, 1.1, 4 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector": [8.0, 1.0, 9.0 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector2": [8.0, 1.0, 8.0, 8 ] }'); -- query should fail SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0, 2], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); -- query should work SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9, -1], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','vectorIndexColl'); begin; set local enable_seqscan to off; EXPLAIN(COSTS OFF) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9, -1], "limit": 1, "path": "myvector2", "numCandidates": 10 } }, { "$project": { "myvector2": 1, "_id": 0 }} ]}'); ROLLBACK; -- check other two vector indexes SET search_path TO documentdb_api_catalog, documentdb_api, public; SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector3": "cosmosSearch" }, "name": "foo_3_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexColl", "indexes": [ { "key": { "myvector4": "cosmosSearch" }, "name": "foo_4_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 4 } } ] }', true); RESET client_min_messages; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "vectorIndexColl" }') ORDER BY 1; \d documentdb_data.documents_91001; SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector3": [8.0, 1.0, 9.0 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexColl', '{ "elem": "some sentence3", "myvector4": [8.0, 1.0, 8.0, 8 ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector3", "numCandidates": 10 } }, { "$project": { "myvector3": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexColl", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); -- Query on a non-existent collection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorCollNonExistent", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); -- Test vector similarity score projection [COS] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_cos", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 1, "a": "some sentence", "b": 10, "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 2, "a": "some other sentence", "b": 20, "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 3, "a": "some sentence", "b": 30, "v": [3, 2, 1 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_cos', '{ "_id": 4, "a": "some other sentence", "b": 40, "v": [-3, -2.0, -1 ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$project": { "rank": { "$meta": "searchScore" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "v": 0 }}, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_cos'); begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_cos", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ROLLBACK; -- Test vector similarity score projection [L2] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_l2", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "sim_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "L2", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_l2', '{ "_id": 4, "a": "some other sentence", "v": [-3, -2.0, -1 ] }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_l2'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_l2", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ROLLBACK; -- Test vector similarity score projection [IP] SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "similarity_score_ip", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "sim_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "IP", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); SELECT documentdb_api.insert_one('db', 'similarity_score_ip', '{ "_id": 4, "a": "some other sentence", "v": [-3, -2.0, -1 ] }'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db','similarity_score_ip'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); begin; set local enable_seqscan to off; EXPLAIN (costs off, verbose on) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ -1.0, 2, -3.0 ], "k": 1, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); EXPLAIN (COSTS OFF, VERBOSE ON) SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "similarity_score_ip", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 1, "path": "v" } } } ], "cursor": {} }'); ROLLBACK; -- ivf, Create index first and shard later SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_ivf_index_first_shard_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; ANALYZE; BEGIN; SET local client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','create_ivf_index_first_shard_later', '{"a":"hashed"}', false); END; SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'create_ivf_index_first_shard_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); -- nProbes = 1, will return 1 result, the vector [3, 2, 1] is only on one shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- nProbes = 1, will return 2 results, the vector [1, 2, 3] is on both shards BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- nProbes = 100, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_ivf_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 100 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- ivf, Shard collection first and create index later SELECT documentdb_api.shard_collection('db','shard_first_create_ivf_index_later', '{"a":"hashed"}', false); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "shard_first_create_ivf_index_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'shard_first_create_ivf_index_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); -- nProbes = 1, will return 1 result, the vector [3, 2, 1] is only on one shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- nProbes = 1, will return 2 results, the vector [1, 2, 3] is on both shards BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "nProbes": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- nProbes = 100, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_ivf_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "nProbes": 100 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- hnsw, Create index first and shard later SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "create_hnsw_index_first_shard_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); ANALYZE; BEGIN; SET local client_min_messages TO WARNING; SELECT documentdb_api.shard_collection('db','create_hnsw_index_first_shard_later', '{"a":"hashed"}', false); END; SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'create_hnsw_index_first_shard_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); -- efSearch = 1, search [3, 2, 1] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- efSearch = 1, search [1, 2, 3] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- efSearch = 10, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "create_hnsw_index_first_shard_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 10 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- hnsw, Shard collection first and create index later SELECT documentdb_api.shard_collection('db','shard_first_create_hnsw_index_later', '{"a":"hashed"}', false); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "shard_first_create_hnsw_index_later", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 1, "a": "some sentence", "v": [1, 2, 3 ] }'); SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 2, "a": "some other sentence", "v": [1, 2.0, 3 ] }'); SELECT documentdb_api.insert_one('db', 'shard_first_create_hnsw_index_later', '{ "_id": 3, "a": "some sentence", "v": [3, 2, 1 ] }'); ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v" } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); -- efSearch = 1, search [3, 2, 1] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- efSearch = 1, search [1, 2, 3] will return 2 results, one vector from each shard BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 1, 2, 3 ], "k": 4, "path": "v", "efSearch": 1 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- efSearch = 10, will return all data BEGIN; SET LOCAL enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "shard_first_create_hnsw_index_later", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3, 2, 1 ], "k": 4, "path": "v", "efSearch": 10 } } }, { "$project": { "rank": {"$round":[{"$multiply": [{"$meta": "searchScore" }, 100000]}]} } } ], "cursor": {} }'); COMMIT; -- multiple cosmosSearch indexes on a same path -- create a hnsw index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); -- same name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); -- same name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 8, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); -- different name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); -- different name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 3 } } ] }', true); -- different name different kind ivf SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); -- create a ivf index CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "multiple_indexes", "index": "foo_1"}'); SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); RESET client_min_messages; -- same name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); -- same name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "COS", "dimensions": 3 } } ] }', true); -- different name same options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); -- different name different options SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "IP", "dimensions": 3 } } ] }', true); -- different name different kind hnsw SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "multiple_indexes", "indexes": [ { "key": { "v": "cosmosSearch" }, "name": "foo_4", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "IP", "dimensions": 3 } } ] }', true); CALL documentdb_api.drop_indexes('db', '{ "dropIndexes": "multiple_indexes", "index": "foo_1"}');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/cursors_basic_support.sql000066400000000000000000000300561507310017400342320ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6700000; SET documentdb.next_collection_id TO 6700; SET documentdb.next_collection_index_id TO 6700; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_basic'); -- insert 20 documents WITH r1 AS (SELECT FORMAT('{"_id": %I, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_basic', r1.formatDoc) FROM r1; -- run the default test. -- now query them with varying page sizes using cursors. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 10 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- try more complex queries that should work. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 10 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; -- add projections to this. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }') FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; -- try on tables that do not exist SELECT document FROM documentdb_api.collection('db', 'cursors_basic_table_dne') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic_table_dne') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- try prepared queries PREPARE q1(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4; EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 1 }', '{ "a.b": { "$gt": 12 }}'); EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 12 }}'); -- try on tables that do not exist. EXECUTE q1('db', 'cursors_basic_table_dne', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); EXECUTE q1('db', 'cursors_basic_table_dne', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 12 }}'); -- queries that return no rows. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 11 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 25 }}'); -- Explain the queries. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); EXPLAIN (VERBOSE ON, ANALYZE ON, COSTS OFF, SUMMARY OFF, TIMING OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); -- explain with projection (projection happens in the custom scan.) EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }') FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; -- do a primary key scan. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$gt": "10" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$gt": "10" } }'; -- do a primary key lookup SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$eq": "10" } }'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "_id": { "$eq": "10" } }'; SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_basic'); -- validate seq scan works. EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 1 }', '{ "a.b": { "$gt": 12 }}'); EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 3 }', '{ "a.b": { "$gt": 12 }}'); EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 11 }', '{ "a.b": { "$gt": 12 }}'); -- queries that return no rows. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 6 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 11 }') AND document @@ '{ "a.b": { "$gt": 25 }}'; EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 25 }}'); -- Explain the queries. EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.d": { "$elemMatch": { "$gt": 2 } }}'; EXPLAIN (VERBOSE ON, COSTS OFF) EXECUTE q1('db', 'cursors_basic', '{ "getpage_batchCount": 7 }', '{ "a.b": { "$gt": 2 }}'); -- now create an index on a.b and a.d SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('cursors_basic', 'index_1', '{"a.b": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('cursors_basic', 'index_2', '{"a.d": 1}'), true); BEGIN; set local enable_seqscan TO OFF; -- now query them with varying page sizes using cursors - this will convert to a bitmap scan (as it's an index scan). SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; ROLLBACK; BEGIN; set local enable_seqscan TO OFF; set local enable_indexscan TO OFF; -- now query them with varying page sizes using cursors - this should work as a normal bitmap heap scan. SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; ROLLBACK; -- ensure parallel scans don't impact this. DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'cursors_basic'; EXECUTE format('ALTER TABLE documentdb_data.documents_%s SET (parallel_workers = 1)', v_collection_id); END $$; BEGIN; set local parallel_tuple_cost TO 0; set local parallel_setup_cost TO 0; set local enable_seqscan TO ON; set local enable_indexscan TO OFF; EXPLAIN (VERBOSE ON, COSTS OFF) SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_basic') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 2 }}'; ROLLBACK; -- invalid cursor scans PREPARE q2(text, text, bson, bson) AS SELECT document FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4 ORDER BY bson_orderby(document, '{ "a": 1 }'); EXECUTE q2('db', 'cursors_basic', '{}', '{}'); DEALLOCATE q2; -- creates projectSet - not allowed. SET client_min_messages TO ERROR; PREPARE q2(text, text, bson, bson) AS SELECT bson_dollar_unwind(document, '{ "$a": 1 }') FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4; EXECUTE q2('db', 'cursors_basic', '{}', '{}'); RESET client_min_messages; DEALLOCATE q2; PREPARE q2(text, text, bson, bson) AS SELECT bson_dollar_project(document, '{ "a": 1 }') FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ $4 OFFSET 1; EXECUTE q2('db', 'cursors_basic', '{}', '{}'); DEALLOCATE q2; -- now create many CTEs of Project/Filter/Project PREPARE q2(text, text, bson) AS WITH r1 AS (SELECT bson_dollar_project(document, '{ "a": 1, "d": "$a.b" }') AS document, current_cursor_state(document) AS cursorState FROM documentdb_api.collection($1, $2) WHERE documentdb_api_internal.cursor_state(document, $3) AND document @@ '{ "_id": { "$exists": true } }'), r2 AS (SELECT bson_dollar_add_fields(document, '{ "c": 4 }') AS document, cursorState FROM r1 WHERE document @@ '{ "d": 1 }'), r3 AS (SELECT bson_dollar_project(document, '{ "_id": 0 }') AS document, cursorState FROM r2 WHERE document @@ '{ "c": 4 }'), r4 AS (SELECT bson_dollar_add_fields(document, '{ "e.f": "foo" }') AS document, cursorState FROM r3), r5 AS (SELECT document, cursorState FROM r4 WHERE document @@ '{ "e.f" : "foo" }') SELECT * FROM r5; EXECUTE q2('db', 'cursors_basic', '{}'); EXECUTE q2('db', 'cursors_non_existent', '{}');documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/cursors_seqscan.sql000066400000000000000000000136231507310017400330130ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6710000; SET documentdb.next_collection_id TO 6710; SET documentdb.next_collection_index_id TO 6710; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_seqscan'); -- insert 20 documents WITH r1 AS (SELECT FORMAT('{"_id": %I, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan', r1.formatDoc) FROM r1; SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_seqscan'); -- limit it by batchSize SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 100 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- specify getpage_batchSizeAttr SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 1, "getpage_batchSizeAttr": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, length(document::bytea) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchSizeHint": 100, "getpage_batchSizeAttr": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- run the default test. -- now query them with varying page sizes using cursors. SELECT document FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- query with page sizes and get cursor state. SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 7 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- query with page sizes, projection and get cursor state. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; -- now test resume from continuation SELECT document, current_cursor_state(document) AS cursor1 INTO TEMPORARY d1 FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT r2 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r2 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], cursor1) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r2 \gset -- print the continuation \echo :r2 -- now run the query with the continuation. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; -- now try with multi-continuation with a different table SELECT r3 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r3 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], '{ "table_name": "someOtherTable" }'::bson) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r3 \gset -- print the continuation \echo :r3 -- now run the query with the continuation (Should have no continuation). SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; -- run with remote execution set citus.enable_local_execution to off; SELECT document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; cursors_seqscan_sharded.sql000066400000000000000000000152211507310017400344220ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, documentdb_api, documentdb_core, documentdb_api_internal, public; SET citus.next_shard_id TO 6720000; SET documentdb.next_collection_id TO 6720; SET documentdb.next_collection_index_id TO 6720; -- create a collection SELECT documentdb_api.create_collection('db', 'cursors_seqscan_sharded'); SELECT documentdb_api.shard_collection('db', 'cursors_seqscan_sharded', '{ "sh": "hashed" }', false); -- insert 20 documents in shard key 1 WITH r1 AS (SELECT FORMAT('{"_id": %I, "sh": 1, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan_sharded', r1.formatDoc) FROM r1; -- insert 20 documents in shard key 2 WITH r1 AS (SELECT FORMAT('{"_id": %I, "sh": 2, "a": { "b": { "$numberInt": %I }, "c": { "$numberInt" : %I }, "d": [ { "$numberInt" : %I }, { "$numberInt" : %I } ] }}', g.Id, g.Id, g.Id, g.Id, g.Id)::bson AS formatDoc FROM generate_series(1, 20) AS g (id) ORDER BY g.Id desc) SELECT documentdb_api.insert_one('db', 'cursors_seqscan_sharded', r1.formatDoc) FROM r1; \d documentdb_data.documents_6720 SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'cursors_seqscan_sharded'); -- run the default test. -- now query them with varying page sizes using cursors. SELECT * FROM execute_and_sort($$SELECT object_id, document::text FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 1 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); SELECT * FROM execute_and_sort($$SELECT object_id, document::text FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); -- query with page sizes and get cursor state. SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' || current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' || current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 7 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); -- query with page sizes, projection and get cursor state. SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', dollarProject:' || bson_dollar_project(document, '{ "a.b": 1 }')::text as document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 5 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', dollarProject:' || bson_dollar_project(document, '{ "a.b": 1 }')::text as document, current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); -- now test resume from continuation SELECT document, current_cursor_state(document) AS cursor1 INTO TEMPORARY d1 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT r2 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r2 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], cursor1) AS "continuation" FROM d1 ORDER BY document -> 'sh', document-> '_id' OFFSET 2 LIMIT 1 ) rec) r2 \gset -- print the continuation \echo :r2 -- now run the query with the continuation. SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d2 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d2 order by document -> '_id'; EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; -- now try with multi-continuation with a different table SELECT r3 FROM (SELECT $$'$$ || row_get_bson(rec) || $$'$$ AS r3 FROM (SELECT 3 AS "getpage_batchCount", array_append('{}'::bson[], '{ "table_name": "someOtherTable" }'::bson) AS "continuation" FROM d1 OFFSET 2 LIMIT 1) rec) r3 \gset -- print the continuation \echo :r3 -- now run the query with the continuation (Should have no continuation). SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d3 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d3 order by document -> '_id'; EXPLAIN (VERBOSE ON, COSTS OFF ) SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r3) AND document @@ '{ "a.b": { "$gt": 12 }}'; -- run with remote execution set citus.enable_local_execution to off; SELECT * FROM execute_and_sort($$SELECT object_id, document::text || ', cursurState:' ||current_cursor_state(document)::text as document FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, '{ "getpage_batchCount": 3 }') AND document @@ '{ "a.b": { "$gt": 12 }}'$$); SELECT document, bson_dollar_project(document, '{ "a.b": 1 }'), current_cursor_state(document) INTO TEMPORARY d4 FROM documentdb_api.collection('db', 'cursors_seqscan_sharded') WHERE documentdb_api_internal.cursor_state(document, :r2) AND document @@ '{ "a.b": { "$gt": 12 }}'; SELECT document, bson_dollar_project, bson_dollar_project(current_cursor_state, '{ "table_name": 0 }') FROM d4 order by document -> '_id'; documentdb_distributed_setup.sql000066400000000000000000000075541507310017400354730ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlCREATE SCHEMA IF NOT EXISTS documentdb_distributed_test_helpers; SELECT datname, datcollate, datctype, pg_encoding_to_char(encoding), datlocprovider FROM pg_database; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.latest_documentdb_distributed_version() RETURNS text LANGUAGE plpgsql AS $fn$ DECLARE v_latest_version text; BEGIN WITH cte AS (SELECT version from pg_available_extension_versions WHERE name='documentdb_distributed'), cte2 AS (SELECT r[1]::integer as r1, r[2]::integer as r2, r[3]::integer as r3, COALESCE(r[4]::integer,0) as r4, version FROM cte, regexp_matches(version,'([0-9]+)\.([0-9]+)-([0-9]+)\.?([0-9]+)?','') r ORDER BY r1 DESC, r2 DESC, r3 DESC, r4 DESC LIMIT 1) SELECT version INTO v_latest_version FROM cte2; RETURN v_latest_version; END; $fn$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.create_latest_extension(p_cascade bool default false) RETURNS void LANGUAGE plpgsql AS $fn$ DECLARE v_latest_version text; BEGIN SELECT documentdb_distributed_test_helpers.latest_documentdb_distributed_version() INTO v_latest_version; IF p_cascade THEN EXECUTE format($$CREATE EXTENSION documentdb_distributed WITH VERSION '%1$s' CASCADE$$, v_latest_version); ELSE EXECUTE format($$CREATE EXTENSION documentdb_distributed WITH VERSION '%1$s'$$, v_latest_version); END IF; CREATE TABLE IF NOT EXISTS documentdb_data.changes ( /* Catalog ID of the collection to which this change belongs to */ collection_id bigint not null, /* derived shard key field of the document that changed */ shard_key_value bigint not null, /* object ID of the document that was changed */ object_id documentdb_core.bson not null, PRIMARY KEY(shard_key_value, object_id) ); END; $fn$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.upgrade_extension(target_version text) RETURNS void AS $$ DECLARE ran_upgrade_script bool; BEGIN IF target_version IS NULL THEN SELECT documentdb_distributed_test_helpers.latest_documentdb_distributed_version() INTO target_version; END IF; SET citus.enable_ddl_propagation = off; EXECUTE format($cmd$ ALTER EXTENSION documentdb_distributed UPDATE to %L $cmd$, target_version); EXECUTE format($cmd$ ALTER EXTENSION documentdb UPDATE to %L $cmd$, target_version); EXECUTE format($cmd$ ALTER EXTENSION documentdb_core UPDATE to %L $cmd$, target_version); IF target_version = '1.0-4.1' THEN SET client_min_messages TO WARNING; PERFORM documentdb_api_distributed.complete_upgrade(); SET client_min_messages TO DEFAULT; END IF; IF target_version IS NULL OR target_version > '1.0-4.1' THEN SET client_min_messages TO WARNING; SELECT documentdb_api_distributed.complete_upgrade() INTO ran_upgrade_script; SET client_min_messages TO DEFAULT; RAISE NOTICE 'Ran Upgrade Script: %', ran_upgrade_script; END IF; END; $$ language plpgsql; -- The schema version should NOT match the binary version SELECT extversion FROM pg_extension WHERE extname = 'documentdb_distributed' \gset -- Check if recreating the extension works DROP EXTENSION IF EXISTS documentdb_distributed CASCADE; DROP EXTENSION IF EXISTS documentdb CASCADE; DROP EXTENSION IF EXISTS documentdb_core CASCADE; -- Install the latest available documentdb_distributed version SELECT documentdb_distributed_test_helpers.create_latest_extension(p_cascade => TRUE); -- The schema version now should match the binary version SELECT extversion FROM pg_extension WHERE extname = 'documentdb_distributed' \gset SELECT documentdb_api_distributed.initialize_cluster(); -- Call initialize again (just to ensure idempotence) SELECT documentdb_api_distributed.initialize_cluster(); GRANT documentdb_admin_role TO current_user; -- install documentdb_extended_rum CREATE EXTENSION documentdb_extended_rum; GRANT USAGE ON SCHEMA documentdb_extended_rum_catalog TO documentdb_admin_role; documentdb_distributed_test_helpers.sql000066400000000000000000000324211507310017400370230ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlCREATE SCHEMA IF NOT EXISTS documentdb_distributed_test_helpers; SELECT citus_set_coordinator_host('localhost', current_setting('port')::integer); SELECT citus_set_node_property('localhost', current_setting('port')::integer, 'shouldhaveshards', true); /* see the comment written for its definition at create_indexes.c */ CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.generate_create_index_arg( p_collection_name text, p_index_name text, p_index_key documentdb_core.bson) RETURNS documentdb_core.bson LANGUAGE C STRICT AS 'pg_documentdb', $$generate_create_index_arg$$; -- Returns the command (without "CONCURRENTLY" option) used to create given -- documentdb index on given collection. CREATE FUNCTION documentdb_distributed_test_helpers.documentdb_index_get_pg_def( p_database_name text, p_collection_name text, p_index_name text) RETURNS SETOF TEXT AS $$ BEGIN RETURN QUERY SELECT pi.indexdef FROM documentdb_api_catalog.collection_indexes mi, documentdb_api_catalog.collections mc, pg_indexes pi WHERE mc.database_name = p_database_name AND mc.collection_name = p_collection_name AND (mi.index_spec).index_name = p_index_name AND mi.collection_id = mc.collection_id AND pi.indexname = concat('documents_rum_index_', index_id::text) AND pi.schemaname = 'documentdb_data'; END; $$ LANGUAGE plpgsql; -- query documentdb_api_catalog.collection_indexes for given collection CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.get_collection_indexes( p_database_name text, p_collection_name text, OUT collection_id bigint, OUT index_id integer, OUT index_spec_as_bson documentdb_core.bson, OUT index_is_valid bool) RETURNS SETOF RECORD AS $$ BEGIN RETURN QUERY SELECT mi.collection_id, mi.index_id, documentdb_api_internal.index_spec_as_bson(mi.index_spec), mi.index_is_valid FROM documentdb_api_catalog.collection_indexes AS mi WHERE mi.collection_id = (SELECT mc.collection_id FROM documentdb_api_catalog.collections AS mc WHERE collection_name = p_collection_name AND database_name = p_database_name); END; $$ LANGUAGE plpgsql; -- query pg_index for the documents table backing given collection CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.get_data_table_indexes ( p_database_name text, p_collection_name text) RETURNS TABLE (LIKE pg_index) AS $$ DECLARE v_collection_id bigint; v_data_table_name text; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE collection_name = p_collection_name AND database_name = p_database_name; v_data_table_name := format('documentdb_data.documents_%s', v_collection_id); RETURN QUERY SELECT * FROM pg_index WHERE indrelid = v_data_table_name::regclass; END; $$ LANGUAGE plpgsql; -- count collection indexes grouping by "pg_index.indisprimary" attr CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.count_collection_indexes( p_database_name text, p_collection_name text) RETURNS TABLE ( index_type_is_primary boolean, index_type_count bigint ) AS $$ BEGIN RETURN QUERY SELECT indisprimary, COUNT(*) FROM pg_index WHERE indrelid = (SELECT ('documentdb_data.documents_' || collection_id::text)::regclass FROM documentdb_api_catalog.collections WHERE database_name = p_database_name AND collection_name = p_collection_name) GROUP BY indisprimary; END; $$ LANGUAGE plpgsql; -- function to mask variable plan id from the explain output of a distributed subplan CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.mask_plan_id_from_distributed_subplan(explain_command text, out query_plan text) RETURNS SETOF TEXT AS $$ BEGIN FOR query_plan IN EXECUTE explain_command LOOP IF query_plan ILIKE '%Distributed Subplan %_%' THEN RETURN QUERY SELECT REGEXP_REPLACE(query_plan,'[[:digit:]]+','X', 'g'); ELSE RETURN next; END IF; END LOOP; RETURN; END; $$ language plpgsql; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.drop_primary_key(p_database_name text, p_collection_name text) RETURNS void AS $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = p_database_name AND collection_name = p_collection_name; DELETE FROM documentdb_api_catalog.collection_indexes WHERE (index_spec).index_key operator(documentdb_core.=) '{"_id": 1}' AND collection_id = v_collection_id; EXECUTE format('ALTER TABLE documentdb_data.documents_%s DROP CONSTRAINT collection_pk_%s', v_collection_id, v_collection_id); END; $$ LANGUAGE plpgsql; -- Function to avoid flakiness of a SQL query typically on a sharded multi-node collection. -- One way to fix such falkiness is to add an order by clause to inject determinism, but -- many queryies like cursors don't support order by. This test function bridges that gap -- by storing the result of such queries in a TEMP table and then ordering the entries in the -- temp table. One caveat is that the sql query in the argument is expacted to have exact two -- columns object_id, and document. This seems to be sufficient for now for our use cases. -- If the caller wants to project multiple columns, thaey can be concatenated as aliased as 'document' CREATE OR REPLACE FUNCTION execute_and_sort(p_sql TEXT) RETURNS TABLE (document text) AS $$ BEGIN EXECUTE 'CREATE TEMP TABLE temp_dynamic_results ON COMMIT DROP AS ' || p_sql; RETURN QUERY EXECUTE 'SELECT document FROM temp_dynamic_results ORDER BY object_id'; EXECUTE 'DROP TABLE temp_dynamic_results'; END; $$ LANGUAGE plpgsql; -- This method mimics how the 2d index extract the geometries from `p_document` from `p_keyPath` -- This function expects the geospatial data in form of legacy coordinate pairs (longitude, latitude). -- returns the 2d flat geometry in form of public.geometry. -- -- This function does strict validation of the values at path for geometry formats and -- checks for valid points and multipoints input format and throws -- error if not valid and only is applicable for creating the geospatial index and control -- insert behaviors for invalid geodetic data points. -- -- example scenario with the reference implementation: -- - db.coll.createIndex({loc: "2dsphere"}); -- -- - db.insert({loc: [10, 'text']}); => This throws error -- -- - db.insert({non-loc: [10, 'text']}) => This is normal insert as no 2d index CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.bson_extract_geometry( p_document documentdb_core.bson, p_keyPath text) RETURNS public.geometry LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'pg_documentdb', $function$bson_extract_geometry$function$; -- This method mimics how the runtime extract the geometries from `p_document` from `p_keyPath` -- This is similar to bson_extract_geometry function but -- it performs a `weak` validation and doesn't throw error in case where the `bson_extract_geometry` function may throw error -- e.g. scenarios with the reference implementation: -- - db.coll.insert({loc: [[10, 20], [30, 40], ["invalid"]]}); (without 2d index on 'loc') -- - db.coll.find({loc: {$geoWithin: { $box: [[30, 30], [40, 40]] }}}) -- -- The above find should match the object if any of the point (in multikey point case) matches the -- geospatial query. CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.bson_extract_geometry_runtime( p_document documentdb_core.bson, p_keyPath text) RETURNS public.geometry LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'pg_documentdb', $function$bson_extract_geometry_runtime$function$; -- This is a helper for create_indexes_background. It performs the submission of index requests in background and wait for their completion. CREATE OR REPLACE PROCEDURE documentdb_distributed_test_helpers.create_indexes_background(IN p_database_name text, IN p_index_spec documentdb_core.bson, IN p_log_index_queue boolean DEFAULT false, INOUT retVal documentdb_core.bson DEFAULT null, INOUT ok boolean DEFAULT false) AS $procedure$ DECLARE create_index_response record; check_build_index_status record; completed boolean := false; indexRequest text; index_cmd_stored text; BEGIN SET search_path TO documentdb_core,documentdb_api; SELECT * INTO create_index_response FROM documentdb_api.create_indexes_background(p_database_name, p_index_spec); IF p_log_index_queue THEN SELECT string_agg(index_cmd, ',') into index_cmd_stored FROM documentdb_api_catalog.documentdb_index_queue; RAISE INFO 'Index Queue Commands: %', index_cmd_stored; END IF; COMMIT; IF create_index_response.ok THEN SELECT create_index_response.requests->>'indexRequest' INTO indexRequest; IF indexRequest IS NOT NULL THEN LOOP SELECT * INTO check_build_index_status FROM documentdb_api_internal.check_build_index_status(create_index_response.requests); IF check_build_index_status.ok THEN completed := check_build_index_status.complete; IF completed THEN ok := create_index_response.ok; retVal := create_index_response.retval; RETURN; END IF; ELSE ok := check_build_index_status.ok; retVal := check_build_index_status.retval; RETURN; END IF; COMMIT; -- COMMIT so that CREATE INDEX CONCURRENTLY does not wait for documentdb_distributed_test_helpers.create_indexes_background PERFORM pg_sleep_for('100 ms'); END LOOP; ELSE ok := create_index_response.ok; retVal := create_index_response.retval; RETURN; END IF; ELSE ok := create_index_response.ok; retVal := create_index_response.retval; END IF; END; $procedure$ LANGUAGE plpgsql; -- This is a helper function to evaluate expressions for testing purposes. -- This is used by backend tests to validate functionality of comparisons. CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.evaluate_query_expression(expression documentdb_core.bson, value documentdb_core.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS '$libdir/pg_documentdb.so', $function$command_evaluate_query_expression$function$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.evaluate_expression_get_first_match(expression documentdb_core.bson, value documentdb_core.bson) RETURNS documentdb_core.bson LANGUAGE c IMMUTABLE STRICT AS '$libdir/pg_documentdb.so', $function$command_evaluate_expression_get_first_match$function$; -- Wait for the background worker to be launched in the `regression` database -- When the extension is loaded, this isn't created yet. CREATE OR REPLACE PROCEDURE documentdb_distributed_test_helpers.wait_for_background_worker() AS $$ DECLARE v_bg_worker_app_name text := NULL; BEGIN LOOP SELECT application_name INTO v_bg_worker_app_name FROM pg_stat_activity WHERE application_name = 'documentdb_bg_worker_leader'; IF v_bg_worker_app_name IS NOT NULL THEN RETURN; END IF; COMMIT; -- This is needed so that we grab a fresh snapshot of pg_stat_activity PERFORM pg_sleep_for('100 ms'); END LOOP; END $$ LANGUAGE plpgsql; CALL documentdb_distributed_test_helpers.wait_for_background_worker(); -- validate background worker is launched SELECT application_name FROM pg_stat_activity WHERE application_name = 'documentdb_bg_worker_leader'; -- create a single table in the 'db' database so that existing tests don't change behavior (yet) set documentdb.enableNativeColocation to off; SELECT documentdb_api.create_collection('db', 'firstCollection'); set documentdb.enableNativeColocation to on; SELECT documentdb_api.create_collection('db', 'secondCollection'); CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.gin_bson_get_single_path_generated_terms( document documentdb_core.bson, path text, isWildcard bool, generateNotFoundTerm bool default false, addMetadata bool default false, indexTermSizeLimit int default -1, enableReducedWildcardTerms bool default false) RETURNS SETOF documentdb_core.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'pg_documentdb', $$gin_bson_get_single_path_generated_terms$$; CREATE OR REPLACE FUNCTION documentdb_distributed_test_helpers.gin_bson_get_wildcard_project_generated_terms( document documentdb_core.bson, pathSpec text, isExclusion bool, includeId bool, addMetadata bool default false, indexTermSizeLimit int default -1) RETURNS SETOF documentdb_core.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'pg_documentdb', $$gin_bson_get_wildcard_project_generated_terms$$; CREATE FUNCTION documentdb_distributed_test_helpers.get_feature_counter_pretty(p_reset_counter bool) RETURNS SETOF json AS $$ BEGIN RETURN QUERY SELECT row_to_json(result) FROM ( SELECT coalesce(json_agg(json_build_object(feature_name, usage_count)), '[]'::json) AS "Feature_usage" FROM documentdb_api_internal.command_feature_counter_stats(p_reset_counter) ) result; END; $$ LANGUAGE plpgsql;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/feature_counters.sql000066400000000000000000000545241507310017400331600ustar00rootroot00000000000000SET search_path TO documentdb_api_catalog, documentdb_core, documentdb_api, public; SET citus.next_shard_id TO 6750000; SET documentdb.next_collection_id TO 67500; SET documentdb.next_collection_index_id TO 67500; -- Reset the counters by making a call to the counter and discarding the results select count(*)*0 as count from documentdb_api_internal.command_feature_counter_stats(true); -- vector index creation error SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": "cosmosSearch"}, "name": "foo_1" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": 1 }, "name": "foo_1", "cosmosSearchOptions": { } } ] }', true); -- create collection SELECT documentdb_api.create_collection_view('db', '{ "create": "feature_counter_col" }'); -- create view SELECT documentdb_api.create_collection_view('db', '{ "create": "feature_counter_col_view", "viewOn": "feature_counter_col" }'); -- now collMod it SELECT documentdb_api.coll_mod('db', 'feature_counter_col_view', '{ "collMod": "feature_counter_col_view", "viewOn": "feature_counter_col", "pipeline": [ { "$limit": 10 } ] }'); -- create a valid indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "a": "cosmosSearch" }, "name": "foo_1", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 100, "similarity": "COS", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "b": "cosmosSearch" }, "name": "foo_2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 200, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "c": "cosmosSearch" }, "name": "foo_3", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 300, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "f": "text" }, "name": "a_text" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "uniq": 1 }, "name": "uniq_1", "unique": true } ] }', true); RESET client_min_messages; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); SELECT document -> 'a' FROM documentdb_api.collection('db', 'feature_counter_col') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; SELECT document -> 'a' FROM documentdb_api.collection('db', 'feature_counter_col') ORDER BY documentdb_api_internal.bson_extract_vector(document, 'elem') <=> '[10, 1, 2]'; -- bad queries SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0], "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col", "pipeline": [{ "$vectorSearch": { "limit": 1, "path": "myvector", "numCandidates": 10 } }, { "$project": { "myvector": 1, "_id": 0 }} ]}'); -- Use unwind, lookup SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$lookup": { "from": "agg_pipeline_inventory", "as": "matched_docs", "localField": "item", "foreignField": "sku" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$lookup": { "from": "agg_pipeline_inventory", "as": "matched_docs", "pipeline": [ { "$count": "efe" } ] } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } } ], "cursor": {} }'); -- add $unset SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$unset": "_id" }, { "$set": { "newField2": "someOtherField" } }], "cursor": {} }'); -- add skip + limit SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$project": { "_id" : 1, "a.b": 1 } }, { "$limit": 1 }, { "$skip": 1 }], "cursor": {} }'); -- match + project + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$project": { "a.b": 1, "c": "$_id", "_id": 0 } }, { "$match": { "c": { "$gt": "2" } } }], "cursor": {} }'); -- replaceRoot SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceRoot": { "newRoot": "$e" } } ], "cursor": {} }'); -- replaceWith SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$replaceWith": "$e" } ], "cursor": {} }'); -- sort + match SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$sort": { "_id": 1 } }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); -- match + sort SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$match": { "_id": { "$gt": "1" } } }, { "$sort": { "_id": 1 } } ], "cursor": {} }'); -- sortByCount SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$sortByCount": { "$eq": [ { "$mod": [ { "$toInt": "$_id" }, 2 ] }, 0 ] } }, { "$sort": { "_id": 1 } }], "cursor": {} }'); -- $group SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$max": "$_id" }, "e": { "$count": 1 } } }], "cursor": {} }'); -- $group with first/last SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$first": "$_id" }, "e": { "$last": "$_id" } } }], "cursor": {} }'); -- $group with firstN/lastN SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$firstN": { "input":"$_id", "n":5 } }, "e": { "$lastN": { "input":"$_id", "n":5 } } } }], "cursor": {} }'); -- $group with firstN/lastN w N>10 SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col2", "pipeline": [ { "$group": { "_id": { "$mod": [ { "$toInt": "$_id" }, 2 ] }, "d": { "$firstN": { "input":"$_id", "n":15 } }, "e": { "$lastN": { "input":"$_id", "n":15 } } } }], "cursor": {} }'); -- collation SET documentdb_core.enablecollation TO on; SELECT document FROM bson_aggregation_find('db', '{ "find": "feature_counter_col2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "a": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }'); SELECT document FROM bson_aggregation_find('db', '{ "find": "feature_counter_col2", "filter": { "$or" : [{ "a": { "$eq": "cat" } }, { "b": { "$eq": "DOG" } }] }, "sort": { "_id": 1 }, "skip": 0, "limit": 10, "collation": { "locale": "fr_CA", "strength" : 3 } }'); RESET documentdb_core.enablecollation; -- Create TTL index SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "feature_counter_col2", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); -- Run validate command SELECT documentdb_api.validate('db', '{ "validate" : "validatecoll", "repair" : true }' ); -- Print without resetting the counters SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(false); -- print and reset the counters SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- check other two vector indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "myvector3": "cosmosSearch" }, "name": "foo_3_ip", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "IP", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "myvector4": "cosmosSearch" }, "name": "foo_4_l2", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 4 } } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "elem": "some sentence3", "myvector3": [8.0, 1.0, 9.0 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "elem": "some sentence3", "myvector4": [8.0, 1.0, 8.0, 8 ] }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 9.0], "limit": 1, "path": "myvector3", "numCandidates": 10 } }, { "$project": { "myvector3": 1, "_id": 0 }} ]}'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); -- Query on a non-existent collection SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorCollNonExistent", "pipeline": [{ "$vectorSearch": { "queryVector": [8.0, 1.0, 8.0, 7], "limit": 1, "path": "myvector4", "numCandidates": 10 } }, { "$project": { "myvector4": 1, "_id": 0 }} ]}'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- check vector indexes SET client_min_messages TO WARNING; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_ivf": "cosmosSearch" }, "name": "ivf_index", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_hnsw": "cosmosSearch" }, "name": "hnsw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 4 } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_ivf_half": "cosmosSearch" }, "name": "ivf_index_half", "cosmosSearchOptions": { "kind": "vector-ivf", "numLists": 2, "similarity": "L2", "dimensions": 3, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "vector_hnsw_half": "cosmosSearch" }, "name": "hnsw_index_half", "cosmosSearchOptions": { "kind": "vector-hnsw", "m": 4, "efConstruction": 16, "similarity": "COS", "dimensions": 4, "compression": "half" } } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "vectorIndexCollFC", "indexes": [ { "key": { "elem": 1 }, "name": "elem_index" } ] }', true); RESET client_min_messages; SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "_id": 1, "elem": "some sentence ivf", "vector_ivf": [8.0, 1.0, 9.0 ] }'); SELECT documentdb_api.insert_one('db', 'vectorIndexCollFC', '{ "_id": 2, "elem": "some sentence hnsw", "vector_hnsw": [8.0, 1.0, 8.0, 8 ] }'); ANALYZE; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf", "nProbes": 10} } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw", "efSearch": 5 } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf_half" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw_half" } } } ], "cursor": {} }'); BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SET local enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 2, "path": "vector_ivf", "nProbes": 10, "filter": { "elem": { "$gt": "some p" } } }}} ], "cursor": {} }'); ROLLBACK; BEGIN; SET LOCAL documentdb.enableVectorPreFilter = on; SET local enable_seqscan = off; SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "vectorIndexCollFC", "pipeline": [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0, 1.0 ], "k": 2, "path": "vector_hnsw", "efSearch": 5, "filter": { "elem": { "$gt": "some p" } } }}} ], "cursor": {} }'); ROLLBACK; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- aggregation operators counters SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 1}'); SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 2}'); SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"a": 1}'); -- should only count once per query, not once per document SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$add": ["$a", 1]}}}], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(false); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$add": ["$a", 1]}}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$multiply": ["$a", 1]}}}], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- nested should be counted SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$filter": {"input": [1, 2, 3, 4], "cond": {"$eq": ["$$this", 3]}}}}}], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"_id": 0, "result": { "$filter": {"input": [1, 2, 3, 4], "cond": {"$gt": ["$$this", 3]}}}}}], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- should not count for non-existent operators SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_counter_col3", "pipeline": [ {"$project": {"result": { "$nonExistent": {"input": [1, 2, 3, 4], "cond": {"$eq": ["$$this", 3]}}}}}], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- Test feature counters for geospatial SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "2dkey": "2d"}, "name": "my_2d_idx" } ] }', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col", "indexes": [ { "key": { "2dspherekey": "2dsphere"}, "name": "my_2dsphere_idx" } ] }', true); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"2dkey": [1, 1]}'); SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{"2dspherekey": [1, 1]}'); SELECT document -> '2dkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dkey": {"$geoWithin": {"$box": [[0, 0], [1, 1]]}}}'; SELECT document -> '2dkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dkey": {"$within": {"$box": [[0, 0], [1, 1]]}}}'; SELECT document -> '2dspherekey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dspherekey": {"$geoWithin": {"$geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0,0]]] } }}}'; SELECT document -> '2dspherekey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{"2dspherekey": {"$geoIntersects": {"$geometry": { "type": "Point", "coordinates": [1, 1] } }}}'; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- Test feature counter for $text SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "feature_counter_col3", "indexes": [ { "key": { "textkey": "text" }, "name": "my_txt_idx" } ] }', true); SELECT documentdb_api.insert_one('db', 'feature_counter_col3', '{ "textkey": "this is a cat" }'); SELECT document -> 'textkey' FROM documentdb_api.collection('db', 'feature_counter_col3') WHERE document @@ '{ "$text": { "$search": "cat" } }'; SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- TTL index usage tests SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 0, "ttl" : { "$date": { "$numberLong": "-1000" } } }', NULL); SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 1, "ttl" : { "$date": { "$numberLong": "0" } } }', NULL); SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 2, "ttl" : { "$date": { "$numberLong": "100" } } }', NULL); -- Documents with date older than when the test was written SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 3, "ttl" : { "$date": { "$numberLong": "1657900030774" } } }', NULL); -- Documents with date way in future SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 4, "ttl" : { "$date": { "$numberLong": "2657899731608" } } }', NULL); -- Documents with date array SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 5, "ttl" : [{ "$date": { "$numberLong": "100" }}] }', NULL); -- Documents with date array, should be deleted based on min timestamp SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 6, "ttl" : [{ "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 7, "ttl" : [true, { "$date": { "$numberLong": "100" }}, { "$date": { "$numberLong": "2657899731608" }}] }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 8, "ttl" : true }', NULL); -- Documents with non-date ttl field SELECT documentdb_api.insert_one('db','feature_usage_ttlcoll', '{ "_id" : 9, "ttl" : "would not expire" }', NULL); -- 1. Create TTL Index -- SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "feature_usage_ttlcoll", "indexes": [{"key": {"ttl": 1}, "name": "ttl_index", "v" : 1, "expireAfterSeconds": 5}]}', true); -- 2. List All indexes -- SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('db','{ "listIndexes": "feature_usage_ttlcoll" }') ORDER BY 1; SELECT * FROM documentdb_distributed_test_helpers.get_collection_indexes('db', 'feature_usage_ttlcoll') ORDER BY collection_id, index_id; -- 4. Call ttl purge procedure with a batch size of 2 CALL documentdb_api_internal.delete_expired_rows(3); CALL documentdb_api_internal.delete_expired_rows(3); CALL documentdb_api_internal.delete_expired_rows(3); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); -- Feature counter for _internalInhibitOptimization SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$addFields": { "e": { "f": "$a.b" } } }, { "$_internalInhibitOptimization": 1 }, { "$replaceWith": "$e" } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$sort": { "_id": 1 } }, { "$_internalInhibitOptimization": 1 }, { "$match": { "_id": { "$gt": "1" } } } ], "cursor": {} }'); SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "feature_usage_inhibit", "pipeline": [ { "$addFields": { "newField" : "1", "a.y": ["p", "q"] } }, { "$_internalInhibitOptimization": 1 }, { "$addFields": { "newField2": "someOtherField" } } ], "cursor": {} }'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true); SELECT documentdb_api.insert('db', '{"insert":"writeFC", "documents":[ { "_id" : 1, "movie": "Iron Man 3", "Budget": 180000000, "year": 2011 } ]}'); SELECT documentdb_api.insert('db', '{"insert":"writeFC", "documents":[ { "_id" : 2, "movie": "Wolverine", "Budget": 180000000, "year": 2012 }, { "_id" : 3, "movie": "Spider Man", "Budget": 180000000, "year": 2013 } ]}'); SELECT documentdb_api.update('db', '{"update": "writeFC", "updates":[{"q": {"_id": 1},"u":{"$set":{"year": "1998" }},"multi":true}]}'); SELECT documentdb_api.update('db', '{"update": "writeFC", "updates":[{"q": {"_id": 1},"u":{"$set":{"year": "2001" }},"multi":true}, {"q": {"_id": 2},"u":{"$set":{"year": "2002" }},"multi":true}]}'); SELECT documentdb_distributed_test_helpers.get_feature_counter_pretty(true);geospatial_extract_2d_geometries.sql000066400000000000000000000567501507310017400362210ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_api_catalog, documentdb_distributed_test_helpers; SET citus.next_shard_id TO 6990000; SET documentdb.next_collection_id TO 699000; SET documentdb.next_collection_index_id TO 699000; -- Case 1: All the below cases are just ignored to have a geodetic type and returns NULL geometry -- This a check based on the type of the field at the given path, if it is not array or object or empty array and objects then it will return NULL SELECT bson_extract_geometry(NULL, 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : "Hello" }', NULL) IS NULL; SELECT bson_extract_geometry('{ "a" : true }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : false }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : null }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "$undefined": true } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : {} }', 'a') IS NULL; -- empty single point SELECT bson_extract_geometry('{ "a" : [] }', 'a') IS NULL; -- empty single point SELECT bson_extract_geometry('{ "a" : [{}, []] }', 'a') IS NULL; -- empty multi points SELECT bson_extract_geometry('{ "a" : [[], {}] }', 'a') IS NULL; -- empty multi points SELECT bson_extract_geometry('{ "a" : { "field1": {} } }', 'a') IS NULL; -- surprise!! this doesn't throw error and only return NULL SELECT bson_extract_geometry('{ "a" : { "field1": [] } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "field1": [], "field2": {} } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "$numberInt": "1" } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "$numberLong": "1" } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "$numberDouble": "1" } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "a" : { "$numberDecimal": "1" } }', 'a') IS NULL; SELECT bson_extract_geometry('{ "b" : true }', 'a') IS NULL; -- Case 2: Top level validation when the geodetic field is either object or array in strict mode SELECT bson_extract_geometry('{ "a" : { "field1": "Hello" } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": true } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": false } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": null } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": { "$undefined": true } } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberInt": "1" } } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberLong": "1" } } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberDouble": "1" } } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": { "$numberDecimal": "1" } } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": [], "field2": 10 } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": [[]], "field2": 10 } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": [{}], "field2": 10 } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": {}, "field2": 10 } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": "Hello" } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": "Hello", "field3": 10 } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": true } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": false } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": null } }', 'a'); SELECT bson_extract_geometry('{ "a" : { "field1": 10, "field2": { "$undefined": true } } }', 'a'); -- Case 2.1: Same Top level validations are skipped for array or object in bson_extract_geometry_runtime and returns NULL SELECT bson_extract_geometry_runtime('{ "a" : { "field1": "Hello" } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": true } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": false } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": null } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$undefined": true } } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberInt": "1" } } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberLong": "1" } } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberDouble": "1" } } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": { "$numberDecimal": "1" } } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [], "field2": 10 } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [[]], "field2": 10 } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": [{}], "field2": 10 } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": {}, "field2": 10 } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": "Hello" } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": true } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": false } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": null } }', 'a') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": { "$undefined": true } } }', 'a') IS NULL; -- Case 3: Top level strict validation for nested paths SELECT bson_extract_geometry('{ "a" : { "b": ["Text", "Text"] } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": [], "field2": 10 } } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": "Hello" } } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": true } } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": false } } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": null } } }', 'a.b'); SELECT bson_extract_geometry('{ "a" : { "b" : { "field1": 10, "field2": { "$undefined": true } } } }', 'a.b'); -- Case 3.1: Same Top level validations are skipped for nested paths in bson_extract_geometry_runtime function and returns NULL SELECT bson_extract_geometry_runtime('{ "a" : { "b": ["Text", "Text"] } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": [], "field2": 10 } } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": "Hello" } } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": true } } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": false } } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": null } } }', 'a.b') IS NULL; SELECT bson_extract_geometry_runtime('{ "a" : { "b" : { "field1": 10, "field2": { "$undefined": true } } } }', 'a.b') IS NULL; -- Case 4: Partial valid multipoint cases, throws error in strict mode SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 33, "2": 33 }}, {"b": ["Text", "Text"]} ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 34, "2": 34 }}, {"b": { "field1": [], "field2": 10 } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 35, "2": 35 }}, {"b": { "field1": 10, "field2": "Hello" } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 36, "2": 36 }}, {"b": { "field1": 10, "field2": true } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 37, "2": 37 }}, {"b": { "field1": 10, "field2": false } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 38, "2": 38 }}, {"b": { "field1": 10, "field2": null } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": { "1": 39, "2": 39 }}, {"b": { "field1": 10, "field2": { "$undefined": true } } } ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": [45,45]} ]}', 'a.b'); SELECT bson_extract_geometry('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120], "lat": 125 } ] } ]}', 'a.b.long'); -- With GeoJson points, errors in case of strict mode SELECT bson_extract_geometry('{"a": {"type": "Point", "coordinates": [45,45] } }', 'a'); SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46] } }', 'a'); SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46], "last": 20 } }', 'a'); SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "point", "coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid type: point (should be Point) SELECT bson_extract_geometry('{"a": {"extra": 10, "Type": "point", "coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid field name: Type SELECT bson_extract_geometry('{"a": {"extra": 10, "type": "point", "Coordinates": [46,46], "last": 20 } }', 'a'); -- Invalid field name: Coordinates SELECT bson_extract_geometry('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": {"type": "Point", "coordinates": [45,45]}} ]}', 'a.b'); -- Case 4.1: Partial points are returned without any error in non strict mode -- public.ST_ASEWKT is used to convert the geometry to Extended Well known text format of postgis SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 33, "2": 33 }}, {"b": ["Text", "Text"]} ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 34, "2": 34 }}, {"b": { "field1": [], "field2": 10 } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 35, "2": 35 }}, {"b": { "field1": 10, "field2": "Hello" } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 36, "2": 36 }}, {"b": { "field1": 10, "field2": true } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 37, "2": 37 }}, {"b": { "field1": 10, "field2": false } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 38, "2": 38 }}, {"b": { "field1": 10, "field2": null } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": { "1": 39, "2": 39 }}, {"b": { "field1": 10, "field2": { "$undefined": true } } } ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": [45,45]} ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120], "lat": 125 } ] } ]}', 'a.b.long')) AS geoms; -- With GeoJson points, no errors in non-strict mode SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"type": "Point", "coordinates": [45,45] } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "Point", "coordinates": [46,46] } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "Point", "coordinates": [47,47], "last": 20 } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "point", "coordinates": [48,48], "last": 20 } }', 'a')) AS geoms; -- Invalid type: array is empty SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "Type": "point", "coordinates": [49,49], "last": 20 } }', 'a')) AS geoms; -- Invalid field name: Type, array is empty SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{"a": {"extra": 10, "type": "point", "Coordinates": [50,50], "last": 20 } }', 'a')) AS geoms; -- Invalid field name: Coordinates, array is empty SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"b": [44, 44]}, {"b": "This is ok"}, {"b": ["This is not", "ok"]}, {"b": {"type": "Point", "coordinates": [51,51]}} ]}', 'a.b')) AS geoms; -- Case 5: Valid cases SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "field1": 10, "field2": 10 } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "thisCanBeAnything": 10, "Doesn''t matter": 10 } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": 10, "lat": 10, "extra": "Ignored" } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberInt": "10" }, "lat": { "$numberInt": "10" } } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberLong": "10" }, "lat": { "$numberLong": "10" } } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDouble": "10" }, "lat": { "$numberDouble": "10" } } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDecimal": "10" }, "lat": { "$numberDecimal": "10" } } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "long": { "$numberDouble": "1.23122e-2" }, "lat": { "$numberDecimal": "1.3160e1" } } }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [10, 10] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [10, 10, 20, 30, 40, 50] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberInt": "10"}, {"$numberInt": "10"}] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberLong": "10"}, {"$numberLong": "10"}] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDouble": "10"}, {"$numberDouble": "10"}] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDecimal": "10"}, {"$numberDecimal": "10"}] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{"$numberDouble": "1.23122e-2"}, {"$numberDecimal": "1.3160e1"}] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [{ "1": 33, "2": 33 }, { "1": 35, "2": 35 }]}', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10], [15, 15], [20, 20]] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10], { "point": 15, "point2": 15 }, [20, 20]] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[10, 10, "extra"], [15, 15, "extra"], [20, 20, "extra"]] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [[{"$numberInt": "10"}, {"$numberInt": "10"}], [{"$numberLong": "15"}, {"$numberLong": "15"}], [{"$numberDouble": "20"}, {"$numberDouble": "20"}], [{"$numberDecimal": "25"}, {"$numberDecimal": "25"}] ] }', 'a')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [-180, 180] }', 'a')); -- nested path valid cases SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : { "b" : [50, 50] } }', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": [30, 30] } ] }', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": false } ] }', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { }, [ ], { "b": [25, 25 ]} ] }', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { }, { "b": [30, 30 ]}, [], { "b": {"val1": 45, "val2": 45 } } ] }', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": "Not valid representation"} ]}', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ {"noBHere": [10, 10]}, {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')); SELECT public.ST_ASEWKT(bson_extract_geometry('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80, 90], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100, 110], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120, 130], "lat": 125 } ] } ]}', 'a.b.long')); -- Case 5.1: All Valid cases work even for non strict mode SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "field1": 10, "field2": 10 } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "thisCanBeAnything": 10, "Doesn''t matter": 10 } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": 10, "lat": 10, "extra": "Ignored" } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberInt": "10" }, "lat": { "$numberInt": "10" } } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberLong": "10" }, "lat": { "$numberLong": "10" } } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDouble": "10" }, "lat": { "$numberDouble": "10" } } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDecimal": "10" }, "lat": { "$numberDecimal": "10" } } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "long": { "$numberDouble": "1.23122e-2" }, "lat": { "$numberDecimal": "1.3160e1" } } }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [10, 10] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [10, 10, 20, 30, 40, 50] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberInt": "10"}, {"$numberInt": "10"}] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberLong": "10"}, {"$numberLong": "10"}] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDouble": "10"}, {"$numberDouble": "10"}] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDecimal": "10"}, {"$numberDecimal": "10"}] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{"$numberDouble": "1.23122e-2"}, {"$numberDecimal": "1.3160e1"}] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [{ "1": 33, "2": 33 }, { "1": 35, "2": 35 }]}', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10], [15, 15], [20, 20]] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10], { "point": 15, "point2": 15 }, [20, 20]] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[10, 10, "extra"], [15, 15, "extra"], [20, 20, "extra"]] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [[{"$numberInt": "10"}, {"$numberInt": "10"}], [{"$numberLong": "15"}, {"$numberLong": "15"}], [{"$numberDouble": "20"}, {"$numberDouble": "20"}], [{"$numberDecimal": "25"}, {"$numberDecimal": "25"}] ] }', 'a')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [-180, 180] }', 'a')) AS geoms; -- nested path valid cases SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : { "b" : [50, 50] } }', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": [30, 30] } ] }', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [10, 10] }, {"b": [20, 20] }, { "b": false } ] }', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { }, [ ], { "b": [25, 25 ]} ] }', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { }, { "b": [30, 30 ]}, [], { "b": {"val1": 45, "val2": 45 } } ] }', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": "Not valid representation"} ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ {"noBHere": [10, 10]}, {"b": { "1": 33, "2": 33 }}, {"b": []} ]}', 'a.b')) AS geoms; SELECT public.ST_ASEWKT(bson_extract_geometry_runtime('{ "a" : [ { "b": [ { "long": [70, 80], "lat": 75 }, { "long": [80, 90], "lat": 85 } ] }, { "b": [ { "long": [90, 100], "lat": 95 }, { "long": [100, 110], "lat": 105 } ] }, { "b": [ { "long": [110, 120], "lat": 115 }, { "long": [120, 130], "lat": 125 } ] } ]}', 'a.b.long')) AS geoms; -- Test to check if segmentize does leave geometries invalid in few cases. The test below shows a perfectly fine geography can be made into an invalid -- or intersecting points geometry by ST_SEGMENTIZE and to fix this we should use ST_MAKEVALID. SELECT public.ST_ISVALID('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography::public.geometry); SET client_min_messages = 'warning'; SELECT public.ST_ISVALID(public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry); -- 500km is our default segment length RESET client_min_messages; -- This is the base segmentize query when run without ST_MAKEVALID DO $$ DECLARE errorMessage text; BEGIN SELECT public.ST_SUBDIVIDE( public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry, 8 -- 8 is the default number of max vertices a divide segment can have )::public.geography; EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%Self-intersection at%' OR errorMessage LIKE '%geometry is invalid%' THEN -- We are only showing that after segmentize the geometry is invalid, the actual error message is irrelevant -- because the next test shows ST_MAKEVALID fixes this errorMessage := 'Invalid geometry found after segmentize.'; END IF; RAISE EXCEPTION '%', errorMessage using ERRCODE = SQLSTATE; END $$; -- Now run this again with ST_MAKEVALID to see the difference, ST_ASTEXT is used to pretty print the output SELECT public.ST_ASTEXT( public.ST_SUBDIVIDE( public.ST_MAKEVALID(public.ST_SEGMENTIZE('SRID=4326;POLYGON((-180 40, -157.5 40, -157.5 55, -180 55, -180 40))'::public.geography, 500000)::public.geometry), 8 -- 8 is the default number of max vertices a divide segment can have )::public.geography, 12 -- Limit output to 12 decimal digits ); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "segmentsTest", "indexes": [{"key": {"a": "2dsphere"}, "name": "my_2ds" }]}', true); --Insert 2 points one out one at the boundary and one inside the original polygon SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 1, "a" : { "type": "Point", "coordinates": [ -167, 48] } }', NULL); -- inside SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 2, "a" : { "type": "Point", "coordinates": [ -180, 40] } }', NULL); -- overlap with a vertex SELECT documentdb_api.insert_one('db','segmentsTest','{ "_id" : 3, "a" : { "type": "Point", "coordinates": [ -142, 49] } }', NULL); -- outside SELECT document FROM documentdb_api.collection('db', 'segmentsTest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-180, 40], [-157.5, 40], [-157.5, 55], [-180, 55], [-180, 40]]]}}}}'; EXPLAIN SELECT document FROM documentdb_api.collection('db', 'segmentsTest') WHERE document @@ '{"a": {"$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[[-180, 40], [-157.5, 40], [-157.5, 55], [-180, 55], [-180, 40]]]}}}}'; -- Polygon with points on a great circle of earth RESET search_path;list_metadata_cursor_tests.sql000066400000000000000000000102561507310017400351500ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 91000; SET documentdb.next_collection_id TO 910; SET documentdb.next_collection_index_id TO 910; -- create a collection in db1 SELECT documentdb_api.create_collection('list_metadata_db1', 'list_metadata_coll1'); UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db1'; SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "nameOnly": true }'); -- create a sharded collection in db1 SELECT documentdb_api.create_collection('list_metadata_db1', 'list_metadata_coll2'); SELECT documentdb_api.shard_collection('list_metadata_db1', 'list_metadata_coll2', '{ "_id": "hashed" }', false); -- create 2 collection in db2 SELECT documentdb_api.create_collection('list_metadata_db2', 'list_metadata_db2_coll1'); SELECT documentdb_api.create_collection('list_metadata_db2', 'list_metadata_db2_coll2'); -- create 2 views (one for db1 and one for db2) SELECT documentdb_api.create_collection_view('list_metadata_db1', '{ "create": "list_metadata_view1_1", "viewOn": "list_metadata_coll1", "pipeline": [{ "$limit": 100 }] }'); SELECT documentdb_api.create_collection_view('list_metadata_db2', '{ "create": "list_metadata_view2_1", "viewOn": "list_metadata_coll2", "pipeline": [{ "$skip": 100 }] }'); -- reset collection_uuids UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db1'; UPDATE documentdb_api_catalog.collections SET collection_uuid = NULL WHERE database_name = 'list_metadata_db2'; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1 }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1, "nameOnly": true }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1 }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "filter": { "type": "view" } }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "filter": { "info.readOnly": false } }') ORDER BY 1; -- create some indexes for the collections in db1 SELECT documentdb_api_internal.create_indexes_non_concurrently('list_metadata_db1', '{ "createIndexes": "list_metadata_coll1", "indexes": [ { "key": { "a": 1 }, "name": "a_1" }, { "key": { "b": 1 }, "name": "b_1", "unique": true } ]}', true); SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_coll1" }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_coll2" }') ORDER BY 1; -- fails SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_view1_1" }') ORDER BY 1; SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_indexes_cursor_first_page('list_metadata_db1', '{ "listIndexes": "list_metadata_non_existent" }') ORDER BY 1; -- test with add distributed metadata when there's a view SELECT COUNT(*) FROM ( SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db1', '{ "listCollections": 1, "addDistributedMetadata": true }')) i; SELECT COUNT(*) FROM ( SELECT bson_dollar_unwind(cursorpage, '$cursor.firstBatch') FROM documentdb_api.list_collections_cursor_first_page('list_metadata_db2', '{ "listCollections": 1, "addDistributedMetadata": true }')) i; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/or9.sql000066400000000000000000000111751507310017400303070ustar00rootroot00000000000000-- Based on or9.js CREATE SCHEMA or9; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,or9; SET citus.next_shard_id TO 10000; SET documentdb.next_collection_id TO 1000; SET documentdb.next_collection_index_id TO 1000; SELECT 1 FROM drop_collection('db','or9_test'); SELECT 1 FROM insert_one('db','or9_test', '{"field1":10,"field2":20}'); SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'or9_test'); -- Since we cannot define compound wildcard indexes, let's define two -- different wildcard indexes here. -- -- Indeed, our current implementation always creates a wildcard index, even for compound cases -- but for compatibility, let's stick to a single-field wildcard index here. SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('or9_test', 'index_1', '{"field1.$**": 1}'), true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('or9_test', 'index_2', '{"field2.$**": 1}'), true); CREATE OR REPLACE FUNCTION or9.assert_count(expected_row_count int, query bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','or9_test') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; BEGIN; set local enable_seqscan TO OFF; -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}}, {"field1": 10}]}'); SELECT assert_count(1, '{"$or": [{"field1": {"$gt": 15, "$lte": 25}}, {"field1": 10}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}}, {"field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 20, "$lte": 25}}, {"field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gt": 25, "$lte": 35}}, {"field2": 20}]}'); -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}}, {"field1": 10, "field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 25}, {"field1": 10}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}}, {"field2": 20, "field1": 10}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 25}, {"field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 25}, {"field1": 10, "field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 20, "$lte": 25}, "field2": 25}, {"field1": 10, "field2": 20}]}'); -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field1": {"$gte": 5, "$lte": 15}, "field2": 20}, {"field1": 10, "field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 25}, {"field1": 10, "field2": 20}]}'); SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 20, "$lte": 25}, "field1": 25}, {"field1": 10, "field2": 20}]}'); -- "SERVER-12594": there are two clauses in this case, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(1, '{"$or": [{"field2": {"$gte": 15, "$lte": 25}, "field1": 10}, {"field1": 10, "field2": 20}]}'); ROLLBACK; DO $$ DECLARE v_collection_id bigint; BEGIN SELECT collection_id INTO v_collection_id FROM documentdb_api_catalog.collections WHERE database_name = 'db' AND collection_name = 'or9_test'; EXECUTE format('TRUNCATE documentdb_data.documents_%s', v_collection_id); END $$; SELECT 1 FROM insert_one('db','or9_test', '{"field1": 10, "field2": 50}'); SELECT 1 FROM insert_one('db','or9_test', '{"field1": 50, "field2": 10}'); BEGIN; set local enable_seqscan to OFF; -- "SERVER-12594": there are two clauses in the case below, because we do -- not yet collapse OR of ANDs to a single ixscan. SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10]}, "field2": {"$in": [10, 50]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); SELECT assert_count(2, '{"$or": [{"field1": {"$in": [10]}, "field2": {"$in": [10]}}, {"field1": {"$in": [10, 50]}, "field2": {"$in": [10, 50]}}]}'); ROLLBACK;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/public_api_schema.sql000066400000000000000000000003431507310017400332200ustar00rootroot00000000000000-- show all functions exported in documentdb_api_distributed \df documentdb_api_distributed.* -- show all aggregates exported \da+ documentdb_api_distributed.* -- This is last (Tables/indexes) \d documentdb_api_distributed.* documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/query_sharding_tests.sql000066400000000000000000000162651507310017400340510ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 739000; SET documentdb.next_collection_id TO 7390; SET documentdb.next_collection_index_id TO 7390; SELECT documentdb_api.insert_one('qst', 'single_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); SELECT documentdb_api.insert_one('qst', 'comp_shard', '{ "_id": 1, "a": 1, "b": 2, "c": 3, "d": 4 }'); SELECT documentdb_api.shard_collection('qst', 'single_shard', '{ "a": "hashed" }', false); SELECT documentdb_api.shard_collection('qst', 'comp_shard', '{ "a": "hashed", "b": "hashed", "c": "hashed" }', false); -- cross shard queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "e": 1 } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "e": 1 } } ] }'); -- single shard queries EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "e": 1, "a": 4 } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "e": 1, "a": 4, "b": 2, "c": 6 } } ] }'); -- single shard with and EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": 4 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": 4 }, { "b": 2 }, { "c": 6 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1, "a": 4 }, { "b": 2, "c": 6 } ] } } ] }'); -- all components speciied but not equals, cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1 }, { "a": { "$ne": 4 } } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "e": 1, "a": 4 }, { "b": 2, "c": { "$gt": 6 } } ] } } ] }'); -- $or with a single branch - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "a": 4 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "b": 2, "$or": [ { "e": 1, "a": 4, "c": 6 } ] } } ] }'); -- top level $or - N shard query but not all branches have shard key: cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1 }, { "a": 4 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5 } ] } } ] }'); -- top level $or - all branches have shard key - N shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } } ] }'); -- $and and $or with $and having shard key and $or having shard key - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "a": 15}, { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "a": 15, "b": 3, "c": 7, "g": 5 }, { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); -- $and and $or with $or having shard key - N shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "g": 15}, { "$or": [ { "e": 1, "a": 5 }, { "a": 4 } ] } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "g": 5 }, { "$or": [ { "e": 1, "a": 4, "b": 2, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); -- $and and $or with $or not having shard key - cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "$and": [ { "g": 15}, { "$or": [ { "e": 1}, { "a": 4 } ] } ] } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "$and": [ { "g": 5 }, { "$or": [ { "e": 1, "a": 4, "c": 6 }, { "a": 4, "b": 5, "c": 9 } ] } ] } } ] }'); -- test all the same above but with $in instead of $or -- $in with a single branch - single shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4 ] } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4 ] }, "b": { "$in": [ 2 ] }, "c": { "$in": [ 6 ] } } } ] }'); -- $in with multiple branches - cross shard but limited subset of shards EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "single_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 6, 7 ] } } } ] }'); -- $in with mixed equality $in EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$eq": 5 }, "b": { "$in": [ 2, 3 ] }, "c": { "$in": [ 6, 6 ] } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$eq": 5 }, "b": { "$in": [ 2, 3 ] }, "c": { "$eq": 6 } } } ] }'); -- $in but not all are specified - full cross-shard EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "c": { "$in": [ 6, 6 ] } } } ] }'); EXPLAIN (COSTS OFF) SELECT document FROM bson_aggregation_pipeline('qst', '{ "aggregate": "comp_shard", "pipeline": [ { "$match": { "a": { "$in": [ 4, 5 ] }, "b": { "$gte": 3 }, "c": { "$in": [ 6, 7 ] } } } ] }'); documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex.sql000066400000000000000000000276011507310017400307110ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 335000; SET documentdb.next_collection_id TO 3350; SET documentdb.next_collection_index_id TO 3350; SELECT create_collection('db','regex'); SELECT insert_one('db','regex', '{"_id" : 99, "b": "abc123"}'); SELECT insert_one('db','regex', '{"_id" : 100, "b" : "abc123", "description" : "this is single line " }'); SELECT insert_one('db','regex', '{"_id" : 101, "b" : "abc789", "description" : "this is tow-line. single line\nSecond line" }'); SELECT insert_one('db','regex', '{"_id" : 102, "b" : "xyz456", "description" : "there are some spaces. Many spaces before line" }'); SELECT insert_one('db','regex', '{"_id" : 103, "b" : "xyz789", "description" : "this is Multiple\nline description" }'); SELECT insert_one('db','regex', '{"_id" : 104, "b" : "xyz790", "description" : "this is Multiple\n incline description" }'); SELECT insert_one('db','regex', '{"_id" : 105, "b" : "xyz800", "description" : "this is Multiple\n in\bcline \bdescription" }'); SELECT insert_one('db','regex', '{"_id" : 106, "a" : "hello a\bcde world" }'); SELECT insert_one('db','regex', '{"_id" : 107, "a" : {"$regularExpression" : {"pattern" : "a\bcde\b", "options" : ""}}}'); SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"pattern" : "hello", "options" : ""}} }'); SELECT insert_one('db','regex', '{"_id" : 109, "b" : "xyz810", "description" : "Multiple\n in\\ycline \bdescription"}'); SELECT insert_one('db','regex', '{"_id" : 110, "a" : {"$regularExpression" : {"pattern" : "a\\ycde\\y", "options" : ""}}}'); SELECT insert_one('db','regex', '{"_id" : 111, "a" : "a value", "b": "b value"}'); SELECT insert_one('db','regex', '{"_id" : 112, "a" : "v2", "b": "bv2"}'); SELECT insert_one('db','regex', '{"_id" : 113, "a" : "v3", "b": "bv3"}'); SELECT insert_one('db','regex', '{"_id" : 114, "a" : "v4", "b": "bv4"}'); SELECT insert_one('db','regex', '{"_id" : 115, "a" : "v5", "b": "bv5"}'); SELECT insert_one('db','regex', '{"_id" : 116, "a" : "v6", "b": "bv6"}'); SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7"}'); -- Some unicodes & mixed numerical SELECT insert_one('db','regex', '{"_id" : 120, "number" : "୩༢༣༤༥"}'); SELECT insert_one('db','regex', '{"_id" : 121, "number" : "02191996"}'); SELECT insert_one('db','regex', '{"_id" : 122, "number" : "9୩୪୬୯678"}'); -- Some unicode text SELECT insert_one('db','regex', '{"_id" : 130, "text" : "kyle"}'); SELECT insert_one('db','regex', '{"_id" : 131, "text" : "박정수"}'); SELECT insert_one('db','regex', '{"_id" : 132, "text" : "Fernández"}'); SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"b": 1}, "name": "index_on_sku"}]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"x": 1}, "name": "index_on_x" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"F1": 1}, "name": "index_on_F1" }]}', true); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"a": 1, "b": 1}, "name": "Compound_index_on_a_and_b" }]}', true); -- avoid plans that use the primary key index SELECT documentdb_distributed_test_helpers.drop_primary_key('db','regex'); SELECT document from collection('db', 'regex') where document @@ '{"b": {"$regex": true} }'; -- SELECT sku SELECT count(*) sku from collection('db', 'regex') where document @@ '{"b": {"$regex": "", "$options": ""} }'; -- 100 to 103 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\bline\\b", "$options" : "" } }'; -- No records. Will try to match \\y (as a char) in the document SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "\\\\yline\\\\y", "$options" : "" } }'; -- 109 Match \y as a char. For libbson \y is a special char. So to \y it needs to be escaped as \\y and for \\y, we need to provide as \\\\y SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\\\\ycline", "$options" : "" } }'; -- 107 Match a where a's value was inserted as a Regular expression object. Here \b will not be used as a flag. This entire regular expression object (/a\bcde\b/) will be compared (as such) against the regular expression object that was inserted. This is like regex is compared with another regex. SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$regularExpression" : { "pattern" : "a\bcde\b", "options" : "" } }}'; -- 110 (Same as 107 match above.) --SELECT document from collection('db', 'regex') where document @@ '{"a" : { "$regularExpression" : { "pattern": "a\\ycde\\y", "options" : ""} } }'; -- 100 and 101 SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "le.*\\bline\\b", "$options" : "" } }'; -- 105 Matching \b as a normal char inside the string. SELECT document from collection('db', 'regex') where document @@ '{ "description": { "$regex": "in\bcline \bdescription", "$options" : "" } }'; -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": { "$options": "i", "$regex": " line " } }'; -- 100 SELECT document from collection('db', 'regex') where document @@ '{"description": {"$regex": " line ","$options": "i"}}'; -- 106 108 SELECT document from collection('db', 'regex') where document @@ '{ "a" : { "$regularExpression" : { "pattern" : "hello", "options" : "" } } } '; -- 120 SELECT document from collection('db', 'regex') where document @@ '{ "number" : { "$regularExpression" : { "pattern" : "༣", "options" : "" } } } '; -- 121 122 if ascii digits are present SELECT document from collection('db', 'regex') where document @@ '{ "number" : { "$regularExpression" : { "pattern" : "[[:digit:]]", "options" : "" } } } '; -- 131 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "(*UTF)ì •", "options" : "" } } } '; -- 131 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "\\p{Hangul}", "options" : "" } } } '; -- 130 131 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Xan}+$", "options" : "" } } } '; -- 130 132 SELECT document from collection('db', 'regex') where document @@ '{ "text" : { "$regularExpression" : { "pattern" : "^\\p{Latin}", "options" : "" } } } '; -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache. SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; BEGIN; /* Make use of Index */ SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; /* Make use of Index */ SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; -- shard the collection by "_id" select documentdb_api.shard_collection('db', 'regex', '{"_id": "hashed"}', false); BEGIN; SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query on sharded collection. Index Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to OFF; SET LOCAL documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- 111 117 Multiple regex in a single query on sharded collection. Index Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; -- 111 117 Multiple regex in a single query on sharded collection. Seq Scan Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; -- 111 117 Multiple regex in a single query on sharded collection. Seq Scan Path. Ensuring multiple regexes, in the same query, are cached as separate entry in the cache EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; SELECT drop_collection('db','regex') IS NOT NULL; SELECT create_collection('db','regex'); SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{"createIndexes": "regex", "indexes": [{"key": {"a": 1}, "name": "index_on_a"}]}', true); -- shard the collection by "a" select documentdb_api.shard_collection('db', 'regex', '{"a": "hashed"}', false); SELECT insert_one('db','regex', '{"_id" : 106, "a" : "hello a\bcde world" }'); SELECT insert_one('db','regex', '{"_id" : 108, "a" : {"$regularExpression" : {"pattern" : "hello", "options" : ""}} }'); SELECT insert_one('db','regex', '{"_id" : 111, "a" : "a value", "b": "b value"}'); SELECT insert_one('db','regex', '{"_id" : 116, "a" : "v6", "b": "bv6"}'); SELECT insert_one('db','regex', '{"_id" : 117, "a" : "a value7", "b": "b value7"}'); BEGIN; SET LOCAL enable_seqscan to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Index Path SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Index Path EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Seq Scan Path SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; BEGIN; SET LOCAL enable_seqscan to ON; SET LOCAL documentdb.ForceUseIndexIfAvailable to OFF; -- 111 117 Multiple regex in a single query on sharded collection, where query is on the shard id column. Seq Scan Path EXPLAIN (COSTS OFF) SELECT document from collection('db', 'regex') where document @@ '{ "a": {"$regex": "a.vaLue", "$options": "i"}, "b": {"$regex": "b va.ue", "$options": ""}}'; ROLLBACK; SELECT drop_collection('db','regex') IS NOT NULL;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex5_tests_core.sql000066400000000000000000000121271507310017400332250ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION assert_count_regex5(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex5') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex5', '{"_id": 1, "x": "ayc"}'); SELECT insert_one('db','regex5', '{"_id": 2, "x": "xValue2"}'); SELECT insert_one('db','regex5', '{"_id": 3, "x": ["abc", "xyz1"]}'); SELECT insert_one('db','regex5', '{"_id": 4, "x": ["acd", "xyz23"]}'); SELECT insert_one('db','regex5', '{"_id": 5, "F1" : "F1_value", "x": ["first regular expression", "second expression", "third value for x"]}'); SELECT insert_one('db','regex5', '{"_id": 6, "F1" : "F1_value2"}'); SELECT insert_one('db','regex5', '{"_id": 7, "F1" : "this is the new value, done"}'); SELECT insert_one('db','regex5', '{"_id": 8, "F1" : "Giving the flag in the middle of the word \bval\bue\b, done"}'); SELECT insert_one('db','regex5', '{"_id": 9, "F1" : "hi, new y \\yvalue\\y; fine"}'); do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex5', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex5'); -- When x is non-array SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : ".*Yc", "$options": "i"}]}}'); -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). SELECT assert_count_regex5(1, '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'); -- When x's value is array and regex matches second element of 3rd record and 3rd element in the 5th record. SELECT assert_count_regex5(2, '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); -- Without any regex SELECT assert_count_regex5(2, '{"x": {"$in": ["acd", "first regular expression"]}}'); -- Mix of Regex and text SELECT assert_count_regex5(2, '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'); -- Test for hasNull (10 filler records and 4 actual records to match) SELECT assert_count_regex5(16, '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'); -- Test for $nin SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*yc", "$options": ""}]}}'); -- Test for $nin. With one REGEX and one normal string. SELECT assert_count_regex5(18, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz1", "xValue1"]}}'); -- Test for $nin. Two documents will match the $nin array. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : ".*b.*c", "$options": ""}, "xyz23", "xValue1"]}}'); -- Test for $nin. Single REGEX. SELECT assert_count_regex5(17, '{"x": {"$nin": [{"$regex" : "^a.c", "$options": ""}]}}'); -- Test for $nin. with null (only null and single null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null]}}'); -- Test for $nin. with null (only null and multiple null) SELECT assert_count_regex5(5, '{"x": {"$nin": [null, null]}}'); -- Test for $nin. with null SELECT assert_count_regex5(3, '{"x": {"$nin": [null, "second expression", {"$regex" : "xy.1", "$options": ""}]}}'); -- Test for $all. With all REGEX SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'); -- Test for $all. With one REGEX and one normal string. SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex" : "^.cd", "$options": ""}, "xyz23"]}}'); -- Test for $all. Empty array SELECT assert_count_regex5(0, '{"x": {"$all": []}}'); -- Test for $all. Single regex SELECT assert_count_regex5(1, '{"x": {"$all": [{"$regex": "^.V.+2$", "$options": ""}]}}'); -- Test for $all. Single string and no regex SELECT assert_count_regex5(1, '{"x": {"$all": ["xValue2"]}}'); -- Test for $all. with null in the $all array SELECT assert_count_regex5(0, '{"x": {"$all": [null, {"$regex": "xValu.+2$", "$options": ""} ]}}'); -- Test for $all. with only null in the $all array SELECT assert_count_regex5(14, '{"x": {"$all": [null]}}'); -- Test for $all. with only null in the $all array (with multiple null) SELECT assert_count_regex5(14, '{"x": {"$all": [null, null]}}'); SELECT assert_count_regex5(4, '{"F1": {"$regex" : "Value", "$options": "i"}}'); select document from collection('db','regex5') where document @@ '{"F1": {"$regex" : "word \bval\bue\b,", "$options": ""}}'; select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "word \bval\bue\b,", "options" : "" } } }'; -- Work as word boundary {"F1" : "this is the new value, done"} select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\bValue\\b", "options" : "i" } } }'; -- rec 9 select document from collection('db','regex5') where document @@ '{"F1": { "$regularExpression" : { "pattern" : "\\\\yValue\\\\y", "options" : "i" } } }'; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex5_tests_explain.sql000066400000000000000000000103101507310017400337250ustar00rootroot00000000000000CREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 1010000; SET documentdb.next_collection_id TO 101000; SET documentdb.next_collection_index_id TO 101000; SELECT insert_one('db','regex5', '{"x": "ayc"}'); SELECT insert_one('db','regex5', '{"x": ["abc", "xyz1"]}'); SELECT insert_one('db','regex5', '{"x": ["acd", "xyz23"]}'); SELECT insert_one('db','regex5', '{"F1" : "F1_value", "x": ["first regular expression", "second expression", "third value for x"]}'); SELECT insert_one('db','regex5', '{"F1" : "F1_value2"}'); -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex5'); \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('regex5', 'index_wc', '{"$**": 1}'), true); \o \set ECHO :prevEcho -- -- FORCING INDEX PATH -- BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceRumIndexScantoBitmapHeapScan TO OFF; -- When x is non-array EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : ".*Yc", "$options": "i"}]}}'; -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'; -- When x'z value is array and regex matches second element of 2nd record and 3rd element in the 4th record. EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; -- Without any regex EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": ["acd", "first regular expression"]}}'; -- Mix of Regex and text EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'; -- Test for hasNull (10 filler records and 3 actual records to match) EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'; -- Test for $all EXPLAIN (COSTS OFF) SELECT document FROM collection('db','regex5') WHERE document @@ '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; ROLLBACK; -- -- RUN TIME PATH -- -- When x is non-array EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : ".*yc", "$options": ""}]}}'; -- When x's value is array and regex matches one of the array elements, specifically the first element (3rd record). EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "^.*cd", "$options": ""}]}}'; -- When x'z value is array and regex matches second element of 2nd record and 3rd element in the 4th record. EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [{"$regex" : "x.+1", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; -- Without any regex EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": ["acd", "first regular expression"]}}'; -- Mix of Regex and text EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", {"$regex" : "xy.1", "$options": ""} ] }}'; -- Test for hasNull (10 filler records and 3 actual records to match) EXPLAIN (COSTS OFF) SELECT document FROM collection('db', 'regex5') WHERE document @@ '{"x": {"$in": [ "second expression", null, {"$regex" : "xy.1", "$options": ""} ] }}'; -- Test for $all EXPLAIN (COSTS OFF) SELECT document FROM collection('db','regex5') WHERE document @@ '{"x": {"$all": [{"$regex" : "expression", "$options": ""}, {"$regex" : "value .+ x", "$options": ""}]}}'; SELECT drop_collection('db','regex5'); DROP SCHEMA regex5 CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex5_tests_index.sql000066400000000000000000000013531507310017400334030ustar00rootroot00000000000000CREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 90000; SET documentdb.next_collection_id TO 900; SET documentdb.next_collection_index_id TO 900; SELECT create_collection('db','regex5'); \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('regex5', 'index_wc', '{"$**": 1}'), true); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/regex5_tests_core.sql ROLLBACK; SELECT drop_collection('db','regex5'); DROP SCHEMA regex5 CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex5_tests_runtime.sql000066400000000000000000000006771507310017400337670ustar00rootroot00000000000000CREATE SCHEMA regex5; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex5; SET citus.next_shard_id TO 90000; SET documentdb.next_collection_id TO 900; SET documentdb.next_collection_index_id TO 900; SELECT create_collection('db','regex5'); BEGIN; set local enable_seqscan TO ON; \i sql/regex5_tests_core.sql ROLLBACK; SELECT drop_collection('db','regex5'); DROP SCHEMA regex5 CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_core.sql000066400000000000000000000075521507310017400334770ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION assert_count_regex_options(expected_row_count int, query documentdb_core.bson) RETURNS void LANGUAGE plpgsql AS $$ DECLARE returned_row_count int; BEGIN SELECT count(*) INTO returned_row_count FROM collection('db','regex_options') WHERE document @@ query; IF returned_row_count <> expected_row_count THEN RAISE 'query % returned % rows instead of %', query, returned_row_count, expected_row_count; END IF; END; $$; SELECT insert_one('db','regex_options', '{"msg": "hpattern New"}'); SELECT insert_one('db','regex_options', '{"msg": "pattX New"}'); SELECT insert_one('db','regex_options', '{"msg": "pattX\nNew"}'); SELECT insert_one('db','regex_options', '{"msg": "pattx\nNew"}'); SELECT insert_one('db','regex_options', '{"msg": "pattx_New"}'); SELECT insert_one('db','regex_options', '{"msg": "hello\npattx\nNewLineStart"}'); SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); SELECT insert_one('db','regex_options', '{"msg": "hello\npattx NewWord"}'); SELECT insert_one('db','regex_options', '{"msg": "hello\npattX New\nWord"}'); do $$ DECLARE temp text; begin for counter in 1..10 loop SELECT insert_one('db','regex_options', '{"filler": "fillerValue"}') into temp; end loop; end $$; -- DROP PRIMARY KEY SELECT documentdb_distributed_test_helpers.drop_primary_key('db', 'regex_options'); SELECT assert_count_regex_options(8, '{"msg": {"$options": "ims", "$regex": "^pattX.New"}}'); SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New$", "$options": "mis"}}'); SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.New", "$options": "ims"}}'); -- With comment and space in pattern and without extended match flag (x) SELECT assert_count_regex_options(0, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ims"}}'); -- With comment and space in pattern and with extended match flag (x) SELECT assert_count_regex_options(8, '{"msg": {"$regex": "^pattX.N#COMMENT\n ew", "$options": "ixms"}}'); SELECT assert_count_regex_options(1, '{"msg": {"$regex": "^pattX.New", "$options": ""}}'); SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "i"}}'); -- . matches new line when s flag is set. SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "s"}}'); -- multiline match flag SELECT assert_count_regex_options(2, '{"msg": {"$regex": "^pattX.New", "$options": "m"}}'); -- . matches new line and case insensitive match SELECT assert_count_regex_options(4, '{"msg": {"$regex": "^pattX.New", "$options": "si"}}'); SELECT assert_count_regex_options(5, '{"msg": {"$regex": "^pattX.New", "$options": "mi"}}'); SELECT assert_count_regex_options(3, '{"msg": {"$regex": "^pattX.New", "$options": "ms"}}'); -- This will work as an implicit AND. TODO. To make the behavior same as from Mongo shell through GW : Mongo on Citus -- SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": "i"}}'); -- eq does not match --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpatternNew", "$options": "i"}}'); -- Regex options does not make the document to match query spec. --SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$eq": "hpattern New", "$options": ""}}'); -- When there are duplicate keys, the last one of each will be considered. SELECT assert_count_regex_options(1,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "mi"}}'); -- In continuation with the above tests: To ensure that the last regex options pair is really getting taken. SELECT assert_count_regex_options(0,'{"msg": {"$regex": "hpattern.new", "$options": "i", "$regex": "^word$", "$options": "i"}}'); -- This will error out because $options needed a $regex. SELECT document FROM collection('db','regex_options') WHERE document @@ '{"msg": {"$options": "i"}}'; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_index.sql000066400000000000000000000014251507310017400336470ustar00rootroot00000000000000CREATE SCHEMA regex_options; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex_options; SET citus.next_shard_id TO 80000; SET documentdb.next_collection_id TO 800; SET documentdb.next_collection_index_id TO 800; SELECT create_collection('db','regex_options'); \set prevEcho :ECHO \set ECHO none \o /dev/null SELECT documentdb_api_internal.create_indexes_non_concurrently('db', documentdb_distributed_test_helpers.generate_create_index_arg('regex_options', 'index_wc', '{"$**": 1}'), true); \o \set ECHO :prevEcho BEGIN; set local enable_seqscan TO OFF; set local documentdb.forceUseIndexIfAvailable to on; \i sql/regex_options_core.sql ROLLBACK; SELECT drop_collection('db','regex_options'); DROP SCHEMA regex_options CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/regex_options_runtime.sql000066400000000000000000000007441507310017400342260ustar00rootroot00000000000000CREATE SCHEMA regex_options; SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal,public,regex_options; SET citus.next_shard_id TO 700000; SET documentdb.next_collection_id TO 700; SET documentdb.next_collection_index_id TO 700; SELECT create_collection('db','regex_options'); BEGIN; set local enable_seqscan TO ON; \i sql/regex_options_core.sql ROLLBACK; SELECT drop_collection('db','regex_options'); DROP SCHEMA regex_options CASCADE; documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sql/schema_validation.sql000066400000000000000000000766741507310017400332670ustar00rootroot00000000000000SET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 17770000; SET documentdb.next_collection_id TO 177700; SET documentdb.next_collection_index_id TO 177700; -- create a collection and insert a document SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); set documentdb.enableSchemaValidation = true; SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "nameOnly": true }'); select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col'; -- create again without schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col"}'); -- create again without schema validation level SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationAction": "warn"}'); -- create again without schema validation action SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "moderate"}'); -- create with unmatched schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"b": {"bsonType": "string"}}}}, "validationLevel": "strict", "validationAction": "error"}'); -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); -- create collection without schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3"}'); -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col3" }, "nameOnly": true }'); select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col3'; -- create again with schema validator SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}}'); -- create again with schema validation level SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validationLevel": "strict"}'); -- create again with schema validation action SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validationAction": "error"}'); -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3"}'); -- create collection with schema validatorAction SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validationLevel": "strict"}'); -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col4" }, "nameOnly": true }'); select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col4'; -- create again with schema validatorAction SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}}'); -- create again with same parameters SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validationLevel": "strict"}'); set documentdb.enableSchemaValidation = false; -- update validation action SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "warn"}'); set documentdb.enableSchemaValidation = true; SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "warn"}'); SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "string"}}}}}'); -- get updated collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col" }, "nameOnly": true }'); select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col'; -- insert a document with type mismatch -- SELECT documentdb_api.insert('schema_validation','{"insert":"col", "documents":[{"_id":"8", "a":"yy"}]}'); -- SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation','col'); -- update: ignore validation when action = warn -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":1},"u":{"$set":{"a":"tt"}}}]}'); -- SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationAction": "error"}'); -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":2},"u":{"$set":{"a":"ss"}},"multi":true}]}'); -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":"yy"},"u":{"$set":{"a":"yyy"}}}]}'); -- update validation level -- SELECT documentdb_api.coll_mod('schema_validation', 'col', '{"collMod":"col", "validationLevel": "moderate"}'); -- update document with type mismatch -- SELECT documentdb_api.update('schema_validation', '{"update":"col", "updates":[{"q":{"a":"yy"},"u":{"$set":{"a":"yyy"}},"multi":true}]}'); -- SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation','col'); -- validator without $jsonSchema SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col1", "validator": {"a":{"$type":"int"}}, "validationLevel": "strict", "validationAction": "error"}'); -- get collection info SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col1" }, "nameOnly": true }'); select validator, validation_level, validation_action from documentdb_api_catalog.collections where database_name = 'schema_validation' and collection_name = 'col1'; -- select documentdb_api.insert('schema_validation', '{"insert":"col1", "documents":[{"_id":"1", "a":1}]}'); -- select documentdb_api.insert('schema_validation', '{"insert":"col1", "documents":[{"_id":"1", "a":"hello"}]}'); -- validator > 10k throw error SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col2", "validator": {"$jsonSchema":{"bsonType":"object","properties":{"name":{"bsonType":"string","description":"The name of the entity"},"age":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_1":{"bsonType":"string","description":"The name of the entity"},"age_1":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_1":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_1":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_1":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_1":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_1":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_2":{"bsonType":"string","description":"The name of the entity"},"age_2":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_2":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_2":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_2":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_2":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_2":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_3":{"bsonType":"string","description":"The name of the entity"},"age_3":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_3":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_3":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_3":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_3":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_3":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_4":{"bsonType":"string","description":"The name of the entity"},"age_4":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_4":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_4":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_4":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_4":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_4":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about theentity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_5":{"bsonType":"string","description":"The name of the entity"},"age_5":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_5":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_5":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_5":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_5":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"Listof contacts"},"info_5":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_6":{"bsonType":"string","description":"The name of the entity"},"age_6":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_6":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_6":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_6":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_6":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type:phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_6":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_7":{"bsonType":"string","description":"The name of the entity"},"age_7":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_7":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_7":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_7":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_7":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_7":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"largeField1":{"bsonType":"string","description":"A large field to increase validator size"},"largeField2":{"bsonType":"int","description":"Another large field to increase validator size"},"largeTextField":{"bsonType":"string","description":"A very large text field"}},"required":["name","age"]}}}'); SELECT cursorpage, continuation, persistconnection, cursorid FROM documentdb_api.list_collections_cursor_first_page('schema_validation', '{ "listCollections": 1, "filter": { "name": "col2" }, "nameOnly": true }'); -- increase maxSchemaValidatorSize to 20KB SET documentdb.maxSchemaValidatorSize = 20480; SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col2", "validator": {"$jsonSchema":{"bsonType":"object","properties":{"name":{"bsonType":"string","description":"The name of the entity"},"age":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_1":{"bsonType":"string","description":"The name of the entity"},"age_1":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_1":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_1":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_1":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_1":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_1":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_2":{"bsonType":"string","description":"The name of the entity"},"age_2":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_2":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_2":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_2":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_2":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_2":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_3":{"bsonType":"string","description":"The name of the entity"},"age_3":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_3":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_3":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_3":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_3":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_3":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_4":{"bsonType":"string","description":"The name of the entity"},"age_4":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_4":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_4":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_4":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_4":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_4":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about theentity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_5":{"bsonType":"string","description":"The name of the entity"},"age_5":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_5":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_5":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_5":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_5":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"Listof contacts"},"info_5":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_6":{"bsonType":"string","description":"The name of the entity"},"age_6":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_6":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_6":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_6":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_6":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type:phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_6":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"name_7":{"bsonType":"string","description":"The name of the entity"},"age_7":{"bsonType":"int","minimum":{"$numberInt":"18"},"description":"The age of the entity, must be at least 18"},"address_7":{"bsonType":"object","properties":{"street":{"bsonType":"string","description":"The street address"},"city":{"bsonType":"string","description":"The city"},"state":{"bsonType":"string","description":"The state or province"},"country":{"bsonType":"string","description":"The country"}},"required":["street","city","country"],"description":"The address object"},"hobbies_7":{"bsonType":"array","items":{"bsonType":"string"},"description":"List of hobbies"},"scores_7":{"bsonType":"object","properties":{"math":{"bsonType":"int"},"science":{"bsonType":"int"},"history":{"bsonType":"int"}},"description":"Subject scores","additionalProperties":false},"contacts_7":{"bsonType":"array","items":{"bsonType":"object","properties":{"type":{"bsonType":"string","enum":["phone","email"],"description":"Contact type: phone or email"},"value":{"bsonType":"string","description":"Contact value"}},"required":["type","value"]},"description":"List of contacts"},"info_7":{"bsonType":"object","properties":{"description":{"bsonType":"string","description":"Description about the entity"},"details":{"bsonType":"object","properties":{"field1":{"bsonType":"string"},"field2":{"bsonType":"string"},"field3":{"bsonType":"string"}}}}},"largeField1":{"bsonType":"string","description":"A large field to increase validator size"},"largeField2":{"bsonType":"int","description":"Another large field to increase validator size"},"largeTextField":{"bsonType":"string","description":"A very large text field"}},"required":["name","age"]}}}'); SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col3", "validator": { "$and": [ { "a": { "$gt": 2 } }, {"$jsonSchema": {"bsonType": "obect", "properties": {"a": {"bsonType": "int", "maximum":5}}}} ] } }'); SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col4", "validator": { "$jsonSchema": {"bsonType": "obect", "properties": {"a": {"bsonType": "int", "maximum":5}}}} } '); SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col5", "validator": { "$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum":"str"}}}} } '); SELECT documentdb_api.create_collection_view('schema_validation', '{ "create": "col6", "validator": { "$jsonSchema": {"bsonType": "object", "required":["a"]}} }'); schema_validation_insert.sql000066400000000000000000000546701507310017400345640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 17771000; SET documentdb.next_collection_id TO 177710; SET documentdb.next_collection_index_id TO 177710; set documentdb.enableSchemaValidation = true; --------------------------------------Need $jsonSchema-------------------------------------- SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int"}}}}, "validationLevel": "strict", "validationAction": "error"}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col", "documents":[{"_id":"1", "a":1}]}'); -- required not supported yet, so this should be inserted SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col", "documents":[{"_id":"2", "b":1}]}'); -- type mismatch SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"3", "a":"hello"}]}'); -- batch insert SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"4", "a":2},{"_id":"5", "a":3}, {"_id":"6", "a":"tt"}]}'); -- 0 documents should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col') ORDER BY shard_key_value, object_id; -- set validationAction to warn SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col', '{"collMod":"col", "validationAction": "warn"}'); SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col", "documents":[{"_id":"7", "a":"hello"}]}'); -- 1 document should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col') ORDER BY shard_key_value, object_id; ---------------------------------------------Need top level operator----------------------------------------------------- -- $expr SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col1", "validator": { "$expr": {"$eq": [ "$a", "$b" ] } } }'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col1", "documents":[{"_id":"1", "a":1, "b":1, "c":1}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col1", "documents":[{"_id":"2", "a":3, "b":1, "c":2}]}'); -- $and SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col2", "validator": { "$and": [ { "a": { "$gt": 2 } }, {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum":5}}}} ] } }'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"1", "a":4}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"2", "a":1}]}'); -- expect to throw error as 6 > 5 (maximum) SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"3", "a":6}]}'); set documentdb.enableBypassDocumentValidation = true; SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col2", "documents":[{"_id":"2", "a":1}], "bypassDocumentValidation": true}'); ---------------------------------------------simple case----------------------------------------------------- -- field SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col3", "validator": {"a":{"$type":"int"}}}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"1", "a":1}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"2", "a":"hello"}]}'); --$merge SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col_", "documents":[{"_id":"1001","a":"world"}]}'); SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col_", "documents":[{"_id":"1002","a":2}]}'); select documentdb_api.insert('schema_validation_insertion', '{"insert":"col_", "documents":[{"_id":"1003","a":11}]}'); -- whenNotMatch is insert SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1001"}}, {"$merge" : { "into": "col3" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1002"}}, {"$merge" : { "into": "col3" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; -- WhenNotMatched is discard SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id":"1003"}}, {"$merge" : { "into": "col3", "whenNotMatched": "discard" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; -- whenMatched is merge SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":22}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; ---- don't throw error as source and target schema is same SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"merge_same"}}}]}'); SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"merge_same"}}}],"bypassDocumentValidation": true}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; ---- throw error as source and target schema is different since key is same but value is different SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":22}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- whenMatched is replace select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":222, "b":1}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; ---- don't throw error as source and target schema is same SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"replace_same"}}}]}'); SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"replace_same"}}}],"bypassDocumentValidation": true}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; ---- throw error as source and target schema is different SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":222, "b":1}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); -- validationLevel is moderate select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test"}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "moderate"}'); select documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test_3"}}}]}'); select documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"test_3"}}}], "bypassDocumentValidation": true}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; select documentdb_api.update('schema_validation_insertion', '{"update":"col_", "updates":[{"q":{"_id":"1002"},"u":{"$set":{"a":"ttt"}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "_id": "1002" }}, {"$merge" : { "into": "col3", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; --$out select documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col5"}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "string" }}}, {"$out": "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "int" }}}, {"$out": "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col5', '{"collMod":"col5", "validator": {"a":{"$type":"int"}}}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "string" }}}, {"$out" : "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_", "pipeline": [ { "$match": { "a": { "$type": "int" }}}, {"$out" : "col5" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col5') ORDER BY shard_key_value, object_id; -- sharded collection test SELECT documentdb_api.shard_collection('schema_validation_insertion', 'col3', '{ "a": "hashed" }', false); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"1", "a":"hello"}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"2", "a":5}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col3", "documents":[{"_id":"3", "a":2}, {"_id":"4", "a":3}, {"_id":"5", "a":4}, {"_id":"6", "a":"string"}]}'); -- 5 documents should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; -- set validationAction to warn SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationAction": "warn"}'); SELECT documentdb_api.insert('schema_validation_insertion','{"insert":"col3", "documents":[{"_id":"7", "a":"hello"}]}'); -- 6 document should be inserted SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3') ORDER BY shard_key_value, object_id; SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "strict"}'); ---------------------------------------------update----------------------------------------------------- -- sharded collection test -- will succeed as validationAction is warn SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a": 1},"u":{"$set":{"a":"one"}}}]}'); -- set validation action to error SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationAction": "error"}'); -- should throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":4},"u":{"$set":{"a":"four"}}}]}'); -- should succeed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":3},"u":{"$set":{"a":300}}}]}'); -- upsert succeeded SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"abc"},"u":{"$set":{"_id":500, "a":500}}, "upsert":true}]}'); -- upsert failed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"abc"},"u":{"$set":{"a":"abcd"}}, "upsert":true}]}'); -- should succeed with bypassDocumentValidation SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":4},"u":{"$set":{"a":"four"}}}], "bypassDocumentValidation": true}'); -- multiple updates -- throw error as multi update is not allowed on sharded collection SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":2},"u":{"$set":{"a":200}}, "multi":true} ]}'); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3'); -- will throw error as validationLevel is strict SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}} ]}'); -- moderate case SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col3', '{"collMod":"col3", "validationLevel": "moderate"}'); -- will succeed as validationLevel is moderate SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}} ]}'); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col3'); -- batch update SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col3", "updates":[{"q":{"a":500},"u":{"$set":{"a":5000}}}, {"q":{"a":"four"},"u":{"$set":{"a":"fourty"}}}, {"q":{"a":6},"u":{"$set":{"a":600, "_id":600}}, "upsert": true}, {"q":{"a":"string"},"u":{"$set":{"a":"str"}}, "upsert":true} ]}'); --unsharded collection test SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col4", "validator": {"a":{"$type":"int"}}, "validationLevel": "strict", "validationAction": "warn"}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col4", "documents":[{"_id":"1", "a":1}, {"_id":"2", "a":2}, {"_id":"3", "a":3}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col4", "documents":[{"_id":"4", "a":"hello"}]}'); -- will succeed as validationAction is warn SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":1},"u":{"$set":{"a":"one"}}}]}'); SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col4', '{"collMod":"col4", "validationAction": "error"}'); -- should throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":2},"u":{"$set":{"a":"one"}}}]}'); -- should succeed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":3},"u":{"$set":{"a":300}}}]}'); -- upsert succeeded SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"abc"},"u":{"$set":{"_id":500, "a":500}}, "upsert":true}]}'); -- upsert failed SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"abc"},"u":{"$set":{"a":"abcd"}}, "upsert":true}]}'); -- should succeed with bypassDocumentValidation SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":2},"u":{"$set":{"a":"one"}}}], "bypassDocumentValidation": true}'); -- multiple updates SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"one"},"u":{"$set":{"a":200}}, "multi":true} ]}'); -- will throw error SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":300},"u":{"$set":{"a":"th"}}, "multi":true} ]}'); -- will throw error as validationLevel is strict SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"hello"},"u":{"$set":{"a":"world"}}} ]}'); -- moderate case SELECT documentdb_api.coll_mod('schema_validation_insertion', 'col4', '{"collMod":"col4", "validationLevel": "moderate"}'); -- will succeed as validationLevel is moderate SELECT documentdb_api.update('schema_validation_insertion', '{"update":"col4", "updates":[{"q":{"a":"hello"},"u":{"$set":{"a":"ten"}}} ]}'); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col4'); -------------------------------merge/out more case--------------------------------------------------------------- -- top level operator in schema information SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col_merge_tar", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "minimum": 5}}}}}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"1", "a":5}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"2", "a":2}]}'); SELECT documentdb_api.insert('schema_validation_insertion', '{"insert":"col_source", "documents":[{"_id":"3", "a":"hello"}]}'); -- $merge SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "2" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "3" }}, {"$merge" : { "into": "col_merge_tar", "whenNotMatched": "insert" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; -- merge with whenMatched select documentdb_api.update('schema_validation_insertion', '{"update":"col_source", "updates":[{"q":{"_id":"1"},"u":{"$set":{"a":11, "b":1}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenMatched": "merge" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; select documentdb_api.update('schema_validation_insertion', '{"update":"col_source", "updates":[{"q":{"_id":"1"},"u":{"$set":{"a":111}, "$unset":{"b":""}}}]}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$merge" : { "into": "col_merge_tar", "whenMatched": "replace" }} ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_merge_tar') ORDER BY shard_key_value, object_id; -- $out SELECT documentdb_api.create_collection_view('schema_validation_insertion', '{ "create": "col_out_tar", "validator": {"$jsonSchema": {"bsonType": "object", "properties": {"a": {"bsonType": "int", "maximum": 5}}}}}'); SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "2" }}, {"$out" : "col_out_tar" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_out_tar') ORDER BY shard_key_value, object_id; SELECT * FROM aggregate_cursor_first_page('schema_validation_insertion', '{ "aggregate": "col_source", "pipeline": [ { "$match": { "_id": "1" }}, {"$out" : "col_out_tar" } ], "cursor": { "batchSize": 1 } }', 4294967294); SELECT shard_key_value, object_id, document from documentdb_api.collection('schema_validation_insertion','col_out_tar') ORDER BY shard_key_value, object_id; set documentdb.enableBypassDocumentValidation = false; set documentdb.enableSchemaValidation = false;setwindowfields_and_group_compliance.sql000066400000000000000000000116551507310017400371640ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 884500; SET documentdb.next_collection_id TO 88450; SET documentdb.next_collection_index_id TO 88450; CREATE SCHEMA setWindowFieldSchema; -- The test is intended to set an agreement between the setwindowfields and group aggregate operators -- to be working on both cases (if implemented) -- [Important] - When any operator is supported for both $group and $setWindowFields then please remove it from here. CREATE OR REPLACE FUNCTION get_unsupported_operators() RETURNS TABLE(unsupported_operator text) AS $$ BEGIN RETURN QUERY SELECT unnest(ARRAY[ '$bottom', '$bottomN', '$maxN', '$median', '$minN', '$percentile', '$stdDevSamp', '$stdDevPop', '$top', '$topN' ]) AS unsupported_operator; END; $$ LANGUAGE plpgsql; -- Make a non-empty collection SELECT documentdb_api.insert_one('db','setWindowField_compliance','{ "_id": 1 }', NULL); DO $$ DECLARE operator text; errorMessage text; supportedInSetWindowFields BOOLEAN; supportedInGroup BOOLEAN; querySpec bson; BEGIN FOR operator IN SELECT * FROM get_unsupported_operators() LOOP supportedInSetWindowFields := TRUE; supportedInGroup := TRUE; querySpec := FORMAT('{ "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", "test": {"%s": { } } }}]}', operator)::documentdb_core.bson; BEGIN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', querySpec); EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%Unknown group operator%' OR errorMessage LIKE '%not implemented%' THEN supportedInGroup := FALSE; END IF; END; querySpec := FORMAT('{ "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": { "field": { "%s": { } } } }}]}', operator)::documentdb_core.bson; BEGIN SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', querySpec); EXCEPTION WHEN OTHERS THEN errorMessage := SQLERRM; IF errorMessage LIKE '%not supported%' THEN supportedInSetWindowFields := FALSE; END IF; END; IF supportedInSetWindowFields <> supportedInGroup THEN RAISE NOTICE '[TEST FAILED] Operator % is not supported in %', operator, CASE WHEN supportedInSetWindowFields THEN '$group' ELSE '$setWindowFields' END; ELSEIF supportedInSetWindowFields THEN RAISE NOTICE '[TEST PASSED] Operator % is supported in both $group and $setWindowFields', operator; ELSE RAISE NOTICE '[TEST PASSED] Operator % is not supported in both $group and $setWindowFields', operator; END IF; END LOOP; END $$; DROP SCHEMA setWindowFieldSchema CASCADE; CREATE OR REPLACE FUNCTION check_aggregates(num_elements int) RETURNS void AS $fn$ DECLARE bson_spec jsonb; bson_spec_str text; group_by_spec text; setwindowFields_spec text; groupResult bson; setwindowFieldsResult bson; groupExplainResult jsonb; setwindowFieldsExplainResult jsonb; i int; BEGIN -- Initialize the BSON spec as an empty JSONB object bson_spec := '{}'::jsonb; -- Loop to add 50 fields to the BSON spec FOR i IN 1..num_elements LOOP bson_spec := jsonb_set(bson_spec, ARRAY['field' || i::text], jsonb_build_object('$sum', 1)); END LOOP; -- Output the BSON spec bson_spec_str := bson_spec::text; RAISE NOTICE '\n============= TESTING MULTIPLE ARGUMENTS AGGREGATES (%) =======================' , num_elements; group_by_spec := '{ "aggregate": "setWindowField_compliance", "pipeline": [{"$group": { "_id": "$_id", ' || substring(bson_spec_str, 2, length(bson_spec_str) - 2) || ' }}]}'; setwindowFields_spec := '{ "aggregate": "setWindowField_compliance", "pipeline": [{"$setWindowFields": { "output": ' || bson_spec_str || ' }}]}'; SET citus.log_remote_commands = 'on'; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', group_by_spec::documentdb_core.bson) INTO groupResult; RAISE NOTICE E'\n=============\nGroup by\n=============\nQuery: %\n\nResult: %', group_by_spec, groupResult; SELECT document FROM documentdb_api_catalog.bson_aggregation_pipeline('db', setwindowFields_spec::documentdb_core.bson) INTO setwindowFieldsResult; RAISE NOTICE E'\n=============\nSetWindowFields\n=============\nQuery: %\n\nResult: %', setwindowFields_spec, setwindowFieldsResult; RESET citus.log_remote_commands; END; $fn$ LANGUAGE plpgsql; -- Check aggregates with different number of aggregation operators SELECT check_aggregates(30); SELECT check_aggregates(50); SELECT check_aggregates(51); SELECT check_aggregates(100); SELECT check_aggregates(105); SELECT check_aggregates(200); three_column_data_table.sql000066400000000000000000000121521507310017400343370ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 2930000; SET documentdb.next_collection_id TO 293000; SET documentdb.next_collection_index_id TO 293000; SET documentdb.enableDataTableWithoutCreationTime to off; -- create table with 4 columns first SELECT documentdb_api.create_collection('db', '4col'); \d documentdb_data.documents_293000 SELECT documentdb_api.insert_one('db', '4col', '{ "_id": 1}'); -- enable GUC SET documentdb.enableDataTableWithoutCreationTime to on; -- [1] let's test 4 column table after enabling GUC -- (1.1) insert to 4 column collection SELECT documentdb_api.insert_one('db', '4col', '{ "_id": 2}'); -- (1.2) multiple-insert to 4 column collection SELECT documentdb_api.insert('db', '{"insert":"4col", "documents":[ { "_id" : 3}, { "_id" : 4}, { "_id" : 5}]}'); -- (1.3) update to 4 column collection SELECT documentdb_api.update('db', '{"update":"4col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); -- (1.4) aggregate to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); -- (1.5) aggregate to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$project" : {"a" : "GUC IS ENABLED"}},{"$merge" : { "into": "4col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "4col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); -- [2] let's test 3 column table after enabling GUC SELECT documentdb_api.create_collection('db', '3col'); \d documentdb_data.documents_293001 -- (2.1) insert to 3 column collection SELECT documentdb_api.insert_one('db', '3col', '{ "_id": 2}'); -- (2.2) multiple-insert to 3 column collection SELECT documentdb_api.insert('db', '{"insert":"3col", "documents":[ { "_id" : 3}, { "_id" : 4}, { "_id" : 5}]}'); -- (2.3) update to 3 column collection SELECT documentdb_api.update('db', '{"update":"3col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); -- (2.4) aggregate to 3 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$project" : {"a" : "GUC IS ENABLED"}},{"$merge" : { "into": "3col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); --3. let's disable GUC SET documentdb.enableDataTableWithoutCreationTime to off; -- (3.1) insert to 3 column collection SELECT documentdb_api.insert_one('db', '3col', '{ "_id": 200}'); -- (3.2) multiple-insert to 3 column collection SELECT documentdb_api.insert('db', '{"insert":"3col", "documents":[ { "_id" : 300}, { "_id" : 400}, { "_id" : 500}]}'); -- (3.3) update to 3 column collection SELECT documentdb_api.update('db', '{"update":"3col", "updates":[{"q":{"_id":{"$eq":1}},"u":[{"$set":{"a" : 1} }]}]}'); -- (3.4) aggregate to 3 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 1 } }', 4294967294); -- (3.5) $merge to 4 column collection SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$project" : {"a" : "GUC IS DISBALE"}},{"$merge" : { "into": "3col", "whenMatched" : "replace" , "whenNotMatched" : "insert" }} ] , "cursor": { "batchSize": 1 } }', 4294967294); SELECT * FROM aggregate_cursor_first_page('db', '{ "aggregate": "3col", "pipeline": [ {"$match" : {}} ] , "cursor": { "batchSize": 10 } }', 4294967294); -- lookup test -- create 4 column table for lookup SELECT documentdb_api.insert_one('db','three_column_data_table_from',' {"_id": 1, "col1": "Value1", "col2": ["item1", "item2"], "col3": 100 , "col4": ["item3", "item4"]}', NULL); SELECT documentdb_api.insert_one('db','three_column_data_table_from','{ "_id": 2, "col1": "Value2", "col2": ["item5", "item6"], "col3": 120, "col4": ["item7"]}', NULL); \d documentdb_data.documents_293002 -- now create table with 3 column SET documentdb.enableDataTableWithoutCreationTime to on; SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 1, "item": "item1", "ref_col": "Value1"}', NULL); SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 2, "item": "item5", "ref_col": "Value2", "extra_col": "extra1"}', NULL); SELECT documentdb_api.insert_one('db','three_column_data_table_to','{ "_id": 3, "item": "item5", "ref_col": "Value2", "extra_col": "item7"}', NULL); \d documentdb_data.documents_293003 SELECT document from bson_aggregation_pipeline('db', '{ "aggregate": "three_column_data_table_to", "pipeline": [ { "$lookup": { "from": "three_column_data_table_from", "pipeline": [ { "$match": { "col3": { "$gt": 110 } }}], "as": "matched_docs", "localField": "ref_col", "foreignField": "col1" }} ], "cursor": {} }'); users_libpq_permissioning.sql000066400000000000000000000045401507310017400350130ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path to documentdb_api_catalog; SET citus.next_shard_id TO 11980000; SET documentdb.next_collection_id TO 11980; SET documentdb.next_collection_index_id TO 11980; -- create new user with basic and insufficient permissions CREATE ROLE user_2 WITH LOGIN PASSWORD 'pass'; GRANT ALL PRIVILEGES ON SCHEMA documentdb_api_catalog TO user_2; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA documentdb_api_catalog TO user_2; GRANT SELECT ON ALL TABLES IN SCHEMA documentdb_data TO user_2; GRANT USAGE ON SCHEMA documentdb_data TO user_2; GRANT USAGE ON SCHEMA documentdb_api TO user_2; GRANT USAGE ON SCHEMA documentdb_api_internal TO user_2; -- create a collection SELECT documentdb_api.create_collection('db', 'test_coll'); -- insert some data SELECT documentdb_api.insert_one('db','test_coll','{"_id":"1", "a": { "$numberInt" : "11" }, "b": { "$numberInt" : "214748" }, "c": { "$numberInt" : "100" }}', NULL); SELECT documentdb_api.insert_one('db','test_coll','{"_id":"2", "a": { "$numberInt" : "16" }, "b": { "$numberInt" : "214740" }, "c": { "$numberInt" : "-22" }}', NULL); SELECT documentdb_api.insert_one('db','test_coll','{"_id":"3", "a": { "$numberInt" : "52" }, "b": { "$numberInt" : "121212" }, "c": { "$numberInt" : "101" }}', NULL); -- switch to the new user (user_2) SELECT current_user as original_user \gset ALTER TABLE documentdb_data.documents_11980 OWNER TO user_2; \c regression user_2 -- should fail index creation SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_coll", "indexes": [ { "key" : { "a": 1 }, "name": "index_a"}] }', true); -- switch back to default user \c regression :original_user ALTER TABLE documentdb_data.documents_11980 OWNER TO documentdb_admin_role; -- index creation should succeed SELECT documentdb_api_internal.create_indexes_non_concurrently('db', '{ "createIndexes": "test_coll", "indexes": [ { "key" : { "a": 1 }, "name": "index_a"}] }', true); -- revoke all privileges and drop role REVOKE ALL PRIVILEGES ON SCHEMA documentdb_api_catalog FROM user_2; REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA documentdb_api_catalog FROM user_2; REVOKE SELECT ON ALL TABLES IN SCHEMA documentdb_data FROM user_2; REVOKE USAGE ON SCHEMA documentdb_data FROM user_2; REVOKE USAGE ON SCHEMA documentdb_api FROM user_2; REVOKE USAGE ON SCHEMA documentdb_api_internal FROM user_2; DROP ROLE IF EXISTS user_2; write_commands_batching.sql000066400000000000000000000113251507310017400343660ustar00rootroot00000000000000documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/sqlSET search_path TO documentdb_core,documentdb_api,documentdb_api_catalog,documentdb_api_internal; SET citus.next_shard_id TO 662000; SET documentdb.next_collection_id TO 6620; SET documentdb.next_collection_index_id TO 6620; CREATE SCHEMA bulk_write; SELECT documentdb_api.create_collection('db', 'write_batching'); CREATE FUNCTION bulk_write.do_bulk_insert(numIterations int, ordered bool) RETURNS bson SET search_path TO documentdb_core,documentdb_api_catalog, pg_catalog AS $fn$ DECLARE v_insertSpec bson; v_resultDocs bson; BEGIN WITH r1 AS ( SELECT array_agg(FORMAT('{ "_id": %s, "a": %s}', g, g)::bson) AS "documents" FROM generate_series(1, numIterations) g), r2 AS (SELECT 'write_batching' AS "insert", r1.documents AS "documents", ordered AS "ordered" FROM r1) SELECT row_get_bson(r2) INTO v_insertSpec FROM r2; SELECT p_result INTO v_resultDocs FROM documentdb_api.insert('db', v_insertSpec); RETURN v_resultDocs; END; $fn$ LANGUAGE plpgsql; CREATE FUNCTION bulk_write.do_bulk_update(numIterations int, ordered bool) RETURNS bson SET search_path TO documentdb_core,documentdb_api_catalog, pg_catalog AS $fn$ DECLARE v_updateSpec bson; v_resultDocs bson; BEGIN WITH r1 AS ( SELECT array_agg(FORMAT('{ "q": { "_id": %s}, "u": { "$inc": { "a": 1 } } }', MOD(g, 10) + 1)::bson) AS "documents" FROM generate_series(1, numIterations) g), r2 AS (SELECT 'write_batching' AS "update", r1.documents AS "updates", ordered AS "ordered" FROM r1) SELECT row_get_bson(r2) INTO v_updateSpec FROM r2; SELECT p_result INTO v_resultDocs FROM documentdb_api.update('db', v_updateSpec); RETURN v_resultDocs; END; $fn$ LANGUAGE plpgsql; -- try a small amount. BEGIN; SELECT bulk_write.do_bulk_insert(10, false); ROLLBACK; -- try an extremely large batch (maxBatchSize) BEGIN; SELECT bulk_write.do_bulk_insert(25000, false); ROLLBACK; -- try an extremely large batch (maxBatchSize + 1 ) fails BEGIN; SELECT bulk_write.do_bulk_insert(25001, false); ROLLBACK; BEGIN; SELECT bulk_write.do_bulk_insert(25001, true); ROLLBACK; -- introduce a failure in the 432'th position (Everything before that succeeds) BEGIN; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 432, "a": 600 }'); SELECT bulk_write.do_bulk_insert(5000, true); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; -- introduce a failure in the 432'th position (Everything except that succeeds) BEGIN; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 432, "a": 600 }'); SELECT bulk_write.do_bulk_insert(5000, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); SELECT bulk_write.do_bulk_insert(35, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); SELECT bulk_write.do_bulk_insert(39, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); SELECT bulk_write.do_bulk_insert(40, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; BEGIN; set local documentdb.batchWriteSubTransactionCount TO 40; SELECT documentdb_api.insert_one('db', 'write_batching', '{ "_id": 31, "a": 600 }'); SELECT bulk_write.do_bulk_insert(41, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching'); ROLLBACK; -- now insert 10 docs and commit SELECT bulk_write.do_bulk_insert(10, false); -- do a small bulk update BEGIN; SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching') WHERE document->'_id' = document->'a'; SELECT bulk_write.do_bulk_update(10, false); SELECT COUNT(*) FROM documentdb_api.collection('db', 'write_batching') WHERE document->'_id' = document->'a'; ROLLBACK; BEGIN; SELECT bulk_write.do_bulk_update(10, true); ROLLBACK; BEGIN; -- do a large number (fail) SELECT bulk_write.do_bulk_update(25001, false); ROLLBACK; BEGIN; -- do a large number (fail) SELECT bulk_write.do_bulk_update(25001, true); ROLLBACK; BEGIN; -- do a large number SELECT bulk_write.do_bulk_update(10000, false); ROLLBACK; -- introduce an error in one document BEGIN; SELECT documentdb_api.update('db', '{ "update": "write_batching", "updates": [{ "q": { "_id": 5 }, "u": { "$set": { "a": "this is a string" } } }] }'); set local documentdb.batchWriteSubTransactionCount TO 40; SELECT bulk_write.do_bulk_update(50, false); ROLLBACK;documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/test_mutate_17000066400000000000000000000001701507310017400310370ustar00rootroot00000000000000s/bson_aggregation_date_operators_tests //g s/bson_aggregation_stage_inversematch_tests //g s/cursors_basic_support //g documentdb-0.108-0/internal/pg_documentdb_distributed/src/test/regress/validate_test_output.sh000077500000000000000000000305211507310017400330610ustar00rootroot00000000000000#!/bin/bash # fail if trying to reference a variable that is not set. set -u -e source="${BASH_SOURCE[0]}" diff=/usr/bin/diff pg_version=$1 while [[ -h $source ]]; do scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" source="$(readlink "$source")" # if $source was a relative symlink, we need to resolve it relative to the path where the # symlink file was located [[ $source != /* ]] && source="$scriptroot/$source" done scriptDir="$( cd -P "$( dirname "$source" )" && pwd )" # Validate index/runtime equivalence. for validationFileName in $(ls ./expected/*_tests_index.out); do runtimeFileName=${validationFileName/_tests_index.out/_tests_runtime.out}; $diff -s -I 'SELECT documentdb_api_internal.create_indexes' -I 'set local enable_seqscan' -I 'documentdb.next_collection_id' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' -I 'documentdb.enableGeospatial' \ $validationFileName $runtimeFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done # Validate new composite index test equivalence for validationFileName in $(ls ./expected/*_tests_index_composite.out); do runtimeFileName=${validationFileName/_tests_index_composite.out/_tests_runtime.out}; $diff -s -I 'SET documentdb.next_collection_id' -I 'SET documentdb.next_collection_index_id' -I 'SET citus.next_shard_id' -I 'SELECT documentdb_api.create_collection' -I 'set documentdb.forceDisableSeqScan' -I 'SELECT documentdb_api_internal.create_indexes' -I 'set local documentdb.enableNewCompositeIndexOpClass' -I 'set local enable_seqscan' -I 'documentdb.next_collection_id' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' -I 'documentdb.enableGeospatial' \ $validationFileName $runtimeFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done for validationFileName in $(ls ./expected/*_tests_index_comp_desc.out); do runtimeFileName=${validationFileName/_tests_index_comp_desc.out/_tests_runtime.out}; $diff -s -I 'SET documentdb.next_collection_id' -I 'documentdb.enableDescendingCompositeIndex' -I 'SET documentdb.next_collection_index_id' -I 'SET citus.next_shard_id' -I 'SELECT documentdb_api.create_collection' -I 'set documentdb.forceDisableSeqScan' -I 'SELECT documentdb_api_internal.create_indexes' -I 'set local documentdb.enableNewCompositeIndexOpClass' -I 'set local enable_seqscan' -I 'documentdb.next_collection_id' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' -I 'documentdb.enableGeospatial' \ $validationFileName $runtimeFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done for validationFileName in $(ls ./expected/*_tests_index_comp_unique.out); do runtimeFileName=${validationFileName/_tests_index_comp_unique.out/_tests_runtime.out}; $diff -s -I 'SET documentdb.next_collection_id' -I 'documentdb.enableDescendingCompositeIndex' -I 'SET documentdb.next_collection_index_id' -I 'SET citus.next_shard_id' -I 'SELECT documentdb_api.create_collection' -I 'set documentdb.forceDisableSeqScan' -I 'SELECT documentdb_api_internal.create_indexes' -I 'set local documentdb.enableNewCompositeIndexOpClass' -I 'set local enable_seqscan' -I 'documentdb.next_collection_id' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' -I 'documentdb.enableGeospatial' \ $validationFileName $runtimeFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done # Validate index_backcompat/index equivalence. for validationFileName in $(ls ./expected/*_tests_index_backcompat.out); do indexFileName=${validationFileName/_tests_index_backcompat.out/_tests_index.out}; $diff -s -I '\set' -I 'set local enable_seqscan' -I 'documentdb.next_collection_id' -I 'citus.next_shard_id' -I 'set documentdb.next_collection_index_id' -I 'set local documentdb.enableGenerateNonExistsTerm' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' \ $validationFileName $indexFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done # Validate index (NoBitMap)/runtime equivalence. for validationFileName in $(ls ./expected/*_tests_index_no_bitmap.out); do regularIndexFileName=${validationFileName/_tests_index_no_bitmap.out$/_tests_index.out}; $diff -s -I 'set local enable_seqscan' -I 'set local enable_bitmapscan' -I 'set local documentdb.forceUseIndexIfAvailable' -I 'set local citus.enable_local_execution' -I '\\set' -I 'set enable_seqscan' -I 'set documentdb.forceUseIndexIfAvailable' \ $validationFileName $regularIndexFileName; if [ $? -ne 0 ]; then echo "Validation failed on '${validationFileName}' against '${runtimeFileName}' error code $?"; exit 1; fi; done # Validate entry has documentdb_api's set next collection id. # These are baselined - will be cleaned up in a subsequent change. aggregateCollectionIdStr="" aggregateShardIdStr="" maxCollectionIdStr="" validationExceptions="/sql/documentdb_distributed_test_helpers.sql,/sql/public_api_schema.sql,/sql/documentdb_distributed_setup.sql" skippedDuplicateCheckFile="" echo "Validating test file output" for validationFile in $(ls $scriptDir/expected/*.out); do fileName=$(basename $validationFile); fileNameBase="${fileName%.out}"; sqlFile="${fileName%.out}.sql"; sqlExceptionStr="/sql/$sqlFile" has_invalid_results=$(grep -E "No function matches the given name and argument types." $validationFile || true) if [ "$has_invalid_results" != "" ]; then if [ "$fileName" == "bson_deduplicate.out" ]; then echo "Skipping $fileName" else echo "test file $validationFile has invalid function specification: '$has_invalid_results'"; exit 1 fi fi # skip isolation test for now if [[ $fileName == isolation* ]]; then continue; fi; if [[ $validationExceptions =~ $sqlExceptionStr ]]; then continue; fi; # check if the base file is in the schedule findResult="" for macro in "" "!PG16_OR_HIGHER!" "!PG17_OR_HIGHER!"; do fileNameMod=$(echo "$fileNameBase" | sed -E "s/_tests/${macro}_tests/g") findResult=$(grep "$fileNameMod" basic_schedule_core || true) [ -n "$findResult" ] && break done if [ "$findResult" == "" ]; then if [[ "$fileNameBase" =~ "pg15" ]] || [[ "$fileNameBase" =~ "pg16" ]] || [[ "$fileNameBase" =~ "pg17" ]] || [[ "$fileNameBase" =~ "_explain" ]]; then echo "Skipping schedule existence check for $fileNameBase" else echo "Test file '$validationFile' with name '$fileNameBase' or '$fileNameMod' is not in the schedule, please add it to the schedule"; exit 1; fi fi # Extract the actual collection ID (we'll use this to check for uniqueness). collectionIdOutput=$(grep -m 1 'documentdb.next_collection_id' $validationFile || true) # Fail if not found. if [ "$collectionIdOutput" == "" ]; then echo "Test file prefix Validation failed on '${sqlFile}': Please ensure test files set documentdb.next_collection_id"; exit 1; fi; # Get the actual collection ID. collectionIdOutput=${collectionIdOutput/SET documentdb.next_collection_id TO/}; collectionIdOutput=${collectionIdOutput/[\s|;]/}; # Allow skipping unique checks skipUniqueCheck="false" if [[ "$sqlFile" =~ "tests_runtime.sql" ]] || [[ "$sqlFile" =~ "explain_index_composite" ]] || [[ "$sqlFile" =~ "explain_index_comp_desc.sql" ]] || [[ "$sqlFile" =~ "tests_index_no_bitmap.sql" ]] || [[ "$sqlFile" =~ "tests_index.sql" ]] || [[ "$sqlFile" =~ "tests_index_backcompat.sql" ]] || [[ "$sqlFile" =~ "tests_pg17_explain" ]] || [[ "$sqlFile" =~ "tests_explain_index.sql" ]] || [[ "$sqlFile" =~ "tests_explain_index_no_bitmap.sql" ]]; then skippedDuplicateCheckFile="$skippedDuplicateCheckFile $sqlFile" skipUniqueCheck="true" elif [[ "$sqlFile" =~ _pg[0-9]+ ]]; then echo "Skipping duplicate collectionId check for $sqlFile" skippedDuplicateCheckFile="$skippedDuplicateCheckFile $sqlFile" skipUniqueCheck="true" elif [[ "$aggregateCollectionIdStr" =~ ":$collectionIdOutput:" ]]; then echo "Duplicate CollectionId used in '$sqlFile' - please use unique collection Ids across tests: $collectionIdOutput. Current max: $maxCollectionIdStr"; exit 1; else # Add it to the collection IDs being tracked. aggregateCollectionIdStr="$aggregateCollectionIdStr :$collectionIdOutput:" fi if ! [[ ":$collectionIdOutput:" =~ "0:" ]]; then echo "CollectionId used in '$sqlFile' must be a multiple of 10: " $collectionIdOutput; exit 1; fi if [[ "$maxCollectionIdStr" == "" ]]; then maxCollectionIdStr=$collectionIdOutput; elif [ $collectionIdOutput -gt $maxCollectionIdStr ]; then maxCollectionIdStr=$collectionIdOutput; fi # See if the index id is also set. collectionIndexIdOutput=$(grep -m 1 'documentdb.next_collection_index_id' $validationFile || true) if [ "$collectionIndexIdOutput" == "" ]; then echo "Test file '${sqlFile}' does not set next_collection_index_id: consider setting documentdb.next_collection_index_id"; exit 1; fi; collectionIndexIdOutput=${collectionIndexIdOutput/SET documentdb.next_collection_index_id TO/}; collectionIndexIdOutput=${collectionIndexIdOutput/[\s|;]/}; if [ "$collectionIndexIdOutput" != "$collectionIdOutput" ]; then echo "CollectionId and CollectionIndexId used in '$sqlFile' must match. CollectionId: $collectionIdOutput, CollectionIndexId: $collectionIndexIdOutput"; exit 1; fi # Validate citus.next_shard_id. nextShardIdOutput=$(grep 'citus.next_shard_id' $validationFile || true) if [ "$nextShardIdOutput" == "" ]; then echo "Test file '${sqlFile}' does not set citus.next_shard_id: consider setting citus.next_shard_id"; exit 1; fi; nextShardIdOutput=${nextShardIdOutput/SET citus.next_shard_id TO/}; nextShardIdOutput=${nextShardIdOutput/[\s|;]/}; if ! [[ ":$nextShardIdOutput:" =~ ":${collectionIdOutput}0" ]]; then echo "citus.next_shard_id should be a multiple of CollectionId in '$sqlFile': CollectionId: $collectionIdOutput, shard_id: $nextShardIdOutput"; exit 1; fi # Add it to the shard IDs being tracked. if [[ "$skipUniqueCheck" == "true" ]]; then # do nothing continue; elif [[ "$aggregateShardIdStr" =~ ":$nextShardIdOutput:" ]]; then echo "Duplicate shard_id used in '$sqlFile' - please use unique shard ids across tests: " $nextShardIdOutput; exit 1; else aggregateShardIdStr="$aggregateShardIdStr :$nextShardIdOutput:" fi done # Now validate for every sql file there's an .out file unless excluded for sqlFile in $(ls $scriptDir/sql/*.sql); do fileName=$(basename $sqlFile); fileNameBase="${fileName%.sql}"; outFile="$scriptDir/expected/$fileNameBase.out"; if [[ "$fileName" =~ "_core.sql" ]] || [[ "$fileName" == "bson_query_operator_tests_insert.sql" ]]; then echo "Skipping sql to out file validation on $fileName"; continue; fi if [ ! -f "$outFile" ]; then echo "Test file '$sqlFile' does not have a corresponding expected output file '$outFile'. Please add to the schedule file and run tests."; exit 1; fi done echo "Skipped duplicate checks on $skippedDuplicateCheckFile" echo "Validation checks done."documentdb-0.108-0/licenses/000077500000000000000000000000001507310017400156065ustar00rootroot00000000000000documentdb-0.108-0/licenses/LICENSE-CRoaring000066400000000000000000000305001507310017400203130ustar00rootroot00000000000000The CRoaring project is under a dual license (Apache/MIT). Users of the library may choose one or the other license. ------------------ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2016-2022 The CRoaring authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------- MIT License Copyright 2016-2022 The CRoaring authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.documentdb-0.108-0/licenses/LICENSE-Intelrdfpmath000066400000000000000000000027701507310017400214200ustar00rootroot00000000000000Copyright (c) 2007-2024, Intel Corp. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. documentdb-0.108-0/licenses/LICENSE-PCRE2000066400000000000000000000066251507310017400174350ustar00rootroot00000000000000PCRE2 LICENCE ------------- PCRE2 is a library of functions to support regular expressions whose syntax and semantics are as close as possible to those of the Perl 5 language. Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD" licence, as specified below, with one exemption for certain binary redistributions. The documentation for PCRE2, supplied in the "doc" directory, is distributed under the same terms as the software itself. The data in the testdata directory is not copyrighted and is in the public domain. The basic library functions are written in C and are freestanding. Also included in the distribution is a just-in-time compiler that can be used to optimize pattern matching. This is an optional feature that can be omitted when the library is built. THE BASIC LIBRARY FUNCTIONS --------------------------- Written by: Philip Hazel Email local part: Philip.Hazel Email domain: gmail.com Retired from University of Cambridge Computing Service, Cambridge, England. Copyright (c) 1997-2022 University of Cambridge All rights reserved. PCRE2 JUST-IN-TIME COMPILATION SUPPORT -------------------------------------- Written by: Zoltan Herczeg Email local part: hzmester Email domain: freemail.hu Copyright(c) 2010-2022 Zoltan Herczeg All rights reserved. STACK-LESS JUST-IN-TIME COMPILER -------------------------------- Written by: Zoltan Herczeg Email local part: hzmester Email domain: freemail.hu Copyright(c) 2009-2022 Zoltan Herczeg All rights reserved. THE "BSD" LICENCE ----------------- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notices, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notices, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of Cambridge nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES ------------------------------------------ The second condition in the BSD licence (covering binary redistributions) does not apply all the way down a chain of software. If binary package A includes PCRE2, it must respect the condition, but if package B is software that includes package A, the condition is not imposed on package B unless it uses PCRE2 independently. End documentdb-0.108-0/licenses/LICENSE-libbson000066400000000000000000000452111507310017400202440ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND conditions The MongoDB C Driver uses third-party code distributed under different licenses. License notice for uthash ------------------------------------------------------------------------------- Copyright (c) 2003-2021, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License notice for common-b64.c ------------------------------------------------------------------------------- ISC License Copyright: 1996, 1998 Internet Software Consortium 1995 International Business Machines, Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Portions Copyright (c) 1995 by International Business Machines, Inc. International Business Machines, Inc. (hereinafter called IBM) grants permission under its copyrights to use, copy, modify, and distribute this Software with or without fee, provided that the above copyright notice and all paragraphs of this notice appear in all copies, and that the name of IBM not be used in connection with the marketing of any product incorporating the Software or modifications thereof, without specific, written prior permission. To the extent it has a right to do so, IBM grants an immunity from suit under its patents, if any, for the use, sale or manufacture of products to the extent that such products are used for performing Domain Name System dynamic updates in TCP/IP networks by means of the Software. No immunity is granted for any product per se or for any other function of any product. THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. License notice for mongoc.css_t ------------------------------------------------------------------------------- MIT License Portions Copyright 2013 by Ignacy Sokolowski. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License notice for zlib ------------------------------------------------------------------------------- /* zlib.h -- interface of the 'zlib' general purpose compression library version 1.2.11, January 15th, 2017 Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Jean-loup Gailly Mark Adler jloup@gzip.org madler@alumni.caltech.edu The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). */ License notice for common-md5.c ------------------------------------------------------------------------------- ZLib License Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. L. Peter Deutsch ghost@aladdin.com License notice for utf8proc ------------------------------------------------------------------------------- **utf8proc** is a software package originally developed by Jan Behrens and the rest of the Public Software Group, who deserve nearly all of the credit for this library, that is now maintained by the Julia-language developers. Like the original utf8proc, whose copyright and license statements are reproduced below, all new work on the utf8proc library is licensed under the [MIT "expat" license](http://opensource.org/licenses/MIT): *Copyright © 2014-2021 by Steven G. Johnson, Jiahao Chen, Tony Kelman, Jonas Fonseca, and other contributors listed in the git history.* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.documentdb-0.108-0/licenses/LICENSE-postgis000066400000000000000000000157001507310017400203040ustar00rootroot00000000000000PostGIS Licensing ================== This file attempts to include all licenses that apply within the PostGIS source tree, in particular any that are supposed to be exposed to the end user for credit requirements for instance. PostGIS General ---------------- In general PostGIS may be distributed and/or modified under the conditions of the GNU General Public License, either version 2 or (at your option) any later version. Please refer to the COPYING file for details. PostGIS has dependencies on other libraries which are not under GPL and that are commonly distributed with PostGIS core libraries. In general these are dynamically linked libraries. Libraries are as follows: Proj4 - http://proj.osgeo.org -- X/MIT License GEOS - http://geos.osgeo.org -- LGPL License LibXML - http://xmlsoft.org/ -- X/MIT License GDAL - http://gdal.osgeo.org/ -- X/MIT Style License Source files included with PostGIS not under GPL ------------------------------------------------ -- The following loader/dumper files are derivative works or direct ports of ShapeLib which is under an X/MIT License: loader/dbfopen, safileio.*, shapefil.h, shpopen.c (copyrighted by Frank Warmerdam and Even Rouault). -- loader/getopt.* are under AT&T public domain (Copyright (c) 1984, 1985 AT&T). -- Doc/xsl files These are under a BSD Style license -- liblwgeom/lookup3.c is released under Public Domain by Bob Jenkins, May 2006. -- deps/ryu (see LICENSE in folder) is released under the Apache 2.0 license; alternatively, in can be used under the Boost 1.0 license. Copyrighted by Ulf Adams and contributors. -- deps/uthash (see LICENSE in folder) is released under a simplified BSD license. Copyright (c) 2005-2018, Troy D. Hanson. -- deps/wagyu (see LICENSE.README in folder) includes code released under the ISC license (copyrighted by Mapbox) and the Boost Software License (copyrighted by Angus Johnson and Mapbox). Copyright for "almost_equal.hpp" file is held by Google Inc and its license is listed at the top of that file. The documentation for PostGIS is under a creative commons share-alike 3.0 license. http://creativecommons.org/licenses/by-sa/3.0/ Data used in documentation falls in one of the following categories - Many of the examples in the topology and tiger geocoder section utilize data from US Census Tiger data 2010 http://www.census.gov/geo/www/tiger/tgrshp2010/tgrshp2010.html - data or snapshots generated by community - many images autogenerated by PostGIS documentation generator (which utilizes ImageMagick) as described http://trac.osgeo.org/postgis/wiki/DevWikiDocNewFeature - PostGIS raster output functions such as the ST_AsPNG etc. - raster/vector data from MassGIS: http://www.mass.gov/mgis/laylist.htm License notice for ryu ------------------------------------------------------------------------------- All the C code is copyrighted by Ulf Adams and contributors, and may be used freely in accordance with the Apache 2.0 license. Alternatively, it may be used freely in accordance with the Boost 1.0 license. License notice for uthash ------------------------------------------------------------------------------- Copyright (c) 2005-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License notice for geometry ------------------------------------------------------------------------------- Copyright (c) 2016, Mapbox Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. License notice for wagyu ------------------------------------------------------------------------------- Parts of the code in the Wagyu Library are derived from the version of the Clipper Library by Angus Johnson listed below. Author : Angus Johnson Version : 6.4.0 Date : 2 July 2015 Website : http://www.angusj.com Copyright for portions of the derived code in the Wagyu library are held by Angus Johnson, 2010-2015. All other copyright for the Wagyu Library are held by Mapbox, 2016. This code is published in accordance with, and retains the same license as the Clipper Library by Angus Johnson. Copyright (c) 2010-2015, Angus Johnson Copyright (c) 2016, Mapbox Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. documentdb-0.108-0/licenses/LICENSE-postgreSQL000066400000000000000000000022551507310017400206600ustar00rootroot00000000000000PostgreSQL Database Management System (also known as Postgres, formerly known as Postgres95) Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group Portions Copyright (c) 1994, The Regents of the University of California Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.documentdb-0.108-0/licenses/LICENSE-rum000066400000000000000000000023331507310017400174150ustar00rootroot00000000000000RUM is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses. Portions Copyright (c) 2015-2024, Postgres Professional Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group Portions Copyright (c) 1994, The Regents of the University of California Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.documentdb-0.108-0/licenses/LICENSE_Apache-2.0000066400000000000000000000260741507310017400203620ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.documentdb-0.108-0/mkdocs.yml000066400000000000000000000005421507310017400160050ustar00rootroot00000000000000site_name: DocumentDB repo_url: https://github.com/microsoft/documentdb theme: name: readthedocs nav: - Version 1.0: - Get Started: v1/index.md - Introduction: v1/documentdb.md - Prebuild Images: v1/prebuild.md - Gateway: v1/gateway.md plugins: - search markdown_extensions: - admonition - toc: permalink: true documentdb-0.108-0/packaging/000077500000000000000000000000001507310017400157255ustar00rootroot00000000000000documentdb-0.108-0/packaging/README.md000077500000000000000000000030301507310017400172030ustar00rootroot00000000000000# To Build Your Own Packages With Docker ## Building Debian/Ubuntu Packages Run `./packaging/build_packages.sh -h` and follow the instructions. E.g. to build for Debian 12 and PostgreSQL 16, run: ```sh ./packaging/build_packages.sh --os deb12 --pg 16 ``` Supported DEB/Ubuntu distributions: - deb11 — Debian 11 (bullseye) - deb12 — Debian 12 (bookworm) - deb13 — Debian 13 (trixie) - ubuntu22.04 — Ubuntu 22.04 (jammy) - ubuntu24.04 — Ubuntu 24.04 (noble) Supported PG versions: 15, 16, 17 ## Building RPM Packages For Red Hat-based distributions, you can build RPM packages: ```sh ./packaging/build_packages.sh --os rhel8 --pg 17 ``` Supported RPM distributions: - rhel8 (Red Hat Enterprise Linux 8 compatible) - rhel9 (Red Hat Enterprise Linux 9 compatible) Supported PG versions: 15, 16, 17 ### RPM Build Prerequisites [Optional] Before building RPM packages, you can validate your environment: ```sh ./packaging/validate_rpm_build.sh ``` This script checks: - Docker installation and availability - Network connectivity for package repositories - Access to required base images ### Example RPM Build Commands ```sh # Build for RHEL 9 with PostgreSQL 16 ./packaging/build_packages.sh --os rhel9 --pg 16 # Build with testing enabled ./packaging/build_packages.sh --os rhel8 --pg 17 --test-clean-install ``` ## Output Packages can be found at the `packages` directory by default, but it can be configured with the `--output-dir` option. **Note:** The packages do not include pg_documentdb_distributed in the `internal` directory.documentdb-0.108-0/packaging/build_packages.sh000077500000000000000000000176431507310017400212340ustar00rootroot00000000000000#!/bin/bash set -euo pipefail # Function to display help message function show_help { echo "Usage: $0 --os --pg [--test-clean-install] [--output-dir ] [-h|--help]" echo "" echo "Description:" echo " This script builds extension packages (DEB/RPM) using Docker." echo "" echo "Mandatory Arguments:" echo " --os OS to build packages for. Possible values: [deb11, deb12, ubuntu22.04, ubuntu24.04, rhel8, rhel9]" echo " --pg PG version to build packages for. Possible values: [15, 16, 17]" echo "" echo "Optional Arguments:" echo " --version The version of documentdb to build. Examples: [0.100.0, 0.101.0]" echo " --test-clean-install Test installing the packages in a clean Docker container." echo " --output-dir Relative path from the repo root of the directory where to drop the packages. The directory will be created if it doesn't exist. Default: packaging" echo " -h, --help Display this help message." exit 0 } # Initialize variables OS="" PG="" DOCUMENTDB_VERSION="" TEST_CLEAN_INSTALL=false OUTPUT_DIR="packaging" # Default value for output directory PACKAGE_TYPE="" # Will be set to "deb" or "rpm" # Process arguments to convert long options to short ones while [[ $# -gt 0 ]]; do case "$1" in --os) shift case $1 in deb11|deb12|deb13|ubuntu22.04|ubuntu24.04) OS=$1 PACKAGE_TYPE="deb" ;; rhel8|rhel9) OS=$1 PACKAGE_TYPE="rpm" ;; *) echo "Invalid --os value. Allowed values are [deb11, deb12, ubuntu22.04, ubuntu24.04, rhel8, rhel9]" exit 1 ;; esac ;; --pg) shift case $1 in 15|16|17) PG=$1 ;; *) echo "Invalid --pg value. Allowed values are [15, 16, 17]" exit 1 ;; esac ;; --version) shift DOCUMENTDB_VERSION=$1 ;; --test-clean-install) TEST_CLEAN_INSTALL=true ;; --output-dir) shift OUTPUT_DIR=$1 ;; -h|--help) show_help ;; *) echo "Unknown argument: $1" show_help exit 1 ;; esac shift done # Check mandatory arguments if [[ -z "$OS" ]]; then echo "Error: --os is required." show_help exit 1 fi if [[ -z "$PG" ]]; then echo "Error: --pg is required." show_help exit 1 fi # get the version from control file if [[ -z "$DOCUMENTDB_VERSION" ]]; then DOCUMENTDB_VERSION=$(grep -E "^default_version" pg_documentdb_core/documentdb_core.control | sed -E "s/.*'([0-9]+\.[0-9]+-[0-9]+)'.*/\1/") DOCUMENTDB_VERSION=$(echo $DOCUMENTDB_VERSION | sed "s/-/./g") echo "DOCUMENTDB_VERSION extracted from control file: $DOCUMENTDB_VERSION" if [[ -z "$DOCUMENTDB_VERSION" ]]; then echo "Error: --version is required and could not be found in the control file." show_help exit 1 fi fi # Set the appropriate Docker image and configuration based on the OS DOCKERFILE="" OS_VERSION_NUMBER="" if [[ "$PACKAGE_TYPE" == "deb" ]]; then DOCKERFILE="packaging/deb/Dockerfile" case $OS in deb11) DOCKER_IMAGE="debian:bullseye" ;; deb12) DOCKER_IMAGE="debian:bookworm" ;; deb13) DOCKER_IMAGE="debian:trixie" ;; ubuntu22.04) DOCKER_IMAGE="ubuntu:22.04" ;; ubuntu24.04) DOCKER_IMAGE="ubuntu:24.04" ;; esac elif [[ "$PACKAGE_TYPE" == "rpm" ]]; then case $OS in rhel8) DOCKERFILE="packaging/rpm/rhel-8/Dockerfile" DOCKER_IMAGE="rockylinux:8" ;; rhel9) DOCKERFILE="packaging/rpm/rhel-9/Dockerfile" DOCKER_IMAGE="rockylinux:9" ;; *) echo "Error: Invalid OS specified for RPM build: $OS" exit 1 ;; esac fi TAG=documentdb-build-packages-$OS-pg$PG:latest repo_root=$(git rev-parse --show-toplevel) abs_output_dir="$repo_root/$OUTPUT_DIR" cd "$repo_root" echo "Building $PACKAGE_TYPE packages for OS: $OS, PostgreSQL version: $PG, DOCUMENTDB version: $DOCUMENTDB_VERSION" echo "Output directory: $abs_output_dir" # Create the output directory if it doesn't exist mkdir -p "$abs_output_dir" # Build the Docker image while showing the output to the console if [[ "$PACKAGE_TYPE" == "deb" ]]; then docker build -t "$TAG" -f "$DOCKERFILE" \ --build-arg BASE_IMAGE="$DOCKER_IMAGE" \ --build-arg POSTGRES_VERSION="$PG" \ --build-arg DOCUMENTDB_VERSION="$DOCUMENTDB_VERSION" . # Run the Docker container to build the packages docker run --rm --env OS="$OS" --env POSTGRES_VERSION="$PG" --env DOCUMENTDB_VERSION="$DOCUMENTDB_VERSION" -v "$abs_output_dir:/output" "$TAG" elif [[ "$PACKAGE_TYPE" == "rpm" ]]; then docker build -t "$TAG" -f "$DOCKERFILE" \ --build-arg BASE_IMAGE="$DOCKER_IMAGE" \ --build-arg POSTGRES_VERSION="$PG" \ --build-arg DOCUMENTDB_VERSION="$DOCUMENTDB_VERSION" . # Run the Docker container to build the packages docker run --rm --env OS="$OS" --env POSTGRES_VERSION="$PG" --env DOCUMENTDB_VERSION="$DOCUMENTDB_VERSION" -v "$abs_output_dir:/output" "$TAG" fi echo "Packages built successfully!!" if [[ $TEST_CLEAN_INSTALL == true ]]; then echo "Testing clean installation in a Docker container..." if [[ "$PACKAGE_TYPE" == "deb" ]]; then deb_package_name=$(ls "$abs_output_dir" | grep -E "${OS}-postgresql-$PG-documentdb_${DOCUMENTDB_VERSION}.*\.deb" | grep -v "dbg" | head -n 1) deb_package_rel_path="$OUTPUT_DIR/$deb_package_name" echo "Debian package path: $deb_package_rel_path" # Build the Docker image while showing the output to the console docker build -t documentdb-test-packages:latest -f packaging/test_packages/deb/Dockerfile \ --build-arg BASE_IMAGE="$DOCKER_IMAGE" \ --build-arg POSTGRES_VERSION="$PG" \ --build-arg DEB_PACKAGE_REL_PATH="$deb_package_rel_path" . # Run the Docker container to test the packages docker run --rm documentdb-test-packages:latest elif [[ "$PACKAGE_TYPE" == "rpm" ]]; then rpm_package_name=$(ls "$abs_output_dir" | grep -E "${OS}-postgresql${PG}-documentdb-${DOCUMENTDB_VERSION}.*\.(x86_64|aarch64)\.rpm" | head -n 1) if [[ -z "$rpm_package_name" ]]; then echo "Error: Could not find the built RPM package in $abs_output_dir for testing." exit 1 fi package_rel_path="$OUTPUT_DIR/$rpm_package_name" echo "RPM package path for testing: $package_rel_path" # Select the correct test Dockerfile for RHEL 8 or RHEL 9 if [[ "$OS" == "rhel8" ]]; then TEST_DOCKERFILE="packaging/test_packages/rhel-8/Dockerfile" elif [[ "$OS" == "rhel9" ]]; then TEST_DOCKERFILE="packaging/test_packages/rhel-9/Dockerfile" else echo "Error: Unknown RPM OS for test Dockerfile: $OS" exit 1 fi docker build -t documentdb-test-rpm-packages:latest -f "$TEST_DOCKERFILE" \ --build-arg BASE_IMAGE="$DOCKER_IMAGE" \ --build-arg POSTGRES_VERSION="$PG" \ --build-arg RPM_PACKAGE_REL_PATH="$package_rel_path" . # Run the Docker container to test the packages docker run --rm --env POSTGRES_VERSION="$PG" documentdb-test-rpm-packages:latest fi echo "Clean installation test successful!!" fi echo "Packages are available in $abs_output_dir"documentdb-0.108-0/packaging/deb/000077500000000000000000000000001507310017400164575ustar00rootroot00000000000000documentdb-0.108-0/packaging/deb/Dockerfile000077500000000000000000000044121507310017400204550ustar00rootroot00000000000000ARG BASE_IMAGE=debian:trixie FROM ${BASE_IMAGE} ARG DEBIAN_FRONTEND=noninteractive ARG POSTGRES_VERSION=16 ARG DOCUMENTDB_VERSION RUN test -n "$DOCUMENTDB_VERSION" || (echo "DOCUMENTDB_VERSION not set" && false) RUN apt-get update RUN apt-get install -y --no-install-recommends \ wget \ gnupg2 \ lsb-release \ ca-certificates \ locales \ python3 RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 ENV LANGUAGE=en_US ENV LC_COLLATE=en_US.UTF-8 ENV LC_CTYPE=en_US.UTF-8 ENV LANG=en_US.UTF-8 RUN echo "deb [signed-by=/usr/share/keyrings/pgdg-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main ${POSTGRES_VERSION}" > /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /usr/share/keyrings/pgdg-archive-keyring.gpg RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ tzdata \ build-essential \ pkg-config \ cmake \ git \ postgresql-${POSTGRES_VERSION} \ postgresql-server-dev-${POSTGRES_VERSION} \ libpq-dev \ libicu-dev \ libkrb5-dev \ postgresql-${POSTGRES_VERSION}-cron \ postgresql-${POSTGRES_VERSION}-pgvector \ postgresql-${POSTGRES_VERSION}-postgis-3 \ postgresql-${POSTGRES_VERSION}-rum \ devscripts \ debhelper \ dpkg-dev \ && rm -rf /var/lib/apt/lists/* COPY scripts /tmp/install_setup RUN export CLEAN_SETUP=1 && \ export INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup && \ MAKE_PROGRAM=cmake /tmp/install_setup/install_setup_libbson.sh && \ /tmp/install_setup/install_setup_pcre2.sh && \ /tmp/install_setup/install_setup_intel_decimal_math_lib.sh && \ /tmp/install_setup/install_citus_indent.sh # Set the working directory inside the container WORKDIR /build # Copy the source code into the container COPY . /build # Setup the debian packaging COPY packaging/deb/common /build/debian RUN sed -i "s/POSTGRES_VERSION/${POSTGRES_VERSION}/g" /build/debian/control RUN sed -i "s/DOCUMENTDB_VERSION/${DOCUMENTDB_VERSION}/g" /build/debian/changelog COPY packaging/deb/packaging-entrypoint.sh /usr/local/bin/packaging-entrypoint.sh # Set the entrypoint ENTRYPOINT ["packaging-entrypoint.sh"] documentdb-0.108-0/packaging/deb/common/000077500000000000000000000000001507310017400177475ustar00rootroot00000000000000documentdb-0.108-0/packaging/deb/common/changelog000077500000000000000000000122441507310017400216270ustar00rootroot00000000000000documentdb (0.106-0) unstable; urgency=medium * Add internal extension that provides extensions to the `rum` index. *[Feature]* * Enable let support for update queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Enable let support for findAndModify queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Add internal extension that provides extensions to the `rum` index. *[Feature]* * Optimized query for `usersInfo` command. * Support collation with `delete` *[Feature]*. Requires `EnableCollation` to be `on`. * Support for index hints for find/aggregate/count/distinct *[Feature]* * Support `createRole` command *[Feature]* * Add schema changes for Role CRUD APIs *[Feature]* * Add support for using EntraId tokens via Plain Auth -- Shuai Tian Fri, Mon, 29 August 2025 12:00:00 +0000 documentdb (0.105-0) unstable; urgency=medium * Support `$bucketAuto` aggregation stage, with granularity types: `POWERSOF2`, `1-2-5`, `R5`, `R10`, `R20`, `R40`, `R80`, `E6`, `E12`, `E24`, `E48`, `E96`, `E192` *[Feature]* * Support `conectionStatus` command *[Feature]*. -- Shuai Tian Mon, 28 Jul 2025 12:00:00 +0000 documentdb (0.104-0) unstable; urgency=medium * Add string case support for `$toDate` operator * Support `sort` with collation in runtime*[Feature]* * Support collation with `$indexOfArray` aggregation operator. *[Feature]* * Support collation with arrays and objects comparisons *[Feature]* * Support background index builds *[Bugfix]* (#36) * Enable user CRUD by default *[Feature]* * Enable let support for delete queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. * Enable rum_enable_index_scan as default on *[Perf]* * Add public `documentdb-local` Docker image with gateway to GHCR * Support `compact` command *[Feature]*. Requires `documentdb.enablecompact` GUC to be `on`. * Enable role privileges for `usersInfo` command *[Feature]* -- Shuai Tian Mon, 09 Jun 2025 12:00:00 +0000 documentdb (0.103-0) unstable; urgency=medium * Support collation with aggregation and find on sharded collections *[Feature]* * Support `$convert` on `binData` to `binData`, `string` to `binData` and `binData` to `string` (except with `format: auto`) *[Feature]* * Fix list_databases for databases with size > 2 GB *[Bugfix]* (#119) * Support half-precision vector indexing, vectors can have up to 4,000 dimensions *[Feature]* * Support ARM64 architecture when building docker container *[Preview]* * Support collation with `$documents` and `$replaceWith` stage of the aggregation pipeline *[Feature]* * Push pg_documentdb_gw for documentdb connections *[Feature]* -- Shuai Tian Fri, 09 May 2025 12:00:00 +0000 documentdb (0.102-0) unstable; urgency=medium * Support index pushdown for vector search queries *[Bugfix]* * Support exact search for vector search queries *[Feature]* * Inline $match with let in $lookup pipelines as JOIN Filter *[Perf]* * Support TTL indexes *[Bugfix]* (#34) * Support joining between postgres and documentdb tables *[Feature]* (#61) * Support current_op command *[Feature]* (#59) * Support for list_databases command *[Feature]* (#45) * Disable analyze statistics for unique index uuid columns which improves resource usage *[Perf]* * Support collation with `$expr`, `$in`, `$cmp`, `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte` comparison operators (Opt-in) *[Feature]* * Support collation in `find`, aggregation `$project`, `$redact`, `$set`, `$addFields`, `$replaceRoot` stages (Opt-in) *[Feature]* * Support collation with `$setEquals`, `$setUnion`, `$setIntersection`, `$setDifference`, `$setIsSubset` in the aggregation pipeline (Opt-in) *[Feature]* * Support unique index truncation by default with new operator class *[Feature]* * Top level aggregate command `let` variables support for `$geoNear` stage *[Feature]* * Enable Backend Command support for Statement Timeout *[Feature]* * Support type aggregation operator `$toUUID`. *[Feature]* * Support Partial filter pushdown for `$in` predicates *[Perf]* * Support the $dateFromString operator with full functionality *[Feature]* * Support extended syntax for `$getField` aggregation operator. Now the value of 'field' could be an expression that resolves to a string. *[Feature]* -- Shuai Tian Wed, 26 Mar 2025 12:00:00 +0000 documentdb (0.101-0) unstable; urgency=medium * Push $graphlookup recursive CTE JOIN filters to index *[Perf]* * Build pg_documentdb for PostgreSQL 17 *[Infra]* (#13) * Enable support of currentOp aggregation stage, along with collstats, dbstats, and indexStats *[Commands]* (#52) * Allow inlining $unwind with $lookup with `preserveNullAndEmptyArrays` *[Perf]* * Skip loading documents if group expression is constant *[Perf]* * Fix Merge stage not outputing to target collection *[Bugfix]* (#20) -- Shuai Tian Wed, 12 Feb 2025 12:00:00 +0000 documentdb (0.100-0) unstable; urgency=medium * Initial Release -- Shuai Tian Thu, 23 Jan 2025 12:00:00 +0000 documentdb-0.108-0/packaging/deb/common/compat000077500000000000000000000000021507310017400211500ustar00rootroot0000000000000012documentdb-0.108-0/packaging/deb/common/control000077500000000000000000000013141507310017400213540ustar00rootroot00000000000000Source: documentdb Section: database Priority: optional Build-Depends: debhelper (>= 11), postgresql-server-dev-POSTGRES_VERSION Maintainer: Shuai Tian Package: postgresql-POSTGRES_VERSION-documentdb Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, postgresql-POSTGRES_VERSION, postgresql-POSTGRES_VERSION-cron, postgresql-POSTGRES_VERSION-pgvector, postgresql-POSTGRES_VERSION-postgis-3, postgresql-POSTGRES_VERSION-rum Description: DocumentDB is the open-source engine powering vCore-based Azure Cosmos DB for MongoDB. It offers a native implementation of document-oriented NoSQL database, enabling seamless CRUD operations on BSON data types within a PostgreSQL framework.documentdb-0.108-0/packaging/deb/common/rules000077500000000000000000000002671507310017400210340ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ override_dh_auto_test: make install adduser --disabled-password --gecos "" documentdb chown -R documentdb:documentdb . su documentdb -c "make check"documentdb-0.108-0/packaging/deb/packaging-entrypoint.sh000077500000000000000000000024241507310017400231550ustar00rootroot00000000000000#!/bin/bash set -e test -n "$OS" || (echo "OS not set" && false) # Change to the build directory cd /build # Update packaging changelogs from CHANGELOG.md (fail build if this fails) if [[ -n "${DOCUMENTDB_VERSION:-}" ]]; then echo "DOCUMENTDB_VERSION provided via environment: ${DOCUMENTDB_VERSION}" else DOCUMENTDB_VERSION=$(grep -E "^default_version" pg_documentdb_core/documentdb_core.control | sed -E "s/.*'([0-9]+\.[0-9]+-[0-9]+)'.*/\1/" || true) fi if [[ -n "$DOCUMENTDB_VERSION" ]]; then echo "Running changelog update for version: $DOCUMENTDB_VERSION" /bin/bash /build/packaging/update_spec_changelog.sh "$DOCUMENTDB_VERSION" else echo "WARNING: Could not determine documentdb version; skipping changelog update" exit 1 fi # Keep the internal directory out of the Debian package sed -i '/internal/d' Makefile # Build the Debian package debuild -us -uc # Change to the root to make file renaming expression simpler cd / # Rename .deb files to include the OS name prefix for f in *.deb; do mv $f $OS-$f; done # Create the output directory if it doesn't exist mkdir -p /output # Copy the built packages to the output directory cp *.deb /output/ # Change ownership of the output files to match the host user's UID and GID chown -R $(stat -c "%u:%g" /output) /outputdocumentdb-0.108-0/packaging/rpm/000077500000000000000000000000001507310017400165235ustar00rootroot00000000000000documentdb-0.108-0/packaging/rpm/packaging-entrypoint-rpm.sh000077500000000000000000000060521507310017400240160ustar00rootroot00000000000000#!/bin/bash set -e # Ensure required environment variables are set test -n "$OS" || (echo "OS not set" && false) test -n "$POSTGRES_VERSION" || (echo "POSTGRES_VERSION not set" && false) # Change to the build directory cd /build # Update packaging changelogs from CHANGELOG.md (fail build if this fails) if [[ -n "${DOCUMENTDB_VERSION:-}" ]]; then echo "DOCUMENTDB_VERSION provided via environment: ${DOCUMENTDB_VERSION}" else DOCUMENTDB_VERSION=$(grep -E "^default_version" pg_documentdb_core/documentdb_core.control | sed -E "s/.*'([0-9]+\.[0-9]+-[0-9]+)'.*/\1/" || true) fi if [[ -n "$DOCUMENTDB_VERSION" ]]; then echo "Running changelog update for version: $DOCUMENTDB_VERSION" /bin/bash /build/packaging/update_spec_changelog.sh "$DOCUMENTDB_VERSION" else echo "WARNING: Could not determine documentdb version; skipping changelog update" exit 1 fi # Remove 'internal' references from Makefile sed -i '/internal/d' Makefile # Create RPM build directories mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} # Get the package version from the spec file PACKAGE_VERSION=$(grep "^Version:" rpm/documentdb.spec | awk '{print $2}') # Construct the package name PACKAGE_NAME="postgresql${POSTGRES_VERSION}-documentdb" # Add PostgreSQL bin directory to PATH to ensure pg_config is found export PATH="/usr/pgsql-${POSTGRES_VERSION}/bin:$PATH" echo "Using PostgreSQL bin directory: $PATH" echo "Package name: $PACKAGE_NAME" echo "Package version: $PACKAGE_VERSION" echo "PostgreSQL version: $POSTGRES_VERSION" # Copy spec file to the SPECS directory cp rpm/documentdb.spec ~/rpmbuild/SPECS/ # Prepare the source directory SOURCE_DIR="/tmp/${PACKAGE_NAME}-${PACKAGE_VERSION}" mkdir -p "$SOURCE_DIR" # Copy source files into the source directory # Adjust this as needed to include all necessary files cp -r /build/* "$SOURCE_DIR/" # Create the source tarball echo "Creating tarball: ~/rpmbuild/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz" tar -czf ~/rpmbuild/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz -C /tmp "${PACKAGE_NAME}-${PACKAGE_VERSION}" # Build the RPM package rpmbuild -ba ~/rpmbuild/SPECS/documentdb.spec # Rename and copy RPMs to the output directory mkdir -p /output if [ -n "${ARCH}" ]; then RPM_ARCH=${ARCH} else UNAME_ARCH=$(uname -m) case "${UNAME_ARCH}" in aarch64|arm64) RPM_ARCH=aarch64 ;; x86_64|amd64) RPM_ARCH=x86_64 ;; *) echo "Unknown runtime arch: ${UNAME_ARCH}, defaulting to x86_64" >&2 RPM_ARCH=x86_64 ;; esac fi for rpm_file in ~/rpmbuild/RPMS/${RPM_ARCH}/*.rpm; do [ -e "$rpm_file" ] || continue base_rpm=$(basename "$rpm_file") mv "$rpm_file" "/output/${OS}-${base_rpm}" done # Also handle source RPMs # if [ -d ~/rpmbuild/SRPMS ]; then # for srpm_file in ~/rpmbuild/SRPMS/*.rpm; do # base_srpm=$(basename "$srpm_file") # mv "$srpm_file" "/output/${OS}-${base_srpm}" # done # fi # Adjust ownership of the output files chown -R $(stat -c "%u:%g" /output) /output documentdb-0.108-0/packaging/rpm/rhel-8/000077500000000000000000000000001507310017400176225ustar00rootroot00000000000000documentdb-0.108-0/packaging/rpm/rhel-8/Dockerfile000066400000000000000000000050471507310017400216220ustar00rootroot00000000000000ARG BASE_IMAGE=rockylinux:8 FROM ${BASE_IMAGE} ARG POSTGRES_VERSION=16 ARG DOCUMENTDB_VERSION ARG TARGETARCH ENV POSTGRES_VERSION=${POSTGRES_VERSION} ENV DOCUMENTDB_VERSION=${DOCUMENTDB_VERSION} RUN test -n "$DOCUMENTDB_VERSION" || (echo "DOCUMENTDB_VERSION not set" && false) # Enable PowerTools repository for RHEL 8 RUN dnf install -y dnf-plugins-core && \ dnf config-manager --set-enabled powertools # Locale setup RUN dnf -y install glibc-langpack-en glibc-common && \ localedef -i en_US -f UTF-8 en_US.UTF-8 || true ENV LANG=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 # Install base build tools and dependencies RUN dnf -y swap curl-minimal curl && \ dnf -y install \ dnf-utils \ rpm-build \ rpmdevtools \ wget \ curl \ git \ gcc \ gcc-c++ \ make \ cmake \ which \ libicu-devel \ krb5-devel \ python3 \ tar && \ dnf clean all RUN echo "Detected architecture: ${TARGETARCH}" # PostgreSQL yum repo setup for RHEL 8 RUN if [ -n "${TARGETARCH}" ] && ( [ "${TARGETARCH}" = "arm64" ] || [ "${TARGETARCH}" = "arm64v8" ] ); then ARCH=aarch64; else ARCH=x86_64; fi; \ echo "Setting up PGDG repo for RHEL 8 (arch=${ARCH})" && \ dnf -y --disablerepo=* install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-${ARCH}/pgdg-redhat-repo-latest.noarch.rpm && \ dnf -qy module disable postgresql && \ dnf -y install postgresql${POSTGRES_VERSION} \ postgresql${POSTGRES_VERSION}-devel \ postgresql${POSTGRES_VERSION}-server RUN dnf -y install \ openssl-devel \ cyrus-sasl-devel \ snappy-devel \ zlib-devel \ libcurl-devel \ libuuid-devel \ lz4-devel \ bzip2-devel RUN rpmdev-setuptree COPY scripts /tmp/install_setup RUN export INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup && \ MAKE_PROGRAM=cmake /tmp/install_setup/install_setup_libbson.sh && \ /tmp/install_setup/install_setup_pcre2.sh && \ /tmp/install_setup/install_setup_intel_decimal_math_lib.sh && \ /tmp/install_setup/install_citus_indent.sh WORKDIR /build COPY . /build COPY packaging/rpm/spec/documentdb.spec /build/rpm/documentdb.spec RUN sed -i "s/POSTGRES_VERSION/${POSTGRES_VERSION}/g" /build/rpm/documentdb.spec RUN sed -i "s/DOCUMENTDB_VERSION/${DOCUMENTDB_VERSION}/g" /build/rpm/documentdb.spec COPY packaging/rpm/packaging-entrypoint-rpm.sh /usr/local/bin/packaging-entrypoint-rpm.sh RUN chmod +x /usr/local/bin/packaging-entrypoint-rpm.sh ENTRYPOINT ["packaging-entrypoint-rpm.sh"] documentdb-0.108-0/packaging/rpm/rhel-9/000077500000000000000000000000001507310017400176235ustar00rootroot00000000000000documentdb-0.108-0/packaging/rpm/rhel-9/Dockerfile000066400000000000000000000054551507310017400216260ustar00rootroot00000000000000ARG BASE_IMAGE=rockylinux:9 FROM ${BASE_IMAGE} ARG POSTGRES_VERSION=16 ARG DOCUMENTDB_VERSION ARG TARGETARCH ENV POSTGRES_VERSION=${POSTGRES_VERSION} ENV DOCUMENTDB_VERSION=${DOCUMENTDB_VERSION} RUN test -n "$DOCUMENTDB_VERSION" || (echo "DOCUMENTDB_VERSION not set" && false) # Enable CRB repository for RHEL 9 RUN dnf install -y dnf-plugins-core && \ dnf config-manager --set-enabled crb # Locale setup RUN dnf -y install glibc-langpack-en glibc-common && \ localedef -i en_US -f UTF-8 en_US.UTF-8 || true ENV LANG=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 # Install base build tools and dependencies RUN dnf -y swap curl-minimal curl && \ dnf -y install \ dnf-utils \ rpm-build \ rpmdevtools \ wget \ curl \ git \ gcc \ gcc-c++ \ make \ cmake \ which \ libicu-devel \ krb5-devel \ python3 \ tar && \ dnf update -y --refresh && \ dnf clean all RUN echo "Detected architecture: ${TARGETARCH}" # PostgreSQL repo setup for RHEL 9 # Note: transient PGDG repodata signature outages were observed (repomd.xml GPG signature verification error). If happends again, consider temporarily using --nogpgcheck flag or check https://github.com/pgdg-packaging/pgdg-rpms/issues for fixing. RUN if [ -n "${TARGETARCH}" ] && ( [ "${TARGETARCH}" = "arm64" ] || [ "${TARGETARCH}" = "arm64v8" ] ); then ARCH=aarch64; else ARCH=x86_64; fi; \ echo "Setting up PGDG repo for RHEL 9 (arch=${ARCH})" && \ dnf -y --disablerepo=* install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-${ARCH}/pgdg-redhat-repo-latest.noarch.rpm && \ dnf -qy module disable postgresql && \ dnf -y install postgresql${POSTGRES_VERSION} \ postgresql${POSTGRES_VERSION}-devel \ postgresql${POSTGRES_VERSION}-server RUN dnf -y install \ openssl-devel \ cyrus-sasl-devel \ snappy-devel \ zlib-devel \ libcurl-devel \ libuuid-devel \ lz4-devel \ bzip2-devel RUN rpmdev-setuptree COPY scripts /tmp/install_setup RUN export INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup && \ MAKE_PROGRAM=cmake /tmp/install_setup/install_setup_libbson.sh && \ /tmp/install_setup/install_setup_pcre2.sh && \ /tmp/install_setup/install_setup_intel_decimal_math_lib.sh && \ /tmp/install_setup/install_citus_indent.sh WORKDIR /build COPY . /build COPY packaging/rpm/spec/documentdb.spec /build/rpm/documentdb.spec RUN sed -i "s/POSTGRES_VERSION/${POSTGRES_VERSION}/g" /build/rpm/documentdb.spec RUN sed -i "s/DOCUMENTDB_VERSION/${DOCUMENTDB_VERSION}/g" /build/rpm/documentdb.spec COPY packaging/rpm/packaging-entrypoint-rpm.sh /usr/local/bin/packaging-entrypoint-rpm.sh RUN chmod +x /usr/local/bin/packaging-entrypoint-rpm.sh ENTRYPOINT ["packaging-entrypoint-rpm.sh"] documentdb-0.108-0/packaging/rpm/spec/000077500000000000000000000000001507310017400174555ustar00rootroot00000000000000documentdb-0.108-0/packaging/rpm/spec/documentdb.spec000066400000000000000000000216021507310017400224560ustar00rootroot00000000000000%global pg_version POSTGRES_VERSION %define debug_package %{nil} Name: postgresql%{pg_version}-documentdb Version: DOCUMENTDB_VERSION Release: 1%{?dist} Summary: DocumentDB is the open-source engine powering vCore-based Azure Cosmos DB for MongoDB License: MIT URL: https://github.com/microsoft/documentdb Source0: %{name}-%{version}.tar.gz BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: make BuildRequires: cmake BuildRequires: postgresql%{pg_version}-devel BuildRequires: libicu-devel BuildRequires: krb5-devel BuildRequires: pkg-config # The following BuildRequires are for system packages. # Libbson and pcre2 development files are provided by scripts # in the Dockerfile_build_rpm_packages environment, not by system RPMs. # BuildRequires: libbson-devel # BuildRequires: pcre2-devel # BuildRequires: intel-decimal-math-devel # If a devel package exists and is used Requires: (postgresql%{pg_version} or percona-postgresql%{pg_version}) Requires: (postgresql%{pg_version}-server or percona-postgresql%{pg_version}-server) Requires: (pgvector_%{pg_version} or percona-pgvector_%{pg_version}) Requires: pg_cron_%{pg_version} Requires: postgis34_%{pg_version} Requires: rum_%{pg_version} # Libbson is now bundled, so no runtime Requires for it. # pcre2 is statically linked. # libbid.a is bundled. %description DocumentDB is the open-source engine powering vCore-based Azure Cosmos DB for MongoDB. It offers a native implementation of document-oriented NoSQL database, enabling seamless CRUD operations on BSON data types within a PostgreSQL framework. %prep %setup -q %build # Keep the internal directory out of the RPM package sed -i '/internal/d' Makefile # Build the extension # Ensure PG_CONFIG points to the correct pg_config for PGDG paths make %{?_smp_mflags} PG_CONFIG=/usr/pgsql-%{pg_version}/bin/pg_config PG_CFLAGS="-std=gnu99 -Wall -Wno-error" CFLAGS="" %install make install DESTDIR=%{buildroot} # Remove the bitcode directory if it's not needed in the final package rm -rf %{buildroot}/usr/pgsql-%{pg_version}/lib/bitcode # Bundle libbid.a (Intel Decimal Math Library static library) # This assumes install_setup_intel_decimal_math_lib.sh has placed libbid.a # at /usr/lib/intelmathlib/LIBRARY/libbid.a in the build environment. mkdir -p %{buildroot}/usr/lib/intelmathlib/LIBRARY cp /usr/lib/intelmathlib/LIBRARY/libbid.a %{buildroot}/usr/lib/intelmathlib/LIBRARY/libbid.a # Bundle libbson shared library and pkg-config file # These are installed by install_setup_libbson.sh into /usr (default INSTALLDESTDIR) mkdir -p %{buildroot}%{_libdir} mkdir -p %{buildroot}%{_libdir}/pkgconfig # fully versioned .so file cp /usr/%{_lib}/libbson-1.0.so.0.0.0 %{buildroot}%{_libdir}/ # Copy the main symlinks cp -P /usr/%{_lib}/libbson-1.0.so %{buildroot}%{_libdir}/ cp -P /usr/%{_lib}/libbson-1.0.so.0 %{buildroot}%{_libdir}/ # static library cp /usr/%{_lib}/pkgconfig/libbson-static-1.0.pc %{buildroot}%{_libdir}/pkgconfig/ # Install source code and test files for make check mkdir -p %{buildroot}/usr/src/documentdb cp -r . %{buildroot}/usr/src/documentdb/ # Remove build artifacts and unnecessary files from source copy find %{buildroot}/usr/src/documentdb -name "*.o" -delete find %{buildroot}/usr/src/documentdb -name "*.so" -delete find %{buildroot}/usr/src/documentdb -name "*.bc" -delete rm -rf %{buildroot}/usr/src/documentdb/.git* rm -rf %{buildroot}/usr/src/documentdb/build %files %defattr(-,root,root,-) /usr/pgsql-%{pg_version}/lib/pg_documentdb_core.so /usr/pgsql-%{pg_version}/lib/pg_documentdb.so /usr/pgsql-%{pg_version}/lib/pg_documentdb_extended_rum.so /usr/pgsql-%{pg_version}/share/extension/documentdb_core.control /usr/pgsql-%{pg_version}/share/extension/documentdb_core--*.sql /usr/pgsql-%{pg_version}/share/extension/documentdb.control /usr/pgsql-%{pg_version}/share/extension/documentdb--*.sql /usr/pgsql-%{pg_version}/share/extension/documentdb_extended_rum.control /usr/pgsql-%{pg_version}/share/extension/documentdb_extended_rum--*.sql /usr/src/documentdb /usr/lib/intelmathlib/LIBRARY/libbid.a # Bundled libbson files: %{_libdir}/libbson-1.0.so %{_libdir}/libbson-1.0.so.0 %{_libdir}/libbson-1.0.so.0.0.0 %{_libdir}/pkgconfig/libbson-static-1.0.pc %changelog * Fri Aug 29 2025 Shuai Tian - 0.106-0 - Add internal extension that provides extensions to the `rum` index. *[Feature]* - Enable let support for update queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. - Enable let support for findAndModify queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. - Add internal extension that provides extensions to the `rum` index. *[Feature]* - Optimized query for `usersInfo` command. - Support collation with `delete` *[Feature]*. Requires `EnableCollation` to be `on`. - Support for index hints for find/aggregate/count/distinct *[Feature]* - Support `createRole` command *[Feature]* - Add schema changes for Role CRUD APIs *[Feature]* - Add support for using EntraId tokens via Plain Auth * Mon Jul 28 2025 Shuai Tian - 0.105-0 - Support `$bucketAuto` aggregation stage, with granularity types: `POWERSOF2`, `1-2-5`, `R5`, `R10`, `R20`, `R40`, `R80`, `E6`, `E12`, `E24`, `E48`, `E96`, `E192` *[Feature]* - Support `conectionStatus` command *[Feature]*. * Mon Jun 09 2025 Shuai Tian - 0.104-0 - Add string case support for `$toDate` operator - Support `sort` with collation in runtime*[Feature]* - Support collation with `$indexOfArray` aggregation operator. *[Feature]* - Support collation with arrays and objects comparisons *[Feature]* - Support background index builds *[Bugfix]* (#36) - Enable user CRUD by default *[Feature]* - Enable let support for delete queries *[Feature]*. Requires `EnableVariablesSupportForWriteCommands` to be `on`. - Enable rum_enable_index_scan as default on *[Perf]* - Add public `documentdb-local` Docker image with gateway to GHCR - Support `compact` command *[Feature]*. Requires `documentdb.enablecompact` GUC to be `on`. - Enable role privileges for `usersInfo` command *[Feature]* * Fri May 09 2025 Shuai Tian - 0.103-0 - Support collation with aggregation and find on sharded collections *[Feature]* - Support `$convert` on `binData` to `binData`, `string` to `binData` and `binData` to `string` (except with `format: auto`) *[Feature]* - Fix list_databases for databases with size > 2 GB *[Bugfix]* (#119) - Support half-precision vector indexing, vectors can have up to 4,000 dimensions *[Feature]* - Support ARM64 architecture when building docker container *[Preview]* - Support collation with `$documents` and `$replaceWith` stage of the aggregation pipeline *[Feature]* - Push pg_documentdb_gw for documentdb connections *[Feature]* * Wed Mar 26 2025 Shuai Tian - 0.102-0 - Support index pushdown for vector search queries *[Bugfix]* - Support exact search for vector search queries *[Feature]* - Inline $match with let in $lookup pipelines as JOIN Filter *[Perf]* - Support TTL indexes *[Bugfix]* (#34) - Support joining between postgres and documentdb tables *[Feature]* (#61) - Support current_op command *[Feature]* (#59) - Support for list_databases command *[Feature]* (#45) - Disable analyze statistics for unique index uuid columns which improves resource usage *[Perf]* - Support collation with `$expr`, `$in`, `$cmp`, `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte` comparison operators (Opt-in) *[Feature]* - Support collation in `find`, aggregation `$project`, `$redact`, `$set`, `$addFields`, `$replaceRoot` stages (Opt-in) *[Feature]* - Support collation with `$setEquals`, `$setUnion`, `$setIntersection`, `$setDifference`, `$setIsSubset` in the aggregation pipeline (Opt-in) *[Feature]* - Support unique index truncation by default with new operator class *[Feature]* - Top level aggregate command `let` variables support for `$geoNear` stage *[Feature]* - Enable Backend Command support for Statement Timeout *[Feature]* - Support type aggregation operator `$toUUID`. *[Feature]* - Support Partial filter pushdown for `$in` predicates *[Perf]* - Support the $dateFromString operator with full functionality *[Feature]* - Support extended syntax for `$getField` aggregation operator. Now the value of 'field' could be an expression that resolves to a string. *[Feature]* * Wed Feb 12 2025 Shuai Tian - 0.101-0 - Push $graphlookup recursive CTE JOIN filters to index *[Perf]* - Build pg_documentdb for PostgreSQL 17 *[Infra]* (#13) - Enable support of currentOp aggregation stage, along with collstats, dbstats, and indexStats *[Commands]* (#52) - Allow inlining $unwind with $lookup with `preserveNullAndEmptyArrays` *[Perf]* - Skip loading documents if group expression is constant *[Perf]* - Fix Merge stage not outputing to target collection *[Bugfix]* (#20) * Thu Jan 23 2025 Shuai Tian - 0.100-0 - Initial Releasedocumentdb-0.108-0/packaging/rpm/validate_rpm_build.sh000077500000000000000000000055271507310017400227210ustar00rootroot00000000000000#!/bin/bash # Script to validate RPM build environment and diagnose network issues set -e echo "=== DocumentDB RPM Build Environment Validation ===" echo # Check Docker availability echo "1. Checking Docker installation..." if ! command -v docker &> /dev/null; then echo "⌠Docker is not installed or not in PATH" echo " Please install Docker to build RPM packages" exit 1 fi echo "✅ Docker is available" # Check Docker daemon echo "2. Checking Docker daemon..." if ! docker info &> /dev/null; then echo "⌠Docker daemon is not running or not accessible" echo " Please start Docker daemon and ensure you have proper permissions" exit 1 fi echo "✅ Docker daemon is running" # Test network connectivity for common package repositories echo "3. Testing network connectivity..." repositories=( "mirrors.rockylinux.org" "download.postgresql.org" "mirrorlist.centos.org" "registry.access.redhat.com" ) failed_repos=() for repo in "${repositories[@]}"; do echo " Testing access to $repo..." if curl -s --connect-timeout 10 --max-time 15 "https://$repo" > /dev/null 2>&1 || \ curl -s --connect-timeout 10 --max-time 15 "http://$repo" > /dev/null 2>&1; then echo " ✅ $repo is accessible" else echo " ⌠$repo is not accessible" failed_repos+=("$repo") fi done # Test base image pull echo "4. Testing base image access..." if docker pull rockylinux:8 &> /dev/null; then echo "✅ Rocky Linux 8 base image is accessible" docker rmi rockylinux:8 &> /dev/null || true else echo "⌠Cannot pull Rocky Linux 8 base image" failed_repos+=("docker.io/rockylinux") fi echo if [ ${#failed_repos[@]} -eq 0 ]; then echo "🎉 Environment validation passed! You should be able to build RPM packages." echo echo "To build RPM packages, run:" echo " ./packaging/build_packages.sh --os rhel8 --pg 16" echo " ./packaging/build_packages.sh --os rhel9 --pg 17" else echo "âš ï¸ Environment validation found issues:" echo echo "The following repositories are not accessible:" for repo in "${failed_repos[@]}"; do echo " - $repo" done echo echo "This indicates network restrictions (firewall/proxy) that will prevent RPM builds." echo echo "SOLUTIONS:" echo echo "1. Contact your system/network administrator to:" echo " - Allow access to the blocked repositories above" echo " - Configure proxy settings if needed" echo " - Add domains to firewall allowlist" echo echo "2. Try building from a different network environment with fewer restrictions" echo echo "3. Use pre-built packages if available, or build in an unrestricted environment" echo echo "For more information, see the Network Requirements section in packaging/README.md" fi echo echo "=== Validation Complete ==="documentdb-0.108-0/packaging/test_packages/000077500000000000000000000000001507310017400205425ustar00rootroot00000000000000documentdb-0.108-0/packaging/test_packages/deb/000077500000000000000000000000001507310017400212745ustar00rootroot00000000000000documentdb-0.108-0/packaging/test_packages/deb/Dockerfile000077500000000000000000000024301507310017400232700ustar00rootroot00000000000000ARG BASE_IMAGE=debian:bookworm FROM ${BASE_IMAGE} ARG DEBIAN_FRONTEND=noninteractive ARG POSTGRES_VERSION=16 ARG DEB_PACKAGE_REL_PATH=packages/postgresql-16-documentdb-1_1.0.0_amd64.deb RUN apt-get update RUN apt-get install -y --no-install-recommends \ make \ wget \ gnupg2 \ lsb-release \ ca-certificates \ locales \ python3 RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 ENV LANGUAGE=en_US ENV LC_COLLATE=en_US.UTF-8 ENV LC_CTYPE=en_US.UTF-8 ENV LANG=en_US.UTF-8 RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main ${POSTGRES_VERSION}" > /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - # actual dependencies of the package RUN apt-get update && apt-get install -y \ postgresql-${POSTGRES_VERSION} \ postgresql-${POSTGRES_VERSION}-cron \ postgresql-${POSTGRES_VERSION}-pgvector \ postgresql-${POSTGRES_VERSION}-postgis-3 \ postgresql-${POSTGRES_VERSION}-rum WORKDIR /test-install COPY . /test-install RUN dpkg -i ${DEB_PACKAGE_REL_PATH} COPY packaging/test_packages/test-install-entrypoint.sh /usr/local/bin/test-install-entrypoint.sh ENTRYPOINT ["test-install-entrypoint.sh"]documentdb-0.108-0/packaging/test_packages/rhel-8/000077500000000000000000000000001507310017400216415ustar00rootroot00000000000000documentdb-0.108-0/packaging/test_packages/rhel-8/Dockerfile000066400000000000000000000034751507310017400236440ustar00rootroot00000000000000ARG BASE_IMAGE=rockylinux:8 FROM ${BASE_IMAGE} ARG POSTGRES_VERSION=16 ARG RPM_PACKAGE_REL_PATH ARG TARGETARCH ENV POSTGRES_VERSION=${POSTGRES_VERSION} RUN echo "Testing for RPM install on RHEL 8" RUN dnf install -y dnf-plugins-core RUN dnf install -y epel-release && \ dnf config-manager --set-enabled powertools && \ dnf clean all RUN dnf -y install glibc-langpack-en glibc-common && \ localedef -i en_US -f UTF-8 en_US.UTF-8 || true ENV LANG=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 RUN dnf -y swap curl-minimal curl && \ dnf -y install \ make \ ca-certificates \ gcc \ gcc-c++ \ pkg-config \ openssl-devel \ zlib-devel \ libuuid-devel \ libicu-devel \ krb5-devel RUN echo "Detected architecture: ${TARGETARCH}" # PostgreSQL yum repo setup for RHEL 8 RUN if [ -n "${TARGETARCH}" ] && ( [ "${TARGETARCH}" = "arm64" ] || [ "${TARGETARCH}" = "arm64v8" ] ); then ARCH=aarch64; else ARCH=x86_64; fi; \ echo "Setting up PGDG repo for RHEL 8 (arch=${ARCH})" && \ dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-${ARCH}/pgdg-redhat-repo-latest.noarch.rpm && \ dnf -qy module disable postgresql && \ dnf -y install postgresql${POSTGRES_VERSION} \ postgresql${POSTGRES_VERSION}-devel \ postgresql${POSTGRES_VERSION}-server \ postgresql${POSTGRES_VERSION}-contrib \ pgvector_${POSTGRES_VERSION} \ pg_cron_${POSTGRES_VERSION} \ postgis34_${POSTGRES_VERSION} \ rum_${POSTGRES_VERSION} RUN mkdir -p /usr/src/documentdb WORKDIR /usr/src/documentdb COPY . /usr/src/documentdb COPY ${RPM_PACKAGE_REL_PATH} /tmp/documentdb.rpm COPY packaging/test_packages/test-install-entrypoint-rpm.sh /usr/local/bin/test-install-entrypoint-rpm.sh RUN chmod +x /usr/local/bin/test-install-entrypoint-rpm.sh ENTRYPOINT ["test-install-entrypoint-rpm.sh"] documentdb-0.108-0/packaging/test_packages/rhel-9/000077500000000000000000000000001507310017400216425ustar00rootroot00000000000000documentdb-0.108-0/packaging/test_packages/rhel-9/Dockerfile000066400000000000000000000034661507310017400236450ustar00rootroot00000000000000ARG BASE_IMAGE=rockylinux:9 FROM ${BASE_IMAGE} ARG POSTGRES_VERSION=16 ARG RPM_PACKAGE_REL_PATH ARG TARGETARCH ENV POSTGRES_VERSION=${POSTGRES_VERSION} RUN echo "Testing for RPM install on RHEL 9" RUN dnf install -y dnf-plugins-core RUN dnf install -y epel-release && \ dnf config-manager --set-enabled crb && \ dnf clean all RUN dnf -y install glibc-langpack-en glibc-common && \ localedef -i en_US -f UTF-8 en_US.UTF-8 || true ENV LANG=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 RUN dnf -y swap curl-minimal curl && \ dnf -y install \ make \ ca-certificates \ gcc \ gcc-c++ \ pkg-config \ openssl-devel \ zlib-devel \ libuuid-devel \ libicu-devel \ krb5-devel RUN echo "Detected architecture: ${TARGETARCH}" # PostgreSQL yum repo setup for RHEL 9 RUN if [ -n "${TARGETARCH}" ] && ( [ "${TARGETARCH}" = "arm64" ] || [ "${TARGETARCH}" = "arm64v8" ] ); then ARCH=aarch64; else ARCH=x86_64; fi; \ echo "Setting up PGDG repo for RHEL 9 (arch=${ARCH})" && \ dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-${ARCH}/pgdg-redhat-repo-latest.noarch.rpm && \ dnf -qy module disable postgresql && \ dnf -y install postgresql${POSTGRES_VERSION} \ postgresql${POSTGRES_VERSION}-devel \ postgresql${POSTGRES_VERSION}-server \ postgresql${POSTGRES_VERSION}-contrib \ pgvector_${POSTGRES_VERSION} \ pg_cron_${POSTGRES_VERSION} \ postgis34_${POSTGRES_VERSION} \ rum_${POSTGRES_VERSION} RUN mkdir -p /usr/src/documentdb WORKDIR /usr/src/documentdb COPY . /usr/src/documentdb COPY ${RPM_PACKAGE_REL_PATH} /tmp/documentdb.rpm COPY packaging/test_packages/test-install-entrypoint-rpm.sh /usr/local/bin/test-install-entrypoint-rpm.sh RUN chmod +x /usr/local/bin/test-install-entrypoint-rpm.sh ENTRYPOINT ["test-install-entrypoint-rpm.sh"] documentdb-0.108-0/packaging/test_packages/test-install-entrypoint-rpm.sh000077500000000000000000000045251507310017400265370ustar00rootroot00000000000000#!/bin/bash set -e echo "Testing RPM package installation..." # Debug: report runtime architecture echo "Runtime uname -m: $(uname -m)" if [ -n "${TARGETARCH:-}" ]; then echo "TARGETARCH env: ${TARGETARCH}" fi # Install the RPM package dnf install -y /tmp/documentdb.rpm echo "RPM package installed successfully!" cd /usr/src/documentdb # Set up environment for make check export PG_CONFIG=/usr/pgsql-${POSTGRES_VERSION}/bin/pg_config export PATH=/usr/pgsql-${POSTGRES_VERSION}/bin:$PATH # Test environment setup first echo "=== Testing environment for make check ===" # Test pg_config if [ -x "$PG_CONFIG" ]; then echo "✓ pg_config found: $($PG_CONFIG --version)" else echo "✗ pg_config not found at $PG_CONFIG" find /usr -name "pg_config" 2>/dev/null | head -3 exit 1 fi # Test libbson pkg-config if pkg-config --exists libbson-static-1.0; then echo "✓ libbson-static-1.0 pkg-config available" else echo "✗ libbson-static-1.0 pkg-config not found" echo "Available pkg-config packages with 'bson':" pkg-config --list-all | grep -i bson || echo "None found" exit 1 fi # Test pg_regress PGXS=$($PG_CONFIG --pgxs) PG_REGRESS_PATH="$(dirname "$PGXS")/../test/regress/pg_regress" if [ -x "$PG_REGRESS_PATH" ]; then echo "✓ pg_regress found at $PG_REGRESS_PATH" else echo "✗ pg_regress not found at expected path: $PG_REGRESS_PATH" echo "Searching for pg_regress..." find /usr -name "pg_regress" 2>/dev/null | head -3 exit 1 fi echo "=== Environment tests passed! ===" # Ensure the documentdb user has permissions to run tests adduser --system --no-create-home documentdb || true chown -R documentdb:documentdb . # Switch to the documentdb user and run the tests echo "Running make check as documentdb user..." if ! su documentdb -c "export PG_CONFIG=/usr/pgsql-${POSTGRES_VERSION}/bin/pg_config && export PATH=/usr/pgsql-${POSTGRES_VERSION}/bin:\$PATH && make check"; then echo "make check failed. Displaying postmaster.log if it exists:" LOG_FILE="/usr/src/documentdb/pg_documentdb/src/test/regress/log/postmaster.log" if [ -f "$LOG_FILE" ]; then echo "=== Contents of $LOG_FILE ===" cat "$LOG_FILE" echo "===============================" else echo "Log file $LOG_FILE not found." fi exit 1 fi echo "Package installation test completed successfully!"documentdb-0.108-0/packaging/test_packages/test-install-entrypoint.sh000077500000000000000000000004241507310017400257350ustar00rootroot00000000000000#!/bin/bash set -e # Change to the test directory cd /test-install # Keep the internal directory out of the testing sed -i '/internal/d' Makefile # Run the test adduser --disabled-password --gecos "" documentdb chown -R documentdb:documentdb . su documentdb -c "make check"documentdb-0.108-0/packaging/update_spec_changelog.sh000066400000000000000000000175421507310017400225750ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail usage() { cat < documentdb_version may be in either '0.106-0' or '0.106.0' form. The script extracts sections from CHANGELOG.md starting at the specified version header and including that version and all earlier (older) versions, then replaces the %changelog block in packaging/rpm/spec/documentdb.spec with the extracted markdown. EOF } if [[ ${#@} -ne 1 ]]; then usage exit 2 fi INPUT_VER="$1" # normalize to dashed form if dotted provided (0.106.0 -> 0.106-0) if [[ "$INPUT_VER" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then VER_DASH="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}-${BASH_REMATCH[3]}" else VER_DASH="$INPUT_VER" fi CHANGELOG=CHANGELOG.md SPEC=packaging/rpm/spec/documentdb.spec if [ ! -f "$CHANGELOG" ]; then echo "ERROR: $CHANGELOG not found" >&2 exit 1 fi if [ ! -f "$SPEC" ]; then echo "ERROR: $SPEC not found" >&2 exit 1 fi echo "Updating $SPEC with changelog from $CHANGELOG starting at version: $VER_DASH (inclusive) and including earlier versions" # For RPM, Version must not contain hyphens. Split VER_DASH into version and release # e.g. 0.105-0 -> ver=0.105 rel=0 RPM_VER="${VER_DASH%%-*}" RPM_REL="${VER_DASH#*-}" if [[ "$RPM_VER" == "$VER_DASH" ]]; then # no dash found; keep release as 1 RPM_REL="1" fi # Update Version and Release fields in the spec so rpmbuild sees valid values spec_tmp_ver=$(mktemp) awk -v ver="$RPM_VER" -v rel="$RPM_REL" 'BEGIN{v=ver;r=rel} /^Version:/{printf "Version: %s\n", v; next} /^Release:/{printf "Release: %s%%{?dist}\n", r; next} {print}' "$SPEC" > "$spec_tmp_ver" mv "$spec_tmp_ver" "$SPEC" # Find header lines that look like: ### documentdb v0.106-0 ... # We'll search for the header that contains the target version and then # extract from that header through EOF (so target + older entries). target_header_line="" # Find first header line that contains the version string target_header_line=$(grep -n '^### ' "$CHANGELOG" | grep -m1 "v${VER_DASH}" | cut -d: -f1 || true) if [[ -z "$target_header_line" ]]; then echo "ERROR: Could not find section for version v$VER_DASH in $CHANGELOG" >&2 exit 1 fi start_line=$target_header_line end_line=$(wc -l < "$CHANGELOG") echo "Extracting lines $start_line..$end_line from $CHANGELOG" temp_changelog=$(mktemp) trap 'rm -f "$temp_changelog"' EXIT sed -n "${start_line},${end_line}p" "$CHANGELOG" > "$temp_changelog" # Determine packager (try git config, else default) GIT_NAME=$(git config user.name 2>/dev/null || true) GIT_EMAIL=$(git config user.email 2>/dev/null || true) if [[ -n "$GIT_NAME" && -n "$GIT_EMAIL" ]]; then PACKAGER="$GIT_NAME <$GIT_EMAIL>" else PACKAGER="documentdb packager " fi # Convert extracted markdown into RPM %changelog format. # We expect sections that start with '###' containing 'v' and # optionally a date in parentheses like '(July 28, 2025)'. For Unreleased # entries we'll use today's date. new_changelog_block="%changelog\n" debian_changelog="" DEB_TEMP=$(mktemp) trap 'rm -f "$temp_changelog" "$DEB_TEMP"' EXIT current_ver="" current_date_raw="" items=() flush_section() { if [[ -z "$current_ver" ]]; then return fi # Determine date to use if [[ -n "$current_date_raw" && "$current_date_raw" != "Unreleased" ]]; then # sanitize ordinal suffixes (1st, 2nd, 3rd, 4th etc) so date -d can parse san_date=$(printf '%s' "$current_date_raw" | sed -E 's/([0-9]{1,2})(st|nd|rd|th)/\1/g') # try to parse e.g. 'July 28, 2025' via date if parsed_date=$(date -d "$san_date" -u +"%a %b %d %Y" 2>/dev/null); then date_str="$parsed_date" else date_str=$(date -u +"%a %b %d %Y") fi else date_str=$(date -u +"%a %b %d %Y") fi new_changelog_block+="* ${date_str} ${PACKAGER} - ${current_ver}\n" if [[ ${#items[@]} -eq 0 ]]; then new_changelog_block+="- No details provided.\n" else for it in "${items[@]}"; do # make sure each item is a single line starting with '- ' new_changelog_block+="- ${it}\n" done fi new_changelog_block+=$'\n' # Also build Debian changelog entry # Debian date format: 'Mon, 28 Jul 2025 12:00:00 +0000' # Parse and sanitize the header date from CHANGELOG.md; fallback to today if parsing fails if [[ -n "$current_date_raw" && "$current_date_raw" != "Unreleased" ]]; then san_date=$(printf '%s' "$current_date_raw" | sed -E 's/([0-9]{1,2})(st|nd|rd|th)/\1/g') if deb_date=$(date -d "$san_date" -u +"%a, %d %b %Y 12:00:00 +0000" 2>/dev/null); then date_rfc="$deb_date" else date_rfc=$(date -u +"%a, %d %b %Y %T +0000") fi else date_rfc=$(date -u +"%a, %d %b %Y %T +0000") fi # Debian changelog needs a blank line after the header, then # each change line indented by two spaces and starting with '* '. # Then a blank line and the trailer line. printf '%s\n' "documentdb (${current_ver}) unstable; urgency=medium" >> "$DEB_TEMP" printf '%s\n' "" >> "$DEB_TEMP" if [[ ${#items[@]} -eq 0 ]]; then printf ' * %s\n' "No details provided." >> "$DEB_TEMP" else for it in "${items[@]}"; do printf ' * %s\n' "$it" >> "$DEB_TEMP" done fi printf '%s\n' "" >> "$DEB_TEMP" printf ' -- %s %s\n\n' "$PACKAGER" "$date_rfc" >> "$DEB_TEMP" # reset items=() current_ver="" current_date_raw="" } # Read the extracted changelog and parse sections while IFS= read -r line; do # header lines start with '###' if [[ "$line" =~ ^### ]]; then # If we already have a section, flush it if [[ -n "$current_ver" ]]; then flush_section fi # Extract version: look for 'v' followed by digits.digits- digits (e.g. v0.105-0 or v1.108-0) if [[ "$line" =~ v([0-9]+\.[0-9]+-[0-9]+) ]]; then current_ver="${BASH_REMATCH[1]}" else # fallback: capture anything after 'v' up to a space or '(' current_ver=$(printf '%s' "$line" | sed -n 's/.*v\([^ (][^ (]*\).*/\1/p' || true) if [[ -z "$current_ver" ]]; then current_ver="unknown" fi fi # Extract parenthesized date, if present (use sed for portability) current_date_raw=$(printf '%s' "$line" | sed -n 's/.*(\([^)]*\)).*/\1/p' || true) if [[ -z "$current_date_raw" ]]; then current_date_raw="" fi continue fi # Collect list items: lines starting with '*' or '-' or plain text. if [[ "$line" =~ ^[[:space:]]*([*\-])[[:space:]]*(.*) ]]; then items+=("${BASH_REMATCH[2]}") else # Non-list lines: if not empty, treat as an item if [[ -n "$line" ]]; then # Trim leading/trailing whitespace trimmed="$line" trimmed="${trimmed## }" trimmed="${trimmed%% }" items+=("$trimmed") fi fi done < "$temp_changelog" # Flush last section flush_section # Replace %changelog section in spec: from line starting with '%changelog' to EOF # Write to a temp file and move into place to avoid partial writes spec_tmp=$(mktemp) awk -v repl="$new_changelog_block" 'BEGIN{ins=0} /^%changelog/{print repl; ins=1; next} { if(ins==0) print }' "$SPEC" > "$spec_tmp" mv "$spec_tmp" "$SPEC" echo "Updated $SPEC" echo "Done." # Write generated Debian changelog from temp file if present DEB_FILE_PACKAGING="packaging/deb/changelog" DEB_FILE_DEBIAN="debian/changelog" if [[ -s "$DEB_TEMP" ]]; then # Update the packaging copy cat "$DEB_TEMP" > "$DEB_FILE_PACKAGING" echo "Updated $DEB_FILE_PACKAGING" # Also update the in-source debian/changelog if present (used inside container builds) if [[ -d "debian" ]]; then cat "$DEB_TEMP" > "$DEB_FILE_DEBIAN" echo "Updated $DEB_FILE_DEBIAN" fi fidocumentdb-0.108-0/pg_documentdb/000077500000000000000000000000001507310017400166135ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/Makefile000066400000000000000000000060201507310017400202510ustar00rootroot00000000000000EXTENSION = documentdb MODULE_big = pg_$(EXTENSION) SQL_DEPDIR=.deps/sql SQL_BUILDDIR=build/sql template_sql_files = $(wildcard sql/*.sql) generated_sql_files = $(patsubst %,build/%,$(template_sql_files)) DATA_built = $(generated_sql_files) sql_file_inputs = $(wildcard sql/**/*.sql) BUILD_SCRIPT_DIR = ../ OSS_SRC_DIR = ../ OSS_COMMON_SQL_HEADER = $(wildcard $(OSS_SRC_DIR)/common_header.sql) # Extension defines API_SCHEMA_NAME=documentdb_api API_SCHEMA_NAME_V2=documentdb_api API_SCHEMA_INTERNAL_NAME=documentdb_api_internal API_SCHEMA_INTERNAL_NAME_V2=documentdb_api_internal API_CATALOG_SCHEMA_NAME=documentdb_api_catalog API_CATALOG_SCHEMA_NAME_V2=documentdb_api_catalog CORE_SCHEMA_NAME=documentdb_core API_DATA_SCHEMA_NAME=documentdb_data API_ADMIN_ROLE=documentdb_admin_role API_READONLY_ROLE=documentdb_readonly_role API_BG_WORKER_ROLE=documentdb_bg_worker_role POSTGIS_SCHEMA_NAME=public EXTENSION_OBJECT_PREFIX=documentdb API_GUC_PREFIX=documentdb API_GUC_PREFIX_V2=documentdb # TODO: Need to remove this with PG16 and expose only valid exports ALLOW_DEFAULT_VISIBILITY=yes USE_DOCUMENTDB_CORE = 1 include $(OSS_SRC_DIR)/Makefile.cflags SOURCES = $(wildcard src/*.c) $(wildcard src/**/*.c) OBJS = $(patsubst %.c,%.o,$(SOURCES)) # Update to notify roaring to use the C atomics implementation (as opposed to c++): See roaring.h CROARING_ATOMIC_IMPL_C PG_CFLAGS += -DCROARING_ATOMIC_IMPL=3 PG_CPPFLAGS += -DCROARING_ATOMIC_IMPL=3 DEBUG ?= no ifeq ($(DEBUG),yes) PG_CPPFLAGS += -ggdb -O0 -g PG_CFLAGS += -ggdb -O0 -g endif SHLIB_LINK = $(libpq) include $(OSS_SRC_DIR)/Makefile.global clean-sql: rm -rf .deps/ build/ check: $(MAKE) -C src/test all check-extended-rum: $(MAKE) -C src/test/extended_rum_tests all check-minimal: $(MAKE) -C src/test/regress check-minimal check-documentdb-minimal: check-minimal check-docdb-rum-minimal: $(MAKE) -C src/test/extended_rum_tests check-minimal citus-indent: citus_indent analysis: citus-indent check-regress: $(MAKE) -C src/test check-regress # Before installing, trim any files extension*.sql files in the target install directory install: trim_installed_data_files trim_installed_data_files: rm -f $(DESTDIR)$(datadir)/$(datamoduledir)/$(EXTENSION)--*.sql build-sql: $(generated_sql_files) $(generated_sql_files): build/%: % @mkdir -p $(SQL_DEPDIR) $(SQL_BUILDDIR) @# -MF is used to store dependency files(.Po) in another directory for separation @# -MT is used to change the target of the rule emitted by dependency generation. @# -P is used to inhibit generation of linemarkers in the output from the preprocessor. @# -undef is used to not predefine any system-specific or GCC-specific macros. @# -imacros is used to specify a file that defines macros for the global context but its output is thrown away. @# `man cpp` for further information cpp -undef -w $(SQL_DEFINES) -imacros $(OSS_COMMON_SQL_HEADER) -P -MMD -MP -MF$(SQL_DEPDIR)/$(*F).Po -MT$@ $< > $@ include $(OSS_SRC_DIR)/Makefile.versions src/documentdb_extension_version.o : build/include/metadata/documentdb_extension_version.hdocumentdb-0.108-0/pg_documentdb/documentdb.control000066400000000000000000000003511507310017400223400ustar00rootroot00000000000000comment = 'API surface for DocumentDB for PostgreSQL' default_version = '0.108-0' module_pathname = '$libdir/pg_documentdb' relocatable = false superuser = true requires = 'documentdb_core, pg_cron, tsm_system_rows, vector, postgis' documentdb-0.108-0/pg_documentdb/include/000077500000000000000000000000001507310017400202365ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/aggregation/000077500000000000000000000000001507310017400225255ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/aggregation/aggregation_commands.h000066400000000000000000000020031507310017400270410ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/aggregation_commands.h * * Exports for the aggregation external commands. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_AGGREGATION_COMMANDS_H #define DOCUMENTDB_AGGREGATION_COMMANDS_H #include extern Datum delete_cursors(ArrayType *cursorArray); extern Datum find_cursor_first_page(text *database, pgbson *findSpec, int64_t cursorId); extern Datum aggregate_cursor_first_page(text *database, pgbson *aggregationSpec, int64_t cursorId); extern Datum aggregation_cursor_get_more(text *database, pgbson *getMoreSpec, pgbson *cursorSpec, AttrNumber maxResponseAttributeNumber); extern Datum list_collections_first_page(text *database, pgbson *listCollectionsSpec); extern Datum list_indexes_first_page(text *database, pgbson *listIndexesSpec); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_aggregation_pipeline.h000066400000000000000000000100321507310017400300670ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_aggregation_pipeline.h * * Exports for the bson_aggregation_pipeline definition * *------------------------------------------------------------------------- */ #ifndef BSON_AGGREGATION_PIPELINE_H #define BSON_AGGREGATION_PIPELINE_H #include #include "operators/bson_expression.h" #include "utils/documentdb_errors.h" typedef enum QueryCursorType { QueryCursorType_Unspecified = 0, /* * Whether or not the query can be done as a streamable * query. */ QueryCursorType_Streamable = 1, /* * Indicates whether this is processed as a single batch query. */ QueryCursorType_SingleBatch, /* * The cursor plan is a point read. */ QueryCursorType_PointRead, /* * Whether or not the query can be done as a tailable * query. */ QueryCursorType_Tailable, /* * By default all queries are persistent cursors. */ QueryCursorType_Persistent, } QueryCursorType; /* * Tracks the overall query spec data * that can be extracted from the query. * Used in cursor management to page and * decide what kind of cursor to use for the outer * request. */ typedef struct { /* * The parameter number used for the cursor * continuation (if it is a streaming cursor) */ int cursorStateParamNumber; /* * The namespaceName associated with the query. */ const char *namespaceName; QueryCursorType cursorKind; /* * The requested batchSize in the query request. */ int32_t batchSize; /* * The time system variables ($$NOW, $$CLUSTER_TIME). */ TimeSystemVariables timeSystemVariables; } QueryData; Query * GenerateFindQuery(text *database, pgbson *findSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout); Query * GenerateCountQuery(text *database, pgbson *countSpec, bool setStatementTimeout); Query * GenerateDistinctQuery(text *database, pgbson *distinctSpec, bool setStatementTimeout); Query * GenerateListCollectionsQuery(text *database, pgbson *listCollectionsSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout); Query * GenerateListIndexesQuery(text *database, pgbson *listIndexesSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout); Query * GenerateAggregationQuery(text *database, pgbson *aggregationSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout); int64_t ParseGetMore(text **databaseName, pgbson *getMoreSpec, QueryData *queryData, bool setStatementTimeout); void ValidateAggregationPipeline(text *databaseDatum, const StringView *baseCollection, const bson_value_t *pipelineValue); void LookupExtractCollectionAndPipeline(const bson_value_t *lookupValue, StringView *collection, bson_value_t *pipeline); void GraphLookupExtractCollection(const bson_value_t *lookupValue, StringView *collection); void ParseUnionWith(const bson_value_t *existingValue, StringView *collectionFrom, bson_value_t *pipeline); void ParseInputDocumentForTopAndBottom(const bson_value_t *inputDocument, bson_value_t *input, bson_value_t *elementsToFetch, bson_value_t *sortSpec, const char *opName); void ParseInputDocumentForMedianAndPercentile(const bson_value_t *inputDocument, bson_value_t *input, bson_value_t *p, bson_value_t *method, bool isMedianOp); void ValidateElementForNGroupAccumulators(bson_value_t *elementsToFetch, const char *opName); void ParseInputForNGroupAccumulators(const bson_value_t *inputDocument, bson_value_t *input, bson_value_t *elementsToFetch, const char *opName); extern int DefaultCursorFirstPageBatchSize; /* Generates a base QueryData used for the first page */ inline static QueryData GenerateFirstPageQueryData(void) { QueryData queryData = { 0 }; queryData.batchSize = DefaultCursorFirstPageBatchSize; return queryData; } #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_aggregation_pipeline_private.h000066400000000000000000000254631507310017400316370ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/bson_aggregation_pipeline_private.h * * Private helpers for the bson_aggregation_pipeline definition * *------------------------------------------------------------------------- */ #include #include #include #include "metadata/collection.h" #include #include "collation/collation.h" #ifndef BSON_AGGREGATION_PIPELINE_PRIVATE_H #define BSON_AGGREGATION_PIPELINE_PRIVATE_H typedef struct AggregationStageDefinition AggregationStageDefinition; /* * for nested stage, use this to record its parent stage name */ typedef enum ParentStageName { ParentStageName_NOPARENT = 0, ParentStageName_LOOKUP, ParentStageName_FACET, ParentStageName_UNIONWITH, ParentStageName_INVERSEMATCH, } ParentStageName; /* * Enums to represent all kind of aggregations stages. * Please keep the list sorted within their groups for easier readability */ typedef enum { Stage_Invalid = 0, /* Start internal stages Mongo */ Stage_Internal_InhibitOptimization = 1, /* Start Mongo Public stages */ Stage_AddFields = 10, Stage_Bucket, Stage_BucketAuto, Stage_ChangeStream, Stage_CollStats, Stage_Count, Stage_CurrentOp, Stage_Densify, Stage_Documents, Stage_Facet, Stage_Fill, Stage_GeoNear, Stage_GraphLookup, Stage_Group, Stage_IndexStats, Stage_Limit, Stage_ListLocalSessions, Stage_ListSessions, Stage_Lookup, Stage_Match, Stage_Merge, Stage_Out, Stage_Project, Stage_Redact, Stage_ReplaceRoot, Stage_ReplaceWith, Stage_Sample, Stage_Search, Stage_SearchMeta, Stage_Set, Stage_SetWindowFields, Stage_Skip, Stage_Sort, Stage_SortByCount, Stage_UnionWith, Stage_Unset, Stage_Unwind, Stage_VectorSearch, /* Start of pg_documentdb Custom or internal stages */ Stage_InverseMatch = 100, Stage_LookupUnwind } Stage; /* * Shared context during aggregation pipeline build phase. */ typedef struct { /* The current stage number (used for tagging stage identifiers) */ int stageNum; /* Whether or not a subquery stage should be injected before the next stage */ bool requiresSubQuery; /* If true, allows 1 project transform, then forces a subquery stage. */ bool requiresSubQueryAfterProject; /* Whether the query should retain an expanded target list*/ bool expandTargetList; /* Whether or not the query is a streamable cursor */ bool requiresPersistentCursor; /* The namespace 'db.coll' associated with this query */ const char *namespaceName; /* The current parameter count (Note: Increment this before use) */ int currentParamCount; /* The current Mongo collection */ MongoCollection *mongoCollection; /* the level of nested pipeline for stages that have nested pipelines ($facet/$lookup). */ int nestedPipelineLevel; /* The number of nested levels (incremented by MigrateSubQuery) */ int numNestedLevels; /* The database name associated with this request */ text *databaseNameDatum; /* The collection name associated with this request (if applicable) */ StringView collectionNameView; /* The sort specification that precedes it (if available). * If the stage changes the sort order, this is reset. * BSON_TYPE_EOD if not available. */ bson_value_t sortSpec; /* The path name of the collection, used for filtering of vector search * it is set only when the filter of vector search is specified */ HTAB *requiredFilterPathNameHashSet; /* Whether or not the aggregation query allows direct shard delegation * This allows queries to go directly against a local shard *iff* it's available. * This can be done for base streaming queries. TODO: Investigate whether or not * this can be extended to other types of queries. */ bool allowShardBaseTable; /* * The variable spec expression that preceds it. */ Expr *variableSpec; /* Whether or not the query requires a tailable cursor */ bool requiresTailableCursor; /* * String indicating a standard ICU collation. An example string is "und-u-ks-level1-kc-true". * We parse the Mongo collation spec and covert it to an ICU standard collation string. * This string uniquely identify collation-based string comparison logic by postgres. * See: https://www.postgresql.org/docs/current/collation.html */ const char collationString[MAX_ICU_COLLATION_LENGTH]; /* * Whether or not to apply the optimization transformation on the stages */ bool optimizePipelineStages; /* Whether or not it's a point read query */ bool isPointReadQuery; /*Parent Stage Name*/ ParentStageName parentStageName; } AggregationPipelineBuildContext; typedef struct { /* The bson value of the pipeline spec */ bson_value_t stageValue; /* Definition of internal handlers */ AggregationStageDefinition *stageDefinition; } AggregationStage; /* Core Infra exports */ Query * MutateQueryWithPipeline(Query *query, List *aggregationStages, AggregationPipelineBuildContext *context); Query * MigrateQueryToSubQuery(Query *parse, AggregationPipelineBuildContext *context); Aggref * CreateMultiArgAggregate(Oid aggregateFunctionId, List *args, List *argTypes, ParseState *parseState); List * ExtractAggregationStages(const bson_value_t *pipelineValue, AggregationPipelineBuildContext *context); Query * GenerateBaseTableQuery(text *databaseDatum, const StringView *collectionNameView, pg_uuid_t *collectionUuid, const bson_value_t *indexHint, AggregationPipelineBuildContext *context); Query * GenerateBaseAgnosticQuery(text *databaseDatum, AggregationPipelineBuildContext *context); RangeTblEntry * MakeSubQueryRte(Query *subQuery, int stageNum, int pipelineDepth, const char *prefix, bool includeAllColumns); bool CanInlineLookupPipeline(const bson_value_t *pipeline, const StringView *lookupPath, bool hasLet, pgbson **inlinedPipeline, pgbson **nonInlinedPipeline, bool *pipelineIsValid); void ParseCursorDocument(bson_iter_t *iterator, QueryData *queryData); const char * CreateNamespaceName(text *databaseName, const StringView *collectionName); Query * HandleMatch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleSimpleProjectionStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, const char *stageName, Oid functionOid, Oid (*functionOidWithLet)(void), Oid (*functionOidWithLetAndCollation)(void)); Query * HandleGroup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* Sub-Pipeline related aggregation stages */ Query * HandleFacet(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleLookup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleLookupUnwind(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleGraphLookup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleDocumentsStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleUnionWith(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleInternalInhibitOptimization(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleInverseMatch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* Metadata based query stages */ Query * HandleCollStats(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleIndexStats(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleCurrentOp(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleChangeStream(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); bool CanInlineLookupStageLookup(const bson_value_t *lookupStage, const StringView *lookupPath, bool hasLet); bool CanInlineLookupWithUnwind(const bson_value_t *lookUpStageValue, const bson_value_t *unwindStageValue, bool *isPreserveNullAndEmptyArrays); /* vector search related aggregation stages */ Query * HandleSearch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* output to collection related aggregation pipeline */ Query * HandleMerge(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleOut(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* Native vector search related aggregation stages */ Query * HandleNativeVectorSearch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* Metadata based query generators */ Query * GenerateConfigDatabaseQuery(AggregationPipelineBuildContext *context); bool IsPartitionByFieldsOnShardKey(const pgbson *partitionByFields, const MongoCollection *collection); Expr * GenerateMultiExpressionRepathExpression(List *repathArgs, bool overrideArrayInProjection); Stage GetAggregationStageAtPosition(const List *aggregationStages, int position); /* Helper methods */ inline static Const * MakeTextConst(const char *cstring, uint32_t stringLength) { text *textValue = cstring_to_text_with_len(cstring, stringLength); return makeConst(TEXTOID, -1, DEFAULT_COLLATION_OID, -1, PointerGetDatum(textValue), false, false); } inline static Const * MakeBsonConst(pgbson *pgbson) { return makeConst(BsonTypeId(), -1, InvalidOid, -1, PointerGetDatum(pgbson), false, false); } /* * Inline method for a bool const specifying the isNull attribute. */ inline static Node * MakeBoolValueConst(bool value) { bool isNull = false; return makeBoolConst(value, isNull); } inline static Const * MakeFloat8Const(float8 floatValue) { return makeConst(FLOAT8OID, -1, InvalidOid, sizeof(float8), Float8GetDatum(floatValue), false, true); } /* * Helper function that creates a UNION ALL Set operation statement * that returns a single BSON field. */ inline static SetOperationStmt * MakeBsonSetOpStatement(void) { SetOperationStmt *setOpStatement = makeNode(SetOperationStmt); setOpStatement->all = true; setOpStatement->op = SETOP_UNION; setOpStatement->colCollations = list_make1_oid(InvalidOid); setOpStatement->colTypes = list_make1_oid(BsonTypeId()); setOpStatement->colTypmods = list_make1_int(-1); return setOpStatement; } #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_aggregation_statistics.h000066400000000000000000000011241507310017400304560ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_aggregation_statistics.h * * Exports for the window operator for stage: $setWindowField * *------------------------------------------------------------------------- */ #include "aggregation/bson_aggregation_window_operators.h" bool ParseInputWeightForExpMovingAvg(const bson_value_t *opValue, bson_value_t *inputExpression, bson_value_t *weightExpression, bson_value_t *decimalWeightValue); documentdb-0.108-0/pg_documentdb/include/aggregation/bson_aggregation_window_operators.h000066400000000000000000000017561507310017400317040ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_aggregation_window_operators.h * * Exports for the window operator for stage: $setWindowField * *------------------------------------------------------------------------- */ #ifndef BSON_AGGREGATION_WINDOW_OPERATORS_H #define BSON_AGGREGATION_WINDOW_OPERATORS_H #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" Query * HandleSetWindowFields(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); Query * HandleSetWindowFieldsCore(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, Expr *partitionByExpr, bool enableInternalWindowOperator); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_bucket_auto.h000066400000000000000000000012241507310017400262230ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_bucket_auto.h * * Common declarations of functions for handling $bucketAuto stage. * *------------------------------------------------------------------------- */ #ifndef BSON_BUCKETAUTO_H #define BSON_BUCKETAUTO_H #include "io/bson_core.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" Query * HandleBucketAuto(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_densify.h000066400000000000000000000012061507310017400253570ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_densify.h * * Common declarations of functions for handling $densify stage. * *------------------------------------------------------------------------- */ #ifndef BSON_DENSIFY_H #define BSON_DENSIFY_H #include "io/bson_core.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" Query * HandleDensify(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_positional_query.h000066400000000000000000000015241507310017400273270ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_positional_query.h * * Declarations of functions for the BSON Positional $ operator. * *------------------------------------------------------------------------- */ #ifndef BSON_POSITIONAL_QUERY_H #define BSON_POSITIONAL_QUERY_H typedef struct BsonPositionalQueryData BsonPositionalQueryData; /* * A list of BsonPositionalQueryQual for each * qualifier found within a top level query. */ typedef struct BsonPositionalQueryData { List *queryQuals; } BsonPositionalQueryData; BsonPositionalQueryData * GetPositionalQueryData(const bson_value_t *query); int32_t MatchPositionalQueryAgainstDocument(const BsonPositionalQueryData *data, const pgbson *document); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_project.h000066400000000000000000000136231507310017400253720ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_project.h * * Common declarations of functions for handling bson projection. * *------------------------------------------------------------------------- */ #ifndef BSON_PROJECT_H #define BSON_PROJECT_H #include "io/bson_core.h" #include "aggregation/bson_projection_tree.h" extern PGDLLIMPORT const StringView IdFieldStringView; /* Forward declare the pointer type ( no need to expose the struct layout) */ typedef struct BsonProjectionQueryState BsonProjectionQueryState; typedef struct BsonProjectDocumentFunctions BsonProjectDocumentFunctions; typedef struct ProjectDocumentState ProjectDocumentState; typedef bool (*TryHandleIntermediateArrayNodeFunc)(const BsonIntermediatePathNode *node, ProjectDocumentState *state, bson_iter_t *sourceValue); typedef void *(*InitializePendingProjectionStateFunc)(uint32_t totalPendingProjections); typedef void (*WritePendingProjectionFunc)(pgbson_writer *writer, void *pendingProjections); typedef bool (*SkipUnresolvedIntermediateFieldsFunc)(const BsonIntermediatePathNode *tree); /* * Context for Projection */ typedef struct BsonProjectionContext { /* Whether or not Id should be forcily projected */ bool forceProjectId; /* Whether or not inclusion and exclusion is allowed simultaneously */ bool allowInclusionExclusion; /* Iterator on path spec */ bson_iter_t *pathSpecIter; /* Query spec for positional projection. It all cases this is null when `isFindProjection` is false */ pgbson *querySpec; /* The variable spec for let scenarios if applicable */ const pgbson *variableSpec; /* Collation string for comparison, if applicable */ const char *collationString; } BsonProjectionContext; /* * Common function pointers hooks uses while project wrting stage */ typedef struct BsonProjectDocumentFunctions { /* * Used to handle the intermediate array fields in a projection * e.g. $ projection use the first intermediate array field and applies * the query to find a matching index and projects it */ TryHandleIntermediateArrayNodeFunc tryMoveArrayIteratorFunc; /* * Used in case when some of the projection needs to be written * at the end, this would initialize the state needed to meet the requirement * of such cases * e.g. $elemMatch Projection */ InitializePendingProjectionStateFunc initializePendingProjectionFunc; /* * Used to write the pendingProjection to the main writer at the end */ WritePendingProjectionFunc writePendingProjectionFunc; } BsonProjectDocumentFunctions; /* Per document projection state */ typedef struct ProjectDocumentState { /* Matched document for projection */ pgbson *parentDocument; /* variable context for the current projection. */ const ExpressionVariableContext *variableContext; /* * Whether or not for a $ projection the query is used to evaluate the matching index * This can only be used once by the outermost array for a positional path spec * e.g. {a.b.c.d.$: 1} => If `b` & `d` are both array fields then positional projeciton * is applied on `b` */ bool isPositionalAlreadyEvaluated; /* Whether the projection is exclusion projection */ bool hasExclusion; /* Optional: Bson Project Document stage function hooks */ BsonProjectDocumentFunctions projectDocumentFuncs; /* Pending projections for the document as a whole */ void *pendingProjectionState; /* For projections that needs to avoid projecting for all elements of an intermediate array * e.g. $geoNear updates the document and for a conflicting intermediate array path it just overrides * the complete array and makes it a single nested object * * Document => {a : {b: [{c: 10}, {c: 20}]]}} * Project => { a.b.c: 100 } * Result => { a: {b: {c: 100} } */ bool skipIntermediateArrayFields; } ProjectDocumentState; /* * Cached state for ReplaceRoot and Redact. */ typedef struct BsonReplaceRootRedactState { /* The aggregation expression data */ AggregationExpressionData *expressionData; /* The variable context for let if any */ ExpressionVariableContext *variableContext; } BsonReplaceRootRedactState; const BsonProjectionQueryState * GetProjectionStateForBsonProject( bson_iter_t *projectionSpecIter, bool forceProjectId, bool allowInclusionExclusion, const pgbson * variableSpec); const BsonProjectionQueryState * GetProjectionStateForBsonAddFields( bson_iter_t *projectionSpecIter, const bson_value_t *variableSpec); const BsonProjectionQueryState * GetProjectionStateForBsonUnset(const bson_value_t * unsetValue, bool forceProjectId); void GetBsonValueForReplaceRoot(bson_iter_t *replaceRootIterator, bson_value_t *value); void ValidateReplaceRootElement(const bson_value_t *value); void PopulateReplaceRootExpressionDataFromSpec(BsonReplaceRootRedactState *state, const bson_value_t *pathSpec, pgbson *variableSpec, const char *collationString); void BuildRedactState(BsonReplaceRootRedactState *redactState, const bson_value_t *redactValue, pgbson *variableSpec, const char *collationString); pgbson * ProjectDocumentWithState(pgbson *sourceDocument, const BsonProjectionQueryState *state); pgbson * ProjectReplaceRootDocument(pgbson *document, const AggregationExpressionData *replaceRootExpression, const ExpressionVariableContext *variableContext, bool forceProjectId); /* projection writer functions */ void TraverseObjectAndAppendToWriter(bson_iter_t *parentIterator, const BsonIntermediatePathNode *pathSpecTree, pgbson_writer *writer, bool projectNonMatchingFields, ProjectDocumentState *projectDocState, bool isInNestedArray); bool TryInlineProjection(Node *currentExpr, Oid functionOid, const bson_value_t *projectValue); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_project_operator.h000066400000000000000000000025761507310017400273120ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_project_operator.h * * Common declarations of functions for handling projection operators in find queries * *------------------------------------------------------------------------- */ #ifndef BSON_PROJECT_OPERATOR_H #define BSON_PROJECT_OPERATOR_H #include "postgres.h" #include "operators/bson_expr_eval.h" #include "aggregation/bson_project.h" /* * Function Pointer for handlers of Projection Operators */ typedef void (*ProjectionOpHandlerFunc)(const bson_value_t *sourceValue, const StringView *path, pgbson_writer *writer, ProjectDocumentState *projectDocState, void *state, bool isInNestedArray); /* * Projection Operator Handler Context */ typedef struct ProjectionOpHandlerContext { /* Projection Operator specific handler function */ ProjectionOpHandlerFunc projectionOpHandlerFunc; void *state; } ProjectionOpHandlerContext; /* * Implementation for functions overriding behavior of * tree traversal for Projection for $find. */ extern BuildBsonPathTreeFunctions FindPathTreeFunctions; void * GetPathTreeStateForFind(pgbson *querySpec); int PostProcessStateForFind(BsonProjectDocumentFunctions *projectDocumentFuncs, BuildBsonPathTreeContext *context); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_projection_tree.h000066400000000000000000000074351507310017400271230ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_projection_tree.h * * Common declarations of functions for handling bson path trees for projection. * *------------------------------------------------------------------------- */ #ifndef BSON_PROJECTION_TREE_H #define BSON_PROJECTION_TREE_H #include "aggregation/bson_tree.h" #include "aggregation/bson_positional_query.h" #include "utils/string_view.h" /* * Different stage functions hooks while creating path tree */ typedef struct BuildBsonPathTreeFunctions { /* The function that creates the child leaf node */ CreateLeafNodeFunc createLeafNodeFunc; /* Function that creates the intermediate nodes */ CreateIntermediateNodeFunc createIntermediateNodeFunc; /* Used for processing the field paths in the tree */ StringView (*preprocessPathFunc)(const StringView *path, const bson_value_t *pathSpecValue, bool isOperator, bool *isFindOperator, void *state, bool *skipInclusionExclusionValidation); /* Used to process existing leaf nodes while building the tree */ void (*validateAlreadyExistsNodeFunc)(void *state, const StringView *path, BsonPathNode *node); /* Used to post process leaf nodes once created */ void (*postProcessLeafNodeFunc)(void *state, const StringView *path, BsonPathNode *node, bool *isExclusionIfNoInclusion, bool *hasFieldsForIntermediate); } BuildBsonPathTreeFunctions; /* * Supporting context object for building the bson Path tree. */ typedef struct BuildBsonPathTreeContext { /* IN: allowInclusionExclusion -> sets if the inclusion and exclusion are allowed together */ bool allowInclusionExclusion; /* IN: This flag indicates if expressions should be parsed or treat as constants, i.e: when building the tree for wildcard index spec. */ bool skipParseAggregationExpressions; /* OUT: hasExclusion -> sets if the spec has exclusion of a field */ bool hasExclusion; /* OUT: hasInclusion -> sets if the spec has inclusion of a field */ bool hasInclusion; /* OUT: Whether the tree contains a leaf node with a non constant aggregation expression or not. */ bool hasAggregationExpressions; /* IN: the parse aggregation expression context. */ ParseAggregationExpressionContext parseAggregationContext; /* INOUT: the state of the tree which is used/modified for special find query operators. */ void *pathTreeState; /* Skip if a node already exists */ bool skipIfAlreadyExists; /* IN: Useful functions to handle intermediate stages while building the path tree */ BuildBsonPathTreeFunctions *buildPathTreeFuncs; } BuildBsonPathTreeContext; /* * Default implementation for functions overriding behavior of * tree traversal for Projection. */ extern BuildBsonPathTreeFunctions DefaultPathTreeFuncs; /* * Tree Leaf node for Find Projection operators * with additional state */ typedef struct BsonLeafNodeWithContext { /* The base node for this path */ BsonLeafPathNode base; /* Any additional state for the node */ void *context; } BsonLeafNodeWithContext; BsonIntermediatePathNode * BuildBsonPathTree(bson_iter_t *pathSpecification, BuildBsonPathTreeContext *context, bool forceLeafExpression, bool *hasFields); void MergeBsonPathTree(BsonIntermediatePathNode *root, bson_iter_t *pathSpecification, BuildBsonPathTreeContext *context, bool forceLeafExpression, bool *hasFields); /* * Helper function to cast node into a specific projection leaf node */ inline static const BsonLeafNodeWithContext * CastAsBsonLeafNodeWithContext(const BsonPathNode *toCast) { Assert(NodeType_IsLeaf(toCast->nodeType)); return (const BsonLeafNodeWithContext *) toCast; } #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_query.h000066400000000000000000000020571507310017400250700ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_query.h * * Common declarations of functions for handling bson queries. * *------------------------------------------------------------------------- */ #ifndef BSON_QUERY_H #define BSON_QUERY_H #include "io/bson_core.h" /* The function that is called when dealing with a querySpec on a leaf * query filter (e.g. "a.b" : ) */ typedef void (*ProcessQueryValueFunc)(void *context, const char *path, const bson_value_t *value); typedef void (*ProcessQueryFilterFunc)(void *context); bool TraverseQueryDocumentAndGetId(bson_iter_t *queryDocument, bson_value_t *idValue, bool errorOnConflict, bool *hasNonIdFields, bool *isIdValueCollationAware); void TraverseQueryDocumentAndProcess(bson_iter_t *queryDocument, void *context, ProcessQueryValueFunc processValueFunc, ProcessQueryFilterFunc processFilterFunc, bool isUpsert); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_query_common.h000066400000000000000000000017401507310017400264360ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_query_common.h * * Private and common declarations of functions for handling bson query * Shared across runtime and index implementations. * *------------------------------------------------------------------------- */ #ifndef BSON_QUERY_COMMON_H #define BSON_QUERY_COMMON_H #include "io/bson_core.h" #include "utils/documentdb_errors.h" /* * This struct defines the parameters for a range query. */ typedef struct DollarRangeParams { bson_value_t minValue; bson_value_t maxValue; bool isMinInclusive; bool isMaxInclusive; bool isFullScan; int32_t orderScanDirection; bool isElemMatch; bson_value_t elemMatchValue; } DollarRangeParams; DollarRangeParams * ParseQueryDollarRange(pgbsonelement *filterElement); void InitializeQueryDollarRange(pgbsonelement *filterElement, DollarRangeParams *params); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_sorted_accumulator.h000066400000000000000000000052341507310017400276220ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/bson/bson_sorted_accumulator.h * * Common declarations related to custom aggregates for group by * accumulator with sort specification: * first (implicit) * last (implicit) * top (explicit) * bottom (explicit) * firstN (implicit) * lastN (implicit) * topN (explicit) * bottomN (explicit) *------------------------------------------------------------------------- */ #ifndef BSON_SORTED_ACCUMULATOR_H #define BSON_SORTED_ACCUMULATOR_H #include "io/bson_core.h" /* --------------------------------------------------------- */ /* Data-types */ /* --------------------------------------------------------- */ typedef struct BsonOrderAggValue { /* The actual value being returned for this result*/ pgbson *value; /* An array of bsons of size numSortKeys computed * by applying the sort spec on an input document. These * bsons are value from the sort keys for ordering documents. * A maximum of 32 sort keys is allowed. */ Datum sortKeyValues[32]; } BsonOrderAggValue; typedef struct BsonOrderAggState { /* The values to be returned as aggregation result. * Array of numAggValues number of elements. */ BsonOrderAggValue **currentResult; /* The number of values to be returned by the aggregation result * 1 for first/last. N for firstN/lastN. */ int64 numAggValues; /* The number of values currently in results */ int64 currentCount; /* The number of sort keys (length of sortKeys) */ int numSortKeys; /* up to 32; */ /* An array of size numSortKeys indicating the * direction of sorting (ASC = true, DESC = false) */ bool sortDirections[32]; /* Input expression spec that will be applied against each * sorted pgbson value on this struct. */ pgbson *inputExpression; } BsonOrderAggState; /* Handles serialization of state */ bytea * SerializeOrderState(BsonOrderAggState *state); void DeserializeOrderState(bytea *bytes, BsonOrderAggState *state); /* * Transition/Combine/Final functions for accumulators * invertSort is 'false' for ascending and 'true' for descending. * isSingle is 'false' if there is an N param (i.e. firstN/LastN) * and 'true' if there is no N param (i.e. first/last). */ Datum BsonOrderTransition(PG_FUNCTION_ARGS, bool invertSort, bool isSingle, bool storeInputExpression); Datum BsonOrderTransitionOnSorted(PG_FUNCTION_ARGS, bool invertSort, bool isSingle); Datum BsonOrderCombine(PG_FUNCTION_ARGS, bool invertSort); Datum BsonOrderFinal(PG_FUNCTION_ARGS, bool isSingle, bool invert); Datum BsonOrderFinalOnSorted(PG_FUNCTION_ARGS, bool isSingle); #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_tree.h000066400000000000000000000253011507310017400246570ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_tree.h * * Common declarations of functions for handling bson path trees. * *------------------------------------------------------------------------- */ #include "aggregation/bson_tree_common.h" #include "utils/documentdb_errors.h" #include "operators/bson_expression.h" #ifndef BSON_TREE_H #define BSON_TREE_H /* Forward declaration of data types */ struct BsonPathNode; struct BsonIntermediatePathNode; struct BsonLeafPathNode; struct BsonLeafArrayWithFieldPathNode; /* * Base PathNode that all types derive from. * For derived types, this must be the first field. */ typedef struct BsonPathNode { /* The type of node for this field: whether it is a path * inclusion/exclusion/field or a tree intermediate node * leading to a field path */ const NodeType nodeType; /* the 'current' field path for projection * This is the non-dotted field path at the current level of * the projection tree. * * For example, for {"a": {"b.c": {"d.e.f": 1}}}, this would be equal to * "d", "e", and "f" for nodes representing "d", "e" and "f". * */ const StringView field; /* * The parent node for this node */ struct BsonIntermediatePathNode *const parent; /* * The siblings of this node in the tree. */ struct BsonPathNode *next; } BsonPathNode; /* * Struct that holds data about child nodes * for node types that have child nodes. * Currently this is LeafWithArray and * Intermediate. * * This is an internal structure and should * *NEVER* be accessed directly. */ typedef struct ChildNodeData { /* The number of children that this field has */ uint32_t numChildren; /* * children points to the tail of the intermediate node. * Given a tree "a": { "b": 1, "c": 1 }, children will point to b * and b.next will point to c. * The first child is tree->children->next. * DO NOT Enumerate the children directly. * DO NOT add to the children directly. */ BsonPathNode *children; } ChildNodeData; /* Data for an intermediate path node in the tree */ typedef struct BsonIntermediatePathNode { /* The base node for this path */ BsonPathNode baseNode; /* Whether the children of the node has at least 1 expression field */ bool hasExpressionFieldsInChildren; /* Child data for the intermediate node. * Do not touch this directly. * Use foreach_child to enumerate */ ChildNodeData childData; } BsonIntermediatePathNode; /* Data for an intermediate path node in the tree */ typedef struct BsonLeafPathNode { /* The base node for this path */ BsonPathNode baseNode; /* the data of the field (if it is a constant and its value, or an operator, field expression, etc.) */ AggregationExpressionData fieldData; } BsonLeafPathNode; /* Data for a leaf array path node in the tree */ typedef struct BsonLeafArrayWithFieldPathNode { /* The base node for this path */ BsonLeafPathNode leafData; /* Child data for the intermediate node. * Do not touch this directly. * Use foreach_array_child to enumerate */ ChildNodeData arrayChild; } BsonLeafArrayWithFieldPathNode; /* * Function that creates a leaf node. */ typedef BsonLeafPathNode *(*CreateLeafNodeFunc)(const StringView *path, const char *relativePath, void *state); /* * Function that creates an intermediate node. */ typedef BsonIntermediatePathNode *(*CreateIntermediateNodeFunc)(const StringView *path, const char *relativePath, void *state); const BsonLeafPathNode * TraverseDottedPathAndGetOrAddLeafFieldNode(const StringView *path, const bson_value_t * value, BsonIntermediatePathNode *tree, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, bool *nodeCreated, ParseAggregationExpressionContext *parseContext); const BsonLeafPathNode * TraverseDottedPathAndAddLeafFieldNode(const StringView *path, const bson_value_t * value, BsonIntermediatePathNode *tree, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext *parseContext); const BsonLeafPathNode * TraverseDottedPathAndAddLeafValueNode(const StringView *path, const bson_value_t *value, BsonIntermediatePathNode * tree, CreateLeafNodeFunc createFunc, CreateIntermediateNodeFunc intermediateFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext *parseContext); BsonLeafArrayWithFieldPathNode * TraverseDottedPathAndAddLeafArrayNode(const StringView *path, BsonIntermediatePathNode *tree, CreateIntermediateNodeFunc intermediateFunc, bool treatLeafDataAsConstant); const BsonPathNode * TraverseDottedPathAndGetOrAddField(const StringView *path, const bson_value_t *value, BsonIntermediatePathNode *tree, CreateIntermediateNodeFunc createIntermediateFunc, CreateLeafNodeFunc createLeafFunc, bool treatLeafNodeAsConstant, void *nodeCreationState, bool *nodeCreated, ParseAggregationExpressionContext *parseContext); const BsonPathNode * TraverseDottedPathAndGetOrAddValue(const StringView *path, const bson_value_t *value, BsonIntermediatePathNode *tree, CreateIntermediateNodeFunc createIntermediateFunc, CreateLeafNodeFunc createLeafFunc, bool treatLeafNodeAsConstant, void *nodeCreationState, bool *nodeCreated, ParseAggregationExpressionContext *parseContext); BsonLeafPathNode * BsonDefaultCreateLeafNode(const StringView *fieldPath, const char *relativePath, void *state); BsonIntermediatePathNode * BsonDefaultCreateIntermediateNode(const StringView *fieldPath, const char *relativePath, void *state); void ResetNodeWithField(const BsonLeafPathNode *baseLeafNode, const char *relativePath, const bson_value_t *value, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext *parseContext); void ResetNodeWithValue(const BsonLeafPathNode *baseLeafNode, const char *relativePath, const bson_value_t *value, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext *parseContext); void FreeTree(BsonIntermediatePathNode *root); const BsonPathNode * ResetNodeWithFieldAndState(const BsonLeafPathNode *baseLeafNode, const char *relativePath, const bson_value_t *value, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext * parseContext, void *leafState); const BsonPathNode * ResetNodeWithValueAndState(const BsonLeafPathNode *baseLeafNode, const char *relativePath, const bson_value_t *value, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext * parseContext, void *leafState); const BsonLeafPathNode * AddValueNodeToLeafArrayWithField( BsonLeafArrayWithFieldPathNode *leafArrayField, const char *relativePath, int index, const bson_value_t *leafValue, CreateLeafNodeFunc createFunc, bool treatLeafDataAsConstant, ParseAggregationExpressionContext *parseContext); void BuildTreeFromPgbson(BsonIntermediatePathNode *tree, pgbson *document, ParseAggregationExpressionContext *parseContext); /* * Helper function to create the Root node of a Bson Path Tree. */ inline static BsonIntermediatePathNode * MakeRootNode() { return palloc0(sizeof(BsonIntermediatePathNode)); } /* * Evaluates to true when the BsonPathNode represents an intermediate path node. */ inline static bool IsIntermediateNode(const BsonPathNode *node) { return node->nodeType == NodeType_Intermediate; } /* * Returns true if the BsonPathNode is an intermediate node * and has a field in its children. */ inline static bool IsIntermediateNodeWithField(const BsonPathNode *node) { return IsIntermediateNode(node) && ((const BsonIntermediatePathNode *) node)-> hasExpressionFieldsInChildren; } /* * Returns true if the BsonPathNode is an intermediate node * and has at least 1 child node. */ inline static bool IntermediateNodeHasChildren(const BsonIntermediatePathNode *intermediateNode) { return intermediateNode->childData.numChildren > 0; } /* * Convenience cast functions to get specific node types */ inline static const BsonIntermediatePathNode * CastAsIntermediateNode(const BsonPathNode *toCast) { Assert(IsIntermediateNode(toCast)); return (const BsonIntermediatePathNode *) toCast; } inline static const BsonLeafPathNode * CastAsLeafNode(const BsonPathNode *toCast) { Assert(NodeType_IsLeaf(toCast->nodeType)); return (const BsonLeafPathNode *) toCast; } inline static const BsonLeafArrayWithFieldPathNode * CastAsLeafArrayFieldNode(const BsonPathNode *toCast) { Assert(toCast->nodeType == NodeType_LeafWithArrayField); return (const BsonLeafArrayWithFieldPathNode *) toCast; } #define foreach_child_common(node, parent, childAccessor, castFunc) node = \ parent->childAccessor.children == NULL ? NULL : \ (castFunc) (parent->childAccessor.children->next); \ for (uint32_t _doNotUseMacroTreeCounter = 0; \ node != NULL && (_doNotUseMacroTreeCounter < parent->childAccessor.numChildren); \ _doNotUseMacroTreeCounter++, node = (castFunc) (((BsonPathNode *) node)->next)) /* * Macros that help enumerate intermediate node's children. */ #ifdef BSON_TREE_PRIVATE #define foreach_child(node, parent) foreach_child_common(node, parent, childData, \ BsonPathNode *) #define foreach_array_child(node, parent) foreach_child_common(node, parent, arrayChild, \ BsonLeafPathNode *) #else #define foreach_child(node, parent) foreach_child_common(node, parent, childData, const \ BsonPathNode *) #define foreach_array_child(node, parent) foreach_child_common(node, parent, arrayChild, \ const BsonLeafPathNode *) #endif #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_tree_common.h000066400000000000000000000036071507310017400262340ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_tree_common.h * * Common declarations of functions for handling bson path trees. * *------------------------------------------------------------------------- */ #include "io/bson_core.h" #include "utils/string_view.h" #ifndef BSON_TREE_COMMON_H #define BSON_TREE_COMMON_H #define LEAF_NODE_BASE 0x80 /* * Node types for various BsonPathNodes * Categories: * 0x80+ are all leaf nodes (not intermediate) */ typedef enum NodeType { /* Default setting assigned for NodeType */ NodeType_None = 0, /* a non-leaf tree node * in a projection a.b.c.d, 'a.b.c' are considered * intermediate nodes */ NodeType_Intermediate = 0x1, /* A leaf tree that contains a * path inclusion (if the path exists, add it to * the target document): e.g. 'a.b': 1 */ NodeType_LeafIncluded = LEAF_NODE_BASE, /* A leaf tree that contains a * path exclusion (if the path exists, actively do not add it to * the target document): e.g. 'a.b': 0 */ NodeType_LeafExcluded = LEAF_NODE_BASE + 0x1, /* A leaf tree that contains an * expression which can be a static field, or a path, or operator * expression : e.g. 'a.b': '$c.1' */ NodeType_LeafField = LEAF_NODE_BASE + 0x2, /* * An effective leaf node, in a sense that once we are at this node, * we can stop traversing and start writing values. However, * the values are a set of array elements that are stored as child nodes. */ NodeType_LeafWithArrayField = LEAF_NODE_BASE + 0x3, /* * A leaf node with context, that can help in storing misc operators states for narrow cases. * e.g. $ positional, $slice and $elemMatch projection operators etc. */ NodeType_LeafFieldWithContext = LEAF_NODE_BASE + 0x4, } NodeType; #define NodeType_IsLeaf(x) ((x & LEAF_NODE_BASE) != 0) #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_tree_private.h000066400000000000000000000065521507310017400264200ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_tree_private.h * * Private declarations functions used for creating the Bson trees * *------------------------------------------------------------------------- */ #ifndef BSON_TREE_PRIVATE #error Do not import this header file. Import bson_tree.h / bson_projection_tree.h instead #endif #ifndef BSON_TREE_PRIVATE_H #define BSON_TREE_PRIVATE_H #include "aggregation/bson_tree.h" #include "aggregation/bson_tree_common.h" #include "utils/error_utils.h" #include "utils/string_view.h" BsonPathNode * GetOrAddChildNode(BsonIntermediatePathNode *tree, const char *relativePath, const StringView *fieldPath, CreateLeafNodeFunc createFunc, CreateIntermediateNodeFunc createIntermediateNodeFunc, NodeType childNodeType, bool replaceExistingNodes, void *nodeCreationState, bool *alreadyExists); void EnsureValidFieldPathString(const StringView *fieldPath); BsonPathNode * TraverseDottedPathAndGetNode(const StringView *path, BsonIntermediatePathNode *tree, bool hasFieldForIntermediateNode, CreateLeafNodeFunc createFunc, CreateIntermediateNodeFunc createIntermediateNodeFunc, NodeType leafNodeType, bool replaceExistingNodes, void *nodeCreationState, bool *alreadyExists); bool ValidateAndSetLeafNodeData(BsonPathNode *childNode, const bson_value_t *value, const StringView *relativePath, bool treatAsConstantExpression, ParseAggregationExpressionContext *parseContext); bool TrySetIntermediateNodeData(BsonPathNode *node, const StringView *relativePath, bool hasFields); void AddChildToTree(ChildNodeData *childData, BsonPathNode *childNode); void ReplaceTreeInNodeCore(BsonPathNode *previousNode, BsonPathNode *baseNode, BsonPathNode *newNode); NodeType DetermineChildNodeType(const bson_value_t *value, bool forceLeafExpression); /* * Given a Node pointed to by childNode, initializes the base data * for the base PathNode. */ inline static void SetBasePathNodeData(BsonPathNode *childNode, NodeType finalNodeType, const StringView *fieldPath, BsonIntermediatePathNode *tree) { BsonPathNode baseNode = { .nodeType = finalNodeType, .field = *fieldPath, .parent = tree, .next = NULL }; memcpy(childNode, &baseNode, sizeof(BsonPathNode)); } /* * Helper method that throws the Path collision error on intermediate node mismatch. */ inline static void pg_attribute_noreturn() ThrowErrorOnIntermediateMismatch(BsonPathNode * node, const StringView * relativePath) { int errorCode = ERRCODE_DOCUMENTDB_LOCATION31250; StringInfo errorMessageStr = makeStringInfo(); appendStringInfo(errorMessageStr, "Collision detected in specified path %.*s", relativePath->length, relativePath->string); if (node->field.length < relativePath->length) { errorCode = ERRCODE_DOCUMENTDB_LOCATION31249; StringView substring = StringViewSubstring(relativePath, node->field.length + 1); appendStringInfo(errorMessageStr, " remaining portion %.*s", substring.length, substring.string); } ereport(ERROR, (errcode(errorCode), errmsg("%s", errorMessageStr->data))); } #endif documentdb-0.108-0/pg_documentdb/include/aggregation/bson_tree_write.h000066400000000000000000000035761507310017400261030ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_tree_write.h * * Common declarations of functions to write components of a tree. * *------------------------------------------------------------------------- */ #include "aggregation/bson_tree_common.h" #ifndef BSON_TREE_WRITE_H #define BSON_TREE_WRITE_H /* Forward declaration of data types */ /* Hook function that returns true if the node should be skipped * when writing a tree to a writer. */ typedef bool (*FilterNodeForWriteFunc)(void *state, int index); /* The write context holding the function hooks and current * write state that is used to write the tree. */ typedef struct WriteTreeContext { /* Pointer to a state that is passed to the filter function. */ void *state; /* Callback function to determine whether the node should be skipped */ FilterNodeForWriteFunc filterNodeFunc; /* Whether we should write null when a path expression is found and the path is undefined on the source document. */ bool isNullOnEmpty; } WriteTreeContext; void TraverseTreeAndWriteFieldsToWriter(const BsonIntermediatePathNode *parentNode, pgbson_writer *writer, pgbson *parentDocument, WriteTreeContext *context, const ExpressionVariableContext *variableContext); void WriteLeafArrayFieldToWriter(pgbson_writer *writer, const BsonPathNode *child, pgbson *document, const ExpressionVariableContext *variableContext); void AppendLeafArrayFieldChildrenToWriter(pgbson_array_writer *arrayWriter, const BsonLeafArrayWithFieldPathNode *leafArrayNode, pgbson *document, const ExpressionVariableContext *variableContext); void TraverseTreeAndWrite(const BsonIntermediatePathNode *parentNode, pgbson_writer *writer, pgbson *parentDocument); #endif documentdb-0.108-0/pg_documentdb/include/api_hooks.h000066400000000000000000000155361507310017400223750ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/api_hooks.h * * Exports related to hooks for the public API surface that enable distribution. * *------------------------------------------------------------------------- */ #ifndef EXTENSION_API_HOOKS_H #define EXTENSION_API_HOOKS_H #include #include "api_hooks_common.h" #include "metadata/collection.h" /* Section: General Extension points */ /* * Returns true if the current Postgres server is a Query Coordinator * that also owns the metadata management of schema (DDL). */ bool IsMetadataCoordinator(void); /* * Runs a command on the MetadataCoordinator if the current node is not a * Metadata Coordinator. The response is returned as a "record" struct * with the nodeId responding, whether or not the command succeeded and * the response datum serialized as a string. * If success, then this is the response datum in text format. * If failed, then this contains the error string from the failure. */ DistributedRunCommandResult RunCommandOnMetadataCoordinator(const char *query); /* * Runs a query via SPI with commutative writes on for distributed scenarios. * Returns the Datum returned by the executed query. */ Datum RunQueryWithCommutativeWrites(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, int expectedSPIOK, bool *isNull); /* * Sets up the system to allow nested distributed query execution for the current * transaction scope. * Note: This should be used very cautiously in any place where data correctness is * required. */ void RunMultiValueQueryWithNestedDistribution(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, bool readOnly, int expectedSPIOK, Datum *datums, bool *isNull, int numValues); /* * Sets up the system to allow sequential execution for commands the current * transaction scope. * Note: This should be used for DDL commands. */ Datum RunQueryWithSequentialModification(const char *query, int expectedSPIOK, bool *isNull); /* * Whether or not the the base tables have sharding with distribution (true if DistributePostgresTable * is run). * the documents table name and the substring where the collectionId was found is provided as an input. */ bool IsShardTableForDocumentDbTable(const char *relName, const char *numEndPointer); /* Section: Create Table Extension points */ /* * Distributes a given postgres table with the provided distribution column. * Optionally supports colocating the distributed table with another distributed table. * Returns the distribution column used (may be equal to the one passed on or NULL). * shardCount: the number of shards or 0 if unspecified and sharded. * For unsharded, specify 0. */ const char * DistributePostgresTable(const char *postgresTable, const char *distributionColumn, const char *colocateWith, int shardCount); /* * Entrypoint to modify a list of column names for queries * For a base RTE (table) */ List * ModifyTableColumnNames(List *tableColumns); /* * Create users with external identity provider */ bool CreateUserWithExternalIdentityProvider(const char *userName, char *pgRole, bson_value_t customData); /* * Drop users with external identity provider */ bool DropUserWithExternalIdentityProvider(const char *userName); /* * Verify if the user is external */ bool IsUserExternal(const char *userName); /* * Get user info from external identity provider */ const pgbson * GetUserInfoFromExternalIdentityProvider(const char *userName); /* * Default password validation implementation * Returns true if password is valid, false otherwise */ bool IsPasswordValid(const char *username, const char *password); /* * Default username validation implementation * Returns true if username is valid, false otherwise */ bool IsUsernameValid(const char *username); /* * Hook for handling colocation of tables */ void HandleColocation(MongoCollection *collection, const bson_value_t *colocationOptions); /* * Mutate's listCollections query generation for distribution data. * This is an optional hook and can manage listCollection to update shardCount * and colocation information as required. Noops for single node. */ Query * MutateListCollectionsQueryForDistribution(Query *cosmosMetadataQuery); /* * Mutates the shards query for handling distributed scenario. */ Query * MutateShardsQueryForDistribution(Query *metadataQuery); /* * Mutates the chunks query for handling distributed scenario. */ Query * MutateChunksQueryForDistribution(Query *cosmosMetadataQuery); /* * Given a table OID, if the table is not the actual physical shard holding the data (say in a * distributed setup), tries to return the full shard name of the actual table if it can be found locally * or NULL otherwise (e.g. for ApiDataSchema.documents_1 returns ApiDataSchema.documents_1_12341 or NULL, or "") * NULL implies that the request can be tried again. "" implies that the shard cannot be resolved locally. */ const char * TryGetShardNameForUnshardedCollection(Oid relationOid, uint64 collectionId, const char *tableName); const char * GetDistributedApplicationName(void); /* * This checks whether the current server version supports ntoreturn spec. */ bool IsNtoReturnSupported(void); /* * Returns if the change stream feature is enabled. */ bool IsChangeStreamFeatureAvailableAndCompatible(void); /* * Ensure the given metadata catalog table is replicated. */ bool EnsureMetadataTableReplicated(const char *tableName); /* * The hook allows the extension to do any additional setup * after the cluster has been initialized or upgraded. */ void PostSetupClusterHook(bool isInitialize, bool (shouldUpgradeFunc(void *, int, int, int)), void *state); /* * Hook for customizing the validation of vector query spec. */ typedef struct VectorSearchOptions VectorSearchOptions; void TryCustomParseAndValidateVectorQuerySpec(const char *key, const bson_value_t *value, VectorSearchOptions *vectorSearchOptions); char * TryGetExtendedVersionRefreshQuery(void); void AllowNestedDistributionInCurrentTransaction(void); void GetShardIdsAndNamesForCollection(Oid relationOid, const char *tableName, Datum **shardOidArray, Datum **shardNameArray, int32_t *shardCount); const char * GetPidForIndexBuild(void); const char * TryGetIndexBuildJobOpIdQuery(void); char * TryGetCancelIndexBuildQuery(int32_t indexId, char cmdType); bool ShouldScheduleIndexBuildJobs(void); List * GetShardIndexOids(uint64_t collectionId, int indexId, bool ignoreMissing); void UpdatePostgresIndexWithOverride(uint64_t colectionId, int indexId, bool hidden, void (*default_update)(uint64_t, int, bool)); #endif documentdb-0.108-0/pg_documentdb/include/api_hooks_common.h000066400000000000000000000016461507310017400237420ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/api_hooks.h * * Exports related to hooks for the public API surface that enable distribution. * *------------------------------------------------------------------------- */ #ifndef EXTENSION_API_HOOKS_COMMON_H #define EXTENSION_API_HOOKS_COMMON_H #include #include "io/bson_core.h" /* * Represents a single row result that is * executed on a remote node. */ typedef struct DistributedRunCommandResult { /* The node that responded for the row */ int nodeId; /* Whether or not the node succeeded in running the command */ bool success; /* the response (string error, or string coerced value) */ text *response; } DistributedRunCommandResult; /* Private: Feature flag for update tracking */ typedef struct BsonUpdateTracker BsonUpdateTracker; #endif documentdb-0.108-0/pg_documentdb/include/api_hooks_def.h000066400000000000000000000234531507310017400232100ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/api_hooks_def.h * * Definition of hooks for the extension that allow for handling * distribution type scenarios. These can be overriden to implement * custom distribution logic. * *------------------------------------------------------------------------- */ #ifndef EXTENSION_API_HOOKS_DEF_H #define EXTENSION_API_HOOKS_DEF_H #include "api_hooks_common.h" #include #include #include /* Section: General Extension points */ /* * Returns true if the current Postgres server is a Query Coordinator * that also owns the metadata management of schema (DDL). */ typedef bool (*IsMetadataCoordinator_HookType)(void); extern IsMetadataCoordinator_HookType is_metadata_coordinator_hook; /* * Indicates whether the Change Stream feature is currently enabled */ typedef bool (*IsChangeStreamEnabledAndCompatible)(void); extern IsChangeStreamEnabledAndCompatible is_changestream_enabled_and_compatible_hook; /* * Runs a command on the MetadataCoordinator if the current node is not a * Metadata Coordinator. The response is returned as a "record" struct * with the nodeId responding, whether or not the command succeeded and * the response datum serialized as a string. * If success, then this is the response datum in text format. * If failed, then this contains the error string from the failure. */ typedef DistributedRunCommandResult (*RunCommandOnMetadataCoordinator_HookType)(const char * query); extern RunCommandOnMetadataCoordinator_HookType run_command_on_metadata_coordinator_hook; /* * Runs a query via SPI with commutative writes on for distributed scenarios. * Returns the Datum returned by the executed query. */ typedef Datum (*RunQueryWithCommutativeWrites_HookType)(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, int expectedSPIOK, bool *isNull); extern RunQueryWithCommutativeWrites_HookType run_query_with_commutative_writes_hook; /* * Runs a query via SPI with sequential shard execution for distributed scenarios * Returns the Datum returned by the executed query. */ typedef Datum (*RunQueryWithSequentialModification_HookType)(const char *query, int expectedSPIOK, bool *isNull); extern RunQueryWithSequentialModification_HookType run_query_with_sequential_modification_mode_hook; /* Section: Create Table Extension points */ /* * Distributes a given postgres table with the provided distribution column. * Optionally supports colocating the distributed table with another distributed table. */ typedef const char *(*DistributePostgresTable_HookType)(const char *postgresTable, const char *distributionColumn, const char *colocateWith, int shardCount); extern DistributePostgresTable_HookType distribute_postgres_table_hook; /* * Entrypoint to modify a list of column names for queries * For a base RTE (table) */ typedef List *(*ModifyTableColumnNames_HookType)(List *tableColumns); extern ModifyTableColumnNames_HookType modify_table_column_names_hook; /* * Creates a user using an external identity provider */ typedef bool (*CreateUserWithExernalIdentityProvider_HookType)(const char *userName, char *pgRole, bson_value_t customData); extern CreateUserWithExernalIdentityProvider_HookType create_user_with_exernal_identity_provider_hook; /* * Drops a user using an external identity provider */ typedef bool (*DropUserWithExernalIdentityProvider_HookType)(const char *userName); extern DropUserWithExernalIdentityProvider_HookType drop_user_with_exernal_identity_provider_hook; /* * Method to verify if a user is native */ typedef bool (*IsUserExternal_HookType)(const char *userName); extern IsUserExternal_HookType is_user_external_hook; /* * Method to get user info from external identity provider */ typedef const pgbson *(*GetUserInfoFromExternalIdentityProvider_HookType)(); extern GetUserInfoFromExternalIdentityProvider_HookType get_user_info_from_external_identity_provider_hook; /* Method for username validation */ typedef bool (*UserNameValidation_HookType)(const char *username); extern UserNameValidation_HookType username_validation_hook; /* Method for password validation */ typedef bool (*PasswordValidation_HookType)(const char *username, const char *password); extern PasswordValidation_HookType password_validation_hook; /* * Hook for enabling running a query with nested distribution enabled. */ typedef void (*RunQueryWithNestedDistribution_HookType)(const char *query, int nArgs, Oid *argTypes, Datum *argDatums, char *argNulls, bool readOnly, int expectedSPIOK, Datum *datums, bool *isNull, int numValues); extern RunQueryWithNestedDistribution_HookType run_query_with_nested_distribution_hook; typedef void (*AllowNestedDistributionInCurrentTransaction_HookType)(void); extern AllowNestedDistributionInCurrentTransaction_HookType allow_nested_distribution_in_current_transaction_hook; typedef bool (*IsShardTableForDocumentDbTable_HookType)(const char *relName, const char *numEndPointer); extern IsShardTableForDocumentDbTable_HookType is_shard_table_for_documentdb_table_hook; typedef void (*HandleColocation_HookType)(MongoCollection *collection, const bson_value_t *colocationOptions); extern HandleColocation_HookType handle_colocation_hook; typedef Query *(*RewriteListCollectionsQueryForDistribution_HookType)(Query *query); extern RewriteListCollectionsQueryForDistribution_HookType rewrite_list_collections_query_hook; typedef Query *(*RewriteConfigQueryForDistribution_HookType)(Query *query); extern RewriteConfigQueryForDistribution_HookType rewrite_config_shards_query_hook; extern RewriteConfigQueryForDistribution_HookType rewrite_config_chunks_query_hook; typedef const char *(*TryGetShardNameForUnshardedCollection_HookType)(Oid relationOid, uint64 collectionId, const char * tableName); extern TryGetShardNameForUnshardedCollection_HookType try_get_shard_name_for_unsharded_collection_hook; /* * Hook for creating an update tracker if tracking is enabled. */ typedef BsonUpdateTracker *(*CreateBsonUpdateTracker_HookType)(void); extern CreateBsonUpdateTracker_HookType create_update_tracker_hook; typedef pgbson *(*BuildUpdateDescription_HookType)(BsonUpdateTracker *); extern BuildUpdateDescription_HookType build_update_description_hook; /* Update tracker method hooks */ typedef void (*NotifyRemovedField_HookType)(BsonUpdateTracker *tracker, const char *relativePath); extern NotifyRemovedField_HookType notify_remove_field_hook; typedef void (*NotifyUpdatedField_HookType)(BsonUpdateTracker *tracker, const char *relativePath, const bson_value_t *value); extern NotifyUpdatedField_HookType notify_updated_field_hook; typedef void (*NotifyUpdatedFieldPathView_HookType)(BsonUpdateTracker *tracker, const StringView *relativePath, const bson_value_t *value); extern NotifyUpdatedFieldPathView_HookType notify_updated_field_path_view_hook; typedef const char *(*GetDistributedApplicationName_HookType)(void); extern GetDistributedApplicationName_HookType get_distributed_application_name_hook; typedef bool (*IsNtoReturnSupported_HookType)(void); extern IsNtoReturnSupported_HookType is_n_to_return_supported_hook; typedef bool (*EnsureMetadataTableReplicated_HookType)(const char *); extern EnsureMetadataTableReplicated_HookType ensure_metadata_table_replicated_hook; typedef void (*PostSetupCluster_HookType)(bool, bool (shouldUpgradeFunc(void *, int, int, int)), void *); extern PostSetupCluster_HookType post_setup_cluster_hook; /* * Hook for customizing the validation of vector query spec. */ typedef struct VectorSearchOptions VectorSearchOptions; typedef void (*TryCustomParseAndValidateVectorQuerySpec_HookType)(const char *key, const bson_value_t *value, VectorSearchOptions * vectorSearchOptions); extern TryCustomParseAndValidateVectorQuerySpec_HookType try_custom_parse_and_validate_vector_query_spec_hook; extern bool DefaultInlineWriteOperations; extern bool ShouldUpgradeDataTables; typedef char *(*TryGetExtendedVersionRefreshQuery_HookType)(void); extern TryGetExtendedVersionRefreshQuery_HookType try_get_extended_version_refresh_query_hook; typedef void (*GetShardIdsAndNamesForCollection_HookType)(Oid relationOid, const char *tableName, Datum **shardOidArray, Datum **shardNameArray, int32_t *shardCount); extern GetShardIdsAndNamesForCollection_HookType get_shard_ids_and_names_for_collection_hook; typedef const char *(*GetPidForIndexBuild_HookType)(void); extern GetPidForIndexBuild_HookType get_pid_for_index_build_hook; typedef const char *(*TryGetIndexBuildJobOpIdQuery_HookType)(void); extern TryGetIndexBuildJobOpIdQuery_HookType try_get_index_build_job_op_id_query_hook; typedef char *(*TryGetCancelIndexBuildQuery_HookType)(int32_t indexId, char cmdType); extern TryGetCancelIndexBuildQuery_HookType try_get_cancel_index_build_query_hook; typedef bool (*ShouldScheduleIndexBuilds_HookType)(); extern ShouldScheduleIndexBuilds_HookType should_schedule_index_builds_hook; typedef List *(*GettShardIndexOids_HookType)(uint64_t collectionId, int indexId, bool ignoreMissing); extern GettShardIndexOids_HookType get_shard_index_oids_hook; typedef void (*UpdatePostgresIndex_HookType)(uint64_t collectionId, int indexId, bool hidden); extern UpdatePostgresIndex_HookType update_postgres_index_hook; #endif documentdb-0.108-0/pg_documentdb/include/background_worker/000077500000000000000000000000001507310017400237465ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/background_worker/background_worker_job.h000066400000000000000000000042061507310017400304630ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/background_worker/background_worker_job.h * * Common declarations related to pg_documentdb background worker. * *------------------------------------------------------------------------- */ #include #ifndef DOCUMENTS_BACKGROUND_WORKER_JOB_H #define DOCUMENTS_BACKGROUND_WORKER_JOB_H /* * Background worker job command. */ typedef struct { /* * Function/Procedure schema. */ const char *schema; /* * Function/Procedure name. */ const char *name; } BackgroundWorkerJobCommand; /* * Background worker job argument. */ typedef struct { /* * Argument Oid. */ Oid argType; /* * Argument value as a string. */ const char *argValue; /* * Boolean for null argument. */ bool isNull; } BackgroundWorkerJobArgument; /* * Define a hook that clients can supply. This can be used to dynamically * change the schedule interval of the job. */ typedef int (*get_schedule_interval_in_seconds_hook_type)(void); /* Background worker job definition */ typedef struct { /* Job id. */ int jobId; /* Job name, this will be used in log emission. */ const char *jobName; /* Pair of schema and function/procedure name to be executed. */ BackgroundWorkerJobCommand command; /* * Argument for the command. The number of arguments * is currently limited to 1. */ BackgroundWorkerJobArgument argument; /* * Hook to get the schedule interval in seconds. * This can be used to dynamically change the schedule interval. */ get_schedule_interval_in_seconds_hook_type get_schedule_interval_in_seconds_hook; /* * Command timeout in seconds. The job will be canceled if it runs for longer than this. */ int timeoutInSeconds; /* Flag to decide whether to run the job on metadata coordinator only or on all nodes. */ bool toBeExecutedOnMetadataCoordinatorOnly; } BackgroundWorkerJob; /* * Function to register a new BackgroundWorkerJob to-be scheduled. */ void RegisterBackgroundWorkerJob(BackgroundWorkerJob job); #endif /* DOCUMENTS_BACKGROUND_WORKER_JOB_H */ documentdb-0.108-0/pg_documentdb/include/commands/000077500000000000000000000000001507310017400220375ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/commands/coll_mod.h000066400000000000000000000007471507310017400240100ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/coll_mod.h * * Exports around the functionality of collmod * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_COLL_MOD_H #define DOCUMENTDB_COLL_MOD_H void UpdatePostgresIndexCore(uint64_t collectionId, int indexId, bool hidden, bool ignoreMissingShards); #endif documentdb-0.108-0/pg_documentdb/include/commands/commands_common.h000066400000000000000000000110061507310017400253570ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/commands_common.h * * Common declarations of commands. * *------------------------------------------------------------------------- */ #ifndef COMMANDS_COMMON_H #define COMMANDS_COMMON_H #include #include #include #include #include #include /* * Maximum size of a output bson document is 16MB. */ #define BSON_MAX_ALLOWED_SIZE (16 * 1024 * 1024) /* * Maximum size of a document produced by an intermediate stage of an aggregation pipeline. * For example, in a pipeline like [$facet, $unwind], $facet is allowed to generate a document * larger than 16MB, since $unwind can break it into smaller documents. However, $facet cannot * generate a document larger than 100MB. */ #define BSON_MAX_ALLOWED_SIZE_INTERMEDIATE (100 * 1024 * 1024) /* StringView that represents the _id field */ extern PGDLLIMPORT const StringView IdFieldStringView; /* * ApiGucPrefix.enable_create_collection_on_insert GUC determines whether * an insert into a non-existent collection should create a collection. */ extern bool EnableCreateCollectionOnInsert; /* * Whether or not write operations are inlined or if they are dispatched * to a remote shard. For single node scenarios like DocumentDB that don't need * distributed dispatch. Reset in scenarios that need distributed dispatch. */ extern bool DefaultInlineWriteOperations; extern int BatchWriteSubTransactionCount; extern int MaxWriteBatchSize; /* * WriteError can be part of the response of a batch write operation. */ typedef struct WriteError { /* Index specified within a write operation batch */ int index; /* error code */ int code; /* description of the error */ char *errmsg; } WriteError; bool FindShardKeyValueForDocumentId(MongoCollection *collection, const bson_value_t *queryDoc, bson_value_t *objectId, bool isIdValueCollationAware, bool queryHasNonIdFilters, int64 *shardKeyValue, const bson_value_t *variableSpec, const char *collationString); bool IsCommonSpecIgnoredField(const char *fieldName); WriteError * GetWriteErrorFromErrorData(ErrorData *errorData, int writeErrorIdx); bool TryGetErrorMessageAndCode(ErrorData *errorData, int *code, char **errmessage); pgbson * GetObjectIdFilterFromQueryDocumentValue(const bson_value_t *queryDoc, bool *hasNonIdFields, bool *isObjectIdFilter); pgbson * GetObjectIdFilterFromQueryDocument(pgbson *queryDoc, bool *hasNonIdFields, bool *isIdValueCollationAware); pgbson * RewriteDocumentAddObjectId(pgbson *document); pgbson * RewriteDocumentValueAddObjectId(const bson_value_t *value); pgbson * RewriteDocumentWithCustomObjectId(pgbson *document, pgbson *objectIdToWrite); void ValidateIdField(const bson_value_t *idValue); void SetExplicitStatementTimeout(int timeoutMilliseconds); void CommitWriteProcedureAndReacquireCollectionLock(MongoCollection *collection, Oid shardTableOid, bool setSnapshot); extern bool SimulateRecoveryState; extern bool DocumentDBPGReadOnlyForDiskFull; inline static void ThrowIfServerOrTransactionReadOnly(void) { if (!XactReadOnly) { return; } if (RecoveryInProgress() || SimulateRecoveryState) { /* * Skip these checks in recovery mode - let the system throw the appropriate * error. */ return; } if (DocumentDBPGReadOnlyForDiskFull) { ereport(ERROR, (errcode(ERRCODE_DISK_FULL), errmsg( "Can't execute write operation, The database disk is full"))); } /* Error is coming because the server has been put in a read-only state, but we're a writable node (primary) */ if (DefaultXactReadOnly) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_NOTWRITABLEPRIMARY), errmsg( "Write operations cannot be performed because the server is currently operating in a read-only mode."), errdetail("the default transaction is read-only"), errdetail_log( "cannot execute write operations when default_transaction_read_only is set to true"))); } /* Error is coming because the transaction has been in a readonly state */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), errmsg( "cannot execute write operation when the transaction is in a read-only state."), errdetail("the current transaction is read-only"))); } #endif documentdb-0.108-0/pg_documentdb/include/commands/connection_management.h000066400000000000000000000020441507310017400265430ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/connection_management.h * * Functions and callbacks related with connection management. * *------------------------------------------------------------------------- */ #include #ifndef CONNECTION_MANAGEMENT_H #define CONNECTION_MANAGEMENT_H /* * Function that needs to be called via abort handler. */ void ConnMgrTryCancelActiveConnection(void); /* * Functions internally used by ExtensionExecuteQueryViaLibPQ to let the * connection manager know about the active libpq connection. */ void ConnMgrResetActiveConnection(PGconn *conn); void ConnMgrForgetActiveConnection(void); /* * Functions used to manage a PG connection's state and report possible errors. */ bool PGConnXactIsActive(PGconn *conn); bool PGConnTryCancel(PGconn *conn); void PGConnReportError(PGconn *conn, PGresult *result, int elevel); void PGConnFinishConnectionEstablishment(PGconn *conn); #endif documentdb-0.108-0/pg_documentdb/include/commands/create_indexes.h000066400000000000000000000203701507310017400251740ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/create_indexes.h * * Internal implementation of ApiSchema.create_indexes. * *------------------------------------------------------------------------- */ #ifndef CREATE_INDEXES_H #define CREATE_INDEXES_H #include #include #include #include "metadata/index.h" #include "io/bson_core.h" #include "operators/bson_expression.h" #include "vector/vector_spec.h" #define MAX_INDEX_OPTIONS_LENGTH 1500 /* * Used with the ERRCODE_DOCUMENTDB_INDEXBUILDABORTED error code. */ #define COLLIDX_CONCURRENTLY_DROPPED_RECREATED_ERRMSG \ "Index build failed :: caused by :: index or " \ "collection dropped/re-created concurrently" extern int32 MaxIndexesPerCollection; typedef struct IndexDefKeyPath { /* The path constructed for the index (See IndexDefKey) */ const char *path; /* The index kind for this path */ MongoIndexKind indexKind; /* Whether or not this specific key is a wildcard index */ bool isWildcard; /* The sort direction: 1 for asc, -1 for desc. */ int sortDirection; } IndexDefKeyPath; typedef struct { /* Whether or not the index path has a wildcard */ bool isWildcard; /* Whether or not the index path has a hashed index */ bool hasHashedIndexes; /* Whether or not the index path has a cosmosdb index */ bool hasCosmosIndexes; /* Whether or not the index path has a text index */ bool hasTextIndexes; /* List of text index paths (each entry will be a TextIndexWeights) */ List *textPathList; /* Whether or not the index path has a 2d index */ bool has2dIndex; /* Whether or not the index path has 2dsphere index */ bool has2dsphereIndex; /* Whether or not index path has descending indexes */ bool hasDescendingIndex; /* Whether or not the key def can support the composite term. */ bool canSupportCompositeTerm; /* * List of IndexDefKeyPath where each path represents a particular * field/path being indexed if it's not a wildcard index. For example, * {"key" : { "a.b": 1, "c.d": 1 } } would yield keyPathList to be * ["a.b", "c.d"]. * * That means, those paths wouldn't contain WILDCARD_INDEX_SUFFIX even * when it is a wildcard index. Evenmore, keyPathList would be an empty * list if wildcard index is on whole document, i.e., doesn't have a * prefixing path. If it's a wildcard index with a prefixing path, then * keyPathList would contain a single element since compound wildcard indexes are not allowed. */ List *keyPathList; MongoIndexKind wildcardIndexKind; } IndexDefKey; typedef struct { /* represents value of "indexName" field */ char *name; /** options **/ /* represents value of "v" field */ int version; /* Indicates the version of the sphere index */ int sphereIndexVersion; /* represents value of "key" field */ IndexDefKey *key; /* represents value of "unique" field */ BoolIndexOption unique; /* represents value of "wildcardProjection" field */ const BsonIntermediatePathNode *wildcardProjectionTree; /* represents value of "partialFilterExpression" field */ Expr *partialFilterExpr; /* represents value of "sparse" field */ BoolIndexOption sparse; /* document expiry field for TTL index. Null is unspecified.*/ int *expireAfterSeconds; /** bson objects to be stored in metadata **/ /* raw document hold by "key" field */ pgbson *keyDocument; /* raw document hold by "partialFilterExpression" field */ pgbson *partialFilterExprDocument; /* * Normalized document hold by "wildcardProjection" field. * * e.g.: if "wildcardProjection" document given in index spec is * "{"a.b": 0.4, "b": 5, "a": {"x": 1}, "b": 1}", * then (normalized) wildcardProjDocument would be equal to: * "{"a": {"b": true, "x": true}, "b": true, "_id": false}". * * That means; * - every key is a single-field path * - redundant path specifications are ignored * - inclusion of the paths are specified by booleans * - inclusion of "_id" field is always provided (false by default) */ pgbson *wildcardProjectionDocument; /* * Search options pertinent to Cosmos Search index. */ CosmosSearchOptions *cosmosSearchOptions; /* The default language for text indexes */ char *defaultLanguage; /* The term in the document for specifying language overrides */ char *languageOverride; /* Optional weights document */ pgbson *weightsDocument; /* Optional bounds for 2d index, NULLs are unspecified */ double *maxBound; double *minBound; int32_t bits; /* Ignorable properties for 2dsphere index */ int32_t *finestIndexedLevel; int32_t *coarsestIndexedLevel; /* Feature flag to enable large index term. */ BoolIndexOption enableLargeIndexKeys; /* Feature flag to enable the composite term index */ BoolIndexOption enableCompositeTerm; /* Flag to indicate we should create the index as unique without the unique constraint being added to the table. Then we can transform it to unique iff an equivalent unique index exists. */ BoolIndexOption buildAsUnique; /* Feature flag to enable the composite term index */ BoolIndexOption enableReducedWildcardTerms; /* * Whether or not this index should be created as a blocking * index create. Default is off (concurrent). */ bool blocking; } IndexDef; /* * For Index creation request in background */ typedef struct { List *indexIds; char cmdType; } SubmittedIndexRequests; /* * Contains the data used when building the bson object that needs to be * sent to the client after a createIndexes() command. */ typedef struct { bool ok; bool createdCollectionAutomatically; int numIndexesBefore; int numIndexesAfter; char *note; /* error reporting; valid only when "ok" is false */ char *errmsg; int errcode; /* For Index creation in background */ SubmittedIndexRequests *request; } CreateIndexesResult; /* Represents whole "arg" document passed to dbcommand/createIndexes */ typedef struct { /* represents value of "createIndexes" field */ char *collectionName; /* * Represents value of "indexes" field. * Contains IndexDef objects for each document in "indexes" array. */ List *indexDefList; /* For unknown index options, ignore or throw error */ bool ignoreUnknownIndexOptions; /* CreateIndex using CREATE INDEX (NON-CONCURRENTLY) blocking the write operations*/ bool blocking; /* TODO: other things such as commitQuorum, comment ... */ } CreateIndexesArg; bool IsCallCreateIndexesStmt(const Node *node); bool IsCallReIndexStmt(const Node *node); CreateIndexesArg ParseCreateIndexesArg(Datum dbNameDatum, pgbson *arg); CreateIndexesResult create_indexes_non_concurrently(Datum dbNameDatum, CreateIndexesArg createIndexesArg, bool skipCheckCollectionCreate, bool uniqueIndexOnly); CreateIndexesResult create_indexes_concurrently(Datum dbNameDatum, CreateIndexesArg createIndexesArg, bool uniqueIndexOnly); void command_create_indexes(const CallStmt *callStmt, ProcessUtilityContext context, const ParamListInfo params, DestReceiver *destReceiver); void command_reindex(const CallStmt *callStmt, ProcessUtilityContext context, const ParamListInfo params, DestReceiver *destReceiver); bool IndexBuildIsInProgress(int indexId); void InitFCInfoForCallStmt(FunctionCallInfo fcinfo, const CallStmt *callStmt, ProcessUtilityContext context, const ParamListInfo params); void SendTupleToClient(HeapTuple tup, TupleDesc tupDesc, DestReceiver *destReceiver); List * CheckForConflictsAndPruneExistingIndexes(uint64 collectionId, List *indexDefList, List **inBuildIndexIds); char * CreatePostgresIndexCreationCmd(uint64 collectionId, IndexDef *indexDef, int indexId, bool concurrently, bool isTempCollection); void ExecuteCreatePostgresIndexCmd(char *cmd, bool concurrently, const Oid userOid, bool useSerialExecution); void UpdateIndexStatsForPostgresIndex(uint64 collectionId, List *indexIdList); void AcquireAdvisoryExclusiveLockForCreateIndexes(uint64 collectionId); IndexSpec MakeIndexSpecForIndexDef(IndexDef *indexDef); pgbson * MakeCreateIndexesMsg(CreateIndexesResult *result); bool WildcardProjDocsAreEquivalent(const pgbson *leftWPDocument, const pgbson *rightWPDocument); #endif documentdb-0.108-0/pg_documentdb/include/commands/cursor_common.h000066400000000000000000000007051507310017400250770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/cursor_common.h * * Common declarations of Cursor commands. * *------------------------------------------------------------------------- */ extern const StringView CursorContinuationTableName; extern const StringView CursorContinuationValue; extern const StringView PrimaryKeyShardKey; documentdb-0.108-0/pg_documentdb/include/commands/cursor_private.h000066400000000000000000000057501507310017400252660ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/cursor_private.h * * Private declarations of functions and types shared between * cursors.c and aggregation_cursors.c * *------------------------------------------------------------------------- */ #ifndef CURSOR_PRIVATE_H #define CURSOR_PRIVATE_H bool DrainStreamingQuery(HTAB *cursorMap, Query *query, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriters); pgbson * DrainTailableQuery(HTAB *cursorMap, Query *query, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter); bool CreateAndDrainPersistedQuery(const char *cursorName, Query *query, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter, bool isHoldCursor, bool closeCursor); void CreateAndDrainSingleBatchQuery(const char *cursorName, Query *query, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter); bytea * CreateAndDrainPersistedQueryWithFiles(const char *cursorName, Query *query, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter, bool closeCursor); bool DrainPersistedCursor(const char *cursorName, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter); bytea * DrainPersistedFileCursor(const char *cursorName, int batchSize, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter, bytea *cursorFileState); void CreateAndDrainPointReadQuery(const char *cursorName, Query *query, int32_t *numIterations, uint32_t accumulatedSize, pgbson_array_writer *arrayWriter); TupleDesc ConstructCursorResultTupleDesc(AttrNumber maxAttrNum); Datum PostProcessCursorPage(pgbson_writer *cursorDoc, pgbson_array_writer *arrayWriter, pgbson_writer *topLevelWriter, int64_t cursorId, pgbson *continuation, bool persistConnection, pgbson *lastContinuationToken, TupleDesc tupleDesc); HTAB * CreateCursorHashSet(void); HTAB * CreateTailableCursorHashSet(void); void BuildContinuationMap(pgbson *continuationValue, HTAB *cursorMap); void BuildTailableCursorContinuationMap(pgbson *continuationValue, HTAB *cursorMap); void SerializeContinuationsToWriter(pgbson_writer *writer, HTAB *cursorMap); void SerializeTailableContinuationsToWriter(pgbson_writer *writer, HTAB *cursorMap); pgbson * DrainSingleResultQuery(Query *query); void SetupCursorPagePreamble(pgbson_writer *topLevelWriter, pgbson_writer *cursorDoc, pgbson_array_writer *arrayWriter, const char *namespaceName, bool isFirstPage, uint32_t *accumulatedLength); #endif documentdb-0.108-0/pg_documentdb/include/commands/delete.h000066400000000000000000000030771507310017400234610ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/delete.h * * Exports related to implementation of a single-document delete. * *------------------------------------------------------------------------- */ #ifndef DELETE_H #define DELETE_H #include #include "collation/collation.h" #include "metadata/collection.h" /* * DeleteOneParams describes delete operation for a single document. */ typedef struct { /* list of Deletions */ const bson_value_t *query; /* sort order to use when selecting 1 row */ const bson_value_t *sort; /* whether to return deleted document */ bool returnDeletedDocument; /* fields to return if returning a document */ const bson_value_t *returnFields; /* parsed variable spec*/ const bson_value_t *variableSpec; /* collation string */ const char collationString[MAX_ICU_COLLATION_LENGTH]; } DeleteOneParams; /* * DeleteOneRow reflects the result of a single-row delete * on a single shard. */ typedef struct { /* whether one row matched the query and was deleted */ bool isRowDeleted; /* object_id of the deleted document (only used within delete_one) */ pgbson *objectId; /* value of the deleted (and maybe projected) document, if requested and matched any */ pgbson *resultDeletedDocument; } DeleteOneResult; void CallDeleteOne(MongoCollection *collection, DeleteOneParams *deleteOneParams, int64 shardKeyHash, text *transactionId, bool forceInlineWrites, DeleteOneResult *result); #endif documentdb-0.108-0/pg_documentdb/include/commands/diagnostic_commands_common.h000066400000000000000000000021301507310017400275610ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/diagnostic_commands_common.h * * Common declarations of Diagnostic commands. * These are used in diag command scenarios like CurrentOp, IndexStats, CollStats * *------------------------------------------------------------------------- */ #ifndef DIAGNOSTIC_COMMANDS_COMMON_H #define DIAGNOSTIC_COMMANDS_COMMON_H List * RunQueryOnAllServerNodes(const char *commandName, Datum *values, Oid *types, int numValues, PGFunction directFunc, const char *nameSpaceName, const char *functionName); pgbson * RunWorkerDiagnosticLogic(pgbson *(*workerFunc)(void *state), void *state); /* Common keys (for parsing error messages and codes from worker to coordinator) * Note that these are #defines instead of consts since the C compiler complains * if any of these aren't explicitly used in any file it's included in. */ #define ErrMsgKey "err_msg" #define ErrMsgLength 7 #define ErrCodeKey "err_code" #define ErrCodeLength 8 #endif documentdb-0.108-0/pg_documentdb/include/commands/drop_indexes.h000066400000000000000000000012521507310017400246730ustar00rootroot00000000000000 /*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/metadata/drop_indexes.h * * Internal implementation of ApiSchema.drop_indexes. * *------------------------------------------------------------------------- */ #ifndef DROP_INDEXES_H #define DROP_INDEXES_H #include "metadata/index.h" void DropPostgresIndex(uint64 collectionId, int indexId, bool unique, bool concurrently, bool missingOk); void DropPostgresIndexWithSuffix(uint64 collectionId, IndexDetails *index, bool concurrently, bool missingOk, const char *suffix); #endif documentdb-0.108-0/pg_documentdb/include/commands/insert.h000066400000000000000000000015311507310017400235140ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/insert.h * * Functions for inserting documents. * *------------------------------------------------------------------------- */ #ifndef COMMANDS_INSERT_H #define COMMANDS_INSERT_H #include #include "commands/commands_common.h" MongoCollection * CreateCollectionForInsert(Datum databaseNameDatum, Datum collectionNameDatum); bool InsertDocument(uint64 collectionId, const char *shardTableName, int64 shardKeyValue, pgbson *objectId, pgbson *document); bool InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64 shardKeyValue, pgbson *objectId, pgbson *document, const bson_value_t *updateSpecValue); #endif documentdb-0.108-0/pg_documentdb/include/commands/lock_tags.h000066400000000000000000000023351507310017400241610ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/lock_tags.h * * Constants defined under DocumentDBAdvisoryLockField4 are meant to be used for * "locktag_field4" field of "LOCKTAG" struct when acquiring an advisory lock * that is specific to documentdb_api. * * In Postgres, "locktag_field4" is used to to discern between different kind of * advisory locks. 1 and 2 are used by Postgres and 4-12 are used by Citus; so * starting from 100 here is a good enough choice that wouldn't cause a conflict * with other known advisory locks that documentdb_api should be compatible with. * * See AdvisoryLocktagClass at citus/src/include/distributed/resource_lock.h. * *------------------------------------------------------------------------- */ #ifndef LOCK_TAGS_H #define LOCK_TAGS_H #include typedef enum { /* AcquireAdvisoryExclusiveLockForCreateIndexes */ LT_FIELD4_EXCL_CREATE_INDEXES = 100, /* LockTagForInProgressIndexBuild */ LT_FIELD4_IN_PROG_INDEX_BUILD, /* AcquireAdvisoryExclusiveSessionLockForCreateIndexBackground */ LT_FIELD4_EXCL_CREATE_INDEX_BACKGROUND } DocumentDBAdvisoryLockField4; #endif documentdb-0.108-0/pg_documentdb/include/commands/parse_error.h000066400000000000000000000142651507310017400245430ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/parse_error.h * * Errors thrown for common parse errors. * *------------------------------------------------------------------------- */ #include #include "io/bson_core.h" #include "utils/documentdb_errors.h" #ifndef PARSE_ERROR_H #define PARSE_ERROR_H static inline void ThrowTopLevelTypeMismatchError(const char *fieldName, const char *fieldTypeName, const char *expectedTypeName) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The BSON field '%s' has an incorrect type '%s'; it should be of type '%s'.", fieldName, fieldTypeName, expectedTypeName), errdetail_log( "The BSON field '%s' has an incorrect type '%s'; it should be of type '%s'.", fieldName, fieldTypeName, expectedTypeName))); } /* * Throw an error if type of the value that given iterator holds doesn't * match the expected one. */ static inline void EnsureTopLevelFieldType(const char *fieldName, const bson_iter_t *iter, bson_type_t expectedType) { bson_type_t fieldType = bson_iter_type(iter); if (fieldType != expectedType) { ThrowTopLevelTypeMismatchError(fieldName, BsonTypeName(fieldType), BsonTypeName(expectedType)); } } /* * Variant of the above with values. */ static inline void EnsureTopLevelFieldValueType(const char *fieldName, const bson_value_t *value, bson_type_t expectedType) { if (value->value_type != expectedType) { ThrowTopLevelTypeMismatchError(fieldName, BsonTypeName(value->value_type), BsonTypeName(expectedType)); } } /* * Similar to EnsureTopLevelFieldType, but null value is also ok even if * expectedType is not "null". * * That means; * - Returns true if type of the value that it holds matches the expected * one. * - Otherwise, returns false if iterator holds null value else throws an * error. * * Mostly useful when given field being set to null implies using the default * setting for that spec option. */ static inline bool EnsureTopLevelFieldTypeNullOk(const char *fieldName, const bson_iter_t *iter, bson_type_t expectedType) { if (BSON_ITER_HOLDS_NULL(iter) && expectedType != BSON_TYPE_NULL) { return false; } EnsureTopLevelFieldType(fieldName, iter, expectedType); return true; } /* * Similar to EnsureTopLevelFieldType, but null value is also ok even if * expectedType is not "null" or "undefined". * * That means; * - Returns true if type of the value that it holds matches the expected * one. * - Otherwise, returns false if iterator holds null value else throws an * error. * * Mostly useful when given field being set to null implies using the default * setting for that spec option. */ static inline bool EnsureTopLevelFieldTypeNullOkUndefinedOK(const char *fieldName, const bson_iter_t *iter, bson_type_t expectedType) { if ((BSON_ITER_HOLDS_NULL(iter) && expectedType != BSON_TYPE_NULL) || (BSON_ITER_HOLDS_UNDEFINED(iter) && expectedType != BSON_TYPE_UNDEFINED)) { return false; } EnsureTopLevelFieldType(fieldName, iter, expectedType); return true; } /* * Throw an error if type of the value that given iterator holds cannot be * interpreted as a boolean. */ static inline void EnsureTopLevelFieldIsBooleanLike(const char *fieldName, const bson_iter_t *iter) { if (!BsonTypeIsNumberOrBool(bson_iter_type(iter))) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The BSON field '%s' has an incorrect type '%s'; it should be" " one of the following valid types: [bool, long, int, decimal, double]", fieldName, BsonIterTypeName(iter)), errdetail_log( "The BSON field '%s' has an incorrect type '%s'; it should be" " one of the following valid types: [bool, long, int, decimal, double]", fieldName, BsonIterTypeName(iter)))); } } /* * Throw an error if type of the value that given iterator holds cannot be * interpreted as a number. */ static inline void EnsureTopLevelFieldIsNumberLike(const char *fieldName, const bson_value_t *value) { if (!BsonTypeIsNumber(value->value_type)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The BSON field '%s' has an incorrect type '%s'; it should be" " one of the following valid types: [int, decimal, double, long]", fieldName, BsonTypeName(value->value_type)), errdetail_log( "The BSON field '%s' has an incorrect type '%s'; it should be" " one of the following valid types: [int, decimal, double, long]", fieldName, BsonTypeName(value->value_type)))); } } /* * Similar to EnsureTopLevelFieldIsBooleanLike, but null value is also ok. * * That means; * - Returns true if type of the value that it holds can be interpreted as * a boolean. * - Otherwise, returns false if iterator holds null value else throws an * error. * * Mostly useful when given field being set to null implies using the default * setting for that spec option. */ static inline bool EnsureTopLevelFieldIsBooleanLikeNullOk(const char *fieldName, const bson_iter_t *iter) { if (BSON_ITER_HOLDS_NULL(iter)) { return false; } EnsureTopLevelFieldIsBooleanLike(fieldName, iter); return true; } static inline void ThrowTopLevelMissingFieldError(const char *fieldName) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("The BSON field '%s' is required but was not provided", fieldName))); } static inline void ThrowTopLevelMissingFieldErrorWithCode(const char *fieldName, int code) { ereport(ERROR, (errcode(code), errmsg("The BSON field '%s' is required but was not provided", fieldName), errdetail_log("The BSON field '%s' is required but was not provided", fieldName))); } static inline void EnsureStringValueNotDollarPrefixed(const char *fieldValue, int fieldLength) { if (fieldLength > 0 && fieldValue[0] == '$') { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "FieldPath field names are not allowed to begin with the operators symbol '$'; consider using $getField or $setField instead."))); } } #endif documentdb-0.108-0/pg_documentdb/include/commands/retryable_writes.h000066400000000000000000000026231507310017400256010ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * transaction/retryable_writes.h * * Common declarations for retryable writes-related functions. * *------------------------------------------------------------------------- */ #ifndef RETRYABLE_WRITES_H #define RETRYABLE_WRITES_H /* * RetryableWriteResult stores information about the result of a retryable * write to be able to return the same result in case of a retry. */ typedef struct RetryableWriteResult { /* object ID that was inserted, updated, or deleted */ pgbson *objectId; /* whether rows affected by the write */ bool rowsAffected; /* shard key value of the write */ int64 shardKeyValue; /* * Value of the (maybe projected) old or new document that next trial * should report (or NULL if not applicable to the command or the command * couldn't match any documents). */ pgbson *resultDocument; } RetryableWriteResult; bool FindRetryRecordInAnyShard(uint64 collectionId, text *transactionId, RetryableWriteResult *writeResult); bool DeleteRetryRecord(uint64 collectionId, int64 shardKeyValue, text *transactionId, RetryableWriteResult *writeResult); void InsertRetryRecord(uint64 collectionId, int64 shardKeyValue, text *transactionId, pgbson *objectId, bool rowsAffected, pgbson *resultDocument); #endif documentdb-0.108-0/pg_documentdb/include/commands/update.h000066400000000000000000000044441507310017400235000ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/commands/update.h * * Exports related to implementation of a single-document update. * *------------------------------------------------------------------------- */ #ifndef UPDATE_H #define UPDATE_H #include #include "metadata/collection.h" #include "operators/bson_expr_eval.h" /* * UpdateReturnValue specifies whether an update should return * no document, the old document, or the new document. */ typedef enum { UPDATE_RETURNS_NONE, UPDATE_RETURNS_OLD, UPDATE_RETURNS_NEW } UpdateReturnValue; /* * UpdateOneParams describes update operation for a single document. */ typedef struct { /* update only documents matching this query */ const bson_value_t *query; /* apply this update */ const bson_value_t *update; /* whether to use upsert if no documents match */ int isUpsert; /* sort order to use when selecting 1 row */ const bson_value_t *sort; /* whether to return a document */ UpdateReturnValue returnDocument; /* fields to return if returning a document */ const bson_value_t *returnFields; /* array filters specified in the update */ const bson_value_t *arrayFilters; /* whether to bypass document validation */ bool bypassDocumentValidation; /* parsed variable spec */ const bson_value_t *variableSpec; } UpdateOneParams; /* * UpdateOneResult reflects the result of a single-row update * on a single shard, which may be a delete. */ typedef struct { /* whether one row matched the query and was updated */ bool isRowUpdated; /* whether we found a document but it was not affected by the update spec */ bool updateSkipped; /* update result came from a retry record */ bool isRetry; /* shard key value changed, reinsertDocument document needs to be inserted */ pgbson *reinsertDocument; /* * Value of the (maybe projected) original or new document, if requested * and matched any. */ pgbson *resultDocument; /* upserted document ID */ pgbson *upsertedObjectId; } UpdateOneResult; void UpdateOne(MongoCollection *collection, UpdateOneParams *updateOneParams, int64 shardKeyHash, text *transactionId, UpdateOneResult *result, bool forceInlineWrites, ExprEvalState *state); #endif documentdb-0.108-0/pg_documentdb/include/configs/000077500000000000000000000000001507310017400216665ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/configs/config_initialization.h000066400000000000000000000014561507310017400264210ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/configs/config_initialization.h * * Common initialization of configs. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTS_CONFIG_INITIALIZATION_H #define DOCUMENTS_CONFIG_INITIALIZATION_H void InitializeTestConfigurations(const char *prefix, const char *newGucPrefix); void InitializeFeatureFlagConfigurations(const char *prefix, const char *newGucPrefix); void InitializeBackgroundJobConfigurations(const char *prefix, const char *newGucPrefix); void InitializeSystemConfigurations(const char *prefix, const char *newGucPrefix); void InitDocumentDBBackgroundWorkerConfigurations(const char *prefix); #endif documentdb-0.108-0/pg_documentdb/include/customscan/000077500000000000000000000000001507310017400224155ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/customscan/bson_custom_query_scan.h000066400000000000000000000016561507310017400273620ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/customscan/bson_custom_query_scan.h * * Implementation of a custom scan plan. * *------------------------------------------------------------------------- */ #ifndef BSON_CUSTOM_QUERY_SCAN_H #define BSON_CUSTOM_QUERY_SCAN_H #include #include #include #include void AddExtensionQueryScanForTextQuery(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, QueryTextIndexData *textIndexOptions); void AddExtensionQueryScanForVectorQuery(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, const SearchQueryEvalData *searchQueryData); void AddExplainCustomScanWrapper(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); #endif documentdb-0.108-0/pg_documentdb/include/customscan/bson_custom_scan.h000066400000000000000000000014571507310017400261340ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/customscan/bson_custom_scan.h * * Implementation of a custom scan plan. * *------------------------------------------------------------------------- */ #ifndef BSON_CUSTOM_SCAN_H #define BSON_CUSTOM_SCAN_H #include bool UpdatePathsWithExtensionStreamingCursorPlans(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); void UpdatePathsToForceRumIndexScanToBitmapHeapScan(PlannerInfo *root, RelOptInfo *rel); Query * ReplaceCursorParamValues(Query *query, ParamListInfo boundParams); void ValidateCursorCustomScanPlan(Plan *plan); PathTarget * BuildBaseRelPathTarget(Relation tableRel, Index relIdIndex); #endif documentdb-0.108-0/pg_documentdb/include/customscan/bson_custom_scan_private.h000066400000000000000000000040511507310017400276570ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/customscan/bson_custom_scan_private.h * * Implementation of a custom scan plan. * *------------------------------------------------------------------------- */ #ifndef BSON_CUSTOM_SCAN_PRIVATE_H #define BSON_CUSTOM_SCAN_PRIVATE_H #include /* These macros are copied from Postgres for I/O of custom nodes */ #define nullable_string(token, length) \ ((length) == 0 ? NULL : debackslash(token, length)) #define booltostr(x) ((x) ? "true" : "false") #define strtobool(x) ((*(x) == 't') ? true : false) /* OID fields */ #define WRITE_OID_FIELD(fldname) \ appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname) #define READ_OID_FIELD(fldname) \ token = pg_strtok(&length); /* skip :fldname */ \ token = pg_strtok(&length); /* Retrieve specified field value */ \ local_node->fldname = atooid(token) /* String fields */ #define WRITE_STRING_FIELD_VALUE(fldname, value) \ (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ outToken(str, value)) #define WRITE_STRING_FIELD(fldname) \ (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ outToken(str, node->fldname)) #define READ_STRING_FIELD(fldname) \ token = pg_strtok(&length); /* skip :fldname */ \ token = pg_strtok(&length); /* Retrieve specified field value */ \ local_node->fldname = nullable_string(token, length) #define READ_STRING_FIELD_VALUE(fldValue) \ token = pg_strtok(&length); /* skip :fldname */ \ token = pg_strtok(&length); /* Retrieve specified field value */ \ fldValue = nullable_string(token, length) /* Bool fields */ #define WRITE_BOOL_FIELD(fldname) \ appendStringInfo(str, " :" CppAsString(fldname) " %s", \ booltostr(node->fldname)) #define READ_BOOL_FIELD(fldname) \ token = pg_strtok(&length); /* skip :fldname */ \ token = pg_strtok(&length); /* Retrieve specified field value */ \ local_node->fldname = strtobool(token) #endif documentdb-0.108-0/pg_documentdb/include/customscan/custom_scan_registrations.h000066400000000000000000000007651507310017400300710ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/customscan/custom_scan_registrations.h * * Implementation of a custom scan plan. * *------------------------------------------------------------------------- */ #ifndef CUSTOM_SCAN_REGISTRATION_H #define CUSTOM_SCAN_REGISTRATION_H void RegisterScanNodes(void); void RegisterQueryScanNodes(void); void RegisterExplainScanNodes(void); #endif documentdb-0.108-0/pg_documentdb/include/documentdb_api_init.h000066400000000000000000000013761507310017400244160ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/documentdb_api_init.h * * Exports related to shared library initialization for the API. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_API_INIT_H #define DOCUMENTDB_API_INIT_H void InitApiConfigurations(char *prefix, char *newGucPrefix); void InstallDocumentDBApiPostgresHooks(void); void UninstallDocumentDBApiPostgresHooks(void); void InitializeDocumentDBBackgroundWorker(char *libraryName, char *gucPrefix, char *extensionObjectPrefix); void InitializeSharedMemoryHooks(void); void InitializeBackgroundWorkerJobAllowedCommands(void); #endif documentdb-0.108-0/pg_documentdb/include/geospatial/000077500000000000000000000000001507310017400223665ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geojson_utils.h000066400000000000000000000013711507310017400264460ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geojson_utils.h * * Definitions for utilities to work with GeoJSON Data type * *------------------------------------------------------------------------- */ #ifndef BSON_GEOJSON_UTILS_H #define BSON_GEOJSON_UTILS_H #include #include "io/bson_core.h" #include "geospatial/bson_geospatial_private.h" #define GEOJSON_CRS_BIGPOLYGON "urn:x-mongodb:crs:strictwinding:EPSG:4326" #define GEOJSON_CRS_EPSG_4326 "EPSG:4326" #define GEOJSON_CRS_84 "urn:ogc:def:crs:OGC:1.3:CRS84" bool ParseValueAsGeoJSON(const bson_value_t *value, GeoJsonParseState *parseState); #endif documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geospatial_common.h000066400000000000000000000151511507310017400272630ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geospatial_common.h * * Common function declarations for method interacting between documentdb_api and * postgis extension to convert and process GeoSpatial Data * *------------------------------------------------------------------------- */ #ifndef BSON_GEOSPATIAL_COMMON_H #define BSON_GEOSPATIAL_COMMON_H #include "postgres.h" #include "float.h" #include "io/bson_core.h" #include "geospatial/bson_geospatial_private.h" #include "planner/mongo_query_operator.h" #include "geospatial/bson_geospatial_shape_operators.h" #include "metadata/metadata_cache.h" /* Default min and max bounds for 2d index */ #define DEFAULT_2D_INDEX_MIN_BOUND -180.0 #define DEFAULT_2D_INDEX_MAX_BOUND 180.0 /* Utility macro to check equality of double value */ #define DOUBLE_EQUALS(a, b) (fabs((a) - (b)) < DBL_EPSILON) /* Forward declaration of struct */ typedef struct ProcessCommonGeospatialState ProcessCommonGeospatialState; /*================================*/ /* Data Types*/ /*================================*/ /* Forward declaration of struct */ typedef struct ProcessCommonGeospatialState ProcessCommonGeospatialState; /* * Types of validation performed when processing the geospatial data */ typedef enum GeospatialValidationLevel { GeospatialValidationLevel_Unknown = 0, /* * Used with bson_validate_* functions to check if a path in the doc has potential geo values or not, * errors are not thrown with this validation level. Also it only checks for first potential geospatial * value and returns immediately after finding first potential geo value */ GeospatialValidationLevel_BloomFilter, /* * This validation level is required by the runtime operator function families e.g. geoIntersects or geoWithin * Errors are not thrown with this level and all valid geometries are returned */ GeospatialValidationLevel_Runtime, /* * Strict validation is used to enforce geospatial index term generation validations, a document with invalid * potential geometry is okay to be inserted if no geospatial index is present otherwise it returns error. * This validation throws error if any invalid geometries processed */ GeospatialValidationLevel_Index, } GeospatialValidationLevel; /* * Type of geospatial data being processed */ typedef enum GeospatialType { GeospatialType_UNKNOWN = 0, GeospatialType_Geometry, GeospatialType_Geography, } GeospatialType; /* * Enum for postgis functions used in runtime matching in $geoWithin and $geoIntersects */ typedef enum PostgisFuncsForDollarGeo { Geometry_Intersects = 0, Geography_Intersects, Geometry_Covers, Geography_Covers, Geometry_DWithin, Geography_DWithin, Geometry_IsValidDetail, PostgisFuncsForDollarGeo_MAX } PostgisFuncsForDollarGeo; /* * The common cache state for geometries / geographies which are used for * caching precomputed geometries / geographies */ typedef struct CommonBsonGeospatialState { /* * Whether the geodetic datum is spherical or not */ bool isSpherical; /* * Pre computed postgis geometry / geography for query */ Datum geoSpatialDatum; } CommonBsonGeospatialState; /* Signature for runtime function to get match result for $geoWithin and $geoIntersects */ typedef bool (*GeospatialQueryMatcherFunc)(const ProcessCommonGeospatialState *, StringInfo); /* * Runtime query matcher for comapring the resulting geometry/geography from * document to a query based on the Mongo geo query operators */ typedef struct RuntimeQueryMatcherInfo { /* Matcher function to call for checking a match */ GeospatialQueryMatcherFunc matcherFunc; /* FmgrInfo store for the runtime matching functions */ FmgrInfo **runtimeFmgrStore; /* Main postgis function to use for runtime matching */ PostgisFuncsForDollarGeo runtimePostgisFunc; /* Query geometry/geography datum precomputed */ Datum queryGeoDatum; /* True when matched */ bool isMatched; } RuntimeQueryMatcherInfo; /* * Common state to process geospatial data in documents */ typedef struct ProcessCommonGeospatialState { /* ========== IN VARIABLES ============ */ /* The geospatial type we are processing, either Geometry or Geography */ GeospatialType geospatialType; /* The level at which we need to parse the geometry/geography. */ GeospatialValidationLevel validationLevel; /* Runtime Query matcher, Only availabl for runtime matching otherwise NULL */ RuntimeQueryMatcherInfo runtimeMatcher; GeospatialErrorContext *errorCtxt; /* Carry shape-specific info, for e.g., radius for $center and $centerSphere */ ShapeOperatorInfo *opInfo; /* ========== OUT VARIABLES ============ */ /* The resulting geometry's / geography's WKB buffer */ StringInfo WKBBuffer; /* Have we processed a multikey case? */ bool isMultiKeyContext; /* Number of total geo values found */ uint32 total; /* Are there no valid regions? */ bool isEmpty; } ProcessCommonGeospatialState; void BsonIterGetLegacyGeometryPoints(bson_iter_t *documentIter, const StringView *keyPathView, ProcessCommonGeospatialState *state); void BsonIterGetGeographies(bson_iter_t *documentIter, const StringView *keyPathView, ProcessCommonGeospatialState *state); void BsonIterValidateGeographies(bson_iter_t *documentIter, const StringView *keyPathView, ProcessCommonGeospatialState *state); Datum BsonExtractGeometryStrict(const pgbson *document, const StringView *pathView); Datum BsonExtractGeographyStrict(const pgbson *document, const StringView *pathView); Datum BsonExtractGeometryRuntime(const pgbson *document, const StringView *pathView); Datum BsonExtractGeographyRuntime(const pgbson *document, const StringView *pathView); /* * Initialize ProcessCommonState with given set of values */ static inline void InitProcessCommonGeospatialState(ProcessCommonGeospatialState *state, GeospatialValidationLevel validationLevel, GeospatialType type, GeospatialErrorContext *errCtxt) { memset(state, 0, sizeof(ProcessCommonGeospatialState)); state->isEmpty = true; state->geospatialType = type; state->validationLevel = validationLevel; state->WKBBuffer = makeStringInfo(); /* * Error context while processing the data as geospatial data used in * ereports to throw error where valid */ state->errorCtxt = errCtxt; } /* * Validates whether this is a geo-within query operator (for both variants) */ static inline bool IsGeoWithinQueryOperator(MongoQueryOperatorType queryOperatorType) { return queryOperatorType == QUERY_OPERATOR_GEOWITHIN || queryOperatorType == QUERY_OPERATOR_WITHIN; } #endif documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geospatial_geonear.h000066400000000000000000000147521507310017400274210ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geospatial_geonear.h * * Common function declarations for method used for $geoNear aggregation stage * *------------------------------------------------------------------------- */ #ifndef BSON_GEOSPATIAL_GEONEAR_H #define BSON_GEOSPATIAL_GEONEAR_H #include #include #include "io/bson_core.h" #include "geospatial/bson_geospatial_private.h" #include "opclass/bson_gin_index_mgmt.h" #include "opclass/bson_index_support.h" #include "geospatial/bson_geospatial_common.h" /* * Represents a Geonear Request */ typedef struct GeonearRequest { /* Field to project the calculated distance from stage */ char *distanceField; /* Field to project the geo value from document */ char *includeLocs; /* key of the geospatial index to be used in the stage */ char *key; /* calculated distance to multiplied by distanceMultiplier */ float8 distanceMultiplier; /* max distance for the filtering the documents in meters for 2dsphere index * and in radians if spherical is true for 2d index */ float8 *maxDistance; /* min distance for the filtering the documents in meters for 2dsphere index * and in radians if spherical is true for 2d index */ float8 *minDistance; /* Referrence point from where the distance is calculated */ Point referencePoint; /* Whether the point is GeoJSON point or legacy point, helps in deciding the index * to use */ bool isGeoJsonPoint; /* Additional query filters for the stage */ bson_value_t query; /* Whether spherical distance calculation is requested */ bool spherical; } GeonearRequest; /* * Enum that defines how $geoNear calculated distance */ typedef enum DistanceMode { DistanceMode_Unknown = 0, /* Spherical distance calculation based on earth's spheroid */ DistanceMode_Spherical, /* 2d cartesian distance */ DistanceMode_Cartesian, /* Similar to spherical but in radians with respect to earth's radius */ DistanceMode_Radians, } DistanceMode; /* * Runtime distance calculating functions cacheable context */ typedef struct GeonearDistanceState { /* For below field definitions consult the GeonearRequest struct */ StringView key; StringView distanceField; StringView includeLocs; float8 distanceMultiplier; Datum referencePoint; float8 *maxDistance; float8 *minDistance; /* FmgrInfo of the Postgis runtime distance method, can be spherical or non-spherical based * on the request */ FmgrInfo *distanceFnInfo; /* Distance calculation mode */ DistanceMode mode; } GeonearDistanceState; /* * State to store validation level and type of index for geonear index validation */ typedef struct GeonearIndexValidationState { /* Index or runtime validation */ GeospatialValidationLevel validationLevel; /* To get index type for validation; may be typecasted to Bson2dGeometryPathOptions for 2d index */ BsonGinIndexOptionsBase *options; } GeonearIndexValidationState; GeonearRequest * ParseGeonearRequest(const pgbson *geoNearQuery); void BuildGeoNearDistanceState(GeonearDistanceState *state, const pgbson *geoNearQuery, const GeonearIndexValidationState *validationState); void BuildGeoNearRangeDistanceState(GeonearDistanceState *state, const pgbson *geoNearQuery); float8 GeonearDistanceFromDocument(const GeonearDistanceState *state, const pgbson *document); bool ValidateQueryOperatorsForGeoNear(Node *node, void *state); pgbson * ConvertQueryToGeoNearQuery(bson_iter_t *operatorDocIterator, const char *path, const char *mongoOperatorName); List * CreateExprForGeonearAndNearSphere(const pgbson *queryDoc, Expr *docExpr, const GeonearRequest *request, TargetEntry **targetEntry, SortGroupClause **sortClause); pgbson * GetGeonearSpecFromNearQuery(bson_iter_t *operatorDocIterator, const char *path, const char *mongoOperatorName); bool CanGeonearQueryUseAlternateIndex(OpExpr *geoNearOpExpr, GeonearRequest **request); void GetAllGeoIndexesFromRelIndexList(List *indexlist, List **_2dIndexList, List **_2dsphereIndexList); char * CheckGeonearEmptyKeyCanUseIndex(GeonearRequest *request, List *_2dIndexList, List *_2dsphereIndexList, bool *useSphericalIndex); void UpdateGeoNearQueryTreeToUseAlternateIndex(PlannerInfo *root, RelOptInfo *rel, OpExpr *geoNearOpExpr, const char *key, bool useSphericalIndex, bool isEmptyKey); bool TryFindGeoNearOpExpr(PlannerInfo *root, ReplaceExtensionFunctionContext *context); pgbson * EvaluateGeoNearConstExpression(const bson_value_t *geoNearSpecValue, Expr *variableExpr); inline static bool Is2dWithSphericalDistance(const GeonearRequest *request) { return !request->isGeoJsonPoint && request->spherical; } inline static float8 ConvertRadiansToMeters(float8 radians) { return radians * RADIUS_OF_EARTH_M; } inline static float8 ConvertMetersToRadians(float8 meters) { return meters / RADIUS_OF_EARTH_M; } /* * Check if the sort clause contains a geonear operator */ inline static bool TargetListContainsGeonearOp(const List *targetList) { if (!targetList) { return false; } TargetEntry *tle; ListCell *cell; foreach(cell, targetList) { tle = (TargetEntry *) lfirst(cell); if (tle->resjunk) { if (IsA(tle->expr, OpExpr)) { OpExpr *expr = (OpExpr *) tle->expr; if (expr->opno == BsonGeonearDistanceOperatorId()) { return true; } } } } return false; } static inline void pg_attribute_noreturn() ThrowGeoNearNotAllowedInContextError() { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_LOCATION5626500), errmsg( "Operators $geoNear, $near, and $nearSphere cannot be used in this particular context"))); } static inline void pg_attribute_noreturn() ThrowGeoNearUnableToFindIndex() { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNABLETOFINDINDEX), errmsg("unable to find index for $geoNear query"))); } static inline void pg_attribute_noreturn() ThrowNoGeoIndexesFound() { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_INDEXNOTFOUND), errmsg( "The $geoNear operator needs either a 2d or 2dsphere index, but no such index exists"))); } static inline void pg_attribute_noreturn() ThrowAmbigousIndexesFound(const char * indexType) { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_INDEXNOTFOUND), errmsg( "Multiple %s indexes found; uncertain which index should be applied for the $geoNear operator", indexType))); } #endif documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geospatial_private.h000066400000000000000000000366641507310017400274610ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geospatial_private.h * * Private data structure and function declarations for geospatial * *------------------------------------------------------------------------- */ #ifndef BSON_GEOSPATIAL_PRIVATE_H #define BSON_GEOSPATIAL_PRIVATE_H #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "utils/documentdb_errors.h" /* * WGS84 uses 4326 SRID (Spatial referrence ID) in PostGIS. * This is used to treat the geodetic data as WGS84. */ #define DEFAULT_GEO_SRID 4326 #define GeometryParseFlag uint32 /* Define the WKB Byte order based on the endianess */ #if __BYTE_ORDER == __LITTLE_ENDIAN # define WKB_BYTE_ORDER (unsigned char) 1 #elif __BYTE_ORDER == __BIG_ENDIAN # define WKB_BYTE_ORDER = (unsigned char) 0 #endif /* * For a well known binary in EWKB format of postgis, the type field * is generally stuffed with metadata about if SRID is part of the buffer or not. * For more info refer postgis => liblwgeom/liblwgeom.h */ #define POSTGIS_EWKB_SRID_FLAG 0x20000000 /* * WKBBufferGetByteaWithSRID embeds SRID Flag into type when extracting bytea from WKB buffer * This flag is used to remove the embedding and get type from bytea */ #define POSTGIS_EWKB_SRID_NEGATE_FLAG 0xDFFFFFFF /* * This is a useful macro defined for handling all the validity error cases for geospatial * and should be placed just before throwing an error to make sure we don't throw error in * cases where should just be ignoring them. * * This is efficient in a way where we don't allocate space for error messages even in case * when they are not thrown * * Usage: * bool shouldThrowError = true / false; * if (some error condition ) * { * RETURN_FALSE_IF_ERROR_NOT_EXPECTED(shouldThrowError, ( * errcode(ERRCODE_DOCUMENTDB_BADVALUE), * errmsg("Error"), * errdetail_log("PII Safe error") * )); * } */ #define RETURN_FALSE_IF_ERROR_NOT_EXPECTED(shouldThrow, errCodeFormat) \ if (!shouldThrow) { return false; } \ else \ { \ ereport(ERROR, errCodeFormat); \ } #define EMPTY_GEO_ERROR_PREFIX "" #define GEO_ERROR_CODE(errorCtxt) (errorCtxt ? errorCtxt->errCode : \ ERRCODE_DOCUMENTDB_BADVALUE) #define GEO_ERROR_PREFIX(errorCtxt) (errorCtxt && errorCtxt->errPrefix ? \ errorCtxt->errPrefix(errorCtxt->document) : \ EMPTY_GEO_ERROR_PREFIX) #define GEO_HINT_PREFIX(errorCtxt) (errorCtxt && errorCtxt->hintPrefix ? \ errorCtxt->hintPrefix(errorCtxt->document) : \ EMPTY_GEO_ERROR_PREFIX) /* Represents byte size for the byte order in WKB */ #define WKB_BYTE_SIZE_ORDER 1 /* Represents byte size for the type of geometry in WKB */ #define WKB_BYTE_SIZE_TYPE 4 /* Represents byte size for the number of components in WKB */ #define WKB_BYTE_SIZE_NUM WKB_BYTE_SIZE_TYPE /* Represents byte size for the number of components in WKB */ #define WKB_BYTE_SIZE_SRID WKB_BYTE_SIZE_TYPE /* Represents byte size for the point value (includes x and y) */ #define WKB_BYTE_SIZE_POINT 16 /* * Radius of earth in meters according to NASA docs for spherical calculations. * ref - https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html */ static const float8 RADIUS_OF_EARTH_M = 6378.137 * 1000; /* * Radius of earth in meters for spherical calculations * Earth is not a perfect sphere, but this is a good approximation of the radius * based on ellipsoid to sphere conversion model. * For more info: https://en.wikipedia.org/wiki/Earth_ellipsoid */ static const float8 RADIUS_OF_ELLIPSOIDAL_EARTH_M = 6371008.7714150595; /* * GeoJSON types specified by the GeoJSON standard * https://datatracker.ietf.org/doc/html/rfc7946 * * Please note: These are meant to be bitmask flags */ typedef enum GeoJsonType { GeoJsonType_UNKNOWN = 0x0, GeoJsonType_POINT = 0x1, GeoJsonType_LINESTRING = 0x2, GeoJsonType_POLYGON = 0x4, GeoJsonType_MULTIPOINT = 0x8, GeoJsonType_MULTILINESTRING = 0x10, GeoJsonType_MULTIPOLYGON = 0x20, GeoJsonType_GEOMETRYCOLLECTION = 0x40, /* A custom type to select all type */ GeoJsonType_ALL = 0xFF } GeoJsonType; /* * WKB types for commonly identified geometries */ typedef enum WKBGeometryType { WKBGeometryType_Invalid = 0x0, WKBGeometryType_Point = 0x1, WKBGeometryType_LineString = 0x2, WKBGeometryType_Polygon = 0x3, WKBGeometryType_MultiPoint = 0x4, WKBGeometryType_MultiLineString = 0x5, WKBGeometryType_MultiPolygon = 0x6, WKBGeometryType_GeometryCollection = 0x7 } WKBGeometryType; typedef const char *(*GeospatialErrorPrefixFunc)(const pgbson *); typedef const char *(*GeospatialErrorHintPrefixFunc)(const pgbson *); /* * Geospatial error context for error reporting */ typedef struct GeospatialErrorContext { /* * document referrence for error reporting, this is passed to errPrefix and hintPrefix callbacks. * Callers can decide whether to ignore or extract metadata such as _id from the document to be inserted in * prefix and hintPrefix */ const pgbson *document; /* The desired error code to be thrown */ int64 errCode; /* Error prefix to be preppended for the errors, this is a callback and is only called when there is a valid error case. * * This helps us in not making strings available when they are not required and avoid unnecessary document traversals * e.g. In geospatial case we don't want to traverse document to get the _id and send it as part of errPrefix, * this might not get used overall if all valid */ GeospatialErrorPrefixFunc errPrefix; /* Error prefix for the hints, same as errPrefix this is also a callback. * This should never include PII in the prefix returned. */ GeospatialErrorHintPrefixFunc hintPrefix; } GeospatialErrorContext; /* * Generic state while parsing any bson value to be a GeoJSON data */ typedef struct GeoJsonParseState { /*=============== IN Variable ===================*/ /* * This helps in either throwing instant errors in case of invalidity or * notifying if error was persent */ bool shouldThrowValidityError; /* * GeoJson Expected type to parse. */ GeoJsonType expectedType; /* * Error context to be used while throwing errors */ GeospatialErrorContext *errorCtxt; /*=============== OUT Variables =================*/ /* The type of the GeoJson found while parsing */ GeoJsonType type; /* The CRS name given in the GeoJSON */ const char *crs; /* Number of rings in a Polygon, for now this is used to error out $geoWithin for polygon with holes * so this contains a max number of rings if geoJSON is a multipolygon. */ int32 numOfRingsInPolygon; /*================ INOUT Variables =================*/ /* * WKB buffer */ StringInfo buffer; } GeoJsonParseState; /* * This is basic structure that holds the x and y for all the Geomtery types * Postgis support */ typedef struct Point { float8 x; float8 y; } Point; /* * Flags to determine how we want to parse the geometries */ typedef enum ParseFlags { /* None */ ParseFlag_None = 0x0, /* Legacy point format */ ParseFlag_Legacy = 0x2, /* Legacy point format, while parsing it will not attempt to throw error */ ParseFlag_Legacy_NoError = 0x4, /* Only GeoJSON point */ ParseFlag_GeoJSON_Point = 0x8, /* Any GeoJSON type */ ParseFlag_GeoJSON_All = 0x10, } ParseFlags; bool ParseBsonValueAsPoint(const bson_value_t *value, bool throwError, GeospatialErrorContext *errCtxt, Point *outPoint); bool ParseBsonValueAsPointWithBounds(const bson_value_t *value, bool throwError, GeospatialErrorContext *errCtxt, Point *outPoint); /*********Buffer Writers********/ bool BsonValueGetGeometryWKB(const bson_value_t *value, const GeometryParseFlag parseFlag, GeoJsonParseState *parseState); /* * Get geometry from the Extended Well Known Binary (that includes the SRID) */ static inline Datum GetGeometryFromWKB(const bytea *wkbBuffer) { return OidFunctionCall1(PostgisGeometryFromEWKBFunctionId(), PointerGetDatum(wkbBuffer)); } /* * Get geography from the Extended Well Known Binary (that includes the SRID) */ static inline Datum GetGeographyFromWKB(const bytea *wkbBuffer) { return OidFunctionCall1(PostgisGeographyFromWKBFunctionId(), PointerGetDatum(wkbBuffer)); } /* * Returns if the GeoJSON type is a collection or Multi type */ static inline bool IsWKBCollectionType(WKBGeometryType type) { return type == WKBGeometryType_GeometryCollection || type == WKBGeometryType_MultiPolygon || type == WKBGeometryType_MultiPoint || type == WKBGeometryType_MultiLineString; } /* * Appends the buffer with 4 bytes, setting values to 0 at the new space and * returns the starting position of the 4 bytes space which can be filled later * with the actual value. * * This is used in cases where we don't know the multi components length at the begining * and since length is 4 bytes, we skip 4 bytes and fill it later. * * e.g. * Current buffer => 0x11110011 * After skipping 4 bytes * Buffer => 0x1111001100000000 * ^ * | => This is the returned position of the 4byte space */ static inline int32 WKBBufferAppend4EmptyBytesForNums(StringInfo buffer) { int32 num = 0; int32 currentLength = buffer->len; appendBinaryStringInfoNT(buffer, (char *) &num, WKB_BYTE_SIZE_NUM); return currentLength; } /* * This buffer writer writes the header information for a geometry * Header information is considered: Byte Endianess and type of geometry * which are the first 5 bytes, 1 byte endianess and 4 bytes type * * e.g * 0x01 01000000 => represents a point in little endian * 0x00 00000001 => represents a point in big endian * */ static inline void WriteHeaderToWKBBuffer(StringInfo buffer, const WKBGeometryType type) { char endianess = (char) WKB_BYTE_ORDER; appendBinaryStringInfoNT(buffer, (char *) &endianess, WKB_BYTE_SIZE_ORDER); appendBinaryStringInfoNT(buffer, (char *) &type, WKB_BYTE_SIZE_TYPE); } /* * Writes a simple point to the buffer * Point has 2 bytes double values to represent x and y coordinates */ static inline void WritePointToWKBBuffer(StringInfo buffer, const Point *point) { appendBinaryStringInfo(buffer, (char *) point, WKB_BYTE_SIZE_POINT); } /* * Write `num` (number of components to the buffer) at the relative position from start of buffer. * `num` can represent number of points in multipoint, number of rings in polygon, number of geometries in collection etc */ static inline void WriteNumToWKBBufferAtPosition(StringInfo buffer, int32 relativePosition, int32 num) { Assert(buffer->len > relativePosition + WKB_BYTE_SIZE_NUM); memcpy(buffer->data + relativePosition, (void *) &num, WKB_BYTE_SIZE_NUM); } /* * Write `num` (number of components to the buffer) to buffer. * `num` can represent number of points in multipoint, number of rings in polygon, number of geometries in collection etc */ static inline void WriteNumToWKBBuffer(StringInfo buffer, int32 num) { appendBinaryStringInfoNT(buffer, (char *) &num, WKB_BYTE_SIZE_NUM); } /* * Appends the StringInfo buffer to the WKB buffer */ static inline void WriteStringInfoBufferToWKBBuffer(StringInfo wkbBuffer, StringInfo bufferToAppend) { appendBinaryStringInfoNT(wkbBuffer, (char *) bufferToAppend->data, bufferToAppend->len); } /* * Appends the buffer with length to the WKB buffer */ static inline void WriteBufferWithLengthToWKBBuffer(StringInfo wkbBuffer, const char *bufferStart, int32 length) { appendBinaryStringInfoNT(wkbBuffer, bufferStart, length); } /* * Appends the StringInfo buffer from the offset to the WKB buffer */ static inline void WriteStringInfoBufferToWKBBufferWithOffset(StringInfo wkbBuffer, StringInfo bufferToAppend, Size offset) { appendBinaryStringInfoNT(wkbBuffer, (char *) bufferToAppend->data + offset, bufferToAppend->len - offset); } /* * Deep frees a WKB buffer stored as StringInfo, resetStringInfo() only reset the data * pointer to null and doesn't clean the palloc'd memory */ static inline void DeepFreeWKB(StringInfo wkbBuffer) { if (wkbBuffer->data != NULL) { pfree(wkbBuffer->data); } pfree(wkbBuffer); } /* * WKBBufferGetByteaWithSRID accepts a WKB of a single geometry / geography * which should be of format: * <1B order> <4B type> . * * This function also converts the WKB to an Extended WKB with SRID stuffed in. * The bytea returned from this function would have the format: * <1B order> <4B modified type> <4B SRID> */ static inline bytea * WKBBufferGetByteaWithSRID(StringInfo wkbBuffer) { /* bytea will have => len (varlena header) + */ Size size = wkbBuffer->len + VARHDRSZ + WKB_BYTE_SIZE_SRID; bytea *result = (bytea *) palloc0(size); /* Write the size */ SET_VARSIZE(result, size); uint8 *wkbData = (uint8 *) VARDATA_ANY(result); /* First copy the endianess */ memcpy(wkbData, wkbBuffer->data, WKB_BYTE_SIZE_ORDER); /* Stuff the SRID flag in type */ uint32 type = 0; memcpy(&type, (wkbBuffer->data + WKB_BYTE_SIZE_ORDER), sizeof(uint32)); type = type | POSTGIS_EWKB_SRID_FLAG; memcpy((wkbData + WKB_BYTE_SIZE_ORDER), (uint8 *) &type, WKB_BYTE_SIZE_TYPE); /* insert SRID after type */ uint32 srid = DEFAULT_GEO_SRID; uint32 sridPos = WKB_BYTE_SIZE_ORDER + WKB_BYTE_SIZE_TYPE; memcpy((wkbData + sridPos), (uint8 *) &srid, WKB_BYTE_SIZE_SRID); /* copy data excluding endianess and type and insert it after srid */ uint32 dataPos = sridPos + WKB_BYTE_SIZE_SRID; uint32 endianAndTypeLen = WKB_BYTE_SIZE_ORDER + WKB_BYTE_SIZE_TYPE; memcpy((wkbData + dataPos), (wkbBuffer->data + endianAndTypeLen), (wkbBuffer->len - endianAndTypeLen)); return result; } /* * WKBBufferGetCollectionByteaWithSRID accepts a WKB of a multiple geometry / geography * which should be of format: * [<1B order> <4B type> ... ] * * This function creates a new collected type of `collectType` and stuffs in SRID and returns * bytea of this format: * <1B order> <4B collectType type> <4B SRID> */ static inline bytea * WKBBufferGetCollectionByteaWithSRID(StringInfo wkbBuffer, WKBGeometryType collectType, int32 totalNum) { /* bytea will have => (varlena header) + endianess + type + Srid + numofcollection + data */ Size size = VARHDRSZ + WKB_BYTE_SIZE_ORDER + WKB_BYTE_SIZE_TYPE + WKB_BYTE_SIZE_SRID + WKB_BYTE_SIZE_NUM + wkbBuffer->len; bytea *result = (bytea *) palloc0(size); /* Write the size */ SET_VARSIZE(result, size); uint8 *wkbData = (uint8 *) VARDATA_ANY(result); /* First write the endianess */ memcpy(wkbData, wkbBuffer->data, WKB_BYTE_SIZE_ORDER); /* Stuff the SRID flag in type */ int32 type = collectType | POSTGIS_EWKB_SRID_FLAG; memcpy((wkbData + WKB_BYTE_SIZE_ORDER), (uint8 *) &type, WKB_BYTE_SIZE_TYPE); /* insert SRID after type */ uint32 srid = DEFAULT_GEO_SRID; uint32 sridPos = WKB_BYTE_SIZE_ORDER + WKB_BYTE_SIZE_TYPE; memcpy((wkbData + sridPos), (uint8 *) &srid, WKB_BYTE_SIZE_SRID); /* Number of items to copy */ uint32 totalPos = sridPos + WKB_BYTE_SIZE_TYPE; memcpy((wkbData + totalPos), (uint8 *) &totalNum, WKB_BYTE_SIZE_SRID); /* * copy data completely, for a collection like Multipoint and GeometryCollection each * each individual entries have their own endianess and type */ uint32 dataPos = totalPos + WKB_BYTE_SIZE_NUM; memcpy((wkbData + dataPos), wkbBuffer->data, wkbBuffer->len); return result; } #endif documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geospatial_shape_operators.h000066400000000000000000000060461507310017400311740ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geospatial_shape_operators.h * * Common function and type declarations for shape operators * *------------------------------------------------------------------------- */ #ifndef BSON_GEOSPATIAL_SHAPE_OPERATORS_H #define BSON_GEOSPATIAL_SHAPE_OPERATORS_H #include "postgres.h" #include "io/bson_core.h" #include "planner/mongo_query_operator.h" /* * Type of shape operators. */ typedef enum GeospatialShapeOperator { GeospatialShapeOperator_UNKNOWN = 0, GeospatialShapeOperator_POLYGON, GeospatialShapeOperator_BOX, GeospatialShapeOperator_CENTER, GeospatialShapeOperator_GEOMETRY, GeospatialShapeOperator_CENTERSPHERE, /* Deprecated !! It is part of the types so that this can be ignored */ GeospatialShapeOperator_UNIQUEDOCS, } GeospatialShapeOperator; /* * $centerSphere uses different postgis functions for different stages */ typedef enum QueryStage { QueryStage_UNKNOWN = 0, QueryStage_RUNTIME, QueryStage_INDEX, } QueryStage; /* * Parent struct for shape operator state, for e.g. DollarCenterOperatorState. * For derived types this should be the first member. */ typedef struct ShapeOperatorState { }ShapeOperatorState; /* * To carry shape-specific info */ typedef struct ShapeOperatorInfo { QueryStage queryStage; GeospatialShapeOperator op; /* Parent query operator type */ MongoQueryOperatorType queryOperatorType; /* * Radius for $center and $centerSphere. * Can be set to anything for other operators */ ShapeOperatorState *opState; } ShapeOperatorInfo; /* * Function prototype for getting the shape operators */ typedef Datum (*BsonValueGetShapeDatum) (const bson_value_t *, ShapeOperatorInfo *); /* * BsonValueGetShapeDatum takes a specific bson value and returns the * corresponding postgis geometry/geography shape. */ typedef struct ShapeOperator { /* Name of the shape operator */ const char *shapeOperatorName; /* Enum type */ GeospatialShapeOperator op; /* Whether or not the operator is spherical in nature */ bool isSpherical; /* Function that return the geometry/geography postgis shape */ BsonValueGetShapeDatum getShapeDatum; /* * Determines if we should segmentize at index pushdown. * Set to false for $box, $center and $centerSphere */ bool shouldSegmentize; } ShapeOperator; /* * Operator state for $center and $centerSphere operators. */ typedef struct DollarCenterOperatorState { ShapeOperatorState opState; /* Input radius, in radians for $centerSphere and in 2d units for $center */ double radius; /* Radius converted to meters */ double radiusInMeters; /* Area of compliment geography for $centerSphere input in case of radius > (pi/2) */ Datum complimentArea; /* Check if radius is infinite for $center or >= pi for $centerSphere */ bool isRadiusInfinite; }DollarCenterOperatorState; const ShapeOperator * GetShapeOperatorByValue(const bson_value_t *shapeValue, bson_value_t *shapePointsOut); #endif documentdb-0.108-0/pg_documentdb/include/geospatial/bson_geospatial_wkb_iterator.h000066400000000000000000000076471507310017400305020ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/geospatial/bson_geospatial_wkb_iterator.h * * Custom iterator for WKB buffer * *------------------------------------------------------------------------- */ #ifndef WKBBufferITERATOR_H #define WKBBufferITERATOR_H #include "postgres.h" #include "geospatial/bson_geospatial_private.h" #include "utils/documentdb_errors.h" typedef struct WKBBufferIterator { /* Pointer to start of wkb buffer */ const char *headptr; /* Pointer to current position in buffer while iterating */ char *currptr; /* Original length of buffer */ int len; }WKBBufferIterator; /* * A set of const pointer, length and type describing a shape in between a WKB buffer * This is designed to be an immutable const struct to avoid any accidental modification of the buffer * and also helps in avoiding memcpy from original wkb buffer to get the single geometry buffer by * referring to the pointers in original buffer. * * Other shape specific const properties can also be added in the future. */ typedef struct WKBGeometryConst { /* Shape definition */ const WKBGeometryType geometryType; const char *geometryStart; const int32 length; /* Polygon state */ const char *ringPointsStart; const int32 numRings; const int32 numPoints; } WKBGeometryConst; typedef struct WKBVisitorFunctions { /* * Executed for a complete geometry represented by the WKB buffer type, it can be an atomic type such as * Point, Linestring, Polygon or a Multi collection such as MultiPoint, GeometryCollection etc. */ void (*VisitGeometry)(const WKBGeometryConst *wkbGeometry, void *state); /* * Executed for each individual geometries inside of a Multi collection geometry. */ void (*VisitSingleGeometry)(const WKBGeometryConst *wkbGeometry, void *state); /* * Called for each individual point found during traversal, points can be part of any geometry e.g lineString, polygons rings, multipoint etc. */ void (*VisitEachPoint)(const WKBGeometryConst *wkbGeometry, void *state); /* Currently only called during polygon validation to check for validitiy of each ring */ void (*VisitPolygonRing)(const WKBGeometryConst *wkbGeometry, void *state); /* * Whether or not continue traversal of the WKB buffer, this can be used to stop the traversal */ bool (*ContinueTraversal)(void *state); } WKBVisitorFunctions; /* Initialize a WKBBufferIterator from given wkb buffer stringinfo */ static inline void InitIteratorFromWKBBuffer(WKBBufferIterator *iter, StringInfo wkbBuffer) { iter->headptr = wkbBuffer->data; /* Set currptr also to wkbBuffer->data as we start from the head */ iter->currptr = wkbBuffer->data; iter->len = wkbBuffer->len; } /* Initialize a WKBBufferIterator from given char * and length */ static inline void InitIteratorFromPtrAndLen(WKBBufferIterator *iter, const char *currptr, int32 len) { iter->headptr = currptr; /* Set currptr also to wkbBuffer->data as we start from the head */ iter->currptr = (char *) currptr; iter->len = len; } /* Util to increment current pointer in iterator by given number of bytes */ static inline void IncrementWKBBufferIteratorByNBytes(WKBBufferIterator *iter, size_t bytes) { size_t remainingLength = (size_t) iter->len - (iter->currptr - iter->headptr); if (remainingLength >= bytes) { iter->currptr += bytes; } else { size_t overflow = bytes - remainingLength; ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Requested to increment WKB buffer %ld bytes beyond limit.", overflow), errdetail_log( "Requested to increment WKB buffer %ld bytes beyond limit.", overflow))); } } void TraverseWKBBuffer(const StringInfo wkbBuffer, const WKBVisitorFunctions *visitorFuncs, void *state); void TraverseWKBBytea(const bytea *wkbBytea, const WKBVisitorFunctions *visitorFuncs, void *state); #endif documentdb-0.108-0/pg_documentdb/include/index_am/000077500000000000000000000000001507310017400220225ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/index_am/documentdb_rum.h000066400000000000000000000077731507310017400252200ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/index_am/documentdb_rum.h * * Common declarations for RUM specific helper functions. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_RUM_H #define DOCUMENTDB_RUM_H #include #include #include #include "index_am/index_am_exports.h" typedef void *(*CreateIndexArrayTrackerState)(void); typedef bool (*IndexArrayTrackerAdd)(void *state, ItemPointer item); typedef void (*FreeIndexArrayTrackerState)(void *); typedef void (*UpdateMultikeyStatusFunc)(Relation index); /* * Adapter struct that provides function pointers to allow * for extensibility in managing index array state for index scans. * The current requirements on the interface is to provide an abstraction * that can be used to deduplicate array entries in the index scan. */ typedef struct RumIndexArrayStateFuncs { /* Create opaque state to manage entries in this specific index scan */ CreateIndexArrayTrackerState createState; /* Add an item to the index scan and return whether or not it is new or existing */ IndexArrayTrackerAdd addItem; /* Frees the temporary state used for the adding of items */ FreeIndexArrayTrackerState freeState; } RumIndexArrayStateFuncs; /* How to load the RUM library into the process */ typedef enum RumLibraryLoadOptions { /* Apply no customizations - load the default RUM lib */ RumLibraryLoadOption_None = 0, /* Prefer to load the custom documentdb_rum if available and fall back */ RumLibraryLoadOption_PreferDocumentDBRum = 1, /* Require hte custom documentdb_rum */ RumLibraryLoadOption_RequireDocumentDBRum = 2, } RumLibraryLoadOptions; /* Registers an extensibility that handles index array deduplication */ void RegisterIndexArrayStateFuncs(const RumIndexArrayStateFuncs *funcs); typedef bool (*CanOrderInIndexScan)(IndexScanDesc scan); extern RumLibraryLoadOptions DocumentDBRumLibraryLoadOption; void LoadRumRoutine(void); IndexAmRoutine *GetRumIndexHandler(PG_FUNCTION_ARGS); IndexScanDesc extension_rumbeginscan_core(Relation rel, int nkeys, int norderbys, IndexAmRoutine *coreRoutine); void extension_rumendscan_core(IndexScanDesc scan, IndexAmRoutine *coreRoutine); void extension_rumrescan_core(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys, IndexAmRoutine *coreRoutine, GetMultikeyStatusFunc multiKeyStatusFunc, CanOrderInIndexScan indexScanOrderedFunc); int64 extension_rumgetbitmap_core(IndexScanDesc scan, TIDBitmap *tbm, IndexAmRoutine *coreRoutine); bool extension_rumgettuple_core(IndexScanDesc scan, ScanDirection direction, IndexAmRoutine *coreRoutine); void extension_rumcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages); IndexBuildResult * extension_rumbuild_core(Relation heapRelation, Relation indexRelation, struct IndexInfo *indexInfo, IndexAmRoutine *coreRoutine, UpdateMultikeyStatusFunc updateMultikeyStatus, bool amCanBuildParallel); bool extension_ruminsert_core(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, struct IndexInfo *indexInfo, IndexAmRoutine *coreRoutine, UpdateMultikeyStatusFunc updateMultikeyStatus); void RumUpdateMultiKeyStatus(Relation index); bool RumGetMultikeyStatus(Relation indexRelation); bool RumGetTruncationStatus(Relation indexRelation); struct ExplainState; void ExplainCompositeScan(IndexScanDesc scan, struct ExplainState *es); void ExplainRegularIndexScan(IndexScanDesc scan, struct ExplainState *es); #endif documentdb-0.108-0/pg_documentdb/include/index_am/index_am_exports.h000066400000000000000000000042241507310017400255450ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/index_am/index_am_exports.h * * Common exports for index extensibility. * *------------------------------------------------------------------------- */ #ifndef INDEX_AM_EXPORTS_H #define INDEX_AM_EXPORTS_H #include #include struct IndexScanDescData; struct ExplainState; typedef void (*TryExplainIndexFunc)(struct IndexScanDescData *scan, struct ExplainState *es); typedef bool (*GetMultikeyStatusFunc)(Relation indexRelation); typedef bool (*GetTruncationStatusFunc)(Relation indexRelation); /* * Data structure for an alternative index acess method for indexing bosn. * It contains the indexing capability and various utility function. */ typedef struct { bool is_single_path_index_supported; bool is_unique_index_supported; bool is_wild_card_supported; bool is_composite_index_supported; bool is_text_index_supported; bool is_hashed_index_supported; bool is_order_by_supported; bool is_backwards_scan_supported; bool is_index_only_scan_supported; Oid (*get_am_oid)(void); Oid (*get_single_path_op_family_oid)(void); Oid (*get_composite_path_op_family_oid)(void); Oid (*get_text_path_op_family_oid)(void); Oid (*get_hashed_path_op_family_oid)(void); Oid (*get_unique_path_op_family_oid)(void); /* optional func to add explain output */ TryExplainIndexFunc add_explain_output; /* The am name for create indexes */ const char *am_name; /* The opclass primary catalog schema name */ const char *(*get_opclass_catalog_schema)(void); /* An alternate internal schema name for op classes if not the catalog schema */ const char *(*get_opclass_internal_catalog_schema)(void); /* Optional function that handles getting multi-key status for an index */ GetMultikeyStatusFunc get_multikey_status; /* Optional function to that returns the truncation status of an index */ GetTruncationStatusFunc get_truncation_status; } BsonIndexAmEntry; /* * Registers an bson index access method at system start time. */ void RegisterIndexAm(BsonIndexAmEntry indexAmEntry); #endif documentdb-0.108-0/pg_documentdb/include/index_am/index_am_utils.h000066400000000000000000000041231507310017400251770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/index_am/index_am_utils.h * * Common declarations for RUM specific helper functions. * *------------------------------------------------------------------------- */ #ifndef INDEX_AM_UTILS_H #define INDEX_AM_UTILS_H #include #include #include "metadata/metadata_cache.h" #include "utils/version_utils.h" #include "index_am/index_am_exports.h" #define MAX_ALTERNATE_INDEX_AMS 5 int SetDynamicIndexAmOidsAndGetCount(Datum *indexAmArray, int32_t indexAmArraySize); /* * Gets an index AM entry by name. */ const BsonIndexAmEntry * GetBsonIndexAmByIndexAmName(const char *index_am_name); /* * Is the Index Acess Method used for indexing bson (as opposed to indexing TEXT, Vector, Points etc) * as indicated by enum MongoIndexKind_Regular. */ bool IsBsonRegularIndexAm(Oid indexAm); bool BsonIndexAmRequiresRangeOptimization(Oid indexAm, Oid opFamilyOid); /* * Whether the index relation was created via a composite index opclass */ bool IsCompositeOpClass(Relation indexRelation); bool IsCompositeOpFamilyOid(Oid relam, Oid opFamilyOid); /* * Whether the Oid of the oprator family points to a single path operator family. */ bool IsSinglePathOpFamilyOid(Oid relam, Oid opFamilyOid); /* * Whether the Oid of the oprator family points to a text path operator family. */ bool IsTextPathOpFamilyOid(Oid relam, Oid opFamilyOid); Oid GetTextPathOpFamilyOid(Oid relam); bool IsUniqueCheckOpFamilyOid(Oid relam, Oid opFamilyOid); bool IsHashedPathOpFamilyOid(Oid relam, Oid opFamilyOid); bool IsOrderBySupportedOnOpClass(Oid indexAm, Oid IndexPathOpFamilyAm); GetMultikeyStatusFunc GetMultiKeyStatusByRelAm(Oid relam); bool GetIndexSupportsBackwardsScan(Oid relam); bool GetIndexAmSupportsIndexOnlyScan(Oid indexAm, Oid opFamilyOid, GetMultikeyStatusFunc *getMultiKeyStatus, GetTruncationStatusFunc *getTruncationStatus); void TryExplainByIndexAm(struct IndexScanDescData *scan, struct ExplainState *es); #endif documentdb-0.108-0/pg_documentdb/include/index_am/roaring_bitmap_adapter.h000066400000000000000000000006441507310017400266740ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) 2025 documentdb. All rights reserved. * * include/bitmap_utils/roaring_bitmap_adapter.h * * adapter for bitmap functions * *------------------------------------------------------------------------- */ #ifndef ROARING_BITMAP_ADAPTER_H #define ROARING_BITMAP_ADAPTER_H void RegisterRoaringBitmapHooks(void); #endif documentdb-0.108-0/pg_documentdb/include/infrastructure/000077500000000000000000000000001507310017400233165ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/infrastructure/cursor_store.h000066400000000000000000000021231507310017400262160ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/documentdb_plan_cache.h * * Common declarations for the pg_documentdb plan cache. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_CURSOR_STORE_H #define DOCUMENTDB_CURSOR_STORE_H #include typedef struct CursorFileState CursorFileState; void SetupCursorStorage(void); void InitializeFileCursorShmem(void); Size FileCursorShmemSize(void); void DeletePendingCursorFiles(void); void GetCurrentCursorCount(int32_t *currentCursorCount, int32_t *measuredCursorCount, int64_t *lastCursorSize); void DeleteCursorFile(const char *cursorName); CursorFileState * CreateCursorFile(const char *cursorName); void WriteToCursorFile(CursorFileState *cursorFileState, pgbson *bson); pgbson * ReadFromCursorFile(CursorFileState *cursorFileState); bytea * CursorFileStateClose(CursorFileState *cursorFileState); CursorFileState * DeserializeFileState(bytea *cursorFileState); #endif documentdb-0.108-0/pg_documentdb/include/infrastructure/documentdb_plan_cache.h000066400000000000000000000101401507310017400277440ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/documentdb_plan_cache.h * * Common declarations for the pg_documentdb plan cache. * *------------------------------------------------------------------------- */ #ifndef BSON_PLAN_CACHE_H #define BSON_PLAN_CACHE_H #include /* * ID prefixes for different types of query. * * The first 32 bits of a query ID are used to identity the operation, * and the latter 32 bits to identify different query variants. */ #define QUERY_ID_INSERT (1L << 32) #define QUERY_ID_UPDATE_BY_TID (2L << 32) #define QUERY_ID_DELETE_BY_TID (3L << 32) /* TODO: remove once we fully support let and collation with delete */ #define QUERY_DELETE_WITH_FILTER (4L << 32); #define QUERY_DELETE_WITH_FILTER_SHARDKEY (5L << 32) #define QUERY_DELETE_WITH_FILTER_ID (6L << 32) #define QUERY_DELETE_WITH_FILTER_SHARDKEY_ID (7L << 32) #define QUERY_CALL_UPDATE_ONE (8L << 32) #define QUERY_DELETE_ONE (9L << 32) #define QUERY_DELETE_ONE_ID (10L << 32) #define QUERY_DELETE_ONE_ID_RETURN_DOCUMENT (11L << 32) /* TODO: remove once we fully support let and collation with delete */ #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE (12L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_NON_OBJECT_ID (13L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_ONLY_OBJECT_ID (14L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_BOTH_FILTER (15L << 32) #define QUERY_ID_RETRY_RECORD_INSERT (20L << 32) #define QUERY_ID_RETRY_RECORD_DELETE (21L << 32) #define QUERY_ID_RETRY_RECORD_SELECT (22L << 32) #define QUERY_ID_INSERT_OR_REPLACE (23L << 32) #define QUERY_DELETE_WITH_FILTER_LET_AND_COLLATION (30L << 32) #define QUERY_DELETE_WITH_FILTER_SHARDKEY_LET_AND_COLLATION (31L << 32) #define QUERY_DELETE_WITH_FILTER_ID_LET_AND_COLLATION (32L << 32) #define QUERY_DELETE_WITH_FILTER_SHARDKEY_ID_LET_AND_COLLATION (33L << 32) #define QUERY_DELETE_ONE_LET_AND_COLLATION (34L << 32) #define QUERY_DELETE_ONE_ID_LET_AND_COLLATION (35L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_LET_AND_COLLATION (36L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_NON_OBJECT_ID_LET_AND_COLLATION (37L << 32) #define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_BOTH_FILTER_LET_AND_COLLATION (38L << 32) #define QUERY_UPDATE_MANY_SHARD_KEY_QUERY_OFFSET (1L << 32) #define QUERY_UPDATE_MANY_OBJECTID_QUERY_OFFSET (2L << 32) #define QUERY_UPDATE_MANY_SHARD_KEY_OBJECT_ID_QUERY_OFFSET \ QUERY_UPDATE_MANY_SHARD_KEY_QUERY_OFFSET + QUERY_UPDATE_MANY_OBJECTID_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION (40L << 32) #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION_WITH_SHARD_KEY \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION + \ QUERY_UPDATE_MANY_SHARD_KEY_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION_WITH_OBJECT_ID \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION + QUERY_UPDATE_MANY_OBJECTID_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION_WITH_SHARD_KEY_AND_OBJECT_ID \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_FUNCTION + \ QUERY_UPDATE_MANY_SHARD_KEY_OBJECT_ID_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR (44L << 32) #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR_WITH_SHARD_KEY \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR + \ QUERY_UPDATE_MANY_SHARD_KEY_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR_WITH_OBJECT_ID \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR + QUERY_UPDATE_MANY_OBJECTID_QUERY_OFFSET #define QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR_WITH_SHARD_KEY_AND_OBJECT_ID \ QUERY_UPDATE_MANY_WITH_QUERY_FILTER_OPERATOR + \ QUERY_UPDATE_MANY_SHARD_KEY_OBJECT_ID_QUERY_OFFSET /* GUC that controls the query plan cache size */ extern int QueryPlanCacheSizeLimit; void InitializeQueryPlanCache(void); SPIPlanPtr GetSPIQueryPlan(uint64 collectionId, uint64 queryId, const char *query, Oid *argTypes, int argCount); SPIPlanPtr GetSPIQueryPlanWithLocalShard(uint64 collectionId, const char *shardTableName, uint64 queryId, const char *query, Oid *argTypes, int argCount); #endif documentdb-0.108-0/pg_documentdb/include/jsonschema/000077500000000000000000000000001507310017400223705ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/jsonschema/bson_json_schema_tree.h000066400000000000000000000134551507310017400271020ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_json_schema_tree.h * * Common declarations of structs and functions for handling bson json schema tree. * *------------------------------------------------------------------------- */ #ifndef BSON_JSON_SCHEMA_TREE_H #define BSON_JSON_SCHEMA_TREE_H #include "query/bson_compare.h" #include "types/pcre_regex.h" #include "query/bson_dollar_operators.h" /* -------------------------------------------------------- */ /* Data types */ /* -------------------------------------------------------- */ typedef struct SchemaNode SchemaNode; typedef struct SchemaFieldNode SchemaFieldNode; typedef struct SchemaKeywordNode SchemaKeywordNode; typedef enum BsonTypeFlags { BsonTypeFlag_EOD = 1 << 0, BsonTypeFlag_DOUBLE = 1 << 1, BsonTypeFlag_UTF8 = 1 << 2, BsonTypeFlag_DOCUMENT = 1 << 3, BsonTypeFlag_ARRAY = 1 << 4, BsonTypeFlag_BINARY = 1 << 5, BsonTypeFlag_UNDEFINED = 1 << 6, BsonTypeFlag_OID = 1 << 7, BsonTypeFlag_BOOL = 1 << 8, BsonTypeFlag_DATE_TIME = 1 << 9, BsonTypeFlag_NULL = 1 << 10, BsonTypeFlag_REGEX = 1 << 11, BsonTypeFlag_DBPOINTER = 1 << 12, BsonTypeFlag_CODE = 1 << 13, BsonTypeFlag_SYMBOL = 1 << 14, BsonTypeFlag_CODEWSCOPE = 1 << 15, BsonTypeFlag_INT32 = 1 << 16, BsonTypeFlag_TIMESTAMP = 1 << 17, BsonTypeFlag_INT64 = 1 << 18, BsonTypeFlag_DECIMAL128 = 1 << 19, BsonTypeFlag_MINKEY = 1 << 20, BsonTypeFlag_MAXKEY = 1 << 21 } BsonTypeFlags; typedef enum ObjectValidationTypes { ObjectValidationTypes_MaxProperties = 1 << 0, ObjectValidationTypes_MinProperties = 1 << 1, ObjectValidationTypes_Required = 1 << 2, ObjectValidationTypes_Properties = 1 << 3, ObjectValidationTypes_PatternProperties = 1 << 4, ObjectValidationTypes_AdditionalPropertiesBool = 1 << 5, ObjectValidationTypes_AdditionalPropertiesObject = 1 << 6, ObjectValidationTypes_Dependency = 1 << 7, ObjectValidationTypes_DependencyArray = 1 << 8, ObjectValidationTypes_DependencyObject = 1 << 9, } ObjectValidationTypes; typedef enum CommonValidationTypes { CommonValidationTypes_Enum = 1 << 0, CommonValidationTypes_JsonType = 1 << 1, CommonValidationTypes_BsonType = 1 << 2, CommonValidationTypes_AllOf = 1 << 3, CommonValidationTypes_AnyOf = 1 << 4, CommonValidationTypes_OneOf = 1 << 5, CommonValidationTypes_Not = 1 << 6 } CommonValidationTypes; typedef enum NumericValidationTypes { NumericValidationTypes_MultipleOf = 1 << 0, NumericValidationTypes_Maximum = 1 << 1, NumericValidationTypes_ExclusiveMaximum = 1 << 2, NumericValidationTypes_Minimum = 1 << 3, NumericValidationTypes_ExclusiveMinimum = 1 << 4, } NumericValidationTypes; typedef enum StringValidationTypes { StringValidationTypes_MaxLength = 1 << 0, StringValidationTypes_MinLength = 1 << 1, StringValidationTypes_Pattern = 1 << 2, } StringValidationTypes; typedef enum ArrayValidationTypes { ArrayValidationTypes_MaxItems = 1 << 0, ArrayValidationTypes_MinItems = 1 << 1, ArrayValidationTypes_UniqueItems = 1 << 2, ArrayValidationTypes_ItemsObject = 1 << 3, ArrayValidationTypes_ItemsArray = 1 << 4, ArrayValidationTypes_AdditionalItemsBool = 1 << 5, ArrayValidationTypes_AdditionalItemsObject = 1 << 6, } ArrayValidationTypes; typedef enum BinaryValidationTypes { BinaryValidationTypes_Encrypt = 1 << 0, } BinaryValidationTypes; typedef enum SchemaNodeType { SchemaNodeType_Invalid = 0, SchemaNodeType_Field, SchemaNodeType_Root, SchemaNodeType_AdditionalProperties, SchemaNodeType_PatternProperties, SchemaNodeType_Dependencies, SchemaNodeType_Items, SchemaNodeType_AdditionalItems, SchemaNodeType_AllOf, SchemaNodeType_AnyOf, SchemaNodeType_OneOf, SchemaNodeType_Not, } SchemaNodeType; typedef struct ValidationsObject { /* List of child field nodes */ SchemaFieldNode *properties; /* Array of required field names */ bson_value_t *required; } ValidationsObject; typedef struct ValidationsCommon { BsonTypeFlags jsonTypes; BsonTypeFlags bsonTypes; } ValidationsCommon; typedef struct ValidationsNumeric { bson_value_t *maximum; bool exclusiveMaximum; bson_value_t *minimum; bool exclusiveMinimum; bson_value_t *multipleOf; } ValidationsNumeric; typedef struct ValidationsString { uint32_t maxLength; uint32_t minLength; RegexData *pattern; } ValidationsString; typedef struct ValidationsArray { uint32_t maxItems; uint32_t minItems; bool uniqueItems; union { SchemaKeywordNode *itemsNode; /* List of dependency item schemas */ SchemaKeywordNode *itemsArray; }; union { bool additionalItemsBool; SchemaKeywordNode *additionalItemsNode; }; } ValidationsArray; typedef struct Validations { ValidationsObject *object; ValidationsCommon *common; ValidationsNumeric *numeric; ValidationsString *string; ValidationsArray *array; }Validations; typedef struct ValidationFlags { uint16_t object; uint16_t common; uint16_t numeric; uint16_t string; uint16_t array; uint16_t binary; }ValidationFlags; struct SchemaNode { SchemaNodeType nodeType; Validations validations; ValidationFlags validationFlags; /* link to next node of linked list (e.g. sibling node) */ struct SchemaNode *next; }; struct SchemaFieldNode { SchemaNode base; /* This is the non-dotted field path at the current level */ StringView field; }; struct SchemaKeywordNode { SchemaNode base; RegexData *fieldPattern; }; typedef struct SchemaTreeState { SchemaNode *rootNode; }SchemaTreeState; /* -------------------------------------------------------- */ /* Functions */ /* -------------------------------------------------------- */ void BuildSchemaTree(SchemaTreeState *treeState, bson_iter_t *schemaIter); SchemaFieldNode * FindFieldNodeByName(const SchemaNode *parent, const char *field); #endif documentdb-0.108-0/pg_documentdb/include/metadata/000077500000000000000000000000001507310017400220165ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/metadata/collection.h000066400000000000000000000177341507310017400243360ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/metadata/collection.h * * Common declarations for collections, views and data tables. * *------------------------------------------------------------------------- */ #ifndef MONGO_COLLECTIONS_H #define MONGO_COLLECTIONS_H #include #include #include #include #include "io/bson_core.h" /* The max depth a view can have */ #define MAX_VIEW_DEPTH 20 #define MAX_DATABASE_NAME_LENGTH (64) #define MAX_COLLECTION_NAME_LENGTH (256) #define MAX_NAMESPACE_NAME_LENGTH (64 + 256 + 1) #define DOCUMENT_DATA_TABLE_NAME_PREFIX "documents_" #define DOCUMENT_DATA_TABLE_NAME_FORMAT DOCUMENT_DATA_TABLE_NAME_PREFIX UINT64_FORMAT /* constants for document column of a data table */ #define DOCUMENT_DATA_TABLE_DOCUMENT_VAR_COLLATION (InvalidOid) #define DOCUMENT_DATA_TABLE_DOCUMENT_VAR_TYPMOD ((int32) (-1)) /* Attribute number constants for the layout of the data table */ #define DOCUMENT_DATA_TABLE_SHARD_KEY_VALUE_VAR_ATTR_NUMBER ((AttrNumber) 1) #define DOCUMENT_DATA_TABLE_OBJECT_ID_VAR_ATTR_NUMBER ((AttrNumber) 2) #define DOCUMENT_DATA_TABLE_DOCUMENT_VAR_ATTR_NUMBER ((AttrNumber) 3) #define DOCUMENT_CHANGE_STREAM_TABLE_DOCUMENT_VAR_ATTR_NUMBER ((AttrNumber) 1) #define DOCUMENT_CHANGE_STREAM_TABLE_CONTINUATION_VAR_ATTR_NUMBER ((AttrNumber) 2) /* * MongoCollectionName represents the qualified name of a Mongo collection. */ typedef struct { char databaseName[MAX_DATABASE_NAME_LENGTH]; char collectionName[MAX_COLLECTION_NAME_LENGTH]; } MongoCollectionName; /* * Validation Level enum used for schema validation of existing docs. * Supported levels: "off", "strict", "moderate" */ typedef enum { ValidationLevel_Invalid = 0, ValidationLevel_Strict, ValidationLevel_Moderate, ValidationLevel_Off } ValidationLevels; /* * Validation Action enum used for schema validation to specify how to handle invalid documents. * Supported actions: "warn", "error" */ typedef enum { ValidationAction_Invalid = 0, ValidationAction_Warn, ValidationAction_Error } ValidationActions; /* This struct stores Schema Validation options associated with a collection */ typedef struct { pgbson *validator; ValidationLevels validationLevel; ValidationActions validationAction; } SchemaValidatorInfo; /* * MongoCollection contains metadata of a single Mongo collection. */ typedef struct { /* qualified name of the Mongo collection */ MongoCollectionName name; /* internal identifier of the Mongo collection */ uint64 collectionId; /* name of the Postgres table */ char tableName[NAMEDATALEN]; /* OID of the Postgres table */ Oid relationId; /* shard key BSON */ pgbson *shardKey; /* View definition if applicable */ pgbson *viewDefinition; /* The unique identifier (UUID) associated with the specified collection or view */ pg_uuid_t collectionUUID; /* creation_time column attribute number */ AttrNumber mongoDataCreationTimeVarAttrNumber; /* * An optional name for the shardTable if it has a distributed table associated with it * on the current node or empty string (Default) if unavailable. */ char shardTableName[NAMEDATALEN]; /* Whether or not the shard for the shardTableName is remote */ bool isShardRemote; /* Schema Validator if applicable */ SchemaValidatorInfo schemaValidator; } MongoCollection; /* * ViewDefinition is the decomposed version of a single viewDefinition bson */ typedef struct { /* The source collection or view for this view definition */ const char *viewSource; /* An optional pipeline to apply to the view * If not specified it's BSON_TYPE_EOD. */ bson_value_t pipeline; } ViewDefinition; /* decomposes the viewSpec into a ViewDefinition struct */ void DecomposeViewDefinition(pgbson *viewSpec, ViewDefinition *viewDefinition); pgbson * CreateViewDefinition(const ViewDefinition *viewDefinition); pgbson * CreateSchemaValidatorInfoDefinition(const SchemaValidatorInfo *schemaValidatorInfo); void ValidateViewDefinition(Datum databaseDatum, const char *viewName, const ViewDefinition *definition); void ValidateDatabaseCollection(Datum databaseDatum, Datum collectionDatum); /* get Mongo collection metadata by name */ MongoCollection * GetMongoCollectionByNameDatum(Datum dbNameDatum, Datum collectionNameDatum, LOCKMODE lockMode); MongoCollection * GetMongoCollectionOrViewByNameDatum(Datum dbNameDatum, Datum collectionNameDatum, LOCKMODE lockMode); MongoCollection * GetTempMongoCollectionByNameDatum(Datum dbNameDatum, Datum collectionNameDatum, char *collectionName, LOCKMODE lockMode); /* * Returns the OID of the physical shard table if applicable and if it * is available on the current node. If no such valid shard table can be * found (due to the table having multiple shards or it being on a different * machine), returns InvalidOid */ Oid TryGetCollectionShardTable(MongoCollection *collection, LOCKMODE lockMode); /* * Check if DB exists. Check is done case insensitively. If exists, return * TRUE and populates the output parameter dbNameInTable with the db name * from the catalog table, else FALSE */ bool TryGetDBNameByDatum(Datum databaseNameDatum, char *dbNameInTable); /* * Checks if the given collection belongs to the group of Non writable system * namespace. If yes, an ereport is done. */ void ValidateCollectionNameForUnauthorizedSystemNs(const char *collectionName, Datum databaseNameDatum); /* * Checks if the given collection name belongs to a valid system namespace */ void ValidateCollectionNameForValidSystemNamespace(StringView *collectionView, Datum databaseNameDatum); /* * Data table for given MongoCollection has been created within the current * transaction ? */ bool IsDataTableCreatedWithinCurrentXact(const MongoCollection *collection); /* make a copy of given MongoCollection */ MongoCollection * CopyMongoCollection(const MongoCollection *collection); /* get Mongo collection metadata by collection id */ MongoCollection * GetMongoCollectionByColId(uint64 collectionId, LOCKMODE lockMode); /* get Mongo collection metadata by realtion ID of a collection's shard */ MongoCollection * GetMongoCollectionByRelationShardId(Oid relationId); /* get OID of data table (documents_*) table by collection id */ Oid GetRelationIdForCollectionId(uint64 collectionId, LOCKMODE lockMode); /* c-wrapper for create_collection() */ bool CreateCollection(Datum dbNameDatum, Datum collectionNameDatum); /* c-wrapper for rename_collection() */ void RenameCollection(Datum dbNameDatum, Datum srcCollectionNameDatum, Datum destCollectionNameDatum, bool dropTarget); /* called by metadata_cache.c when cache invalidation occurs */ void ResetCollectionsCache(void); void InvalidateCollectionByRelationId(Oid relationId); /* insert/update schema validation meta*/ void UpsertSchemaValidation(Datum databaseDatum, Datum collectionNameDatum, const bson_value_t *validator, char *validationLevel, char *validationAction); const bson_value_t * ParseAndGetValidatorSpec(bson_iter_t *iter, const char *validatorName, bool *hasValue); char * ParseAndGetValidationLevelOption(bson_iter_t *iter, const char *validationLevelName, bool *hasValue); char * ParseAndGetValidationActionOption(bson_iter_t *iter, const char *validationActionName, bool *hasValue); void UpdateMongoCollectionUsingIds(MongoCollection *mongoCollection, uint64 collectionId, Oid shardOid); void SetUnshardedColocationData(text *databaseDatum, const char **shardingColumn, const char **colocateWith); void CreateRetryTable(char *retryTableName, char *colocateWith, const char *distributionColumnUsed, int shardCount); bool GetMongoCollectionShardOidsAndNames(MongoCollection *collection, ArrayType **shardIdArray, ArrayType **shardNames); #endif documentdb-0.108-0/pg_documentdb/include/metadata/index.h000066400000000000000000000233161507310017400233030ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/metadata/index.h * * Accessors around ApiCatalogSchema.collection_indexes. * *------------------------------------------------------------------------- */ #ifndef INDEXES_H #define INDEXES_H #include #include #include "io/bson_core.h" #define INVALID_INDEX_ID ((int) 0) /* arg1: ApiCatalogSchema.collection_indexes.index_id */ #define DOCUMENT_DATA_TABLE_INDEX_NAME_FORMAT_PREFIX "documents_rum_index_" #define DOCUMENT_DATA_TABLE_INDEX_NAME_FORMAT \ DOCUMENT_DATA_TABLE_INDEX_NAME_FORMAT_PREFIX "%d" #define DOCUMENT_DATA_PRIMARY_KEY_FORMAT_PREFIX "collection_pk_" #define ID_FIELD_KEY "_id" #define ID_INDEX_NAME "_id_" #define CREATE_INDEX_COMMAND_TYPE 'C' #define REINDEX_COMMAND_TYPE 'R' #define IndexRequestKey "indexRequest" #define IndexRequestKeyLength 12 #define CmdTypeKey "cmdType" #define CmdTypeKeyLength 7 #define IdsKey "ids" #define IdsKeyLength 3 extern int MaxNumActiveUsersIndexBuilds; typedef enum BoolIndexOption { BoolIndexOption_Undefined = 0, BoolIndexOption_False = 1, BoolIndexOption_True = 2, } BoolIndexOption; /* * Representation of index_spec_type. * * If you decide making any changes to this struct, consider syncing * following functions: * - DatumGetIndexSpec() * - IndexSpecGetDatum() * - CopyIndexSpec() * - IndexSpecOptionsAreEquivalent() * - MakeIndexSpecForIndexDef() * , and index_spec_type_internal type in documentdb_api.sql. */ typedef struct IndexSpec { /* index name, cannot be NULL */ char *indexName; /** index options start here **/ /* index version specified by "v" number. must be a positive number */ int indexVersion; /* "key" document, cannot be NULL */ pgbson *indexKeyDocument; /* "partialFilterExpression" document, allowed to be NULL */ pgbson *indexPFEDocument; /* normalized form of "wildcardProjection" document, allowed to be NULL */ pgbson *indexWPDocument; /* whether it's "sparse" or undefined */ BoolIndexOption indexSparse; /* whether it's "unique" or undefined */ BoolIndexOption indexUnique; /* document expiry time for TTL index, NULL means it's not specified */ int *indexExpireAfterSeconds; /* Options pertaining to cosmosSearch: TODO: Integrate with indexOptions */ pgbson *cosmosSearchOptions; /* General index options - new options should be appended here. */ pgbson *indexOptions; } IndexSpec; /* A set of text indexing weights for text indexes */ typedef struct TextIndexWeights { /* The path in the doc to index */ const char *path; /* The weight associated with the path */ double weight; } TextIndexWeights; /* * Metadata about indexes that can be queried from the index metadata API. */ typedef struct IndexDetails { /* index id assigned to this Mongo index */ int indexId; /* collection id of a collection to which this Mongo index belongs*/ uint64 collectionId; /* Mongo index spec */ IndexSpec indexSpec; /* Whether or not the index build is in progress (background build) */ bool isIndexBuildInProgress; } IndexDetails; /* * Index command status in ApiCatalogSchemaName.{ExtensionObjectPrefix}_index_queue * Since GetRequestFromIndexQueue relies on order of index_cmd_status to avoid the starvation * the enum values are kept in such a way that GetRequestFromIndexQueue always picks request in order * IndexCmdStatus_Queued first then IndexCmdStatus_Failed (ascending order). */ typedef enum IndexCmdStatus { IndexCmdStatus_Unknown = 0, IndexCmdStatus_Queued = 1, IndexCmdStatus_Inprogress = 2, IndexCmdStatus_Failed = 3, IndexCmdStatus_Skippable = 4, } IndexCmdStatus; /* * Index command request. The command can be of CREATE INDEX/DROP INDEX. */ typedef struct IndexCmdRequest { /* Postgres command */ char *cmd; /* index id assigned to this index */ int indexId; /* collection id of a collection to which this index belongs*/ uint64 collectionId; /* Internal retry attempt count that we maintain for each request*/ int16 attemptCount; /* comment from previous attempt*/ pgbson *comment; /* Denotes the time when request was updated in the extension_index_queue*/ TimestampTz updateTime; IndexCmdStatus status; /* Denotes the user who has triggered CreateIndexes*/ Oid userOid; /* The cmdType for this request */ char cmdType; } IndexCmdRequest; /* Return value of GetIndexBuildJobOpId */ typedef struct { /* timestamp for query start time from pg_stat_activity*/ TimestampTz start_time; /* global_pid from pg_stat_activity*/ int64 global_pid; } IndexJobOpId; /* * Represents the type of index for a given path. * Treat this as a flags so that we can check for * plugins. */ typedef enum MongoIndexKind { /* Unrecognized or unsupported index plugin */ MongoIndexKind_Unknown = 0x0, /* Regular asc/desc index */ MongoIndexKind_Regular = 0x1, /* Hashed index */ MongoIndexKind_Hashed = 0x2, /* Geospatial 2D index */ MongoIndexKind_2d = 0x4, /* Text search index */ MongoIndexKind_Text = 0x8, /* Geospatial 2D index */ MongoIndexKind_2dsphere = 0x10, /* A CosmosDB Indexing kind */ MongoIndexingKind_CosmosSearch = 0x20, } MongoIndexKind; typedef struct { const char *mongoIndexName; bool isSupported; MongoIndexKind indexKind; } MongoIndexSupport; /* index build tasks */ void UnscheduleIndexBuildTasks(char *extensionPrefix); void ScheduleIndexBuildTasks(char *extensionPrefix); MongoIndexKind GetMongoIndexKind(char *indexKindName, bool *isSupported); /* query index metadata */ IndexDetails * FindIndexWithSpecOptions(uint64 collectionId, const IndexSpec *targetIndexSpec); IndexDetails * IndexIdGetIndexDetails(int indexId); IndexDetails * IndexNameGetIndexDetails(uint64 collectionId, const char *indexName); IndexDetails * IndexNameGetReadyIndexDetails(uint64 collectionId, const char *indexName); List * IndexKeyGetMatchingIndexes(uint64 collectionId, const pgbson *indexKeyDocument); List * IndexKeyGetReadyMatchingIndexes(uint64 collectionId, const pgbson *indexKeyDocument); List * CollectionIdGetIndexes(uint64 collectionId, bool excludeIdIndex, bool enableNestedDistribution); List * CollectionIdGetValidIndexes(uint64 collectionId, bool excludeIdIndex, bool enableNestedDistribution); List * CollectionIdGetIndexNames(uint64 collectionId, bool excludeIdIndex, bool inProgressOnly); int CollectionIdGetIndexCount(uint64 collectionId); int CollectionIdsGetIndexCount(ArrayType *collectionIdsArray); bool IndexSpecIsWildcardIndex(const IndexSpec *indexSpec); bool IndexSpecIsOrderedIndex(const IndexSpec *indexSpec); /* modify/write index metadata */ int RecordCollectionIndex(uint64 collectionId, const IndexSpec *indexSpec, bool isKnownValid); int MarkIndexesAsValid(uint64 collectionId, const List *indexIdList); void DeleteAllCollectionIndexRecords(uint64 collectionId); void DeleteCollectionIndexRecord(uint64 collectionId, int indexId); List * MergeTextIndexWeights(List *textIndexes, const bson_value_t *weights, bool *isWildCard, bool includeWildCardInWeights); /* * An equivalency for Index Specifications. */ typedef enum IndexOptionsEquivalency { /* * The index specifications are not equivalent * (They are different) */ IndexOptionsEquivalency_NotEquivalent, /* * The index specifications are equivalent from * an options being compatible with each other * and should be treated as indexes that match * each other but are actually different indexes */ IndexOptionsEquivalency_Equivalent, /* * We allow only one text index per collection. * So, all subsequent text indexes are equivalent, * but we would need to throw a different error message. */ IndexOptionsEquivalency_TextEquivalent, /* * The index specs are actually the same. */ IndexOptionsEquivalency_Equal, } IndexOptionsEquivalency; /* public helpers for IndexSpec */ IndexOptionsEquivalency IndexSpecOptionsAreEquivalent(const IndexSpec *leftIndexSpec, const IndexSpec *rightIndexSpec); bool IndexSpecTTLOptionsAreSame(const IndexSpec *leftIndexSpec, const IndexSpec *rightIndexSpec); pgbson * IndexSpecAsBson(const IndexSpec *indexSpec); /* utilities for index_spec_type and IndexSpec objects */ BoolIndexOption BoolDatumGetBoolIndexOption(bool datumIsNull, Datum datum); IndexSpec * DatumGetIndexSpec(Datum datum); IndexSpec MakeIndexSpecForBuiltinIdIndex(void); Datum IndexSpecGetDatum(IndexSpec *indexSpec); IndexSpec * CopyIndexSpec(const IndexSpec *indexSpec); void WriteIndexSpecAsCurrentOpCommand(pgbson_writer *finalWriter, const char *databaseName, const char *collectionName, const IndexSpec *indexSpec); void RemoveRequestFromIndexQueue(int indexId, char cmdType); void MarkIndexRequestStatus(int indexId, char cmdType, IndexCmdStatus status, pgbson *comment, IndexJobOpId *opId, int16 attemptCount); IndexCmdStatus GetIndexBuildStatusFromIndexQueue(int indexId); IndexCmdRequest * GetRequestFromIndexQueue(uint64 collectionId, MemoryContext mcxt); IndexCmdRequest * GetSkippableRequestFromIndexQueue(int expireTimeInSeconds, List *skipCollections); uint64 * GetCollectionIdsForIndexBuild(List *excludeCollectionIds); void AddRequestInIndexQueue(char *createIndexCmd, int indexId, uint64 collectionId, char cmd_type, Oid userOid); char * GetIndexQueueName(void); const char * GetIndexTypeFromKeyDocument(pgbson *keyDocument); /* Static utilities */ static inline bool GetBoolFromBoolIndexOptionDefaultTrue(BoolIndexOption option) { return option == BoolIndexOption_Undefined || option == BoolIndexOption_False ? false : true; } static inline bool GetBoolFromBoolIndexOptionDefaultFalse(BoolIndexOption option) { return option == BoolIndexOption_True; } #endif documentdb-0.108-0/pg_documentdb/include/metadata/metadata_cache.h000066400000000000000000000413741507310017400251030ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/metadata/metadata_cache.h * * Common declarations for metadata caching functions. * *------------------------------------------------------------------------- */ #ifndef METADATA_CACHE_H #define METADATA_CACHE_H #include #include "utils/type_cache.h" extern PGDLLIMPORT char *ApiDataSchemaName; extern PGDLLIMPORT char *ApiSchemaName; extern PGDLLIMPORT char *ApiSchemaNameV2; extern PGDLLIMPORT char *ApiInternalSchemaName; extern PGDLLIMPORT char *ApiInternalSchemaNameV2; extern PGDLLIMPORT char *ExtensionObjectPrefix; extern PGDLLIMPORT char *ExtensionObjectPrefixV2; extern PGDLLIMPORT char *CoreSchemaName; extern PGDLLIMPORT char *CoreSchemaNameV2; extern PGDLLIMPORT char *FullBsonTypeName; extern PGDLLIMPORT char *ApiCatalogSchemaName; extern PGDLLIMPORT char *ApiCatalogSchemaNameV2; extern PGDLLIMPORT char *ApiToApiInternalSchemaName; extern PGDLLIMPORT char *ApiCatalogToApiInternalSchemaName; extern PGDLLIMPORT char *PostgisSchemaName; extern PGDLLIMPORT char *DocumentDBApiInternalSchemaName; extern PGDLLIMPORT char *ApiCatalogToCoreSchemaName; /* Roles */ extern PGDLLIMPORT char *ApiAdminRole; extern PGDLLIMPORT char *ApiAdminRoleV2; extern PGDLLIMPORT char *ApiBgWorkerRole; extern PGDLLIMPORT char *ApiReadOnlyRole; extern PGDLLEXPORT char *ApiReadWriteRole; extern PGDLLEXPORT char *ApiRootInternalRole; extern PGDLLIMPORT char *ApiRootRole; extern PGDLLEXPORT char *ApiUserAdminRole; extern MemoryContext DocumentDBApiMetadataCacheContext; /* functions related with pg_documentdb "extension" itself */ void InitializeDocumentDBApiExtensionCache(void); void InvalidateCollectionsCache(void); bool IsDocumentDBApiExtensionActive(void); Oid DocumentDBApiExtensionOwner(void); char * GetExtensionApplicationName(void); /* functions and procedures */ Oid ApiCollectionFunctionId(void); Oid DocumentDBApiCollectionFunctionId(void); Oid ApiCreateIndexesProcedureId(void); Oid ApiReIndexProcedureId(void); Oid BsonEqualMatchRuntimeFunctionId(void); Oid BsonEqualMatchRuntimeOperatorId(void); Oid BsonEqualMatchIndexFunctionId(void); Oid BsonGreaterThanMatchRuntimeFunctionId(void); Oid BsonGreaterThanMatchRuntimeOperatorId(void); Oid BsonGreaterThanMatchIndexFunctionId(void); Oid BsonGreaterThanEqualMatchRuntimeFunctionId(void); Oid BsonGreaterThanEqualMatchRuntimeOperatorId(void); Oid BsonGreaterThanEqualMatchIndexFunctionId(void); Oid BsonLessThanMatchRuntimeFunctionId(void); Oid BsonLessThanMatchRuntimeOperatorId(void); Oid BsonLessThanMatchIndexFunctionId(void); Oid BsonLessThanEqualMatchRuntimeFunctionId(void); Oid BsonLessThanEqualMatchRuntimeOperatorId(void); Oid BsonLessThanEqualMatchIndexFunctionId(void); Oid BsonRangeMatchFunctionId(void); Oid BsonRangeMatchOperatorOid(void); Oid BsonFullScanFunctionOid(void); Oid BsonIndexHintFunctionOid(void); Oid BsonInMatchFunctionId(void); Oid BsonNinMatchFunctionId(void); Oid BsonNotEqualMatchFunctionId(void); Oid BsonElemMatchMatchFunctionId(void); Oid BsonAllMatchFunctionId(void); Oid BsonBitsAllClearFunctionId(void); Oid BsonBitsAnyClearFunctionId(void); Oid BsonBitsAllSetFunctionId(void); Oid BsonBitsAnySetFunctionId(void); Oid BsonRegexMatchFunctionId(void); Oid BsonModMatchFunctionId(void); Oid BsonSizeMatchFunctionId(void); Oid BsonTypeMatchFunctionId(void); Oid BsonExistsMatchFunctionId(void); Oid BsonExprFunctionId(void); Oid BsonExprWithLetFunctionId(void); Oid BsonJsonSchemaFunctionId(void); Oid BsonTextFunctionId(void); Oid BsonEmptyDataTableFunctionId(void); Oid IndexSpecAsBsonFunctionId(void); Oid IndexBuildIsInProgressFunctionId(void); Oid ApiCursorStateFunctionId(void); Oid ApiCurrentCursorStateFunctionId(void); Oid ExtensionTableSampleSystemRowsFunctionId(void); Oid BsonInRangeNumericFunctionId(void); Oid BsonInRangeIntervalFunctionId(void); Oid BsonQueryMatchWithLetAndCollationFunctionId(void); /* bson_value functions */ Oid BsonValueEqualMatchFunctionId(void); Oid BsonValueGreaterThanMatchFunctionId(void); Oid BsonValueGreaterThanEqualMatchFunctionId(void); Oid BsonValueLessThanMatchFunctionId(void); Oid BsonValueLessThanEqualMatchFunctionId(void); Oid BsonValueSizeMatchFunctionId(void); Oid BsonValueTypeMatchFunctionId(void); Oid BsonValueInMatchFunctionId(void); Oid BsonValueNinMatchFunctionId(void); Oid BsonValueNotEqualMatchFunctionId(void); Oid BsonValueExistsMatchFunctionId(void); Oid BsonValueElemMatchMatchFunctionId(void); Oid BsonValueAllMatchFunctionId(void); Oid BsonValueRegexMatchFunctionId(void); Oid BsonValueModMatchFunctionId(void); Oid BsonValueBitsAllClearFunctionId(void); Oid BsonValueBitsAnyClearFunctionId(void); Oid BsonValueBitsAllSetFunctionId(void); Oid BsonValueBitsAnySetFunctionId(void); Oid BsonNotLessThanEqualFunctionId(void); Oid BsonNotLessThanFunctionId(void); Oid BsonNotGreaterThanFunctionId(void); Oid BsonNotGreaterThanEqualFunctionId(void); Oid BsonIndexBoundsEqualOperatorId(void); Oid BsonIndexBoundsEqualOperatorFuncId(void); /* operators */ Oid BigintEqualOperatorId(void); Oid BigIntGreaterOperatorId(void); Oid TextEqualOperatorId(void); Oid TextNotEqualOperatorId(void); Oid TextLessOperatorId(void); Oid BsonEqualOperatorId(void); Oid BsonEqualMatchOperatorId(void); Oid BsonInOperatorId(void); Oid BsonQueryOperatorId(void); Oid BsonTrueFunctionId(void); Oid BsonQueryMatchFunctionId(void); Oid BsonIndexSpecSelectionFunctionId(void); Oid BsonIndexSpecEqualOperatorId(void); Oid BsonGreaterThanOperatorId(void); Oid BsonLessThanOperatorId(void); Oid BsonGreaterThanEqualOperatorId(void); Oid BsonLessThanEqualOperatorId(void); Oid BsonGetValueFunctionOid(void); Oid PostgresInt4PlusFunctionOid(void); Oid PostgresInt4LessOperatorOid(void); Oid PostgresInt4LessOperatorFunctionOid(void); Oid PostgresInt4EqualOperatorOid(void); /* Opclass */ Oid IntegerOpsOpFamilyOid(void); Oid BsonBtreeOpFamilyOid(void); Oid BsonRumCompositeIndexOperatorFamily(void); /* types */ Oid BsonQueryTypeId(void); Oid VectorTypeId(void); Oid HalfVectorTypeId(void); Oid IndexSpecTypeId(void); Oid ApiCatalogCollectionsTypeOid(void); Oid GetClusterBsonQueryTypeId(void); Oid GetBsonArrayTypeOid(void); Oid BsonIndexBoundsTypeId(void); Oid GetBsonIndexBoundsArrayTypeOid(void); /* sequences */ Oid ApiCatalogCollectionIdSequenceId(void); Oid ApiCatalogCollectionIndexIdSequenceId(void); /* order by */ Oid BsonOrderByFunctionOid(void); Oid BsonOrderByWithCollationFunctionOid(void); Oid BsonOrderByPartitionFunctionOid(void); Oid BsonOrderByPartitionWithCollationFunctionOid(void); Oid BsonOrderByCompareFunctionOId(void); Oid BsonOrderByLtFunctionOId(void); Oid BsonOrderByEqFunctionOId(void); Oid BsonOrderByGtFunctionOId(void); Oid BsonOrderyByLtOperatorId(void); Oid BsonOrderyByEqOperatorId(void); Oid BsonOrderyByGtOperatorId(void); Oid BsonOrderByIndexOperatorId(void); Oid BsonOrderByReverseIndexOperatorId(void); /* Postgres internal functions */ Oid PostgresDrandomFunctionId(void); Oid PostgresToTimestamptzFunctionId(void); Oid PostgresDatePartFunctionId(void); Oid PostgresTimestampToZoneFunctionId(void); Oid PostgresAddIntervalToTimestampFunctionId(void); Oid PostgresAddIntervalToDateFunctionId(void); Oid PostgresTimestampToZoneWithoutTzFunctionId(void); Oid PostgresToDateFunctionId(void); Oid Float8EqualOperatorId(void); Oid Float8LessThanEqualOperatorId(void); Oid Float8GreaterThanEqualOperatorId(void); Oid PostgresArrayAppendFunctionOid(void); Oid PostgresMakeIntervalFunctionId(void); Oid PostgresDateBinFunctionId(void); Oid PostgresAgeBetweenTimestamp(void); Oid PostgresDatePartFromInterval(void); /* Index AM */ Oid RumIndexAmId(void); Oid PgVectorIvfFlatIndexAmId(void); Oid PgVectorHNSWIndexAmId(void); /* IndexAM Support functions */ Oid BsonExclusionPreConsistentFunctionId(void); /* Operator Class*/ Oid VectorIVFFlatCosineSimilarityOperatorFamilyId(void); Oid VectorIVFFlatIPSimilarityOperatorFamilyId(void); Oid VectorIVFFlatL2SimilarityOperatorFamilyId(void); Oid VectorHNSWCosineSimilarityOperatorFamilyId(void); Oid VectorHNSWIPSimilarityOperatorFamilyId(void); Oid VectorHNSWL2SimilarityOperatorFamilyId(void); Oid BsonRumTextPathOperatorFamily(void); Oid BsonGistGeographyOperatorFamily(void); Oid BsonGistGeometryOperatorFamily(void); Oid BsonRumSinglePathOperatorFamily(void); Oid Float8PlusOperatorId(void); Oid Float8MinusOperatorId(void); Oid Float8MultiplyOperatorId(void); Oid BsonRumHashPathOperatorFamily(void); Oid BsonRumUniquePathOperatorFamily(void); /* Vector Functions */ Oid PgDoubleToVectorFunctionOid(void); Oid PgDoubleToSparseVecFunctionOid(bool missingOK); Oid VectorAsVectorFunctionOid(void); Oid VectorAsHalfVecFunctionOid(bool missingOK); Oid ApiCatalogBsonExtractVectorFunctionId(void); Oid ApiBsonSearchParamFunctionId(void); Oid ApiBsonDocumentAddScoreFieldFunctionId(void); /* Vector Operators */ Oid VectorOrderByQueryOperatorId(void); Oid VectorCosineSimilarityOperatorId(void); Oid VectorL2SimilarityOperatorId(void); Oid VectorIPSimilarityOperatorId(void); Oid VectorCosineSimilarityFunctionId(void); Oid VectorL2SimilarityFunctionId(void); Oid VectorIPSimilarityFunctionId(void); /* Half Vector Operators */ Oid VectorHalfCosineSimilarityOperatorId(void); Oid VectorHalfL2SimilarityOperatorId(void); Oid VectorHalfIPSimilarityOperatorId(void); Oid VectorHalfCosineSimilarityFunctionId(void); Oid VectorHalfL2SimilarityFunctionId(void); Oid VectorHalfIPSimilarityFunctionId(void); /* Geospatial data/type/support functions */ Oid Box2dfTypeId(void); Oid GeometryTypeId(void); Oid GeographyTypeId(void); Oid GIDXTypeId(void); Oid GeometryArrayTypeId(void); Oid BsonGeonearDistanceOperatorId(void); Oid BsonGeonearDistanceRangeOperatorId(void); Oid BsonDollarGeoIntersectsFunctionOid(void); Oid BsonDollarGeowithinFunctionOid(void); Oid BsonValidateGeometryFunctionId(void); Oid BsonValidateGeographyFunctionId(void); Oid BsonGistGeographyDistanceFunctionOid(void); Oid BsonGistGeographyConsistentFunctionOid(void); Oid PostgisGeometryBufferFunctionId(void); Oid PostgisGeographyBufferFunctionId(void); Oid PostgisGeometryAreaFunctionId(void); Oid PostgisGeometryFromEWKBFunctionId(void); Oid PostgisGeometryAsGeography(void); Oid PostgisGeometryIsValidDetailFunctionId(void); Oid PostgisGeometryMakeValidFunctionId(void); Oid PostgisGeometryGistCompress2dFunctionId(void); Oid PostgisGeometryGistConsistent2dFunctionId(void); Oid PostgisGeographyFromWKBFunctionId(void); Oid PostgisForcePolygonCWFunctionId(void); Oid PostgisGeometryAsBinaryFunctionId(void); Oid PostgisGeographyGistCompressFunctionId(void); Oid PostgisGeographyGistConsistentFunctionId(void); Oid PostgisMakeEnvelopeFunctionId(void); Oid PostgisMakePointFunctionId(void); Oid PostgisMakePolygonFunctionId(void); Oid PostgisMakeLineFunctionId(void); Oid PostgisGeographyCoversFunctionId(void); Oid PostgisGeographyDWithinFunctionId(void); Oid PostgisGeometryDistanceCentroidFunctionId(void); Oid PostgisGeographyDistanceKNNFunctionId(void); Oid PostgisGeometryGistDistanceFunctionId(void); Oid PostgisGeographyGistDistanceFunctionId(void); Oid PostgisGeometryDWithinFunctionId(void); Oid PostgisBox2dfGeometryOverlapsFunctionId(void); Oid PostgisGIDXGeographyOverlapsFunctionId(void); Oid PostgisGeometryCoversFunctionId(void); Oid PostgisGeographyIntersectsFunctionId(void); Oid PostgisGeometryIntersectsFunctionId(void); Oid PostgisSetSRIDFunctionId(void); Oid PostgisGeometryExpandFunctionId(void); Oid PostgisGeographyExpandFunctionId(void); /* Text search functions */ Oid WebSearchToTsQueryFunctionId(void); Oid WebSearchToTsQueryWithRegConfigFunctionId(void); Oid BsonTextSearchMetaQualFuncId(void); Oid TsRankFunctionId(void); Oid TsVectorConcatFunctionId(void); Oid TsMatchFunctionOid(void); /* Aggregation functions */ Oid ApiCatalogAggregationPipelineFunctionId(void); Oid ApiCatalogAggregationFindFunctionId(void); Oid ApiCatalogAggregationCountFunctionId(void); Oid ApiCatalogAggregationDistinctFunctionId(void); Oid BsonCovariancePopAggregateFunctionOid(void); Oid BsonCovarianceSampAggregateFunctionOid(void); Oid BsonDollarAddFieldsFunctionOid(void); Oid BsonDollarAddFieldsWithLetFunctionOid(void); Oid BsonDollarAddFieldsWithLetAndCollationFunctionOid(void); Oid BsonDollarMergeDocumentAtPathFunctionOid(void); Oid BsonDollaMergeDocumentsFunctionOid(void); Oid BsonDollarProjectGeonearFunctionOid(void); Oid BsonDollarInverseMatchFunctionId(void); Oid BsonDollarProjectFunctionOid(void); Oid BsonDollarProjectWithLetFunctionOid(void); Oid BsonDollarProjectWithLetAndCollationFunctionOid(void); Oid BsonDollarRedactWithLetFunctionOid(void); Oid BsonDollarRedactWithLetAndCollationFunctionOid(void); Oid BsonDollarMergeHandleWhenMatchedFunctionOid(void); Oid BsonDollarMergeAddObjectIdFunctionOid(void); Oid BsonDollarMergeGenerateObjectId(void); Oid BsonDollarMergeFailWhenNotMatchedFunctionOid(void); Oid BsonDollarMergeExtractFilterFunctionOid(void); Oid BsonDollarMergeJoinFunctionOid(void); Oid BsonDollarProjectFindFunctionOid(void); Oid BsonDollarProjectFindWithLetFunctionOid(void); Oid BsonDollarProjectFindWithLetAndCollationFunctionOid(void); Oid BsonDollarUnwindFunctionOid(void); Oid BsonDollarUnwindWithOptionsFunctionOid(void); Oid BsonDollarReplaceRootFunctionOid(void); Oid BsonDollarReplaceRootWithLetFunctionOid(void); Oid BsonDollarReplaceRootWithLetAndCollationFunctionOid(void); Oid BsonSumAggregateFunctionOid(void); Oid BsonIntegralAggregateFunctionOid(void); Oid BsonDerivativeAggregateFunctionOid(void); Oid BsonAvgAggregateFunctionOid(void); Oid BsonRepathAndBuildFunctionOid(void); Oid BsonExpressionGetFunctionOid(void); Oid BsonExpressionGetWithLetFunctionOid(void); Oid BsonExpressionGetWithLetAndCollationFunctionOid(void); Oid BsonExpressionPartitionGetFunctionOid(void); Oid BsonExpressionPartitionByFieldsGetFunctionOid(void); Oid BsonExpressionPartitionGetWithLetFunctionOid(void); Oid BsonExpressionPartitionGetWithLetAndCollationFunctionOid(void); Oid BsonExpressionMapFunctionOid(void); Oid BsonExpressionMapWithLetFunctionOid(void); Oid BsonExpressionAppendCollationFunctionOid(void); Oid BsonMaxAggregateFunctionOid(void); Oid BsonMinAggregateFunctionOid(void); Oid PgRandomFunctionOid(void); Oid BsonArrayAggregateFunctionOid(void); Oid BsonArrayAggregateAllArgsFunctionOid(void); Oid BsonExpMovingAvgAggregateFunctionOid(void); Oid BsonObjectAggregateFunctionOid(void); Oid BsonMergeObjectsOnSortedFunctionOid(void); Oid BsonMergeObjectsFunctionOid(void); Oid BsonDollarFacetProjectFunctionOid(void); Oid BsonFirstOnSortedAggregateFunctionOid(void); Oid BsonFirstOnSortedAggregateAllArgsFunctionOid(void); Oid BsonLastOnSortedAggregateFunctionOid(void); Oid BsonLastOnSortedAggregateAllArgsFunctionOid(void); Oid BsonFirstAggregateFunctionOid(void); Oid BsonFirstAggregateAllArgsFunctionOid(void); Oid BsonLastAggregateFunctionOid(void); Oid BsonLastAggregateAllArgsFunctionOid(void); Oid BsonFirstNAggregateFunctionOid(void); Oid BsonFirstNAggregateAllArgsFunctionOid(void); Oid BsonFirstNOnSortedAggregateFunctionOid(void); Oid BsonFirstNOnSortedAggregateAllArgsFunctionOid(void); Oid BsonLastNAggregateFunctionOid(void); Oid BsonLastNAggregateAllArgsFunctionOid(void); Oid BsonLastNOnSortedAggregateFunctionOid(void); Oid BsonLastNOnSortedAggregateAllArgsFunctionOid(void); Oid BsonAddToSetAggregateFunctionOid(void); Oid BsonStdDevPopAggregateFunctionOid(void); Oid BsonStdDevSampAggregateFunctionOid(void); Oid PostgresAnyValueFunctionOid(void); Oid BsonLookupExtractFilterExpressionFunctionOid(void); Oid BsonDollarLookupExpressionEvalMergeOid(void); Oid DocumentDBApiInternalBsonLookupExtractFilterExpressionFunctionOid(void); Oid BsonDollarLookupJoinFilterFunctionOid(void); Oid BsonLookupExtractFilterArrayFunctionOid(void); Oid BsonLookupUnwindFunctionOid(void); Oid BsonDistinctUnwindFunctionOid(void); Oid BsonDollarBucketAutoFunctionOid(void); Oid BsonDistinctAggregateFunctionOid(void); Oid RowGetBsonFunctionOid(void); Oid ApiChangeStreamAggregationFunctionOid(void); Oid ApiCollStatsAggregationFunctionOid(void); Oid ApiIndexStatsAggregationFunctionOid(void); Oid BsonCurrentOpAggregationFunctionId(void); Oid BsonMaxNAggregateFunctionOid(void); Oid BsonMinNAggregateFunctionOid(void); Oid BsonMedianAggregateFunctionOid(void); Oid BsonPercentileAggregateFunctionOid(void); /* Window functions*/ Oid BsonLinearFillFunctionOid(void); Oid BsonLocfFillFunctionOid(void); Oid BsonConstFillFunctionOid(void); Oid BsonRankFunctionOid(void); Oid BsonDenseRankFunctionOid(void); Oid BsonShiftFunctionOid(void); Oid BsonDocumentNumberFunctionOid(void); /* Window functions */ Oid BsonDensifyRangeWindowFunctionOid(void); Oid BsonDensifyPartitionWindowFunctionOid(void); Oid BsonDensifyFullWindowFunctionOid(void); /* Catalog */ Oid ApiDataNamespaceOid(void); /* CRUD functions */ Oid UpdateWorkerFunctionOid(void); Oid InsertWorkerFunctionOid(void); Oid DeleteWorkerFunctionOid(void); Oid CommandNodeWorkerFunctionOid(void); /* Compat functions*/ Oid DocumentDBCoreBsonToBsonFunctionOId(void); /* Helper functions */ TypeName * ParseTypeNameCore(const char *typeName); #endif documentdb-0.108-0/pg_documentdb/include/metadata/metadata_guc.h000066400000000000000000000007731507310017400246140ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/metadata/index.h * * Accessors around ApiCatalogSchema.collection_indexes. * *------------------------------------------------------------------------- */ #ifndef METADATA_GUC_H #define METADATA_GUC_H #define NEXT_COLLECTION_ID_UNSET 0 extern int NextCollectionId; #define NEXT_COLLECTION_INDEX_ID_UNSET 0 extern int NextCollectionIndexId; #endif documentdb-0.108-0/pg_documentdb/include/metadata/relation_utils.h000066400000000000000000000007071507310017400252300ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/relation_utils.h * * Utilities that operate on relation-like objects. * *------------------------------------------------------------------------- */ #include #ifndef RELATION_UTILS_H #define RELATION_UTILS_H Datum SequenceGetNextValAsUser(Oid sequenceId, Oid userId); #endif documentdb-0.108-0/pg_documentdb/include/opclass/000077500000000000000000000000001507310017400217025ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_common.h000066400000000000000000000046111507310017400252230ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_common.h * * Common declarations of the bson gin methods. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_COMMON_H #define BSON_GIN_COMMON_H /* * Maps the set of operators for the gin index as strategies that are used in * gin operator functions. */ typedef enum BsonIndexStrategy { BSON_INDEX_STRATEGY_INVALID = 0, BSON_INDEX_STRATEGY_DOLLAR_EQUAL = 1, BSON_INDEX_STRATEGY_DOLLAR_GREATER = 2, BSON_INDEX_STRATEGY_DOLLAR_GREATER_EQUAL = 3, BSON_INDEX_STRATEGY_DOLLAR_LESS = 4, BSON_INDEX_STRATEGY_DOLLAR_LESS_EQUAL = 5, BSON_INDEX_STRATEGY_DOLLAR_IN = 6, BSON_INDEX_STRATEGY_DOLLAR_NOT_EQUAL = 7, BSON_INDEX_STRATEGY_DOLLAR_NOT_IN = 8, BSON_INDEX_STRATEGY_DOLLAR_REGEX = 9, BSON_INDEX_STRATEGY_DOLLAR_EXISTS = 10, BSON_INDEX_STRATEGY_DOLLAR_SIZE = 11, BSON_INDEX_STRATEGY_DOLLAR_TYPE = 12, BSON_INDEX_STRATEGY_DOLLAR_ALL = 13, BSON_INDEX_STRATEGY_UNIQUE_EQUAL = 14, BSON_INDEX_STRATEGY_DOLLAR_BITS_ALL_CLEAR = 15, BSON_INDEX_STRATEGY_DOLLAR_BITS_ANY_CLEAR = 16, BSON_INDEX_STRATEGY_DOLLAR_ELEMMATCH = 17, BSON_INDEX_STRATEGY_DOLLAR_BITS_ALL_SET = 18, BSON_INDEX_STRATEGY_DOLLAR_BITS_ANY_SET = 19, BSON_INDEX_STRATEGY_DOLLAR_MOD = 20, BSON_INDEX_STRATEGY_DOLLAR_ORDERBY = 21, BSON_INDEX_STRATEGY_DOLLAR_TEXT = 22, BSON_INDEX_STRATEGY_DOLLAR_GEOWITHIN = 23, BSON_INDEX_STRATEGY_DOLLAR_GEOINTERSECTS = 24, BSON_INDEX_STRATEGY_DOLLAR_RANGE = 25, BSON_INDEX_STRATEGY_DOLLAR_NOT_GT = 26, BSON_INDEX_STRATEGY_DOLLAR_NOT_GTE = 27, BSON_INDEX_STRATEGY_DOLLAR_NOT_LT = 28, BSON_INDEX_STRATEGY_DOLLAR_NOT_LTE = 29, BSON_INDEX_STRATEGY_GEONEAR = 30, BSON_INDEX_STRATEGY_GEONEAR_RANGE = 31, BSON_INDEX_STRATEGY_COMPOSITE_QUERY = 32, BSON_INDEX_STRATEGY_IS_MULTIKEY = 33, BSON_INDEX_STRATEGY_DOLLAR_ORDERBY_REVERSE = 34, BSON_INDEX_STRATEGY_HAS_TRUNCATED_TERMS = 35, } BsonIndexStrategy; inline static bool IsNegationStrategy(BsonIndexStrategy strategy) { return (strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_EQUAL || strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_IN || strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_GT || strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_GTE || strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_LT || strategy == BSON_INDEX_STRATEGY_DOLLAR_NOT_LTE); } #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_composite_private.h000066400000000000000000000066261507310017400274770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_index_mgmt.h * * Common declarations of the bson index management methods. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_COMPOSITE_PRIVATE_H #define BSON_GIN_COMPOSITE_PRIVATE_H #include "io/bson_core.h" typedef struct CompositeSingleBound { bson_value_t bound; bool isBoundInclusive; /* The processed bound (post truncation if any) */ bytea *serializedTerm; BsonIndexTerm indexTermValue; } CompositeSingleBound; typedef struct IndexRecheckArgs { Pointer queryDatum; BsonIndexStrategy queryStrategy; } IndexRecheckArgs; typedef struct CompositeIndexBounds { CompositeSingleBound lowerBound; CompositeSingleBound upperBound; bool isEqualityBound; bool requiresRuntimeRecheck; /* A list of IndexRecheckArgs that need recheck */ List *indexRecheckFunctions; } CompositeIndexBounds; typedef struct PathScanKeyMap { /* integer list of term indexes - one for each scanKey */ List *scanIndices; } PathScanKeyMap; typedef struct PathScanTermMap { /* Integer list of key indexes - one for each index path */ List *scanKeyIndexList; int32_t numTermsPerPath; } PathScanTermMap; typedef struct CompositeQueryMetaInfo { int32_t numIndexPaths; bool hasTruncation; int32_t truncationTermIndex; bool requiresRuntimeRecheck; int32_t numScanKeys; bool hasMultipleScanKeysPerPath; bool isBackwardScan; PathScanKeyMap *scanKeyMap; } CompositeQueryMetaInfo; typedef struct CompositeQueryRunData { CompositeQueryMetaInfo *metaInfo; CompositeIndexBounds indexBounds[FLEXIBLE_ARRAY_MEMBER]; } CompositeQueryRunData; typedef struct CompositeIndexBoundsSet { /* The index path attribute (0 based) */ int32_t indexAttribute; int32_t numBounds; CompositeIndexBounds bounds[FLEXIBLE_ARRAY_MEMBER]; } CompositeIndexBoundsSet; typedef struct VariableIndexBounds { /* List of CompositeIndexBoundsSet */ List *variableBoundsList; } VariableIndexBounds; static inline CompositeIndexBoundsSet * CreateCompositeIndexBoundsSet(int32_t numTerms, int32_t indexAttribute) { CompositeIndexBoundsSet *set = palloc0(sizeof(CompositeIndexBoundsSet) + (sizeof(CompositeIndexBounds) * numTerms)); set->numBounds = numTerms; set->indexAttribute = indexAttribute; return set; } bool IsValidRecheckForIndexValue(const BsonIndexTerm *compareTerm, IndexRecheckArgs *recheckArgs); bytea * BuildLowerBoundTermFromIndexBounds(CompositeQueryRunData *runData, IndexTermCreateMetadata *metadata, bool *hasInequalityMatch, int8_t *sortOrders); bool UpdateBoundsForTruncation(CompositeIndexBounds *queryBounds, int32_t numPaths, IndexTermCreateMetadata *metadata, int8_t *sortOrders); void ParseOperatorStrategy(const char **indexPaths, int32_t numPaths, pgbsonelement *queryElement, BsonIndexStrategy queryStrategy, VariableIndexBounds *indexBounds); void UpdateRunDataForVariableBounds(CompositeQueryRunData *runData, PathScanTermMap *termMap, VariableIndexBounds *variableBounds, int32_t permutation); List * MergeSingleVariableBounds(List *variableBounds, CompositeIndexBounds *mergedBounds); void PickVariableBoundsForOrderedScan(VariableIndexBounds *variableBounds, CompositeQueryRunData *runData); #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_composite_scan.h000066400000000000000000000021121507310017400267330ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_index_mgmt.h * * Common declarations of the bson index management methods. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_COMPOSITE_SCAN_H #define BSON_GIN_COMPOSITE_SCAN_H #include struct IndexPath; bool GetEqualityRangePredicatesForIndexPath(struct IndexPath *indexPath, void *options, bool equalityPrefixes[INDEX_MAX_KEYS], bool nonEqualityPrefixes[INDEX_MAX_KEYS]); bool CompositePathHasFirstColumnSpecified(IndexPath *indexPath); char *SerializeBoundsStringForExplain(bytea * entry, void *extraData, PG_FUNCTION_ARGS); bool ModifyScanKeysForCompositeScan(ScanKey scankey, int nscankeys, ScanKey targetScanKey, bool hasArrayKeys, bool hasOrderBys, ScanDirection scanDirection); ScanDirection DetermineCompositeScanDirection(bytea *compositeScanOptions, ScanKey orderbys, int norderbys); #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_index_mgmt.h000066400000000000000000000151101507310017400260620ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_index_mgmt.h * * Common declarations of the bson index management methods. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_INDEX_MGMT_H #define BSON_GIN_INDEX_MGMT_H #include "opclass/bson_gin_common.h" /* * Enum identifying the kind of index based on the options. */ typedef enum IndexOptionsType { /* This is an index of a single path - wildcard or not */ IndexOptionsType_SinglePath, /* This is a wildcard index with multiple path projections */ IndexOptionsType_Wildcard, /* This is a hash index on a single path */ IndexOptionsType_Hashed, /* This is the unique shard_key hash index */ IndexOptionsType_UniqueShardKey, /* This is a text index on a single path */ IndexOptionsType_Text, /* This is a 2d index on a single path */ IndexOptionsType_2d, /* This is a 2dsphere index on a path */ IndexOptionsType_2dsphere, /* This is a composite index on a path */ IndexOptionsType_Composite, } IndexOptionsType; /* * Versioning for indexes when making breaking changes to index layout/terms. */ typedef enum IndexOptionsVersion { /* The default value (version that got started with) */ IndexOptionsVersion_V0 = 0, /* Version that includes term path prefix elision for single path indexes & index term truncation */ IndexOptionsVersion_V1 = 1, } IndexOptionsVersion; /* * Base struct for all options used in the GIN index. * Note - all option classes must have the same layout. */ typedef struct { int32 vl_len_; /* varlena header (do not touch directly!) */ IndexOptionsType type; /* This must be the first field */ IndexOptionsVersion version; int intOption_deprecated; /* This is a deprecated field for int type fields */ int32_t indexTermTruncateLimit; /* this must be the next field in all index options */ uint32_t wildcardIndexTruncatedPathLimit; } BsonGinIndexOptionsBase; /* * This is the serialized post-processed structure that holds the indexing options * for single path indexes (both wildcard and non-wildcard) * This handles indexes of the form { "$**": 1 }, { "a.b.$**" : 1 } * { "a.b" : 1 }, { "a": 1 } etc. */ typedef struct { BsonGinIndexOptionsBase base; bool isWildcard; bool generateNotFoundTerm; bool useReducedWildcardTerms; int path; } BsonGinSinglePathOptions; /* * This is the serialized post-processed structure that holds the indexing options * for wildcard projection path indexes * This handles indexes of the form * { "$**": 1, { "wildcardProjection": { "a.b": 1, "d": 1 } } } * { "$**": 1, { "wildcardProjection": { "a.b": 0, "_id": 1 } } } * Holds information on whether it's an inclusion/exclusion index and the set of paths * to be considered for indexing. */ typedef struct { BsonGinIndexOptionsBase base; bool isExclusion; bool includeId; int pathSpec; } BsonGinWildcardProjectionPathOptions; /* * This is the serialized post-processed structure that holds the indexing options * for hashed indexes * This handles indexes of the form { "a": "hashed" }, { "a.b" : "hashed" } */ typedef struct { BsonGinIndexOptionsBase base; int path; } BsonGinHashOptions; /* * This is the serialized post-processed structure that holds the indexing options * for single path exclusion hash indexes. */ typedef struct { BsonGinIndexOptionsBase base; int path; } BsonGinExclusionHashOptions; /* * This is the serialized post-processed structure that holds the indexing options * for single path text indexes (both wildcard and non-wildcard) * This handles indexes of the form { "$**": "text" }, * { "a.b" : "text" }, { "a": "text" } etc. */ typedef struct { BsonGinIndexOptionsBase base; bool isWildcard; int defaultLanguage; int weights; int languageOverride; } BsonGinTextPathOptions; /* * This is the serialized post-processed structure that holds the indexing options * for single path 2d indexes. * * This handles indexes of the form { "a": "2d" }, { "a.b" : "2d" } */ typedef struct { BsonGinIndexOptionsBase base; int path; double maxBound; double minBound; } Bson2dGeometryPathOptions; /* * This is the serialized post-processed structure that holds the indexing options * for single path 2dsphere indexes. */ typedef struct { BsonGinIndexOptionsBase base; int path; } Bson2dGeographyPathOptions; typedef struct { BsonGinIndexOptionsBase base; int compositePathSpec; } BsonGinCompositePathOptions; bool ValidateIndexForQualifierValue(bytea *indexOptions, Datum queryValue, BsonIndexStrategy strategy); bool ValidateIndexForQualifierPathForDollarIn(bytea *indexOptions, const StringView *queryPath); Size FillSinglePathSpec(const char *prefix, void *buffer); void ValidateSinglePathSpec(const char *prefix); Size FillDeprecatedStringSpec(const char *value, void *ptr); struct PathKey; struct Expr; typedef struct SortIndexInputDetails { const char *sortPath; struct Expr *sortVar; struct Expr *sortDatum; struct PathKey *sortPathKey; } SortIndexInputDetails; struct IndexPath; bool CompositeIndexSupportsOrderByPushdown(struct IndexPath *indexPath, List *sortDetails, int32_t *maxPathKeySupported, bool *isReverseOrder, bool isGroupBy); bool CompositeIndexSupportsIndexOnlyScan(const struct IndexPath *indexPath); int32_t GetCompositeOpClassColumnNumber(const char *currentPath, void *contextOptions, int8_t *sortDirection); int32_t GetCompositeOpClassPathCount(void *contextOptions); const char * GetCompositeFirstIndexPath(void *contextOptions); const char * GetFirstPathFromIndexOptionsIfApplicable(bytea *indexOptions, bool *isWildcardIndex); bool PathHasArrayIndexElements(const StringView *path); struct PlannerInfo; bool TraverseIndexPathForCompositeIndex(struct IndexPath *indexPath, struct PlannerInfo *root); /* Helper macro to retrieve a length prefixed value in the index options */ #define Get_Index_Path_Option(options, field, result, resultFieldLength) \ const char *pathDefinition = GET_STRING_RELOPTION(options, field); \ if (pathDefinition == NULL) { resultFieldLength = 0; result = NULL; } \ else { resultFieldLength = *(uint32_t *) pathDefinition; result = pathDefinition + \ sizeof(uint32_t); } #define Get_Index_Path_Option_Length(options, field, resultFieldLength) \ const char *pathDefinition = GET_STRING_RELOPTION(options, field); \ if (pathDefinition == NULL) { resultFieldLength = 0; } \ else { resultFieldLength = *(uint32_t *) pathDefinition; } #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_index_term.h000066400000000000000000000110421507310017400260650ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_index_term.h * * Common declarations of the serialization of index terms. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_INDEX_TERM_H #define BSON_GIN_INDEX_TERM_H #include "utils/string_view.h" #include "io/bson_core.h" #include "opclass/bson_gin_index_mgmt.h" /* Struct used in manipulating bson index terms */ typedef struct BsonIndexTerm { /* Whether or not it's a metadata term */ bool isIndexTermMetadata; /* The metadata for the term */ uint8_t termMetadata; /* The index term element */ pgbsonelement element; } BsonIndexTerm; /* Struct for a serialized index term */ typedef struct BsonIndexTermSerialized { /* Whether or not the term is truncated */ bool isIndexTermTruncated; /* Whether or not it's a root metadata term (exists/not exists) */ bool isRootMetadataTerm; /* The serialized index term value */ bytea *indexTermVal; } BsonIndexTermSerialized; /* Struct for a serialized index term */ typedef struct BsonCompressableIndexTermSerialized { /* Whether or not the term is truncated */ bool isIndexTermTruncated; /* Whether or not it's a root metadata term (exists/not exists) */ bool isRootMetadataTerm; /* The serialized index term value */ Datum indexTermDatum; } BsonCompressableIndexTermSerialized; /* * Index term metadata used in creating index terms. */ typedef struct IndexTermCreateMetadata { /* Index term size limit for the term. */ int32_t indexTermSizeLimit; /* The key size limit for wildcard indexes with truncation enabled. */ uint32_t wildcardIndexTruncatedPathLimit; /* The path prefix to truncate from the index term path. */ StringView pathPrefix; /* If the term belongs to a wildcard index. */ bool isWildcard; /* If the term belongs to a wildcard projection index. */ bool isWildcardProjection; /* Version of the index */ IndexOptionsVersion indexVersion; /* Whether or not the term is for a descending index */ bool isDescending; } IndexTermCreateMetadata; bool IsIndexTermTruncated(const BsonIndexTerm *indexTerm); /* Special case of an undefined value in an array that * has a defined value. */ bool IsIndexTermMaybeUndefined(const BsonIndexTerm *indexTerm); /* Whether or not an undefined term is due to the * value being undefined (as opposed to the listeral * undefined). */ bool IsIndexTermValueUndefined(const BsonIndexTerm *indexTerm); /* * Whether or not the index term is compared in a descending manner. */ bool IsIndexTermValueDescending(const BsonIndexTerm *indexTerm); bool IsSerializedIndexTermComposite(bytea *indexTermSerialized); bool IsSerializedIndexTermTruncated(bytea *indexTermSerialized); bool IsSerializedIndexTermMetadata(bytea *indexTermSerialized); void InitializeBsonIndexTerm(bytea *indexTermSerialized, BsonIndexTerm *indexTerm); int32_t InitializeCompositeIndexTerm(bytea *indexTermSerialized, BsonIndexTerm indexTerm[INDEX_MAX_KEYS]); int32_t InitializeSerializedCompositeIndexTerm(bytea *indexTermSerialized, bytea *termValues[INDEX_MAX_KEYS]); BsonIndexTermSerialized SerializeBsonIndexTerm(pgbsonelement *indexElement, const IndexTermCreateMetadata * indexMetadata); BsonCompressableIndexTermSerialized SerializeBsonIndexTermWithCompression( pgbsonelement *indexElement, const IndexTermCreateMetadata *indexMetadata); BsonIndexTermSerialized SerializeCompositeBsonIndexTerm(bytea **individualTerms, int32_t numTerms); BsonCompressableIndexTermSerialized SerializeCompositeBsonIndexTermWithCompression( bytea **individualTerms, int32_t numTerms); Datum GenerateRootTerm(const IndexTermCreateMetadata *); Datum GenerateRootExistsTerm(const IndexTermCreateMetadata *); Datum GenerateRootNonExistsTerm(const IndexTermCreateMetadata *); Datum GenerateRootTruncatedTerm(const IndexTermCreateMetadata *); Datum GenerateRootMultiKeyTerm(const IndexTermCreateMetadata *); Datum GenerateValueUndefinedTerm(const IndexTermCreateMetadata *termData); Datum GenerateValueMaybeUndefinedTerm(const IndexTermCreateMetadata *termData); int32_t CompareBsonIndexTerm(const BsonIndexTerm *left, const BsonIndexTerm *right, bool *isComparisonValid); /* Check if the term is a root truncation term */ inline static bool IsRootTruncationTerm(BsonIndexTerm *term) { return IsIndexTermTruncated(term) && term->element.pathLength == 0 && term->element.bsonValue.value_type == BSON_TYPE_MAXKEY; } #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_index_types_core.h000066400000000000000000000011471507310017400272770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_index_types_core.h * * Common declarations of the serialization of index terms. * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_INDEX_TYPES_CORE_H #define BSON_GIN_INDEX_TYPES_CORE_H bson_value_t GetUpperBound(bson_type_t type, bool *isUpperBoundInclusive); bson_value_t GetLowerBound(bson_type_t type); bson_type_t GetBsonTypeNameFromStringForDollarType(const char *typeNameStr); #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_gin_private.h000066400000000000000000000156031507310017400254100ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_gin_private.h * * Private declarations of the bson gin methods shared across files * that implement the GIN index extensibility * *------------------------------------------------------------------------- */ #ifndef BSON_GIN_PRIVATE_H #define BSON_GIN_PRIVATE_H #include "opclass/bson_gin_common.h" #include "planner/mongo_query_operator.h" #include "operators/bson_expr_eval.h" #include "opclass/bson_gin_index_term.h" #include "opclass/bson_gin_index_mgmt.h" /* * Arguments to Extract query used by mongo operators wrapped in a struct. */ typedef struct BsonExtractQueryArgs { pgbsonelement filterElement; const char *collationString; int32 *nentries; bool **partialmatch; Pointer **extra_data; bytea *options; IndexTermCreateMetadata termMetadata; } BsonExtractQueryArgs; /* * Holds state pertinent to index term evaluation for * Expression based $elemMatch. */ typedef struct BsonElemMatchIndexExprState { /* The query expression to be evaluated */ ExprEvalState *expression; /* Whether or not the query expression is empty */ bool isEmptyExpression; } BsonElemMatchIndexExprState; Datum * GinBsonExtractQueryCore(BsonIndexStrategy strategy, BsonExtractQueryArgs *args); int32_t GinBsonComparePartialCore(BsonIndexStrategy strategy, BsonIndexTerm *queryValue, BsonIndexTerm *compareValue, Pointer extraData); bool GinBsonConsistentCore(BsonIndexStrategy strategy, bool *check, Pointer *extra_data, int32_t numKeys, bool *recheck, Datum *queryKeys, bytea *options, bool isPreconsistent); int32_t GinBsonComparePartialElemMatchExpression(BsonIndexTerm *queryValue, BsonIndexTerm *compareValue, BsonElemMatchIndexExprState *exprState); /* $elemMatch methods */ Datum * GinBsonExtractQueryElemMatch(BsonExtractQueryArgs *args); int32_t GinBsonComparePartialElemMatch(BsonIndexTerm *queryValue, BsonIndexTerm *compareValue, Pointer extraData); bool GinBsonElemMatchConsistent(bool *checkArray, Pointer *extraData, int32_t numKeys); /* Shared with exclusion ops */ /* * Defines the behavior of index term traversal for a given path when walking a document */ typedef enum IndexTraverseOption { /* The path is invalid and no terms should be generated in that tree. */ IndexTraverse_Invalid, /* The path may have valid descendants that could generate terms on the index */ /* do not consider the path, but recurse down nested objects and arrays for terms */ IndexTraverse_Recurse, /* the path is a match and should be added to the index. */ IndexTraverse_Match, /* The path is a match and child paths are also matches */ IndexTraverse_MatchAndRecurse, } IndexTraverseOption; /* Index path options */ IndexTraverseOption GetSinglePathIndexTraverseOption(void *contextOptions, const char *currentPath, uint32_t currentPathLength, bson_type_t bsonType); IndexTraverseOption GetWildcardProjectionPathIndexTraverseOption(void *contextOptions, const char *currentPath, uint32_t currentPathLength, bson_type_t bsonType); IndexTraverseOption GetSinglePathIndexTraverseOptionCore(const char *indexPath, uint32_t indexPathLength, const char *currentPath, uint32_t currentPathLength, bool isWildcard); /* * Defines a function that provides instruction on how to handle a path 'currentPath' given an index option * specification via contextOptions. */ typedef IndexTraverseOption (*GetIndexTraverseOptionFunc)(void *contextOptions, const char *currentPath, uint32_t currentPathLength, bson_type_t valueType); /* * Context object used to keep track of state while generating terms for the index. */ typedef struct { /* After computation, this holds the total number of terms that should be generated by this document and index spec. */ int32_t totalTermCount; /* holds the actual index term datums. */ struct { /* The entry array of index terms.*/ Datum *entries; /* The size in Datum entries available in entries. */ int32_t entryCapacity; } terms; /* the current position into the entries that should be written into. */ int32_t index; /* Any index configuration options used to determine whether to generate terms or not */ void *options; /* A function that provides instruction on whether a path should be indexed or not. */ GetIndexTraverseOptionFunc traverseOptionsFunc; /* Whether or not to generate the not found term for a path */ bool generateNotFoundTerm; /* Whether or not to skip generating the path undefined term on null */ bool skipGeneratedPathUndefinedTermOnLiteralNull; /* metadata including truncation limit for index terms. */ IndexTermCreateMetadata termMetadata; /* Whether a root truncation term has already been created for this document */ bool hasTruncatedTerms; /* Whether or not to skip generating the top level array term */ bool skipGenerateTopLevelArrayTerm; /* Whether or not to generate path based undefined terms (used in composite indexes) */ bool generatePathBasedUndefinedTerms; /* * Whether or not the path has array ancestors in the pre paths: * for a path a.b.c * if a, or b are arrays then this returns true. * For wildcard indexes, returns true if any path had an array ancestor */ bool hasArrayAncestors; /* * When an array path has subtrees that have terms, and other other subtrees * that do not have terms, this is marked as true. */ bool hasArrayPartialTermExistence; /* * Whether or not to use the reduced wildcard term generation support. */ bool useReducedWildcardTerms; /* Whether array values were encountered during term generation */ bool hasArrayValues; } GenerateTermsContext; /* Exports for the core index processing layer. */ void GenerateSinglePathTermsCore(pgbson *bson, GenerateTermsContext *context, BsonGinSinglePathOptions *singlePathOptions); void GenerateWildcardPathTermsCore(pgbson *bson, GenerateTermsContext *context, BsonGinWildcardProjectionPathOptions *wildcardOptions); void GenerateTerms(pgbson *bson, GenerateTermsContext *context, bool addRootTerm); Datum *GinBsonExtractQueryUniqueIndexTerms(PG_FUNCTION_ARGS); Datum *GinBsonExtractQueryOrderBy(PG_FUNCTION_ARGS); int32_t GinBsonComparePartialOrderBy(BsonIndexTerm *queryValue, BsonIndexTerm *compareValue); IndexTermCreateMetadata GetIndexTermMetadata(void *indexOptions); IndexTraverseOption GetCompositePathIndexTraverseOption(BsonIndexStrategy strategy, void *contextOptions, const char *currentPath, uint32_t currentPathLength, const bson_value_t *bsonValue, int32_t *compositeIndexCol); #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_index_support.h000066400000000000000000000115721507310017400260050ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_index_support.h * * Common declarations for Index support functions. * *------------------------------------------------------------------------- */ #ifndef BSON_INDEX_SUPPORT_H #define BSON_INDEX_SUPPORT_H #include #include #include #include "planner/mongo_query_operator.h" struct IndexOptInfo; /* * Input immutable data for the ReplaceExtensionFunctionContext */ typedef struct ReplaceFunctionContextInput { /* Whether or not to do a runtime check for $text */ bool isRuntimeTextScan; /* Whether or not this is the query on the actual Shard table */ bool isShardQuery; /* CollectionId of the base collection if it's known */ uint64 collectionId; Index rteIndex; } ReplaceFunctionContextInput; /* The operation type for forcing index pushdown */ typedef enum ForceIndexOpType { /* No index pushdown required */ ForceIndexOpType_None = 0, /* Index pushdown required due to $text */ ForceIndexOpType_Text = 1, /* Index pushdown required due to $geoNear */ ForceIndexOpType_GeoNear = 2, /* Index pushdown required for a vectorSearch */ ForceIndexOpType_VectorSearch = 3, /* Index pushdown required for a index hint */ ForceIndexOpType_IndexHint = 4, /* Index pushdown required for a primary key lookup */ ForceIndexOpType_PrimaryKeyLookup = 5, ForceIndexOpType_Max, } ForceIndexOpType; /* * Data used to enforce index to special query operators like $geoNear, $text etc */ typedef struct ForceIndexQueryOperatorData { /* Type of the mongo query operator used */ ForceIndexOpType type; /* * If pushed to index by default by Postgres, then the it points to the index path otherwise NULL * In case this is NULL, we try to push to the available index */ IndexPath *path; /* * Any operator specific metadata or state. * e.g. For $geoNear, it is the operatorExpression which is used for deciding the index pushdown */ void *opExtraState; } ForceIndexQueryOperatorData; /* Context persisted during walking the query for order by scenarios */ typedef struct { /* Equality on shardKey if available */ RestrictInfo *shardKeyEqualityExpr; } PlannerQueryOrderByData; /* * Context object passed between ReplaceExtensionFunctionOperatorsInPaths * and ReplaceExtensionFunctionOperatorsInRestrictionPaths. This takes context * about what index paths were replaced and uses that in the replacement of * restriction paths. */ typedef struct ReplaceExtensionFunctionContext { SearchQueryEvalData queryDataForVectorSearch; /* Whether or not the index paths/restriction paths have vector search query */ bool hasVectorSearchQuery; /* Whether or not the rel pathlist has streaming cursor scan filters */ bool hasStreamingContinuationScan; /* Whether or not the index paths already has a primary key lookup */ IndexPath *primaryKeyLookupPath; /* The input data context for the call */ ReplaceFunctionContextInput inputData; /* The index data for operators can be put inside this, which are mutually exclusive and should require index */ ForceIndexQueryOperatorData forceIndexQueryOpData; PlannerQueryOrderByData plannerOrderByData; } ReplaceExtensionFunctionContext; /* Type of the parent node in the query plan of a query for $in optimization. This is not * intended for general use */ typedef enum PlanParentType { /* Don't perform $in rewrite when parent is invalid */ PARENTTYPE_INVALID = 0, /* Perform rewrite, but the rewritten BitmapORPath needs to be wrapped in a BitMapHeapPath*/ PARENTTYPE_NONE, /* Peform rewrite into a BitmapORPath*/ PARENTTYPE_BITMAPHEAP }PlanParentType; List * ReplaceExtensionFunctionOperatorsInRestrictionPaths(List *restrictInfo, ReplaceExtensionFunctionContext *context); void ReplaceExtensionFunctionOperatorsInPaths(PlannerInfo *root, RelOptInfo *rel, List *pathsList, PlanParentType parentType, ReplaceExtensionFunctionContext *context); Path * ForceIndexForQueryOperators(PlannerInfo *root, RelOptInfo *rel, ReplaceExtensionFunctionContext *context); void ConsiderIndexOrderByPushdown(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti, ReplaceExtensionFunctionContext *context); void ConsiderIndexOnlyScan(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti, ReplaceExtensionFunctionContext *context); void WalkPathsForIndexOperations(List *pathsList, ReplaceExtensionFunctionContext *context); void WalkRestrictionPathsForIndexOperations(List *restrictInfo, List *joinInfo, ReplaceExtensionFunctionContext *context); bool IsBtreePrimaryKeyIndex(struct IndexOptInfo *indexInfo); bool InMatchIsEquvalentTo(ScalarArrayOpExpr *opExpr, const bson_value_t *arrayValue); #endif documentdb-0.108-0/pg_documentdb/include/opclass/bson_text_gin.h000066400000000000000000000024551507310017400247230ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/opclass/bson_text_gin.h * * Specific exports that handle indexing for $text operators * *------------------------------------------------------------------------- */ #ifndef BSON_TEXT_GIN_H #define BSON_TEXT_GIN_H #include "tsearch/ts_type.h" #include "nodes/primnodes.h" /* * Type that holds data needed for * managing basic Text indexing query * related data. */ typedef struct QueryTextIndexData { /* * The index options of the text index * that this query will be pushed down to */ bytea *indexOptions; /* * The TSQuery Datum that is applied against * this query. */ Datum query; } QueryTextIndexData; Datum BsonTextGenerateTSQuery(const bson_value_t *queryValue, bytea *indexOptions); void BsonValidateTextQuery(const bson_value_t *queryValue); Expr * GetFuncExprForTextWithIndexOptions(List *args, bytea *indexOptions, bool doRuntimeScan, QueryTextIndexData *textIndexData); /* This is currently a hack to get $meta working. Ideally * this will be hooked up via the same framework as '$let' */ double EvaluateMetaTextScore(pgbson *document); bool TryCheckMetaScoreOrderBy(const bson_value_t *value); #endif documentdb-0.108-0/pg_documentdb/include/operators/000077500000000000000000000000001507310017400222545ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/operators/bson_expr_eval.h000066400000000000000000000061741507310017400254430ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_expr_eval.h * * Common declarations of functions for handling expression evaluation on values for bson query expressions. * *------------------------------------------------------------------------- */ #ifndef BSON_EXPR_EVAL_H #define BSON_EXPR_EVAL_H #include "io/bson_core.h" #include typedef struct FuncExpr FuncExpr; /* * State tracking necessary objects to evaluate a function * against multiple datums. Reused across multiple expression * executions. */ typedef struct ExprEvalState { /* * Executor state that is retained for execution for the functions (PG Internal state). * This tracks parameters, query JIT state, memory contexts per row etc. */ EState *estate; /* * State that tracks the compiled and JITed expression. Holds the IL steps and function * calls to be evaluated for the expression. */ ExprState *exprState; /* * Holds the slots that will have the data for each row (Evaluation of expression requires * a tuple table slot holding the Datums that are inputs to the expression). * This will be updated per execution with the current tuple (datum) being evaluated. */ TupleTableSlot *tupleSlot; /* * The Expression context used by PG (Internal state) for expression evaluation. * This holds per evaluation execution state including the incoming tuple table slot * and is mutated during the execution of the expression. This will be reset per * execution of the expression. */ ExprContext *exprContext; /* * Pre-allocated memory for the array of datums placed in the tuple table slot. * This array can be reused across executions of the expression. */ Datum *datums; }ExprEvalState; ExprEvalState * GetExpressionEvalState(const bson_value_t *expression, MemoryContext memoryContext); ExprEvalState * GetExpressionEvalStateWithCollation(const bson_value_t *expression, MemoryContext memoryContext, const char *collationString); ExprEvalState * GetExpressionEvalStateFromFuncExpr(const FuncExpr *expression, MemoryContext memoryContext); ExprEvalState * GetExpressionEvalStateForBsonInput(const bson_value_t *expression, MemoryContext memoryContext, bool hasOperatorRestrictions); void FreeExprEvalState(ExprEvalState *exprEvalState, MemoryContext memoryContext); bool EvalBooleanExpressionAgainstArray(ExprEvalState *evalState, const bson_value_t *queryValue); bool EvalBooleanExpressionAgainstValue(ExprEvalState *evalState, const bson_value_t *queryValue, bool shouldRecurseIfArray); bool EvalBooleanExpressionAgainstBson(ExprEvalState *evalState, const bson_value_t *queryValue); bson_value_t EvalExpressionAgainstArrayGetFirstMatch(ExprEvalState *evalState, const bson_value_t *queryValue); List * EvalExpressionAgainstArrayGetAllMatchingIndices(ExprEvalState *evalState, const bson_value_t *arrayValue, const bool shouldRecurseIfArray); #endif documentdb-0.108-0/pg_documentdb/include/operators/bson_expression.h000066400000000000000000000220011507310017400256400ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_expression.h * * Common declarations of the bson expressions. * *------------------------------------------------------------------------- */ #ifndef BSON_EXPRESSION_H #define BSON_EXPRESSION_H #include #define MISSING_TYPE_NAME "missing" #define MISSING_VALUE_NAME "MISSING" typedef struct ExpressionResult ExpressionResult; typedef struct BsonIntermediatePathNode BsonIntermediatePathNode; typedef struct AggregationExpressionData AggregationExpressionData; /* * A struct that defines the value for a specific variable */ typedef struct { /* The name of the variable. */ StringView name; /* Whether the variable is a constant or an expression. */ bool isConstant; /* A union which holds either the constant value or the expression data. */ union { AggregationExpressionData *expression; bson_value_t bsonValue; }; } VariableData; /* * A struct that defines the variable context available for an expression. */ typedef struct ExpressionVariableContext { /* bool to indicate if there is a single or multiple variables defined in the context. */ bool hasSingleVariable; union { /* a struct representing the variable. */ VariableData variable; /* a hashtable containing the variables at this context. */ HTAB *table; } context; /* the expression's parent to be able to traverse if the variable is not found in the current context. */ const struct ExpressionVariableContext *parent; } ExpressionVariableContext; /* Func that will handle evaluating a given operator on a document. */ typedef void (*LegacyEvaluateOperator)(pgbson *doc, const bson_value_t *operatorValue, ExpressionResult *writer); /* Func that handles evaluating a preparsed operator on a given document. */ typedef void (*HandlePreParsedOperatorFunc)(pgbson *doc, void *arguments, ExpressionResult *expressionResult); /* Enum that defines the kind of an aggregation expression. */ typedef enum AggregationExpressionKind { /* An invalid aggregation expression kind (default value). */ AggregationExpressionKind_Invalid = 0, /* An aggregation operator that is an operator, i.e: { $eq: [1, 1] } */ AggregationExpressionKind_Operator = 1, /* A constant aggregation expression, i.e: a bson value representing an int, string, bool, doc, etc. */ AggregationExpressionKind_Constant = 2, /* An aggregation expression referencing a path in the document being evaluated i.e: "$a". */ AggregationExpressionKind_Path = 3, /* An aggregation expression referencing a variable in the given variable context i.e: $$variable. */ AggregationExpressionKind_Variable = 4, /* An aggregation expression referencing a system variable in the global variable context i.e: $$variable. */ AggregationExpressionKind_SystemVariable = 5, /* An aggregation expression which is an array that contains nested expressions that are not constant. */ AggregationExpressionKind_Array = 6, /* An aggregation expression which is a document that contains nested expressions that are not constant. */ AggregationExpressionKind_Document = 7, } AggregationExpressionKind; /* Enum that defines the kind of arguments that an expression parsed. * This is temporary and it is used to free memory after the operator is evaluated from the old * expression operators engine, since there we don't reuse the parsed data. */ typedef enum AggregationExpressionArgumentsKind { /* Invalid argument kind (default value). */ AggregationExpressionArgumentsKind_Invalid = 0, /* Palloc'd struct, could be any custom struct that is palloc'd (must be freed with pfree). */ AggregationExpressionArgumentsKind_Palloc = 1, /* List * that must be freed with list_free_deep PG method. */ AggregationExpressionArgumentsKind_List = 2, /* Empty argument kind. */ AggregationExpressionArgumentsKind_Empty = 3 } AggregationExpressionArgumentsKind; /* The identifiers for system variables in aggregation expressions */ typedef enum AggregationExpressionSystemVariableKind { /* The $$NOW variable */ AggregationExpressionSystemVariableKind_Now = 1, /* The $$CLUSTER_TIME variable */ AggregationExpressionSystemVariableKind_ClusterTime = 2, /* The $$ROOT variable */ AggregationExpressionSystemVariableKind_Root = 3, /* The $$CURRENT variable */ AggregationExpressionSystemVariableKind_Current = 4, /* The $$REMOVE variable */ AggregationExpressionSystemVariableKind_Remove = 5, /* The $$DESCEND variable */ AggregationExpressionSystemVariableKind_Descend = 6, /* The $$PRUNE variable */ AggregationExpressionSystemVariableKind_Prune = 7, /* The $$KEEP variable */ AggregationExpressionSystemVariableKind_Keep = 8, /* The $$SEARCH_META variable */ AggregationExpressionSystemVariableKind_SearchMeta = 9, /* The $$USER_ROLES variable */ AggregationExpressionSystemVariableKind_UserRoles = 10, } AggregationExpressionSystemVariableKind; /* Struct representing an aggregation expression containing the necessary data in order to evaluate it. */ typedef struct AggregationExpressionData { /* The kind of the aggregation expression to know how to evaluate the expression. */ AggregationExpressionKind kind; union { /* The value representing a constant expression (AggregationExpressionKind_Constant). */ bson_value_t value; /* The root node for a tree representing a document or array expression (which are not constant values). */ const BsonIntermediatePathNode *expressionTree; /* A struct containing the data for an operator expression in order to evaluate the operator. */ struct { /* The kind of pointer typed used for the arguments, this is in order to free the allocated memory when an operator is parsed in the OLD framework. * Will remove once all expressions implement the pre-evaluated framework. */ AggregationExpressionArgumentsKind argumentsKind; /* The arguments for the operator. */ void *arguments; /* The function that evaluates the pre-parsed operator. */ HandlePreParsedOperatorFunc handleExpressionFunc; /* The return type for the operator which will help do validations or optimizations when parsing the expressions. */ bson_type_t returnType; /* The document for the operator, used to evaluate an operator that is not pre parsed. Will remove once all expressions implement the pre-evaluated framework. */ bson_value_t expressionValue; } operator; struct { /* The enum tracking the system variable (if kind is AggregationExpressionKind_SystemVariable ) */ AggregationExpressionSystemVariableKind kind; /* A path suffix if the variable has a sub dotted path (e.g. for $$ROOT.a.b will be a.b) */ StringView pathSuffix; } systemVariable; }; } AggregationExpressionData; /* Struct for the time system variables ($$NOW and $$CLUSTER_TIME). */ typedef struct TimeSystemVariables { bson_value_t nowValue; } TimeSystemVariables; /* Func that is called after every aggregation expression is parsed to check if it is valid on the current context, i.e let in top level commands like find can't have path expressions ($a) nor use $$CURRENT/$$ROOT system variables. */ typedef void (*ValidateParsedAggregationExpression)(AggregationExpressionData *data); /* Struct to pass down at parse time of the aggregation expressions that sets the information of what kind of expressions were found on the expression tree.*/ typedef struct ParseAggregationExpressionContext { /* Function that is called after every aggregation expression is parsed. */ ValidateParsedAggregationExpression validateParsedExpressionFunc; /* The time system variables */ TimeSystemVariables timeSystemVariables; /* Only $redact is allowed to use the $$KEEP,$$PRUNE, and $$DESCEND system variables. Use this boolean to prevent other operators from using these three variables.*/ bool allowRedactVariables; /* collationString to be used by comparison operators */ const char *collationString; } ParseAggregationExpressionContext; void EvaluateAggregationExpressionDataToWriter(const AggregationExpressionData *expressionData, pgbson *document, StringView path, pgbson_writer *writer, const ExpressionVariableContext * variableContext, bool isNullOnEmpty); void ParseAggregationExpressionData(AggregationExpressionData *expressionData, const bson_value_t *value, ParseAggregationExpressionContext *context); void ParseVariableSpec(const bson_value_t *variableSpec, ExpressionVariableContext *variableContext, ParseAggregationExpressionContext *parseContext); void VariableContextSetVariableData(ExpressionVariableContext *variableContext, const VariableData *variableData); void ValidateVariableName(StringView name); void GetTimeSystemVariablesFromVariableSpec(const pgbson *variableSpec, TimeSystemVariables *timeSystemVariables); pgbson * ParseAndGetTopLevelVariableSpec(const bson_value_t *varSpec, TimeSystemVariables *timeSystemVariables, bool isWriteCommand); #endif documentdb-0.108-0/pg_documentdb/include/operators/bson_expression_bucket_operator.h000066400000000000000000000010451507310017400311150ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_bucket.h * * Common function declarations for method used for $bucket aggregation stage * *------------------------------------------------------------------------- */ #ifndef BSON_EXPRESSION_BUCKET_OPERATOR_H #define BSON_EXPRESSION_BUCKET_OPERATOR_H #include "io/bson_core.h" void RewriteBucketGroupSpec(const bson_value_t *bucketSpec, bson_value_t *groupSpec); #endif documentdb-0.108-0/pg_documentdb/include/operators/bson_expression_date_operators.h000066400000000000000000000011111507310017400307320ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/aggregation/bson_expression_date_operators.h * * Common function declarations for method used for date processing in aggregation expressions * *------------------------------------------------------------------------- */ #ifndef BSON_EXPRESSION_DATE_OPERATORS_H #define BSON_EXPRESSION_DATE_OPERATORS_H #include "io/bson_core.h" void StringToDateWithDefaultFormat(bson_value_t *dateString, bson_value_t *result); #endif documentdb-0.108-0/pg_documentdb/include/operators/bson_expression_operators.h000066400000000000000000001377411507310017400277600ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/operators/bson_expression_operators.h * * Common declarations of the bson expression operators. * *------------------------------------------------------------------------- */ #include "utils/documentdb_errors.h" #include "operators/bson_expression.h" #ifndef BSON_EXPRESSION_OPERATORS_H #define BSON_EXPRESSION_OPERATORS_H /* --------------------------------------------------------- */ /* Type definitions */ /* --------------------------------------------------------- */ /* * Wrapper that tracks the lifetime of inner temporary objects * created during expression evaluation that will be freed * when expression evaluation is complete. */ typedef struct ExpressionLifetimeTracker { List *itemsToFree; } ExpressionLifetimeTracker; /* Private state tracked by the ExpressionResult. Not to be used * by operators or other implementations */ typedef struct ExpressionResultPrivate { /* the writer if one is requested and is initialized with one. */ pgbson_element_writer writer; /* Scratch space for the elementWriter if needed */ pgbson_writer baseWriter; /* whether or not baseWriter is initialized */ bool hasBaseWriter; /* whether or not the value has been set already */ bool valueSet; struct ExpressionLifetimeTracker *tracker; /* The context containing variables available for the current expression being evaluated. */ ExpressionVariableContext variableContext; } ExpressionResultPrivate; /* * structure to manage expression results in operator evaluations. * DO NOT access these fields directly. Use the ExpressionResult* functions. * Use ExpressionResultCreateChild() to initialize expression results. */ typedef struct ExpressionResult { /* The final expression result. */ bson_value_t value; /* whether the result is a writer or a value. */ bool isExpressionWriter; /* whether the expression result value was set from a field path expression or not. * i.e, "$" -> "{$project: {a: "$b.c" }}" in this case "$b.c" is a field path expression. */ bool isFieldPathExpression; ExpressionResultPrivate expressionResultPrivate; } ExpressionResult; /* State for operators that have two arguments used to apply the * operation to the result. i.e: $divide, $substract. */ typedef struct DualArgumentExpressionState { /* The first argument. */ bson_value_t firstArgument; /* The second argument. */ bson_value_t secondArgument; /* Whether any of the arguments was null or undefined. */ bool hasNullOrUndefined; /* Whether any of the arguments was a field expression ("$a") or not. */ bool hasFieldExpression; } DualArgumentExpressionState; /* State for $slice, $range which takes either 2 or 3 arguments */ typedef struct ThreeArgumentExpressionState { /* The first argument */ bson_value_t firstArgument; /* The Second argument */ bson_value_t secondArgument; /* The Third argument */ bson_value_t thirdArgument; /* Whether any of the arguments was null or undefined. */ bool hasNullOrUndefined; /* number of args which are parsed */ int totalProcessedArgs; } ThreeArgumentExpressionState; /* State for $indexOfBytes, $indexOfCP which takes either 2 or 4 arguments */ typedef struct FourArgumentExpressionState { /* The first argument */ bson_value_t firstArgument; /* The Second argument */ bson_value_t secondArgument; /* The Third argument */ bson_value_t thirdArgument; /* The Fourth argument */ bson_value_t fourthArgument; /* Whether any of the arguments was null or undefined. */ bool hasNullOrUndefined; /* number of args which are parsed */ int totalProcessedArgs; } FourArgumentExpressionState; /* Type that holds information about a timezone. * If this is used to represent a timezone ID, it should be created * with the ParseTimezone method to make sure the ID is correct. */ typedef struct ExtensionTimezone { /* Specifies if the timezone is a UTC offset in milliseconds or not. * If not it is a timezone ID, i.e America/Los_Angeles. */ bool isUtcOffset; union { /* The UTC offset in milliseconds if isUtcOffset == true. */ int64_t offsetInMs; /* The timezone ID if isUtcOffset == false. */ const char *id; }; } ExtensionTimezone; /* Type to specify the case for date and timestamp types for * GetDateStringWithDefaultFormat and GetTimestampStringWithDefaultFormat methods */ typedef enum DateStringFormatCase { /* For e.g.: Jan, Feb*/ DateStringFormatCase_CamelCase, /* For e.g.: JAN, FEB*/ DateStringFormatCase_UpperCase, /* For e.g.: jan, feb*/ DateStringFormatCase_LowerCase, } DateStringFormatCase; /* --------------------------------------------------------- */ /* Shared functions */ /* --------------------------------------------------------- */ pgbson_element_writer * ExpressionResultGetElementWriter(ExpressionResult *context); void ExpressionResultSetValue(ExpressionResult *expressionResult, const bson_value_t *value); void ExpressionResultSetValueFromWriter(ExpressionResult *expressionResult); void EvaluateAggregationExpressionData(const AggregationExpressionData *expressionData, pgbson *document, ExpressionResult *expressionResult, bool isNullOnEmpty); ExpressionResult ExpressionResultCreateChild(ExpressionResult *parent); void ExpressionResultReset(ExpressionResult *expressionResult); void ExpressionResultSetConstantVariable(ExpressionResult *expressionResult, const StringView *variableName, const bson_value_t *value); /* ************************************************************* * New operator functions that use the pre parsed framework ************************************************************* */ void HandlePreParsedDollarAbs(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAcos(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAcosh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAdd(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAllElementsTrue(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAnd(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAnyElementTrue(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarArrayElemAt(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarArrayToObject(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAsin(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAsinh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAtan(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAtan2(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAtanh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarAvg(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBsonSize(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBinarySize(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBitAnd(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBitNot(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBitOr(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBitXor(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarBucketInternal(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarCeil(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarCmp(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarConcat(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarConcatArrays(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarCond(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarConvert(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarCos(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarCosh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateAdd(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateDiff(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateFromParts(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateFromString(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateSubtract(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateToParts(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateToString(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDateTrunc(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDayOfMonth(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDayOfWeek(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDayOfYear(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDegreesToRadians(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarDivide(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarEq(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarExp(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarFilter(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarFirst(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarFirstN(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarFloor(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarGetField(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarGt(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarGte(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIndexOfBytes(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIndexOfCP(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarHour(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIfNull(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIn(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIndexOfArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIsNumber(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIsArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLast(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIsoDayOfWeek(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIsoWeek(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarIsoWeekYear(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLastN(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLet(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLog(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLog10(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLn(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLt(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLte(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarLtrim(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMakeArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMaxMinN(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMap(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMax(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMergeObjects(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMeta(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMillisecond(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMin(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMinute(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMod(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMonth(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarMultiply(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarNe(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarNot(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarObjectToArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarOr(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarPow(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRadiansToDegrees(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRand(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRange(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarReduce(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRegexFind(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRegexFindAll(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRegexMatch(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarReplaceAll(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarReplaceOne(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarReverseArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRound(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarRtrim(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSecond(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetDifference(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetEquals(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetField(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetIntersection(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetIsSubset(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSetUnion(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSin(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSinh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSize(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSlice(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSortArray(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSplit(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSqrt(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarStrCaseCmp(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarStrLenBytes(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarStrLenCP(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSubstrBytes(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSubstrCP(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSubtract(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSum(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarSwitch(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTan(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTanh(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToBool(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToDate(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToDecimal(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToDecimal(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToDouble(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToInt(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToLong(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToObjectId(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToString(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToUUID(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToLower(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToUpper(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTrim(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTrunc(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarToHashedIndexKey(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTsIncrement(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarTsSecond(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarType(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarUnsetField(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarWeek(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarYear(pgbson *doc, void *arguments, ExpressionResult *expressionResult); void HandlePreParsedDollarZip(pgbson *doc, void *arguments, ExpressionResult *ExpressionResult); void ParseDollarAbs(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAcos(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAcosh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAdd(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAllElementsTrue(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAnd(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAnyElemAt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAnyElementTrue(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarArrayElemAt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarArrayToObject(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAsin(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAsinh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAtan(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAtan2(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAtanh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarAvg(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBsonSize(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBinarySize(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBitAnd(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBitNot(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBitOr(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBitXor(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarBucketInternal(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarCeil(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarConcat(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarConcatArrays(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarCond(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarConvert(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarCos(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarCosh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarCmp(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateAdd(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateDiff(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateFromParts(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateFromString(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateSubtract(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateToParts(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateToString(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDateTrunc(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDayOfMonth(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDayOfWeek(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDayOfYear(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDegreesToRadians(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarDivide(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarEq(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarExp(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFirst(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFirstN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFloor(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFilter(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarGetField(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarGt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarGte(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarHour(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIfNull(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIn(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIndexOfArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIsArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIsNumber(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIsoDayOfWeek(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIsoWeek(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIsoWeekYear(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLast(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLet(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLiteral(const bson_value_t *inputDocument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLn(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLog(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLog10(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLte(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMap(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMax(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLastN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMakeArray(const bson_value_t *inputDocument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMaxN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMeta(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMergeObjects(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMillisecond(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMin(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMinN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMinute(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMod(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMonth(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMultiply(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarNe(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarNot(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarObjectToArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarOr(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFilter(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarFirstN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIndexOfArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIndexOfBytes(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarIndexOfCP(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLastN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLiteral(const bson_value_t *inputDocument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarLtrim(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMakeArray(const bson_value_t *inputDocument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMaxN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarMinN(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarPow(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRadiansToDegrees(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRand(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRange(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarReduce(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRegexFind(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRegexFindAll(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRegexMatch(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarReplaceAll(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarReplaceOne(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarReverseArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRound(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarRtrim(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSecond(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetDifference(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetEquals(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetField(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetIntersection(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetIsSubset(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSetUnion(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSin(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSize(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSinh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSlice(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSortArray(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSplit(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSqrt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarStrCaseCmp(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarStrLenBytes(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarStrLenCP(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSubstr(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSubstrBytes(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSubstrCP(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSubtract(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSum(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarSwitch(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTan(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTanh(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToBool(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToDate(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToDecimal(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToDouble(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToHashedIndexKey(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToInt(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToLong(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToObjectId(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToString(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToUUID(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToLower(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToUpper(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarToHashedIndexKey(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTrim(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTrunc(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTsSecond(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarTsIncrement(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarType(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarUnsetField(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarWeek(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarYear(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); void ParseDollarZip(const bson_value_t *argument, AggregationExpressionData *data, ParseAggregationExpressionContext *context); /* Shared functions for operator handlers */ void * ParseFixedArgumentsForExpression(const bson_value_t *argumentValue, int numberOfExpectedArgs, const char *operatorName, AggregationExpressionArgumentsKind *argumentsKind, ParseAggregationExpressionContext *context); void * ParseRangeArgumentsForExpression(const bson_value_t *argumentValue, int minRequiredArgs, int maxRequiredArgs, const char *operatorName, AggregationExpressionArgumentsKind *argumentsKind, ParseAggregationExpressionContext *context); List * ParseVariableArgumentsForExpression(const bson_value_t *value, bool *isConstant, ParseAggregationExpressionContext *context); void ProcessThreeArgumentElement(const bson_value_t *currentElement, bool isFieldPathExpression, void *state); StringView GetDateStringWithDefaultFormat(int64_t dateInMs, ExtensionTimezone timezone, DateStringFormatCase formatCase); StringView GetTimestampStringWithDefaultFormat(const bson_value_t *timeStampBsonElement, ExtensionTimezone timezone, DateStringFormatCase formatCase); /* Helper inline method to throw error for expressions that take N number of args * but a different number was provided. */ inline static void pg_attribute_noreturn() ThrowExpressionTakesExactlyNArgs(const char * expression, int requiredArgs, int numArgs) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16020), errmsg( "The expression %s requires exactly %d arguments, but %d arguments were actually provided.", expression, requiredArgs, numArgs))); } /* Helper inline method to throw error for expressions that take minimum N number of args and Maximum M * but a different number was provided. */ inline static void pg_attribute_noreturn() ThrowExpressionNumOfArgsOutsideRange(const char * expression, int minRequiredArgs, int maxRequiredArgs, int numArgs) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_RANGEARGUMENTEXPRESSIONARGSOUTOFRANGE), errmsg( "The expression %s requires no fewer than %d arguments and no more than %d arguments, but %d arguments were actually provided.", expression, minRequiredArgs, maxRequiredArgs, numArgs))); } /* Whether or not the expression result value is undefined */ inline static bool IsExpressionResultUndefined(const bson_value_t *value) { return value->value_type == BSON_TYPE_UNDEFINED || value->value_type == BSON_TYPE_EOD; } /* Whether or not the expression result value is null or undefined */ inline static bool IsExpressionResultNull(const bson_value_t *value) { return value->value_type == BSON_TYPE_NULL || value->value_type == BSON_TYPE_UNDEFINED; } /* Whether or not the expression result value is null or undefined */ inline static bool IsExpressionResultNullOrUndefined(const bson_value_t *value) { return value->value_type == BSON_TYPE_NULL || IsExpressionResultUndefined(value); } /* Whether the AggregationExpressionData contains a constant */ static inline bool IsAggregationExpressionConstant(const AggregationExpressionData *data) { return data->kind == AggregationExpressionKind_Constant; } /* Given a list checks if each element in list is constant or not */ static inline bool AreElementsInListConstant(List *args) { Assert(args != NULL && IsA((args), List)); int index = 0; int sizeOfList = args->length; while (index < sizeOfList) { if (!IsAggregationExpressionConstant(list_nth(args, index))) { return false; } index++; } return true; } /* Initializes the state for dual argument expressions. */ static inline void InitializeDualArgumentExpressionState(bson_value_t firstValue, bson_value_t secondValue, bool hasFieldExpression, DualArgumentExpressionState *state) { state->firstArgument = firstValue; state->secondArgument = secondValue; state->hasFieldExpression = hasFieldExpression; state->hasNullOrUndefined = IsExpressionResultNullOrUndefined(&firstValue) || IsExpressionResultNullOrUndefined(&secondValue); } /* * Helper to free the space allocated when parsing operator expression. * This is used in place of list_free_deep when arguments may contain NULL entries. */ static inline void FreeVariableLengthArgs(List *arguments) { Assert(arguments != NIL); ListCell *cell; foreach(cell, arguments) { AggregationExpressionData *data = lfirst(cell); if (data != NULL) { pfree(data); } } pfree(arguments); } #endif documentdb-0.108-0/pg_documentdb/include/planner/000077500000000000000000000000001507310017400216755ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/planner/documentdb_planner.h000066400000000000000000000060721507310017400257160ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/documentdb_planner.h * * The pg_documentdb planner hook function. * *------------------------------------------------------------------------- */ #ifndef DOCUMENTDB_PLANNER_H #define DOCUMENTDB_PLANNER_H #include "postgres.h" #include #include #include #include #include extern planner_hook_type ExtensionPreviousPlannerHook; extern set_rel_pathlist_hook_type ExtensionPreviousSetRelPathlistHook; extern explain_get_index_name_hook_type ExtensionPreviousIndexNameHook; extern get_relation_info_hook_type ExtensionPreviousGetRelationInfoHook; extern bool SimulateRecoveryState; extern bool DocumentDBPGReadOnlyForDiskFull; PlannedStmt * DocumentDBApiPlanner(Query *parse, const char *queryString, int cursorOptions, ParamListInfo boundParams); void ExtensionRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte); void ExtensionGetRelationInfoHook(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel); bool IsDocumentDbCollectionBasedRTE(RangeTblEntry *rte); bool IsResolvableDocumentDbCollectionBasedRTE(RangeTblEntry *rte, ParamListInfo boundParams); const char * ExtensionExplainGetIndexName(Oid indexId); Const * GetConstParamValue(Node *param, ParamListInfo boundParams); const char * ExtensionIndexOidGetIndexName(Oid indexId, bool useLibPq); const char * GetDocumentDBIndexNameFromPostgresIndex(const char *pgIndexName, bool useLibPq); /* Method that throws an error if we're trying to execute a write command and the * current database is in recovery mode (read-only mode). */ static inline void ThrowIfWriteCommandNotAllowed(void) { if (RecoveryInProgress() || SimulateRecoveryState) { ereport(ERROR, (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION), errmsg( "Can't execute write operation, the database is in recovery and waiting for the standby node to be promoted."))); } if (DocumentDBPGReadOnlyForDiskFull) { /* * We want to throw `ERRCODE_DISK_FULL` from backend when the disk is say `90% full` as opposed to waiting * for the disk to be `100% full`. Marlin runs a background task that monitors the disk and * sets a config `ApiGucPrefix.IsPgReadOnlyForDiskFull = true`, the postgres process then reads the config * and stores it in the `DocumentDBPGReadOnlyForDiskFull` variable. Marlin also set the postgres config * `default_transaction_read_only = on` which makes postgres throw `ERRCODE_READ_ONLY_SQL_TRANSACTION` * for any operation that can update data. * * ToMongoError() utility in PostgresMongoResultExtensions.cs (aka gateway) then converts the Postgres * error to appropriate Mongo Client error code and error message. */ ereport(ERROR, (errcode(ERRCODE_DISK_FULL), errmsg( "Can't execute write operation, The database disk is full"))); } } #endif documentdb-0.108-0/pg_documentdb/include/planner/documents_custom_planner.h000066400000000000000000000006711507310017400271640ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/documents_custom_planner.h * * Custom planning for Document APIs * *------------------------------------------------------------------------- */ #ifndef DOCUMENTS_CUSTOM_PLANNER_H #define DOCUMENTS_CUSTOM_PLANNER_H PlannedStmt * TryCreatePointReadPlan(Query *query); #endif documentdb-0.108-0/pg_documentdb/include/planner/mongo_query_operator.h000066400000000000000000000116561507310017400263360ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/planner/mongo_query_operator.h * * Common declarations for query operators in Mongo. * *------------------------------------------------------------------------- */ #ifndef MONGO_QUERY_OPERATOR_H #define MONGO_QUERY_OPERATOR_H #include "io/bson_core.h" #include "opclass/bson_gin_common.h" #include "utils/feature_counter.h" /* Invalid Feature counter tag for query operators that are not defined */ #define INVALID_QUERY_OPERATOR_FEATURE_TYPE MAX_FEATURE_INDEX /* type of Mongo query operator * Note for every entry here there must be an entry in the mongo_query_operators * array that matches the exact index. */ typedef enum MongoQueryOperatorType { /* comparison */ QUERY_OPERATOR_EQ = 0, QUERY_OPERATOR_GT, QUERY_OPERATOR_GTE, QUERY_OPERATOR_LT, QUERY_OPERATOR_LTE, QUERY_OPERATOR_NE, QUERY_OPERATOR_IN, QUERY_OPERATOR_NIN, QUERY_OPERATOR_ALL, /* logical */ QUERY_OPERATOR_AND, QUERY_OPERATOR_OR, QUERY_OPERATOR_NOT, QUERY_OPERATOR_NOR, QUERY_OPERATOR_ALWAYS_TRUE, QUERY_OPERATOR_ALWAYS_FALSE, /* element */ QUERY_OPERATOR_EXISTS, QUERY_OPERATOR_TYPE, QUERY_OPERATOR_SIZE, QUERY_OPERATOR_ELEMMATCH, /* evaluation */ QUERY_OPERATOR_REGEX, QUERY_OPERATOR_MOD, QUERY_OPERATOR_TEXT, QUERY_OPERATOR_EXPR, QUERY_OPERATOR_SAMPLERATE, QUERY_OPERATOR_JSONSCHEMA, /* bit-wise */ QUERY_OPERATOR_BITS_ALL_CLEAR, QUERY_OPERATOR_BITS_ANY_CLEAR, QUERY_OPERATOR_BITS_ALL_SET, QUERY_OPERATOR_BITS_ANY_SET, /* Geospatial operators */ QUERY_OPERATOR_WITHIN, QUERY_OPERATOR_GEOWITHIN, QUERY_OPERATOR_GEOINTERSECTS, QUERY_OPERATOR_NEAR, QUERY_OPERATOR_NEARSPHERE, /* * This is different from geonear agg stage. * Behaviour is same as nearsphere */ QUERY_OPERATOR_GEONEAR, /* Negation operators */ QUERY_OPERATOR_NOT_GT, QUERY_OPERATOR_NOT_GTE, QUERY_OPERATOR_NOT_LT, QUERY_OPERATOR_NOT_LTE, /* Miscellaneous operators */ QUERY_OPERATOR_COMMENT, QUERY_OPERATOR_UNKNOWN } MongoQueryOperatorType; /* * The type of input for the MongoQueryOperator requested */ typedef enum { /* Not a valid input bson type */ MongoQueryOperatorInputType_Invalid = 0, /* Query Operator based on Bson */ MongoQueryOperatorInputType_Bson, /* Query Operator based on Bson values */ MongoQueryOperatorInputType_BsonValue, } MongoQueryOperatorInputType; typedef Oid (*OperatorOidLookupFunc)(void); /* * MongoQueryOperator represents a Mongo query operator * Holds information about the operator and that pertaining * to runtime query planning. */ typedef struct { /* operator key (e.g. "$eq") */ char *mongoOperatorName; /* operator type number */ MongoQueryOperatorType operatorType; /* Whether the operator operates on bson or bsonquery */ OperatorOidLookupFunc operandTypeOid; /* Function that queries the Oid of bson query function name * (e.g. bson_dollar_eq(, )) if applicable */ OperatorOidLookupFunc postgresRuntimeFunctionOidLookup; /* Function that queries the Oid of the bson query operator name and * for the runtime evaluation of the function (e.g. #>) if applicable. */ OperatorOidLookupFunc postgresRuntimeOperatorOidLookup; /* Function that queries the Oid of the bson function name for the index * (e.g. bson_dollar_eq(, )) if applicable . */ OperatorOidLookupFunc postgresIndexFunctionOidLookup; /* * Feature counter type to be used with the query operator */ FeatureType featureType; } MongoQueryOperator; /* * MongoIndexOperatorInfo holds information about the mongo operator * and the corresponding information for pushing down operators to the index */ typedef struct { /* bson query operator name (e.g. " @= ") - if applicable */ char *postgresOperatorName; /* The indexing strategy for this operator */ BsonIndexStrategy indexStrategy; /* Whether the operator is in the internal schema */ bool isApiInternalSchema; } MongoIndexOperatorInfo; const MongoQueryOperator * GetMongoQueryOperatorByMongoOpName(const char *key, MongoQueryOperatorInputType inputType); const MongoQueryOperator * GetMongoQueryOperatorByPostgresFuncId(Oid functionId); const MongoQueryOperator * GetMongoQueryOperatorByQueryOperatorType(MongoQueryOperatorType operatorType, MongoQueryOperatorInputType inputType); const MongoIndexOperatorInfo * GetMongoIndexOperatorInfoByPostgresFuncId(Oid functionId); BsonIndexStrategy GetBsonStrategyForFuncId(Oid functionOid); Oid GetMongoQueryOperatorOid(const MongoIndexOperatorInfo *mongoQueryOperator); const MongoQueryOperator * GetMongoQueryOperatorFromExpr(Node *expr, List **args); const MongoIndexOperatorInfo * GetMongoIndexQueryOperatorFromNode(Node *expr, List **args); const MongoIndexOperatorInfo * GetMongoIndexOperatorByPostgresOperatorId(Oid operatorId); #endif documentdb-0.108-0/pg_documentdb/include/query/000077500000000000000000000000001507310017400214035ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/query/bson_dollar_operators.h000066400000000000000000000071241507310017400261540ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_dollar_operators.h * * Common declarations of the bson dollar operators. * *------------------------------------------------------------------------- */ #ifndef BSON_DOLLAR_OPERATOR_H #define BSON_DOLLAR_OPERATOR_H #include "types/pcre_regex.h" /* * This enum defines the result of a traverse operation to a document * when attempting to compare a document's field against a filter. */ typedef enum CompareResult { /* * The field was not found on attempting to traverse the document * for a dotted path. */ CompareResult_PathNotFound = 0, /* * The field had a type or value mismatch, or the parent path * had a value that was incompatible with the dotted path traversal. */ CompareResult_Mismatch = 1, /* * The value was a match based on the comparison criteria selected. */ CompareResult_Match = 2, } CompareResult; /* forward declaration of validation state */ typedef struct TraverseValidateState *TraverseValidateStatePointer; /* The core comparison function extension for comparisons of Bson operators */ typedef bool (*CompareMatchValueFunc)(const pgbsonelement *element, TraverseValidateStatePointer state, bool isArrayInnerTerm); /* To store the Regex pattern strings and its options used for matching */ typedef struct RegexData { /* Regex pattern */ char *regex; /* Options that can be used for regex pattern matching */ char *options; /* PCRE context, compiled Regex, matched data etc */ PcreData *pcreData; } RegexData; /* * This is state that is used by TraverseBson for Comparison functions * by TraverseBsonExecutionFuncs * Each intent for Comparison can create sub-structs that contain their own state. * The base state is represented here and used by the BsonExecutionFuncs to process * comparisons. */ typedef struct TraverseValidateState { CompareMatchValueFunc matchFunc; CompareResult compareResult; const char *collationString; } TraverseValidateState; /* The core comparison function extension for compare set bit position array for Bitwise operators */ typedef bool (*CompareArrayForBitwiseOp)(bson_iter_t *sourceArrayIter, bson_iter_t *filterArrayIter, bool isSignExtended); bool CompareRegexTextMatch(const bson_value_t *docBsonVal, RegexData *regexData); bool CompareModOperator(const bson_value_t *srcVal, const bson_value_t *modArrVal); void GetRemainderFromModBsonValues(const bson_value_t *dividendValue, const bson_value_t *divisorValue, bool validateInputs, bson_value_t *result); void WriteSetBitPositionArray(uint8_t *src, int srcLength, pgbson_writer *writer); bool CompareBitwiseOperator(const bson_value_t *documentIterator, const bson_value_t *filterArray, CompareArrayForBitwiseOp bitsCompareFunc); /* core functions for compare set bit position array for bitwise operators*/ bool CompareArrayForBitsAllClear(bson_iter_t *sourceArrayIter, bson_iter_t *filterArrayIter, bool isSignExtended); bool CompareArrayForBitsAnyClear(bson_iter_t *sourceArrayIter, bson_iter_t *filterArrayIter, bool isSignExtended); bool CompareArrayForBitsAllSet(bson_iter_t *sourceArrayIter, bson_iter_t *filterArrayIter, bool isSignExtended); bool CompareArrayForBitsAnySet(bson_iter_t *sourceArrayIter, bson_iter_t *filterArrayIter, bool isSignExtended); Datum BsonOrderby(pgbson *leftBson, pgbson *rightBson, bool validateSort, const char *collationString); #endif documentdb-0.108-0/pg_documentdb/include/query/bson_dollar_selectivity.h000066400000000000000000000015511507310017400265000ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/query/bson_dollar_selectivity.h * * Exports for Query Selectivity for DocumentDB boolean index operators/functions. * *------------------------------------------------------------------------- */ #ifndef BSON_DOLLAR_SELECTIVITY_H #define BSON_DOLLAR_SELECTIVITY_H #include #include /* The low selectivity - based on prior guess. */ static const double LowSelectivity = 0.01; /* Selectivity when most of the table is accessed (Selectivity max is 1) */ static const double HighSelectivity = 0.9; double GetDollarOperatorSelectivity(PlannerInfo *planner, Oid selectivityOpExpr, List *args, Oid collation, int varRelId, double defaultExprSelectivity); #endif documentdb-0.108-0/pg_documentdb/include/query/query_operator.h000066400000000000000000000123061507310017400246360ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/bson_query.h * * Common declarations for BSON query functions. * *------------------------------------------------------------------------- */ #ifndef QUERY_OPERATOR_H #define QUERY_OPERATOR_H #include #include #include "metadata/collection.h" #include "io/bson_core.h" #include "opclass/bson_gin_common.h" #include "planner/mongo_query_operator.h" /* BsonElemMatchContext is passed down while expanding BSON query expressions to handle $elemMatch operator */ typedef struct BsonElemMatchContext { /* Depth in case of nested elemMatch while traversing the query */ int currentDepth; /* Max Depth in case of nested elemMatch */ int maxDepth; /* List of quals to be applied as outermost quals in elemMatch query tree * Example: { a: {$elemMatch: {d: {$elemMatch: {e: {$gte: 1}}}, b: {$elemMatch: { $gte: 80, $lt: 85 }}}} } * The outermost quals will be {"a.d.e" : {"$gte" : 1}, "a.b" : {"$gte" : 80}, "a.b" : {"$lt" : 85} } */ List *outerMostExpressionQuals; /* It is set when bson query expression results in SUBLINK creation in query tree */ bool hasSublink; /* It is set when bson query expression contains number field inside $elemMatch * Example: {"a" : { "$elemMatch": { "0" : 100 } } } */ bool hasNumberField; /* It is set when there is expression inside $elemMatch for $ne, $not */ bool hasNegationOp; /* isCmpOpInsideElemMatch : it will be set to true when there is a cmp operator inside $elemMatch i.e. for calling CreateOpExprFromOperatorDocIterator. * {path : {$elemMatch : {$op : {...}}}}. we are interested in $op being another $elemMatch for array of array scenario. */ bool isCmpOpInsideElemMatch; } BsonElemMatchContext; /* * BsonQueryOperatorContext is passed down while expanding BSON query expressions * of the form @@ */ typedef struct BsonQueryOperatorContext { Expr *documentExpr; /* The input variable type for functions. Note that this should * match the data type expectations of documentExpr above. * If documentExpr is bson -> this is bson (otherwise it's bsonValue) */ MongoQueryOperatorInputType inputType; /* * Whether or not to treat a simple $or as $in. */ bool simplifyOperators; /* * Coerce expressions to runtime OpExpr if available */ bool coerceOperatorExprIfApplicable; /* Required path names for vector search * it is set only when the filter of vector search is specified */ HTAB *requiredFilterPathNameHashSet; /* List of sort clauses, if any query operator adds them * e.g. $near, $nearSphere etc, will be NULL for most of * the query operators. * * Please note that the `ressortgroupref` is needed to be updated * based on the overall query structure later */ List *sortClauses; /* List of Target entries for these sort clauses * * Please note that the `resno` is needed to be updated * based on the overall query structure later */ List *targetEntries; /* Any let variable context for this query operator */ Expr *variableContext; /* ICU standard colation string. See AggregationPipelineBuildContext for more details. */ const char *collationString; /* The following query operators cannot be used to evaluate input values during schema validation. * $expr with $function expressions / $near / $nearSphere / $text / $where */ bool hasOperatorRestrictions; } BsonQueryOperatorContext; Var * MakeSimpleDocumentVar(void); Node * ReplaceBsonQueryOperators(Query *node, ParamListInfo boundParams); void ValidateQueryDocumentValue(const bson_value_t *queryDocumentValue); void ValidateQueryDocument(pgbson *queryDocument); bool QueryDocumentsAreEquivalent(const pgbson *leftQueryDocument, const pgbson *rightQueryDocument); List * CreateQualsFromQueryDocIterator(bson_iter_t *queryDocIterator, BsonQueryOperatorContext *context); Node * EvaluateBoundParameters(Node *expression, ParamListInfo boundParams); List * CreateQualsForBsonValueTopLevelQueryIter(bson_iter_t *queryIter); Expr * CreateQualForBsonValueExpression(const bson_value_t *expression, const char *collationString); Expr * CreateQualForBsonValueArrayExpression(const bson_value_t *expression); void BsonQueryOperatorContextCommonBuilder(BsonQueryOperatorContext *context); Expr * CreateQualForBsonExpression(const bson_value_t *expression, const char *queryPath, BsonQueryOperatorContext *context); Expr * CreateNonShardedShardKeyValueFilter(int collectionVarNo, const MongoCollection *collection); Expr * CreateShardKeyFiltersForQuery(const bson_value_t *queryDocument, pgbson *shardKey, uint64_t collectionId, Index collectionVarno, bool *isShardKeyCollationAware); Expr * CreateIdFilterForQuery(List *existingQuals, Index collectionVarno, bool *isCollationAware, bool *isPointRead); bool ValidateOrderbyExpressionAndGetIsAscending(pgbson *orderby); /* Checks the validity of value for $in and $nin ops */ bool IsValidBsonDocumentForDollarInOrNinOp(const bson_value_t *value); void UpdateQueryOperatorContextSortList(Query *query, List *sortClauses, List *targetEntries); #endif documentdb-0.108-0/pg_documentdb/include/roles.h000066400000000000000000000016621507310017400215400ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/roles.h * * Role CRUD functions. * *------------------------------------------------------------------------- */ #ifndef EXTENSION_ROLES_H #define EXTENSION_ROLES_H #include "postgres.h" #include "utils/string_view.h" typedef struct { const char *roleName; List *inheritedBuiltInRoles; } CreateRoleSpec; typedef struct { List *roleNames; bool showAllRoles; bool showBuiltInRoles; bool showPrivileges; } RolesInfoSpec; typedef struct { const char *roleName; } DropRoleSpec; /* Method to create a role */ Datum create_role(pgbson *createRoleBson); /* Method to drop a role */ Datum drop_role(pgbson *dropRoleBson); /* Method to get roles information */ Datum roles_info(pgbson *rolesInfoBson); /* Method to update a role */ Datum update_role(pgbson *updateRoleBson); #endif documentdb-0.108-0/pg_documentdb/include/schema_validation/000077500000000000000000000000001507310017400237105ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/schema_validation/schema_validation.h000066400000000000000000000032741507310017400275410ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/schema_validation.h * * Common declarations for schema validation functions. * *------------------------------------------------------------------------- */ #ifndef SCHEMA_VALIDATION_H #define SCHEMA_VALIDATION_H #include "metadata/collection.h" #include "operators/bson_expr_eval.h" extern bool EnableSchemaValidation; #define FAILED_VALIDATION_ERROR_MSG "Document failed validation" #define FAILED_VALIDATION_PLAN_EXECUTOR_ERROR_MSG \ "PlanExecutor error during aggregation :: caused by :: Document failed validation" ExprEvalState * PrepareForSchemaValidation(pgbson *schemaValidationInfo, MemoryContext memoryContext); void AssignSchemaValidationState(ExprEvalState *state, pgbson *schemaValidationInfo, MemoryContext memoryContext); void ValidateSchemaOnDocumentInsert(ExprEvalState *evalState, const bson_value_t *document, const char *errMsg); void ValidateSchemaOnDocumentUpdate(ValidationLevels validationLevelText, ExprEvalState *evalState, const pgbson *sourceDocument, const pgbson *targetDocument, const char *errMsg); /* Inline function that determines whether to perform schema validation */ static inline bool CheckSchemaValidationEnabled(MongoCollection *collection, bool bypassDocumentValidation) { return EnableSchemaValidation && collection->schemaValidator.validationLevel != ValidationLevel_Off && !bypassDocumentValidation && collection->schemaValidator.validator != NULL && collection->schemaValidator.validationAction == ValidationAction_Error; } #endif documentdb-0.108-0/pg_documentdb/include/sharding/000077500000000000000000000000001507310017400220355ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/sharding/sharding.h000066400000000000000000000021261507310017400240060ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * sharding/sharding.h * * Common declarations for sharding functions. * *------------------------------------------------------------------------- */ #ifndef SHARDING_H #define SHARDING_H #include "metadata/collection.h" int64 ComputeShardKeyHashForDocument(pgbson *shardKey, uint64_t collectionId, pgbson *document); bool ComputeShardKeyHashForQuery(pgbson *shardKey, uint64_t collectionId, pgbson *query, int64 *shardKeyHash, bool *isShardKeyCollationAware); bool ComputeShardKeyHashForQueryValue(pgbson *shardKey, uint64_t collectionId, const bson_value_t *query, int64 *shardKeyHash, bool *isShardKeyCollationAware); Expr * ComputeShardKeyExprForQueryValue(pgbson *shardKey, uint64_t collectionId, const bson_value_t *queryDocument, int32_t collectionVarno, bool *isShardKeyCollationAware); Expr * CreateShardKeyValueFilter(int collectionVarNo, Const *valueConst); #endif documentdb-0.108-0/pg_documentdb/include/update/000077500000000000000000000000001507310017400215205ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/update/bson_update.h000066400000000000000000000016661507310017400242050ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_update.h * * Common declarations of functions for handling bson updates. * *------------------------------------------------------------------------- */ #ifndef BSON_UPDATE_H #define BSON_UPDATE_H #include "io/bson_core.h" typedef enum { UpdateType_ReplaceDocument, UpdateType_Operator, UpdateType_AggregationPipeline } UpdateType; UpdateType DetermineUpdateType(const bson_value_t *updateSpec); void ValidateUpdateDocument(const bson_value_t *updateSpec, const bson_value_t *querySpec, const bson_value_t *arrayFilters, const bson_value_t *variableSpec); pgbson * BsonUpdateDocument(pgbson *sourceDocument, const bson_value_t *updateSpec, const bson_value_t *querySpec, const bson_value_t *arrayFilters, const bson_value_t *variableSpec); #endif documentdb-0.108-0/pg_documentdb/include/update/bson_update_common.h000066400000000000000000000123601507310017400255460ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_update_common.h * * Private and common declarations of functions for handling bson updates * Shared across update implementations. * *------------------------------------------------------------------------- */ #ifndef BSON_UPDATE_COMMON_H #define BSON_UPDATE_COMMON_H #include #include "io/bson_core.h" #include "utils/documentdb_errors.h" #include "aggregation/bson_positional_query.h" struct AggregationPipelineUpdateState; struct BsonIntermediatePathNode; typedef struct BsonUpdateTracker BsonUpdateTracker; struct UpdateOperatorWriter; struct UpdateSetValueState; struct CurrentDocumentState; struct BsonIntermediatePathNode; /* Any positional metadata available during building the update spec for * target documents */ typedef struct PositionalUpdateSpec { /* The input query spec - used when evaluating $ positional operators */ const bson_value_t *querySpec; /* hashmap of char* to bson_value_t* */ HTAB *arrayFilters; /* The processed positional query data from the original querySpec */ BsonPositionalQueryData *processedQuerySpec; } PositionalUpdateSpec; /* WriteUpdatedValuesFunc function takes an existing value in the current document, * applies the update mutation pertinent to that operator, and writes the updated * value to the writer */ typedef void (*WriteUpdatedValuesFunc)(const bson_value_t *existingValue, struct UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const struct UpdateSetValueState *setValueState, const struct CurrentDocumentState *state); /* OPERATOR DEFINITIONS * These types specify how to build operators and define all supported * update operators. */ /* * An optional function to retrieve operator specific state given a specific * updateSpec value. */ typedef void *(*UpdateOperatorGetFuncState)(const bson_value_t *tree); /* * HandleUpdateOperatorUpdateBsonTree takes a specific update operator document * and constructs the update tree. The function is also given a pointer to the * function that will apply the update on the target document - this can be cached * into the tree so we don't need to look up this data again. */ typedef void (*HandleUpdateOperatorUpdateBsonTree)(struct BsonIntermediatePathNode *tree, bson_iter_t *updateSpec, WriteUpdatedValuesFunc updateFunc, UpdateOperatorGetFuncState stateFunc, const PositionalUpdateSpec * positionalSpec, bool isUpsert); /* The declaration of the Mongo update operators */ typedef struct MongoUpdateOperatorSpec { /* The name of the update operator e.g. $set */ const char *operatorName; /* Function that handles parsing the update Spec for the operator * and updates the tree with the set of paths being updated */ HandleUpdateOperatorUpdateBsonTree updateTreeFunc; /* Function that writes the updated values into the target writer * for a given document */ WriteUpdatedValuesFunc updateWriterFunc; /* An optional function for retreiving state pertinent to the * update node value */ UpdateOperatorGetFuncState updateWriterGetState; } MongoUpdateOperatorSpec; /* aggregation */ struct AggregationPipelineUpdateState * GetAggregationPipelineUpdateState(const bson_value_t * updateSpec, const bson_value_t * variableSpec); pgbson * ProcessAggregationPipelineUpdate(pgbson *sourceDoc, const struct AggregationPipelineUpdateState * updateState, bool isUpsert); /* Update workflows */ void RegisterUpdateOperatorExtension(const MongoUpdateOperatorSpec *extensibleDefinition); const struct BsonIntermediatePathNode * GetOperatorUpdateState(const bson_value_t *updateSpec, const bson_value_t * querySpec, const bson_value_t * arrayFilters, bool isUpsert); pgbson * ProcessUpdateOperatorWithState(pgbson *sourceDoc, const struct BsonIntermediatePathNode * updateState, bool isUpsert, BsonUpdateTracker *updateDescription); /* * Throws an error that the _id has been detected as changed in the process of updating the document. * Call it when UpdateType is OperatorUpdate and _id has changed. */ inline static void pg_attribute_noreturn() ThrowIdPathModifiedErrorForOperatorUpdate() { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_IMMUTABLEFIELD), errmsg( "Updating the path '_id' is not allowed because it would change the immutable field '_id'"))); } /* * Throws an error that the path in the projection tree has a prior update requested that would conflict * with the update requested. */ inline static void pg_attribute_noreturn() ThrowPathConflictError(const char * requestedPath, const char * existingPath) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_CONFLICTINGUPDATEOPERATORS), errmsg( "Modifying the path '%s' will result in a conflict occurring at '%s'", requestedPath, existingPath))); } #endif documentdb-0.108-0/pg_documentdb/include/update/bson_update_operators.h000066400000000000000000000173021507310017400262750ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/bson/bson_update_operators.h * * Private and update operator declarations of functions for handling bson updates. * *------------------------------------------------------------------------- */ #ifndef BSON_UPDATE_OPERATORS_H #define BSON_UPDATE_OPERATORS_H #include "io/bson_core.h" #include "operators/bson_expr_eval.h" #include "utils/documentdb_errors.h" /* * State that is passed to the update operators when writing the * update values. Contains global state that is pertinent to the * current document being updated. */ typedef struct CurrentDocumentState { /* * The document ID of the document being updated */ const bson_value_t documentId; /* Whether or not updating the current document is an upsert * operation */ const bool isUpsert; /* The source document used to evaluate specific update scenarios * like rename etc. */ const pgbson *sourceDocument; /* For the '$' positional operator, the matching index from the last array in the query filter is found and stored here for reuse in all '$' positional updates */ int indexOfPositionalTypeQueryFilter; } CurrentDocumentState; /* * State that is passed to each update function * that is pertinent to the field path that is being * updated. Contains information that is used for error logging * and diagnostics. */ typedef struct UpdateSetValueState { /* The update field path (contains only the current field) */ const StringView *fieldPath; /* The relative dotted path from the root to the field */ const char *relativePath; /* Whether the update path is in an array context */ bool isArray; /* Whether or not the ancestors of this node has arrays */ bool hasArrayAncestors; } UpdateSetValueState; /* * Common State for $pull update operator based on the updateSpec */ typedef struct BsonUpdateDollarPullState { /* Compiled expression for $pull spec of a field */ ExprEvalState *evalState; /* * This would be true if $pull spec is a non-doc value or doc value without Expression * e.g.: {a: 2} or {a: {b: 2}} */ bool isValue; } BsonUpdateDollarPullState; /* Declare a writer type for writing responses * This abstracts tracking the modified value and building the changestream spec. */ typedef struct UpdateOperatorWriter UpdateOperatorWriter; typedef struct UpdateArrayWriter UpdateArrayWriter; /* These work similar to element writer functions except they track whether * there was any modifications */ void UpdateWriterWriteModifiedValue(UpdateOperatorWriter *writer, const bson_value_t *value); void UpdateWriterSkipValue(UpdateOperatorWriter *writer); /* UpdateWriter functions for update operators that modify arrays. here the operator * is responsible for writing original values, and modified values into the array * and finalizing it similar to the array-writer interface. */ UpdateArrayWriter * UpdateWriterGetArrayWriter(UpdateOperatorWriter *writer); void UpdateArrayWriterWriteOriginalValue(UpdateArrayWriter *writer, const bson_value_t *value); void UpdateArrayWriterWriteModifiedValue(UpdateArrayWriter *writer, const bson_value_t *value); void UpdateArrayWriterSkipValue(UpdateArrayWriter *writer); void UpdateArrayWriterFinalize(UpdateOperatorWriter *writer, UpdateArrayWriter *arrayWriter); /* operators */ void HandleUpdateDollarSet(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarInc(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarMin(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarMax(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarUnset(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarMul(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarBit(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarCurrentDate(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarRenameSource(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarRename(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarSetOnInsert(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarAddToSet(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarPullAll(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarPush(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarPop(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); void HandleUpdateDollarPull(const bson_value_t *existingValue, UpdateOperatorWriter *writer, const bson_value_t *updateValue, void *updateNodeContext, const UpdateSetValueState *setValueState, const CurrentDocumentState *state); #endif documentdb-0.108-0/pg_documentdb/include/users.h000066400000000000000000000025561507310017400215600ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/users.h * * User CRUD functions. * *------------------------------------------------------------------------- */ #ifndef EXTENSION_USERS_H #define EXTENSION_USERS_H #include "postgres.h" #include "utils/string_view.h" enum DocumentDB_BuiltInRoles { DocumentDB_Role_Read_AnyDatabase = 0x1, DocumentDB_Role_ReadWrite_AnyDatabase = 0x2, DocumentDB_Role_Cluster_Admin = 0x4, }; typedef struct { /* "createUser" field */ const char *createUser; /* "pwd" field */ const char *pwd; /* "roles" field */ bson_value_t roles; /* "identityProvider" field*/ bson_value_t identityProviderData; /* pgRole the passed in role maps to */ char *pgRole; /* principalType */ char *principalType; /* has_identity_provider */ bool has_identity_provider; } CreateUserSpec; typedef struct { /* "updateUser" field */ const char *updateUser; /* "pwd" field */ const char *pwd; } UpdateUserSpec; typedef struct { StringView user; bool showPrivileges; } GetUserSpec; /* * Hash entry structure for user roles. */ typedef struct UserRoleHashEntry { char *user; HTAB *roles; bool isExternal; } UserRoleHashEntry; /* Method to call Connection Status command */ Datum connection_status(pgbson *showPrivilegesSpec); #endif documentdb-0.108-0/pg_documentdb/include/utils/000077500000000000000000000000001507310017400213765ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/utils/data_table_utils.h000066400000000000000000000010301507310017400250410ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/data_table_utils.h * * Utilities for mongo feature usage tracking. * *------------------------------------------------------------------------- */ #ifndef DATA_TABLE_UTILS_H #define DATA_TABLE_UTILS_H ArrayType * GetCollectionIds(void); ArrayType * GetCollectionIdsStartingFrom(uint64 startCollectionId); void AlterCreationTime(void); #endif /* DATA_TABLE_UTILS_H */ documentdb-0.108-0/pg_documentdb/include/utils/feature_counter.h000066400000000000000000000311351507310017400247440ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/feature_counter.h * * Utilities for feature usage tracking. * *------------------------------------------------------------------------- */ #ifndef FEATURE_COUNTER_H #define FEATURE_COUNTER_H #if PG_VERSION_NUM >= 170000 #include #else #include #endif #include #define MAX_FEATURE_NAME_LENGTH 255 #define MAX_FEATURE_COUNT 331 /* Internal features that are not exposed */ #define INTERNAL_FEATURE_TYPE MAX_FEATURE_COUNT /* * IMP: Keep this alphabetically sorted while adding new feature types. Sorting is done for better reability. * #CodeSync: Keep this in sync with FeatureMapping array in feature_counter.c * For each FeatureType enum a FeatureMapping entry should exist. * * Make sure that we don't exceed MAX_FEATURE_COUNT * * Do not use MAX_FEATURE_INDEX and ensure it is the last entry. */ typedef enum { /* Feature counter region - Aggregation operators */ FEATURE_AGG_OPERATOR_ABS, FEATURE_AGG_OPERATOR_ACCUMULATOR, FEATURE_AGG_OPERATOR_ACOS, FEATURE_AGG_OPERATOR_ACOSH, FEATURE_AGG_OPERATOR_ADD, FEATURE_AGG_OPERATOR_ADDTOSET, FEATURE_AGG_OPERATOR_ALLELEMENTSTRUE, FEATURE_AGG_OPERATOR_AND, FEATURE_AGG_OPERATOR_ANYELEMENTTRUE, FEATURE_AGG_OPERATOR_ARRAYELEMAT, FEATURE_AGG_OPERATOR_ARRAYTOOBJECT, FEATURE_AGG_OPERATOR_ASIN, FEATURE_AGG_OPERATOR_ASINH, FEATURE_AGG_OPERATOR_ATAN, FEATURE_AGG_OPERATOR_ATAN2, FEATURE_AGG_OPERATOR_ATANH, FEATURE_AGG_OPERATOR_AVG, FEATURE_AGG_OPERATOR_BINARYSIZE, FEATURE_AGG_OPERATOR_BITAND, FEATURE_AGG_OPERATOR_BITNOT, FEATURE_AGG_OPERATOR_BITOR, FEATURE_AGG_OPERATOR_BITXOR, FEATURE_AGG_OPERATOR_BSONSIZE, FEATURE_AGG_OPERATOR_CEIL, FEATURE_AGG_OPERATOR_CMP, FEATURE_AGG_OPERATOR_CONCAT, FEATURE_AGG_OPERATOR_CONCATARRAYS, FEATURE_AGG_OPERATOR_COND, FEATURE_AGG_OPERATOR_CONST, FEATURE_AGG_OPERATOR_CONVERT, FEATURE_AGG_OPERATOR_COS, FEATURE_AGG_OPERATOR_COSH, FEATURE_AGG_OPERATOR_DATEADD, FEATURE_AGG_OPERATOR_DATEDIFF, FEATURE_AGG_OPERATOR_DATESUBTRACT, FEATURE_AGG_OPERATOR_DATEFROMPARTS, FEATURE_AGG_OPERATOR_DATEFROMSTRING, FEATURE_AGG_OPERATOR_DATETOPARTS, FEATURE_AGG_OPERATOR_DATETOSTRING, FEATURE_AGG_OPERATOR_DATETRUNC, FEATURE_AGG_OPERATOR_DAYOFMONTH, FEATURE_AGG_OPERATOR_DAYOFWEEK, FEATURE_AGG_OPERATOR_DAYOFYEAR, FEATURE_AGG_OPERATOR_DEGREESTORADIANS, FEATURE_AGG_OPERATOR_DIVIDE, FEATURE_AGG_OPERATOR_EQ, FEATURE_AGG_OPERATOR_EXP, FEATURE_AGG_OPERATOR_FILTER, FEATURE_AGG_OPERATOR_FIRST, FEATURE_AGG_OPERATOR_FIRSTN, FEATURE_AGG_OPERATOR_FLOOR, FEATURE_AGG_OPERATOR_FUNCTION, FEATURE_AGG_OPERATOR_GETFIELD, FEATURE_AGG_OPERATOR_GT, FEATURE_AGG_OPERATOR_GTE, FEATURE_AGG_OPERATOR_HOUR, FEATURE_AGG_OPERATOR_IFNULL, FEATURE_AGG_OPERATOR_IN, FEATURE_AGG_OPERATOR_INDEXOFARRAY, FEATURE_AGG_OPERATOR_INDEXOFBYTES, FEATURE_AGG_OPERATOR_INDEXOFCP, FEATURE_AGG_OPERATOR_ISARRAY, FEATURE_AGG_OPERATOR_ISNUMBER, FEATURE_AGG_OPERATOR_ISODAYOFWEEK, FEATURE_AGG_OPERATOR_ISOWEEK, FEATURE_AGG_OPERATOR_ISOWEEKYEAR, FEATURE_AGG_OPERATOR_LAST, FEATURE_AGG_OPERATOR_LASTN, FEATURE_AGG_OPERATOR_LET, FEATURE_AGG_OPERATOR_LITERAL, FEATURE_AGG_OPERATOR_LN, FEATURE_AGG_OPERATOR_LOG, FEATURE_AGG_OPERATOR_LOG10, FEATURE_AGG_OPERATOR_LT, FEATURE_AGG_OPERATOR_LTE, FEATURE_AGG_OPERATOR_LTRIM, FEATURE_AGG_OPERATOR_MAKE_ARRAY, FEATURE_AGG_OPERATOR_MAP, FEATURE_AGG_OPERATOR_MAX, FEATURE_AGG_OPERATOR_MAXN, FEATURE_AGG_OPERATOR_MERGEOBJECTS, FEATURE_AGG_OPERATOR_META, FEATURE_AGG_OPERATOR_MILLISECOND, FEATURE_AGG_OPERATOR_MIN, FEATURE_AGG_OPERATOR_MINN, FEATURE_AGG_OPERATOR_MINUTE, FEATURE_AGG_OPERATOR_MOD, FEATURE_AGG_OPERATOR_MONTH, FEATURE_AGG_OPERATOR_MULTIPLY, FEATURE_AGG_OPERATOR_NE, FEATURE_AGG_OPERATOR_NOT, FEATURE_AGG_OPERATOR_OBJECTTOARRAY, FEATURE_AGG_OPERATOR_OR, FEATURE_AGG_OPERATOR_POW, FEATURE_AGG_OPERATOR_PUSH, FEATURE_AGG_OPERATOR_RADIANSTODEGREES, FEATURE_AGG_OPERATOR_RAND, FEATURE_AGG_OPERATOR_RANGE, FEATURE_AGG_OPERATOR_REDUCE, FEATURE_AGG_OPERATOR_REGEXFIND, FEATURE_AGG_OPERATOR_REGEXFINDALL, FEATURE_AGG_OPERATOR_REGEXMATCH, FEATURE_AGG_OPERATOR_REPLACEONE, FEATURE_AGG_OPERATOR_REPLACEALL, FEATURE_AGG_OPERATOR_REVERSEARRAY, FEATURE_AGG_OPERATOR_ROUND, FEATURE_AGG_OPERATOR_RTRIM, FEATURE_AGG_OPERATOR_SECOND, FEATURE_AGG_OPERATOR_SETDIFFERENCE, FEATURE_AGG_OPERATOR_SETEQUALS, FEATURE_AGG_OPERATOR_SETFIELD, FEATURE_AGG_OPERATOR_SETINTERSECTION, FEATURE_AGG_OPERATOR_SETISSUBSET, FEATURE_AGG_OPERATOR_SETUNION, FEATURE_AGG_OPERATOR_SIN, FEATURE_AGG_OPERATOR_SINH, FEATURE_AGG_OPERATOR_SIZE, FEATURE_AGG_OPERATOR_SLICE, FEATURE_AGG_OPERATOR_SORTARRAY, FEATURE_AGG_OPERATOR_SPLIT, FEATURE_AGG_OPERATOR_SQRT, FEATURE_AGG_OPERATOR_STDDEVPOP, FEATURE_AGG_OPERATOR_STDDEVSAMP, FEATURE_AGG_OPERATOR_STRLENBYTES, FEATURE_AGG_OPERATOR_STRLENCP, FEATURE_AGG_OPERATOR_STRCASECMP, FEATURE_AGG_OPERATOR_SUBSTR, FEATURE_AGG_OPERATOR_SUBSTRBYTES, FEATURE_AGG_OPERATOR_SUBSTRCP, FEATURE_AGG_OPERATOR_SUBTRACT, FEATURE_AGG_OPERATOR_SUM, FEATURE_AGG_OPERATOR_SWITCH, FEATURE_AGG_OPERATOR_TAN, FEATURE_AGG_OPERATOR_TANH, FEATURE_AGG_OPERATOR_TOBOOL, FEATURE_AGG_OPERATOR_TODATE, FEATURE_AGG_OPERATOR_TODECIMAL, FEATURE_AGG_OPERATOR_TODOUBLE, FEATURE_AGG_OPERATOR_TOHASHEDINDEXKEY, FEATURE_AGG_OPERATOR_TOINT, FEATURE_AGG_OPERATOR_TOLONG, FEATURE_AGG_OPERATOR_TOLOWER, FEATURE_AGG_OPERATOR_TOOBJECTID, FEATURE_AGG_OPERATOR_TOSTRING, FEATURE_AGG_OPERATOR_TOUPPER, FEATURE_AGG_OPERATOR_TOUUID, FEATURE_AGG_OPERATOR_TRIM, FEATURE_AGG_OPERATOR_TRUNC, FEATURE_AGG_OPERATOR_TSINCREMENT, FEATURE_AGG_OPERATOR_TSSECOND, FEATURE_AGG_OPERATOR_TYPE, FEATURE_AGG_OPERATOR_UNSETFIELD, FEATURE_AGG_OPERATOR_WEEK, FEATURE_AGG_OPERATOR_YEAR, FEATURE_AGG_OPERATOR_ZIP, FEATURE_COLLATION, /* Feature counter region - Commands */ FEATURE_COMMAND_AGG_CURSOR_FIRST_PAGE, FEATURE_COMMAND_COLLMOD, FEATURE_COMMAND_COLLSTATS, FEATURE_COMMAND_COMPACT, FEATURE_COMMAND_COUNT, FEATURE_COMMAND_CREATE_COLLECTION, FEATURE_COMMAND_CREATE_VALIDATION, FEATURE_COMMAND_CREATE_VIEW, FEATURE_COMMAND_CURRENTOP, FEATURE_COMMAND_DBSTATS, FEATURE_COMMAND_DELETE, FEATURE_COMMAND_DISTINCT, FEATURE_COMMAND_FINDANDMODIFY, FEATURE_COMMAND_FIND_CURSOR_FIRST_PAGE, FEATURE_COMMAND_GET_MORE, FEATURE_COMMAND_INSERT, FEATURE_COMMAND_INSERT_ONE, FEATURE_COMMAND_INSERT_100, FEATURE_COMMAND_INSERT_500, FEATURE_COMMAND_INSERT_1000, FEATURE_COMMAND_INSERT_EXTENDED, FEATURE_COMMAND_INSERT_BULK, FEATURE_COMMAND_LIST_COLLECTIONS_CURSOR_FIRST_PAGE, FEATURE_COMMAND_LIST_INDEXES_CURSOR_FIRST_PAGE, FEATURE_COMMAND_RESHARD_COLLECTION, FEATURE_COMMAND_SHARD_COLLECTION, FEATURE_COMMAND_UNSHARD_COLLECTION, FEATURE_COMMAND_UPDATE, FEATURE_COMMAND_UPDATE_ONE, FEATURE_COMMAND_UPDATE_100, FEATURE_COMMAND_UPDATE_500, FEATURE_COMMAND_UPDATE_1000, FEATURE_COMMAND_UPDATE_EXTENDED, FEATURE_COMMAND_UPDATE_BULK, FEATURE_COMMAND_VALIDATE_REPAIR, /* Feature collMod subfeatures */ FEATURE_COMMAND_COLLMOD_VIEW, FEATURE_COMMAND_COLLMOD_COLOCATION, FEATURE_COMMAND_COLLMOD_VALIDATION, FEATURE_COMMAND_COLLMOD_TTL_UPDATE, FEATURE_COMMAND_COLLMOD_INDEX_HIDDEN, /* Feature Connection Status*/ FEATURE_CONNECTION_STATUS, /* Feature counter region - Create index types */ FEATURE_CREATE_INDEX_2D, FEATURE_CREATE_INDEX_2DSPHERE, FEATURE_CREATE_INDEX_ALTERNATE_AM, FEATURE_CREATE_INDEX_COMPOSITE_BASED_TERM, FEATURE_CREATE_INDEX_FTS, FEATURE_CREATE_INDEX_TEXT, FEATURE_CREATE_INDEX_TTL, FEATURE_CREATE_INDEX_UNIQUE, FEATURE_CREATE_INDEX_VECTOR, FEATURE_CREATE_INDEX_VECTOR_COS, FEATURE_CREATE_INDEX_VECTOR_COMPRESSION_HALF, FEATURE_CREATE_INDEX_VECTOR_COMPRESSION_PQ, FEATURE_CREATE_INDEX_VECTOR_IP, FEATURE_CREATE_INDEX_VECTOR_L2, FEATURE_CREATE_INDEX_VECTOR_TYPE_DISKANN, FEATURE_CREATE_INDEX_VECTOR_TYPE_HNSW, FEATURE_CREATE_INDEX_VECTOR_TYPE_IVFFLAT, FEATURE_CREATE_UNIQUE_INDEX_WITH_TERM_TRUNCATION, /* Feature counter region - Cursor types */ FEATURE_CURSOR_TYPE_PERSISTENT, FEATURE_CURSOR_TYPE_POINT_READ, FEATURE_CURSOR_TYPE_SINGLE_BATCH, FEATURE_CURSOR_TYPE_STREAMING, FEATURE_CURSOR_TYPE_TAILABLE, /* Feature mapping region - ExternalIdentityProvider */ FEATURE_EXTERNAL_IDENTITY_USER_CREATE, FEATURE_EXTERNAL_IDENTITY_USER_DROP, FEATURE_EXTERNAL_IDENTITY_USER_AUTHENTICATE, FEATURE_EXTERNAL_IDENTITY_USER_GET, FEATURE_INDEX_AM_PREREGISTERED, FEATURE_INDEX_HINT, /* Feature counter region - let support */ FEATURE_LET_TOP_LEVEL, /* Feature counter region - Query Operators */ FEATURE_QUERY_OPERATOR_ALL, FEATURE_QUERY_OPERATOR_ALWAYSFALSE, FEATURE_QUERY_OPERATOR_ALWAYSTRUE, FEATURE_QUERY_OPERATOR_AND, FEATURE_QUERY_OPERATOR_BITS_ALL_CLEAR, FEATURE_QUERY_OPERATOR_BITS_ALL_SET, FEATURE_QUERY_OPERATOR_BITS_ANY_CLEAR, FEATURE_QUERY_OPERATOR_BITS_ANY_SET, FEATURE_QUERY_OPERATOR_COMMENT, FEATURE_QUERY_OPERATOR_ELEMMATCH, FEATURE_QUERY_OPERATOR_EQ, FEATURE_QUERY_OPERATOR_EXISTS, FEATURE_QUERY_OPERATOR_EXPR, FEATURE_QUERY_OPERATOR_GEOINTERSECTS, FEATURE_QUERY_OPERATOR_GEONEAR, FEATURE_QUERY_OPERATOR_GEOWITHIN, FEATURE_QUERY_OPERATOR_GT, FEATURE_QUERY_OPERATOR_GTE, FEATURE_QUERY_OPERATOR_IN, FEATURE_QUERY_OPERATOR_JSONSCHEMA, FEATURE_QUERY_OPERATOR_LT, FEATURE_QUERY_OPERATOR_LTE, FEATURE_QUERY_OPERATOR_MOD, FEATURE_QUERY_OPERATOR_NE, FEATURE_QUERY_OPERATOR_NEAR, FEATURE_QUERY_OPERATOR_NEARSPHERE, FEATURE_QUERY_OPERATOR_NIN, FEATURE_QUERY_OPERATOR_NOR, FEATURE_QUERY_OPERATOR_NOT, FEATURE_QUERY_OPERATOR_OR, FEATURE_QUERY_OPERATOR_REGEX, FEATURE_QUERY_OPERATOR_SAMPLERATE, FEATURE_QUERY_OPERATOR_SIZE, FEATURE_QUERY_OPERATOR_TEXT, FEATURE_QUERY_OPERATOR_TYPE, /* Feature mapping region - Role CRUD */ FEATURE_ROLE_CREATE, /* Feature counter region - Aggregation stages */ FEATURE_STAGE_ADD_FIELDS, FEATURE_STAGE_CHANGE_STREAM, FEATURE_STAGE_BUCKET, FEATURE_STAGE_BUCKET_AUTO, FEATURE_STAGE_COLLSTATS, FEATURE_STAGE_COUNT, FEATURE_STAGE_CURRENTOP, FEATURE_STAGE_DENSIFY, FEATURE_STAGE_DOCUMENTS, FEATURE_STAGE_FACET, FEATURE_STAGE_FILL, FEATURE_STAGE_GEONEAR, FEATURE_STAGE_GRAPH_LOOKUP, FEATURE_STAGE_GROUP, FEATURE_STAGE_GROUP_ACC_BOTTOMN, FEATURE_STAGE_GROUP_ACC_FIRSTN, FEATURE_STAGE_GROUP_ACC_FIRSTN_GT10, FEATURE_STAGE_GROUP_ACC_LASTN, FEATURE_STAGE_GROUP_ACC_LASTN_GT10, FEATURE_STAGE_GROUP_ACC_MEDIAN, FEATURE_STAGE_GROUP_ACC_PERCENTILE, FEATURE_STAGE_GROUP_ACC_TOPN, FEATURE_STAGE_INDEXSTATS, FEATURE_STAGE_INTERNAL_INHIBIT_OPTIMIZATION, FEATURE_STAGE_INVERSEMATCH, FEATURE_STAGE_LIMIT, FEATURE_STAGE_LOOKUP, FEATURE_STAGE_MATCH, FEATURE_STAGE_MERGE, FEATURE_STAGE_OUT, FEATURE_STAGE_PROJECT, FEATURE_STAGE_PROJECT_FIND, FEATURE_STAGE_REDACT, FEATURE_STAGE_REPLACE_ROOT, FEATURE_STAGE_REPLACE_WITH, FEATURE_STAGE_SAMPLE, FEATURE_STAGE_SEARCH, FEATURE_STAGE_SEARCH_VECTOR, FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_HALF, FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_PQ, FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_NPROBES, FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_EFSEARCH, FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_LSEARCH, FEATURE_STAGE_SEARCH_VECTOR_DISKANN, FEATURE_STAGE_SEARCH_VECTOR_EXACT, FEATURE_STAGE_SEARCH_VECTOR_GEN_EMBEDDINGS, FEATURE_STAGE_SEARCH_VECTOR_HNSW, FEATURE_STAGE_SEARCH_VECTOR_IVFFLAT, FEATURE_STAGE_SEARCH_VECTOR_PRE_FILTER, FEATURE_STAGE_SET, FEATURE_STAGE_SETWINDOWFIELDS, FEATURE_STAGE_SKIP, FEATURE_STAGE_SORT, FEATURE_STAGE_SORT_BY_COUNT, FEATURE_STAGE_SORT_BY_ID, FEATURE_STAGE_UNIONWITH, FEATURE_STAGE_UNSET, FEATURE_STAGE_UNWIND, FEATURE_STAGE_VECTOR_SEARCH_KNN, FEATURE_STAGE_VECTOR_SEARCH_NATIVE, /* Feature counter region - Update operators */ FEATURE_UPDATE_OPERATOR_GEN_EMBEDDINGS, /* Feature usage stats */ FEATURE_USAGE_TTL_PURGER_CALLS, FEATURE_USAGE_INDEX_SCAN_WITH_LIMIT, /* Feature mapping region - User CRUD*/ FEATURE_USER_CREATE, FEATURE_USER_DROP, FEATURE_USER_GET, FEATURE_USER_UPDATE, /* This value must appear at the end in the FeatureType definition. */ MAX_FEATURE_INDEX } FeatureType; typedef int FeatureCounter[MAX_FEATURE_COUNT]; extern Size SharedFeatureCounterShmemSize(void); extern void SharedFeatureCounterShmemInit(void); extern const char * GetFeatureCountersAsString(void); extern void ResetFeatureCounters(void); extern FeatureCounter *FeatureCounterBackendArray; /* * Given a feature id this method increments the feature usage count for the * feature for the current backend process. * * Postgres guarantees that MyBackendId is always between 1 and MaxBackend. */ static inline void ReportFeatureUsage(int featureId) { pg_write_barrier(); #if PG_VERSION_NUM >= 170000 FeatureCounterBackendArray[MyProcNumber][featureId]++; #else FeatureCounterBackendArray[MyBackendId - 1][featureId]++; #endif } #endif /* FEATURE_COUNTER_H */ documentdb-0.108-0/pg_documentdb/include/utils/guc_utils.h000066400000000000000000000014161507310017400235470ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/guc_utils.h * * Utilities for GUCs (Grand Unified Configuration) * *------------------------------------------------------------------------- */ #ifndef GUC_UTILS_H #define GUC_UTILS_H #include "utils/guc.h" void SetGUCLocally(const char *name, const char *value); /* * Helper function to do an early rollback of a local GUC set with SetGUCLocally function. * Given the GUC level, it rollbacks the GUC change to its previous value in the current transcation. */ static inline void RollbackGUCChange(int savedGUCLevel) { bool commitGUCChanges = false; AtEOXact_GUC(commitGUCChanges, savedGUCLevel); } #endif documentdb-0.108-0/pg_documentdb/include/utils/heap_utils.h000066400000000000000000000025121507310017400237040ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/heap_utils.h * * Utility to maintain min/max heap. * *------------------------------------------------------------------------- */ #include #include #include #include "commands/commands_common.h" #ifndef HEAP_UTILS_H #define HEAP_UTILS_H /** * Defines how the heap is sorted. * For minheap, the comparator should return true if first < second. * For maxheap, the comparator should return true if first > second. */ typedef bool (*HeapComparator)(const void *first, const void *second); /* * binaryheap * heapNodes variable-length array of "space" nodes * bh_size how many nodes are currently in "nodes" * bh_space how many nodes can be stored in "nodes" * heapComparator comparison function to define the heap property */ typedef struct BinaryHeap { bson_value_t *heapNodes; int64_t heapSize; int64_t heapSpace; HeapComparator heapComparator; } BinaryHeap; BinaryHeap * AllocateHeap(int64_t capacity, HeapComparator comparator); void PushToHeap(BinaryHeap *heap, const bson_value_t *value); bson_value_t PopFromHeap(BinaryHeap *heap); bson_value_t TopHeap(BinaryHeap *heap); void FreeHeap(BinaryHeap *heap); #endif documentdb-0.108-0/pg_documentdb/include/utils/index_utils.h000066400000000000000000000006411507310017400240770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/index_utils.h * * Utilities for build/drop index. * *------------------------------------------------------------------------- */ #ifndef INDEX_UTILS_H #define INDEX_UTILS_H void set_indexsafe_procflags(void); void PopAllActiveSnapshots(void); #endif documentdb-0.108-0/pg_documentdb/include/utils/query_utils.h000066400000000000000000000133371507310017400241430ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/query_utils.h * * Utilities to execute a command/query. * *------------------------------------------------------------------------- */ #include #include #include #ifndef QUERY_UTILS_H #define QUERY_UTILS_H /* * Execute a query within the current transaction and return the first datum * of the first tuple returned by given query (if any). * * Rollbacking or aborting the current transaction / subtransaction is * guaranteed to rollback the query that has been executed even if query * execution has been completed already. */ Datum ExtensionExecuteQueryViaSPI(const char *query, bool readOnly, int expectedSPIOK, bool *isNull); void ExtensionExecuteMultiValueQueryViaSPI(const char *query, bool readOnly, int expectedSPIOK, Datum *datums, bool *isNull, int numValues); Datum ExtensionExecuteQueryWithArgsViaSPI(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, bool readOnly, int expectedSPIOK, bool *isNull); Datum ExtensionExecuteCappedQueryWithArgsViaSPI(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, bool readOnly, int expectedSPIOK, bool *isNull, int statementTimeout, int lockTimeout); void ExtensionExecuteMultiValueQueryWithArgsViaSPI(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, bool readOnly, int expectedSPIOK, Datum *datums, bool *isNull, int numValues); uint64 ExtensionExecuteCappedStatementWithArgsViaSPI(const char *query, int nargs, Oid *argTypes, Datum *argValues, char *argNulls, bool readOnly, int expectedSPIOK, int statementTimeout, int lockTimeout); /* * Execute a query outside the current transaction and return the first * attribute of the first tuple returned by given query (if any). * * After the execution of given query completes, it cannot be rollbacked even * if current transaction / subtransaction rollbacks or aborts. * * Otherwise, i.e.: if this function didn't return yet, then there is still * a chance to cancel the query when rollbacking or aborting the current the * transaction / subtransaction since the abort handlers in * TransactionCallback & SubTransactionCallback will then try * cancelling the query. However, it is still not guaranteed that given query * will be rollbacked. This is because; * i) The transaction that we started over the libpq connection might got * committed already, i.e.: remote transaction is not active anymore. * ii) Theoretically, connection establishment to localhost might still fail * while trying to send the cancellation. * * [1] Why can using a libpq connection might cause an undetectable deadlock ? * (Please keep in mind that "s" means "session" and "r" means "resource" * in this scenario.) * * Suppose that s1 acquired r1 and waits for r2, and s2 acquired r2 and * waits for r1. In that case, postgres would throw an error telling that * those two sessions entered into a deadlock. Or, if those resources belong * to different Citus nodes (coordinator / MX worker), then Citus would * report this as a "distributed deadlock" instead of postgres. * * And now let's consider another scenario. Suppose that s1 acquired r1 * and the libpq connection (initiated via ExtensionExecuteQueryOnLocalhostViaLibPQ()) * that s1 is waiting for is waiting for r2, and s2 acquired r2 and it * waits for r1. Here, s2 waits for s1 to release a resource, and s1 waits * for the libpq to finish its IO; and that libpq connection is waiting for * s2 to release a resource. Given the wait-triangle here, one could expect * postgres or Citus to detect this as a deadlock condition where three * processes involved; but this is not the case. This is because, postgres * doesn't take the connection-IO waits into the account (even if they are * local) when detecting deadlock conditions and such a scenario would cause * those processes to wait for each other indefinitely. For this reason, callers * should be careful about such cases when using ExtensionExecuteQueryViaLibPQ() * instead of ExtensionExecuteQueryViaSPI() or such. */ char * ExtensionExecuteQueryOnLocalhostViaLibPQ(char *query); /* * Same as ExtensionExecuteQueryOnLocalhostViaLibPQ, but connects as specific user. */ char * ExtensionExecuteQueryAsUserOnLocalhostViaLibPQ(char *query, const Oid userOid, bool useSerialExecution); /* Same as ExtensionExecuteQueryAsUserOnLocalhostViaLibPQ, but it allows to execute parameterized query */ char * ExtensionExecuteQueryWithArgsAsUserOnLocalhostViaLibPQ(char *query, const Oid userOid, int nParams, Oid *paramTypes, const char **parameterValues); /* * Helper method to create a string query using a variable number * of arguments - similar to doing * StringInfo s = makeStringInfo(); * appendStringInfo(s, "queryFormat", args); * return s->data; */ pg_attribute_printf(1, 2) inline static const char * FormatSqlQuery(const char *queryFormat, ...) { StringInfoData cmdbuf; initStringInfo(&cmdbuf); for (;;) { va_list args; int needed; va_start(args, queryFormat); needed = appendStringInfoVA(&cmdbuf, queryFormat, args); va_end(args); if (needed == 0) { break; /* success */ } enlargeStringInfo(&cmdbuf, needed); } return cmdbuf.data; } #endif documentdb-0.108-0/pg_documentdb/include/utils/role_utils.h000066400000000000000000000031711507310017400237320ustar00rootroot00000000000000#ifndef ROLE_UTILS_H #define ROLE_UTILS_H #include "postgres.h" #include "fmgr.h" /* Macro to check if a role is a system role */ #define IS_SYSTEM_ROLE(roleName) \ (strcmp((roleName), ApiBgWorkerRole) == 0) /* Macro to check if a role is a customer facing built-in role */ #define IS_BUILTIN_ROLE(roleName) \ (strcmp((roleName), ApiAdminRoleV2) == 0 || \ strcmp((roleName), ApiReadOnlyRole) == 0 || \ strcmp((roleName), ApiReadWriteRole) == 0 || \ strcmp((roleName), ApiRootRole) == 0 || \ strcmp((roleName), ApiUserAdminRole) == 0) /* * Privilege stores a privilege and its actions. */ typedef struct { const char *db; const char *collection; bool isCluster; size_t numActions; const StringView *actions; } Privilege; /* * ConsolidatedPrivilege contains the db, collection, isCluster, and actions of a privilege. */ typedef struct { const char *db; const char *collection; bool isCluster; HTAB *actions; } ConsolidatedPrivilege; /* Function to write a single role's privileges to a BSON array writer */ void WriteSingleRolePrivileges(const char *roleName, pgbson_array_writer *privilegesArrayWriter); /* Function to write multiple roles' privileges from an HTAB to a BSON array writer*/ void WriteMultipleRolePrivileges(HTAB *rolesTable, pgbson_array_writer *privilegesArrayWriter); /* Function to check if a given role name contains any reserved pg role name prefixes. */ bool ContainsReservedPgRoleNamePrefix(const char *name); /* Function to build a List of parent role names from an array of Datums */ List * ConvertUserOrRoleNamesDatumToList(Datum *parentRolesDatums, int parentRolesCount); #endif documentdb-0.108-0/pg_documentdb/include/utils/sort_utils.h000066400000000000000000000046731507310017400237700ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/sort_utils.h * * Utilities to execute a sort. * *------------------------------------------------------------------------- */ #include #include "io/bson_core.h" #ifndef SORT_UTILS_H #define SORT_UTILS_H /* * Sort direction * it is for $sort modifier in $push update operator * or sortBy specification in $sortArray operator */ typedef enum SortDirection { SortDirection_Ascending, SortDirection_Descending, } SortDirection; /** * Defines the Sort type needed for Sort Context * 1) SortType_No_Sort: no sort required, * 2) SortType_ObjectFieldSort: sort is required on specific field paths e.g: { $sort: {'a.b': 1, 'b.c': -1}} * or { $sortBy: {'a.b': 1, 'b.c': -1}} * 3) SortType_WholeElementSort: sort on element or type e.g: {$sort : -1} / {$sort : 1} * or {$sortBy : -1} / {$sortBy : 1} * */ typedef enum SortType { SortType_No_Sort, SortType_ObjectFieldSort, SortType_WholeElementSort, } SortType; /** * This is used by the push operator's sort stage or $sortArray operator, * 1) sortType * 2) SortDirection: Represents the direction in case of SortType_WholeElementSort * 3) sortSpecHead: Head referrence to sort spec list in case of SortType_ObjectFieldSort * */ typedef struct SortContext { List *sortSpecList; SortDirection sortDirection; SortType sortType; const char *collationString; } SortContext; /* * A structure holding the bson_value_t and the index for sort comparator * * "index" is used to perform well order sort similar to Mongo protocol * in case when sorting is needed on object specific fields */ typedef struct ElementWithIndex { bson_value_t bsonValue; uint32_t index; } ElementWithIndex; /* * A structure to hold the data for $sort spec of $push operator, * or sortBy in $sortArray operator * It holds the key and the sort direction * */ typedef struct SortSpecData { const char *key; SortDirection direction; } SortSpecData; int CompareBsonValuesForSort(const void *a, const void *b, void *args); void ValidateSortSpecAndSetSortContext(bson_value_t sortBsonValue, SortContext *sortContext); ElementWithIndex * GetElementWithIndex(const bson_value_t *val, uint32_t index); void UpdateElementWithIndex(const bson_value_t *val, uint32_t index, ElementWithIndex *element); #endif documentdb-0.108-0/pg_documentdb/include/utils/storage_utils.h000066400000000000000000000017071507310017400244400ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/storage_utils.h * * Utilities that provide physical storage related metrics and information. * *------------------------------------------------------------------------- */ #include #include #ifndef DOCDB_STORAGE_UTILS_H #define DOCDB_STORAGE_UTILS_H #define BYTES_PER_MB (double) (1024 * 1024) typedef struct CollectionBloatStats { /* Whether the PG stats are available or not for the collection */ bool nullStats; /* Estimated bloats storage consumed by dead tuples for the colleciton in bytes based on PG relation's stats */ uint64 estimatedBloatStorage; /* Estimated total collection size based on PG relation's stats */ uint64 estimatedTableStorage; } CollectionBloatStats; CollectionBloatStats GetCollectionBloatEstimate(uint64 collectionId); #endif documentdb-0.108-0/pg_documentdb/include/utils/version_utils.h000066400000000000000000000014501507310017400244540ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/version_utils.h * * Utilities that Provide extension functions to handle version upgrade * scenarios. * *------------------------------------------------------------------------- */ #include #ifndef VERSION_UTILS_H #define VERSION_UTILS_H typedef enum DocumentsMajorVersion { DocDB_V0 = 0, } MajorVersion; bool IsClusterVersionAtleast(MajorVersion major, int minor, int patch); bool IsClusterVersionAtLeastPatch(MajorVersion major, int minor, int patch); void InvalidateVersionCache(void); void InitializeVersionCache(void); Size VersionCacheShmemSize(void); bool IsVersionRefreshQueryString(const char *queryString); #endif documentdb-0.108-0/pg_documentdb/include/utils/version_utils_private.h000066400000000000000000000020151507310017400262040ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/utils/version_utils.h * * Utilities that Provide extension functions to handle version upgrade * scenarios. * *------------------------------------------------------------------------- */ #include #include "utils/version_utils.h" #ifndef VERSION_UTILS_PRIVATE_H #define VERSION_UTILS_PRIVATE_H /* * The current Extensions' version. * Note Extension versions are of the form * .- */ typedef struct ExtensionVersion { /* The major version of the extension */ int Major; /* The minor version of the extension */ int Minor; /* The patch version of the extension */ int Patch; } ExtensionVersion; const char * GetCurrentVersionForLogging(void); const char * GetCurrentShortVersionStringForLogging(void); bool IsExtensionVersionAtleast(ExtensionVersion extVersion, MajorVersion major, int minor, int patch); #endif documentdb-0.108-0/pg_documentdb/include/vector/000077500000000000000000000000001507310017400215405ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/include/vector/bson_extract_vector.h000066400000000000000000000002531507310017400257660ustar00rootroot00000000000000#ifndef VECTOR_EXTRACT__H #define VECTOR_EXTRACT__H #include Datum command_bson_extract_vector_base(pgbson *document, char *pathStr, bool *isNull); #endif documentdb-0.108-0/pg_documentdb/include/vector/vector_common.h000066400000000000000000000054001507310017400245620ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/vector/vector_common.h * * Common definitions for vector indexes. * *------------------------------------------------------------------------- */ #ifndef VECTOR_COMMON__H #define VECTOR_COMMON__H /* pgvector VECTOR_MAX_DIM: 16000 */ /* dimensions for type vector cannot exceed 16000 */ #define VECTOR_MAX_DIMENSIONS 16000 #define VECTOR_MAX_DIMENSIONS_NON_COMPRESSED 2000 #define VECTOR_MAX_DIMENSIONS_HALF_COMPRESSED 4000 #define VECTOR_MAX_DIMENSIONS_PQ_COMPRESSED VECTOR_MAX_DIMENSIONS /* ivfflat parameters */ #define IVFFLAT_DEFAULT_NPROBES 1 #define IVFFLAT_MIN_NPROBES 1 #define IVFFLAT_MAX_NPROBES 32768 #define IVFFLAT_DEFAULT_LISTS 100 #define IVFFLAT_MIN_LISTS 1 #define IVFFLAT_MAX_LISTS 32768 #define VECTOR_PARAMETER_NAME_IVF_NPROBES "nProbes" #define VECTOR_PARAMETER_NAME_IVF_NPROBES_STR_LEN 7 #define VECTOR_PARAMETER_NAME_IVF_NLISTS "numLists" /* hnsw parameters */ #define HNSW_DEFAULT_M 16 #define HNSW_MIN_M 2 #define HNSW_MAX_M 100 #define HNSW_DEFAULT_EF_CONSTRUCTION 64 #define HNSW_MIN_EF_CONSTRUCTION 4 #define HNSW_MAX_EF_CONSTRUCTION 1000 #define HNSW_DEFAULT_EF_SEARCH 40 #define HNSW_MIN_EF_SEARCH 1 #define HNSW_MAX_EF_SEARCH 1000 #define VECTOR_PARAMETER_NAME_HNSW_M "m" #define VECTOR_PARAMETER_NAME_HNSW_EF_CONSTRUCTION "efConstruction" #define VECTOR_PARAMETER_NAME_HNSW_EF_SEARCH "efSearch" #define VECTOR_PARAMETER_NAME_HNSW_EF_SEARCH_STR_LEN 8 /* Search parameter name for iterative scan mode */ #define VECTOR_PARAMETER_NAME_ITERATIVE_SCAN "iterativeScan" #define VECTOR_PARAMETER_NAME_ITERATIVE_SCAN_STR_LEN 13 /* dynamic calculation of nprobes or efSearch depending on collection size */ #define VECTOR_SEARCH_SMALL_COLLECTION_ROWS 10000 /* metadata field names */ #define VECTOR_METADATA_FIELD_NAME "__cosmos_meta__" #define VECTOR_METADATA_FIELD_NAME_STR_LEN 15 #define VECTOR_METADATA_SCORE_FIELD_NAME "score" #define VECTOR_METADATA_SCORE_FIELD_NAME_STR_LEN 5 /* * ApiGucPrefix.enableVectorHNSWIndex GUC determines vector indexes * and queries are enabled in documentdb_api or not. */ extern bool EnableVectorHNSWIndex; /* * GUC to enable vector pre-filtering feature for vector search. * This is disabled by default. */ extern bool EnableVectorPreFilter; extern bool EnableVectorPreFilterV2; /* * GUC to set the iterative scan mode for pre-filtering */ extern int VectorPreFilterIterativeScanMode; /* * GUC to enable vector compression feature for vector search. */ extern bool EnableVectorCompressionHalf; extern bool EnableVectorCompressionPQ; /* * GUC to enable vector search default search parameter calculation. */ extern bool EnableVectorCalculateDefaultSearchParameter; #endif documentdb-0.108-0/pg_documentdb/include/vector/vector_configs.h000066400000000000000000000021061507310017400247220ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/vector/vector_configs.h * * Vector index configuration * *------------------------------------------------------------------------- */ #ifndef VECTOR_CONFIGS__H #define VECTOR_CONFIGS__H /* Possible iterative scan modes for pre-filtering */ typedef enum VectorIterativeScanMode { VectorIterativeScan_OFF = 0, /* Relaxed allows results to be slightly out of order by distance, but provides better recall */ VectorIterativeScan_RELAXED_ORDER = 1, /* Strict ensures results are in the exact order by distance * * During the iterative scan, if an out-of-order vector is fetched, it will be ignored and continue to get next. * This usually happens between different iterations(e.g. number of efSearch vectors as an iteration) of the index scan. * The strict order skips the "right" vector to keep results in order, which may result in lower recall. */ VectorIterativeScan_STRICT_ORDER = 2 } VectorIterativeScanMode; #endif documentdb-0.108-0/pg_documentdb/include/vector/vector_planner.h000066400000000000000000000013161507310017400247330ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/vector/vector_planner.h * * Function declarations for vector index used in planner and custom scan. * *------------------------------------------------------------------------- */ #ifndef VECTOR_PLANNER__H #define VECTOR_PLANNER__H #include #include #include "io/bson_core.h" #include "vector/vector_utilities.h" pgbson * CalculateSearchParamBsonForIndexPath(IndexPath *vectorSearchPath, pgbson *searchParamBson); void SetSearchParametersToGUC(Oid vectorAccessMethodOid, pgbson *searchParamBson); #endif documentdb-0.108-0/pg_documentdb/include/vector/vector_spec.h000066400000000000000000000136131507310017400242310ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/vector/vector_spec.h * * Common definitions for vector indexes. * *------------------------------------------------------------------------- */ #ifndef VECTOR_SPEC__H #define VECTOR_SPEC__H #include #include #include "io/bson_core.h" typedef struct VectorIndexDefinition VectorIndexDefinition; /* * The distance metric for a vector based index. */ typedef enum VectorIndexDistanceMetric { VectorIndexDistanceMetric_Unknown = 0, /* Use basic linear vector distance */ VectorIndexDistanceMetric_L2Distance = 1, /* Use vector inner product distance */ VectorIndexDistanceMetric_IPDistance = 2, /* Use inner product cosine distance. */ VectorIndexDistanceMetric_CosineDistance = 3, } VectorIndexDistanceMetric; /* * The compression type for a vector index. */ typedef enum VectorIndexCompressionType { /* Use no compression */ VectorIndexCompressionType_None = 0, /* Use half precision compression */ VectorIndexCompressionType_Half = 1, /* Use product quantization */ VectorIndexCompressionType_PQ = 2, /* Use binary quantization */ VectorIndexCompressionType_BQ = 3, } VectorIndexCompressionType; /* * Options associated with vector based Cosmos Search indexes */ typedef struct VectorIndexCommonOptions { /* The type of distance for the vector distance */ VectorIndexDistanceMetric distanceMetric; /* The type of compression for the vector index */ VectorIndexCompressionType compressionType; /* The number of dimensions of the vector */ int32_t numDimensions; } VectorIndexCommonOptions; /* * Options for a vector index that specifies the kind of index. */ typedef struct VectorKindSpecifiedOptions { } VectorKindSpecifiedOptions; /* * Index options specific to cosmosSearchOptions * for vector and text search support. */ typedef struct { /* The raw pgbson for the cosmosSearchOptions. */ pgbson *searchOptionsDoc; /* The index kind for the cosmosSearch index. */ const char *indexKindStr; /* Options for a vector search */ VectorIndexCommonOptions commonOptions; VectorKindSpecifiedOptions *vectorOptions; } CosmosSearchOptions; typedef struct VectorSearchOptions { /* it's the query spec pgbson that we pass to the bson_extract_vector() method to get the float[] vector. */ pgbson *searchSpecPgbson; /* the bson value for the query vector */ bson_value_t queryVectorValue; /* the length of the query vector */ int32_t queryVectorLength; /* search path*/ char *searchPath; /* query result count */ int32_t resultCount; /* search param pgbson e.g. {"efSearch": 10} or {"nProbes": 10} */ pgbson *searchParamPgbson; /* filter bson */ bson_value_t filterBson; /* score bson */ bson_value_t scoreBson; /* The vector access method oid */ Oid vectorAccessMethodOid; /* whether to use exact search or ann search */ bool exactSearch; /* The vector index definition */ const VectorIndexDefinition *vectorIndexDef; /* Over sample rate */ double oversampling; /* The compression type of the vector index */ VectorIndexCompressionType compressionType; /* The type of distance for the vector distance */ VectorIndexDistanceMetric distanceMetric; } VectorSearchOptions; /* * Function pointers for parsing and validating * vector index creation specs on coordinator. */ typedef void (*ParseIndexCreationSpecFunc)(bson_iter_t *indexDefDocIter, CosmosSearchOptions *cosmosSearchOptions); typedef char * (*GenerateIndexParamStringFunc)(const CosmosSearchOptions *cosmosSearchOptions); /* * Function pointers for parsing and validating * vector index search specs on coordinator. */ typedef pgbson *(*ParseIndexSearchSpecFunc)(const VectorSearchOptions *vectorSearchOptions); /* * Function pointers for planner and custom scan */ typedef Oid (*GetIndexAccessMethodOidFunc)(void); /* * Function pointers for setting search parameters to GUC on worker. */ typedef void (*SetSearchParametersToGUCFunc)(const pgbson *searchParamBson); /* * Dynamic calculation of search parameters * based on the number of rows and index options. */ typedef pgbson *(*CalculateSearchParamBsonFunc)(bytea *indexOptions, Cardinality indexRows, pgbson *searchParamBson); /* * Retrieve the type of index compression specified within the provided index options. */ typedef VectorIndexCompressionType (*ExtractIndexCompressionTypeFunc)( bytea *indexOptions); /* * Definition of an extensible vector index. * It contains the function pointers for * 1. Vector index creation * 1.1 Parsing and validating index creation specs. * 1.2 Generating index parameter for the index creation. * 2. Vector search * 2.1 Parsing and validating index search specs. * 2.2 Getting the index access method oid. * 2.3 Getting the similarity operator oid by family oid. * 3. Planner and custom scan * 3.1 Setting search parameters to GUC on worker. * 3.2 Getting the default search parameter bson. * 3.3 Calculating search parameter based on the number of rows and index options. */ typedef struct VectorIndexDefinition { const char *kindName; const char *indexAccessMethodName; ParseIndexCreationSpecFunc parseIndexCreationSpecFunc; GenerateIndexParamStringFunc generateIndexParamStrFunc; ParseIndexSearchSpecFunc parseIndexSearchSpecFunc; GetIndexAccessMethodOidFunc getIndexAccessMethodOidFunc; SetSearchParametersToGUCFunc setSearchParametersToGUCFunc; CalculateSearchParamBsonFunc calculateSearchParamBsonFunc; ExtractIndexCompressionTypeFunc extractIndexCompressionTypeFunc; } VectorIndexDefinition; const VectorIndexDefinition * GetVectorIndexDefinitionByIndexAmOid(Oid indexAmOid); const VectorIndexDefinition * GetVectorIndexDefinitionByIndexKindName( StringView *indexKindStr); void RegisterVectorIndexExtension(const VectorIndexDefinition *extensibleDefinition); #endif documentdb-0.108-0/pg_documentdb/include/vector/vector_utilities.h000066400000000000000000000030551507310017400253110ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * include/vector/vector_utilities.h * * Utility functions for computing vector scores * *------------------------------------------------------------------------- */ #ifndef VECTOR_UTILITIES__H #define VECTOR_UTILITIES__H #include #include #include "vector/vector_spec.h" #include "vector/vector_configs.h" /* * Type that holds data needed for * computing scores vector returned from * a vector search query. This is used to * move required data across nodes via * CustomScan. */ typedef struct SearchQueryEvalData { /* This contains the bson value of the search parameter, * like { "nProbes": 4 } */ Datum SearchParamBson; /* The access method oid of the vector index * ivfflat/hnsw */ Oid VectorAccessMethodOid; } SearchQueryEvalData; double EvaluateMetaSearchScore(pgbson *document); char * GenerateVectorIndexExprStr(const char *keyPath, const CosmosSearchOptions *searchOptions); Expr * GenerateVectorSortExpr(VectorSearchOptions *vectorSearchOptions, FuncExpr *vectorCastFunc, Relation indexRelation, Node *documentExpr, Node *vectorQuerySpecNode); bool IsMatchingVectorIndex(Relation indexRelation, const char *queryVectorPath, FuncExpr **vectorExtractorFunc); Oid GetFullVectorOperatorId(VectorIndexDistanceMetric distanceMetric); bool IsHalfVectorCastFunction(FuncExpr *vectorCastFunc); bool IsPgvectorHalfVectorAvailable(void); #endif documentdb-0.108-0/pg_documentdb/sql/000077500000000000000000000000001507310017400174125ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/documentdb--0.100-0--0.101-0.sql000066400000000000000000000001641507310017400237750ustar00rootroot00000000000000 #include "udfs/commands_diagnostic/current_op--0.101-0.sql" #include "udfs/projection/bson_projection--0.101-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.101-0--0.102-0.sql000066400000000000000000000030141507310017400237740ustar00rootroot00000000000000#include "udfs/metadata/list_databases--0.102-0.sql" #include "udfs/ttl/ttl_support_functions--0.102-0.sql" #include "udfs/commands_diagnostic/current_op--0.102-0.sql" #include "udfs/query/bson_query_match--0.102-0.sql" #include "udfs/projection/bson_projection--0.102-0.sql" #include "udfs/aggregation/bson_aggregation_redact--0.102-0.sql" #include "udfs/aggregation/bson_merge_functions--0.102-0.sql" #include "udfs/aggregation/group_aggregates_support--0.102-0.sql" #include "udfs/aggregation/group_aggregates--0.102-0.sql" #include "types/bsonindexbounds--0.102-0.sql" #include "udfs/index_mgmt/bson_indexbounds_functions--0.102-0.sql" #include "operators/bson_btree_pfe_operators--0.102-0.sql" #include "operators/bsonindexbounds_btree_pfe_family--0.102-0.sql" -- Schedule TTL Cron job to prune TTL indexes on every documentdb instance. DO LANGUAGE plpgsql $cmd$ BEGIN IF NOT EXISTS(SELECT 1 FROM cron.job where jobname = 'documentdb_ttl_task') THEN PERFORM cron.schedule('documentdb_ttl_task', '* * * * *', $$CALL documentdb_api_internal.delete_expired_rows();$$); END IF; END; $cmd$; DROP AGGREGATE IF EXISTS __API_CATALOG_SCHEMA__.BSON_OUT(__CORE_SCHEMA__.bson, text, text, text, text); DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_out_transition; DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_out_final; -- ALTER creation_time column for all the documentdb tables #include "udfs/schema_mgmt/data_table_upgrade--0.102-0.sql" SELECT __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(0, 102, 0); documentdb-0.108-0/pg_documentdb/sql/documentdb--0.102-0--0.102-1.sql000066400000000000000000000041571507310017400240070ustar00rootroot00000000000000-- this release repeats what's deployed between 0.101 and 0.102, -- but handles the case where a partial upgrade may have happened to 0.102 -- due to a specific concern raised for this release as a one-off. -- repeat all the UDF upgrades for 102 #include "udfs/metadata/list_databases--0.102-0.sql" #include "udfs/ttl/ttl_support_functions--0.102-0.sql" #include "udfs/commands_diagnostic/current_op--0.102-0.sql" #include "udfs/query/bson_query_match--0.102-0.sql" #include "udfs/projection/bson_projection--0.102-0.sql" #include "udfs/aggregation/bson_aggregation_redact--0.102-0.sql" #include "udfs/aggregation/bson_merge_functions--0.102-0.sql" #include "udfs/aggregation/group_aggregates_support--0.102-0.sql" #include "udfs/aggregation/group_aggregates--0.102-0.sql" #include "udfs/schema_mgmt/data_table_upgrade--0.102-0.sql" -- Schedule TTL Cron job to prune TTL indexes on every documentdb instance (This is idempotent and will not create duplicates) DO LANGUAGE plpgsql $cmd$ BEGIN IF NOT EXISTS(SELECT 1 FROM cron.job where jobname = 'documentdb_ttl_task') THEN PERFORM cron.schedule('documentdb_ttl_task', '* * * * *', $$CALL documentdb_api_internal.delete_expired_rows();$$); END IF; END; $cmd$; -- drop the aggregates for $out. These are unused anyway and idempotent DROP AGGREGATE IF EXISTS __API_CATALOG_SCHEMA__.BSON_OUT(__CORE_SCHEMA__.bson, text, text, text, text); DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_out_transition; DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_out_final; -- ALTER creation_time column for all the documentdb tables SELECT __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(0, 102, 1); -- now handle the upgrade for bsonindexbounds DO LANGUAGE plpgsql $cmd$ BEGIN IF NOT EXISTS(SELECT 1 FROM pg_type where typname = 'bsonindexbounds' AND typnamespace = 'documentdb_api_internal'::regnamespace) THEN #include "types/bsonindexbounds--0.102-0.sql" #include "udfs/index_mgmt/bson_indexbounds_functions--0.102-0.sql" #include "operators/bson_btree_pfe_operators--0.102-0.sql" #include "operators/bsonindexbounds_btree_pfe_family--0.102-0.sql" END IF; END; $cmd$;documentdb-0.108-0/pg_documentdb/sql/documentdb--0.102-1--0.103-0.sql000066400000000000000000000004341507310017400240020ustar00rootroot00000000000000#include "udfs/rum/composite_path_operator_functions--0.103-0.sql" #include "schema/composite_path_operator_class--0.103-0.sql" #include "udfs/projection/bson_expression--0.103-0.sql" #include "udfs/commands_crud/insert--0.103-0.sql" #include "udfs/commands_crud/update--0.103-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.103-0--0.104-0.sql000066400000000000000000000016211507310017400240020ustar00rootroot00000000000000#include "udfs/query/bson_orderby--0.104-0.sql" #include "operators/bson_orderby_operators--0.104-0.sql" #include "operators/bson_btree_orderby_operators_family--0.104-0.sql" #include "schema/bson_orderby_hash_operator_class--0.104-0.sql" #include "udfs/projection/bson_projection--0.104-0.sql" #include "udfs/index_mgmt/create_index_background--0.104-0.sql" #include "udfs/schema_mgmt/compact--0.104-0.sql" #include "udfs/schema_mgmt/cursor_support--0.104-0.sql" -- Schedule the index build task DO LANGUAGE plpgsql $cmd$ BEGIN PERFORM __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(); END; $cmd$; DO LANGUAGE plpgsql $cmd$ BEGIN IF NOT EXISTS(SELECT 1 FROM cron.job where jobname = 'documentdb_cursor_cleanup_task') THEN PERFORM cron.schedule('documentdb_cursor_cleanup_task', '* * * * *', $$CALL documentdb_api_internal.cursor_directory_cleanup();$$); END IF; END; $cmd$; documentdb-0.108-0/pg_documentdb/sql/documentdb--0.104-0--0.104-1.sql000066400000000000000000000004501507310017400240030ustar00rootroot00000000000000 #include "udfs/query/bson_dollar_comparison--0.104-1.sql" -- update the job to use the correct syntax. SELECT cron.alter_job( (SELECT jobid FROM cron.job WHERE jobname = 'documentdb_cursor_cleanup_task' LIMIT 1), command => 'SELECT documentdb_api_internal.cursor_directory_cleanup();');documentdb-0.108-0/pg_documentdb/sql/documentdb--0.104-1--0.105-0.sql000066400000000000000000000003471507310017400240110ustar00rootroot00000000000000 #include "udfs/aggregation/bson_bucket_auto--0.105-0.sql" #include "udfs/commands_crud/bson_update_document--0.105-0.sql" #include "udfs/schema_mgmt/cursor_support--0.105-0.sql" #include "udfs/users/connection_status--0.105-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.105-0--0.106-0.sql000066400000000000000000000015221507310017400240060ustar00rootroot00000000000000#include "udfs/commands_crud/bson_update_document--0.106-0.sql" #include "udfs/ttl/delete_expired_rows_background--0.106-0.sql" #include "udfs/index_mgmt/build_index_background--0.106-0.sql" #include "schema/setup_background_worker_role--0.106-0.sql" #include "operators/bson_dollar_operators--0.106-0.sql" #include "udfs/index_mgmt/bson_rum_ordering_functions--0.106-0.sql" #include "udfs/metadata/collection--0.106-0.sql" #include "udfs/metadata/empty_data_table--0.106-0.sql" #include "udfs/roles/create_role--0.106-0.sql" #include "udfs/roles/drop_role--0.106-0.sql" #include "udfs/roles/roles_info--0.106-0.sql" #include "udfs/roles/update_role--0.106-0.sql" #include "udfs/aggregation/group_aggregates_support--0.106-0.sql" #include "udfs/aggregation/group_aggregates--0.106-0.sql" #include "udfs/query/bson_dollar_index_hints--0.106-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.106-0--0.107-0.sql000066400000000000000000000005001507310017400240030ustar00rootroot00000000000000 #include "udfs/query/bson_orderby_sort_support--0.107-0.sql" #include "operators/bson_btree_orderby_operators_family--0.107-0.sql" #include "udfs/query/bson_orderby_reverse--0.107-0.sql" #include "operators/bson_dollar_operators--0.107-0.sql" #include "udfs/index_mgmt/bson_rum_index_transform_functions--0.107-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.107-0--0.108-0.sql000066400000000000000000000034661507310017400240230ustar00rootroot00000000000000#include "udfs/commands_crud/bson_update_document--0.108-0.sql" #include "udfs/index_mgmt/create_index_background--0.108-0.sql" #include "udfs/rum/bson_rum_text_path_adapter_funcs--0.24-0.sql" #include "udfs/commands_crud/command_node_worker--0.108-0.sql" GRANT UPDATE (indisvalid) ON pg_catalog.pg_index to __API_ADMIN_ROLE__; -- update operator restrict function for $range. ALTER OPERATOR __API_CATALOG_SCHEMA__.@<>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL__.bson_dollar_selectivity); -- if there's existing installations that were created before 0.108 we need to update the operator class to not depend on rum directly. DO LANGUAGE plpgsql $cmd$ DECLARE text_ops_op_family oid; BEGIN SELECT opf.oid INTO text_ops_op_family FROM pg_opfamily opf JOIN pg_namespace pgn ON opf.opfnamespace = pgn.oid where opf.opfname = 'bson_rum_text_path_ops' AND pgn.nspname = 'documentdb_api_catalog'; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_extract_tsquery'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 3; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_tsquery_consistent'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 4; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_tsvector_config'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 6; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_tsquery_pre_consistent'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 7; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_tsquery_distance'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 8; UPDATE pg_amproc SET amproc = 'documentdb_api_internal.rum_ts_join_pos'::regproc WHERE amprocfamily = text_ops_op_family AND amprocnum = 10; END; $cmd$; documentdb-0.108-0/pg_documentdb/sql/documentdb--0.24-0--0.100-0.sql000066400000000000000000000001151507310017400237150ustar00rootroot00000000000000/* * Region: Authentication */ #include "udfs/auth/auth_scram--0.100-0.sql"documentdb-0.108-0/pg_documentdb/sql/documentdb--0.24-0.sql000066400000000000000000000202751507310017400230600ustar00rootroot00000000000000 CREATE SCHEMA documentdb_api; CREATE SCHEMA documentdb_api_internal; CREATE SCHEMA documentdb_api_catalog; CREATE SCHEMA documentdb_data; /* total sql files: 125 */ /* udfs files: 84 */ /* operators files: 17 */ /* schema files: 21 */ /* rbac files: 3 */ /* * Region: Query functions */ #include "udfs/query/bson_query_match--0.14-0.sql" #include "udfs/query/bson_dollar_comparison--0.23-0.sql" #include "udfs/query/bsonquery_dollar_operators--0.10-0.sql" #include "udfs/query/bson_dollar_array--0.10-0.sql" #include "udfs/query/bson_dollar_element_bitwise--0.10-0.sql" #include "udfs/query/bson_dollar_evaluation--0.19-0.sql" #include "udfs/query/bson_orderby--0.19-0.sql" #include "udfs/query/bson_dollar_text--0.24-0.sql" #include "udfs/projection/bson_projection--0.24-0.sql" #include "udfs/projection/bson_expression--0.22-0.sql" #include "udfs/query/bson_dollar_selectivity--0.16-0.sql" #include "udfs/query/bson_dollar_negation--0.16-0.sql" #include "udfs/query/bson_value_functions--0.21-0.sql" /* * Region: Query operators */ #include "operators/bson_query_operators--0.10-0.sql" #include "operators/bson_partial_filter_operators--0.10-0.sql" #include "operators/bsonquery_dollar_operators--0.10-0.sql" #include "operators/bsonquery_btree_family--0.10-0.sql" /* * Region: geospatial */ #include "udfs/aggregation/bson_geonear_functions--0.18-0.sql" #include "udfs/query/bson_dollar_geospatial--0.10-0.sql" #include "operators/bson_geospatial_operators--0.16-0.sql" #include "operators/bson_geospatial_operators--0.18-0.sql" #include "udfs/geospatial/bson_gist_extensibility_functions--0.16-0.sql" #include "operators/bson_gist_geospatial_op_classes--0.16-0.sql" #include "operators/bson_gist_geospatial_op_classes_members--0.16-0.sql" #include "operators/bson_gist_geospatial_op_classes_members--0.18-0.sql" /* * Region: Shard key and document */ #include "schema/shard_key_and_document--0.10-0.sql" #include "udfs/rum/bson_preconsistent--0.11-0.sql" #include "udfs/rum/bson_rum_exclusion_functions--0.23-0.sql" #include "operators/shard_key_and_document_operators--0.23-0.sql" /* * Region: RUM operators and functions */ #include "udfs/rum/bson_rum_shard_exclusion_functions--0.24-0.sql" #include "operators/bson_unique_shard_path_operators--0.24-0.sql" #include "operators/bson_path_operators--0.10-0.sql" #include "operators/bson_path_operators--0.23-0.sql" #include "operators/bson_path_operators--0.24-0.sql" #include "operators/bson_dollar_operators--0.16-0.sql" #include "operators/bson_dollar_negation_operators--0.16-0.sql" #include "udfs/rum/handler--0.10-0.sql" #include "schema/rum_access_method--0.10-0.sql" #include "schema/unique_shard_path_operator_class--0.24-0.sql" #include "schema/bson_rum_exclusion_operator_class--0.23-0.sql" #include "operators/bson_dollar_text_operators--0.24-0.sql" #include "udfs/rum/bson_rum_text_path_funcs--0.24-0.sql" #include "udfs/rum/bson_rum_text_path_adapter_funcs--0.24-0.sql" #include "schema/bson_rum_text_path_ops--0.24-0.sql" #include "udfs/rum/extensibility_functions--0.10-0.sql" #include "udfs/rum/single_path_extensibility_functions--0.10-0.sql" #include "schema/single_path_operator_class--0.10-0.sql" #include "udfs/rum/wildcard_project_path_extensibility_functions--0.12-0.sql" #include "schema/wildcard_project_path_operator_class--0.12-0.sql" #include "udfs/rum/bson_rum_hashed_ops_functions--0.23-0.sql" #include "schema/bson_hash_operator_class--0.23-0.sql" #include "schema/index_operator_classes_negation--0.16-0.sql" #include "schema/index_operator_classes_range--0.23-0.sql" /* * Region: Aggregation operators. */ #include "udfs/aggregation/bson_aggregation_support--0.10-0.sql" #include "udfs/aggregation/bson_aggregation_pipeline--0.10-0.sql" #include "udfs/aggregation/bson_aggregation_find--0.10-0.sql" #include "udfs/aggregation/bson_aggregation_count--0.10-0.sql" #include "udfs/aggregation/bson_aggregation_distinct--0.10-0.sql" #include "udfs/aggregation/window_aggregate_support--0.22-0.sql" #include "udfs/aggregation/window_aggregates--0.22-0.sql" #include "udfs/aggregation/group_aggregates_support--0.24-0.sql" #include "udfs/aggregation/group_aggregates--0.24-0.sql" #include "udfs/aggregation/bson_unwind_functions--0.10-0.sql" #include "udfs/aggregation/bson_lookup_functions--0.23-0.sql" #include "udfs/aggregation/distinct_aggregates--0.10-0.sql" #include "udfs/aggregation/bson_coercion_compat--0.24-0.sql" #include "udfs/aggregation/bson_densify_functions--0.22-0.sql" #include "udfs/aggregation/bson_inverse_match--0.16-0.sql" #include "udfs/aggregation/bson_merge_functions--0.20-0.sql" #include "udfs/metadata/empty_data_table--0.16-0.sql" #include "udfs/metadata/collection--0.10-0.sql" #include "udfs/aggregation/bson_aggregation_redact--0.24-0.sql" /* * Region: Collection Metadata */ #include "udfs/metadata/collection_metadata_functions--0.23-0.sql" #include "udfs/metadata/collection_triggers--0.21-0.sql" #include "schema/collection_metadata--0.10-0.sql" #include "schema/collection_metadata--0.21-0.sql" #include "schema/collection_metadata--0.23-0.sql" #include "schema/collection_metadata_views--0.10-0.sql" #include "schema/collection_metadata_schemavalidation--0.10-0.sql" #include "udfs/metadata/collection_indexes_metadata_functions--0.10-0.sql" #include "schema/collection_indexes_metadata--0.10-0.sql" #include "schema/collection_indexes_metadata--0.23-0.sql" /* * Region: Sharding Metadata */ #include "udfs/metadata/sharding_metadata_functions--0.10-0.sql" /* * Region: Schema Management APIs */ #include "udfs/schema_mgmt/create_collection--0.12-0.sql" #include "udfs/schema_mgmt/shard_collection--0.24-0.sql" #include "udfs/schema_mgmt/coll_mod--0.12-0.sql" #include "udfs/schema_mgmt/create_collection_view--0.12-0.sql" #include "udfs/schema_mgmt/drop_collection--0.12-0.sql" #include "udfs/schema_mgmt/drop_database--0.13-0.sql" #include "udfs/schema_mgmt/rename_collection--0.15-0.sql" /* * Region: Index Manangement APIs */ #include "udfs/index_mgmt/create_indexes_non_concurrently--0.21-0.sql" #include "udfs/index_mgmt/create_builtin_id_index--0.10-0.sql" #include "udfs/index_mgmt/record_id_index--0.10-0.sql" #include "udfs/index_mgmt/index_build_is_in_progress--0.10-0.sql" #include "udfs/index_mgmt/index_spec_as_bson--0.10-0.sql" #include "udfs/index_mgmt/index_spec_options_are_equivalent--0.10-0.sql" #include "udfs/index_mgmt/create_index_background--0.23-0.sql" #include "udfs/index_mgmt/drop_indexes--0.12-0.sql" /* * Region: Basic CRUD APIs & Commands */ #include "udfs/commands_crud/insert--0.16-0.sql" #include "udfs/commands_crud/insert_one_helper--0.12-0.sql" #include "udfs/commands_crud/bson_update_document--0.10-0.sql" #include "udfs/commands_crud/update--0.16-0.sql" #include "udfs/commands_crud/delete--0.16-0.sql" #include "udfs/commands_crud/find_and_modify--0.12-0.sql" #include "udfs/commands_crud/query_cursors_aggregate--0.12-0.sql" #include "udfs/commands_crud/query_cursors_single_page--0.10-0.sql" #include "udfs/commands_crud/cursor_functions--0.16-0.sql" /* * Region: user management APIs */ #include "udfs/users/create_user--0.19-0.sql" #include "udfs/users/drop_user--0.19-0.sql" #include "udfs/users/update_user--0.19-0.sql" #include "udfs/users/users_info--0.19-0.sql" /* * Region: schema validation APIs */ #include "udfs/schema_validation/schema_validation--0.24-0.sql" /* * Region: Telemetry APIs */ #include "udfs/telemetry/command_feature_counter--0.24-0.sql" /* * Region: TTL APIs */ #include "udfs/ttl/ttl_support_functions--0.24-0.sql" /* * Region: vector search APIs */ #include "udfs/vector/bson_extract_vector--0.24-0.sql" /* * Region: Extension Version APIs */ #include "udfs/utils/extension_version_utils--0.11-0.sql" /* * Region: Diagnostic APIs */ #include "udfs/commands_diagnostic/coll_stats--0.16-0.sql" #include "udfs/commands_diagnostic/db_stats--0.24-0.sql" #include "udfs/commands_diagnostic/index_stats--0.24-0.sql" #include "udfs/commands_diagnostic/validate--0.24-0.sql" /* * Region: RBAC Metadata */ #include "rbac/extension_admin_setup--0.10-0.sql" #include "rbac/extension_admin_setup--0.16-0.sql" #include "rbac/extension_readonly_setup--0.17-1.sql" /* * Region: Background Index Schema */ #include "schema/background_index_queue--0.11-0.sql" #include "schema/background_index_queue--0.14-0.sql" documentdb-0.108-0/pg_documentdb/sql/operators/000077500000000000000000000000001507310017400214305ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/operators/bson_btree_orderby_operators_family--0.104-0.sql000066400000000000000000000012641507310017400323350ustar00rootroot00000000000000CREATE OPERATOR FAMILY __API_SCHEMA_INTERNAL_V2__.bson_btree_orderby_operators_family USING btree; CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare_ops FOR TYPE __CORE_SCHEMA__.bson USING btree FAMILY __API_SCHEMA_INTERNAL_V2__.bson_btree_orderby_operators_family AS OPERATOR 1 __API_SCHEMA_INTERNAL_V2__.<<< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 3 __API_SCHEMA_INTERNAL_V2__.=== (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 5 __API_SCHEMA_INTERNAL_V2__.>>> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson);documentdb-0.108-0/pg_documentdb/sql/operators/bson_btree_orderby_operators_family--0.107-0.sql000066400000000000000000000003211507310017400323310ustar00rootroot00000000000000ALTER OPERATOR FAMILY __API_SCHEMA_INTERNAL_V2__.bson_btree_orderby_operators_family USING btree ADD FUNCTION 2 (__CORE_SCHEMA__.bson)__API_SCHEMA_INTERNAL_V2__.bson_orderby_compare_sort_support(internal);documentdb-0.108-0/pg_documentdb/sql/operators/bson_btree_pfe_operators--0.102-0.sql000066400000000000000000000040301507310017400300700ustar00rootroot00000000000000CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.##= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_eq ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.##> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_gt ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.##>= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_gte ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.##< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_lt ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.##<= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_lte ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.< ( LEFTARG = __CORE_SCHEMA__.bsonquery, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bsonquery_lt ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.<= ( LEFTARG = __CORE_SCHEMA__.bsonquery, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bsonquery_lte ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.> ( LEFTARG = __CORE_SCHEMA__.bsonquery, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bsonquery_gt ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.>= ( LEFTARG = __CORE_SCHEMA__.bsonquery, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bsonquery_gte ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.= ( LEFTARG = __CORE_SCHEMA__.bsonquery, RIGHTARG = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bsonquery_eq );documentdb-0.108-0/pg_documentdb/sql/operators/bson_dollar_negation_operators--0.16-0.sql000066400000000000000000000017771507310017400312410ustar00rootroot00000000000000 CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.@!> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gt, RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.@!>= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gte, RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.@!< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lt, RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity ); CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.@!<= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lte, RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity );documentdb-0.108-0/pg_documentdb/sql/operators/bson_dollar_operators--0.106-0.sql000066400000000000000000000002601507310017400274170ustar00rootroot00000000000000 CREATE OPERATOR __API_CATALOG_SCHEMA__.|-<> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_orderby ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_dollar_operators--0.107-0.sql000066400000000000000000000003001507310017400274130ustar00rootroot00000000000000 CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.<>-| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_orderby_reverse ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_dollar_operators--0.16-0.sql000066400000000000000000000072311507310017400273440ustar00rootroot00000000000000ALTER OPERATOR __API_CATALOG_SCHEMA__.@=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@!=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@<(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@<=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@>=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@*=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@!*=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@~(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@%(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@?(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@@#(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@#(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@&=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@#?(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@!&(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@!|(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@&(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.@|(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.#=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.#>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.#>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.#< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity); ALTER OPERATOR __API_CATALOG_SCHEMA__.#<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery) SET (RESTRICT = __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity);documentdb-0.108-0/pg_documentdb/sql/operators/bson_dollar_text_operators--0.24-0.sql000066400000000000000000000003421507310017400304030ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.@#% ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = tsquery, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_text_tsquery, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity );documentdb-0.108-0/pg_documentdb/sql/operators/bson_geospatial_operators--0.16-0.sql000066400000000000000000000012401507310017400302110ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.@|-| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_geowithin, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@|#| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_geointersects, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.<|-|> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_geonear_distance ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_geospatial_operators--0.18-0.sql000066400000000000000000000003041507310017400302130ustar00rootroot00000000000000CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.@|><| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_geonear_within_range ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_gist_geospatial_op_classes--0.16-0.sql000066400000000000000000000066161507310017400313700ustar00rootroot00000000000000-- This is a bson type operator class wrapper around `__POSTGIS_SCHEMA_NAME__.gist_geometry_ops_2d` which is implemented for 2d geometries, -- This operator class has following updates: -- i) This works for `bson` type instead of `geometry` -- ii) `compress` support function is changed to support extracting geometries and then converting them to `box2df` -- iii) This also has `options` support which takes care of storing documentdb 2d index options and validating them e.g. bounds CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_gist_geometry_ops_2d FOR TYPE __CORE_SCHEMA__.bson USING GIST AS OPERATOR 23 __API_CATALOG_SCHEMA__.@|-| , FUNCTION 1 __API_CATALOG_SCHEMA__.bson_gist_geometry_consistent_2d (internal, __CORE_SCHEMA__.bson, integer), FUNCTION 2 __POSTGIS_SCHEMA_NAME__.geometry_gist_union_2d (bytea, internal), FUNCTION 3 __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_compress (internal), FUNCTION 4 __POSTGIS_SCHEMA_NAME__.geometry_gist_decompress_2d (internal), FUNCTION 5 __POSTGIS_SCHEMA_NAME__.geometry_gist_penalty_2d (internal, internal, internal), FUNCTION 6 __POSTGIS_SCHEMA_NAME__.geometry_gist_picksplit_2d (internal, internal), FUNCTION 7 __POSTGIS_SCHEMA_NAME__.geometry_gist_same_2d (geom1 __POSTGIS_SCHEMA_NAME__.geometry, geom2 __POSTGIS_SCHEMA_NAME__.geometry, internal), FUNCTION 8 __API_CATALOG_SCHEMA__.bson_gist_geometry_distance_2d (internal, __CORE_SCHEMA__.bson, integer), FUNCTION 10 (__CORE_SCHEMA__.bson) __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_options(internal), STORAGE __POSTGIS_SCHEMA_NAME__.box2df; -- This is a bson type operator class wrapper around `__POSTGIS_SCHEMA_NAME__.gist_geography_ops` which is implemented for geographies, -- i) `compress` support function is changed to support extracting geographies and then converting them to `gidx` for storage -- ii) This also has `options` support which takes care of storing documentdb 2dsphere index options CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_gist_geography_ops_2d FOR TYPE __CORE_SCHEMA__.bson USING GIST AS OPERATOR 23 __API_CATALOG_SCHEMA__.@|-| , OPERATOR 24 __API_CATALOG_SCHEMA__.@|#| , FUNCTION 1 __API_CATALOG_SCHEMA__.bson_gist_geography_consistent (internal, __CORE_SCHEMA__.bson, integer), FUNCTION 2 __POSTGIS_SCHEMA_NAME__.geography_gist_union (bytea, internal), FUNCTION 3 __API_CATALOG_SCHEMA__.bson_gist_geography_compress (internal), FUNCTION 4 __POSTGIS_SCHEMA_NAME__.geography_gist_decompress (internal), FUNCTION 5 __POSTGIS_SCHEMA_NAME__.geography_gist_penalty (internal, internal, internal), FUNCTION 6 __POSTGIS_SCHEMA_NAME__.geography_gist_picksplit (internal, internal), FUNCTION 7 __POSTGIS_SCHEMA_NAME__.geography_gist_same (__POSTGIS_SCHEMA_NAME__.box2d,__POSTGIS_SCHEMA_NAME__.box2d, internal), FUNCTION 8 __API_CATALOG_SCHEMA__.bson_gist_geography_distance (internal, __CORE_SCHEMA__.bson, integer), FUNCTION 10 (__CORE_SCHEMA__.bson)__API_CATALOG_SCHEMA__.bson_gist_geography_options(internal), STORAGE __POSTGIS_SCHEMA_NAME__.gidx;documentdb-0.108-0/pg_documentdb/sql/operators/bson_gist_geospatial_op_classes_members--0.16-0.sql000066400000000000000000000007271507310017400330770ustar00rootroot00000000000000-- add the distance function to index support for $geoNear ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geometry_ops_2d USING gist ADD OPERATOR 25 __API_CATALOG_SCHEMA__.<|-|>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) FOR ORDER BY pg_catalog.float_ops; ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geography_ops_2d USING gist ADD OPERATOR 25 __API_CATALOG_SCHEMA__.<|-|>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) FOR ORDER BY pg_catalog.float_ops;documentdb-0.108-0/pg_documentdb/sql/operators/bson_gist_geospatial_op_classes_members--0.18-0.sql000066400000000000000000000023541507310017400330770ustar00rootroot00000000000000-- Drop the existing $geoNear operator and update the index strategy to be consistent with strategy defined in opclass/bson_gin_common.h ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geometry_ops_2d USING gist DROP OPERATOR 25 (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geography_ops_2d USING gist DROP OPERATOR 25 (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geometry_ops_2d USING gist ADD OPERATOR 30 __API_CATALOG_SCHEMA__.<|-|>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) FOR ORDER BY pg_catalog.float_ops; ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geography_ops_2d USING gist ADD OPERATOR 30 __API_CATALOG_SCHEMA__.<|-|>(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) FOR ORDER BY pg_catalog.float_ops; -- Add the range operator to the index support for $geoNear ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geometry_ops_2d USING gist ADD OPERATOR 31 __API_SCHEMA_INTERNAL_V2__.@|><|(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_gist_geography_ops_2d USING gist ADD OPERATOR 31 __API_SCHEMA_INTERNAL_V2__.@|><|(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); documentdb-0.108-0/pg_documentdb/sql/operators/bson_orderby_operators--0.104-0.sql000066400000000000000000000017021507310017400276100ustar00rootroot00000000000000-- These are the BSON ordering comparison operators that support collation. -- Used for ordering BSON values in ascending order CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.<<< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_orderby_lt, COMMUTATOR = OPERATOR(__API_SCHEMA_INTERNAL_V2__.>>>) ); -- Used for equality comparison of BSON values CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.=== ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_orderby_eq, COMMUTATOR = OPERATOR(__API_SCHEMA_INTERNAL_V2__.===) ); -- Used for ordering BSON values in descending order CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.>>> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_orderby_gt, COMMUTATOR = OPERATOR(__API_SCHEMA_INTERNAL_V2__.<<<) );documentdb-0.108-0/pg_documentdb/sql/operators/bson_partial_filter_operators--0.10-0.sql000066400000000000000000000020401507310017400310530ustar00rootroot00000000000000 -- these are runtime operators for specific functions that are compatible -- with partial filter expressions. For more details see comments on -- bson_partial_filter_btree_ops. CREATE OPERATOR __API_CATALOG_SCHEMA__.#= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_eq ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gt ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#>= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gte ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lt ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#<= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lte ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_path_operators--0.10-0.sql000066400000000000000000000115221507310017400270130ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.@= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_eq, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity, NEGATOR = OPERATOR(__API_CATALOG_SCHEMA__.@!=) ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@!= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_ne, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity, NEGATOR = OPERATOR(__API_CATALOG_SCHEMA__.@=) ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lt, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@<= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lte, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gt, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@>= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gte, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@*= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_in, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity, NEGATOR = OPERATOR(__API_CATALOG_SCHEMA__.@!*=) ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@!*= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_nin, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity, NEGATOR = OPERATOR(__API_CATALOG_SCHEMA__.@*=) ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@~ ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_regex, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@% ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_mod, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@? ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_exists, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@@# ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_size, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@# ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_type, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@&= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_all, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@#? ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_elemmatch, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@!& ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_bits_all_clear, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@!| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_bits_any_clear, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@& ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_bits_all_set, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.@| ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_bits_any_set, RESTRICT = __CORE_SCHEMA__.bson_operator_selectivity ); CREATE OPERATOR __API_CATALOG_SCHEMA__.=?= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __CORE_SCHEMA__.bson_unique_index_equal, COMMUTATOR = OPERATOR(__API_CATALOG_SCHEMA__.=?=) ); documentdb-0.108-0/pg_documentdb/sql/operators/bson_path_operators--0.23-0.sql000066400000000000000000000002651507310017400270210ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.@<> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_dollar_range );documentdb-0.108-0/pg_documentdb/sql/operators/bson_path_operators--0.24-0.sql000066400000000000000000000005221507310017400270160ustar00rootroot00000000000000DROP OPERATOR IF EXISTS __API_CATALOG_SCHEMA__.=?=(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); CREATE OPERATOR __API_CATALOG_SCHEMA__.=?= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_unique_index_equal, COMMUTATOR = OPERATOR(__API_CATALOG_SCHEMA__.=?=) );documentdb-0.108-0/pg_documentdb/sql/operators/bson_query_operators--0.10-0.sql000066400000000000000000000002571507310017400272270ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.@@ ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_CATALOG_SCHEMA__.bson_query_match );documentdb-0.108-0/pg_documentdb/sql/operators/bson_unique_shard_path_operators--0.24-0.sql000066400000000000000000000003771507310017400315750ustar00rootroot00000000000000CREATE OPERATOR __API_SCHEMA_INTERNAL_V2__.=#= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bson, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_unique_shard_path_equal, COMMUTATOR = OPERATOR(__API_SCHEMA_INTERNAL_V2__.=#=) );documentdb-0.108-0/pg_documentdb/sql/operators/bsonindexbounds_btree_pfe_family--0.102-0.sql000066400000000000000000000047161507310017400316110ustar00rootroot00000000000000 CREATE OPERATOR FAMILY __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_pfe_btree_family USING btree; -- This is the comparison clause for predicate proof. CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bsonquery_indexbounds_btree_pfe_compare_ops FOR TYPE __CORE_SCHEMA__.bsonquery USING btree FAMILY __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_pfe_btree_family AS OPERATOR 1 __API_SCHEMA_INTERNAL_V2__.< (__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 2 __API_SCHEMA_INTERNAL_V2__.<= (__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 3 __API_SCHEMA_INTERNAL_V2__.= (__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 4 __API_SCHEMA_INTERNAL_V2__.>= (__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 5 __API_SCHEMA_INTERNAL_V2__.> (__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds); -- This is what's on the index PFE CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bson_btree_pfe_base_ops FOR TYPE __CORE_SCHEMA__.bson USING btree FAMILY __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_pfe_btree_family AS OPERATOR 1 __API_CATALOG_SCHEMA__.#< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 2 __API_CATALOG_SCHEMA__.#<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 3 __API_CATALOG_SCHEMA__.#= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 4 __API_CATALOG_SCHEMA__.#>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 5 __API_CATALOG_SCHEMA__.#> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery); -- This is the query clause that's created CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_btree_pfe_ops FOR TYPE __CORE_SCHEMA__.bson USING btree FAMILY __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_pfe_btree_family AS OPERATOR 1 __API_SCHEMA_INTERNAL_V2__.##< (__CORE_SCHEMA__.bson, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 2 __API_SCHEMA_INTERNAL_V2__.##<= (__CORE_SCHEMA__.bson, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 3 __API_SCHEMA_INTERNAL_V2__.##= (__CORE_SCHEMA__.bson, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 4 __API_SCHEMA_INTERNAL_V2__.##>= (__CORE_SCHEMA__.bson, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds), OPERATOR 5 __API_SCHEMA_INTERNAL_V2__.##> (__CORE_SCHEMA__.bson, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds);documentdb-0.108-0/pg_documentdb/sql/operators/bsonquery_btree_family--0.10-0.sql000066400000000000000000000044111507310017400275100ustar00rootroot00000000000000 CREATE OPERATOR FAMILY __API_CATALOG_SCHEMA__.bsonquery_btree_family USING btree; CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bsonquery_btree_ops DEFAULT FOR TYPE __CORE_SCHEMA__.bsonquery USING btree FAMILY __API_CATALOG_SCHEMA__.bsonquery_btree_family AS OPERATOR 1 __CORE_SCHEMA__.< (__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery), OPERATOR 2 __CORE_SCHEMA__.<= (__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery), OPERATOR 3 __CORE_SCHEMA__.= (__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery), OPERATOR 4 __CORE_SCHEMA__.>= (__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery), OPERATOR 5 __CORE_SCHEMA__.> (__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery), FUNCTION 1 __CORE_SCHEMA__.bsonquery_compare(__CORE_SCHEMA__.bsonquery, __CORE_SCHEMA__.bsonquery); CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bsonquery_bson_btree_ops FOR TYPE __CORE_SCHEMA__.bson USING btree FAMILY __API_CATALOG_SCHEMA__.bsonquery_btree_family AS OPERATOR 1 __API_CATALOG_SCHEMA__.#< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 2 __API_CATALOG_SCHEMA__.#<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 3 __API_CATALOG_SCHEMA__.#= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 4 __API_CATALOG_SCHEMA__.#>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), OPERATOR 5 __API_CATALOG_SCHEMA__.#> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery), FUNCTION 1 __CORE_SCHEMA__.bsonquery_compare(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bsonquery); CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_btree_pfe_ops FOR TYPE __CORE_SCHEMA__.bson USING btree FAMILY __API_CATALOG_SCHEMA__.bsonquery_btree_family AS OPERATOR 1 __API_CATALOG_SCHEMA__.#< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 2 __API_CATALOG_SCHEMA__.#<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 3 __API_CATALOG_SCHEMA__.#= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 4 __API_CATALOG_SCHEMA__.#>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 5 __API_CATALOG_SCHEMA__.#> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __CORE_SCHEMA__.bson_compare(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson);documentdb-0.108-0/pg_documentdb/sql/operators/bsonquery_dollar_operators--0.10-0.sql000066400000000000000000000016071507310017400304250ustar00rootroot00000000000000 CREATE OPERATOR __API_CATALOG_SCHEMA__.#= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bsonquery, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_eq ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#> ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bsonquery, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gt ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#>= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bsonquery, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_gte ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#< ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bsonquery, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lt ); CREATE OPERATOR __API_CATALOG_SCHEMA__.#<= ( LEFTARG = __CORE_SCHEMA__.bson, RIGHTARG = __CORE_SCHEMA__.bsonquery, PROCEDURE = __API_CATALOG_SCHEMA__.bson_dollar_lte );documentdb-0.108-0/pg_documentdb/sql/operators/shard_key_and_document_operators--0.23-0.sql000066400000000000000000000004521507310017400315330ustar00rootroot00000000000000CREATE OPERATOR __API_CATALOG_SCHEMA__.= ( LEFTARG = __API_CATALOG_SCHEMA__.shard_key_and_document, RIGHTARG = __API_CATALOG_SCHEMA__.shard_key_and_document, PROCEDURE = __API_SCHEMA_INTERNAL_V2__.bson_unique_exclusion_index_equal, COMMUTATOR = OPERATOR(__API_CATALOG_SCHEMA__.=) );documentdb-0.108-0/pg_documentdb/sql/rbac/000077500000000000000000000000001507310017400203215ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/rbac/extension_admin_setup--0.10-0.sql000066400000000000000000000024351507310017400262400ustar00rootroot00000000000000DO $do$ BEGIN /* * The role is a system-wide object which is not dropped if the extension * is dropped. Therefore, if __API_SCHEMA__ api is repeatedly created and dropped, * a regular CREATE ROLE would fail since __API_ADMIN_ROLE__ still exists. * We therefore only create the role if it does not exist. */ IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = __SINGLE_QUOTED_STRING__(__API_ADMIN_ROLE__)) THEN CREATE ROLE __API_ADMIN_ROLE__; END IF; END $do$; GRANT SELECT ON TABLE __API_CATALOG_SCHEMA__.collections TO public; GRANT SELECT ON TABLE __API_CATALOG_SCHEMA__.collection_indexes TO public; GRANT USAGE ON SCHEMA __API_CATALOG_SCHEMA__ TO __API_ADMIN_ROLE__; GRANT USAGE ON SCHEMA __API_SCHEMA_INTERNAL__ TO __API_ADMIN_ROLE__; GRANT USAGE ON SCHEMA __API_SCHEMA__ TO __API_ADMIN_ROLE__; GRANT USAGE ON SCHEMA public TO __API_ADMIN_ROLE__; GRANT ALL ON SCHEMA __API_DATA_SCHEMA__ TO __API_ADMIN_ROLE__; GRANT ALL ON TABLE __API_CATALOG_SCHEMA__.collections TO __API_ADMIN_ROLE__; GRANT ALL ON TABLE __API_CATALOG_SCHEMA__.collection_indexes TO __API_ADMIN_ROLE__; GRANT ALL ON SEQUENCE __API_CATALOG_SCHEMA__.collections_collection_id_seq TO __API_ADMIN_ROLE__; GRANT ALL ON SEQUENCE __API_CATALOG_SCHEMA__.collection_indexes_index_id_seq TO __API_ADMIN_ROLE__;documentdb-0.108-0/pg_documentdb/sql/rbac/extension_admin_setup--0.16-0.sql000066400000000000000000000000771507310017400262460ustar00rootroot00000000000000GRANT USAGE ON SCHEMA __CORE_SCHEMA_V2__ TO __API_ADMIN_ROLE__;documentdb-0.108-0/pg_documentdb/sql/rbac/extension_readonly_setup--0.17-1.sql000066400000000000000000000016661507310017400270020ustar00rootroot00000000000000DO $do$ BEGIN /* * The role is a system-wide object which is not dropped if the extension * is dropped. Therefore, if __API_SCHEMA__ api is repeatedly created and dropped, * a regular CREATE ROLE would fail since __API_ADMIN_ROLE__ still exists. * We therefore only create the role if it does not exist. */ IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = __SINGLE_QUOTED_STRING__(__API_READONLY_ROLE__)) THEN CREATE ROLE __API_READONLY_ROLE__; END IF; END $do$; GRANT USAGE ON SCHEMA __API_CATALOG_SCHEMA__ TO __API_READONLY_ROLE__; GRANT USAGE ON SCHEMA __API_SCHEMA_INTERNAL__ TO __API_READONLY_ROLE__; GRANT USAGE ON SCHEMA __API_SCHEMA__ TO __API_READONLY_ROLE__; GRANT USAGE ON SCHEMA __API_DATA_SCHEMA__ TO __API_READONLY_ROLE__; GRANT SELECT ON TABLE __API_CATALOG_SCHEMA__.collections TO __API_READONLY_ROLE__; GRANT SELECT ON TABLE __API_CATALOG_SCHEMA__.collection_indexes TO __API_READONLY_ROLE__;documentdb-0.108-0/pg_documentdb/sql/schema/000077500000000000000000000000001507310017400206525ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/schema/background_index_queue--0.11-0.sql000066400000000000000000000022241507310017400266740ustar00rootroot00000000000000DROP TABLE IF EXISTS __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue); CREATE TABLE __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue) ( index_cmd text not null, cmd_type char CHECK (cmd_type IN ('C', 'R')), -- 'C' for CREATE INDEX and 'R' for REINDEX index_id integer not null, index_cmd_status integer default 1, -- This gets represented as enum IndexCmdStatus in index.h global_pid bigint, start_time timestamp WITH TIME ZONE, collection_id bigint not null, comment __CORE_SCHEMA__.bson, attempt smallint, update_time timestamp with time zone DEFAULT now() ); CREATE INDEX IF NOT EXISTS __EXTENSION_OBJECT__(_index_queue_indexid_cmdtype) on __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue) (index_id, cmd_type); CREATE INDEX IF NOT EXISTS __EXTENSION_OBJECT__(_index_queue_cmdtype_collectionid_cmdstatus) on __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue) (cmd_type, collection_id, index_cmd_status); GRANT SELECT ON TABLE __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue) TO public; GRANT ALL ON TABLE __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_index_queue) TO __API_ADMIN_ROLE__;documentdb-0.108-0/pg_documentdb/sql/schema/background_index_queue--0.14-0.sql000066400000000000000000000024011507310017400266740ustar00rootroot00000000000000DROP TABLE IF EXISTS __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue); CREATE TABLE __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue) ( index_cmd text not null, cmd_type char CHECK (cmd_type IN ('C', 'R')), -- 'C' for CREATE INDEX and 'R' for REINDEX index_id integer not null, index_cmd_status integer default 1, -- This gets represented as enum IndexCmdStatus in index.h global_pid bigint, start_time timestamp WITH TIME ZONE, collection_id bigint not null, comment __CORE_SCHEMA__.bson, attempt smallint, update_time timestamp with time zone DEFAULT now(), user_oid Oid CHECK (user_oid IS NULL OR user_oid != '0'::oid) ); CREATE INDEX IF NOT EXISTS __EXTENSION_OBJECT_V2__(_index_queue_indexid_cmdtype) on __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue) (index_id, cmd_type); CREATE INDEX IF NOT EXISTS __EXTENSION_OBJECT_V2__(_index_queue_cmdtype_collectionid_cmdstatus) on __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue) (cmd_type, collection_id, index_cmd_status); GRANT SELECT ON TABLE __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue) TO public; GRANT ALL ON TABLE __API_CATALOG_SCHEMA_V2__.__EXTENSION_OBJECT_V2__(_index_queue) TO __API_ADMIN_ROLE__;documentdb-0.108-0/pg_documentdb/sql/schema/bson_hash_operator_class--0.23-0.sql000066400000000000000000000017461507310017400272410ustar00rootroot00000000000000CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(_rum_hashed_ops) FOR TYPE __CORE_SCHEMA__.bson USING __EXTENSION_OBJECT__(_rum) AS -- hashed index only supports the equal and in operators OPERATOR 1 __API_CATALOG_SCHEMA__.@=, OPERATOR 6 __API_CATALOG_SCHEMA__.@*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 btint8cmp(int8,int8), FUNCTION 2 __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_value(__CORE_SCHEMA__.bson, internal), FUNCTION 3 __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 11 (__CORE_SCHEMA__.bson) __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_options(internal), STORAGE int8;documentdb-0.108-0/pg_documentdb/sql/schema/bson_orderby_hash_operator_class--0.104-0.sql000066400000000000000000000005571507310017400310460ustar00rootroot00000000000000 CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bson_orderby_hash_ops FOR TYPE __CORE_SCHEMA__.bson USING hash AS OPERATOR 1 __API_SCHEMA_INTERNAL_V2__.=== (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __CORE_SCHEMA__.bson_hash_int4(__CORE_SCHEMA__.bson), FUNCTION 2 __CORE_SCHEMA__.bson_hash_int8(__CORE_SCHEMA__.bson, int8);documentdb-0.108-0/pg_documentdb/sql/schema/bson_rum_exclusion_operator_class--0.23-0.sql000066400000000000000000000025211507310017400312020ustar00rootroot00000000000000-- for Unique indexes, we need to add shard key into the unique index filter -- To ensure that we have these, we pull in the uuid operator class -- similar to the btree_gin extension. CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_rum_exclusion_ops FOR TYPE __API_CATALOG_SCHEMA__.shard_key_and_document USING __EXTENSION_OBJECT__(_rum) AS -- we only add Btree equal (since we don't need to support others for Unique) OPERATOR 3 __API_CATALOG_SCHEMA__.= , FUNCTION 1 uuid_cmp(uuid,uuid), FUNCTION 2 __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_value(__API_CATALOG_SCHEMA__.shard_key_and_document, internal), FUNCTION 3 __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_query(__API_CATALOG_SCHEMA__.shard_key_and_document, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 7 (__API_CATALOG_SCHEMA__.shard_key_and_document) __API_CATALOG_SCHEMA__.gin_bson_exclusion_pre_consistent(internal,smallint,__API_CATALOG_SCHEMA__.shard_key_and_document,int,internal,internal,internal,internal), FUNCTION 11 (__API_CATALOG_SCHEMA__.shard_key_and_document) __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_options(internal), STORAGE uuid;documentdb-0.108-0/pg_documentdb/sql/schema/bson_rum_text_path_ops--0.24-0.sql000066400000000000000000000035211507310017400267540ustar00rootroot00000000000000-- This is a variant of public.rum_tsvector_ops. However, this takes 'bson' as an input so we can hook it up against our -- index selection and handling of array paths etc. We override the extract tsvector where we take the bson, generate the tsvector -- and generate the 'text' terms for the index (just like rum would). The query path remains identical. Note that the terms in the -- index are still text. CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_rum_text_path_ops FOR TYPE __CORE_SCHEMA__.bson using __EXTENSION_OBJECT__(_rum) AS OPERATOR 1 __API_CATALOG_SCHEMA__.@#% (__CORE_SCHEMA__.bson, tsquery), FUNCTION 1 gin_cmp_tslexeme(text, text), FUNCTION 2 __API_SCHEMA_INTERNAL_V2__.rum_bson_single_path_extract_tsvector(__CORE_SCHEMA__.bson,internal,internal,internal,internal), FUNCTION 3 __API_SCHEMA_INTERNAL_V2__.rum_extract_tsquery(tsquery,internal,smallint,internal,internal,internal,internal), FUNCTION 4 __API_SCHEMA_INTERNAL_V2__.rum_tsquery_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal), FUNCTION 5 gin_cmp_prefix(text,text,smallint,internal), FUNCTION 6 __API_SCHEMA_INTERNAL_V2__.rum_tsvector_config(internal), FUNCTION 7 __API_SCHEMA_INTERNAL_V2__.rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal), FUNCTION 8 __API_SCHEMA_INTERNAL_V2__.rum_tsquery_distance(internal,smallint,tsvector,int,internal,internal,internal,internal,internal), FUNCTION 10 __API_SCHEMA_INTERNAL_V2__.rum_ts_join_pos(internal, internal), FUNCTION 11 (__CORE_SCHEMA__.bson) __API_SCHEMA_INTERNAL_V2__.rum_bson_text_path_options(internal), STORAGE text;documentdb-0.108-0/pg_documentdb/sql/schema/collection_indexes_metadata--0.10-0.sql000066400000000000000000000056731507310017400277060ustar00rootroot00000000000000 /* * If you decide making any changes to this "type", consider syncing * - __API_SCHEMA_INTERNAL__.index_spec_as_bson() * - IndexSpec struct defined in index.h * , and make sure to add necessary constraints to index_spec_type "domain". */ CREATE TYPE __API_CATALOG_SCHEMA__.index_spec_type_internal AS ( -- Index name index_name text, -- -- Index options start here -- -- "key" document used when creating the index index_key __CORE_SCHEMA__.bson, -- "partialFilterExpression" document used when creating the index index_pfe __CORE_SCHEMA__.bson, -- Normalized form of "wildcardProjection" document used when creating the index. -- "null" if the index doesn't have a "wildcardProjection" specification. index_wp __CORE_SCHEMA__.bson, -- indicates if the index was created as sparse index or not index_is_sparse bool, -- indicates if the index was created as a unique index or not. index_is_unique bool, -- version of the indexing engine used to create this index index_version int, -- document expiry threshold for ttl index index_expire_after_seconds int ); CREATE DOMAIN __API_CATALOG_SCHEMA__.index_spec_type AS __API_CATALOG_SCHEMA__.index_spec_type_internal CHECK ((VALUE).index_version IS NOT NULL AND (VALUE).index_version > 0 AND (VALUE).index_name IS NOT NULL AND (VALUE).index_key IS NOT NULL AND ((VALUE).index_expire_after_seconds IS NULL OR (VALUE).index_expire_after_seconds >= 0)); CREATE SEQUENCE __API_CATALOG_SCHEMA__.collection_indexes_index_id_seq AS integer START WITH 1; -- let 0 mean invalid, see index.h/INVALID_INDEX_ID /* * i) Maps indexes to __API_SCHEMA__ api index id's * ii) Does book-keeping for index keys, options etc. */ CREATE TABLE __API_CATALOG_SCHEMA__.collection_indexes ( -- Postgres side collection id that corresponds to -- __API_CATALOG_SCHEMA__.collections(database_name, collection_name) collection_id bigint not null, -- Postgres side index id assigned to this document index index_id integer default __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_index_id)(), -- Index spec index_spec __API_CATALOG_SCHEMA__.index_spec_type not null, -- The __API_SCHEMA__.create_indexes() command that attempted -- to create the index got completed successfully ? -- -- This either means that creation of this index is still in -- progress or __API_SCHEMA__.create_indexes() command failed but -- couldn't perform the clean-up for the indexes that it left -- behind. index_is_valid bool not null, PRIMARY KEY (index_id) ); -- Speeds up queries based on index_name. CREATE INDEX collection_index_name ON __API_CATALOG_SCHEMA__.collection_indexes (collection_id, ((index_spec).index_name)); -- Speeds up queries based on index_key. CREATE INDEX collection_index_key ON __API_CATALOG_SCHEMA__.collection_indexes (collection_id, ((index_spec).index_key)); documentdb-0.108-0/pg_documentdb/sql/schema/collection_indexes_metadata--0.23-0.sql000066400000000000000000000003421507310017400276760ustar00rootroot00000000000000 ALTER TYPE __API_CATALOG_SCHEMA__.index_spec_type_internal ADD ATTRIBUTE cosmos_search_options __CORE_SCHEMA__.bson; ALTER TYPE __API_CATALOG_SCHEMA__.index_spec_type_internal ADD ATTRIBUTE index_options __CORE_SCHEMA__.bson;documentdb-0.108-0/pg_documentdb/sql/schema/collection_metadata--0.10-0.sql000066400000000000000000000011711507310017400261540ustar00rootroot00000000000000 /* table that records committed writes and their logical transaction IDs */ CREATE SEQUENCE __API_CATALOG_SCHEMA__.collections_collection_id_seq AS bigint; CREATE TABLE __API_CATALOG_SCHEMA__.collections ( database_name text not null, collection_name text not null, collection_id bigint not null unique default __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_id)(), shard_key __CORE_SCHEMA__.bson, collection_uuid uuid, PRIMARY KEY (database_name, collection_name), CONSTRAINT valid_db_coll_name CHECK (__API_SCHEMA_INTERNAL__.ensure_valid_db_coll(database_name, collection_name)) ); documentdb-0.108-0/pg_documentdb/sql/schema/collection_metadata--0.21-0.sql000066400000000000000000000003301507310017400261520ustar00rootroot00000000000000CREATE OR REPLACE TRIGGER collections_trigger_validate_dbname BEFORE INSERT OR UPDATE ON __API_CATALOG_SCHEMA__.collections FOR EACH ROW EXECUTE FUNCTION __API_SCHEMA_INTERNAL_V2__.trigger_validate_dbname();documentdb-0.108-0/pg_documentdb/sql/schema/collection_metadata--0.23-0.sql000066400000000000000000000002731507310017400261620ustar00rootroot00000000000000CREATE TRIGGER collections_trigger AFTER UPDATE OR DELETE ON __API_CATALOG_SCHEMA_V2__.collections FOR STATEMENT EXECUTE FUNCTION __API_SCHEMA_INTERNAL_V2__.collection_update_trigger();documentdb-0.108-0/pg_documentdb/sql/schema/collection_metadata_schemavalidation--0.10-0.sql000066400000000000000000000006151507310017400315510ustar00rootroot00000000000000 ALTER TABLE __API_CATALOG_SCHEMA__.collections ADD COLUMN validator __CORE_SCHEMA__.bson DEFAULT null, ADD COLUMN validation_level text DEFAULT null CONSTRAINT validation_level_check CHECK (validation_level IN ('off', 'strict', 'moderate')), ADD COLUMN validation_action text DEFAULT null CONSTRAINT validation_action_check CHECK (validation_action IN ('warn', 'error'));documentdb-0.108-0/pg_documentdb/sql/schema/collection_metadata_views--0.10-0.sql000066400000000000000000000001461507310017400273720ustar00rootroot00000000000000 ALTER TABLE __API_CATALOG_SCHEMA__.collections ADD view_definition __CORE_SCHEMA__.bson default null;documentdb-0.108-0/pg_documentdb/sql/schema/composite_path_operator_class--0.103-0.sql000066400000000000000000000071121507310017400303630ustar00rootroot00000000000000CREATE OPERATOR CLASS __API_OPCLASS_INTERNAL_SCHEMA__.__EXTENSION_INDEX_OPCLASS__(__API_INDEX_PREFIX_NAME__, composite_path_ops) FOR TYPE __CORE_SCHEMA__.bson using __EXTENSION_OBJECT__(_rum) AS OPERATOR 1 __API_CATALOG_SCHEMA__.@= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 2 __API_CATALOG_SCHEMA__.@> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 3 __API_CATALOG_SCHEMA__.@>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 4 __API_CATALOG_SCHEMA__.@< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 5 __API_CATALOG_SCHEMA__.@<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 6 __API_CATALOG_SCHEMA__.@*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 7 __API_CATALOG_SCHEMA__.@!= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 8 __API_CATALOG_SCHEMA__.@!*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 9 __API_CATALOG_SCHEMA__.@~ (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 10 __API_CATALOG_SCHEMA__.@? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 11 __API_CATALOG_SCHEMA__.@@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 12 __API_CATALOG_SCHEMA__.@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 13 __API_CATALOG_SCHEMA__.@&= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 14 __API_CATALOG_SCHEMA__.=?= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 15 __API_CATALOG_SCHEMA__.@!& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 16 __API_CATALOG_SCHEMA__.@!| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 17 __API_CATALOG_SCHEMA__.@#? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 18 __API_CATALOG_SCHEMA__.@& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 19 __API_CATALOG_SCHEMA__.@| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 20 __API_CATALOG_SCHEMA__.@% (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 25 __API_CATALOG_SCHEMA__.@<> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 26 __API_SCHEMA_INTERNAL_V2__.@!> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 27 __API_SCHEMA_INTERNAL_V2__.@!>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 28 __API_SCHEMA_INTERNAL_V2__.@!< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 29 __API_SCHEMA_INTERNAL_V2__.@!<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __API_CATALOG_SCHEMA__.gin_bson_compare(bytea, bytea), FUNCTION 2 __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_value(__CORE_SCHEMA__.bson, internal), FUNCTION 3 __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 5 __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_compare_partial(bytea, bytea, int2, internal), FUNCTION 11 (__CORE_SCHEMA__.bson) __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_options(internal), STORAGE bytea;documentdb-0.108-0/pg_documentdb/sql/schema/index_operator_classes_negation--0.16-0.sql000066400000000000000000000031161507310017400306130ustar00rootroot00000000000000 ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_single_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 26 __API_SCHEMA_INTERNAL_V2__.@!> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_single_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 27 __API_SCHEMA_INTERNAL_V2__.@!>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_single_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 28 __API_SCHEMA_INTERNAL_V2__.@!< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_single_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 29 __API_SCHEMA_INTERNAL_V2__.@!<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 26 __API_SCHEMA_INTERNAL_V2__.@!> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 27 __API_SCHEMA_INTERNAL_V2__.@!>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 28 __API_SCHEMA_INTERNAL_V2__.@!< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 29 __API_SCHEMA_INTERNAL_V2__.@!<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); documentdb-0.108-0/pg_documentdb/sql/schema/index_operator_classes_range--0.23-0.sql000066400000000000000000000006221507310017400301000ustar00rootroot00000000000000ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_single_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 25 __API_CATALOG_SCHEMA__.@<> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); ALTER OPERATOR FAMILY __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops USING __EXTENSION_OBJECT__(_rum) ADD OPERATOR 25 __API_CATALOG_SCHEMA__.@<> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson);documentdb-0.108-0/pg_documentdb/sql/schema/rum_access_method--0.10-0.sql000066400000000000000000000001741507310017400256470ustar00rootroot00000000000000CREATE ACCESS METHOD __EXTENSION_OBJECT__(_rum) TYPE INDEX HANDLER __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(rumhandler); documentdb-0.108-0/pg_documentdb/sql/schema/setup_background_worker_role--0.106-0.sql000066400000000000000000000012231507310017400302160ustar00rootroot00000000000000/* Role to be used for background_worker database operations. */ DO $do$ BEGIN /* * The role is a system-wide object which is not dropped if the extension * is dropped. Therefore, if __API_SCHEMA__ api is repeatedly created and dropped, * a regular CREATE ROLE would fail since __API_ADMIN_ROLE__ still exists. * We therefore only create the role if it does not exist. */ IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = __SINGLE_QUOTED_STRING__(__API_BG_WORKER_ROLE__)) THEN CREATE ROLE __API_BG_WORKER_ROLE__ WITH LOGIN; GRANT __API_ADMIN_ROLE__ TO __API_BG_WORKER_ROLE__; END IF; END $do$;documentdb-0.108-0/pg_documentdb/sql/schema/shard_key_and_document--0.10-0.sql000066400000000000000000000001751507310017400266550ustar00rootroot00000000000000CREATE TYPE __API_CATALOG_SCHEMA__.shard_key_and_document AS ( shard_key_value int8, document __CORE_SCHEMA__.bson );documentdb-0.108-0/pg_documentdb/sql/schema/single_path_operator_class--0.10-0.sql000066400000000000000000000057401507310017400275640ustar00rootroot00000000000000CREATE OPERATOR CLASS __API_OPCLASS_SCHEMA__.__EXTENSION_INDEX_OPCLASS__(__API_INDEX_PREFIX_NAME__, single_path_ops) DEFAULT FOR TYPE __CORE_SCHEMA__.bson using __EXTENSION_OBJECT__(_rum) AS OPERATOR 1 __API_CATALOG_SCHEMA__.@= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 2 __API_CATALOG_SCHEMA__.@> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 3 __API_CATALOG_SCHEMA__.@>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 4 __API_CATALOG_SCHEMA__.@< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 5 __API_CATALOG_SCHEMA__.@<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 6 __API_CATALOG_SCHEMA__.@*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 7 __API_CATALOG_SCHEMA__.@!= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 8 __API_CATALOG_SCHEMA__.@!*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 9 __API_CATALOG_SCHEMA__.@~ (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 10 __API_CATALOG_SCHEMA__.@? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 11 __API_CATALOG_SCHEMA__.@@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 12 __API_CATALOG_SCHEMA__.@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 13 __API_CATALOG_SCHEMA__.@&= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 14 __API_CATALOG_SCHEMA__.=?= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 15 __API_CATALOG_SCHEMA__.@!& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 16 __API_CATALOG_SCHEMA__.@!| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 17 __API_CATALOG_SCHEMA__.@#? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 18 __API_CATALOG_SCHEMA__.@& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 19 __API_CATALOG_SCHEMA__.@| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 20 __API_CATALOG_SCHEMA__.@% (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __API_CATALOG_SCHEMA__.gin_bson_compare(bytea, bytea), FUNCTION 2 __API_CATALOG_SCHEMA__.gin_bson_single_path_extract_value(__CORE_SCHEMA__.bson, internal), FUNCTION 3 __API_CATALOG_SCHEMA__.gin_bson_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_CATALOG_SCHEMA__.gin_bson_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 5 __API_CATALOG_SCHEMA__.gin_bson_compare_partial(bytea, bytea, int2, internal), FUNCTION 11 (__CORE_SCHEMA__.bson) __API_CATALOG_SCHEMA__.gin_bson_single_path_options(internal), STORAGE bytea;documentdb-0.108-0/pg_documentdb/sql/schema/unique_shard_path_operator_class--0.24-0.sql000066400000000000000000000016211507310017400307710ustar00rootroot00000000000000CREATE OPERATOR CLASS __API_SCHEMA_INTERNAL_V2__.bson_rum_unique_shard_path_ops FOR TYPE __CORE_SCHEMA__.bson using __EXTENSION_OBJECT__(_rum) AS OPERATOR 1 __API_SCHEMA_INTERNAL_V2__.=#= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 uuid_cmp(uuid,uuid), FUNCTION 2 __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_value(__CORE_SCHEMA__.bson, internal), FUNCTION 3 __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 7 (__CORE_SCHEMA__.bson) __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_pre_consistent(internal,smallint,__CORE_SCHEMA__.bson,int,internal,internal,internal,internal), STORAGE uuid;documentdb-0.108-0/pg_documentdb/sql/schema/wildcard_project_path_operator_class--0.12-0.sql000066400000000000000000000060251507310017400316210ustar00rootroot00000000000000CREATE OPERATOR CLASS __API_CATALOG_SCHEMA__.bson_rum_wildcard_project_path_ops FOR TYPE __CORE_SCHEMA__.bson using __EXTENSION_OBJECT__(_rum) AS OPERATOR 1 __API_CATALOG_SCHEMA__.@= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 2 __API_CATALOG_SCHEMA__.@> (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 3 __API_CATALOG_SCHEMA__.@>= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 4 __API_CATALOG_SCHEMA__.@< (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 5 __API_CATALOG_SCHEMA__.@<= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 6 __API_CATALOG_SCHEMA__.@*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 7 __API_CATALOG_SCHEMA__.@!= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 8 __API_CATALOG_SCHEMA__.@!*= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 9 __API_CATALOG_SCHEMA__.@~ (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 10 __API_CATALOG_SCHEMA__.@? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 11 __API_CATALOG_SCHEMA__.@@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 12 __API_CATALOG_SCHEMA__.@# (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 13 __API_CATALOG_SCHEMA__.@&= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), -- skip unique index equal for wildcard since unique is not supported for wildcard -- OPERATOR 14 __API_CATALOG_SCHEMA__.=?= (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 15 __API_CATALOG_SCHEMA__.@!& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 16 __API_CATALOG_SCHEMA__.@!| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 17 __API_CATALOG_SCHEMA__.@#? (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 18 __API_CATALOG_SCHEMA__.@& (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 19 __API_CATALOG_SCHEMA__.@| (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), OPERATOR 20 __API_CATALOG_SCHEMA__.@% (__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson), FUNCTION 1 __API_CATALOG_SCHEMA__.gin_bson_compare(bytea, bytea), FUNCTION 2 __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_extract_value(__CORE_SCHEMA__.bson, internal), FUNCTION 3 __API_CATALOG_SCHEMA__.gin_bson_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal), FUNCTION 4 __API_CATALOG_SCHEMA__.gin_bson_consistent(internal, int2, anyelement, int4, internal, internal), FUNCTION 5 __API_CATALOG_SCHEMA__.gin_bson_compare_partial(bytea, bytea, int2, internal), FUNCTION 11 (__CORE_SCHEMA__.bson) __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_options(internal), STORAGE bytea;documentdb-0.108-0/pg_documentdb/sql/types/000077500000000000000000000000001507310017400205565ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/types/bsonindexbounds--0.102-0.sql000066400000000000000000000024651507310017400253620ustar00rootroot00000000000000CREATE TYPE __API_SCHEMA_INTERNAL_V2__.bsonindexbounds; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_in(cstring) RETURNS __API_SCHEMA_INTERNAL_V2__.bsonindexbounds LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_in$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_out(__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS cstring LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_out$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_send(__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bytea LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_send$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_recv(internal) RETURNS __API_SCHEMA_INTERNAL_V2__.bsonindexbounds LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_recv$function$; CREATE TYPE __API_SCHEMA_INTERNAL_V2__.bsonindexbounds ( input = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_in, output = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_out, send = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_send, receive = __API_SCHEMA_INTERNAL_V2__.bsonindexbounds_recv, alignment = int4, storage = extended );documentdb-0.108-0/pg_documentdb/sql/udfs/000077500000000000000000000000001507310017400203535ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/000077500000000000000000000000001507310017400226425ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_count--0.10-0.sql000066400000000000000000000012541507310017400306730ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_count; -- This function is the `count` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_count( databaseName text, countSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_count--latest.sql000066400000000000000000000012541507310017400314540ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_count; -- This function is the `count` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_count( databaseName text, countSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_distinct--0.10-0.sql000066400000000000000000000012701507310017400313620ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_distinct; -- This function is the `distinct` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_distinct( databaseName text, distinctSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_distinct--latest.sql000066400000000000000000000012701507310017400321430ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_distinct; -- This function is the `distinct` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_distinct( databaseName text, distinctSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_find--0.10-0.sql000066400000000000000000000012501507310017400304570ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_find; -- This function is the `find` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_find( databaseName text, findSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_find--latest.sql000066400000000000000000000012501507310017400312400ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_find; -- This function is the `find` query function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_find( databaseName text, findSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_pipeline--0.10-0.sql000066400000000000000000000013051507310017400313450ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_pipeline; -- This function is the `aggregation pipeline` function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_pipeline( databaseName text, aggregationPipeline __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_pipeline--latest.sql000066400000000000000000000013051507310017400321260ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA__.bson_aggregation_pipeline; -- This function is the `aggregation pipeline` function. -- It is a wrapper function that passes the aggregation pipeline from the GW to the backend -- such that the planner phase can replace the parameterized value in the planning phase. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_aggregation_pipeline( databaseName text, aggregationPipeline __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_SCHEMA_INTERNAL__.aggregation_support AS 'MODULE_PATHNAME', $function$command_bson_aggregation_pipeline$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_redact--0.102-0.sql000066400000000000000000000012071507310017400310650ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_redact(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, text, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_redact$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_redact(document __CORE_SCHEMA__.bson, redactSpec __CORE_SCHEMA__.bson, redactSpecText text, variableSpec __CORE_SCHEMA__.bson, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_redact$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_redact--0.24-0.sql000066400000000000000000000004311507310017400310060ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_redact(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, text, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_redact$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_redact--latest.sql000066400000000000000000000012071507310017400315640ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_redact(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, text, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_redact$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_redact(document __CORE_SCHEMA__.bson, redactSpec __CORE_SCHEMA__.bson, redactSpecText text, variableSpec __CORE_SCHEMA__.bson, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_redact$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_support--0.10-0.sql000066400000000000000000000003071507310017400312550ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.aggregation_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$command_aggregation_support$$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_aggregation_support--latest.sql000066400000000000000000000003071507310017400320360ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.aggregation_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$command_aggregation_support$$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_bucket_auto--0.105-0.sql000066400000000000000000000004051507310017400275630ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_bucket_auto(document __CORE_SCHEMA__.bson, spec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_dollar_bucket_auto$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_bucket_auto--latest.sql000066400000000000000000000004051507310017400302570ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_bucket_auto(document __CORE_SCHEMA__.bson, spec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_dollar_bucket_auto$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_coercion_compat--0.24-0.sql000066400000000000000000000004761507310017400303520ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.__EXTENSION_OBJECT_V2__(_core_bson_to_bson)(__CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$, __EXTENSION_OBJECT_PREFIX_V2__, _core_bson_to_bson$function$);documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_coercion_compat--latest.sql000066400000000000000000000004761507310017400311260ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.__EXTENSION_OBJECT_V2__(_core_bson_to_bson)(__CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$, __EXTENSION_OBJECT_PREFIX_V2__, _core_bson_to_bson$function$);documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_densify_functions--0.22-0.sql000066400000000000000000000013171507310017400307300ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_range$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_partition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_full(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_full$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_densify_functions--latest.sql000066400000000000000000000013171507310017400315060ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_range$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_partition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_densify_full(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c WINDOW STABLE AS 'MODULE_PATHNAME', $function$bson_densify_full$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_geonear_functions--0.18-0.sql000066400000000000000000000014501507310017400307120ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_geonear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project_geonear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_geonear_distance(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS float8 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_geonear_distance$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_geonear_within_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_geonear_within_range$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_geonear_functions--latest.sql000066400000000000000000000014501507310017400314630ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_geonear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project_geonear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_geonear_distance(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS float8 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_geonear_distance$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_geonear_within_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_geonear_within_range$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_inverse_match--0.16-0.sql000066400000000000000000000006631507310017400300340ustar00rootroot00000000000000-- drop the public schema function and move it to __API_SCHEMA_INTERNAL_V2__ DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA_V2__.bson_dollar_inverse_match; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_inverse_match( document __CORE_SCHEMA_V2__.bson, spec __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_inverse_match$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_inverse_match--latest.sql000066400000000000000000000006631507310017400306070ustar00rootroot00000000000000-- drop the public schema function and move it to __API_SCHEMA_INTERNAL_V2__ DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA_V2__.bson_dollar_inverse_match; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_inverse_match( document __CORE_SCHEMA_V2__.bson, spec __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_inverse_match$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_lookup_functions--0.23-0.sql000066400000000000000000000034111507310017400305760ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA_V2__.bson_dollar_lookup_extract_filter_expression; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_extract_filter_expression(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_extract_filter_expression$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lookup_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_lookup_unwind$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_extract_filter_array(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson[] LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_extract_filter_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_filter_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$bson_dollar_lookup_filter_support$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_join_filter(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, text) RETURNS bool LANGUAGE c SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_filter_support IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_join_filter$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_project(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_project$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_lookup_functions--latest.sql000066400000000000000000000034111507310017400313530ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_CATALOG_SCHEMA_V2__.bson_dollar_lookup_extract_filter_expression; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_extract_filter_expression(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_extract_filter_expression$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lookup_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_lookup_unwind$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_extract_filter_array(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson[] LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_extract_filter_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_filter_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$bson_dollar_lookup_filter_support$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_join_filter(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, text) RETURNS bool LANGUAGE c SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_filter_support IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_join_filter$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_project(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_project$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_merge_functions--0.102-0.sql000066400000000000000000000077441507310017400304570ustar00rootroot00000000000000/* Description: This function is use in $merge stage aggregation pipeline to perform action in case of a match. Arguments: - @bson: source document - @bson: target document - @int_parameter: action to perform in case of match e.g, replace, keepExisting, merge, fail, pipeline - @bson: schema validation information - @int_parameter: validation level, e.g. strict, moderate Returns: @bson: The final output to writing into target collection. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_handle_when_matched(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson, int4) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_handle_when_matched$function$; /* Description: support function for index pushdown in merge join used by __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$bson_dollar_merge_filter_support$$; /* Description: * The runtime implementation of this is identical to $eq. so we just make a direct function call to the function. We just have a tail end argument of the index path so that we can do index pushdown for $merge scenarios. Arguments: - @bson: target document - @bson: filter document - @text: index path Returns: @bool : True if target document matches the filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, text) RETURNS BOOLEAN LANGUAGE c SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_join_filter$function$; /* Description: This function adds object ID in a bson document if it not present. Arguments: - @bson: input document - @bson: object id to add - @bson: schema validation information Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_add_object_id(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_add_object_id$function$; /* Description: This function is use in $merge stage aggregation to fail in case of user wants to fail in `whenNotMatced`. This function accepts dummy arguments and has return type to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_fail_when_not_matched(__CORE_SCHEMA__.bson,text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_fail_when_not_matched$function$; /* Description: This function generates object ID. Arguments: - @bson: this is a dummy input as Non Immutable function are not supported in citus MERGE command. passing dummy input to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_generate_object_id(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_generate_object_id$function$; /* Description: This function extracts merge filter from source document to match against target document. Arguments: - @bson: source document - @text: path to extract filter from source document Returns: @bson: extracted filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_extract_merge_filter(__CORE_SCHEMA__.bson, text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_extract_merge_filter$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_merge_functions--0.20-0.sql000066400000000000000000000074451507310017400303740ustar00rootroot00000000000000/* Description: This function is use in $merge stage aggregation pipeline to perform action in case of a match. Arguments: - @bson: source document - @bson: target document - @int_parameter: action to perform in case of match e.g, replace, keepExisting, merge, fail, pipeline Returns: @bson: The final output to writing into target collection. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_handle_when_matched(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, int4) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_handle_when_matched$function$; /* Description: support function for index pushdown in merge join used by __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$bson_dollar_merge_filter_support$$; /* Description: * The runtime implementation of this is identical to $eq. so we just make a direct function call to the function. We just have a tail end argument of the index path so that we can do index pushdown for $merge scenarios. Arguments: - @bson: target document - @bson: filter document - @text: index path Returns: @bool : True if target document matches the filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, text) RETURNS BOOLEAN LANGUAGE c SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_join_filter$function$; /* Description: This function adds object ID in a bson document if it not present. Arguments: - @bson: input document - @bson: object id to add Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_add_object_id(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_add_object_id$function$; /* Description: This function is use in $merge stage aggregation to fail in case of user wants to fail in `whenNotMatced`. This function accepts dummy arguments and has return type to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_fail_when_not_matched(__CORE_SCHEMA__.bson,text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_fail_when_not_matched$function$; /* Description: This function generates object ID. Arguments: - @bson: this is a dummy input as Non Immutable function are not supported in citus MERGE command. passing dummy input to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_generate_object_id(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_generate_object_id$function$; /* Description: This function extracts merge filter from source document to match against target document. Arguments: - @bson: source document - @text: path to extract filter from source document Returns: @bson: extracted filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_extract_merge_filter(__CORE_SCHEMA__.bson, text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_extract_merge_filter$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_merge_functions--latest.sql000066400000000000000000000077441507310017400311560ustar00rootroot00000000000000/* Description: This function is use in $merge stage aggregation pipeline to perform action in case of a match. Arguments: - @bson: source document - @bson: target document - @int_parameter: action to perform in case of match e.g, replace, keepExisting, merge, fail, pipeline - @bson: schema validation information - @int_parameter: validation level, e.g. strict, moderate Returns: @bson: The final output to writing into target collection. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_handle_when_matched(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson, int4) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_handle_when_matched$function$; /* Description: support function for index pushdown in merge join used by __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$bson_dollar_merge_filter_support$$; /* Description: * The runtime implementation of this is identical to $eq. so we just make a direct function call to the function. We just have a tail end argument of the index path so that we can do index pushdown for $merge scenarios. Arguments: - @bson: target document - @bson: filter document - @text: index path Returns: @bool : True if target document matches the filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, text) RETURNS BOOLEAN LANGUAGE c SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_join_filter$function$; /* Description: This function adds object ID in a bson document if it not present. Arguments: - @bson: input document - @bson: object id to add - @bson: schema validation information Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_add_object_id(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_add_object_id$function$; /* Description: This function is use in $merge stage aggregation to fail in case of user wants to fail in `whenNotMatced`. This function accepts dummy arguments and has return type to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_fail_when_not_matched(__CORE_SCHEMA__.bson,text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_fail_when_not_matched$function$; /* Description: This function generates object ID. Arguments: - @bson: this is a dummy input as Non Immutable function are not supported in citus MERGE command. passing dummy input to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. Returns: @bson: output bson with object id. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_generate_object_id(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_generate_object_id$function$; /* Description: This function extracts merge filter from source document to match against target document. Arguments: - @bson: source document - @text: path to extract filter from source document Returns: @bson: extracted filter document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_extract_merge_filter(__CORE_SCHEMA__.bson, text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_extract_merge_filter$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_unwind_functions--0.10-0.sql000066400000000000000000000017771507310017400306020ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_unwind$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unwind(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_unwind_with_options$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_distinct_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_distinct_unwind$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_build_distinct_response(__CORE_SCHEMA__.bson[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_build_distinct_response$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/bson_unwind_functions--latest.sql000066400000000000000000000017771507310017400313630ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_unwind$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unwind(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_dollar_unwind_with_options$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_distinct_unwind(__CORE_SCHEMA__.bson, text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$bson_distinct_unwind$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_build_distinct_response(__CORE_SCHEMA__.bson[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_build_distinct_response$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/distinct_aggregates--0.10-0.sql000066400000000000000000000013201507310017400301570ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_distinct_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_distinct_array_agg_final$function$; CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_DISTINCT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_transition, FINALFUNC = __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_final, stype = bytea, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/distinct_aggregates--latest.sql000066400000000000000000000013201507310017400307400ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_distinct_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_distinct_array_agg_final$function$; CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_DISTINCT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_transition, FINALFUNC = __API_SCHEMA_INTERNAL__.bson_distinct_array_agg_final, stype = bytea, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates--0.102-0.sql000066400000000000000000000362141507310017400275660ustar00rootroot00000000000000 CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONSUM(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONAVERAGE(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMAX(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_max_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_max_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMIN(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_min_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_min_combine, PARALLEL = SAFE ); /* * __API_CATALOG_SCHEMA__.bsonFIRST and __API_CATALOG_SCHEMA__.bsonLAST are the custom aggregation for first() and * last() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Note that __API_CATALOG_SCHEMA__.bsonFIRST() and __API_CATALOG_SCHEMA__.bsonLAST() has a __API_CATALOG_SCHEMA__.bson[] as the second * argument which is an array of sort order specs of the form * document |-<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRST() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTONSORTED and __CORE_SCHEMA__.bsonLASTONSORTED are the custom aggregation * functions for first() and last() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won't need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTN and __CORE_SCHEMA__.bsonLASTN are the custom aggregation for firstN() and * lastN() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Second argument is the number of results to return or 'n'. * * Note that __CORE_SCHEMA__.bsonFIRSTN() and __CORE_SCHEMA__.bsonLASTN() has a __CORE_SCHEMA__.bson[] as the third * argument which is an array of sort order specs of the form * document | -<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTN() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTNONSORTED and __CORE_SCHEMA__.bsonLASTNONSORTED are the custom aggregation * functions for firstn() and lastn() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won\'t need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OBJECT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * Implementation of the bson_array_agg aggregator with the addition of a boolean * field that indicates whether to treat { "": value } as an object or value. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text, boolean) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_ADD_TO_SET(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS_ON_SORTED(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVPOP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVSAMP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRST corresponding to input expression for $top operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLAST corresponding to input expression for $bottom operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRSTN corresponding to input expression for $topN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLASTN corresponding to input expression for $bottomN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMAXN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMINN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_minn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONPERCENTILE(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMEDIAN(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_percentile, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates--0.106-0.sql000066400000000000000000000362021507310017400275670ustar00rootroot00000000000000 CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONSUM(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONAVERAGE(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMAX(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_max_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_max_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMIN(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_min_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_min_combine, PARALLEL = SAFE ); /* * __API_CATALOG_SCHEMA__.bsonFIRST and __API_CATALOG_SCHEMA__.bsonLAST are the custom aggregation for first() and * last() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Note that __API_CATALOG_SCHEMA__.bsonFIRST() and __API_CATALOG_SCHEMA__.bsonLAST() has a __API_CATALOG_SCHEMA__.bson[] as the second * argument which is an array of sort order specs of the form * document |-<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRST() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTONSORTED and __CORE_SCHEMA__.bsonLASTONSORTED are the custom aggregation * functions for first() and last() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won't need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTN and __CORE_SCHEMA__.bsonLASTN are the custom aggregation for firstN() and * lastN() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Second argument is the number of results to return or 'n'. * * Note that __CORE_SCHEMA__.bsonFIRSTN() and __CORE_SCHEMA__.bsonLASTN() has a __CORE_SCHEMA__.bson[] as the third * argument which is an array of sort order specs of the form * document | -<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTN() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTNONSORTED and __CORE_SCHEMA__.bsonLASTNONSORTED are the custom aggregation * functions for firstn() and lastn() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won\'t need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OBJECT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * Implementation of the bson_array_agg aggregator with the addition of a boolean * field that indicates whether to treat { "": value } as an object or value. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text, boolean) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_ADD_TO_SET(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS_ON_SORTED(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVPOP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVSAMP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRST corresponding to input expression for $top operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLAST corresponding to input expression for $bottom operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRSTN corresponding to input expression for $topN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLASTN corresponding to input expression for $bottomN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMAXN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMINN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_minn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONPERCENTILE(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMEDIAN(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_percentile, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates--0.22-0.sql000066400000000000000000000346741507310017400275170ustar00rootroot00000000000000 CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONSUM(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONAVERAGE(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMAX(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_max_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_max_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMIN(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_min_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_min_combine, PARALLEL = SAFE ); /* * __API_CATALOG_SCHEMA__.bsonFIRST and __API_CATALOG_SCHEMA__.bsonLAST are the custom aggregation for first() and * last() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Note that __API_CATALOG_SCHEMA__.bsonFIRST() and __API_CATALOG_SCHEMA__.bsonLAST() has a __API_CATALOG_SCHEMA__.bson[] as the second * argument which is an array of sort order specs of the form * document |-<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRST() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTONSORTED and __CORE_SCHEMA__.bsonLASTONSORTED are the custom aggregation * functions for first() and last() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won't need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTN and __CORE_SCHEMA__.bsonLASTN are the custom aggregation for firstN() and * lastN() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Second argument is the number of results to return or 'n'. * * Note that __CORE_SCHEMA__.bsonFIRSTN() and __CORE_SCHEMA__.bsonLASTN() has a __CORE_SCHEMA__.bson[] as the third * argument which is an array of sort order specs of the form * document | -<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTN() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTNONSORTED and __CORE_SCHEMA__.bsonLASTNONSORTED are the custom aggregation * functions for firstn() and lastn() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won\'t need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OBJECT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OUT(__CORE_SCHEMA__.bson, text, text, text, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_out_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_out_final, stype = bytea ); /* * Implementation of the bson_array_agg aggregator with the addition of a boolean * field that indicates whether to treat { "": value } as an object or value. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text, boolean) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_ADD_TO_SET(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS_ON_SORTED(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVPOP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVSAMP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRST corresponding to input expression for $top operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLAST corresponding to input expression for $bottom operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRSTN corresponding to input expression for $topN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLASTN corresponding to input expression for $bottomN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMAXN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMINN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_minn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates--0.24-0.sql000066400000000000000000000365751507310017400275230ustar00rootroot00000000000000 CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONSUM(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONAVERAGE(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMAX(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_max_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_max_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMIN(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_min_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_min_combine, PARALLEL = SAFE ); /* * __API_CATALOG_SCHEMA__.bsonFIRST and __API_CATALOG_SCHEMA__.bsonLAST are the custom aggregation for first() and * last() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Note that __API_CATALOG_SCHEMA__.bsonFIRST() and __API_CATALOG_SCHEMA__.bsonLAST() has a __API_CATALOG_SCHEMA__.bson[] as the second * argument which is an array of sort order specs of the form * document |-<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRST() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTONSORTED and __CORE_SCHEMA__.bsonLASTONSORTED are the custom aggregation * functions for first() and last() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won't need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTN and __CORE_SCHEMA__.bsonLASTN are the custom aggregation for firstN() and * lastN() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Second argument is the number of results to return or 'n'. * * Note that __CORE_SCHEMA__.bsonFIRSTN() and __CORE_SCHEMA__.bsonLASTN() has a __CORE_SCHEMA__.bson[] as the third * argument which is an array of sort order specs of the form * document | -<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTN() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTNONSORTED and __CORE_SCHEMA__.bsonLASTNONSORTED are the custom aggregation * functions for firstn() and lastn() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won\'t need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OBJECT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OUT(__CORE_SCHEMA__.bson, text, text, text, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_out_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_out_final, stype = bytea ); /* * Implementation of the bson_array_agg aggregator with the addition of a boolean * field that indicates whether to treat { "": value } as an object or value. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text, boolean) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_ADD_TO_SET(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS_ON_SORTED(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVPOP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVSAMP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRST corresponding to input expression for $top operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLAST corresponding to input expression for $bottom operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRSTN corresponding to input expression for $topN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLASTN corresponding to input expression for $bottomN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMAXN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMINN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_minn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONPERCENTILE(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMEDIAN(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_percentile, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates--latest.sql000066400000000000000000000362021507310017400302620ustar00rootroot00000000000000 CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONSUM(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_sum_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONAVERAGE(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_combine, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_sum_avg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_avg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMAX(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_max_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_max_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONMIN(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_min_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_min_max_final, stype = __CORE_SCHEMA__.bson, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_min_combine, PARALLEL = SAFE ); /* * __API_CATALOG_SCHEMA__.bsonFIRST and __API_CATALOG_SCHEMA__.bsonLAST are the custom aggregation for first() and * last() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Note that __API_CATALOG_SCHEMA__.bsonFIRST() and __API_CATALOG_SCHEMA__.bsonLAST() has a __API_CATALOG_SCHEMA__.bson[] as the second * argument which is an array of sort order specs of the form * document |-<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRST() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTONSORTED and __CORE_SCHEMA__.bsonLASTONSORTED are the custom aggregation * functions for first() and last() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won't need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTONSORTED(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTN and __CORE_SCHEMA__.bsonLASTN are the custom aggregation for firstN() and * lastN() accumulators when sorting/ordering operation can be pushed * down to the worker nodes. * * Worker nodes will apply the transition function on their share of * the data to generate one partial AGGREGATE __API_CATALOG_SCHEMA__.per group per worker. * The coordinator will then combine the partial aggregates using * the combine function. Finally the finalfunc will be called on the * intermediate result for each group. * * Second argument is the number of results to return or 'n'. * * Note that __CORE_SCHEMA__.bsonFIRSTN() and __CORE_SCHEMA__.bsonLASTN() has a __CORE_SCHEMA__.bson[] as the third * argument which is an array of sort order specs of the form * document | -<> '{ "sorkeypath1":1}'. The worker nodes will use * these sort keys to order the documents while applying the transition * function. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTN() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); /* * __CORE_SCHEMA__.bsonFIRSTNONSORTED and __CORE_SCHEMA__.bsonLASTNONSORTED are the custom aggregation * functions for firstn() and lastn() accumulators when the input to * the group by stage is pre-sorted. * * In this case the aggregation is not pushed down to the worker node. * All the data will be pulled at the coordinator and the transition * function will be called on that data. * * Note the missing COMBINEFUNC. Since the work will be done at the * coordinator, we won\'t need that. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_OBJECT_AGG(__CORE_SCHEMA__.bson) ( SFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * Implementation of the bson_array_agg aggregator with the addition of a boolean * field that indicates whether to treat { "": value } as an object or value. */ CREATE OR REPLACE AGGREGATE __API_CATALOG_SCHEMA__.BSON_ARRAY_AGG(__CORE_SCHEMA__.bson, text, boolean) ( SFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, stype = bytea, mstype = bytea, MSFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_transition, MFINALFUNC = __API_CATALOG_SCHEMA__.bson_array_agg_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_ADD_TO_SET(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS_ON_SORTED(__CORE_SCHEMA_V2__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_object_agg_final, stype = bytea, PARALLEL = SAFE ); /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSON_MERGE_OBJECTS(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVPOP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONSTDDEVSAMP(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRST corresponding to input expression for $top operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_first_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLAST corresponding to input expression for $bottom operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLAST(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_last_combine, PARALLEL = SAFE ); /* * Additional argument to BSONFIRSTN corresponding to input expression for $topN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_firstn_combine, PARALLEL = SAFE ); /* * Additional argument to BSONLASTN corresponding to input expression for $bottomN operator */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTN(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_final, stype = bytea, COMBINEFUNC = __API_CATALOG_SCHEMA__.bson_lastn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMAXN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMINN(__CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_minn_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final, stype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTONSORTED(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONFIRSTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); /* * See summary of __CORE_SCHEMA__.bsonFIRSTNONSORTED() */ CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONLASTNONSORTED(__CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted, FINALFUNC = __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONPERCENTILE(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONMEDIAN(__CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_add_double, stype = internal, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_percentile, SERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_serial, DESERIALFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_deserial, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.tdigest_combine, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates_support--0.102-0.sql000066400000000000000000000313151507310017400313570ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_avg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_avg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_max_final(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_max_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_first_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_last_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final$function$; /* * TODO: Replace this in favor of the new approach below. */ CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final(bytea) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition_on_sorted$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_minn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_minn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_percentile(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_percentile$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_array_percentiles$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_combine(internal, internal) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_serial(internal) RETURNS bytea LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_serial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_deserial(bytea, internal) RETURNS internal LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_deserial$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates_support--0.106-0.sql000066400000000000000000000321111507310017400313560ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_avg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_avg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_max_final(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_max_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_first_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_last_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final$function$; /* * TODO: Replace this in favor of the new approach below. */ CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final(bytea) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition_on_sorted$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_minn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_minn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_percentile(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_percentile$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_array_percentiles$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_combine(internal, internal) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_serial(internal) RETURNS bytea LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_serial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_deserial(bytea, internal) RETURNS internal LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_deserial$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates_support--0.22-0.sql000066400000000000000000000272471507310017400313110ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_avg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_avg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_max_final(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_max_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_first_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_last_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final$function$; /* * TODO: Replace this in favor of the new approach below. */ CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_out_transition(bytea, __CORE_SCHEMA__.bson, text, text, text, text) RETURNS bytea LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$bson_out_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_out_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$bson_out_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final(bytea) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition_on_sorted$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_minn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_minn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates_support--0.24-0.sql000066400000000000000000000321441507310017400313030ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_avg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_avg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_max_final(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_max_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_first_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_last_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final$function$; /* * TODO: Replace this in favor of the new approach below. */ CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_out_transition(bytea, __CORE_SCHEMA__.bson, text, text, text, text) RETURNS bytea LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$bson_out_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_out_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$bson_out_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final(bytea) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition_on_sorted$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_minn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_minn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_percentile(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_percentile$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_array_percentiles$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_combine(internal, internal) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_serial(internal) RETURNS bytea LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_serial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_deserial(bytea, internal) RETURNS internal LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_deserial$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/group_aggregates_support--latest.sql000066400000000000000000000321111507310017400320510ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_avg_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_sum_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_avg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_avg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_max_final(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_max_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_transition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_min_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_min_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_max_combine(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_max_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_first_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_last_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE STRICT AS 'MODULE_PATHNAME', $function$bson_last_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_first_last_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_last_final$function$; /* * TODO: Replace this in favor of the new approach below. */ CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_transition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_array_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_object_agg_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_object_agg_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[]) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_combine$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_final$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_firstn_lastn_final_on_sorted(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_lastn_final_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_transition(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_add_to_set_final(bytea) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_add_to_set_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition_on_sorted(bytea, __CORE_SCHEMA_V2__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition_on_sorted$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_transition$function$; /* * This can't use __CORE_SCHEMA_V2__.bson due to citus type checks. We can migrate once the underlying tuples use the new types. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_merge_objects_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_merge_objects_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson[], __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_minn_transition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_minn_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_maxminn_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_maxminn_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_first_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_first_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_last_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_last_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_firstn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_firstn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_lastn_transition_on_sorted(bytea, __CORE_SCHEMA__.bson, bigint, __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_lastn_transition_on_sorted$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_add_double_array(internal, __CORE_SCHEMA__.bson, int4, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_add_double_array$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_percentile(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_percentile$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_array_percentiles(internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_array_percentiles$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_combine(internal, internal) RETURNS internal LANGUAGE c IMMUTABLE AS 'MODULE_PATHNAME', $function$tdigest_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_serial(internal) RETURNS bytea LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_serial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.tdigest_deserial(bytea, internal) RETURNS internal LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$tdigest_deserial$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/window_aggregate_support--0.22-0.sql000066400000000000000000000111611507310017400312650ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_minvtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_minvtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_invtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_rank() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_rank$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dense_rank() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_dense_rank$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_exp_moving_avg(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_linear_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_linear_fill$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_locf_fill(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_locf_fill$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_document_number() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_document_number$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_shift(__CORE_SCHEMA__.bson, integer, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_shift$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_derivative_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_derivative_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_integral_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_integral_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_integral_derivative_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_winfunc_invtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_winfunc_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_winfunc_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_const_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_const_fill$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/window_aggregate_support--latest.sql000066400000000000000000000111611507310017400320430ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_sum_avg_minvtransition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_sum_avg_minvtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_array_agg_minvtransition(bytea, __CORE_SCHEMA__.bson, text, boolean) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_array_agg_minvtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine(bytea, bytea) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_combine$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_samp_invtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_pop_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_covariance_samp_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_rank() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_rank$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dense_rank() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_dense_rank$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_exp_moving_avg(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_linear_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_linear_fill$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_locf_fill(__CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_locf_fill$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_document_number() RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_document_number$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_shift(__CORE_SCHEMA__.bson, integer, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_shift$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_derivative_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_derivative_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_integral_transition(bytea, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_integral_transition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_integral_derivative_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_samp_winfunc_invtransition(bytea, __CORE_SCHEMA__.bson) RETURNS bytea LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_samp_winfunc_invtransition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_pop_winfunc_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_pop_winfunc_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_std_dev_samp_winfunc_final(bytea) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$bson_std_dev_samp_winfunc_final$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_const_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c STABLE WINDOW AS 'MODULE_PATHNAME', $function$bson_const_fill$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/window_aggregates--0.22-0.sql000066400000000000000000000035441507310017400276620ustar00rootroot00000000000000CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONCOVARIANCEPOP(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONCOVARIANCESAMP(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONDERIVATIVE(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_derivative_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONINTEGRAL(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final, stype = bytea, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/aggregation/window_aggregates--latest.sql000066400000000000000000000035441507310017400304400ustar00rootroot00000000000000CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONCOVARIANCEPOP(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONCOVARIANCESAMP(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final, MSFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_transition, MFINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_samp_final, MINVFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_invtransition, stype = bytea, mstype = bytea, COMBINEFUNC = __API_SCHEMA_INTERNAL_V2__.bson_covariance_pop_samp_combine, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONDERIVATIVE(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_derivative_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final, stype = bytea, PARALLEL = SAFE ); CREATE OR REPLACE AGGREGATE __API_SCHEMA_INTERNAL_V2__.BSONINTEGRAL(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, bigint) ( SFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_transition, FINALFUNC = __API_SCHEMA_INTERNAL_V2__.bson_integral_derivative_final, stype = bytea, PARALLEL = SAFE );documentdb-0.108-0/pg_documentdb/sql/udfs/auth/000077500000000000000000000000001507310017400213145ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/auth/auth_scram--0.100-0.sql000066400000000000000000000020701507310017400250300ustar00rootroot00000000000000/* Authenticate using SCRAM SHA256 with postgresql db for a specific user name */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.authenticate_with_scram_sha256( p_user_name text, p_auth_msg text, p_client_proof text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $$command_authenticate_with_scram_sha256$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.authenticate_with_scram_sha256(text, text, text) IS 'Used to authenticate the user with Postgresql DB using SCRAM SHA-256'; /* * scram_sha256_get_salt_and_iterations() gets SALT and Iteration * count for the given user from the Postgresql DB */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.scram_sha256_get_salt_and_iterations( p_user_name text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $$command_scram_sha256_get_salt_and_iterations$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.scram_sha256_get_salt_and_iterations(text) IS 'Gets SALT and Iteration count for the given user from the backend'; documentdb-0.108-0/pg_documentdb/sql/udfs/auth/auth_scram--latest.sql000066400000000000000000000020701507310017400255310ustar00rootroot00000000000000/* Authenticate using SCRAM SHA256 with postgresql db for a specific user name */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.authenticate_with_scram_sha256( p_user_name text, p_auth_msg text, p_client_proof text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $$command_authenticate_with_scram_sha256$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.authenticate_with_scram_sha256(text, text, text) IS 'Used to authenticate the user with Postgresql DB using SCRAM SHA-256'; /* * scram_sha256_get_salt_and_iterations() gets SALT and Iteration * count for the given user from the Postgresql DB */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.scram_sha256_get_salt_and_iterations( p_user_name text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $$command_scram_sha256_get_salt_and_iterations$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.scram_sha256_get_salt_and_iterations(text) IS 'Gets SALT and Iteration count for the given user from the backend'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/000077500000000000000000000000001507310017400231715ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/bson_update_document--0.10-0.sql000066400000000000000000000010671507310017400307050ustar00rootroot00000000000000 /* Command: update */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.bson_update_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_update_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, buildUpdateDesc bool DEFAULT false, OUT newDocument __CORE_SCHEMA__.bson, OUT updateDesc __CORE_SCHEMA__.bson) RETURNS RECORD LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/bson_update_document--0.105-0.sql000066400000000000000000000017221507310017400307700ustar00rootroot00000000000000 /* Command: update */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.bson_update_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_update_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, buildUpdateDesc bool DEFAULT false, OUT newDocument __CORE_SCHEMA__.bson, OUT updateDesc __CORE_SCHEMA__.bson) RETURNS RECORD LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_bson_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, OUT newDocument __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/bson_update_document--0.106-0.sql000066400000000000000000000022021507310017400307630ustar00rootroot00000000000000 /* Command: update */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.bson_update_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_update_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, buildUpdateDesc bool DEFAULT false, variableSpec __CORE_SCHEMA__.bson DEFAULT NULL, OUT newDocument __CORE_SCHEMA__.bson, OUT updateDesc __CORE_SCHEMA__.bson) RETURNS RECORD LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.update_bson_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_bson_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, variableSpec __CORE_SCHEMA__.bson DEFAULT NULL, OUT newDocument __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/bson_update_document--0.108-0.sql000066400000000000000000000022021507310017400307650ustar00rootroot00000000000000 /* Command: update */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.bson_update_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_update_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, buildUpdateDesc bool DEFAULT false, variableSpec __CORE_SCHEMA__.bson DEFAULT NULL, OUT newDocument __CORE_SCHEMA__.bson, OUT updateDesc __CORE_SCHEMA__.bson) RETURNS RECORD LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.update_bson_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_bson_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson, variableSpec __CORE_SCHEMA__.bson, collationString text, OUT newDocument __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/bson_update_document--latest.sql000066400000000000000000000022021507310017400314560ustar00rootroot00000000000000 /* Command: update */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.bson_update_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.bson_update_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson DEFAULT NULL, buildUpdateDesc bool DEFAULT false, variableSpec __CORE_SCHEMA__.bson DEFAULT NULL, OUT newDocument __CORE_SCHEMA__.bson, OUT updateDesc __CORE_SCHEMA__.bson) RETURNS RECORD LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.update_bson_document; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_bson_document( document __CORE_SCHEMA__.bson, updateSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson, arrayFilters __CORE_SCHEMA__.bson, variableSpec __CORE_SCHEMA__.bson, collationString text, OUT newDocument __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_update_document$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/command_node_worker--0.108-0.sql000066400000000000000000000005621507310017400306070ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.command_node_worker( p_local_function_oid Oid, p_local_function_arg __CORE_SCHEMA_V2__.bson, p_current_table regclass, p_chosen_tables text[], p_tables_qualified boolean, p_optional_arg_unused text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_node_worker$$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/command_node_worker--latest.sql000066400000000000000000000005621507310017400313000ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.command_node_worker( p_local_function_oid Oid, p_local_function_arg __CORE_SCHEMA_V2__.bson, p_current_table regclass, p_chosen_tables text[], p_tables_qualified boolean, p_optional_arg_unused text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_node_worker$$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/cursor_functions--0.16-0.sql000066400000000000000000000015211507310017400301120ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.current_cursor_state(__CORE_SCHEMA_V2__.bson); DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.cursor_state(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson); -- This function is STABLE (Not Volatile) as within 1 transaction snapshot -- The value given the "document" does not change. -- However it's not guaranteed to be the same across transaction snapshots. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_cursor_state(__CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$command_current_cursor_state$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.cursor_state(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_cursor_state$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/cursor_functions--latest.sql000066400000000000000000000015211507310017400306650ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.current_cursor_state(__CORE_SCHEMA_V2__.bson); DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.cursor_state(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson); -- This function is STABLE (Not Volatile) as within 1 transaction snapshot -- The value given the "document" does not change. -- However it's not guaranteed to be the same across transaction snapshots. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_cursor_state(__CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c STABLE AS 'MODULE_PATHNAME', $function$command_current_cursor_state$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.cursor_state(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_cursor_state$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/delete--0.16-0.sql000066400000000000000000000032551507310017400257550ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.delete processes a mongo wire protocol delete command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.delete( p_database_name text, p_delete __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.delete(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'deletes documents from a collection'; /* Command: delete */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_one( p_collection_id bigint, p_shard_key_value bigint, p_query __CORE_SCHEMA_V2__.bson, p_sort __CORE_SCHEMA_V2__.bson, p_return_document bool, p_return_fields __CORE_SCHEMA_V2__.bson, p_transaction_id text, OUT o_is_row_deleted bool, OUT o_result_deleted_document __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,text) IS 'deletes a single document from a collection'; /* Command: delete */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec __CORE_SCHEMA_V2__.bson, p_update_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete_worker$$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/delete--latest.sql000066400000000000000000000032551507310017400265300ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.delete processes a mongo wire protocol delete command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.delete( p_database_name text, p_delete __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.delete(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'deletes documents from a collection'; /* Command: delete */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_one( p_collection_id bigint, p_shard_key_value bigint, p_query __CORE_SCHEMA_V2__.bson, p_sort __CORE_SCHEMA_V2__.bson, p_return_document bool, p_return_fields __CORE_SCHEMA_V2__.bson, p_transaction_id text, OUT o_is_row_deleted bool, OUT o_result_deleted_document __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,text) IS 'deletes a single document from a collection'; /* Command: delete */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec __CORE_SCHEMA_V2__.bson, p_update_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_delete_worker$$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/find_and_modify--0.12-0.sql000066400000000000000000000006511507310017400276150ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.find_and_modify processes a mongo wire protocol findAndModify command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.find_and_modify( p_database_name text, p_message __CORE_SCHEMA_V2__.bson, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_find_and_modify$$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/find_and_modify--latest.sql000066400000000000000000000006511507310017400303740ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.find_and_modify processes a mongo wire protocol findAndModify command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.find_and_modify( p_database_name text, p_message __CORE_SCHEMA_V2__.bson, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_find_and_modify$$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/insert--0.103-0.sql000066400000000000000000000042341507310017400260720ustar00rootroot00000000000000 /* * processes a documentdb insert wire protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.insert( p_database_name text, p_insert __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.insert(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'inserts documents into a documentdb collection for wire protocol command'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one( p_collection_id bigint, p_shard_key_value bigint, p_document __CORE_SCHEMA_V2__.bson, p_transaction_id text) RETURNS bool LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,text) IS 'internal command to insert one document into a collection'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_insert_internal_spec __CORE_SCHEMA_V2__.bson, p_insert_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_worker$$; /* insert procedure will use when not called inside transaction */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_V2__.insert_bulk( IN p_database_name text, IN p_insert __CORE_SCHEMA_V2__.bson, IN p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, IN p_transaction_id text default NULL, INOUT p_result __CORE_SCHEMA_V2__.bson default NULL, INOUT p_success boolean default NULL) LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_bulk$$; COMMENT ON PROCEDURE __API_SCHEMA_V2__.insert_bulk(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text,__CORE_SCHEMA_V2__.bson,boolean) IS 'inserts documents into a collection for a wire protocol command outside transaction'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/insert--0.16-0.sql000066400000000000000000000027221507310017400260150ustar00rootroot00000000000000 /* * processes a documentdb insert wire protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.insert( p_database_name text, p_insert __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.insert(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'inserts documents into a documentdb collection for wire protocol command'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one( p_collection_id bigint, p_shard_key_value bigint, p_document __CORE_SCHEMA_V2__.bson, p_transaction_id text) RETURNS bool LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,text) IS 'internal command to insert one document into a collection'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_insert_internal_spec __CORE_SCHEMA_V2__.bson, p_insert_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_worker$$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/insert--latest.sql000066400000000000000000000042341507310017400265700ustar00rootroot00000000000000 /* * processes a documentdb insert wire protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.insert( p_database_name text, p_insert __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.insert(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'inserts documents into a documentdb collection for wire protocol command'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one( p_collection_id bigint, p_shard_key_value bigint, p_document __CORE_SCHEMA_V2__.bson, p_transaction_id text) RETURNS bool LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,text) IS 'internal command to insert one document into a collection'; /* Command: insert */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.insert_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_insert_internal_spec __CORE_SCHEMA_V2__.bson, p_insert_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_worker$$; /* insert procedure will use when not called inside transaction */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_V2__.insert_bulk( IN p_database_name text, IN p_insert __CORE_SCHEMA_V2__.bson, IN p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, IN p_transaction_id text default NULL, INOUT p_result __CORE_SCHEMA_V2__.bson default NULL, INOUT p_success boolean default NULL) LANGUAGE C AS 'MODULE_PATHNAME', $$command_insert_bulk$$; COMMENT ON PROCEDURE __API_SCHEMA_V2__.insert_bulk(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text,__CORE_SCHEMA_V2__.bson,boolean) IS 'inserts documents into a collection for a wire protocol command outside transaction'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/insert_one_helper--0.12-0.sql000066400000000000000000000016121507310017400302060ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.insert_one is a convenience function for inserting a single * single document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.insert_one( p_database_name text, p_collection_name text, p_document __CORE_SCHEMA_V2__.bson, p_transaction_id text default null) RETURNS __CORE_SCHEMA_V2__.bson SET search_path TO __CORE_SCHEMA_V2__, pg_catalog AS $fn$ DECLARE v_insert __CORE_SCHEMA_V2__.bson; p_resultBson __CORE_SCHEMA_V2__.bson; BEGIN v_insert := ('{"insert":"' || p_collection_name || '" }')::bson; SELECT p_result INTO p_resultBson FROM __API_SCHEMA_V2__.insert( p_database_name, v_insert, p_document::bsonsequence, p_transaction_id); RETURN p_resultBson; END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_V2__.insert_one(text,text,__CORE_SCHEMA_V2__.bson,text) IS 'insert one document into a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/insert_one_helper--latest.sql000066400000000000000000000016121507310017400307650ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.insert_one is a convenience function for inserting a single * single document. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.insert_one( p_database_name text, p_collection_name text, p_document __CORE_SCHEMA_V2__.bson, p_transaction_id text default null) RETURNS __CORE_SCHEMA_V2__.bson SET search_path TO __CORE_SCHEMA_V2__, pg_catalog AS $fn$ DECLARE v_insert __CORE_SCHEMA_V2__.bson; p_resultBson __CORE_SCHEMA_V2__.bson; BEGIN v_insert := ('{"insert":"' || p_collection_name || '" }')::bson; SELECT p_result INTO p_resultBson FROM __API_SCHEMA_V2__.insert( p_database_name, v_insert, p_document::bsonsequence, p_transaction_id); RETURN p_resultBson; END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_V2__.insert_one(text,text,__CORE_SCHEMA_V2__.bson,text) IS 'insert one document into a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/query_cursors_aggregate--0.103.sql000066400000000000000000000047721507310017400313730ustar00rootroot00000000000000-- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.aggregate_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_aggregate_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.find_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_find_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_collections_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_collections_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_indexes_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_indexes_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.cursor_get_more( database text, getMoreSpec __CORE_SCHEMA_V2__.bson, continuationSpec __CORE_SCHEMA_V2__.bson, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_cursor_get_more$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/query_cursors_aggregate--0.12-0.sql000066400000000000000000000040231507310017400314340ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.aggregate_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_aggregate_cursor_first_page$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.find_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_find_cursor_first_page$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_collections_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_collections_cursor_first_page$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_indexes_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_indexes_cursor_first_page$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.cursor_get_more( database text, getMoreSpec __CORE_SCHEMA_V2__.bson, continuationSpec __CORE_SCHEMA_V2__.bson, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_cursor_get_more$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/query_cursors_aggregate--latest.sql000066400000000000000000000047721507310017400322260ustar00rootroot00000000000000-- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.aggregate_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_aggregate_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.find_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_find_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_collections_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_collections_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_indexes_cursor_first_page( database text, commandSpec __CORE_SCHEMA_V2__.bson, cursorId int8 DEFAULT 0, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson, OUT persistConnection bool, OUT cursorId int8) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_list_indexes_cursor_first_page$function$; -- CODESYNC: See PostProcessCursorPage at src/commands/cursors.c when modifying the OUT variables CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.cursor_get_more( database text, getMoreSpec __CORE_SCHEMA_V2__.bson, continuationSpec __CORE_SCHEMA_V2__.bson, OUT cursorPage __CORE_SCHEMA_V2__.bson, OUT continuation __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_cursor_get_more$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/query_cursors_single_page--0.10-0.sql000066400000000000000000000010501507310017400317560ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA__.count_query(database text, countSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_count_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA__.distinct_query(database text, distinctSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_distinct_query$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/query_cursors_single_page--latest.sql000066400000000000000000000010501507310017400325370ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA__.count_query(database text, countSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_count_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA__.distinct_query(database text, distinctSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_distinct_query$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/update--0.103-0.sql000066400000000000000000000061571507310017400260560ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.update processes a documentdb update wire-protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update( p_database_name text, p_update __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_update$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.update(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'update documents in a collection'; CREATE OR REPLACE PROCEDURE __API_SCHEMA_V2__.update_bulk( p_database_name text, p_update __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence DEFAULT NULL, p_transaction_id text DEFAULT NULL, p_result INOUT __CORE_SCHEMA_V2__.bson DEFAULT NULL, p_success INOUT boolean DEFAULT NULL) LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_bulk$$; COMMENT ON PROCEDURE __API_SCHEMA_V2__.update_bulk(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text,__CORE_SCHEMA_V2__.bson,boolean) IS 'update documents in a collection in a non-transactional manner'; /* Command: update */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one( p_collection_id bigint, p_shard_key_value bigint, p_query __CORE_SCHEMA_V2__.bson, p_update __CORE_SCHEMA_V2__.bson, p_shard_key __CORE_SCHEMA_V2__.bson, p_is_upsert bool, p_sort __CORE_SCHEMA_V2__.bson, /* * p_return_old_or_new: see update.c/UpdateReturnValue enum: * * NULL -> do not return * false -> return old document * true -> return new document */ p_return_old_or_new bool, p_return_fields __CORE_SCHEMA_V2__.bson, p_array_filters __CORE_SCHEMA_V2__.bson, p_transaction_id text, OUT o_is_row_updated bool, OUT o_update_skipped bool, OUT o_is_retry bool, OUT o_reinsert_document __CORE_SCHEMA_V2__.bson, OUT o_upserted_object_id bytea, OUT o_result_document __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,text) IS 'updates a single document in a collection'; /* Command: update_worker */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec __CORE_SCHEMA_V2__.bson, p_update_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_worker$$; /* Helper function for multi-update to track number of updated documents */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_update_returned_value(shard_key_id bigint) RETURNS int LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_update_returned_value$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/update--0.16-0.sql000066400000000000000000000050121507310017400257660ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.update processes a documentdb update wire-protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update( p_database_name text, p_update __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_update$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.update(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'update documents in a collection'; /* Command: update */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one( p_collection_id bigint, p_shard_key_value bigint, p_query __CORE_SCHEMA_V2__.bson, p_update __CORE_SCHEMA_V2__.bson, p_shard_key __CORE_SCHEMA_V2__.bson, p_is_upsert bool, p_sort __CORE_SCHEMA_V2__.bson, /* * p_return_old_or_new: see update.c/UpdateReturnValue enum: * * NULL -> do not return * false -> return old document * true -> return new document */ p_return_old_or_new bool, p_return_fields __CORE_SCHEMA_V2__.bson, p_array_filters __CORE_SCHEMA_V2__.bson, p_transaction_id text, OUT o_is_row_updated bool, OUT o_update_skipped bool, OUT o_is_retry bool, OUT o_reinsert_document __CORE_SCHEMA_V2__.bson, OUT o_upserted_object_id bytea, OUT o_result_document __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,text) IS 'updates a single document in a collection'; /* Command: update_worker */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec __CORE_SCHEMA_V2__.bson, p_update_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_worker$$; /* Helper function for multi-update to track number of updated documents */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_update_returned_value(shard_key_id bigint) RETURNS int LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_update_returned_value$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_crud/update--latest.sql000066400000000000000000000061571507310017400265540ustar00rootroot00000000000000 /* * __API_SCHEMA_V2__.update processes a documentdb update wire-protocol command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update( p_database_name text, p_update __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence default NULL, p_transaction_id text default NULL, p_result OUT __CORE_SCHEMA_V2__.bson, p_success OUT boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_update$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.update(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text) IS 'update documents in a collection'; CREATE OR REPLACE PROCEDURE __API_SCHEMA_V2__.update_bulk( p_database_name text, p_update __CORE_SCHEMA_V2__.bson, p_insert_documents __CORE_SCHEMA_V2__.bsonsequence DEFAULT NULL, p_transaction_id text DEFAULT NULL, p_result INOUT __CORE_SCHEMA_V2__.bson DEFAULT NULL, p_success INOUT boolean DEFAULT NULL) LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_bulk$$; COMMENT ON PROCEDURE __API_SCHEMA_V2__.update_bulk(text,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bsonsequence,text,__CORE_SCHEMA_V2__.bson,boolean) IS 'update documents in a collection in a non-transactional manner'; /* Command: update */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one( p_collection_id bigint, p_shard_key_value bigint, p_query __CORE_SCHEMA_V2__.bson, p_update __CORE_SCHEMA_V2__.bson, p_shard_key __CORE_SCHEMA_V2__.bson, p_is_upsert bool, p_sort __CORE_SCHEMA_V2__.bson, /* * p_return_old_or_new: see update.c/UpdateReturnValue enum: * * NULL -> do not return * false -> return old document * true -> return new document */ p_return_old_or_new bool, p_return_fields __CORE_SCHEMA_V2__.bson, p_array_filters __CORE_SCHEMA_V2__.bson, p_transaction_id text, OUT o_is_row_updated bool, OUT o_update_skipped bool, OUT o_is_retry bool, OUT o_reinsert_document __CORE_SCHEMA_V2__.bson, OUT o_upserted_object_id bytea, OUT o_result_document __CORE_SCHEMA_V2__.bson) RETURNS record LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_one$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.update_one(bigint,bigint,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,bool,__CORE_SCHEMA_V2__.bson,__CORE_SCHEMA_V2__.bson,text) IS 'updates a single document in a collection'; /* Command: update_worker */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.update_worker( p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec __CORE_SCHEMA_V2__.bson, p_update_internal_docs __CORE_SCHEMA_V2__.bsonsequence, p_transaction_id text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $$command_update_worker$$; /* Helper function for multi-update to track number of updated documents */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_update_returned_value(shard_key_id bigint) RETURNS int LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_update_returned_value$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/000077500000000000000000000000001507310017400243605ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/coll_stats--0.16-0.sql000066400000000000000000000017601507310017400300500ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.coll_stats( IN p_database_name text, IN p_collection_name text, IN p_scale float8 DEFAULT 1) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_coll_stats$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.coll_stats(text, text, float8) IS 'Returns variety of storage statistics for a given collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.coll_stats_worker( IN p_database_name text, IN p_collection_name text, IN p_scale float8 DEFAULT 1) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_coll_stats_worker$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.coll_stats_aggregation( IN p_database_name text, IN p_collection_name text, IN p_collStatsSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_coll_stats_aggregation$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/coll_stats--latest.sql000066400000000000000000000017601507310017400306230ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.coll_stats( IN p_database_name text, IN p_collection_name text, IN p_scale float8 DEFAULT 1) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_coll_stats$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.coll_stats(text, text, float8) IS 'Returns variety of storage statistics for a given collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.coll_stats_worker( IN p_database_name text, IN p_collection_name text, IN p_scale float8 DEFAULT 1) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_coll_stats_worker$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.coll_stats_aggregation( IN p_database_name text, IN p_collection_name text, IN p_collStatsSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_coll_stats_aggregation$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/current_op--0.101-0.sql000066400000000000000000000016211507310017400301300ustar00rootroot00000000000000/* Add functions for the currentOp aggregation stage */ /* Spec contains { allUsers: , idleConnections: , idleCursors: , idleSessions: , localOps: } */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_aggregation; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_aggregation(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS SETOF __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$command_current_op_aggregation$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_worker; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_worker(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT AS 'MODULE_PATHNAME', $function$command_current_op_worker$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/current_op--0.102-0.sql000066400000000000000000000023171507310017400301340ustar00rootroot00000000000000/* Add functions for the currentOp aggregation stage */ /* Spec contains { allUsers: , idleConnections: , idleCursors: , idleSessions: , localOps: } */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_aggregation; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_aggregation(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS SETOF __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$command_current_op_aggregation$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_worker; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_worker(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT AS 'MODULE_PATHNAME', $function$command_current_op_worker$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.current_op_command; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.current_op_command(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT AS 'MODULE_PATHNAME', $function$command_current_op$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/current_op--latest.sql000066400000000000000000000023171507310017400306330ustar00rootroot00000000000000/* Add functions for the currentOp aggregation stage */ /* Spec contains { allUsers: , idleConnections: , idleCursors: , idleSessions: , localOps: } */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_aggregation; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_aggregation(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS SETOF __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$command_current_op_aggregation$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.current_op_worker; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.current_op_worker(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT AS 'MODULE_PATHNAME', $function$command_current_op_worker$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.current_op_command; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.current_op_command(p_spec __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE STRICT AS 'MODULE_PATHNAME', $function$command_current_op$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/db_stats--0.24-0.sql000066400000000000000000000011251507310017400274760ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.db_stats( IN p_database_name text, IN p_scale float8 DEFAULT 1, IN p_freeStorage bool DEFAULT false) RETURNS __CORE_SCHEMA__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_db_stats$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.db_stats(text, float8, bool) IS 'Returns storage statistics for a given database'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.db_stats_worker( IN p_collection_ids bigint[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_db_stats_worker$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/db_stats--latest.sql000066400000000000000000000011251507310017400302520ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.db_stats( IN p_database_name text, IN p_scale float8 DEFAULT 1, IN p_freeStorage bool DEFAULT false) RETURNS __CORE_SCHEMA__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_db_stats$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.db_stats(text, float8, bool) IS 'Returns storage statistics for a given database'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.db_stats_worker( IN p_collection_ids bigint[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE C AS 'MODULE_PATHNAME', $function$command_db_stats_worker$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/index_stats--0.24-0.sql000066400000000000000000000010741507310017400302230ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.index_stats_aggregation( IN p_database_name text, IN p_collection_name text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$command_index_stats_aggregation$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.index_stats_worker( IN p_database_name text, IN p_collection_name text) RETURNS __CORE_SCHEMA__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_index_stats_worker$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/index_stats--latest.sql000066400000000000000000000010741507310017400307770ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.index_stats_aggregation( IN p_database_name text, IN p_collection_name text) RETURNS SETOF __CORE_SCHEMA__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT ROWS 100 AS 'MODULE_PATHNAME', $function$command_index_stats_aggregation$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.index_stats_worker( IN p_database_name text, IN p_collection_name text) RETURNS __CORE_SCHEMA__.bson LANGUAGE C STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_index_stats_worker$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/validate--0.24-0.sql000066400000000000000000000006211507310017400274640ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.validate(database text, validateSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_validate$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.validate(text, __CORE_SCHEMA__.bson) IS 'Validates the indexes for a given collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/commands_diagnostic/validate--latest.sql000066400000000000000000000006211507310017400302400ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.validate(database text, validateSpec __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_validate$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.validate(text, __CORE_SCHEMA__.bson) IS 'Validates the indexes for a given collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/geospatial/000077500000000000000000000000001507310017400225035ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/geospatial/bson_gist_extensibility_functions--0.16-0.sql000066400000000000000000000074451507310017400330650ustar00rootroot00000000000000-- Index options function for bson_gist_geometry_ops_2d operator class family CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_options(internal) RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_gist_geometry_2d_options$function$; -- GIST compress support function for 2d index, this internally uses Postgis GIST compress support function -- geometry_gist_compress_2d. -- It extract the geomtery from a `bson` document and compresses it into the box2df type for storage. It also -- apply additional validations on geometries e.g. bound checks. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_compress(internal) RETURNS INTERNAL LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_2d_compress$function$; -- GIST distance support functions for bson, used for ORDER BY and nearest neighbour queries CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_distance_2d(internal, __CORE_SCHEMA__.bson, integer) RETURNS float8 LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_distance_2d$function$; -- GIST consistent support functions for bson, which checks if the query can be satisfied by the key stored in index CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_consistent_2d(internal, __CORE_SCHEMA__.bson, integer) RETURNS bool LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_consistent_2d$function$; -- Geography type GIST support functions for bson -- Index options function for bson_gist_geography_ops_2d operator class family CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_options(internal) RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_gist_geography_options$function$; -- GIST compress support function for 2dsphere index, this internally uses Postgis GIST compress support function -- It extract the geography from a `bson` document and compresses it into the gidx type for storage CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_compress(internal) RETURNS INTERNAL LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_compress$function$; -- GIST distance support functions for bson, used for ORDER BY and nearest neighbour queries CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_distance(internal, __CORE_SCHEMA__.bson, integer) RETURNS float8 LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_distance$function$; -- GIST consistent support functions for bson, which checks if the query can be satisfied by the key stored in index CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_consistent(internal, __CORE_SCHEMA__.bson, integer) RETURNS bool LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_consistent$function$; -- bson_validate_geography function is used to make the 2dsphere indexes sparse with IS NOT NULL construct -- and also used with geospatial query operators to match the 2dsphere index predicate -- for detailed info look at the description of `bson_validate_geography` C function CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_validate_geography( p_document __CORE_SCHEMA__.bson, p_keyPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_validate_geography$function$; -- for detailed info look at the description of `bson_validate_geometry` C function CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_validate_geometry( p_document __CORE_SCHEMA__.bson, p_keyPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_validate_geometry$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/geospatial/bson_gist_extensibility_functions--latest.sql000066400000000000000000000074451507310017400336400ustar00rootroot00000000000000-- Index options function for bson_gist_geometry_ops_2d operator class family CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_options(internal) RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_gist_geometry_2d_options$function$; -- GIST compress support function for 2d index, this internally uses Postgis GIST compress support function -- geometry_gist_compress_2d. -- It extract the geomtery from a `bson` document and compresses it into the box2df type for storage. It also -- apply additional validations on geometries e.g. bound checks. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_2d_compress(internal) RETURNS INTERNAL LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_2d_compress$function$; -- GIST distance support functions for bson, used for ORDER BY and nearest neighbour queries CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_distance_2d(internal, __CORE_SCHEMA__.bson, integer) RETURNS float8 LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_distance_2d$function$; -- GIST consistent support functions for bson, which checks if the query can be satisfied by the key stored in index CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geometry_consistent_2d(internal, __CORE_SCHEMA__.bson, integer) RETURNS bool LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geometry_consistent_2d$function$; -- Geography type GIST support functions for bson -- Index options function for bson_gist_geography_ops_2d operator class family CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_options(internal) RETURNS void LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_gist_geography_options$function$; -- GIST compress support function for 2dsphere index, this internally uses Postgis GIST compress support function -- It extract the geography from a `bson` document and compresses it into the gidx type for storage CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_compress(internal) RETURNS INTERNAL LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_compress$function$; -- GIST distance support functions for bson, used for ORDER BY and nearest neighbour queries CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_distance(internal, __CORE_SCHEMA__.bson, integer) RETURNS float8 LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_distance$function$; -- GIST consistent support functions for bson, which checks if the query can be satisfied by the key stored in index CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_gist_geography_consistent(internal, __CORE_SCHEMA__.bson, integer) RETURNS bool LANGUAGE C PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_gist_geography_consistent$function$; -- bson_validate_geography function is used to make the 2dsphere indexes sparse with IS NOT NULL construct -- and also used with geospatial query operators to match the 2dsphere index predicate -- for detailed info look at the description of `bson_validate_geography` C function CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_validate_geography( p_document __CORE_SCHEMA__.bson, p_keyPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_validate_geography$function$; -- for detailed info look at the description of `bson_validate_geometry` C function CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_validate_geometry( p_document __CORE_SCHEMA__.bson, p_keyPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_validate_geometry$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/000077500000000000000000000000001507310017400225065ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_indexbounds_functions--0.102-0.sql000066400000000000000000000053171507310017400315400ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_eq(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lt(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lte(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_gt(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_gte(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_eq(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_equal$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_lt(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_lte(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_gt(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_gte(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_gte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_indexbounds_functions--latest.sql000066400000000000000000000053171507310017400322370ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_eq(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lt(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lte(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_gt(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_gte(__CORE_SCHEMA__.bson,__API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_eq(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_equal$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_lt(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_lte(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_gt(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bsonquery_gte(__CORE_SCHEMA__.bsonquery, __API_SCHEMA_INTERNAL_V2__.bsonindexbounds) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bsonquery_gte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_rum_index_transform_functions--0.107-0.sql000066400000000000000000000003401507310017400332770ustar00rootroot00000000000000CREATE FUNCTION __API_SCHEMA_INTERNAL__.bson_index_transform(bytea, bytea, int2, internal) RETURNS bytea LANGUAGE C IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$gin_bson_composite_index_term_transform$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_rum_index_transform_functions--latest.sql000066400000000000000000000003401507310017400337710ustar00rootroot00000000000000CREATE FUNCTION __API_SCHEMA_INTERNAL__.bson_index_transform(bytea, bytea, int2, internal) RETURNS bytea LANGUAGE C IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$gin_bson_composite_index_term_transform$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_rum_ordering_functions--0.106-0.sql000066400000000000000000000004051507310017400317070ustar00rootroot00000000000000 CREATE FUNCTION __API_SCHEMA_INTERNAL__.bson_rum_composite_ordering(bytea, __CORE_SCHEMA__.bson, int2, internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE C IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$gin_bson_composite_ordering_transform$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/bson_rum_ordering_functions--latest.sql000066400000000000000000000004051507310017400324020ustar00rootroot00000000000000 CREATE FUNCTION __API_SCHEMA_INTERNAL__.bson_rum_composite_ordering(bytea, __CORE_SCHEMA__.bson, int2, internal) RETURNS __CORE_SCHEMA__.bson LANGUAGE C IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$gin_bson_composite_ordering_transform$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/build_index_background--0.106-0.sql000066400000000000000000000007641507310017400305770ustar00rootroot00000000000000/* * Drop-in replacement for build_index_concurrently. This will be called periodically by the * background worker framework and will coexist with the previous UDF until it reaches * stability. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_background(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_background$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_background(int) IS 'Builds a index for a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/build_index_background--latest.sql000066400000000000000000000007641507310017400312720ustar00rootroot00000000000000/* * Drop-in replacement for build_index_concurrently. This will be called periodically by the * background worker framework and will coexist with the previous UDF until it reaches * stability. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_background(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_background$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_background(int) IS 'Builds a index for a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_builtin_id_index--0.10-0.sql000066400000000000000000000012311507310017400306460ustar00rootroot00000000000000 DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_builtin_id_index; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_builtin_id_index( collection_id bigint, register_id_index bool default true ) RETURNS void AS $fn$ DECLARE final_record record; BEGIN /* sync collection_pk_%s with index.h */ EXECUTE format($$ ALTER TABLE __API_DATA_SCHEMA__.documents_%s ADD CONSTRAINT collection_pk_%s PRIMARY KEY (shard_key_value, object_id) $$, collection_id, collection_id); IF register_id_index THEN PERFORM __API_SCHEMA_INTERNAL__.record_id_index(collection_id); END IF; END; $fn$ LANGUAGE plpgsql; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_builtin_id_index--latest.sql000066400000000000000000000012311507310017400314270ustar00rootroot00000000000000 DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_builtin_id_index; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_builtin_id_index( collection_id bigint, register_id_index bool default true ) RETURNS void AS $fn$ DECLARE final_record record; BEGIN /* sync collection_pk_%s with index.h */ EXECUTE format($$ ALTER TABLE __API_DATA_SCHEMA__.documents_%s ADD CONSTRAINT collection_pk_%s PRIMARY KEY (shard_key_value, object_id) $$, collection_id, collection_id); IF register_id_index THEN PERFORM __API_SCHEMA_INTERNAL__.record_id_index(collection_id); END IF; END; $fn$ LANGUAGE plpgsql; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_index_background--0.104-0.sql000066400000000000000000000052331507310017400307350ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_concurrently$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(int) IS 'Builds a index for a collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status( IN p_arg __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT complete boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(__CORE_SCHEMA__.bson) IS 'Calls check_build_index_status_internal.'; -- TODO: DROP the __API_SCHEMA__.create_indexes_background CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_indexes_background( p_database_name text, p_index_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_indexes_background(text, __CORE_SCHEMA__.bson) IS 'Submits the build index(es) requests on a collection and waits for them to finish.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal( IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(__CORE_SCHEMA__.bson) IS 'Checks for build index(es) requests to finish.'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(text,__CORE_SCHEMA__.bson) IS 'Queues the Index creation request(s) on a collection'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.schedule_background_index_build_workers; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(IN p_force_override boolean DEFAULT false) RETURNS void LANGUAGE C AS 'MODULE_PATHNAME', $$schedule_background_index_build_jobs$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(boolean) IS 'Schedules the background index build cron job.';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_index_background--0.108-0.sql000066400000000000000000000065371507310017400307510ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_concurrently$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(int) IS 'Builds a index for a collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status( IN p_arg __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT complete boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(__CORE_SCHEMA__.bson) IS 'Calls check_build_index_status_internal.'; -- TODO: DROP the __API_SCHEMA__.create_indexes_background CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_indexes_background( p_database_name text, p_index_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_indexes_background(text, __CORE_SCHEMA__.bson) IS 'Submits the build index(es) requests on a collection and waits for them to finish.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal( IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(__CORE_SCHEMA__.bson) IS 'Checks for build index(es) requests to finish.'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(text,__CORE_SCHEMA__.bson) IS 'Queues the Index creation request(s) on a collection'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.schedule_background_index_build_workers; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(IN p_force_override boolean DEFAULT false) RETURNS void LANGUAGE C AS 'MODULE_PATHNAME', $$schedule_background_index_build_jobs$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(boolean) IS 'Schedules the background index build cron job.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.reindex_index_background( p_database_name text, p_reindex_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_reindex_index_background$$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.reindex_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.reindex_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_reindex_index_background_internal$$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_index_background--0.23-0.sql000066400000000000000000000070531507310017400306570ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_concurrently$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(int) IS 'Builds a index for a collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status( IN p_arg __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT complete boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(__CORE_SCHEMA__.bson) IS 'Calls check_build_index_status_internal using run_command_on_coordinator.'; -- TODO: DROP the __API_SCHEMA__.create_indexes_background CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_indexes_background( p_database_name text, p_index_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_indexes_background(text, __CORE_SCHEMA__.bson) IS 'Submits the build index(es) requests on a collection and waits for them to finish.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal( IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(__CORE_SCHEMA__.bson) IS 'Checks for build index(es) requests to finish.'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(text,__CORE_SCHEMA__.bson) IS 'Queues the Index creation request(s) on a collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_workers(p_max_num_active_user_index_builds int default current_setting(__SINGLE_QUOTED_STRING__(__API_GUC_PREFIX__) || '.maxNumActiveUsersIndexBuilds')::int, p_user_index_build_schedule int default current_setting(__SINGLE_QUOTED_STRING__(__API_GUC_PREFIX__) || '.indexBuildScheduleInSec')::int) RETURNS void AS $fn$ DECLARE v_indexBuildScheduleInterval text; BEGIN IF citus_is_coordinator() THEN SELECT '* * * * *' INTO v_indexBuildScheduleInterval; IF p_user_index_build_schedule < 60 THEN SELECT p_user_index_build_schedule || ' seconds' INTO v_indexBuildScheduleInterval; END IF; PERFORM cron.unschedule(jobid) FROM cron.job WHERE jobname LIKE __SINGLE_QUOTED_STRING__(__EXTENSION_OBJECT_PREFIX_V2__) || '_index_build_task_%'; FOR i IN 1..p_max_num_active_user_index_builds LOOP PERFORM cron.schedule(__SINGLE_QUOTED_STRING__(__EXTENSION_OBJECT_PREFIX_V2__) || '_index_build_task_' || i, v_indexBuildScheduleInterval, format($$ CALL __API_SCHEMA_INTERNAL__.build_index_concurrently(%s) $$, i)); END LOOP; ELSE RAISE EXCEPTION 'schedule_background_index_build_workers() to be run on coordinator only'; END IF; END; $fn$ LANGUAGE plpgsql;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_index_background--latest.sql000066400000000000000000000065371507310017400314420ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(IN p_job_index int) LANGUAGE C AS 'MODULE_PATHNAME', $procedure$command_build_index_concurrently$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(int) IS 'Builds a index for a collection'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status( IN p_arg __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT complete boolean) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(__CORE_SCHEMA__.bson) IS 'Calls check_build_index_status_internal.'; -- TODO: DROP the __API_SCHEMA__.create_indexes_background CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_indexes_background( p_database_name text, p_index_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_indexes_background(text, __CORE_SCHEMA__.bson) IS 'Submits the build index(es) requests on a collection and waits for them to finish.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal( IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_check_build_index_status_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(__CORE_SCHEMA__.bson) IS 'Checks for build index(es) requests to finish.'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_background_internal$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(text,__CORE_SCHEMA__.bson) IS 'Queues the Index creation request(s) on a collection'; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.schedule_background_index_build_workers; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(IN p_force_override boolean DEFAULT false) RETURNS void LANGUAGE C AS 'MODULE_PATHNAME', $$schedule_background_index_build_jobs$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(boolean) IS 'Schedules the background index build cron job.'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.reindex_index_background( p_database_name text, p_reindex_spec __CORE_SCHEMA__.bson, OUT retval __CORE_SCHEMA__.bson, OUT ok boolean, OUT requests __CORE_SCHEMA__.bson) RETURNS record LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_reindex_index_background$$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.reindex_indexes_background_internal CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.reindex_indexes_background_internal( IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_reindex_index_background_internal$$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_indexes_non_concurrently--0.21-0.sql000066400000000000000000000010141507310017400324560ustar00rootroot00000000000000/* * This is nearly same as calling __API_SCHEMA__.create_indexes() within a * transaction block. */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.create_indexes_non_concurrently; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.create_indexes_non_concurrently( IN p_database_name text, IN p_arg __CORE_SCHEMA_V2__.bson, IN p_skip_check_collection_create boolean default FALSE) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_non_concurrently$$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/create_indexes_non_concurrently--latest.sql000066400000000000000000000010141507310017400332350ustar00rootroot00000000000000/* * This is nearly same as calling __API_SCHEMA__.create_indexes() within a * transaction block. */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.create_indexes_non_concurrently; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.create_indexes_non_concurrently( IN p_database_name text, IN p_arg __CORE_SCHEMA_V2__.bson, IN p_skip_check_collection_create boolean default FALSE) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $$command_create_indexes_non_concurrently$$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/drop_indexes--0.12-0.sql000066400000000000000000000006611507310017400265050ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA__.drop_indexes(IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson, INOUT retval __CORE_SCHEMA__.bson DEFAULT null) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$command_drop_indexes$procedure$; COMMENT ON PROCEDURE __API_SCHEMA__.drop_indexes(text, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) IS 'drop index(es) from a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/drop_indexes--latest.sql000066400000000000000000000006611507310017400272640ustar00rootroot00000000000000CREATE OR REPLACE PROCEDURE __API_SCHEMA__.drop_indexes(IN p_database_name text, IN p_arg __CORE_SCHEMA__.bson, INOUT retval __CORE_SCHEMA__.bson DEFAULT null) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$command_drop_indexes$procedure$; COMMENT ON PROCEDURE __API_SCHEMA__.drop_indexes(text, __CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) IS 'drop index(es) from a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_build_is_in_progress--0.10-0.sql000066400000000000000000000002761507310017400314150ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_build_is_in_progress( p_index_id int) RETURNS boolean LANGUAGE C AS 'MODULE_PATHNAME', $$command_index_build_is_in_progress$$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_build_is_in_progress--latest.sql000066400000000000000000000002761507310017400321760ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_build_is_in_progress( p_index_id int) RETURNS boolean LANGUAGE C AS 'MODULE_PATHNAME', $$command_index_build_is_in_progress$$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_spec_as_bson--0.10-0.sql000066400000000000000000000006731507310017400276500ustar00rootroot00000000000000/* returns a bson object for given index spec */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.index_spec_as_bson; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_spec_as_bson( index_spec __API_CATALOG_SCHEMA__.index_spec_type, for_get_indexes boolean default false, namespaceName text default NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$index_spec_as_bson$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_spec_as_bson--latest.sql000066400000000000000000000006731507310017400304310ustar00rootroot00000000000000/* returns a bson object for given index spec */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.index_spec_as_bson; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_spec_as_bson( index_spec __API_CATALOG_SCHEMA__.index_spec_type, for_get_indexes boolean default false, namespaceName text default NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$index_spec_as_bson$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_spec_options_are_equivalent--0.10-0.sql000066400000000000000000000007411507310017400327770ustar00rootroot00000000000000/* * Returns true if index options provided by given two index specs are * equivalent, i.e.: compares everything except index names. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_spec_options_are_equivalent( left_index_spec __API_CATALOG_SCHEMA__.index_spec_type, right_index_spec __API_CATALOG_SCHEMA__.index_spec_type) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$index_spec_options_are_equivalent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/index_spec_options_are_equivalent--latest.sql000066400000000000000000000007411507310017400335600ustar00rootroot00000000000000/* * Returns true if index options provided by given two index specs are * equivalent, i.e.: compares everything except index names. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.index_spec_options_are_equivalent( left_index_spec __API_CATALOG_SCHEMA__.index_spec_type, right_index_spec __API_CATALOG_SCHEMA__.index_spec_type) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$index_spec_options_are_equivalent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/record_id_index--0.10-0.sql000066400000000000000000000004421507310017400271360ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.record_id_index( p_collection_id bigint) RETURNS VOID LANGUAGE C AS 'MODULE_PATHNAME', $$command_record_id_index$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.record_id_index(bigint) IS 'record built-in "_id" to index metadata';documentdb-0.108-0/pg_documentdb/sql/udfs/index_mgmt/record_id_index--latest.sql000066400000000000000000000004421507310017400277170ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.record_id_index( p_collection_id bigint) RETURNS VOID LANGUAGE C AS 'MODULE_PATHNAME', $$command_record_id_index$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.record_id_index(bigint) IS 'record built-in "_id" to index metadata';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/000077500000000000000000000000001507310017400221335ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection--0.10-0.sql000066400000000000000000000014331507310017400255760ustar00rootroot00000000000000 /* * __API_SCHEMA__.collection() can be used to query collections, e.g.: * SELECT * FROM __API_SCHEMA__.collection('db','collection') * * While this seems slow, we use the planner hook to replace this function * directly with the table, so we usually do not call it directly. * * Output arguments need to match data tables exactly. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.collection( p_database_name text, p_collection_name text, OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson, OUT creation_time timestamptz) RETURNS SETOF record LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_api_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.collection(text,text) IS 'query a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection--0.106-0.sql000066400000000000000000000014701507310017400256650ustar00rootroot00000000000000/* * __API_SCHEMA__.collection() can be used to query collections, e.g.: * SELECT * FROM __API_SCHEMA__.collection('db','collection') * * While this seems slow, we use the planner hook to replace this function * directly with the table, so we usually do not call it directly. * * Output arguments need to match data tables exactly. */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.collection(text,text); CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.collection( p_database_name text, p_collection_name text, OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF record LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_api_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.collection(text,text) IS 'query a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection--latest.sql000066400000000000000000000014701507310017400263600ustar00rootroot00000000000000/* * __API_SCHEMA__.collection() can be used to query collections, e.g.: * SELECT * FROM __API_SCHEMA__.collection('db','collection') * * While this seems slow, we use the planner hook to replace this function * directly with the table, so we usually do not call it directly. * * Output arguments need to match data tables exactly. */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.collection(text,text); CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.collection( p_database_name text, p_collection_name text, OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA__.bson, OUT document __CORE_SCHEMA__.bson) RETURNS SETOF record LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_api_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.collection(text,text) IS 'query a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_indexes_metadata_functions--0.10-0.sql000066400000000000000000000006321507310017400332450ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_index_id)() RETURNS integer LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_get_next_collection_index_id$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_index_id)() IS 'get next unique index id to be used in __API_CATALOG_SCHEMA__.collection_indexes';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_indexes_metadata_functions--latest.sql000066400000000000000000000006321507310017400340260ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_index_id)() RETURNS integer LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_get_next_collection_index_id$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_index_id)() IS 'get next unique index id to be used in __API_CATALOG_SCHEMA__.collection_indexes';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_metadata_functions--0.23-0.sql000066400000000000000000000017241507310017400315350ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_id)() RETURNS bigint LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_get_next_collection_id$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_id)() IS 'get next unique collection id to be used in __API_CATALOG_SCHEMA__.collections'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.ensure_valid_db_coll(text, text) RETURNS bool LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_ensure_valid_db_coll$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.collection_update_trigger() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN PERFORM __API_SCHEMA_INTERNAL_V2__.invalidate_collection_cache(); RETURN NULL; END; $function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.invalidate_collection_cache() RETURNS void LANGUAGE c AS 'MODULE_PATHNAME', $$command_invalidate_collection_cache$$;documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_metadata_functions--latest.sql000066400000000000000000000017241507310017400323120ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_id)() RETURNS bigint LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_get_next_collection_id$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.__EXTENSION_OBJECT__(_get_next_collection_id)() IS 'get next unique collection id to be used in __API_CATALOG_SCHEMA__.collections'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.ensure_valid_db_coll(text, text) RETURNS bool LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_ensure_valid_db_coll$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.collection_update_trigger() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN PERFORM __API_SCHEMA_INTERNAL_V2__.invalidate_collection_cache(); RETURN NULL; END; $function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.invalidate_collection_cache() RETURNS void LANGUAGE c AS 'MODULE_PATHNAME', $$command_invalidate_collection_cache$$;documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_triggers--0.21-0.sql000066400000000000000000000010161507310017400275030ustar00rootroot00000000000000/* Trigger function to validate dbname before a create collection */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.trigger_validate_dbname() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN PERFORM __API_SCHEMA_INTERNAL_V2__.validate_dbname(NEW.database_name); RETURN NEW; END; $function$; /* Function to validate dbname in the collecitons catalog table */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.validate_dbname(dbname text) RETURNS void LANGUAGE c AS 'MODULE_PATHNAME', $$validate_dbname$$; documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/collection_triggers--latest.sql000066400000000000000000000010161507310017400302620ustar00rootroot00000000000000/* Trigger function to validate dbname before a create collection */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.trigger_validate_dbname() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN PERFORM __API_SCHEMA_INTERNAL_V2__.validate_dbname(NEW.database_name); RETURN NEW; END; $function$; /* Function to validate dbname in the collecitons catalog table */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.validate_dbname(dbname text) RETURNS void LANGUAGE c AS 'MODULE_PATHNAME', $$validate_dbname$$; documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/empty_data_table--0.106-0.sql000066400000000000000000000024431507310017400270310ustar00rootroot00000000000000/* * This function returns rows from an empty table that mimics a documentdb collection data table * w.r.t. the data types of the columns. * * We need this to enable scenarios that require us to return an the equvalent of a empty collection when the collection does not exists. * * The planner hook for __API_SCHEMA__.collection('db', 'collName') will call this function * when the desired collection is not found. * * We could have made a similar change in the __API_SCHEMA__.collection() function itself, * but having a different function provides better debuggability, i.e., the EXPLAIN will * show "Function Scan on empty_data_table collection" instead of "Function Scan on collection". * The latter could happen for other reasons. */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.empty_data_table; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table( OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS SETOF record AS $fn$ BEGIN RETURN QUERY EXECUTE format($$SELECT 0::bigint, null::__CORE_SCHEMA_V2__.bson, null::__CORE_SCHEMA_V2__.bson WHERE false$$); END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table() IS 'mimics a data collection with 0 rows'; documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/empty_data_table--0.16-0.sql000066400000000000000000000025161507310017400267520ustar00rootroot00000000000000/* * This function returns rows from an empty table that mimics a documentdb collection data table * w.r.t. the data types of the columns. * * We need this to enable scenarios that require us to return an the equvalent of a empty collection when the collection does not exists. * * The planner hook for __API_SCHEMA__.collection('db', 'collName') will call this function * when the desired collection is not found. * * We could have made a similar change in the __API_SCHEMA__.collection() function itself, * but having a different function provides better debuggability, i.e., the EXPLAIN will * show "Function Scan on empty_data_table collection" instead of "Function Scan on collection". * The latter could happen for other reasons. */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.empty_data_table; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table( OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson, OUT creation_time timestamptz) RETURNS SETOF record AS $fn$ BEGIN RETURN QUERY EXECUTE format($$SELECT 0::bigint, null::__CORE_SCHEMA_V2__.bson, null::__CORE_SCHEMA_V2__.bson, null::timestamptz WHERE false$$); END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table() IS 'mimics a data collection with 0 rows';documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/empty_data_table--latest.sql000066400000000000000000000024431507310017400275240ustar00rootroot00000000000000/* * This function returns rows from an empty table that mimics a documentdb collection data table * w.r.t. the data types of the columns. * * We need this to enable scenarios that require us to return an the equvalent of a empty collection when the collection does not exists. * * The planner hook for __API_SCHEMA__.collection('db', 'collName') will call this function * when the desired collection is not found. * * We could have made a similar change in the __API_SCHEMA__.collection() function itself, * but having a different function provides better debuggability, i.e., the EXPLAIN will * show "Function Scan on empty_data_table collection" instead of "Function Scan on collection". * The latter could happen for other reasons. */ DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.empty_data_table; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table( OUT shard_key_value bigint, OUT object_id __CORE_SCHEMA_V2__.bson, OUT document __CORE_SCHEMA_V2__.bson) RETURNS SETOF record AS $fn$ BEGIN RETURN QUERY EXECUTE format($$SELECT 0::bigint, null::__CORE_SCHEMA_V2__.bson, null::__CORE_SCHEMA_V2__.bson WHERE false$$); END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.empty_data_table() IS 'mimics a data collection with 0 rows'; documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/list_databases--0.102-0.sql000066400000000000000000000003501507310017400265040ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_databases( p_list_databases_spec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$command_list_databases$$;documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/list_databases--latest.sql000066400000000000000000000003501507310017400272030ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.list_databases( p_list_databases_spec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$command_list_databases$$;documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/sharding_metadata_functions--0.10-0.sql000066400000000000000000000011231507310017400311660ustar00rootroot00000000000000/* get_shard_key_value returns the shard key value from the given document. * Returns the collection_id for non-sharded collections. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.get_shard_key_value( p_shard_key __CORE_SCHEMA__.bson, p_collection_id bigint, p_document __CORE_SCHEMA__.bson) RETURNS bigint LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $$command_get_shard_key_value$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.get_shard_key_value(__CORE_SCHEMA__.bson,bigint,__CORE_SCHEMA__.bson) IS 'return the shard key value for the given document'; documentdb-0.108-0/pg_documentdb/sql/udfs/metadata/sharding_metadata_functions--latest.sql000066400000000000000000000011231507310017400317470ustar00rootroot00000000000000/* get_shard_key_value returns the shard key value from the given document. * Returns the collection_id for non-sharded collections. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.get_shard_key_value( p_shard_key __CORE_SCHEMA__.bson, p_collection_id bigint, p_document __CORE_SCHEMA__.bson) RETURNS bigint LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $$command_get_shard_key_value$$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.get_shard_key_value(__CORE_SCHEMA__.bson,bigint,__CORE_SCHEMA__.bson) IS 'return the shard key value for the given document'; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/000077500000000000000000000000001507310017400225275ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_expression--0.103-0.sql000066400000000000000000000061371507310017400273500ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_map(document __CORE_SCHEMA__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_map(document __CORE_SCHEMA_V2__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_by_fields_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_by_fields_get$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_expression--0.22-0.sql000066400000000000000000000045161507310017400272670ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_map(document __CORE_SCHEMA__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_map(document __CORE_SCHEMA_V2__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_by_fields_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_by_fields_get$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_expression--latest.sql000066400000000000000000000061371507310017400300460ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_expression_get$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_expression_map(document __CORE_SCHEMA__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_map(document __CORE_SCHEMA_V2__.bson, sourceArrayName text, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_map$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson, isNullOnEmpty bool default false) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_get(document __CORE_SCHEMA_V2__.bson, expressionSpec __CORE_SCHEMA_V2__.bson, isNullOnEmpty bool, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_expression_partition_get$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_expression_partition_by_fields_get(document __CORE_SCHEMA__.bson, expressionSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_expression_partition_by_fields_get$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--0.101-0.sql000066400000000000000000000107721507310017400273230ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, overrideArray bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--0.102-0.sql000066400000000000000000000137171507310017400273260ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, overrideArray bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--0.104-0.sql000066400000000000000000000136151507310017400273250ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; -- DROP bson_dollar_merge_documents(bson, bson) in favor of bson_merge_documents(bson, bson, bool) DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, overrideArray bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--0.20-0.sql000066400000000000000000000075721507310017400272470ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--0.24-0.sql000066400000000000000000000103041507310017400272360ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/projection/bson_projection--latest.sql000066400000000000000000000136151507310017400300220ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson, collationString text) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$; -- DROP bson_dollar_merge_documents(bson, bson) in favor of bson_merge_documents(bson, bson, bool) DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson); CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, overrideArray bool) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/000077500000000000000000000000001507310017400215205ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_array--0.10-0.sql000066400000000000000000000015061507310017400265250ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_size(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_size$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_elemmatch(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_elemmatch$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_all(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_all$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_array--latest.sql000066400000000000000000000015061507310017400273060ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_size(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_size$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_elemmatch(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_elemmatch$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_all(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_all$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_comparison--0.104-1.sql000066400000000000000000000055741507310017400276570ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.dollar_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$dollar_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_eq(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_in(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_in$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_ne(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_ne$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_nin(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_nin$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_range$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_fullscan(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_fullscan$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_comparison--0.23-0.sql000066400000000000000000000051331507310017400275650ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.dollar_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$dollar_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_eq(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_in(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_in$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_ne(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_ne$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_nin(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_nin$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_range$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_comparison--latest.sql000066400000000000000000000055741507310017400303530ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.dollar_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$dollar_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_eq(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_in(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_in$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_ne(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_ne$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_nin(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_nin$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_range(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_range$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_fullscan(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_fullscan$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_element_bitwise--0.10-0.sql000066400000000000000000000033121507310017400305630ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_exists(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_exists$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_type(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_type$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_all_clear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_all_clear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_any_clear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_any_clear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_all_set(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_all_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_any_set(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_any_set$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_element_bitwise--latest.sql000066400000000000000000000033121507310017400313440ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_exists(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_exists$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_type(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_type$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_all_clear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_all_clear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_any_clear(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_any_clear$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_all_set(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_all_set$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_bits_any_set(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_bits_any_set$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_evaluation--0.19-0.sql000066400000000000000000000024271507310017400275720ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_regex(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_regex$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_expr(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_expr$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_expr(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_expr$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_json_schema(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c COST 100 IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_json_schema$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_mod(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_mod$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_evaluation--latest.sql000066400000000000000000000024271507310017400303420ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_regex(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_regex$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_expr(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_expr$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_expr(__CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson, __CORE_SCHEMA_V2__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_expr$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_json_schema(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c COST 100 IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_json_schema$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_mod(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_mod$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_geospatial--0.10-0.sql000066400000000000000000000011061507310017400275330ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_geowithin(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_geowithin$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_geointersects(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_geointersects$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_geospatial--latest.sql000066400000000000000000000011061507310017400303140ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_geowithin(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_geowithin$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_geointersects(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_geointersects$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_index_hints--0.106-0.sql000066400000000000000000000004601507310017400300070ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_index_hint(document __CORE_SCHEMA__.bson, index_name text, key_document __CORE_SCHEMA__.bson, is_sparse boolean) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_index_hint$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_index_hints--latest.sql000066400000000000000000000004601507310017400305020ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_index_hint(document __CORE_SCHEMA__.bson, index_name text, key_document __CORE_SCHEMA__.bson, is_sparse boolean) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_index_hint$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_negation--0.16-0.sql000066400000000000000000000021711507310017400272200ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_lte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_negation--latest.sql000066400000000000000000000021711507310017400277730ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_gte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_not_lte(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_not_lte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_selectivity--0.16-0.sql000066400000000000000000000003651507310017400277630ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity(internal, oid, internal, integer) RETURNS double precision LANGUAGE c STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_selectivity$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_selectivity--latest.sql000066400000000000000000000003651507310017400305360ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_selectivity(internal, oid, internal, integer) RETURNS double precision LANGUAGE c STABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_selectivity$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_text--0.24-0.sql000066400000000000000000000037631507310017400264070ustar00rootroot00000000000000 -- dummy function that accepts the query planner phase, and exists only to handle the support function handling -- to push down to the index. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_text(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c SUPPORT __API_CATALOG_SCHEMA__.dollar_support COST 10000000000 -- really dissuade the planner from using this and force the index. IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text$function$; -- dummy function that exists to support the index operator (below). Needs to be separate from above due to the -- 'tsquery' being an input. We can't generate the tsquery during the planning phase as we must use the default_language -- in the index definition as STOP words defaults. Consequently the planner generates the function above, then the support -- generates the operator below. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_text_tsquery(__CORE_SCHEMA__.bson, tsquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text$function$; -- This is a function that tracks the input tsquery, and the index options associated with it so that $meta queries -- can be made to work - injected during the plan phase. -- Also used to do a runtime $text scan if necessary. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_text_meta_qual(__CORE_SCHEMA__.bson, tsquery, bytea, bool) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text_meta_qual$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.bson_query_to_tsquery; -- This is a diagnostic query used to test translation of $text search clauses to TSQuery in Postgres. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_query_to_tsquery(query __CORE_SCHEMA__.bson, textSearch text default NULL) RETURNS tsquery LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$command_bson_query_to_tsquery$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_dollar_text--latest.sql000066400000000000000000000037631507310017400271630ustar00rootroot00000000000000 -- dummy function that accepts the query planner phase, and exists only to handle the support function handling -- to push down to the index. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_text(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c SUPPORT __API_CATALOG_SCHEMA__.dollar_support COST 10000000000 -- really dissuade the planner from using this and force the index. IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text$function$; -- dummy function that exists to support the index operator (below). Needs to be separate from above due to the -- 'tsquery' being an input. We can't generate the tsquery during the planning phase as we must use the default_language -- in the index definition as STOP words defaults. Consequently the planner generates the function above, then the support -- generates the operator below. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_text_tsquery(__CORE_SCHEMA__.bson, tsquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text$function$; -- This is a function that tracks the input tsquery, and the index options associated with it so that $meta queries -- can be made to work - injected during the plan phase. -- Also used to do a runtime $text scan if necessary. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_text_meta_qual(__CORE_SCHEMA__.bson, tsquery, bytea, bool) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_dollar_text_meta_qual$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.bson_query_to_tsquery; -- This is a diagnostic query used to test translation of $text search clauses to TSQuery in Postgres. CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_query_to_tsquery(query __CORE_SCHEMA__.bson, textSearch text default NULL) RETURNS tsquery LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$command_bson_query_to_tsquery$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby--0.104-0.sql000066400000000000000000000041161507310017400256040ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_orderby(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby(document __CORE_SCHEMA__.bson, filter __CORE_SCHEMA__.bson, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby$function$; -- ORDER BY operator function for $setWindowFields CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_partition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_partition(document __CORE_SCHEMA__.bson, filter __CORE_SCHEMA__.bson, isTimeRangeWindow boolean, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS int LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_compare$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_eq(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_gt$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby--0.19-0.sql000066400000000000000000000010711507310017400255260ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_orderby(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby$function$; -- ORDER BY operator function for $setWindowFields CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_partition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_partition$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby--latest.sql000066400000000000000000000041161507310017400263010ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_orderby(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby(document __CORE_SCHEMA__.bson, filter __CORE_SCHEMA__.bson, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby$function$; -- ORDER BY operator function for $setWindowFields CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_partition(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson, boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_partition(document __CORE_SCHEMA__.bson, filter __CORE_SCHEMA__.bson, isTimeRangeWindow boolean, collationString text) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_partition$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS int LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_compare$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_lt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_eq(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_gt(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_gt$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby_reverse--0.107-0.sql000066400000000000000000000004121507310017400273350ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_reverse(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby_reverse$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby_reverse--latest.sql000066400000000000000000000004121507310017400300270ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_reverse(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$command_bson_orderby_reverse$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby_sort_support--0.107-0.sql000066400000000000000000000003501507310017400304460ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare_sort_support(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_compare_sort_support$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_orderby_sort_support--latest.sql000066400000000000000000000003501507310017400311400ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_orderby_compare_sort_support(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_orderby_compare_sort_support$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_query_match--0.102-0.sql000066400000000000000000000017171507310017400264610ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.query_match_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$query_match_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_query_match(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.query_match_support AS 'MODULE_PATHNAME', $function$bson_query_match$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_true_match(__CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_true_match$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_query_match(document __CORE_SCHEMA__.bson, query __CORE_SCHEMA__.bson, variableSpec __CORE_SCHEMA__.bson, collationString text) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_query_match$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_query_match--0.14-0.sql000066400000000000000000000012451507310017400263770ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.query_match_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$query_match_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_query_match(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.query_match_support AS 'MODULE_PATHNAME', $function$bson_query_match$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_true_match(__CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_true_match$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_query_match--latest.sql000066400000000000000000000017171507310017400271600ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.query_match_support(internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $$query_match_support$$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_query_match(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.query_match_support AS 'MODULE_PATHNAME', $function$bson_query_match$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_true_match(__CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_true_match$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_query_match(document __CORE_SCHEMA__.bson, query __CORE_SCHEMA__.bson, variableSpec __CORE_SCHEMA__.bson, collationString text) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_query_match$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_value_functions--0.21-0.sql000066400000000000000000000107441507310017400272640ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_eq(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_gt(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_gte(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_lt(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_lte(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_size(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_size$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_type(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_type$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_in(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_in$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_nin(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_nin$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_ne(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_ne$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_exists(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_exists$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_elemmatch(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_elemmatch$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_all(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_all$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_regex(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_regex$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_mod(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_mod$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_all_clear(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_all_clear$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_any_clear(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_any_clear$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_all_set(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_all_set$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_any_set(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_any_set$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bson_value_functions--latest.sql000066400000000000000000000107441507310017400300430ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_eq(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_gt(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_gte(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_gte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_lt(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_lte(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_size(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_size$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_type(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_type$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_in(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_in$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_nin(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_nin$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_ne(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_ne$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_exists(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_exists$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_elemmatch(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_elemmatch$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_all(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_all$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_regex(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_regex$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_mod(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_mod$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_all_clear(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_all_clear$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_any_clear(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_any_clear$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_all_set(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_all_set$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_value_dollar_bits_any_set(internal, __CORE_SCHEMA__.bson) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_value_dollar_bits_any_set$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bsonquery_dollar_operators--0.10-0.sql000066400000000000000000000025551507310017400305200ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_eq(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lt(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lte(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gt(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gte(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/query/bsonquery_dollar_operators--latest.sql000066400000000000000000000025551507310017400313010ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_eq(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_eq$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lt(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_lte(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_lte$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gt(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gt$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_gte(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bsonquery) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT SUPPORT __API_CATALOG_SCHEMA__.dollar_support AS 'MODULE_PATHNAME', $function$bson_dollar_gte$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/000077500000000000000000000000001507310017400214775ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/roles/create_role--0.106-0.sql000066400000000000000000000004341507310017400253610ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_role processes a createRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_create_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/create_role--latest.sql000066400000000000000000000004341507310017400260540ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_role processes a createRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_create_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/drop_role--0.106-0.sql000066400000000000000000000004241507310017400250610ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.drop_role processes a dropRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_drop_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/drop_role--latest.sql000066400000000000000000000004241507310017400255540ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.drop_role processes a dropRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_drop_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/roles_info--0.106-0.sql000066400000000000000000000004301507310017400252300ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.roles_info processes a rolesInfo command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.roles_info( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_roles_info$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/roles_info--latest.sql000066400000000000000000000004301507310017400257230ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.roles_info processes a rolesInfo command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.roles_info( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_roles_info$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/update_role--0.106-0.sql000066400000000000000000000004341507310017400254000ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.update_role processes a updateRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_update_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/roles/update_role--latest.sql000066400000000000000000000004341507310017400260730ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.update_role processes a updateRole command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update_role( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_update_role$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/000077500000000000000000000000001507310017400211565ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_preconsistent--0.11-0.sql000066400000000000000000000015611507310017400264120ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_pre_consistent(internal,smallint,__CORE_SCHEMA__.bson,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_exclusion_pre_consistent(internal,smallint,__API_CATALOG_SCHEMA__.shard_key_and_document,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_can_pre_consistent(smallint, __CORE_SCHEMA__.bson, int, internal, internal, internal) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_can_pre_consistent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_preconsistent--latest.sql000066400000000000000000000015611507310017400271720ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_pre_consistent(internal,smallint,__CORE_SCHEMA__.bson,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_exclusion_pre_consistent(internal,smallint,__API_CATALOG_SCHEMA__.shard_key_and_document,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_can_pre_consistent(smallint, __CORE_SCHEMA__.bson, int, internal, internal, internal) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_can_pre_consistent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_exclusion_functions--0.23-0.sql000066400000000000000000000025761507310017400305100ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_exclusion_index_equal( __API_CATALOG_SCHEMA__.shard_key_and_document, __API_CATALOG_SCHEMA__.shard_key_and_document) RETURNS boolean LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_unique_exclusion_index_equal$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_value(__API_CATALOG_SCHEMA__.shard_key_and_document, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_options$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_query(__API_CATALOG_SCHEMA__.shard_key_and_document, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_consistent$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_exclusion_functions--latest.sql000066400000000000000000000025761507310017400312650ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_exclusion_index_equal( __API_CATALOG_SCHEMA__.shard_key_and_document, __API_CATALOG_SCHEMA__.shard_key_and_document) RETURNS boolean LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_unique_exclusion_index_equal$function$; CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_value(__API_CATALOG_SCHEMA__.shard_key_and_document, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_options$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_extract_query(__API_CATALOG_SCHEMA__.shard_key_and_document, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_exclusion_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_exclusion_consistent$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_hashed_ops_functions--0.23-0.sql000066400000000000000000000017571507310017400306140ustar00rootroot00000000000000CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_hashed_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_options$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_consistent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_hashed_ops_functions--latest.sql000066400000000000000000000017571507310017400313710ustar00rootroot00000000000000CREATE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_hashed_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_options$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_hashed_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_hashed_consistent$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_shard_exclusion_functions--0.24-0.sql000066400000000000000000000037311507310017400316640ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.generate_unique_shard_document(p_document __CORE_SCHEMA__.bson, p_shard_key_value bigint, p_unique_spec __CORE_SCHEMA__.bson, p_sparse boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$generate_unique_shard_document$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_shard_path_equal(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS boolean LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_unique_shard_path_equal$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_pre_consistent(internal,smallint,__CORE_SCHEMA__.bson,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_index_equal(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_unique_index_term_equal$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_shard_exclusion_functions--latest.sql000066400000000000000000000037311507310017400324400ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.generate_unique_shard_document(p_document __CORE_SCHEMA__.bson, p_shard_key_value bigint, p_unique_spec __CORE_SCHEMA__.bson, p_sparse boolean) RETURNS __CORE_SCHEMA__.bson LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$generate_unique_shard_document$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_shard_path_equal(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS boolean LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE AS 'MODULE_PATHNAME', $function$bson_unique_shard_path_equal$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE C STRICT IMMUTABLE AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_pre_consistent(internal,smallint,__CORE_SCHEMA__.bson,int,internal,internal,internal,internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_pre_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_unique_shard_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_unique_shard_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_unique_index_equal(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$bson_unique_index_term_equal$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_text_path_adapter_funcs--0.24-0.sql000066400000000000000000000025311507310017400312750ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_extract_tsquery(tsquery,internal,smallint,internal,internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME', 'documentdb_rum_extract_tsquery' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_consistent(internal, smallint, tsvector, integer, internal, internal, internal, internal) RETURNS bool AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_consistent' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsvector_config(internal) RETURNS void AS 'MODULE_PATHNAME', 'documentdb_rum_tsvector_config' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal) RETURNS bool AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_pre_consistent' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_distance(internal,smallint,tsvector,int,internal,internal,internal,internal,internal) RETURNS float8 AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_distance' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_ts_join_pos(internal, internal) RETURNS bytea AS 'MODULE_PATHNAME', 'documentdb_rum_ts_join_pos' LANGUAGE C IMMUTABLE STRICT;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_text_path_adapter_funcs--latest.sql000066400000000000000000000025311507310017400320510ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_extract_tsquery(tsquery,internal,smallint,internal,internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME', 'documentdb_rum_extract_tsquery' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_consistent(internal, smallint, tsvector, integer, internal, internal, internal, internal) RETURNS bool AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_consistent' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsvector_config(internal) RETURNS void AS 'MODULE_PATHNAME', 'documentdb_rum_tsvector_config' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal) RETURNS bool AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_pre_consistent' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_tsquery_distance(internal,smallint,tsvector,int,internal,internal,internal,internal,internal) RETURNS float8 AS 'MODULE_PATHNAME', 'documentdb_rum_tsquery_distance' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_ts_join_pos(internal, internal) RETURNS bytea AS 'MODULE_PATHNAME', 'documentdb_rum_ts_join_pos' LANGUAGE C IMMUTABLE STRICT;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_text_path_funcs--0.24-0.sql000066400000000000000000000012561507310017400276000ustar00rootroot00000000000000 DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.rum_bson_single_path_extract_tsvector; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_bson_single_path_extract_tsvector(__CORE_SCHEMA__.bson, internal, internal, internal, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$rum_bson_single_path_extract_tsvector$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.rum_bson_text_path_options; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_bson_text_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$rum_bson_text_path_options$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/bson_rum_text_path_funcs--latest.sql000066400000000000000000000012561507310017400303540ustar00rootroot00000000000000 DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.rum_bson_single_path_extract_tsvector; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_bson_single_path_extract_tsvector(__CORE_SCHEMA__.bson, internal, internal, internal, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$rum_bson_single_path_extract_tsvector$function$; DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.rum_bson_text_path_options; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.rum_bson_text_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$rum_bson_text_path_options$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/composite_path_operator_functions--0.103-0.sql000066400000000000000000000025161507310017400315750ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS internal LANGUAGE c PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_compare_partial(bytea, bytea, int2, internal) RETURNS int4 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_compare_partial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_options$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/composite_path_operator_functions--latest.sql000066400000000000000000000025161507310017400322730ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_extract_value$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS internal LANGUAGE c PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_extract_query$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_consistent$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_compare_partial(bytea, bytea, int2, internal) RETURNS int4 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_compare_partial$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.gin_bson_composite_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_composite_path_options$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/extensibility_functions--0.10-0.sql000066400000000000000000000023511507310017400274520ustar00rootroot00000000000000-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_compare(bytea, bytea) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_compare$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS internal LANGUAGE c PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $function$gin_bson_extract_query$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_compare_partial(bytea, bytea, int2, internal) RETURNS int4 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_compare_partial$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_consistent$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/extensibility_functions--latest.sql000066400000000000000000000023511507310017400302330ustar00rootroot00000000000000-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_compare(bytea, bytea) RETURNS bool LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_compare$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_extract_query(__CORE_SCHEMA__.bson, internal, int2, internal, internal, internal, internal) RETURNS internal LANGUAGE c PARALLEL SAFE STABLE AS 'MODULE_PATHNAME', $function$gin_bson_extract_query$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_compare_partial(bytea, bytea, int2, internal) RETURNS int4 LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_compare_partial$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_consistent(internal, smallint, anyelement, integer, internal, internal) RETURNS boolean LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_consistent$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/rum/handler--0.10-0.sql000066400000000000000000000003021507310017400240750ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(rumhandler)(internal) RETURNS index_am_handler LANGUAGE C AS 'MODULE_PATHNAME', $function$extensionrumhandler$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/handler--latest.sql000066400000000000000000000003021507310017400246560ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.__EXTENSION_OBJECT__(rumhandler)(internal) RETURNS index_am_handler LANGUAGE C AS 'MODULE_PATHNAME', $function$extensionrumhandler$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/single_path_extensibility_functions--0.10-0.sql000066400000000000000000000014111507310017400320230ustar00rootroot00000000000000-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_single_path_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_single_path_extract_value$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_single_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_single_path_options$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/rum/single_path_extensibility_functions--latest.sql000066400000000000000000000014111507310017400326040ustar00rootroot00000000000000-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_single_path_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_single_path_extract_value$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_single_path_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_single_path_options$function$; wildcard_project_path_extensibility_functions--0.12-0.sql000066400000000000000000000014351507310017400340120ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/rum-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_wildcard_project_extract_value$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_wildcard_project_options$function$; wildcard_project_path_extensibility_functions--latest.sql000066400000000000000000000014351507310017400345710ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/rum-- Note that the functions here have the prefix 'gin' even though they may be used on the RUM index. -- This is because the RUM docs also use the same constants/functions as GIN extensibility for all existing functionality. -- Consequently we reuse the gin prefix for functionality shared with GIN. CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_extract_value(__CORE_SCHEMA__.bson, internal) RETURNS internal LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_wildcard_project_extract_value$function$; CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.gin_bson_wildcard_project_options(internal) RETURNS void LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$gin_bson_wildcard_project_options$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/000077500000000000000000000000001507310017400226375ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/coll_mod--0.12-0.sql000066400000000000000000000007431507310017400257440ustar00rootroot00000000000000-- collMod database command implementation for the wire protocol CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.coll_mod( IN p_database_name text, IN p_collection_name text, IN p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $function$command_coll_mod$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.coll_mod(text, text, __CORE_SCHEMA_V2__.bson) IS 'Updates the specification of collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/coll_mod--latest.sql000066400000000000000000000007431507310017400265230ustar00rootroot00000000000000-- collMod database command implementation for the wire protocol CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.coll_mod( IN p_database_name text, IN p_collection_name text, IN p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $function$command_coll_mod$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.coll_mod(text, text, __CORE_SCHEMA_V2__.bson) IS 'Updates the specification of collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/compact--0.104-0.sql000066400000000000000000000014341507310017400256620ustar00rootroot00000000000000-- compact database command implementation for the wire protocol CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.compact( IN p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_compact$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.compact(__CORE_SCHEMA_V2__.bson) IS 'Compact the collection data tables and indexes'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.get_bloat_stats_worker( p_collection_id INT8) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$get_bloat_stats_worker$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.get_bloat_stats_worker(INT8) IS 'Gets bloat stats for a collection table in the worker'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/compact--latest.sql000066400000000000000000000014341507310017400263570ustar00rootroot00000000000000-- compact database command implementation for the wire protocol CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.compact( IN p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE PARALLEL UNSAFE STRICT AS 'MODULE_PATHNAME', $function$command_compact$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.compact(__CORE_SCHEMA_V2__.bson) IS 'Compact the collection data tables and indexes'; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.get_bloat_stats_worker( p_collection_id INT8) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', $function$get_bloat_stats_worker$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.get_bloat_stats_worker(INT8) IS 'Gets bloat stats for a collection table in the worker'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/create_collection--0.12-0.sql000066400000000000000000000006551507310017400276340ustar00rootroot00000000000000 /* SQL API function that creates a collection given a database and collection */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_collection(p_database_name text, p_collection_name text) RETURNS bool LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_create_collection_core$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_collection(p_database_name text, p_collection_name text) IS 'create a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/create_collection--latest.sql000066400000000000000000000006551507310017400304130ustar00rootroot00000000000000 /* SQL API function that creates a collection given a database and collection */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_collection(p_database_name text, p_collection_name text) RETURNS bool LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$command_create_collection_core$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.create_collection(p_database_name text, p_collection_name text) IS 'create a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/create_collection_view--0.12-0.sql000066400000000000000000000005221507310017400306570ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_collection_view processes a wire protocol create command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_collection_view(dbname text, createSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $$command_create_collection_view$$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/create_collection_view--latest.sql000066400000000000000000000005221507310017400314360ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_collection_view processes a wire protocol create command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_collection_view(dbname text, createSpec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE c VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $$command_create_collection_view$$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/cursor_support--0.104-0.sql000066400000000000000000000003321507310017400273410ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.cursor_directory_cleanup(expiry_time_seconds int8 DEFAULT NULL) RETURNS void LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$cursor_directory_cleanup$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/cursor_support--0.105-0.sql000066400000000000000000000006511507310017400273460ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.cursor_directory_cleanup(expiry_time_seconds int8 DEFAULT NULL) RETURNS void LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$cursor_directory_cleanup$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_cursors(cursorids int8[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$command_delete_cursors$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/cursor_support--latest.sql000066400000000000000000000006511507310017400300420ustar00rootroot00000000000000CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.cursor_directory_cleanup(expiry_time_seconds int8 DEFAULT NULL) RETURNS void LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$cursor_directory_cleanup$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_cursors(cursorids int8[]) RETURNS __CORE_SCHEMA__.bson LANGUAGE c VOLATILE AS 'MODULE_PATHNAME', $function$command_delete_cursors$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/data_table_upgrade--0.102-0.sql000066400000000000000000000006671507310017400300300ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(int4, int4, int4) RETURNS void LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$apply_extension_data_table_upgrade$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(int4, int4, int4) IS 'alter creation time column';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/data_table_upgrade--latest.sql000066400000000000000000000006671507310017400305270ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(int4, int4, int4) RETURNS void LANGUAGE c STRICT AS 'MODULE_PATHNAME', $function$apply_extension_data_table_upgrade$function$; COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.apply_extension_data_table_upgrade(int4, int4, int4) IS 'alter creation time column';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/drop_collection--0.12-0.sql000066400000000000000000000011021507310017400273210ustar00rootroot00000000000000/* db.collection.drop(writeConcern) */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.drop_collection CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_collection( p_database_name text, p_collection_name text, p_write_concern __CORE_SCHEMA_V2__.bson default null, p_collection_uuid uuid default null, p_track_changes bool default true) RETURNS bool LANGUAGE C AS 'MODULE_PATHNAME', $function$command_drop_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.drop_collection(text,text,__CORE_SCHEMA_V2__.bson,uuid,bool) IS 'drop a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/drop_collection--latest.sql000066400000000000000000000011021507310017400301000ustar00rootroot00000000000000/* db.collection.drop(writeConcern) */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.drop_collection CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_collection( p_database_name text, p_collection_name text, p_write_concern __CORE_SCHEMA_V2__.bson default null, p_collection_uuid uuid default null, p_track_changes bool default true) RETURNS bool LANGUAGE C AS 'MODULE_PATHNAME', $function$command_drop_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.drop_collection(text,text,__CORE_SCHEMA_V2__.bson,uuid,bool) IS 'drop a collection'; documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/drop_database--0.13-0.sql000066400000000000000000000015051507310017400267420ustar00rootroot00000000000000/* db.dropDatabase(writeConcern) */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_database( p_database_name text, p_write_concern __CORE_SCHEMA_V2__.bson default null) RETURNS void SET search_path TO __CORE_SCHEMA_V2__, pg_catalog AS $fn$ DECLARE v_collection record; BEGIN /* TODO: lock on database to prevent concurrent table addition */ FOR v_collection IN SELECT database_name, collection_name FROM __API_CATALOG_SCHEMA__.collections WHERE database_name = p_database_name LOOP PERFORM __API_SCHEMA_V2__.drop_collection(v_collection.database_name, v_collection.collection_name); END LOOP; END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_V2__.drop_database(text,__CORE_SCHEMA_V2__.bson) IS 'drops a logical document database';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/drop_database--latest.sql000066400000000000000000000015051507310017400275200ustar00rootroot00000000000000/* db.dropDatabase(writeConcern) */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_database( p_database_name text, p_write_concern __CORE_SCHEMA_V2__.bson default null) RETURNS void SET search_path TO __CORE_SCHEMA_V2__, pg_catalog AS $fn$ DECLARE v_collection record; BEGIN /* TODO: lock on database to prevent concurrent table addition */ FOR v_collection IN SELECT database_name, collection_name FROM __API_CATALOG_SCHEMA__.collections WHERE database_name = p_database_name LOOP PERFORM __API_SCHEMA_V2__.drop_collection(v_collection.database_name, v_collection.collection_name); END LOOP; END; $fn$ LANGUAGE plpgsql; COMMENT ON FUNCTION __API_SCHEMA_V2__.drop_database(text,__CORE_SCHEMA_V2__.bson) IS 'drops a logical document database';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/rename_collection--0.15-0.sql000066400000000000000000000010701507310017400276330ustar00rootroot00000000000000/* API that renames a collection given a database and a collection to the specified target name. */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.rename_collection; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.rename_collection( p_database_name text, p_collection_name text, p_target_name text, p_drop_target bool default false) RETURNS void LANGUAGE c VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $function$command_rename_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.rename_collection(text, text, text, bool) IS 'rename a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/rename_collection--latest.sql000066400000000000000000000010701507310017400304070ustar00rootroot00000000000000/* API that renames a collection given a database and a collection to the specified target name. */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.rename_collection; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.rename_collection( p_database_name text, p_collection_name text, p_target_name text, p_drop_target bool default false) RETURNS void LANGUAGE c VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $function$command_rename_collection$function$; COMMENT ON FUNCTION __API_SCHEMA_V2__.rename_collection(text, text, text, bool) IS 'rename a collection';documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/shard_collection--0.24-0.sql000066400000000000000000000022751507310017400274750ustar00rootroot00000000000000 /* Wire protocol command to shard or reshard a collection */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.shard_collection CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.shard_collection( p_database_name text, p_collection_name text, p_shard_key __CORE_SCHEMA_V2__.bson, p_is_reshard bool default true) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_shard_collection$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.shard_collection(text, text,__CORE_SCHEMA_V2__.bson,bool) IS 'Top level command to shard or reshard a collection'; -- create clones for the new schemas CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.shard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_shard_collection$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.reshard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_reshard_collection$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.unshard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_unshard_collection$$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_mgmt/shard_collection--latest.sql000066400000000000000000000022751507310017400302510ustar00rootroot00000000000000 /* Wire protocol command to shard or reshard a collection */ DROP FUNCTION IF EXISTS __API_SCHEMA_V2__.shard_collection CASCADE; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.shard_collection( p_database_name text, p_collection_name text, p_shard_key __CORE_SCHEMA_V2__.bson, p_is_reshard bool default true) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_shard_collection$$; COMMENT ON FUNCTION __API_SCHEMA_V2__.shard_collection(text, text,__CORE_SCHEMA_V2__.bson,bool) IS 'Top level command to shard or reshard a collection'; -- create clones for the new schemas CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.shard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_shard_collection$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.reshard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_reshard_collection$$; CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.unshard_collection( p_shard_key_spec __CORE_SCHEMA_V2__.bson) RETURNS void LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_unshard_collection$$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_validation/000077500000000000000000000000001507310017400240255ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/schema_validation/schema_validation--0.24-0.sql000066400000000000000000000005761507310017400310230ustar00rootroot00000000000000 /* apply schema validation while data updating */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schema_validation_against_update( p_eval_state bytea, p_target_document __CORE_SCHEMA__.bson, p_source_document __CORE_SCHEMA__.bson, p_is_moderate boolean ) RETURNS boolean LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_schema_validation_against_update$$;documentdb-0.108-0/pg_documentdb/sql/udfs/schema_validation/schema_validation--latest.sql000066400000000000000000000005761507310017400315770ustar00rootroot00000000000000 /* apply schema validation while data updating */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schema_validation_against_update( p_eval_state bytea, p_target_document __CORE_SCHEMA__.bson, p_source_document __CORE_SCHEMA__.bson, p_is_moderate boolean ) RETURNS boolean LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$command_schema_validation_against_update$$;documentdb-0.108-0/pg_documentdb/sql/udfs/telemetry/000077500000000000000000000000001507310017400223655ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/telemetry/command_feature_counter--0.24-0.sql000066400000000000000000000005761507310017400306010ustar00rootroot00000000000000-- This function is used to get current feature usage statistics for reporting to -- the telemetry pipeline CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.command_feature_counter_stats( IN reset_stats_after_read bool, OUT feature_name text, OUT usage_count int) RETURNS SETOF RECORD LANGUAGE C VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $$get_feature_counter_stats$$;documentdb-0.108-0/pg_documentdb/sql/udfs/telemetry/command_feature_counter--latest.sql000066400000000000000000000005761507310017400313550ustar00rootroot00000000000000-- This function is used to get current feature usage statistics for reporting to -- the telemetry pipeline CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.command_feature_counter_stats( IN reset_stats_after_read bool, OUT feature_name text, OUT usage_count int) RETURNS SETOF RECORD LANGUAGE C VOLATILE PARALLEL UNSAFE AS 'MODULE_PATHNAME', $$get_feature_counter_stats$$;documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/000077500000000000000000000000001507310017400211565ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/delete_expired_rows_background--0.106-0.sql000066400000000000000000000010711507310017400310050ustar00rootroot00000000000000/* * Drop-in replacement for delete_expired_rows. This will be called periodically by the * background worker framework and will coexist with the previous UDF until it reaches * stability. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_background(IN p_batch_size int default -1) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$delete_expired_rows_background$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_background(int) IS 'Drops expired rows from applicable collections based on TTL indexes.';documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/delete_expired_rows_background--latest.sql000066400000000000000000000010711507310017400315000ustar00rootroot00000000000000/* * Drop-in replacement for delete_expired_rows. This will be called periodically by the * background worker framework and will coexist with the previous UDF until it reaches * stability. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_background(IN p_batch_size int default -1) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$delete_expired_rows_background$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_background(int) IS 'Drops expired rows from applicable collections based on TTL indexes.';documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/ttl_support_functions--0.102-0.sql000066400000000000000000000030661507310017400272430ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_for_index( IN collection_id bigint, IN index_id bigint, IN index_key __CORE_SCHEMA__.bson, IN index_pfe __CORE_SCHEMA__.bson, IN current_datetime bigint, IN index_expiry int, IN ttl_batch_size int, IN shard_id bigint); /* * Procedure to delete expired rows specified by ttl indexes. The procedure goes over * all the valid TTL indexes and deletes a small batch of expired rows from one of the * shards of the corresponding collection. As longs as we delete some data from one of * the shards of the collection, we exit out of the function to make forward progress and * to keep delete deletion prcess short, so that it does not hold locks for a long period. * * Note since we go over all the shards for the collection, the solution works for all sharded * and unsharded collection. * * The method takes the maximum number of documents than can be deleted in a batch as a parameter. * A value of -1 (default) instructs the caller to use the default batch size avilable via GUC. * Ability of pass the batch size parameter is useful for testing. * * IMP: This procedure is designed only to be called from pg_cron ttl purger task. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows(IN p_batch_size int default -1) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$delete_expired_rows$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows(int) IS 'Drops expired rows from applicable collections based on TTL indexes.';documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/ttl_support_functions--0.24-0.sql000066400000000000000000000115571507310017400271720ustar00rootroot00000000000000/* * This function deletes a batch of documents from a collection with an active ttl index. * * Param 1: Collection Id * Param 2: Index Id * Param 2: Index Key * Param 3: Current date time in milliseconds since epoch * Param 4: Partial filter expression * Param 5: IndexExpiryAfterSeconds field specified in the index * Param 6: Batch size * Param 7: Shard Id */ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_for_index( IN collection_id bigint, IN index_id bigint, IN index_key __CORE_SCHEMA__.bson, IN index_pfe __CORE_SCHEMA__.bson, IN current_datetime bigint, IN index_expiry int, IN ttl_batch_size int, IN shard_id bigint) RETURNS bigint LANGUAGE C VOLATILE PARALLEL UNSAFE CALLED ON NULL INPUT AS 'MODULE_PATHNAME', $function$delete_expired_rows_for_index$function$; /* * Procedure to delete expired rows specified by ttl indexes. The procedure goes over * all the valid TTL indexes and deletes a small batch of expired rows from one of the * shards of the corresponding collection. As longs as we delete some data from one of * the shards of the collection, we exit out of the function to make forward progress and * to keep delete deletion prcess short, so that it does not hold locks for a long period. * * Note since we go over all the shards for the collection, the solution works for all sharded * and unsharded collection. * * The method takes the maximum number of documents than can be deleted in a batch as a parameter. * A value of -1 (default) instructs the caller to use the default batch size avilable via GUC. * Ability of pass the batch size parameter is useful for testing. * * IMP: This procedure is designed only to be called from pg_cron ttl purger task. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows(IN p_batch_size int default -1) AS $procedure$ DECLARE collection_row record; expired_rows_deleted bigint; start_time TIMESTAMP; end_time TIMESTAMP; config_value TEXT; elapsed_time INTERVAL; single_ttl_task_time_budget INTERVAL; exception_message TEXT; exception_detail TEXT; BEGIN config_value := current_setting(__SINGLE_QUOTED_STRING__(__API_GUC_PREFIX__) || '.SingleTTLTaskTimeBudget'); single_ttl_task_time_budget := (config_value::INTEGER * '1 millisecond'::INTERVAL); start_time := clock_timestamp(); SET LOCAL search_path TO __API_DATA_SCHEMA__; -- This loop goes over all the shards of a collection holding the ttl index and starts deleting data. FOR collection_row IN SELECT idx.collection_id, idx.index_id, (index_spec).index_key as key, (index_spec).index_pfe as pfe, trunc(extract(epoch FROM now()) * 1000, 0)::int8 as currentDateTime, (index_spec).index_expire_after_seconds as expiry, coll.shard_key, dist.shardid FROM __API_CATALOG_SCHEMA__.collection_indexes as idx, __API_CATALOG_SCHEMA__.collections as coll, pg_dist_shard as dist, pg_dist_placement as placement, pg_dist_local_group as lg WHERE index_is_valid AND (index_spec).index_expire_after_seconds >= 0 AND idx.collection_id = coll.collection_id AND dist.logicalrelid = ('documents_' || coll.collection_id)::regclass AND placement.shardid = dist.shardid AND placement.groupid = lg.groupid -- filter shards that live on this worker node AND (dist.shardid = get_shard_id_for_distribution_column(logicalrelid, coll.collection_id) OR (coll.shard_key IS NOT NULL)) LOOP expired_rows_deleted:= __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_for_index( collection_row.collection_id, collection_row.index_id, collection_row.key, collection_row.pfe, collection_row.currentDateTime, collection_row.expiry, p_batch_size, collection_row.shardid); end_time := clock_timestamp(); elapsed_time := end_time - start_time; IF current_setting(__SINGLE_QUOTED_STRING__(__API_GUC_PREFIX__) || '.logTTLProgressActivity')::BOOLEAN IS TRUE THEN RAISE LOG 'TTL task: deleted_documents=%, collection_id=%, index_id=%, shard_id=%, elapsed_time=%ms, budgeted_time=%ms', expired_rows_deleted, collection_row.collection_id, collection_row.index_id, collection_row.shardid, elapsed_time, single_ttl_task_time_budget; END IF; -- As long as we could delete data from any shards of a collection with ttl index -- we keep going until the time budget allocated for a single invocation of a -- ttl task exceeds. IF elapsed_time > single_ttl_task_time_budget THEN RETURN; END IF; COMMIT; END LOOP; END; $procedure$ LANGUAGE plpgsql;documentdb-0.108-0/pg_documentdb/sql/udfs/ttl/ttl_support_functions--latest.sql000066400000000000000000000030661507310017400277420ustar00rootroot00000000000000DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL_V2__.delete_expired_rows_for_index( IN collection_id bigint, IN index_id bigint, IN index_key __CORE_SCHEMA__.bson, IN index_pfe __CORE_SCHEMA__.bson, IN current_datetime bigint, IN index_expiry int, IN ttl_batch_size int, IN shard_id bigint); /* * Procedure to delete expired rows specified by ttl indexes. The procedure goes over * all the valid TTL indexes and deletes a small batch of expired rows from one of the * shards of the corresponding collection. As longs as we delete some data from one of * the shards of the collection, we exit out of the function to make forward progress and * to keep delete deletion prcess short, so that it does not hold locks for a long period. * * Note since we go over all the shards for the collection, the solution works for all sharded * and unsharded collection. * * The method takes the maximum number of documents than can be deleted in a batch as a parameter. * A value of -1 (default) instructs the caller to use the default batch size avilable via GUC. * Ability of pass the batch size parameter is useful for testing. * * IMP: This procedure is designed only to be called from pg_cron ttl purger task. */ CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows(IN p_batch_size int default -1) LANGUAGE c AS 'MODULE_PATHNAME', $procedure$delete_expired_rows$procedure$; COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL_V2__.delete_expired_rows(int) IS 'Drops expired rows from applicable collections based on TTL indexes.';documentdb-0.108-0/pg_documentdb/sql/udfs/users/000077500000000000000000000000001507310017400215145ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/users/connection_status--0.105-0.sql000066400000000000000000000004641507310017400266560ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.connection_status processes a connectionStatus command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.connection_status( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_connection_status$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/users/connection_status--latest.sql000066400000000000000000000004641507310017400273520ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.connection_status processes a connectionStatus command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.connection_status( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', $function$command_connection_status$function$; documentdb-0.108-0/pg_documentdb/sql/udfs/users/create_user--0.19-0.sql000066400000000000000000000005311507310017400253340ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_user processes a wire protocol createUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_create_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/create_user--latest.sql000066400000000000000000000005311507310017400261040ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.create_user processes a wire protocol createUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_create_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/drop_user--0.19-0.sql000066400000000000000000000005211507310017400250340ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.drop_user processes a wire protocol dropUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_drop_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/drop_user--latest.sql000066400000000000000000000005211507310017400256040ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.drop_user processes a wire protocol dropUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.drop_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_drop_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/update_user--0.19-0.sql000066400000000000000000000005311507310017400253530ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.update_user processes a wire protocol updateUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_update_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/update_user--latest.sql000066400000000000000000000005311507310017400261230ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.update_user processes a wire protocol updateUser command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.update_user( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_update_user$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/users_info--0.19-0.sql000066400000000000000000000005241507310017400252110ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.users_info processes a wire protocol usersInfo command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.users_info( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_get_users$$); documentdb-0.108-0/pg_documentdb/sql/udfs/users/users_info--latest.sql000066400000000000000000000005241507310017400257610ustar00rootroot00000000000000/* * __API_SCHEMA_V2__.users_info processes a wire protocol usersInfo command. */ CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.users_info( p_spec __CORE_SCHEMA_V2__.bson) RETURNS __CORE_SCHEMA_V2__.bson LANGUAGE C VOLATILE AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($$, __EXTENSION_OBJECT_PREFIX_V2__, _extension_get_users$$); documentdb-0.108-0/pg_documentdb/sql/udfs/utils/000077500000000000000000000000001507310017400215135ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/utils/extension_version_utils--0.11-0.sql000066400000000000000000000007311507310017400300250ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.binary_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$get_, __API_SCHEMA_V2__, _binary_version$function$); CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.binary_extended_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$get_, __API_SCHEMA_V2__, _extended_binary_version$function$);documentdb-0.108-0/pg_documentdb/sql/udfs/utils/extension_version_utils--latest.sql000066400000000000000000000007311507310017400306050ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.binary_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$get_, __API_SCHEMA_V2__, _binary_version$function$); CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.binary_extended_version() RETURNS text LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT AS 'MODULE_PATHNAME', __CONCAT_NAME_FUNCTION__($function$get_, __API_SCHEMA_V2__, _extended_binary_version$function$);documentdb-0.108-0/pg_documentdb/sql/udfs/vector/000077500000000000000000000000001507310017400216555ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/sql/udfs/vector/bson_extract_vector--0.24-0.sql000066400000000000000000000013701507310017400272470ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_extract_vector(document __CORE_SCHEMA__.bson, path text) RETURNS public.vector LANGUAGE c IMMUTABLE PARALLEL SAFE RETURNS NULL ON NULL INPUT AS 'MODULE_PATHNAME', $function$command_bson_extract_vector$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_search_param(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_bson_search_param$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_document_add_score_field(__CORE_SCHEMA__.bson, float8) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_bson_document_add_score_field$function$;documentdb-0.108-0/pg_documentdb/sql/udfs/vector/bson_extract_vector--latest.sql000066400000000000000000000013701507310017400300230ustar00rootroot00000000000000 CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_extract_vector(document __CORE_SCHEMA__.bson, path text) RETURNS public.vector LANGUAGE c IMMUTABLE PARALLEL SAFE RETURNS NULL ON NULL INPUT AS 'MODULE_PATHNAME', $function$command_bson_extract_vector$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_search_param(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) RETURNS bool LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_bson_search_param$function$; CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_document_add_score_field(__CORE_SCHEMA__.bson, float8) RETURNS __CORE_SCHEMA__.bson LANGUAGE c IMMUTABLE STRICT AS 'MODULE_PATHNAME', $function$command_bson_document_add_score_field$function$;documentdb-0.108-0/pg_documentdb/src/000077500000000000000000000000001507310017400174025ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/src/aggregation/000077500000000000000000000000001507310017400216715ustar00rootroot00000000000000documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregates.c000066400000000000000000001437121507310017400251770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/bson/bson_aggregates.c * * Aggregation implementations of BSON. * *------------------------------------------------------------------------- */ #include #include #include #include "io/bson_core.h" #include "query/bson_compare.h" #include #include #include #include "utils/documentdb_errors.h" #include "metadata/collection.h" #include "commands/insert.h" #include "sharding/sharding.h" #include "utils/hashset_utils.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_tree.h" #include "aggregation/bson_tree_write.h" #include "aggregation/bson_sorted_accumulator.h" #include "operators/bson_expression_operators.h" /* --------------------------------------------------------- */ /* Data-types */ /* --------------------------------------------------------- */ typedef struct BsonNumericAggState { bson_value_t sum; int64_t count; } BsonNumericAggState; typedef struct BsonArrayGroupAggState { pgbson_writer writer; pgbson_array_writer arrayWriter; } BsonArrayGroupAggState; /* * Window aggregation state for bson_array_agg, contains the * list of contents for bson array */ typedef struct BsonArrayWindowAggState { List *aggregateList; } BsonArrayWindowAggState; typedef struct BsonArrayAggState { union { /* Transition state when used a regular aggregate with $group */ BsonArrayGroupAggState group; /* Transition state when used as window aggregate with $setWindowFields */ BsonArrayWindowAggState window; } aggState; int64_t currentSizeWritten; bool isWindowAggregation; } BsonArrayAggState; typedef struct BsonObjectAggState { BsonIntermediatePathNode *tree; int64_t currentSizeWritten; bool addEmptyPath; } BsonObjectAggState; typedef struct BsonAddToSetState { HTAB *set; int64_t currentSizeWritten; bool isWindowAggregation; } BsonAddToSetState; /* state used for maxN and minN both */ typedef struct BinaryHeapState { BinaryHeap *heap; bool isMaxN; } BinaryHeapState; const char charset[] = "abcdefghijklmnopqrstuvwxyz0123456789"; /* --------------------------------------------------------- */ /* Forward declaration */ /* --------------------------------------------------------- */ static bytea * AllocateBsonNumericAggState(void); static void CheckAggregateIntermediateResultSize(uint32_t size); static void CreateObjectAggTreeNodes(BsonObjectAggState *currentState, pgbson *currentValue); static void ValidateMergeObjectsInput(pgbson *input); static Datum ParseAndReturnMergeObjectsTree(BsonObjectAggState *state); static Datum bson_maxminn_transition(PG_FUNCTION_ARGS, bool isMaxN); void DeserializeBinaryHeapState(bytea *byteArray, BinaryHeapState *state); bytea * SerializeBinaryHeapState(MemoryContext aggregateContext, BinaryHeapState *state, bytea *byteArray); /* --------------------------------------------------------- */ /* Top level exports */ /* --------------------------------------------------------- */ PG_FUNCTION_INFO_V1(bson_sum_avg_transition); PG_FUNCTION_INFO_V1(bson_sum_final); PG_FUNCTION_INFO_V1(bson_avg_final); PG_FUNCTION_INFO_V1(bson_sum_avg_combine); PG_FUNCTION_INFO_V1(bson_sum_avg_minvtransition); PG_FUNCTION_INFO_V1(bson_min_transition); PG_FUNCTION_INFO_V1(bson_max_transition); PG_FUNCTION_INFO_V1(bson_min_max_final); PG_FUNCTION_INFO_V1(bson_min_combine); PG_FUNCTION_INFO_V1(bson_max_combine); PG_FUNCTION_INFO_V1(bson_build_distinct_response); PG_FUNCTION_INFO_V1(bson_array_agg_transition); PG_FUNCTION_INFO_V1(bson_array_agg_minvtransition); PG_FUNCTION_INFO_V1(bson_array_agg_final); PG_FUNCTION_INFO_V1(bson_distinct_array_agg_transition); PG_FUNCTION_INFO_V1(bson_distinct_array_agg_final); PG_FUNCTION_INFO_V1(bson_object_agg_transition); PG_FUNCTION_INFO_V1(bson_object_agg_final); PG_FUNCTION_INFO_V1(bson_out_transition); PG_FUNCTION_INFO_V1(bson_out_final); PG_FUNCTION_INFO_V1(bson_add_to_set_transition); PG_FUNCTION_INFO_V1(bson_add_to_set_final); PG_FUNCTION_INFO_V1(bson_merge_objects_transition_on_sorted); PG_FUNCTION_INFO_V1(bson_merge_objects_transition); PG_FUNCTION_INFO_V1(bson_merge_objects_final); PG_FUNCTION_INFO_V1(bson_maxn_transition); PG_FUNCTION_INFO_V1(bson_maxminn_final); PG_FUNCTION_INFO_V1(bson_minn_transition); PG_FUNCTION_INFO_V1(bson_maxminn_combine); Datum bson_out_transition(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("bson_out_transition is not deprecated"))); } Datum bson_out_final(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("bson_out_final is not deprecated"))); } inline static Datum BsonArrayAggTransitionCore(PG_FUNCTION_ARGS, bool handleSingleValueElement, const char *path) { BsonArrayAggState *currentState = { 0 }; bytea *bytes; MemoryContext aggregateContext; int aggregationContext = AggCheckCallContext(fcinfo, &aggregateContext); if (aggregationContext == 0) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } bool isWindowAggregation = aggregationContext == AGG_CONTEXT_WINDOW; /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) /* First arg is the running aggregated state*/ { int bson_size = sizeof(BsonArrayAggState) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); bytes = combinedStateBytes; currentState = (BsonArrayAggState *) VARDATA(bytes); currentState->isWindowAggregation = isWindowAggregation; currentState->currentSizeWritten = 0; if (isWindowAggregation) { currentState->aggState.window.aggregateList = NIL; } else { PgbsonWriterInit(¤tState->aggState.group.writer); PgbsonWriterStartArray(¤tState->aggState.group.writer, path, strlen( path), ¤tState->aggState.group.arrayWriter); } } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonArrayAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON_PACKED(1); bool isMissingValue = IsPgbsonEmptyDocument(currentValue); if (currentValue == NULL) { if (isWindowAggregation) { currentState->aggState.window.aggregateList = lappend( currentState->aggState.window.aggregateList, NULL); } else { PgbsonArrayWriterWriteNull(¤tState->aggState.group.arrayWriter); } } else { CheckAggregateIntermediateResultSize(currentState->currentSizeWritten + PgbsonGetBsonSize(currentValue)); if (isWindowAggregation) { pgbson *copiedPgbson = CopyPgbsonIntoMemoryContext(currentValue, aggregateContext); currentState->aggState.window.aggregateList = lappend( currentState->aggState.window.aggregateList, copiedPgbson); } else if (!isMissingValue) { pgbsonelement singleBsonElement; if (handleSingleValueElement && TryGetSinglePgbsonElementFromPgbson(currentValue, &singleBsonElement) && singleBsonElement.pathLength == 0) { /* If it's a bson that's { "": value } */ PgbsonArrayWriterWriteValue(¤tState->aggState.group.arrayWriter, &singleBsonElement.bsonValue); } else { PgbsonArrayWriterWriteDocument(¤tState->aggState.group.arrayWriter, currentValue); } } currentState->currentSizeWritten += PgbsonGetBsonSize(currentValue); } if (currentValue != NULL) { PG_FREE_IF_COPY(currentValue, 1); } MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } Datum bson_array_agg_transition(PG_FUNCTION_ARGS) { char *path = text_to_cstring(PG_GETARG_TEXT_P(2)); /* We currently have 2 implementations of bson_array_agg. The newest has a parameter for handleSingleValueElement. */ bool handleSingleValueElement = PG_NARGS() == 4 ? PG_GETARG_BOOL(3) : false; return BsonArrayAggTransitionCore(fcinfo, handleSingleValueElement, path); } Datum bson_array_agg_minvtransition(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } if (PG_ARGISNULL(0)) { /* Returning NULL is an indiacation that inverse can't be applied and the aggregation needs to be redone */ PG_RETURN_NULL(); } bytea *bytes = PG_GETARG_BYTEA_P(0); BsonArrayAggState *currentState = (BsonArrayAggState *) VARDATA_ANY(bytes); if (!currentState->isWindowAggregation) { ereport(ERROR, errmsg( "window aggregate function received an invalid state for $push")); } MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue != NULL) { /* * Inverse function is called in sequence in which the row are added using the transition function, * so we don't need to find the `currentValue` pgbson in the list, it can be safely assume that this * is always present at the head of the list. * We only assert that these values are equal to make sure that we are deleting the correct value * * TODO: Maybe move to DLL in future to avoid memory moves when removing first entry */ Assert(PgbsonEquals(currentValue, (pgbson *) linitial( currentState->aggState.window.aggregateList))); currentState->currentSizeWritten -= PgbsonGetBsonSize(currentValue); } currentState->aggState.window.aggregateList = list_delete_first( currentState->aggState.window.aggregateList); MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } Datum bson_distinct_array_agg_transition(PG_FUNCTION_ARGS) { bool handleSingleValueElement = true; char *path = "values"; return BsonArrayAggTransitionCore(fcinfo, handleSingleValueElement, path); } Datum bson_array_agg_final(PG_FUNCTION_ARGS) { bytea *currentArrayAgg = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); if (currentArrayAgg != NULL) { BsonArrayAggState *state = (BsonArrayAggState *) VARDATA_ANY( currentArrayAgg); if (state->isWindowAggregation) { pgbson_writer writer; pgbson_array_writer arrayWriter; PgbsonWriterInit(&writer); PgbsonWriterStartArray(&writer, "", 0, &arrayWriter); ListCell *cell; foreach(cell, state->aggState.window.aggregateList) { pgbson *currentValue = lfirst(cell); /* Empty pgbson values are missing field values which should not be pushed to the array */ bool isMissingValue = IsPgbsonEmptyDocument(currentValue); if (currentValue != NULL && !isMissingValue) { pgbsonelement singleBsonElement; if (TryGetSinglePgbsonElementFromPgbson(currentValue, &singleBsonElement) && singleBsonElement.pathLength == 0) { /* If it's a bson that's { "": value } */ PgbsonArrayWriterWriteValue(&arrayWriter, &singleBsonElement.bsonValue); } else { PgbsonArrayWriterWriteDocument(&arrayWriter, currentValue); } } } PgbsonWriterEndArray(&writer, &arrayWriter); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } else { PgbsonWriterEndArray(&state->aggState.group.writer, &state->aggState.group.arrayWriter); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&state->aggState.group.writer)); } } else { MemoryContext aggregateContext; int aggContext = AggCheckCallContext(fcinfo, &aggregateContext); if (aggContext == AGG_CONTEXT_WINDOW) { /* * We will need to return the default value of $push accumulator which is empty array in case * where the window doesn't select any document. * * e.g ["unbounded", -1] => For the first row it doesn't select any rows. */ pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendEmptyArray(&writer, "", 0); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } PG_RETURN_NULL(); } } /* * The finalfunc for distinct array aggregation. * Similar to array_agg but also writes "ok": 1 * Also returns an empty array with "ok": 1 if never initialized. */ Datum bson_distinct_array_agg_final(PG_FUNCTION_ARGS) { bytea *currentArrayAgg = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); if (currentArrayAgg != NULL) { BsonArrayAggState *state = (BsonArrayAggState *) VARDATA_ANY( currentArrayAgg); if (state->isWindowAggregation) { ereport(ERROR, errmsg( "distinct array aggregate can't be used in a window context")); } PgbsonWriterEndArray(&state->aggState.group.writer, &state->aggState.group.arrayWriter); PgbsonWriterAppendDouble(&state->aggState.group.writer, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&state->aggState.group.writer)); } else { pgbson_writer emptyWriter; PgbsonWriterInit(&emptyWriter); PgbsonWriterAppendEmptyArray(&emptyWriter, "values", 6); PgbsonWriterAppendDouble(&emptyWriter, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&emptyWriter)); } } /* * Core implementation of the object aggregation stage. This is used by both object_agg and merge_objects. * Both have the same implementation but differ in validations made inside the caller method. */ inline static Datum AggregateObjectsCore(PG_FUNCTION_ARGS) { BsonObjectAggState *currentState; bytea *bytes; MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) /* First arg is the running aggregated state*/ { int bson_size = sizeof(BsonObjectAggState) + sizeof(int64_t) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); bytes = combinedStateBytes; currentState = (BsonObjectAggState *) VARDATA(bytes); currentState->currentSizeWritten = 0; currentState->tree = MakeRootNode(); currentState->addEmptyPath = false; } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonObjectAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue != NULL) { CheckAggregateIntermediateResultSize(currentState->currentSizeWritten + PgbsonGetBsonSize(currentValue)); /* * We need to copy the whole pgbson because otherwise the pointers we store * in the tree will reference an address in the stack. These are released after * the function resolves and will point to garbage. */ currentValue = PgbsonCloneFromPgbson(currentValue); CreateObjectAggTreeNodes(currentState, currentValue); currentState->currentSizeWritten += PgbsonGetBsonSize(currentValue); } MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } Datum bson_object_agg_transition(PG_FUNCTION_ARGS) { return AggregateObjectsCore(fcinfo); } /* * Merge objects transition function for pipelines without a sort spec. */ Datum bson_merge_objects_transition_on_sorted(PG_FUNCTION_ARGS) { pgbson *input = PG_GETARG_MAYBE_NULL_PGBSON(1); ValidateMergeObjectsInput(input); return AggregateObjectsCore(fcinfo); } /* * Merge objects transition function for pipelines that contain a sort spec. */ Datum bson_merge_objects_transition(PG_FUNCTION_ARGS) { bool isLast = false; bool isSingle = false; bool storeInputExpression = true; /* If there is a sort spec, we push it to the mergeObjects accumulator stage. */ return BsonOrderTransition(fcinfo, isLast, isSingle, storeInputExpression); } /* * Merge objects final function for aggregation pipelines that contain a sort spec. */ Datum bson_merge_objects_final(PG_FUNCTION_ARGS) { BsonOrderAggState orderState = { 0 }; BsonObjectAggState mergeObjectsState = { 0 }; /* * Here we initialize BsonObjectAggState. * It is necessary to build the bson tree used by $mergeObjects. */ mergeObjectsState.currentSizeWritten = 0; mergeObjectsState.tree = MakeRootNode(); mergeObjectsState.addEmptyPath = false; /* Deserializing the structure used to sort data. */ DeserializeOrderState(PG_GETARG_BYTEA_P(0), &orderState); /* Preparing expressionData to evaluate expression against each sorted bson value. */ pgbsonelement expressionElement; pgbson_writer writer; AggregationExpressionData expressionData; memset(&expressionData, 0, sizeof(AggregationExpressionData)); ParseAggregationExpressionContext parseContext = { 0 }; PgbsonToSinglePgbsonElement(orderState.inputExpression, &expressionElement); ParseAggregationExpressionData(&expressionData, &expressionElement.bsonValue, &parseContext); const AggregationExpressionData *state = &expressionData; StringView path = { .length = expressionElement.pathLength, .string = expressionElement.path, }; /* Populate tree with sorted documents. */ for (int i = 0; i < orderState.currentCount; i++) { /* No more results*/ if (orderState.currentResult[i] == NULL) { break; } /* Check for null value*/ if (orderState.currentResult[i]->value != NULL) { PgbsonWriterInit(&writer); EvaluateAggregationExpressionDataToWriter(state, orderState.currentResult[i]->value, path, &writer, NULL, false); pgbson *evaluatedDoc = PgbsonWriterGetPgbson(&writer); /* We need to validate the result here since we sorted the original documents first. */ ValidateMergeObjectsInput(evaluatedDoc); /* Feed the tree with the evaluated bson. */ CreateObjectAggTreeNodes(&mergeObjectsState, evaluatedDoc); } } return ParseAndReturnMergeObjectsTree(&mergeObjectsState); } Datum bson_object_agg_final(PG_FUNCTION_ARGS) { bytea *currentArrayAgg = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); if (currentArrayAgg != NULL) { BsonObjectAggState *state = (BsonObjectAggState *) VARDATA_ANY( currentArrayAgg); return ParseAndReturnMergeObjectsTree(state); } else { PG_RETURN_POINTER(PgbsonInitEmpty()); } } /* * Applies the "state transition" (SFUNC) for sum and average. * This counts the sum of the values encountered as well as the count * It ignores non-numeric values, and manages type upgrades and coercion * to the right types as documents are encountered. */ Datum bson_sum_avg_transition(PG_FUNCTION_ARGS) { bytea *bytes; BsonNumericAggState *currentState; /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytes = AllocateBsonNumericAggState(); currentState = (BsonNumericAggState *) VARDATA(bytes); currentState->count = 0; currentState->sum.value_type = BSON_TYPE_INT32; currentState->sum.value.v_int32 = 0; MemoryContextSwitchTo(oldContext); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonNumericAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue == NULL) { PG_RETURN_POINTER(bytes); } if (IsPgbsonEmptyDocument(currentValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); bool overflowedFromInt64Ignore = false; if (AddNumberToBsonValue(¤tState->sum, ¤tValueElement.bsonValue, &overflowedFromInt64Ignore)) { currentState->count++; } PG_RETURN_POINTER(bytes); } /* * Applies the "inverse state transition" for sum and average. * This subtracts the sum of the values leaving the group and decrements the count * It ignores non-numeric values, and manages type upgrades and coercion * to the right types as documents are encountered. */ Datum bson_sum_avg_minvtransition(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } bytea *bytes; BsonNumericAggState *currentState; if (PG_ARGISNULL(0)) { /* Returning NULL is an indiacation that inverse can't be applied and the aggregation needs to be redone */ PG_RETURN_NULL(); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonNumericAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue == NULL || IsPgbsonEmptyDocument(currentValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); bool overflowedFromInt64Ignore = false; /* Aply the inverse of $sum and $avg */ if (currentState->count > 0 && SubtractNumberFromBsonValue(¤tState->sum, ¤tValueElement.bsonValue, &overflowedFromInt64Ignore)) { currentState->count--; } PG_RETURN_POINTER(bytes); } /* * Applies the "final calculation" (FINALFUNC) for sum. * This takes the final value created and outputs a bson "sum" * with the appropriate type. */ Datum bson_sum_final(PG_FUNCTION_ARGS) { bytea *currentSum = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (currentSum != NULL) { BsonNumericAggState *state = (BsonNumericAggState *) VARDATA_ANY( currentSum); finalValue.bsonValue = state->sum; } else { /* Mongo returns 0 for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_INT32; finalValue.bsonValue.value.v_int32 = 0; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for average. * This takes the final value created and outputs a bson "average" */ Datum bson_avg_final(PG_FUNCTION_ARGS) { bytea *avgIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (avgIntermediateState != NULL) { BsonNumericAggState *averageState = (BsonNumericAggState *) VARDATA_ANY( avgIntermediateState); if (averageState->count == 0) { /* Mongo returns $null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } else { double sum = BsonValueAsDouble(&averageState->sum); finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = sum / averageState->count; } } else { /* Mongo returns $null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for min and max. * This takes the final value fills in a null bson for empty sets */ Datum bson_min_max_final(PG_FUNCTION_ARGS) { pgbson *current = PG_GETARG_MAYBE_NULL_PGBSON(0); if (current != NULL) { PG_RETURN_POINTER(current); } else { /* Mongo returns $null for empty sets */ pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } } /* * Applies the "state transition" (SFUNC) for max. * This returns the max value of the currently computed max * and the next candidate value. * if the current max is null, returns the next candidate value * If the candidate is null, returns the current max. */ Datum bson_max_transition(PG_FUNCTION_ARGS) { pgbson *left = PG_GETARG_MAYBE_NULL_PGBSON(0); pgbson *right = PG_GETARG_MAYBE_NULL_PGBSON(1); if (left == NULL) { if (right == NULL) { PG_RETURN_NULL(); } PG_RETURN_POINTER(right); } else if (right == NULL) { PG_RETURN_POINTER(left); } int32_t compResult = ComparePgbson(left, right); if (compResult > 0) { PG_RETURN_POINTER(left); } PG_RETURN_POINTER(right); } /* * Applies the "state transition" (SFUNC) for min. * This returns the min value of the currently computed min * and the next candidate value. * if the current min is null, returns the next candidate value * If the candidate is null, returns the current min. */ Datum bson_min_transition(PG_FUNCTION_ARGS) { pgbson *left = PG_GETARG_MAYBE_NULL_PGBSON(0); pgbson *right = PG_GETARG_MAYBE_NULL_PGBSON(1); if (left == NULL) { if (right == NULL) { PG_RETURN_NULL(); } PG_RETURN_POINTER(right); } else if (right == NULL) { PG_RETURN_POINTER(left); } int32_t compResult = ComparePgbson(left, right); if (compResult < 0) { PG_RETURN_POINTER(left); } PG_RETURN_POINTER(right); } /* * Applies the "combine function" (COMBINEFUNC) for sum and average. * takes two of the aggregate state structures (bson_numeric_agg_state) * and combines them to form a new bson_numeric_agg_state that has the combined * sum and count. */ Datum bson_sum_avg_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytea *combinedStateBytes = AllocateBsonNumericAggState(); BsonNumericAggState *currentState = (BsonNumericAggState *) VARDATA_ANY( combinedStateBytes); MemoryContextSwitchTo(oldContext); /* Handle either left or right being null. A new state needs to be allocated regardless */ currentState->count = 0; if (PG_ARGISNULL(0)) { if (PG_ARGISNULL(1)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(1)), sizeof(BsonNumericAggState)); } else if (PG_ARGISNULL(1)) { if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(0)), sizeof(BsonNumericAggState)); } else { BsonNumericAggState *leftState = (BsonNumericAggState *) VARDATA_ANY( PG_GETARG_BYTEA_P(0)); BsonNumericAggState *rightState = (BsonNumericAggState *) VARDATA_ANY( PG_GETARG_BYTEA_P(1)); currentState->count = leftState->count + rightState->count; currentState->sum = leftState->sum; bool overflowedFromInt64Ignore = false; AddNumberToBsonValue(¤tState->sum, &rightState->sum, &overflowedFromInt64Ignore); } PG_RETURN_POINTER(combinedStateBytes); } /* * Applies the "combine function" (COMBINEFUNC) for min. * takes two bsons * makes a new bson equal to the minimum */ Datum bson_min_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); pgbson *left = PG_GETARG_MAYBE_NULL_PGBSON(0); pgbson *right = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *result; if (left == NULL) { if (right == NULL) { result = NULL; } else { result = PgbsonCloneFromPgbson(right); } } else if (right == NULL) { result = PgbsonCloneFromPgbson(left); } else { int32_t compResult = ComparePgbson(left, right); if (compResult < 0) { result = PgbsonCloneFromPgbson(left); } else { result = PgbsonCloneFromPgbson(right); } } MemoryContextSwitchTo(oldContext); if (result == NULL) { PG_RETURN_NULL(); } PG_RETURN_POINTER(result); } /* * Applies the "combine function" (COMBINEFUNC) for max. * takes two bsons * makes a new bson equal to the maximum */ Datum bson_max_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); pgbson *left = PG_GETARG_MAYBE_NULL_PGBSON(0); pgbson *right = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *result; if (left == NULL) { if (right == NULL) { result = NULL; } else { result = PgbsonCloneFromPgbson(right); } } else if (right == NULL) { result = PgbsonCloneFromPgbson(left); } else { int32_t compResult = ComparePgbson(left, right); if (compResult > 0) { result = PgbsonCloneFromPgbson(left); } else { result = PgbsonCloneFromPgbson(right); } } MemoryContextSwitchTo(oldContext); if (result == NULL) { PG_RETURN_NULL(); } PG_RETURN_POINTER(result); } /* * Builds the final distinct response to be sent to the client. * Formats the response as * { "value": [ array_elements ], "ok": 1 } * This allows the gateway to serialize the response directly to the client * without reconverting the response on the Gateway. */ Datum bson_build_distinct_response(PG_FUNCTION_ARGS) { ArrayType *val_array = PG_GETARG_ARRAYTYPE_P(0); Datum *val_datums; bool *val_is_null_marker; int val_count; deconstruct_array(val_array, ARR_ELEMTYPE(val_array), -1, false, TYPALIGN_INT, &val_datums, &val_is_null_marker, &val_count); /* Distinct never has SQL NULL in the array */ pfree(val_is_null_marker); pgbson_writer writer; PgbsonWriterInit(&writer); pgbson_array_writer arrayWriter; PgbsonWriterStartArray(&writer, "values", 6, &arrayWriter); for (int i = 0; i < val_count; i++) { pgbsonelement singleElement; PgbsonToSinglePgbsonElement((pgbson *) val_datums[i], &singleElement); PgbsonArrayWriterWriteValue(&arrayWriter, &singleElement.bsonValue); } PgbsonWriterEndArray(&writer, &arrayWriter); PgbsonWriterAppendDouble(&writer, "ok", 2, 1); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } /* * Transition function for the BSON_ADD_TO_SET aggregate. */ Datum bson_add_to_set_transition(PG_FUNCTION_ARGS) { BsonAddToSetState *currentState = { 0 }; bytea *bytes; MemoryContext aggregateContext; int aggregationContext = AggCheckCallContext(fcinfo, &aggregateContext); if (aggregationContext == 0) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } bool isWindowAggregation = aggregationContext == AGG_CONTEXT_WINDOW; /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) /* First arg is the running aggregated state*/ { int bson_size = sizeof(BsonAddToSetState) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); bytes = combinedStateBytes; currentState = (BsonAddToSetState *) VARDATA(bytes); currentState->currentSizeWritten = 0; currentState->set = CreateBsonValueHashSet(); currentState->isWindowAggregation = isWindowAggregation; } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonAddToSetState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue != NULL && !IsPgbsonEmptyDocument(currentValue)) { CheckAggregateIntermediateResultSize(currentState->currentSizeWritten + PgbsonGetBsonSize(currentValue)); /* * We need to copy the whole pgbson because otherwise the pointers we store * in the hash table will reference an address in the stack. These are released * after the function resolves and will point to garbage. */ currentValue = PgbsonCloneFromPgbson(currentValue); pgbsonelement singleBsonElement; /* If it's a bson that's { "": value } */ if (TryGetSinglePgbsonElementFromPgbson(currentValue, &singleBsonElement) && singleBsonElement.pathLength == 0) { bool found = false; hash_search(currentState->set, &singleBsonElement.bsonValue, HASH_ENTER, &found); /* * If the BSON was not found in the hash table, add its size to the current * state object. */ if (!found) { currentState->currentSizeWritten += PgbsonGetBsonSize(currentValue); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Bad input format for addToSet transition."))); } } MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } /* * Final function for the BSON_ADD_TO_SET aggregate. */ Datum bson_add_to_set_final(PG_FUNCTION_ARGS) { bytea *currentState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); if (currentState != NULL) { BsonAddToSetState *state = (BsonAddToSetState *) VARDATA_ANY( currentState); HASH_SEQ_STATUS seq_status; const bson_value_t *entry; hash_seq_init(&seq_status, state->set); pgbson_writer writer; PgbsonWriterInit(&writer); pgbson_array_writer arrayWriter; PgbsonWriterStartArray(&writer, "", 0, &arrayWriter); while ((entry = hash_seq_search(&seq_status)) != NULL) { PgbsonArrayWriterWriteValue(&arrayWriter, entry); } /* * For window aggregation, with the HASHCTL destroyed (on the call for the first group), * subsequent calls to this final function for other groups will fail * for certain bounds such as ["unbounded", constant]. * This is because the head never moves and the aggregation is not restarted. * Thus, the table is expected to hold something valid. */ if (!state->isWindowAggregation) { hash_destroy(state->set); } PgbsonWriterEndArray(&writer, &arrayWriter); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } else { MemoryContext aggregateContext; int aggContext = AggCheckCallContext(fcinfo, &aggregateContext); if (aggContext == AGG_CONTEXT_WINDOW) { /* * We will need to return the default value of $addToSet accumulator which is empty array in case * where the window doesn't select any document. * * e.g ["unbounded", -1] => For the first row it doesn't select any rows. */ pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendEmptyArray(&writer, "", 0); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&writer)); } PG_RETURN_NULL(); } } /* --------------------------------------------------------- */ /* Private helper methods */ /* --------------------------------------------------------- */ bytea * AllocateBsonNumericAggState() { int bson_size = sizeof(BsonNumericAggState) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); return combinedStateBytes; } void CheckAggregateIntermediateResultSize(uint32_t size) { if (size > BSON_MAX_ALLOWED_SIZE_INTERMEDIATE) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERMEDIATERESULTTOOLARGE), errmsg( "Size %u is larger than maximum size allowed for an intermediate document %u", size, BSON_MAX_ALLOWED_SIZE_INTERMEDIATE))); } } /* * Helper method that iterates a pgbson writing its values to a bson tree. If a key already * exists in the tree, then it's overwritten. */ static void CreateObjectAggTreeNodes(BsonObjectAggState *currentState, pgbson *currentValue) { bson_iter_t docIter; pgbsonelement singleBsonElement; bool treatLeafDataAsConstant = true; ParseAggregationExpressionContext parseContext = { 0 }; /* * If currentValue has the form of { "": value } and value is a bson document, * write only the value in the BsonTree. We need this because of how accumulators work * with bson_repath_and_build. */ if (TryGetSinglePgbsonElementFromPgbson(currentValue, &singleBsonElement) && singleBsonElement.pathLength == 0 && singleBsonElement.bsonValue.value_type == BSON_TYPE_DOCUMENT) { BsonValueInitIterator(&singleBsonElement.bsonValue, &docIter); currentState->addEmptyPath = true; } else { PgbsonInitIterator(currentValue, &docIter); } while (bson_iter_next(&docIter)) { StringView pathView = bson_iter_key_string_view(&docIter); const bson_value_t *docValue = bson_iter_value(&docIter); bool nodeCreated = false; const BsonLeafPathNode *treeNode = TraverseDottedPathAndGetOrAddLeafFieldNode( &pathView, docValue, currentState->tree, BsonDefaultCreateLeafNode, treatLeafDataAsConstant, &nodeCreated, &parseContext); /* If the node already exists we need to update the value as object agg and merge objects * have the behavior that the last path spec (if duplicate) takes precedence. */ if (!nodeCreated) { ResetNodeWithField(treeNode, NULL, docValue, BsonDefaultCreateLeafNode, treatLeafDataAsConstant, &parseContext); } } } /* * Validates $mergeObject input. It must be a non-null document. */ static void ValidateMergeObjectsInput(pgbson *input) { pgbsonelement singleBsonElement; /* * The $mergeObjects accumulator expects a document in the form of * { "": }. This required by the bson_repath_and_build function. * Hence we check for a document with a single element below. */ if (input == NULL || !TryGetSinglePgbsonElementFromPgbson(input, &singleBsonElement)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Bad input format for mergeObjects transition."))); } /* * We fail if the bson value type is not DOCUMENT or NULL. */ if (singleBsonElement.bsonValue.value_type != BSON_TYPE_DOCUMENT && singleBsonElement.bsonValue.value_type != BSON_TYPE_NULL) { ereport(ERROR, errcode(ERRCODE_DOCUMENTDB_DOLLARMERGEOBJECTSINVALIDTYPE), errmsg( "$mergeObjects needs both inputs to be objects, but the provided input %s has the type %s", BsonValueToJsonForLogging(&singleBsonElement.bsonValue), BsonTypeName(singleBsonElement.bsonValue.value_type)), errdetail_log( "$mergeObjects needs both inputs to be objects, but the provided input has the type %s", BsonTypeName(singleBsonElement.bsonValue.value_type))); } } /* * Function used to parse and return a mergeObjects tree. */ static Datum ParseAndReturnMergeObjectsTree(BsonObjectAggState *state) { if (state != NULL) { pgbson_writer writer; PgbsonWriterInit(&writer); /* * If we removed the original empty path, then we need to include it * again for bson_repath_and_build. */ if (state->addEmptyPath) { pgbson_writer childWriter; PgbsonWriterStartDocument(&writer, "", 0, &childWriter); TraverseTreeAndWrite(state->tree, &childWriter, NULL); PgbsonWriterEndDocument(&writer, &childWriter); } else { TraverseTreeAndWrite(state->tree, &writer, NULL); } pgbson *result = PgbsonWriterGetPgbson(&writer); FreeTree(state->tree); PG_RETURN_POINTER(result); } else { PG_RETURN_POINTER(PgbsonInitEmpty()); } } /* * Comparator function for heap utils. For MaxN, we need to build min-heap */ static bool HeapSortComparatorMaxN(const void *first, const void *second) { bool ignoreIsComparisonValid = false; /* IsComparable ensures this is taken care of */ return CompareBsonValueAndType((const bson_value_t *) first, (const bson_value_t *) second, &ignoreIsComparisonValid) < 0; } /* * Comparator function for heap utils. For MinN, we need to build max-heap */ static bool HeapSortComparatorMinN(const void *first, const void *second) { bool ignoreIsComparisonValid = false; /* IsComparable ensures this is taken care of */ return CompareBsonValueAndType((const bson_value_t *) first, (const bson_value_t *) second, &ignoreIsComparisonValid) > 0; } /* * Applies the "state transition" (SFUNC) for maxN/minN accumulators. * The args in PG_FUNCTION_ARGS: * Evaluated expression: input and N. * * For maxN: * we need to maintain a small root heap and compare the current value with the top of the heap (minimum value). * If the current value is greater than the top of the heap (minimum value), then we will pop the top of the heap and insert the current value. * * For minN: * we need to maintain a big root heap and compare the current value with the top of the heap (minimum value). * If the current value is less than the top of the heap (minimum value), then we will pop the top of the heap and insert the current value. */ Datum bson_maxminn_transition(PG_FUNCTION_ARGS, bool isMaxN) { bytea *bytes = NULL; MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function %s transition invoked in non-aggregate context", isMaxN ? "maxN" : "minN")); } /* Create the aggregate state in the aggregate context. */ pgbson *copiedPgbson = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *currentValue = CopyPgbsonIntoMemoryContext(copiedPgbson, aggregateContext); pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); bson_value_t currentBsonValue = currentValueElement.bsonValue; /*input and N are both expression, so we evaluate them togather.*/ bson_iter_t docIter; BsonValueInitIterator(¤tBsonValue, &docIter); bson_value_t inputBsonValue = { 0 }; bson_value_t elementBsonValue = { 0 }; while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "input") == 0) { inputBsonValue = *bson_iter_value(&docIter); } else if (strcmp(key, "n") == 0) { elementBsonValue = *bson_iter_value(&docIter); } } /* Ensure that N is a valid integer value. */ ValidateElementForNGroupAccumulators(&elementBsonValue, isMaxN == true ? "maxN" : "minN"); bool throwIfFailed = true; int64_t element = BsonValueAsInt64WithRoundingMode(&elementBsonValue, ConversionRoundingMode_Floor, throwIfFailed); BinaryHeapState *currentState = (BinaryHeapState *) palloc0(sizeof(BinaryHeapState)); /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) { currentState->isMaxN = isMaxN; /* * For maxN, we need to maintain a small root heap. * When currentValue is greater than the top of the heap, we need to remove the top of the heap and insert currentValue. * * For minN, we need to maintain a large root heap. * When currentValue is less than the top of the heap, we need to remove the top of the heap and insert currentValue. */ int64_t totalSize = sizeof(bson_value_t) * element + sizeof(BinaryHeapState) + sizeof(BinaryHeap); /* TODO: Support element as int64. */ if (element > INT32_MAX || totalSize > BSON_MAX_ALLOWED_SIZE_INTERMEDIATE) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERMEDIATERESULTTOOLARGE), errmsg( "Size is larger than maximum size allowed for an intermediate document %u", BSON_MAX_ALLOWED_SIZE_INTERMEDIATE))); } currentState->heap = AllocateHeap(element, isMaxN == true ? HeapSortComparatorMaxN : HeapSortComparatorMinN); } else { bytes = PG_GETARG_BYTEA_P(0); DeserializeBinaryHeapState(bytes, currentState); } /*if the input is null or an undefined path, ignore it */ if (!IsExpressionResultNullOrUndefined(&inputBsonValue)) { if (currentState->heap->heapSize < element) { /* Heap is not full, insert value. */ PushToHeap(currentState->heap, &inputBsonValue); } else { /* Heap is full, replace the top if the new value should be included instead */ bson_value_t topHeap = TopHeap(currentState->heap); if (!currentState->heap->heapComparator(&inputBsonValue, &topHeap)) { PopFromHeap(currentState->heap); PushToHeap(currentState->heap, &inputBsonValue); } } } bytes = SerializeBinaryHeapState(aggregateContext, currentState, PG_ARGISNULL(0) ? NULL : bytes); PG_RETURN_POINTER(bytes); } /* * Converts a BinaryHeapState into a serialized form to allow the internal type to be bytea * Resulting bytes look like: * | Varlena Header | isMaxN | heapSize | heapSpace | heapNode * heapSpace | */ bytea * SerializeBinaryHeapState(MemoryContext aggregateContext, BinaryHeapState *state, bytea *byteArray) { int heapNodesSize = 0; pgbson **heapNodeList = NULL; if (state->heap->heapSize > 0) { heapNodeList = (pgbson **) palloc(sizeof(pgbson *) * state->heap->heapSize); for (int i = 0; i < state->heap->heapSize; i++) { heapNodeList[i] = BsonValueToDocumentPgbson(&state->heap->heapNodes[i]); pgbsonelement element; PgbsonToSinglePgbsonElement(heapNodeList[i], &element); heapNodesSize += VARSIZE(heapNodeList[i]); } } int requiredByteSize = VARHDRSZ + sizeof(bool) + sizeof(int64) + sizeof(int64) + heapNodesSize; char *bytes; int existingByteSize = (byteArray == NULL) ? 0 : VARSIZE(byteArray); if (existingByteSize >= requiredByteSize) { /* Reuse existing bytes */ bytes = (char *) byteArray; } else { bytes = (char *) MemoryContextAlloc(aggregateContext, requiredByteSize); SET_VARSIZE(bytes, requiredByteSize); } /* Copy in the currentValue */ char *byteAllocationPointer = (char *) VARDATA(bytes); *((bool *) (byteAllocationPointer)) = state->isMaxN; byteAllocationPointer += sizeof(bool); *((int64 *) (byteAllocationPointer)) = state->heap->heapSize; byteAllocationPointer += sizeof(int64); *((int64 *) (byteAllocationPointer)) = state->heap->heapSpace; byteAllocationPointer += sizeof(int64); if (state->heap->heapSize > 0) { for (int i = 0; i < state->heap->heapSize; i++) { memcpy(byteAllocationPointer, heapNodeList[i], VARSIZE(heapNodeList[i])); byteAllocationPointer += VARSIZE(heapNodeList[i]); } } return (bytea *) bytes; } /* * Converts a BinaryHeapState from a serialized form to allow the internal type to be bytea * Incoming bytes look like: * | Varlena Header | isMaxN | heapSize | heapSpace | heapNode * heapSpace | */ void DeserializeBinaryHeapState(bytea *byteArray, BinaryHeapState *state) { if (byteArray == NULL) { return; } char *bytes = (char *) VARDATA(byteArray); state->isMaxN = *(bool *) (bytes); bytes += sizeof(bool); int64 heapSize = *(int64 *) (bytes); bytes += sizeof(int64); int64 heapSpace = *(int64 *) (bytes); bytes += sizeof(int64); state->heap = (BinaryHeap *) palloc(sizeof(BinaryHeap)); state->heap->heapSize = heapSize; state->heap->heapSpace = heapSpace; state->heap->heapNodes = (bson_value_t *) palloc(sizeof(bson_value_t) * heapSpace); if (state->heap->heapSize > 0) { for (int i = 0; i < state->heap->heapSize; i++) { pgbson *pgbsonValue = (pgbson *) bytes; bytes += VARSIZE(pgbsonValue); pgbsonelement element; PgbsonToSinglePgbsonElement(pgbsonValue, &element); state->heap->heapNodes[i] = element.bsonValue; } } state->heap->heapComparator = state->isMaxN ? HeapSortComparatorMaxN : HeapSortComparatorMinN; } /* * Applies the "final" (FINALFUNC) for maxN/minN. * This takes the final value created and outputs a bson "maxN/minN" * with the appropriate type. */ Datum bson_maxminn_final(PG_FUNCTION_ARGS) { bytea *maxNIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbson *finalPgbson = NULL; pgbson_writer writer; pgbson_array_writer arrayWriter; PgbsonWriterInit(&writer); PgbsonWriterStartArray(&writer, "", 0, &arrayWriter); if (maxNIntermediateState != NULL) { BinaryHeapState *maxNState = (BinaryHeapState *) palloc(sizeof(BinaryHeapState)); DeserializeBinaryHeapState(maxNIntermediateState, maxNState); int64_t numEntries = maxNState->heap->heapSize; bson_value_t *valueArray = (bson_value_t *) palloc(sizeof(bson_value_t) * numEntries); while (maxNState->heap->heapSize > 0) { valueArray[maxNState->heap->heapSize - 1] = PopFromHeap(maxNState->heap); } for (int64_t i = 0; i < numEntries; i++) { PgbsonArrayWriterWriteValue(&arrayWriter, &valueArray[i]); } pfree(valueArray); FreeHeap(maxNState->heap); } PgbsonWriterEndArray(&writer, &arrayWriter); finalPgbson = PgbsonWriterGetPgbson(&writer); PG_RETURN_POINTER(finalPgbson); } /* * Applies the "state transition" (SFUNC) for maxN. * For maxN, we need to maintain a small root heap. * When currentValue is greater than the top of the heap, we need to remove the top of the heap and insert currentValue. */ Datum bson_maxn_transition(PG_FUNCTION_ARGS) { bool isMaxN = true; return bson_maxminn_transition(fcinfo, isMaxN); } /* * Applies the "state transition" (SFUNC) for minN. * For minN, we need to maintain a large root heap. * When currentValue is less than the top of the heap, we need to remove the top of the heap and insert currentValue. */ Datum bson_minn_transition(PG_FUNCTION_ARGS) { bool isMaxN = false; return bson_maxminn_transition(fcinfo, isMaxN); } /* * Applies the "combine" (COMBINEFUNC) for maxN/minN. */ Datum bson_maxminn_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate functions maxN or minN have been invoked within a non-aggregation context.")); } if (PG_ARGISNULL(0)) { return PG_GETARG_DATUM(1); } if (PG_ARGISNULL(1)) { return PG_GETARG_DATUM(0); } bytea *bytesLeft; bytea *bytesRight; BinaryHeapState *currentLeftState = (BinaryHeapState *) palloc( sizeof(BinaryHeapState)); BinaryHeapState *currentRightState = (BinaryHeapState *) palloc( sizeof(BinaryHeapState)); bytesLeft = PG_GETARG_BYTEA_P(0); DeserializeBinaryHeapState(bytesLeft, currentLeftState); bytesRight = PG_GETARG_BYTEA_P(1); DeserializeBinaryHeapState(bytesRight, currentRightState); /* Merge the left heap into the currentRightState heap. */ while (currentLeftState->heap->heapSize > 0) { bson_value_t leftBsonValue = TopHeap(currentLeftState->heap); bson_value_t rightBsonValue = TopHeap(currentRightState->heap); /* * For maxN, If the root of the left heap is greater than the root of the currentState heap, * remove the root of the currentState heap and insert the root of the left heap. * * For minN, If the root of the left heap is less than the root of the currentState heap, * remove the root of the currentState heap and insert the root of the left heap. * */ if (currentRightState->heap->heapSize < currentRightState->heap->heapSpace) { PushToHeap(currentRightState->heap, &leftBsonValue); } else if (!currentLeftState->heap->heapComparator(&leftBsonValue, &rightBsonValue)) { PopFromHeap(currentRightState->heap); PushToHeap(currentRightState->heap, &leftBsonValue); } PopFromHeap(currentLeftState->heap); } FreeHeap(currentLeftState->heap); bytesRight = SerializeBinaryHeapState(aggregateContext, currentRightState, bytesRight); PG_RETURN_POINTER(bytesRight); } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_config_queries.c000066400000000000000000000417741507310017400304440ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_config_queries.c * * Implementation of the backend query generation for queries targetting * the config database. * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" #include "api_hooks.h" static Query * GenerateVersionQuery(AggregationPipelineBuildContext *context); static Query * GenerateDatabasesQuery(AggregationPipelineBuildContext *context); static Query * GenerateCollectionsQuery(AggregationPipelineBuildContext *context); static Query * GenerateChunksQuery(AggregationPipelineBuildContext *context); static Query * GenerateShardsQuery(AggregationPipelineBuildContext *context); static Query * GenerateSettingsQuery(AggregationPipelineBuildContext *context); /* * Sets the RTE of a table in the Config database. */ Query * GenerateConfigDatabaseQuery(AggregationPipelineBuildContext *context) { if (StringViewEqualsCString(&context->collectionNameView, "version")) { return GenerateVersionQuery(context); } else if (StringViewEqualsCString(&context->collectionNameView, "databases")) { context->requiresPersistentCursor = true; return GenerateDatabasesQuery(context); } else if (StringViewEqualsCString(&context->collectionNameView, "collections")) { context->requiresPersistentCursor = true; return GenerateCollectionsQuery(context); } else if (StringViewEqualsCString(&context->collectionNameView, "chunks")) { context->requiresPersistentCursor = true; return GenerateChunksQuery(context); } else if (StringViewEqualsCString(&context->collectionNameView, "settings")) { context->requiresPersistentCursor = true; return GenerateSettingsQuery(context); } else if (StringViewEqualsCString(&context->collectionNameView, "_shards")) { /* TODO: We can't enable this on shards because there's a dependency */ /* on the "host" which requires a connection string. Once we can pass */ /* the MX connection string - reconsider adding this back. */ context->requiresPersistentCursor = true; return GenerateShardsQuery(context); } else { return NULL; } } /* * Generates a query that mimics the output of config.versions */ static Query * GenerateVersionQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->mongoCollection = NULL; query->rtable = NIL; /* Create an empty jointree structure */ query->jointree = makeNode(FromExpr); /* Create the projector. We only project the NULL::bson in this type of query */ pgbson_writer versionsWriter; PgbsonWriterInit(&versionsWriter); PgbsonWriterAppendBool(&versionsWriter, "shardingEnabled", 15, true); Const *documentEntry = MakeBsonConst(PgbsonWriterGetPgbson(&versionsWriter)); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); context->requiresPersistentCursor = true; query = MigrateQueryToSubQuery(query, context); return query; } /* * Mimics the output of the config.databases collection. */ static Query * GenerateDatabasesQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiCatalogSchemaName.collections function */ List *colNames = list_concat(list_make3(makeString("database_name"), makeString( "collection_name"), makeString( "collection_id")), list_make3(makeString("shard_key"), makeString( "collection_uuid"), makeString( "view_definition"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collections", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif query->rtable = list_make1(rte); /* Now register the RTE in the "FROM" clause with a single filter on shard_key not null */ NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NOT_NULL; nullTest->arg = (Expr *) makeVar(1, 4, BsonTypeId(), -1, InvalidOid, 0); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), (Node *) nullTest); /* Add a row_get_bson to make it a single bson document */ Var *rowExpr = makeVar(1, 0, ApiCatalogCollectionsTypeOid(), -1, InvalidOid, 0); FuncExpr *funcExpr = makeFuncExpr(RowGetBsonFunctionOid(), BsonTypeId(), list_make1(rowExpr), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) funcExpr, 1, "document", false); query->targetList = list_make1(baseTargetEntry); /* Move to a subquery */ query = MigrateQueryToSubQuery(query, context); /* Now group by database_name */ pgbson_writer groupWriter; PgbsonWriterInit(&groupWriter); PgbsonWriterAppendUtf8(&groupWriter, "_id", 3, "$database_name"); pgbson *groupSpec = PgbsonWriterGetPgbson(&groupWriter); bson_value_t groupValue = ConvertPgbsonToBsonValue(groupSpec); query = HandleGroup(&groupValue, query, context); query = MigrateQueryToSubQuery(query, context); pgbson_writer projectionSpec; PgbsonWriterInit(&projectionSpec); PgbsonWriterAppendBool(&projectionSpec, "partitioned", 11, true); pgbson *spec = PgbsonWriterGetPgbson(&projectionSpec); bson_value_t projectionValue = ConvertPgbsonToBsonValue(spec); /* no use for *WithLet or *WithLetAndCollation projection functions here, so we set them to NULL */ Oid (*addFieldsWithLetFuncOid) (void) = NULL; Oid (*addFieldsWithLetAndCollationFuncOid) (void) = NULL; query = HandleSimpleProjectionStage( &projectionValue, query, context, "$addFields", BsonDollarAddFieldsFunctionOid(), addFieldsWithLetFuncOid, addFieldsWithLetAndCollationFuncOid); return query; } /* * Mimics the output of the config.collections collection. */ static Query * GenerateCollectionsQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiCatalogSchemaName.collections function */ List *colNames = list_concat(list_make3(makeString("database_name"), makeString( "collection_name"), makeString( "collection_id")), list_make3(makeString("shard_key"), makeString( "collection_uuid"), makeString( "view_definition"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collections", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif query->rtable = list_make1(rte); /* Now register the RTE in the "FROM" clause with a single filter on shard_key not null */ NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NOT_NULL; nullTest->arg = (Expr *) makeVar(1, 4, BsonTypeId(), -1, InvalidOid, 0); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), (Node *) nullTest); /* Add a row_get_bson to make it a single bson document */ Var *rowExpr = makeVar(1, 0, ApiCatalogCollectionsTypeOid(), -1, InvalidOid, 0); FuncExpr *funcExpr = makeFuncExpr(RowGetBsonFunctionOid(), BsonTypeId(), list_make1(rowExpr), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) funcExpr, 1, "document", false); query->targetList = list_make1(baseTargetEntry); /* Modify the output to match the config.collections output */ pgbson_writer writer; PgbsonWriterInit(&writer); pgbson_writer childWriter; PgbsonWriterStartDocument(&writer, "_id", 3, &childWriter); pgbson_array_writer childArray; PgbsonWriterStartArray(&childWriter, "$concat", 7, &childArray); PgbsonArrayWriterWriteUtf8(&childArray, "$database_name"); PgbsonArrayWriterWriteUtf8(&childArray, "."); PgbsonArrayWriterWriteUtf8(&childArray, "$collection_name"); PgbsonWriterEndArray(&childWriter, &childArray); PgbsonWriterEndDocument(&writer, &childWriter); PgbsonWriterAppendUtf8(&writer, "key", 3, "$shard_key"); /* Since we use $project, use $literal since bools and numbers need to be escaped */ pgbson_writer expressionWriter; PgbsonWriterStartDocument(&writer, "noBalance", 9, &expressionWriter); PgbsonWriterAppendBool(&expressionWriter, "$literal", -1, true); PgbsonWriterEndDocument(&writer, &expressionWriter); pgbson *spec = PgbsonWriterGetPgbson(&writer); bson_value_t projectionValue = ConvertPgbsonToBsonValue(spec); /* no use for *WithLet or *WithLetAndCollation projection functions here, so we set them to NULL */ Oid (*addFieldsWithLetFuncOid) (void) = NULL; Oid (*addFieldsWithLetAndCollationFuncOid) (void) = NULL; query = HandleSimpleProjectionStage( &projectionValue, query, context, "$project", BsonDollarProjectFunctionOid(), addFieldsWithLetFuncOid, addFieldsWithLetAndCollationFuncOid); return query; } /* Simulates the output of the config.chunks table */ static Query * GenerateChunksQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiCatalogSchemaName.collections function */ List *colNames = list_concat(list_make3(makeString("database_name"), makeString( "collection_name"), makeString( "collection_id")), list_make3(makeString("shard_key"), makeString( "collection_uuid"), makeString( "view_definition"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collections", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif query->rtable = list_make1(rte); /* Now register the RTE in the "FROM" clause with a single filter on shard_key not null */ NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NOT_NULL; nullTest->arg = (Expr *) makeVar(1, 4, BsonTypeId(), -1, InvalidOid, 0); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), (Node *) nullTest); /* Add a row_get_bson to make it a single bson document */ Var *rowExpr = makeVar(1, 0, ApiCatalogCollectionsTypeOid(), -1, InvalidOid, 0); FuncExpr *funcExpr = makeFuncExpr(RowGetBsonFunctionOid(), BsonTypeId(), list_make1(rowExpr), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) funcExpr, 1, "document", false); query->targetList = list_make1(baseTargetEntry); /* Modify the output to match the config.chunks output */ pgbson_writer writer; PgbsonWriterInit(&writer); pgbson_writer childWriter; PgbsonWriterStartDocument(&writer, "ns", 2, &childWriter); pgbson_array_writer childArray; PgbsonWriterStartArray(&childWriter, "$concat", 7, &childArray); PgbsonArrayWriterWriteUtf8(&childArray, "$database_name"); PgbsonArrayWriterWriteUtf8(&childArray, "."); PgbsonArrayWriterWriteUtf8(&childArray, "$collection_name"); PgbsonWriterEndArray(&childWriter, &childArray); PgbsonWriterEndDocument(&writer, &childWriter); PgbsonWriterAppendUtf8(&writer, "shard", 5, "defaultShard"); /* Since we use $project, use $literal since bools and numbers need to be escaped */ pgbson_writer expressionWriter; PgbsonWriterStartDocument(&writer, "min", 3, &expressionWriter); PgbsonWriterAppendInt64(&expressionWriter, "$literal", -1, LONG_MIN); PgbsonWriterEndDocument(&writer, &expressionWriter); PgbsonWriterStartDocument(&writer, "max", 3, &expressionWriter); PgbsonWriterAppendInt64(&expressionWriter, "$literal", -1, LONG_MAX); PgbsonWriterEndDocument(&writer, &expressionWriter); pgbson *spec = PgbsonWriterGetPgbson(&writer); bson_value_t projectionValue = ConvertPgbsonToBsonValue(spec); /* no use for *WithLet or *WithLetAndCollation projection functions here, so we set them to NULL */ Oid (*projectWithLetFuncOid) (void) = NULL; Oid (*projectWithLetAndCollationFuncOid) (void) = NULL; query = HandleSimpleProjectionStage( &projectionValue, query, context, "$project", BsonDollarProjectFunctionOid(), projectWithLetFuncOid, projectWithLetAndCollationFuncOid); return MutateChunksQueryForDistribution(query); } static Query * GenerateShardsQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->mongoCollection = NULL; query->rtable = NIL; /* Create an empty jointree structure */ query->jointree = makeNode(FromExpr); /* Create the projector. We only project the NULL::bson in this type of query */ pgbson_writer shardsWriter; PgbsonWriterInit(&shardsWriter); PgbsonWriterAppendUtf8(&shardsWriter, "_id", 3, "defaultShard"); Const *documentEntry = MakeBsonConst(PgbsonWriterGetPgbson(&shardsWriter)); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); context->requiresPersistentCursor = true; query = MigrateQueryToSubQuery(query, context); return MutateShardsQueryForDistribution(query); } static Query * GenerateSettingsQuery(AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->mongoCollection = NULL; List *valuesList = NIL; /* { _id: balancer, stopped: true } */ pgbson_writer balancerWriter; PgbsonWriterInit(&balancerWriter); PgbsonWriterAppendUtf8(&balancerWriter, "_id", 3, "balancer"); PgbsonWriterAppendBool(&balancerWriter, "stopped", 7, true); valuesList = lappend(valuesList, list_make1(MakeBsonConst(PgbsonWriterGetPgbson( &balancerWriter)))); /* { _id: autosplit, enabled: false } */ pgbson_writer autosplitWriter; PgbsonWriterInit(&autosplitWriter); PgbsonWriterAppendUtf8(&autosplitWriter, "_id", 3, "autosplit"); PgbsonWriterAppendBool(&autosplitWriter, "enabled", 7, false); valuesList = lappend(valuesList, list_make1(MakeBsonConst(PgbsonWriterGetPgbson( &autosplitWriter)))); RangeTblEntry *valuesRte = makeNode(RangeTblEntry); valuesRte->rtekind = RTE_VALUES; valuesRte->alias = valuesRte->eref = makeAlias("values", list_make1(makeString( "document"))); valuesRte->lateral = false; valuesRte->values_lists = valuesList; valuesRte->inh = false; valuesRte->inFromCl = true; valuesRte->coltypes = list_make1_oid(INT8OID); valuesRte->coltypmods = list_make1_int(-1); valuesRte->colcollations = list_make1_oid(InvalidOid); query->rtable = list_make1(valuesRte); query->jointree = makeNode(FromExpr); RangeTblRef *valuesRteRef = makeNode(RangeTblRef); valuesRteRef->rtindex = 1; query->jointree->fromlist = list_make1(valuesRteRef); /* Point to the values RTE */ Var *documentEntry = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); context->requiresPersistentCursor = true; return query; } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_metadata_queries.c000066400000000000000000000746661507310017400307650ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/planner/bson_aggregation_metadata_queries.c * * Implementation of the backend query generation for metadata type queries * (e.g. listCollections, listIndexes). * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "query/query_operator.h" #include "planner/documentdb_planner.h" #include "aggregation/bson_aggregation_pipeline.h" #include "commands/parse_error.h" #include "commands/commands_common.h" #include "utils/feature_counter.h" #include "utils/version_utils.h" #include "aggregation/bson_aggregation_pipeline_private.h" #include "api_hooks.h" static Query * GenerateBaseListCollectionsQuery(Datum databaseDatum, bool nameOnly, bool addDistributedMetadata, AggregationPipelineBuildContext *context); static Query * HandleListCollectionsProjector(Query *query, AggregationPipelineBuildContext *context, bool nameOnly, bool addDistributedMetadata); static Query * GenerateBaseListIndexesQuery(text *databaseDatum, const StringView *collectionName, AggregationPipelineBuildContext *context); static Query * BuildSingleFunctionQuery(Oid queryFunctionOid, List *queryArgs, bool isMultiRow); /* * Generates the base query for collection agnostic aggregate queries * and populates the necessary state into the context object. * The query formed is * SELECT NULL::bson; * This is because any agnostic stage will overwrite this anyway. */ Query * GenerateBaseAgnosticQuery(text *databaseDatum, AggregationPipelineBuildContext *context) { StringView agnosticCollection = CreateStringViewFromString("$cmd.aggregate"); Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->collectionNameView = agnosticCollection; context->namespaceName = CreateNamespaceName(databaseDatum, &agnosticCollection); context->mongoCollection = NULL; query->rtable = NIL; /* Create an empty jointree structure */ query->jointree = makeNode(FromExpr); /* Create the projector. We only project the NULL::bson in this type of query */ Const *documentEntry = makeConst(BsonTypeId(), -1, InvalidOid, -1, (Datum) 0, true, false); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); return query; } /* * Generates a query that is akin to the MongoDB $listCollections query command */ Query * GenerateListCollectionsQuery(text *databaseDatum, pgbson *listCollectionsSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = databaseDatum; bson_iter_t listCollectionsIter; PgbsonInitIterator(listCollectionsSpec, &listCollectionsIter); bson_value_t filter = { 0 }; bool nameOnly = false; bool distributedMetadata = false; while (bson_iter_next(&listCollectionsIter)) { StringView keyView = bson_iter_key_string_view(&listCollectionsIter); const bson_value_t *value = bson_iter_value(&listCollectionsIter); if (StringViewEqualsCString(&keyView, "listCollections")) { continue; } else if (StringViewEqualsCString(&keyView, "filter")) { if (!BSON_ITER_HOLDS_NULL(&listCollectionsIter)) { EnsureTopLevelFieldType("filter", &listCollectionsIter, BSON_TYPE_DOCUMENT); filter = *value; } } else if (StringViewEqualsCString(&keyView, "cursor")) { ParseCursorDocument(&listCollectionsIter, queryData); } else if (StringViewEqualsCString(&keyView, "nameOnly")) { nameOnly = BsonValueAsBool(value); } else if (StringViewEqualsCString(&keyView, "addDistributedMetadata")) { distributedMetadata = BsonValueAsBool(value); } else if (StringViewEqualsCString(&keyView, "authorizedCollections")) { /* TODO: Handle this */ } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { EnsureTopLevelFieldIsNumberLike("listCollections.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (StringViewEqualsCString(&keyView, "$db")) { if (context.databaseNameDatum == NULL) { /* Extract the database out of $db */ EnsureTopLevelFieldType("$db", &listCollectionsIter, BSON_TYPE_UTF8); uint32_t databaseLength = 0; const char *databaseName = bson_iter_utf8(&listCollectionsIter, &databaseLength); context.databaseNameDatum = cstring_to_text_with_len(databaseName, databaseLength); databaseDatum = context.databaseNameDatum; } } else if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field listCollections.%.*s is not recognized as a valid field", keyView.length, keyView.string), errdetail_log( "The BSON field listCollections.%.*s is not recognized as a valid field", keyView.length, keyView.string))); } } if (context.databaseNameDatum == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required field database must be valid"))); } Query *query = GenerateBaseListCollectionsQuery(PointerGetDatum(databaseDatum), nameOnly, distributedMetadata, &context); queryData->namespaceName = context.namespaceName; query = HandleListCollectionsProjector(query, &context, nameOnly, distributedMetadata); /* apply match */ if (filter.value_type != BSON_TYPE_EOD) { query = HandleMatch(&filter, query, &context); context.stageNum++; } return query; } /* * Generates a query that is akin to the MongoDB $listIndexes query command */ Query * GenerateListIndexesQuery(text *databaseDatum, pgbson *listIndexesSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = databaseDatum; bson_iter_t listIndexesIter; PgbsonInitIterator(listIndexesSpec, &listIndexesIter); StringView collectionName = { 0 }; while (bson_iter_next(&listIndexesIter)) { StringView keyView = bson_iter_key_string_view(&listIndexesIter); if (StringViewEqualsCString(&keyView, "listIndexes") || StringViewEqualsCString(&keyView, "listindexes")) { EnsureTopLevelFieldType("listIndexes", &listIndexesIter, BSON_TYPE_UTF8); collectionName.string = bson_iter_utf8(&listIndexesIter, &collectionName.length); } else if (StringViewEqualsCString(&keyView, "cursor")) { ParseCursorDocument(&listIndexesIter, queryData); } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { const bson_value_t *value = bson_iter_value(&listIndexesIter); EnsureTopLevelFieldIsNumberLike("listIndexes.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (StringViewEqualsCString(&keyView, "$db")) { if (context.databaseNameDatum == NULL) { /* Extract the database out of $db */ EnsureTopLevelFieldType("$db", &listIndexesIter, BSON_TYPE_UTF8); uint32_t databaseLength = 0; const char *databaseName = bson_iter_utf8(&listIndexesIter, &databaseLength); context.databaseNameDatum = cstring_to_text_with_len(databaseName, databaseLength); databaseDatum = context.databaseNameDatum; } } else if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field listIndexes.%.*s is not recognized as a valid field", keyView.length, keyView.string), errdetail_log( "The BSON field listIndexes.%.*s is not recognized as a valid field", keyView.length, keyView.string))); } } if (context.databaseNameDatum == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required field database must be valid"))); } Query *query = GenerateBaseListIndexesQuery(databaseDatum, &collectionName, &context); queryData->namespaceName = context.namespaceName; return query; } /* * Mutates the query to process the CurrentOp aggregation stage * Stage parameters: * { allUsers: , idleConnections: , idleCursors: , idleSessions: , localOps: } * This stage will form the query * SELECT document FROM ApiSchema.current_op_aggregation({ currentOpSpec }); * Requires this to be the first stage, so the prior query is discarded. */ Query * HandleCurrentOp(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_CURRENTOP); EnsureTopLevelFieldValueType("pipeline.$currentOp", existingValue, BSON_TYPE_DOCUMENT); if (context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40602), errmsg( "The $currentOp can only be used as the initial stage in the pipeline."))); } const char *databaseStr = text_to_cstring(context->databaseNameDatum); if (strcmp(databaseStr, "admin") != 0 || query->jointree->fromlist != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg( "$currentOp must be executed on the 'admin' database with parameter {aggregate: 1}"))); } /* Any further validation done during processing of the currentOp aggregation */ Assert(query->jointree->fromlist == NULL); Assert(query->rtable == NIL); /* Now create a function RTE */ RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_FUNCTION; rte->relid = InvalidOid; List *colNames = list_make1(makeString("document")); rte->alias = rte->eref = makeAlias("currentOp", colNames); rte->lateral = false; rte->inFromCl = true; rte->functions = NIL; rte->inh = false; #if PG_VERSION_NUM >= 160000 rte->perminfoindex = 0; #else rte->requiredPerms = ACL_SELECT; #endif rte->rellockmode = AccessShareLock; /* Now create the rtfunc*/ List *args = list_make1(MakeBsonConst(PgbsonInitFromDocumentBsonValue( existingValue))); FuncExpr *rangeFunc = makeFuncExpr(BsonCurrentOpAggregationFunctionId(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); rangeFunc->funcretset = true; RangeTblFunction *rangeTableFunction = makeNode(RangeTblFunction); rangeTableFunction->funccolcount = 1; rangeTableFunction->funccolnames = colNames; rangeTableFunction->funccoltypes = list_make1_oid(BsonTypeId()); rangeTableFunction->funccoltypmods = list_make1_oid(-1); rangeTableFunction->funccolcollations = list_make1_oid(InvalidOid); rangeTableFunction->funcparams = NULL; rangeTableFunction->funcexpr = (Node *) rangeFunc; /* Add the RTFunc to the RTE */ rte->functions = list_make1(rangeTableFunction); query->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), NULL); /* Create the projector. We only project the 'document' column in this type of query */ Var *documentEntry = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); return query; } /* * Generates the base query that queries the ApiCatalogSchemaName.collection_indexes * for a listIndexes scenario. */ static Query * GenerateBaseListIndexesQuery(text *databaseDatum, const StringView *collectionName, AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->namespaceName = CreateNamespaceName(databaseDatum, collectionName); context->collectionNameView = *collectionName; MongoCollection *collection = GetMongoCollectionByNameDatum(PointerGetDatum( databaseDatum), CStringGetTextDatum( collectionName->string), NoLock); if (collection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_NAMESPACENOTFOUND), errmsg("Namespace does not currently exist: %s", context->namespaceName))); } /* Add ApiInternalSchemaName.index_spec_as_bson(index_spec, TRUE) projector */ /* create Var that references the index_spec column in ApiCatalogSchemaName.collection_indexes */ Index varno = 1; Index varlevelsup = 0; Var *indexSpecVar = makeVar(varno, 3, IndexSpecTypeId(), -1, InvalidOid, varlevelsup); bool boolConstValue = true; List *args = list_make2(indexSpecVar, MakeBoolValueConst(boolConstValue)); FuncExpr *indexSpecAsBsonExpr = makeFuncExpr(IndexSpecAsBsonFunctionId(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) indexSpecAsBsonExpr, 1, "indexes", false); query->targetList = list_make1(baseTargetEntry); RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiCatalogSchemaName.collection_indexes function */ List *colNames = list_concat(list_make3(makeString("collection_id"), makeString("index_id"), makeString("index_spec")), list_make1(makeString("index_is_valid"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("indexspec", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collection_indexes", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif query->rtable = list_make1(rte); /* Register the RTE in the "FROM" clause and add where clause * collection_id = AND (index_is_valud OR ApiInternalSchemaName.index_build_is_in_progress)*/ RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; Var *indexIsValidIdVar = makeVar(varno, 4, BOOLOID, -1, InvalidOid, varlevelsup); Var *indexIdVar = makeVar(varno, 2, INT4OID, -1, InvalidOid, varlevelsup); FuncExpr *indexBuildIsInProgressExpr = makeFuncExpr( IndexBuildIsInProgressFunctionId(), BOOLOID, list_make1(indexIdVar), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); /* index_is_valud OR ApiInternalSchemaName.index_build_is_in_progress */ Expr *orClause = make_orclause(list_make2(indexIsValidIdVar, indexBuildIsInProgressExpr)); Var *collectionIdVar = makeVar(varno, 1, INT8OID, -1, InvalidOid, varlevelsup); /* collection_id = */ Expr *opExpr = make_opclause(BigintEqualOperatorId(), BOOLOID, false, (Expr *) collectionIdVar, (Expr *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum( collection->collectionId), false, true), InvalidOid, InvalidOid); /* collection_id = AND (index_is_valud OR ApiInternalSchemaName.index_build_is_in_progress) */ Expr *andClause = make_andclause(list_make2(opExpr, orClause)); query->jointree = makeFromExpr(list_make1(rtr), (Node *) andClause); /* ORDER BY index_id */ TargetEntry *entry = linitial(query->targetList); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = entry->resno + 1; SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_ASC; sortBy->node = (Node *) indexIdVar; bool resjunk = true; TargetEntry *sortEntry = makeTargetEntry((Expr *) indexIdVar, (AttrNumber) parseState->p_next_resno++, "?sort?", resjunk); query->targetList = lappend(query->targetList, sortEntry); List *sortlist = addTargetToSortList(parseState, sortEntry, NIL, query->targetList, sortBy); pfree(parseState); query->sortClause = sortlist; return query; } /* * Generates the base table that queries the ApiCatalogSchemaName.collections * for a listCollections scenario. */ static Query * GenerateBaseListCollectionsQuery(Datum databaseDatum, bool nameOnly, bool addDistributedMetadata, AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; StringView collectionsView = CreateStringViewFromString("$cmd.ListCollections"); context->namespaceName = CreateNamespaceName(DatumGetTextP(databaseDatum), &collectionsView); context->collectionNameView = collectionsView; RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiCatalogSchemaName.collections function */ List *colNames = list_concat(list_make3(makeString("database_name"), makeString( "collection_name"), makeString( "collection_id")), list_make3(makeString("shard_key"), makeString( "collection_uuid"), makeString( "view_definition"))); rte->rtekind = RTE_RELATION; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; rte->rellockmode = AccessShareLock; RangeVar *rangeVar = makeRangeVar(ApiCatalogSchemaName, "collections", -1); rte->relid = RangeVarGetRelid(rangeVar, AccessShareLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif query->rtable = list_make1(rte); /* Now register the RTE in the "FROM" clause with a single filter on the database_name */ RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; Var *databaseVar = makeVar(1, 1, TEXTOID, -1, InvalidOid, 0); Expr *opExpr = make_opclause(TextEqualOperatorId(), BOOLOID, false, (Expr *) databaseVar, (Expr *) makeConst(TEXTOID, -1, InvalidOid, -1, databaseDatum, false, false), InvalidOid, DEFAULT_COLLATION_OID); /* Remove system collections */ Var *collectionVar = makeVar(1, 2, TEXTOID, -1, InvalidOid, 0); StringView sentinelCollection = CreateStringViewFromString("system.dbSentinel"); Const *systemCollection = MakeTextConst(sentinelCollection.string, sentinelCollection.length); Expr *notExpr = make_opclause(TextNotEqualOperatorId(), BOOLOID, false, (Expr *) collectionVar, (Expr *) systemCollection, InvalidOid, DEFAULT_COLLATION_OID); query->jointree = makeFromExpr(list_make1(rtr), (Node *) make_ands_explicit( list_make2(opExpr, notExpr))); /* Add a row_get_bson to make it a single bson document */ Var *rowExpr = makeVar(1, 0, ApiCatalogCollectionsTypeOid(), -1, InvalidOid, 0); FuncExpr *funcExpr = makeFuncExpr(RowGetBsonFunctionOid(), BsonTypeId(), list_make1(rowExpr), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) funcExpr, 1, "document", false); query->targetList = list_make1(baseTargetEntry); if (addDistributedMetadata) { query = MutateListCollectionsQueryForDistribution(query); } return query; } /* * Modifies the query to handle the $collStats stage. */ Query * HandleCollStats(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_COLLSTATS); EnsureTopLevelFieldValueType("$collStats", existingValue, BSON_TYPE_DOCUMENT); if (context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40602), errmsg( "$collStats can only be used as the initial stage within the processing pipeline."))); } /* Skip validate the collStats document: done in the function */ /* Now create the rtfunc*/ Const *databaseConst = makeConst(TEXTOID, -1, InvalidOid, -1, PointerGetDatum(context->databaseNameDatum), false, false); Const *collectionConst = MakeTextConst(context->collectionNameView.string, context->collectionNameView.length); pgbson *bson = PgbsonInitFromDocumentBsonValue(existingValue); List *collStatsArgs = list_make3(databaseConst, collectionConst, MakeBsonConst(bson)); /* Remove the collection (it's not on the base table) */ context->mongoCollection = NULL; bool isMultiRow = false; return BuildSingleFunctionQuery(ApiCollStatsAggregationFunctionOid(), collStatsArgs, isMultiRow); } /* * Modifies the query to handle the $indexStats stage. */ Query * HandleIndexStats(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_INDEXSTATS); EnsureTopLevelFieldValueType("$indexStats", existingValue, BSON_TYPE_DOCUMENT); if (!IsBsonValueEmptyDocument(existingValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28803), errmsg( "The $indexStats stage specification is required to be provided as an empty object."))); } if (context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40602), errmsg( "The $indexStats operator can only be used as the initial stage in the pipeline."))); } bool isTopLevel = true; if (IsInTransactionBlock(isTopLevel)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), errmsg( "$indexStats is not permitted for use within a transaction"))); } Const *databaseConst = makeConst(TEXTOID, -1, InvalidOid, -1, PointerGetDatum(context->databaseNameDatum), false, false); Const *collectionConst = MakeTextConst(context->collectionNameView.string, context->collectionNameView.length); List *indexStatsArgs = list_make2(databaseConst, collectionConst); /* Remove the collection (it's not on the base table) */ context->mongoCollection = NULL; bool isMultiRow = true; return BuildSingleFunctionQuery(ApiIndexStatsAggregationFunctionOid(), indexStatsArgs, isMultiRow); } /* * Builds a single query that is the equivalent of * SELECT document FROM queryFunction(args); */ static Query * BuildSingleFunctionQuery(Oid queryFunctionOid, List *queryArgs, bool isMultiRow) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; List *colNames = list_make1(makeString("document")); RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_FUNCTION; rte->relid = InvalidOid; rte->alias = rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->functions = NIL; rte->inh = false; #if PG_VERSION_NUM >= 160000 rte->perminfoindex = 0; #else rte->requiredPerms = ACL_SELECT; #endif rte->rellockmode = AccessShareLock; /* Now create the rtfunc*/ FuncExpr *rangeFunc = makeFuncExpr(queryFunctionOid, BsonTypeId(), queryArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (isMultiRow) { rangeFunc->funcretset = true; } RangeTblFunction *rangeTableFunction = makeNode(RangeTblFunction); rangeTableFunction->funccolcount = 1; rangeTableFunction->funccolnames = NIL; rangeTableFunction->funccoltypes = list_make1_oid(BsonTypeId()); rangeTableFunction->funccoltypmods = list_make1_int(-1); rangeTableFunction->funccolcollations = list_make1_oid(InvalidOid); rangeTableFunction->funcparams = NULL; rangeTableFunction->funcexpr = (Node *) rangeFunc; /* Add the RTFunc to the RTE */ rte->functions = list_make1(rangeTableFunction); query->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), NULL); Var *documentEntry = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); return query; } /* build project to get schema validation information * {"validator": "$validator", "validationLevel":"$validation_level", "validationAction":"$validation_action"} */ static bson_value_t WriteConditionForSchemaValidation() { pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendUtf8(&writer, "validator", 9, "$validator"); PgbsonWriterAppendUtf8(&writer, "validationLevel", 15, "$validation_level"); PgbsonWriterAppendUtf8(&writer, "validationAction", 16, "$validation_action"); return ConvertPgbsonToBsonValue(PgbsonWriterGetPgbson(&writer)); } /* writes the condition * path: { "$cond": [ { "$toBool": "$view_definition" }, value1, value2 ]} * if view_definition is null and ignoreSchemaValidation is false, value2 should be an array as ["$validator", "$validation_level", "$validation_action"] to get schema validation information */ static void WriteConditionWithIfViewsNull(pgbson_writer *writer, const char *path, uint32_t pathLength, const bson_value_t *trueValue, const bson_value_t *falseValue) { pgbson_writer childWriter; pgbson_array_writer arrayWriter; PgbsonWriterStartDocument(writer, path, pathLength, &childWriter); PgbsonWriterStartArray(&childWriter, "$cond", 5, &arrayWriter); pgbson_writer toBoolWriter; PgbsonArrayWriterStartDocument(&arrayWriter, &toBoolWriter); PgbsonWriterAppendUtf8(&toBoolWriter, "$toBool", 7, "$view_definition"); PgbsonArrayWriterEndDocument(&arrayWriter, &toBoolWriter); PgbsonArrayWriterWriteValue(&arrayWriter, trueValue); PgbsonArrayWriterWriteValue(&arrayWriter, falseValue); PgbsonWriterEndArray(&childWriter, &arrayWriter); PgbsonWriterEndDocument(writer, &childWriter); } /* * Modifies the ListCollections base table to match the mongo syntax. */ static Query * HandleListCollectionsProjector(Query *query, AggregationPipelineBuildContext *context, bool nameOnly, bool addDistributedMetadata) { pgbson_writer writer; PgbsonWriterInit(&writer); /* "name": "collection_name "*/ PgbsonWriterAppendUtf8(&writer, "name", 4, "$collection_name"); /* "type": { "$cond": [ { "$toBool": "$view_definition" }, "view", "collection" ]} */ { bson_value_t collectionValue = { 0 }; collectionValue.value_type = BSON_TYPE_UTF8; collectionValue.value.v_utf8.str = "collection"; collectionValue.value.v_utf8.len = 10; bson_value_t viewValue = { 0 }; viewValue.value_type = BSON_TYPE_UTF8; viewValue.value.v_utf8.str = "view"; viewValue.value.v_utf8.len = 4; WriteConditionWithIfViewsNull(&writer, "type", 4, &viewValue, &collectionValue); } if (!nameOnly) { /* "options": { "$cond": [ { "$toBool": "$view_definition" }, "$view_definition", {"validator": "$validator", "validationLevel":"$validation_level", "validationAction":"$validation_action"} ] } */ bson_value_t collectionValue = WriteConditionForSchemaValidation(); bson_value_t viewValue = { 0 }; viewValue.value_type = BSON_TYPE_UTF8; viewValue.value.v_utf8.str = "$view_definition"; viewValue.value.v_utf8.len = 16; WriteConditionWithIfViewsNull(&writer, "options", 7, &viewValue, &collectionValue); /* "info": { "readOnly": { "$ifNull": [ { "$toBool": "$view_definition"}, false] }, "uuid": "$collection_uuid", "shardKey": "$shard_key" } } */ pgbson_writer infoWriter; PgbsonWriterStartDocument(&writer, "info", 4, &infoWriter); pgbson_writer readOnlyWriter; PgbsonWriterStartDocument(&infoWriter, "readOnly", 8, &readOnlyWriter); pgbson_array_writer ifNullWriter; PgbsonWriterStartArray(&readOnlyWriter, "$ifNull", 7, &ifNullWriter); pgbson_writer toBoolWriter; PgbsonArrayWriterStartDocument(&ifNullWriter, &toBoolWriter); PgbsonWriterAppendUtf8(&toBoolWriter, "$toBool", 7, "$view_definition"); PgbsonArrayWriterEndDocument(&ifNullWriter, &toBoolWriter); bson_value_t falseValue = { 0 }; falseValue.value_type = BSON_TYPE_BOOL; falseValue.value.v_bool = false; PgbsonArrayWriterWriteValue(&ifNullWriter, &falseValue); PgbsonWriterEndArray(&readOnlyWriter, &ifNullWriter); PgbsonWriterEndDocument(&infoWriter, &readOnlyWriter); PgbsonWriterAppendUtf8(&infoWriter, "uuid", 4, "$collection_uuid"); PgbsonWriterAppendUtf8(&infoWriter, "shardKey", 8, "$shard_key"); PgbsonWriterEndDocument(&writer, &infoWriter); /* "idIndex": { "$cond": [ { "$toBool": "$view_definition" }, null, { "v": 2, "key": { "_id": 1 }, "name": "_id_" } ] } */ pgbson_writer idIndexWriter; pgbson_writer keyWriter; PgbsonWriterInit(&idIndexWriter); PgbsonWriterAppendInt32(&idIndexWriter, "v", 1, 2); PgbsonWriterAppendUtf8(&idIndexWriter, "name", 4, "_id_"); PgbsonWriterStartDocument(&idIndexWriter, "key", 3, &keyWriter); PgbsonWriterAppendInt32(&keyWriter, "_id", 3, 1); PgbsonWriterEndDocument(&idIndexWriter, &keyWriter); collectionValue = ConvertPgbsonToBsonValue(PgbsonWriterGetPgbson( &idIndexWriter)); viewValue = (bson_value_t) { 0 }; viewValue.value_type = BSON_TYPE_NULL; WriteConditionWithIfViewsNull(&writer, "idIndex", 7, &viewValue, &collectionValue); } if (addDistributedMetadata) { PgbsonWriterAppendInt32(&writer, "shardCount", 10, 1); PgbsonWriterAppendInt32(&writer, "colocationId", 12, 1); } pgbson *bson = PgbsonWriterGetPgbson(&writer); bson_value_t bsonValue = ConvertPgbsonToBsonValue(bson); /* no use for *WithLet or *WithLetAndCollation projection functions here, so we set them to NULL */ Oid (*projectWithLetFuncOid) (void) = NULL; Oid (*projectWithLetAndCollationFuncOid) (void) = NULL; return HandleSimpleProjectionStage(&bsonValue, query, context, "$project", BsonDollarProjectFunctionOid(), projectWithLetFuncOid, projectWithLetAndCollationFuncOid); } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_nested_pipeline.c000066400000000000000000004224021507310017400306000ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/planner/bson_aggregation_nested_pipeline.c * * Implementation of the backend query generation for pipelines that have * nested pipelines (such as $lookup, $facet, $inverseMatch). * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "query/query_operator.h" #include "planner/documentdb_planner.h" #include "aggregation/bson_aggregation_pipeline.h" #include "commands/parse_error.h" #include "commands/commands_common.h" #include "utils/feature_counter.h" #include "utils/version_utils.h" #include "operators/bson_expression.h" #include "aggregation/bson_aggregation_pipeline_private.h" /* We use this flag to determine if an specialized VAR in $lookup whether let or document VAR needs varlevelsup adjustment * The last 2 bytes are reserved to store the nested pipeline level, since the * maximum nested pipeline level is 20, we can use 2 bytes to store it. */ #define NESTED_PIPELINE_VAR_FLAG 0x0F000000 const int MaximumLookupPipelineDepth = 20; extern bool EnableLookupIdJoinOptimizationOnCollation; extern bool EnableNowSystemVariable; extern bool EnableLookupInnerJoin; /* * Struct having parsed view of the * arguments to Lookup. */ typedef struct { /* * The name of the collection to lookup */ StringView from; /* * The alias where the results of the lookup are placed */ StringView lookupAs; /* * The remote field to match (if applicable) */ StringView foreignField; /* * The local field to match (if applicable) */ StringView localField; /* * A pipeline to execute (for uncorrelated lookups) */ bson_value_t pipeline; /* * let variables for $lookup */ pgbson *let; /* * has a join (foreign/local field). */ bool hasLookupMatch; } LookupArgs; typedef struct { bool isLookupUnwind; /* * Only applicable for Lookup Unwind combination. */ bool preserveNullAndEmptyArrays; } LookupContext; typedef struct LookupOptimizationArgs { /* * Is the query agnostic */ bool isLookupAgnostic; /* * Whether or not the $lookup is uncorrelated. */ bool isLookupUncorrelated; /* * The segment of the pipeline stages that can be inlined. */ List *inlinedPipelineStages; /* * The segment of the pipeline stages that cannot be inlined and needs * to be applied post-join. */ List *nonInlinedPipelineStages; /* * Can the join be done on the right query's _id? */ bool isLookupJoinOnRightId; /* * Can the join be done on the left query's _id? */ bool isLookupJoinOnLeftId; /* * Right query's subqueryContext */ AggregationPipelineBuildContext rightQueryContext; /* * The base query on the rightquery. */ Query *rightBaseQuery; /* * Whether or not the query has Let. * This is true if the lookupArgs has let *or* the parent context * has a let that is non const. */ bool hasLet; /* * Referrence to the first non-inlined $match stage with $expr qualifiers which * was not inlined due to the presence of a `let`. * We do a best effort inlining of this stage close to the right query to avoid * the stage post-JOIN */ AggregationStage *nonInlinedMatchStage; /* * The attrNum for the lookup let in left query */ AttrNumber lookupLetAttrNum; } LookupOptimizationArgs; /* * The walker state to replace the Let variable in queries. */ typedef struct LevelsUpQueryTreeWalkerState { /* numLevels up - modified during modify state*/ int numLevels; /* the let variable in the query */ Var *originalVariable; /* Used by the RTE CTE LevelsUp Walker */ const char *cteName; } LevelsUpQueryTreeWalkerState; /* * Args processed from the $graphLookup stage. */ typedef struct { /* the input expression must start with the specified input */ bson_value_t inputExpression; /* The target collection */ StringView fromCollection; /* the connectFrom field */ StringView connectFromField; /* the connectTo field */ StringView connectToField; /* the field it should be written to */ StringView asField; /* How many times to recurse */ int32_t maxDepth; /* optional depth Field to write it into */ StringView depthField; /* A match clause to restrict search */ bson_value_t restrictSearch; /* connectFrom field as an expression */ bson_value_t connectFromFieldExpression; } GraphLookupArgs; /* * Args processed from the $inverseMatch stage. */ typedef struct InverseMatchArgs { /* The specified path. */ StringView path; /* The from collection to run the aggregation pipeline provided in the args. */ StringView fromCollection; /* The specified input. */ bson_value_t input; /* The aggregation pipeline specified to run on the fromCollection. */ bson_value_t pipeline; /* The default result to use if a query in a document is not found. */ bson_value_t defaultResult; } InverseMatchArgs; static int ValidateFacet(const bson_value_t *facetValue); static Query * BuildFacetUnionAllQuery(int numStages, const bson_value_t *facetValue, CommonTableExpr *baseCte, QuerySource querySource, const bson_value_t *sortSpec, AggregationPipelineBuildContext *parentContext); static Query * AddBsonArrayAggFunction(Query *baseQuery, AggregationPipelineBuildContext *context, ParseState *parseState, const char *fieldPath, uint32_t fieldPathLength, bool migrateToSubQuery, Aggref **aggrefPtr); static Query * AddBsonObjectAggFunction(Query *baseQuery, AggregationPipelineBuildContext *context); static void ParseLookupStage(const bson_value_t *existingValue, LookupArgs *args); static void ParseGraphLookupStage(const bson_value_t *existingValue, GraphLookupArgs *args); static Query * CreateInverseMatchFromCollectionQuery(InverseMatchArgs *inverseMatchArgs, AggregationPipelineBuildContext * context, ParseState *parseState); static bool ParseInverseMatchSpec(const bson_value_t *spec, InverseMatchArgs *args); static Query * CreateCteSelectQuery(CommonTableExpr *baseCte, const char *prefix, int stageNum, int levelsUp); static Query * ProcessLookupCoreWithLet(Query *query, AggregationPipelineBuildContext *context, LookupArgs *lookupArgs, LookupContext *lookupContext); static void ValidatePipelineForShardedLookupWithLet(const bson_value_t *pipeline); static Query * ProcessGraphLookupCore(Query *query, AggregationPipelineBuildContext *context, GraphLookupArgs *lookupArgs); static Query * BuildGraphLookupCteQuery(QuerySource parentSource, CommonTableExpr *baseCteExpr, GraphLookupArgs *args, AggregationPipelineBuildContext *parentContext); static Query * BuildRecursiveGraphLookupQuery(QuerySource parentSource, GraphLookupArgs *args, AggregationPipelineBuildContext * parentContext, CommonTableExpr *baseCteExpr, int levelsUp); static void ValidateUnionWithPipeline(const bson_value_t *pipeline, bool hasCollection); static void ValidateLetHasNoVariables(AggregationExpressionData *parsedData); static void WalkQueryAndSetLevelsUp(Query *query, Var *varToCheck, int varLevelsUpBase); static void WalkQueryAndSetCteLevelsUp(Query *query, const char *cteName, int varLevelsUpBase); static Query * HandleLookupCore(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, LookupContext *lookupContext); static Query * AddLookupRightQueryExpressionOrArrayAgg(Query *rightQuery, AggregationPipelineBuildContext * context, ParseState *parseState, LookupArgs *lookupArgs, LookupContext *lookupContext, bool requiresSubQuery); /* * Validates and returns a given pipeline stage: Used in validations for facet/lookup/unionWith */ inline static pgbsonelement GetPipelineStage(bson_iter_t *pipelineIter, const char *parentStage, const char *pipelineKey) { const bson_value_t *pipelineStage = bson_iter_value(pipelineIter); if (!BSON_ITER_HOLDS_DOCUMENT(pipelineIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Pipeline stage for %s %s must be a document", parentStage, pipelineKey))); } pgbsonelement stageElement; if (!TryGetBsonValueToPgbsonElement(pipelineStage, &stageElement)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40323), errmsg( "Pipeline stage must have a single field."))); } return stageElement; } /* * Processes the $_internalInhibitOptimization Pipeine stage. * Injects a CTE into the pipeline with the MaterializeAlways flag * generating a break in the pipeline. */ Query * HandleInternalInhibitOptimization(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_INTERNAL_INHIBIT_OPTIMIZATION); /* First step, move the current query into a CTE */ CommonTableExpr *baseCte = makeNode(CommonTableExpr); baseCte->ctename = "internalinhibitoptimization"; baseCte->ctequery = (Node *) query; /* Mark it as materialize always */ baseCte->ctematerialized = CTEMaterializeAlways; int levelsUp = 0; query = CreateCteSelectQuery(baseCte, "inhibit", context->stageNum, levelsUp); query->cteList = list_make1(baseCte); return query; } /* * Processes the $facet Pipeine stage. * Injects a CTE for the current query. * Then builds a UNION ALL query that has the N pipelines * selecting from the common CTE. * Finally aggregates all of it into a BSON_OBJECT_AGG */ Query * HandleFacet(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_FACET); if (list_length(query->targetList) > 1) { /* if we have multiple projectors, push to a subquery (Facet needs 1 projector) */ /* TODO: Can we get rid of this Subquery? */ query = MigrateQueryToSubQuery(query, context); } int numStages = ValidateFacet(existingValue); /* First step, move the current query into a CTE */ CommonTableExpr *baseCte = makeNode(CommonTableExpr); /* Adding the stage number to the CTE alias (which is done in CreateCteSelectQuery()) is not enough to avoid conflict * when there are multiple top level facets due to the facet stage is planned (see facet explains)*/ baseCte->ctename = psprintf("facet_base_%d_%d", context->stageNum, context->nestedPipelineLevel); baseCte->ctequery = (Node *) query; /* Second step: Build UNION ALL query */ Query *finalQuery = BuildFacetUnionAllQuery(numStages, existingValue, baseCte, query->querySource, &context->sortSpec, context); /* Finally, add bson_object_agg */ finalQuery = AddBsonObjectAggFunction(finalQuery, context); finalQuery->cteList = list_make1(baseCte); WalkQueryAndSetCteLevelsUp(finalQuery, baseCte->ctename, 0); context->requiresSubQuery = true; return finalQuery; } /* * Top level method handling processing of the lookup stage. */ Query * HandleLookup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_LOOKUP); LookupContext lookupContext = { 0 }; return HandleLookupCore(existingValue, query, context, &lookupContext); } /* * Top level method handling processing of the lookup and unwind stage combination. */ Query * HandleLookupUnwind(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_LOOKUP); ReportFeatureUsage(FEATURE_STAGE_UNWIND); /* The spec for lookup unwind has 2 fields, `lookup` spec and `preserveNullAndEmptyArrays` from inlined unwind */ bson_value_t lookupSpec; bool preserveNullAndEmptyArrays = false; bson_iter_t iter; BsonValueInitIterator(existingValue, &iter); while (bson_iter_next(&iter)) { const char *key = bson_iter_key(&iter); if (strcmp(key, "lookup") == 0) { lookupSpec = *bson_iter_value(&iter); } else if (strcmp(key, "preserveNullAndEmptyArrays") == 0) { preserveNullAndEmptyArrays = bson_iter_as_bool(&iter); } } LookupContext lookupContext = { .isLookupUnwind = true, .preserveNullAndEmptyArrays = preserveNullAndEmptyArrays }; return HandleLookupCore(&lookupSpec, query, context, &lookupContext); } /* * CanInlineLookupWithUnwind checks if the lookup stage can be inlined with the unwind stage. * Iff the lookup stage is a simple lookup with no pipeline and the aggregated field of lookup is same * as unwinding path, then we can inline the lookup stage with the unwind stage. */ bool CanInlineLookupWithUnwind(const bson_value_t *lookUpStageValue, const bson_value_t *unwindStageValue, bool *isPreserveEmptyAndNullArrays) { LookupArgs lookupArgs; memset(&lookupArgs, 0, sizeof(LookupArgs)); ParseLookupStage(lookUpStageValue, &lookupArgs); if (lookupArgs.lookupAs.length == 0) { return false; } if (lookupArgs.pipeline.value_type != BSON_TYPE_EOD) { /* * We can't inline the lookup stage with unwind stage if the lookup stage has a pipeline. * because today we run the pipeline against all the documents that are matched post JOIN * which requires us to aggregate the matched docs anywat, so inlining for this case is tricky plus * calls for a lookup rewrite so better drop the inlining */ return false; } StringView unwindPath = { 0 }; /* If the unwind has options don't inline */ if (unwindStageValue->value_type == BSON_TYPE_DOCUMENT || unwindStageValue->value_type == BSON_TYPE_UTF8) { if (unwindStageValue->value_type == BSON_TYPE_DOCUMENT) { bson_iter_t iter; BsonValueInitIterator(unwindStageValue, &iter); while (bson_iter_next(&iter)) { const char *key = bson_iter_key(&iter); if (strcmp(key, "includeArrayIndex") == 0) { /* We can't inline the documents need to be rewritten with the array index */ return false; } else if (strcmp("preserveNullAndEmptyArrays", key) == 0) { if (BSON_ITER_HOLDS_BOOL(&iter)) { *isPreserveEmptyAndNullArrays = bson_iter_as_bool(&iter); } else { /* Don't inline so that invalid specs are caught and error is thrown */ return false; } } else if (strcmp(key, "path") == 0 && BSON_ITER_HOLDS_UTF8(&iter)) { unwindPath.string = bson_iter_utf8(&iter, &unwindPath.length); } } } else { unwindPath.string = unwindStageValue->value.v_utf8.str; unwindPath.length = unwindStageValue->value.v_utf8.len; *isPreserveEmptyAndNullArrays = false; } } else { /* Any other unwind value is invalid */ return false; } if (unwindPath.length > 1 && StringViewStartsWith(&unwindPath, '$') && strcmp(unwindPath.string + 1, lookupArgs.lookupAs.string) == 0) { return true; } return false; } /* * Top level method handling processing of the $graphLookup Stage. */ Query * HandleGraphLookup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_GRAPH_LOOKUP); GraphLookupArgs graphArgs; memset(&graphArgs, 0, sizeof(GraphLookupArgs)); ParseGraphLookupStage(existingValue, &graphArgs); return ProcessGraphLookupCore(query, context, &graphArgs); } /* * Top level method handling processing of the $documents stage. */ Query * HandleDocumentsStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_DOCUMENTS); if (list_length(query->rtable) != 0 || context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$documents can only be used as the first stage in a pipeline."))); } /* Documents is an expression */ StringView documentsPath = { .string = "$documents", .length = 10 }; pgbson_writer writer; PgbsonWriterInit(&writer); ParseAggregationExpressionContext parseContext = { 0 }; parseContext.collationString = context->collationString; AggregationExpressionData expressionData; memset(&expressionData, 0, sizeof(AggregationExpressionData)); ParseAggregationExpressionData(&expressionData, existingValue, &parseContext); ExpressionVariableContext *variableContext = NULL; bool isNullOnEmpty = false; EvaluateAggregationExpressionDataToWriter(&expressionData, PgbsonInitEmpty(), documentsPath, &writer, variableContext, isNullOnEmpty); /* Validate documents */ pgbson *targetBson = PgbsonWriterGetPgbson(&writer); pgbsonelement fetchedElement = { 0 }; if (!TryGetSinglePgbsonElementFromPgbson(targetBson, &fetchedElement) || fetchedElement.bsonValue.value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5858203), errmsg( "An array was expected."))); } /* Create a distinct unwind - to expand arrays and such */ Const *unwindValue = MakeTextConst(documentsPath.string, documentsPath.length); List *args = list_make2(MakeBsonConst(targetBson), unwindValue); FuncExpr *resultExpr = makeFuncExpr( BsonLookupUnwindFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); resultExpr->funcretset = true; RangeTblFunction *tblFunction = makeNode(RangeTblFunction); tblFunction->funcexpr = (Node *) resultExpr; tblFunction->funccolcount = 1; tblFunction->funccoltypes = list_make1_oid(BsonTypeId()); tblFunction->funccolcollations = list_make1_oid(InvalidOid); tblFunction->funccoltypmods = list_make1_int(-1); RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_FUNCTION; rte->self_reference = false; rte->lateral = false; rte->inh = false; rte->inFromCl = true; rte->functions = list_make1(tblFunction); List *colnames = list_make1(makeString("documents")); rte->alias = makeAlias("documents", NIL); rte->eref = makeAlias("documents", colnames); Var *queryOutput = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); bool resJunk = false; TargetEntry *upperEntry = makeTargetEntry((Expr *) queryOutput, 1, "documents_aggregate", resJunk); query->targetList = list_make1(upperEntry); query->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), NULL); context->requiresSubQuery = true; return query; } /* Handles the $inverseMatch stage. * It generates a query like: * SELECT document FROM collection WHERE * bson_dollar_inverse_match(document, '{"path": , "input": }') */ Query * HandleInverseMatch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_INVERSEMATCH); if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$inverseMatch requires a document as an input instead got: %s", BsonTypeName( existingValue->value_type)), errdetail_log( "$inverseMatch requires a document as an input instead got: %s", BsonTypeName( existingValue->value_type)))); } if (query->limitOffset != NULL || query->limitCount != NULL || query->sortClause != NULL) { query = MigrateQueryToSubQuery(query, context); } InverseMatchArgs arguments; memset(&arguments, 0, sizeof(InverseMatchArgs)); bool useFromCollection = ParseInverseMatchSpec(existingValue, &arguments); /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; /* build WHERE ApiSchemaName.bson_dollar_inverse_match clause */ Expr *specArgument = NULL; ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = list_length(query->targetList) + 1; if (!useFromCollection) { pgbson *specBson = PgbsonInitFromBuffer( (char *) existingValue->value.v_doc.data, existingValue->value.v_doc.data_len); specArgument = (Expr *) MakeBsonConst(specBson); } else { /* if from collection is specified we generate a query like: * SELECT document * FROM ApiDataSchemaName.documents_963002 collection * WHERE ApiInternalSchemaName.bson_dollar_inverse_match( * document, * ( * SELECT ApiCatalogSchema.bson_dollar_add_fields( * '{ "path" : "rule", "defaultResult" : false }'::ApiCatalogSchema.bson, * ( * SELECT COALESCE( * ApiCatalogSchema.bson_array_agg(collection_0_1.document, 'input'::text), * '{ "input" : [ ] }'::CoreSchema.bson * ) AS document * FROM ApiDataSchemaName.documents_963001_9630019 collection_0_1 * WHERE ApiCatalogSchema.bson_dollar_ne( * collection_0_1.document, * '{ "user_id" : { "$numberInt" : "200" } }'::CoreSchema.bson * ) * AND collection_0_1.shard_key_value OPERATOR(pg_catalog.=) '963001'::bigint * LIMIT '1'::bigint * ) * ) AS spec * ) * ) * AND shard_key_value OPERATOR(pg_catalog.=) '963002'::bigint; */ if (StringViewEquals(&context->collectionNameView, &arguments.fromCollection)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'from' collection should be a different collection than the base collection the inverseMatch is running against."))); } /* Generate add_fields subquery to pass down as an argument. */ Query *addFieldsQuery = CreateInverseMatchFromCollectionQuery(&arguments, context, parseState); SubLink *addFieldsSubLink = makeNode(SubLink); addFieldsSubLink->subLinkType = EXPR_SUBLINK; addFieldsSubLink->subLinkId = 1; /* addFieldsQuery has a sublink already. */ addFieldsSubLink->subselect = (Node *) addFieldsQuery; query->hasSubLinks = true; specArgument = (Expr *) addFieldsSubLink; } FuncExpr *inverseMatchFuncExpr = makeFuncExpr( BsonDollarInverseMatchFunctionId(), BOOLOID, list_make2(currentProjection, specArgument), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); List *quals = list_make1(inverseMatchFuncExpr); if (query->jointree->quals != NULL) { quals = lappend(quals, query->jointree->quals); } free_parsestate(parseState); query->jointree->quals = (Node *) make_ands_explicit(quals); return query; } /* Helper method to generate the sub query used as an argument to the bson_inverse_match UDF. * When from collection is specified we need to generate the spec we pass down to inverse match, * using the result of the pipeline executed on the from collection. For that we need to generate * a subquery used as the parameter to inverse match, i.e: * (SELECT bson_dollar_add_fields(spec, (SELECT COALESCE(bson_array_agg(document, "input"), '{"input": []}')) as spec FROM collection)) * * The query passed to bson_dollar_add_fields will vary depending on the pipeline specified. */ static Query * CreateInverseMatchFromCollectionQuery(InverseMatchArgs *inverseMatchArgs, AggregationPipelineBuildContext *context, ParseState *parseState) { pg_uuid_t *collectionUuid = NULL; AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = context->nestedPipelineLevel + 1; subPipelineContext.databaseNameDatum = context->databaseNameDatum; subPipelineContext.variableSpec = context->variableSpec; subPipelineContext.parentStageName = ParentStageName_INVERSEMATCH; strncpy((char *) subPipelineContext.collationString, context->collationString, MAX_ICU_COLLATION_LENGTH); bson_value_t *indexHint = NULL; Query *nestedPipeline = GenerateBaseTableQuery(context->databaseNameDatum, &inverseMatchArgs->fromCollection, collectionUuid, indexHint, &subPipelineContext); if (subPipelineContext.mongoCollection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_NAMESPACENOTFOUND), errmsg( "The 'from' collection '%s.%s' could not be found.", text_to_cstring(context->databaseNameDatum), inverseMatchArgs->fromCollection.string))); } List *stages = ExtractAggregationStages(&inverseMatchArgs->pipeline, &subPipelineContext); nestedPipeline = MutateQueryWithPipeline(nestedPipeline, stages, &subPipelineContext); bool requiresSubQuery = false; Aggref **aggrefPtr = NULL; nestedPipeline = AddBsonArrayAggFunction(nestedPipeline, &subPipelineContext, parseState, "input", 5, requiresSubQuery, aggrefPtr); /* once we have the bson with the input, we should append this to the spec with bson_add_fields. */ Query *addFieldsQuery = makeNode(Query); addFieldsQuery->commandType = CMD_SELECT; addFieldsQuery->querySource = QSRC_ORIGINAL; addFieldsQuery->canSetTag = true; addFieldsQuery->hasSubLinks = true; SubLink *subLink = makeNode(SubLink); subLink->subLinkType = EXPR_SUBLINK; subLink->subLinkId = 0; subLink->subselect = (Node *) nestedPipeline; /* Write new spec with the path and defaultResult arguments. */ pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendUtf8(&writer, "path", -1, inverseMatchArgs->path.string); PgbsonWriterAppendValue(&writer, "defaultResult", -1, &inverseMatchArgs->defaultResult); pgbson *specBson = PgbsonWriterGetPgbson(&writer); /* Since no dotted path, no need to override array */ bool overrideArray = false; List *addFieldsArgs = list_make3(MakeBsonConst(specBson), subLink, MakeBoolValueConst(overrideArray)); FuncExpr *projectorFunc = makeFuncExpr( BsonDollaMergeDocumentsFunctionOid(), BsonTypeId(), addFieldsArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *specProjector = makeTargetEntry((Expr *) projectorFunc, 1, "spec", false); addFieldsQuery->targetList = list_make1(specProjector); addFieldsQuery->jointree = makeNode(FromExpr); return addFieldsQuery; } /* Parses and validates the inverse match spec. * The only validation it doesn't do is enforcing that input is a document or an array of documents. * We leave that validation to the bson_dollar_inverse_match UDF since a path expression is valid in this context * and we can't validate it at this stage. * Returns true if it is from collection is specified, false other-wise */ static bool ParseInverseMatchSpec(const bson_value_t *spec, InverseMatchArgs *args) { bson_iter_t docIter; BsonValueInitIterator(spec, &docIter); while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "path") == 0) { EnsureTopLevelFieldType("$inverseMatch.path", &docIter, BSON_TYPE_UTF8); const bson_value_t pathValue = *bson_iter_value(&docIter); args->path.length = pathValue.value.v_utf8.len; args->path.string = pathValue.value.v_utf8.str; } else if (strcmp(key, "input") == 0) { args->input = *bson_iter_value(&docIter); } else if (strcmp(key, "defaultResult") == 0) { EnsureTopLevelFieldType("$inverseMatch.defaultResult", &docIter, BSON_TYPE_BOOL); args->defaultResult = *bson_iter_value(&docIter); } else if (strcmp(key, "from") == 0) { EnsureTopLevelFieldType("$inverseMatch.from", &docIter, BSON_TYPE_UTF8); args->fromCollection.string = bson_iter_utf8(&docIter, &args->fromCollection.length); } else if (strcmp(key, "pipeline") == 0) { EnsureTopLevelFieldType("$inverseMatch.pipeline", &docIter, BSON_TYPE_ARRAY); args->pipeline = *bson_iter_value(&docIter); bson_iter_t pipelineArray; BsonValueInitIterator(&args->pipeline, &pipelineArray); /* These are the allowed nested stages in an $inverseMatch */ while (bson_iter_next(&pipelineArray)) { pgbsonelement stageElement = GetPipelineStage(&pipelineArray, "inverseMatch", "pipeline"); const char *nestedPipelineStage = stageElement.path; if (strcmp(nestedPipelineStage, "$match") != 0 && strcmp(nestedPipelineStage, "$project") != 0 && strcmp(nestedPipelineStage, "$limit") != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "%s is not allowed to be used within an $inverseMatch stage, only $match, $project or $limit are allowed", nestedPipelineStage))); } } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Unrecognized parameter supplied to $inverseMatch: '%s'", key))); } } if (args->path.length == 0 || args->path.string == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Path parameter is missing for the operator $inverseMatch"))); } bool useFromCollection = false; if (args->fromCollection.length > 0) { if (args->input.value_type != BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'input' and 'from' can't be used together in an $inverseMatch stage."))); } if (args->pipeline.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'pipeline' argument is required when 'from' is specified in an $inverseMatch stage."))); } useFromCollection = true; } else if (args->input.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Missing 'input' and 'from' parameter to $inverseMatch, one should be provided."))); } if (args->defaultResult.value_type == BSON_TYPE_EOD) { /* If missing, it will automatically default to false. */ args->defaultResult.value_type = BSON_TYPE_BOOL; args->defaultResult.value.v_bool = false; } return useFromCollection; } /* * Helper method to parse the union with arguments */ void ParseUnionWith(const bson_value_t *existingValue, StringView *collectionFrom, bson_value_t *pipeline) { if (existingValue->value_type == BSON_TYPE_UTF8) { /* This is unionWith on the base collection */ collectionFrom->length = existingValue->value.v_utf8.len; collectionFrom->string = existingValue->value.v_utf8.str; } else if (existingValue->value_type == BSON_TYPE_DOCUMENT) { bson_iter_t pipelineIterator; BsonValueInitIterator(existingValue, &pipelineIterator); while (bson_iter_next(&pipelineIterator)) { const char *key = bson_iter_key(&pipelineIterator); const bson_value_t *value = bson_iter_value(&pipelineIterator); if (strcmp(key, "coll") == 0) { EnsureTopLevelFieldType("$unionWith.coll", &pipelineIterator, BSON_TYPE_UTF8); collectionFrom->length = value->value.v_utf8.len; collectionFrom->string = value->value.v_utf8.str; } else if (strcmp(key, "pipeline") == 0) { EnsureTopLevelFieldType("$unionWith.pipeline", &pipelineIterator, BSON_TYPE_ARRAY); *pipeline = *value; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field '$unionWith.%s' is not recognized as a valid field.", key), errdetail_log( "The BSON field '$unionWith.%s' is not recognized as a valid field.", key))); } } if (collectionFrom->length == 0 && pipeline->value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage."))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The $unionWith stage requires its specification to be either an object or a string, but instead encountered %s", BsonTypeName(existingValue->value_type)), errdetail_log( "The $unionWith stage requires its specification to be either an object or a string, but instead encountered %s", BsonTypeName(existingValue->value_type)))); } } /* * Top level method handling processing of the $unionWith stage. */ Query * HandleUnionWith(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_UNIONWITH); if (context->nestedPipelineLevel >= MaximumLookupPipelineDepth) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_MAXSUBPIPELINEDEPTHEXCEEDED), errmsg( "The allowed limit for nested sub-pipelines has been surpassed, exceeding the maximum of %d.", MaximumLookupPipelineDepth))); } Query *leftQuery = query; Query *rightQuery = NULL; StringView collectionFrom = { 0 }; bson_value_t pipelineValue = { 0 }; ParseUnionWith(existingValue, &collectionFrom, &pipelineValue); if (pipelineValue.value_type == BSON_TYPE_EOD) { AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = context->nestedPipelineLevel + 1; subPipelineContext.databaseNameDatum = context->databaseNameDatum; subPipelineContext.variableSpec = context->variableSpec; subPipelineContext.parentStageName = ParentStageName_UNIONWITH; strncpy((char *) subPipelineContext.collationString, context->collationString, MAX_ICU_COLLATION_LENGTH); /* This is unionWith on the base collection */ pg_uuid_t *collectionUuid = NULL; bson_value_t *indexHint = NULL; rightQuery = GenerateBaseTableQuery(context->databaseNameDatum, &collectionFrom, collectionUuid, indexHint, &subPipelineContext); } else { AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = context->nestedPipelineLevel + 1; subPipelineContext.databaseNameDatum = context->databaseNameDatum; subPipelineContext.variableSpec = context->variableSpec; subPipelineContext.parentStageName = ParentStageName_UNIONWITH; strncpy((char *) subPipelineContext.collationString, context->collationString, MAX_ICU_COLLATION_LENGTH); pg_uuid_t *collectionUuid = NULL; if (collectionFrom.length == 0) { rightQuery = GenerateBaseAgnosticQuery(context->databaseNameDatum, &subPipelineContext); } else { bson_value_t *indexHint = NULL; rightQuery = GenerateBaseTableQuery(context->databaseNameDatum, &collectionFrom, collectionUuid, indexHint, &subPipelineContext); } if (pipelineValue.value_type != BSON_TYPE_EOD) { bool hasCollection = collectionFrom.length != 0; ValidateUnionWithPipeline(&pipelineValue, hasCollection); List *stages = ExtractAggregationStages(&pipelineValue, &subPipelineContext); rightQuery = MutateQueryWithPipeline(rightQuery, stages, &subPipelineContext); } } bool includeAllColumns = false; RangeTblEntry *leftRte = MakeSubQueryRte(leftQuery, context->stageNum, 0, "unionLeft", includeAllColumns); RangeTblEntry *rightRte = MakeSubQueryRte(rightQuery, context->stageNum, 0, "unionRight", includeAllColumns); Query *modifiedQuery = makeNode(Query); modifiedQuery->commandType = CMD_SELECT; modifiedQuery->querySource = query->querySource; modifiedQuery->canSetTag = true; modifiedQuery->jointree = makeNode(FromExpr); modifiedQuery->rtable = list_make2(leftRte, rightRte); RangeTblRef *leftReference = makeNode(RangeTblRef); leftReference->rtindex = 1; RangeTblRef *rightReference = makeNode(RangeTblRef); rightReference->rtindex = 2; SetOperationStmt *setOpStatement = MakeBsonSetOpStatement(); setOpStatement->larg = (Node *) leftReference; setOpStatement->rarg = (Node *) rightReference; /* Update the query with the SetOp statement */ modifiedQuery->setOperations = (Node *) setOpStatement; /* Result column node */ TargetEntry *leftMostTargetEntry = linitial(leftQuery->targetList); Var *var = makeVar(1, leftMostTargetEntry->resno, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *restle = makeTargetEntry((Expr *) var, leftMostTargetEntry->resno, leftMostTargetEntry->resname, false); modifiedQuery->targetList = list_make1(restle); modifiedQuery = MigrateQueryToSubQuery(modifiedQuery, context); return modifiedQuery; } /* * Validates the facet pipeline definition. */ static int ValidateFacet(const bson_value_t *facetValue) { if (facetValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15947), errmsg( "Expected 'document' type for $facet but found '%s' type", BsonTypeName(facetValue->value_type)))); } bson_iter_t facetIter; BsonValueInitIterator(facetValue, &facetIter); int numStages = 0; while (bson_iter_next(&facetIter)) { const char *key = bson_iter_key(&facetIter); const bson_value_t *pipeline = bson_iter_value(&facetIter); EnsureTopLevelFieldValueType("$facet.pipeline", pipeline, BSON_TYPE_ARRAY); numStages++; bson_iter_t pipelineArray; BsonValueInitIterator(pipeline, &pipelineArray); /* These stages are not allowed when executing $facet */ while (bson_iter_next(&pipelineArray)) { pgbsonelement stageElement = GetPipelineStage(&pipelineArray, "facet", key); const char *nestedPipelineStage = stageElement.path; if (strcmp(nestedPipelineStage, "$collStats") == 0 || strcmp(nestedPipelineStage, "$facet") == 0 || strcmp(nestedPipelineStage, "$geoNear") == 0 || strcmp(nestedPipelineStage, "$indexStats") == 0 || strcmp(nestedPipelineStage, "$out") == 0 || strcmp(nestedPipelineStage, "$merge") == 0 || strcmp(nestedPipelineStage, "$planCacheStats") == 0 || strcmp(nestedPipelineStage, "$search") == 0 || strcmp(nestedPipelineStage, "$changeStream") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40600), errmsg( "%s cannot be utilized within an operators facet processing stage", nestedPipelineStage), errdetail_log( "%s cannot be utilized within an operators facet processing stage", nestedPipelineStage))); } } } if (numStages == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40169), errmsg( "No stages are specified for $facet"))); } return numStages; } /* * Given a specific facet value that corresponds to an object with * one or more fields containing pipelines, creates a query that has * the UNION ALL SELECT operators of all those pipelines. */ static Query * BuildFacetUnionAllQuery(int numStages, const bson_value_t *facetValue, CommonTableExpr *baseCte, QuerySource querySource, const bson_value_t *sortSpec, AggregationPipelineBuildContext *parentContext) { Query *modifiedQuery = NULL; ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = 1; /* Special case, if there's only 1 facet stage, we can just treat it as a SELECT from the CTE * with a Subquery and skip all the UNION ALL processing. */ if (numStages == 1) { pgbsonelement singleElement = { 0 }; BsonValueToPgbsonElement(facetValue, &singleElement); /* Creates a CTE that selects from the base CTE */ /* Levels up is unused as we reset it after we build the aggregation and the final levelsup * is determined. */ int levelsUpUnused = 0; Query *baseQuery = CreateCteSelectQuery(baseCte, "facetsub", parentContext->stageNum, levelsUpUnused); /* Mutate the Query to add the aggregation pipeline */ AggregationPipelineBuildContext nestedContext = { 0 }; nestedContext.nestedPipelineLevel = parentContext->nestedPipelineLevel + 1; nestedContext.databaseNameDatum = parentContext->databaseNameDatum; nestedContext.sortSpec = *sortSpec; nestedContext.variableSpec = parentContext->variableSpec; nestedContext.parentStageName = ParentStageName_FACET; strncpy((char *) nestedContext.collationString, parentContext->collationString, MAX_ICU_COLLATION_LENGTH); nestedContext.mongoCollection = parentContext->mongoCollection; nestedContext.collectionNameView = parentContext->collectionNameView; List *stages = ExtractAggregationStages(&singleElement.bsonValue, &nestedContext); modifiedQuery = MutateQueryWithPipeline(baseQuery, stages, &nestedContext); /* Add bson_array_agg to the output */ bool migrateToSubQuery = true; Aggref **aggrefPtr = NULL; modifiedQuery = AddBsonArrayAggFunction(modifiedQuery, &nestedContext, parseState, singleElement.path, singleElement.pathLength, migrateToSubQuery, aggrefPtr); } else { /* We need yet another layer thats going to hold the Set UNION ALL queries */ modifiedQuery = makeNode(Query); modifiedQuery->commandType = CMD_SELECT; modifiedQuery->querySource = querySource; modifiedQuery->canSetTag = true; modifiedQuery->jointree = makeNode(FromExpr); modifiedQuery->hasAggs = true; List *rangeTableReferences = NIL; bson_iter_t facetIterator; BsonValueInitIterator(facetValue, &facetIterator); int nestedStage = 1; Query *firstInnerQuery = NULL; Index firstRangeTableIndex = 0; while (bson_iter_next(&facetIterator)) { StringView pathView = bson_iter_key_string_view(&facetIterator); /* Same drill - create a CTE Scan */ /* Note that levelsUp is overridden after the query is built. * In this path because we create a wrapper for the SetOperation, the * prior stage query is at least 1 level up from each nested pipeline query. * Since we attach the CTE to the query with the obj_agg, we add one more level * to the CTE levels up. */ Query *baseQuery = CreateCteSelectQuery(baseCte, "facetsub", nestedStage, 0); /* Modify the pipeline */ AggregationPipelineBuildContext nestedContext = { 0 }; nestedContext.nestedPipelineLevel = 1; nestedContext.databaseNameDatum = parentContext->databaseNameDatum; nestedContext.sortSpec = *sortSpec; nestedContext.variableSpec = parentContext->variableSpec; nestedContext.parentStageName = ParentStageName_FACET; strncpy((char *) nestedContext.collationString, parentContext->collationString, MAX_ICU_COLLATION_LENGTH); nestedContext.mongoCollection = parentContext->mongoCollection; nestedContext.collectionNameView = parentContext->collectionNameView; nestedContext.nestedPipelineLevel = parentContext->nestedPipelineLevel + 1; List *stages = ExtractAggregationStages(bson_iter_value(&facetIterator), &nestedContext); Query *innerQuery = MutateQueryWithPipeline(baseQuery, stages, &nestedContext); /* Add the BSON_ARRAY_AGG function */ bool migrateToSubQuery = true; Aggref **aggrefPtr = NULL; innerQuery = AddBsonArrayAggFunction(innerQuery, &nestedContext, parseState, pathView.string, pathView.length, migrateToSubQuery, aggrefPtr); /* Build the RTE for the output and add it to the SetOperation wrapper */ bool includeAllColumns = false; RangeTblEntry *entry = MakeSubQueryRte(innerQuery, nestedStage, 0, "facetinput", includeAllColumns); modifiedQuery->rtable = lappend(modifiedQuery->rtable, entry); /* Track the RangeTableRef to this RTE (Will be used later) */ RangeTblRef *innerRangeTableRef = makeNode(RangeTblRef); innerRangeTableRef->rtindex = list_length(modifiedQuery->rtable); if (firstInnerQuery == NULL) { firstInnerQuery = innerQuery; firstRangeTableIndex = innerRangeTableRef->rtindex; } rangeTableReferences = lappend(rangeTableReferences, innerRangeTableRef); nestedStage++; } /* now build the SetOperationStmt tree: This is the UNION ALL */ int i = 0; SetOperationStmt *setOpStatement = MakeBsonSetOpStatement(); bool insertLeft = false; for (i = 0; i < list_length(rangeTableReferences); i++) { if (setOpStatement->larg == NULL) { setOpStatement->larg = (Node *) list_nth(rangeTableReferences, i); } else if (setOpStatement->rarg == NULL) { setOpStatement->rarg = (Node *) list_nth(rangeTableReferences, i); } else if (insertLeft) { /* Both left and right are full and we want to add a node * Flip flop between inserting on the left and right */ SetOperationStmt *newStatement = MakeBsonSetOpStatement(); newStatement->larg = setOpStatement->larg; newStatement->rarg = (Node *) list_nth(rangeTableReferences, i); setOpStatement->larg = (Node *) newStatement; insertLeft = false; } else { SetOperationStmt *newStatement = MakeBsonSetOpStatement(); newStatement->larg = setOpStatement->rarg; newStatement->rarg = (Node *) list_nth(rangeTableReferences, i); setOpStatement->rarg = (Node *) newStatement; insertLeft = true; } } /* Update the query with the SetOp statement */ modifiedQuery->setOperations = (Node *) setOpStatement; /* Result column node */ TargetEntry *leftMostTargetEntry = linitial(firstInnerQuery->targetList); Var *var = makeVar(firstRangeTableIndex, leftMostTargetEntry->resno, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *restle = makeTargetEntry((Expr *) var, leftMostTargetEntry->resno, leftMostTargetEntry->resname, false); modifiedQuery->targetList = list_make1(restle); } pfree(parseState); return modifiedQuery; } /* * Creates the COALESCE(Expr, '{ "field": [] }'::bson) * Expression for an arbitrary expression. */ static Expr * GetArrayAggCoalesce(Expr *innerExpr, const char *fieldPath, uint32_t fieldPathLength) { pgbson_writer defaultValueWriter; PgbsonWriterInit(&defaultValueWriter); PgbsonWriterAppendEmptyArray(&defaultValueWriter, fieldPath, fieldPathLength); pgbson *bson = PgbsonWriterGetPgbson(&defaultValueWriter); /* Add COALESCE operator */ CoalesceExpr *coalesce = makeNode(CoalesceExpr); coalesce->coalescetype = BsonTypeId(); coalesce->coalescecollid = InvalidOid; coalesce->args = list_make2(innerExpr, MakeBsonConst(bson)); return (Expr *) coalesce; } /* * Creates the COALESCE(Expr, '{ }'::bson) * Expression for an arbitrary expression. */ static Expr * GetEmptyBsonCoalesce(Expr *innerExpr) { pgbson_writer defaultValueWriter; PgbsonWriterInit(&defaultValueWriter); pgbson *emptyBson = PgbsonWriterGetPgbson(&defaultValueWriter); /* Add COALESCE operator */ CoalesceExpr *coalesce = makeNode(CoalesceExpr); coalesce->coalescetype = BsonTypeId(); coalesce->coalescecollid = InvalidOid; coalesce->args = list_make2(innerExpr, MakeBsonConst(emptyBson)); return (Expr *) coalesce; } /* * Adds either the BSON_ARRAY_AGG or bson_expression_get function to a given lookup right query. * Also migrates the existing query to a subquery if required. */ static Query * AddLookupRightQueryExpressionOrArrayAgg(Query *rightQuery, AggregationPipelineBuildContext *context, ParseState *parseState, LookupArgs *lookupArgs, LookupContext *lookupContext, bool requiresSubQuery) { Query *modifiedQuery = requiresSubQuery ? MigrateQueryToSubQuery(rightQuery, context) : rightQuery; requiresSubQuery = false; if (lookupContext->isLookupUnwind) { /* Don't aggregate the documents inside array for lookUp + Unwind, later we use an specialized * merge operation to add the right document into the left docuement under the lookupAs field. */ return modifiedQuery; } else { Aggref **aggrefPtr = NULL; return AddBsonArrayAggFunction(modifiedQuery, context, parseState, lookupArgs->lookupAs.string, lookupArgs->lookupAs.length, requiresSubQuery, aggrefPtr); } } /* * Adds the BSON_ARRAY_AGG function to a given query. Also migrates the existing query * to a subquery if required. */ static Query * AddBsonArrayAggFunction(Query *baseQuery, AggregationPipelineBuildContext *context, ParseState *parseState, const char *fieldPath, uint32_t fieldPathLength, bool migrateToSubQuery, Aggref **aggrefPtr) { /* Now add the bson_array_agg function */ Query *modifiedQuery = migrateToSubQuery ? MigrateQueryToSubQuery(baseQuery, context) : baseQuery; /* The first projector is the document */ TargetEntry *firstEntry = linitial(modifiedQuery->targetList); List *aggregateArgs = list_make2( firstEntry->expr, MakeTextConst(fieldPath, fieldPathLength)); List *argTypesList = list_make2_oid(BsonTypeId(), TEXTOID); Aggref *aggref = CreateMultiArgAggregate(BsonArrayAggregateFunctionOid(), aggregateArgs, argTypesList, parseState); if (aggrefPtr != NULL) { *aggrefPtr = aggref; } firstEntry->expr = GetArrayAggCoalesce((Expr *) aggref, fieldPath, fieldPathLength); modifiedQuery->hasAggs = true; return modifiedQuery; } /* * Adds the BSON_OBJECT_AGG function to a given query. */ static Query * AddBsonObjectAggFunction(Query *baseQuery, AggregationPipelineBuildContext *context) { /* We replace the targetEntry so we're fine to take the resno 1 slot */ ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = 1; /* Better safe than sorry (Move it to a subquery) */ Query *modifiedQuery = MigrateQueryToSubQuery(baseQuery, context); /* The first projector is the document */ TargetEntry *firstEntry = linitial(modifiedQuery->targetList); /* Now add the bson_object_agg function */ List *aggregateArgs = list_make1(firstEntry->expr); List *argTypesList = list_make1_oid(BsonTypeId()); Aggref *aggref = CreateMultiArgAggregate(BsonObjectAggregateFunctionOid(), aggregateArgs, argTypesList, parseState); firstEntry->expr = (Expr *) aggref; modifiedQuery->hasAggs = true; pfree(parseState); return modifiedQuery; } /* * Updates an RTE with the CTE information */ static void UpdateCteRte(RangeTblEntry *rte, CommonTableExpr *baseCte) { Assert(rte->rtekind == RTE_CTE); rte->ctename = baseCte->ctename; rte->lateral = false; rte->inh = false; rte->inFromCl = true; List *colnames = NIL; List *coltypes = NIL; List *coltypmods = NIL; ListCell *cell; Query *baseQuery = (Query *) baseCte->ctequery; foreach(cell, baseQuery->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(cell); colnames = lappend(colnames, makeString(tle->resname ? tle->resname : "")); coltypes = lappend_oid(coltypes, exprType((Node *) tle->expr)); coltypmods = lappend_int(coltypmods, exprTypmod((Node *) tle->expr)); } rte->eref = makeAlias(rte->alias->aliasname, colnames); rte->alias = makeAlias(rte->alias->aliasname, NIL); rte->coltypes = coltypes; rte->coltypmods = coltypmods; baseCte->ctecolnames = colnames; baseCte->ctecoltypes = coltypes; baseCte->ctecoltypmods = coltypmods; } static RangeTblEntry * CreateCteRte(CommonTableExpr *baseCte, const char *prefix, int stageNum, int levelsUp) { StringInfo s = makeStringInfo(); appendStringInfo(s, "%s_stage_%d", prefix, stageNum); RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_CTE; rte->ctelevelsup = levelsUp; rte->alias = makeAlias(s->data, NIL); baseCte->cterefcount++; rte->self_reference = false; UpdateCteRte(rte, baseCte); return rte; } /* * Creates a base query that selects from a given FuncExpr. */ static Query * CreateFunctionSelectorQuery(FuncExpr *funcExpr, const char *prefix, int subStageNum, QuerySource querySource) { StringInfo s = makeStringInfo(); appendStringInfo(s, "%s_substage_%d", prefix, subStageNum); RangeTblFunction *tblFunction = makeNode(RangeTblFunction); tblFunction->funcexpr = (Node *) funcExpr; tblFunction->funccolcount = 1; tblFunction->funccoltypes = list_make1_oid(BsonTypeId()); tblFunction->funccolcollations = list_make1_oid(InvalidOid); tblFunction->funccoltypmods = list_make1_int(-1); RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_FUNCTION; rte->self_reference = false; rte->lateral = false; rte->inh = false; rte->inFromCl = true; rte->functions = list_make1(tblFunction); List *colnames = list_make1(makeString("lookup_unwind")); rte->alias = makeAlias(s->data, NIL); rte->eref = makeAlias(s->data, colnames); Var *queryOutput = makeVar(1, 1, funcExpr->funcresulttype, -1, InvalidOid, 0); bool resJunk = false; TargetEntry *upperEntry = makeTargetEntry((Expr *) queryOutput, 1, "funcName", resJunk); Query *newquery = makeNode(Query); newquery->commandType = CMD_SELECT; newquery->querySource = querySource; newquery->canSetTag = true; newquery->targetList = list_make1(upperEntry); newquery->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; newquery->jointree = makeFromExpr(list_make1(rtr), NULL); return newquery; } /* * Creates a base query that selects from a given CTE. */ static Query * CreateCteSelectQuery(CommonTableExpr *baseCte, const char *prefix, int stageNum, int levelsUp) { Assert(baseCte->ctequery != NULL); Query *baseQuery = (Query *) baseCte->ctequery; RangeTblEntry *rte = CreateCteRte(baseCte, prefix, stageNum, levelsUp); List *upperTargetList = NIL; Index rtIndex = 1; ListCell *cell; foreach(cell, baseQuery->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(cell); Var *newQueryOutput = makeVar(rtIndex, tle->resno, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *upperEntry = makeTargetEntry((Expr *) newQueryOutput, tle->resno, tle->resname, tle->resjunk); upperTargetList = lappend(upperTargetList, upperEntry); } Query *newquery = makeNode(Query); newquery->commandType = CMD_SELECT; newquery->querySource = baseQuery->querySource; newquery->canSetTag = true; newquery->targetList = upperTargetList; newquery->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; newquery->jointree = makeFromExpr(list_make1(rtr), NULL); return newquery; } /* * Parses the lookup aggregation value and extracts the from collection and pipeline. */ void LookupExtractCollectionAndPipeline(const bson_value_t *lookupValue, StringView *collection, bson_value_t *pipeline) { LookupArgs args; memset(&args, 0, sizeof(LookupArgs)); ParseLookupStage(lookupValue, &args); *collection = args.from; *pipeline = args.pipeline; } /* * Parses the graphLookup aggregation value and extracts the from collection. */ void GraphLookupExtractCollection(const bson_value_t *lookupValue, StringView *collection) { GraphLookupArgs args; memset(&args, 0, sizeof(LookupArgs)); ParseGraphLookupStage(lookupValue, &args); *collection = args.fromCollection; } /* * Parses & validates the input lookup spec. * Parsed outputs are placed in the LookupArgs struct. */ static void ParseLookupStage(const bson_value_t *existingValue, LookupArgs *args) { if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40319), errmsg( "The $lookup stage must be defined as an object, but instead a %s value was provided.", BsonTypeName(existingValue->value_type)))); } bson_iter_t lookupIter; BsonValueInitIterator(existingValue, &lookupIter); while (bson_iter_next(&lookupIter)) { const char *key = bson_iter_key(&lookupIter); const bson_value_t *value = bson_iter_value(&lookupIter); if (strcmp(key, "as") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "lookup argument 'as' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->lookupAs = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; } else if (strcmp(key, "foreignField") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "lookup argument 'foreignField' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->foreignField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; } else if (strcmp(key, "from") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40321), errmsg( "The 'from' parameter in lookup must be provided as a string, but a value of type %s was given instead.", BsonTypeName(value->value_type)))); } args->from = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; } else if (strcmp(key, "let") == 0) { if (value->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "lookup argument 'let' must be a document, is type %s", BsonTypeName(value->value_type)))); } /* let's use bson_dollar_project to evalute expression just exclude _id field */ if (!IsBsonValueEmptyDocument(value)) { args->let = PgbsonInitFromDocumentBsonValue(value); } } else if (strcmp(key, "localField") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "lookup argument 'localField' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->localField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; } else if (strcmp(key, "pipeline") == 0) { EnsureTopLevelFieldValueType("$lookup.pipeline", value, BSON_TYPE_ARRAY); args->pipeline = *value; bson_iter_t pipelineArray; BsonValueInitIterator(value, &pipelineArray); /* These stages are not allowed when executing $lookup */ while (bson_iter_next(&pipelineArray)) { pgbsonelement stageElement = GetPipelineStage(&pipelineArray, "lookup", "pipeline"); const char *nestedPipelineStage = stageElement.path; if (strcmp(nestedPipelineStage, "$out") == 0 || strcmp(nestedPipelineStage, "$merge") == 0 || strcmp(nestedPipelineStage, "$changeStream") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51047), errmsg( "%s usage is prohibited inside a $lookup stage", nestedPipelineStage))); } } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Unrecognized parameter provided to $lookup: %s", key))); } } if (args->lookupAs.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("must specify 'as' field for a $lookup"))); } bool isPipelineLookup = args->pipeline.value_type != BSON_TYPE_EOD; if (args->from.length == 0 && !isPipelineLookup) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("must specify 'from' field for a $lookup"))); } if (!isPipelineLookup && (args->foreignField.length == 0 || args->localField.length == 0)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "$lookup needs to be provided with either a 'pipeline' definition or both 'localField' and 'foreignField' parameters explicitly"))); } if ((args->foreignField.length == 0) ^ (args->localField.length == 0)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "$lookup needs either both 'localField' and 'foreignField' specified or neither of them provided"))); } if (args->foreignField.length != 0) { args->hasLookupMatch = true; } } /* * Helper method to create Lookup's JOIN RTE - this is the entry in the RTE * That goes in the Lookup's FROM clause and ties the two tables together. * * Note: useInnerJoin makes use of the INNER JOIN instead of LEFT JOIN */ inline static RangeTblEntry * MakeLookupJoinRte(List *joinVars, List *colNames, List *joinLeftCols, List *joinRightCols, bool useInnerJoin) { /* Add an RTE for the JoinExpr */ RangeTblEntry *joinRte = makeNode(RangeTblEntry); joinRte->rtekind = RTE_JOIN; joinRte->relid = InvalidOid; joinRte->subquery = NULL; joinRte->jointype = useInnerJoin ? JOIN_INNER : JOIN_LEFT; joinRte->joinmergedcols = 0; /* No using clause */ joinRte->joinaliasvars = joinVars; joinRte->joinleftcols = joinLeftCols; joinRte->joinrightcols = joinRightCols; joinRte->join_using_alias = NULL; joinRte->alias = makeAlias("lookup_join", colNames); joinRte->eref = joinRte->alias; joinRte->inh = false; /* never true for joins */ joinRte->inFromCl = true; #if PG_VERSION_NUM >= 160000 joinRte->perminfoindex = 0; #else joinRte->requiredPerms = 0; joinRte->checkAsUser = InvalidOid; joinRte->selectedCols = NULL; joinRte->insertedCols = NULL; joinRte->updatedCols = NULL; joinRte->extraUpdatedCols = NULL; #endif return joinRte; } /* * Given a query in a specified RTE index that returns only BSON values, updates 3 lists based on the query: * 1) OutputVars are going to be Var nodes that point to the (RTE, Output) position * 2) The names of the output columns across the query * 3) The integer result numbers of the Vars. * Used to build the JoinRTE for lookup */ inline static void MakeBsonJoinVarsFromQuery(Index queryIndex, Query *query, List **outputVars, List **outputColNames, List **joinCols) { ListCell *cell; foreach(cell, query->targetList) { TargetEntry *entry = lfirst(cell); Var *outputVar = makeVar(queryIndex, entry->resno, BsonTypeId(), -1, InvalidOid, 0); *outputVars = lappend(*outputVars, outputVar); *outputColNames = lappend(*outputColNames, makeString(entry->resname)); *joinCols = lappend_int(*joinCols, (int) entry->resno); } } /* * Before applying the lookup query, parses the lookup args & context * and builds an optimization plan including how to join, how to apply the * pipeline and such. * This also handles splitting a lookup pipeline into pushdown and * non-pushdown etc. */ static void OptimizeLookup(LookupArgs *lookupArgs, Query *leftQuery, AggregationPipelineBuildContext *leftQueryContext, LookupOptimizationArgs *optimizationArgs) { optimizationArgs->rightQueryContext.nestedPipelineLevel = leftQueryContext->nestedPipelineLevel + 1; optimizationArgs->rightQueryContext.databaseNameDatum = leftQueryContext->databaseNameDatum; optimizationArgs->rightQueryContext.variableSpec = leftQueryContext->variableSpec; strncpy((char *) optimizationArgs->rightQueryContext.collationString, leftQueryContext->collationString, MAX_ICU_COLLATION_LENGTH); optimizationArgs->rightQueryContext.parentStageName = ParentStageName_LOOKUP; optimizationArgs->rightQueryContext.optimizePipelineStages = leftQueryContext->optimizePipelineStages; optimizationArgs->isLookupAgnostic = lookupArgs->from.length == 0; optimizationArgs->isLookupUncorrelated = !lookupArgs->hasLookupMatch; bson_value_t inlinedLookupPipeline = (bson_value_t) { 0 }; bson_value_t nonInlinedLookupPipeline = (bson_value_t) { 0 }; if (leftQueryContext->variableSpec != NULL && !IsA(leftQueryContext->variableSpec, Const)) { optimizationArgs->hasLet = true; } if (lookupArgs->let) { /* Validate the lookupArgs->let if the left query had no let variables specified in it. */ /* With EnableNowSystemVariable, time system variables are stored in the left query's variableSpec even in the absence of let. */ /* Thus, if the left query's variableSpec contains only the time system variables, */ /* we perform a validation on the lookupArgs->let. */ if (leftQueryContext->variableSpec == NULL) { bson_value_t varsValue = ConvertPgbsonToBsonValue(lookupArgs->let); ExpressionVariableContext *nullContext = NULL; ParseAggregationExpressionContext parseContext = { .validateParsedExpressionFunc = &ValidateLetHasNoVariables, }; ParseVariableSpec(&varsValue, nullContext, &parseContext); } else if (EnableNowSystemVariable && IsA(leftQueryContext->variableSpec, Const)) { Node *specNode = (Node *) leftQueryContext->variableSpec; Const *specConst = (Const *) specNode; pgbson *specBson = DatumGetPgBson(specConst->constvalue); bson_iter_t iter; if (!PgbsonInitIteratorAtPath(specBson, "let", &iter)) { bson_value_t varsValue = ConvertPgbsonToBsonValue(lookupArgs->let); ExpressionVariableContext *nullContext = NULL; ParseAggregationExpressionContext parseContext = { .validateParsedExpressionFunc = &ValidateLetHasNoVariables, }; GetTimeSystemVariablesFromVariableSpec(specBson, &parseContext. timeSystemVariables); ParseVariableSpec(&varsValue, nullContext, &parseContext); } } /* If there is lookup let, we will build the let in the left query and then the let expression * should be used by the right query / post join stages wherever needed. */ Const *letConstValue = MakeBsonConst(lookupArgs->let); List *args; Oid funcOid; Expr *sourceVariableSpec = leftQueryContext->variableSpec; if (sourceVariableSpec == NULL) { sourceVariableSpec = (Expr *) MakeBsonConst(PgbsonInitEmpty()); } Expr *documentExpr = linitial_node(TargetEntry, leftQuery->targetList)->expr; args = list_make3(documentExpr, letConstValue, sourceVariableSpec); funcOid = BsonDollarLookupExpressionEvalMergeOid(); Expr *letExpr = (Expr *) makeFuncExpr(funcOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); optimizationArgs->lookupLetAttrNum = list_length(leftQuery->targetList) + 1; TargetEntry *lookupLetEntry = makeTargetEntry(letExpr, optimizationArgs->lookupLetAttrNum, "let", false); leftQuery->targetList = lappend(leftQuery->targetList, lookupLetEntry); /* * Make a VAR to access the above let in right query. * Today the right query is pushed to a CTE for and this Var is * used to support special case non-inline stages i.e. $match * so varlevelsup is 1 */ Index varLevelsUp = 1; int leftQueryVarNo = 1; Expr *letVarExpr = (Expr *) makeVar(leftQueryVarNo, optimizationArgs->lookupLetAttrNum, BsonTypeId(), -1, InvalidOid, varLevelsUp); optimizationArgs->rightQueryContext.variableSpec = letVarExpr; optimizationArgs->hasLet = true; } if (optimizationArgs->hasLet) { optimizationArgs->isLookupUncorrelated = false; if (optimizationArgs->isLookupAgnostic) { /* TODO Support agnostic queries with lookup with let */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$lookup with let with agnostic queries not supported yet"))); } } /* For the right query, generate a base table query for the right collection */ pg_uuid_t *collectionUuid = NULL; bson_value_t *indexHint = NULL; optimizationArgs->rightBaseQuery = optimizationArgs->isLookupAgnostic ? GenerateBaseAgnosticQuery( optimizationArgs->rightQueryContext.databaseNameDatum, &optimizationArgs->rightQueryContext) : GenerateBaseTableQuery( optimizationArgs->rightQueryContext.databaseNameDatum, &lookupArgs->from, collectionUuid, indexHint, &optimizationArgs->rightQueryContext); /* Now let's figure out if we can join on _id */ optimizationArgs->isLookupJoinOnRightId = StringViewEquals(&lookupArgs->foreignField, &IdFieldStringView) && !optimizationArgs->isLookupAgnostic; if (IsCollationApplicable(leftQueryContext->collationString) && !EnableLookupIdJoinOptimizationOnCollation) { /* Can't perform _id join when collation is applicable (since _id can * contain UTF8 which is collation aware), unless it is explicitly instructed * via GUC `EnableLookupIdJoinOptimizationOnCollation` (e.g., for cases when _id * contains collation agnostic datatype) */ optimizationArgs->isLookupJoinOnRightId = false; } if (optimizationArgs->isLookupJoinOnRightId && list_length(optimizationArgs->rightBaseQuery->rtable) == 1 && list_length(optimizationArgs->rightBaseQuery->targetList) == 1 && optimizationArgs->rightQueryContext.mongoCollection != NULL && optimizationArgs->rightQueryContext.mongoCollection->shardKey == NULL) { RangeTblEntry *entry = linitial(optimizationArgs->rightBaseQuery->rtable); TargetEntry *firstEntry = linitial(optimizationArgs->rightBaseQuery->targetList); if (entry->rtekind != RTE_RELATION || !IsA(firstEntry->expr, Var)) { /* These cases can't do lookup on _id */ optimizationArgs->isLookupJoinOnRightId = false; } } else { /* Not a single RTE, or is a sharded collection or a collection that doesn't exist * Can't do _id optimization. */ optimizationArgs->isLookupJoinOnRightId = false; } /* No point in inlining lookup pipeline on agnostic - it Has to be applied */ if (lookupArgs->pipeline.value_type == BSON_TYPE_EOD) { inlinedLookupPipeline = lookupArgs->pipeline; nonInlinedLookupPipeline = (bson_value_t) { 0 }; } else if (IsBsonValueEmptyArray(&lookupArgs->pipeline)) { inlinedLookupPipeline = lookupArgs->pipeline; nonInlinedLookupPipeline = (bson_value_t) { 0 }; } else if (optimizationArgs->isLookupUncorrelated || optimizationArgs->isLookupAgnostic) { inlinedLookupPipeline = lookupArgs->pipeline; nonInlinedLookupPipeline = (bson_value_t) { 0 }; } else if (optimizationArgs->isLookupJoinOnRightId) { /* In the cases where we are joining on _id, we don't want to apply the pipeline here. * This is because it's better to join on _id (index pushdown) then apply the pipeline on * the result. */ inlinedLookupPipeline = (bson_value_t) { 0 }; nonInlinedLookupPipeline = lookupArgs->pipeline; } else { StringView localFieldValue = lookupArgs->localField; StringView prefix = StringViewFindPrefix(&localFieldValue, '.'); if (prefix.length != 0) { localFieldValue = prefix; } bool isPipelineValid = false; pgbson *inlinedPipeline = NULL; pgbson *nonInlinedPipeline = NULL; bool canInlinePipelineCore = CanInlineLookupPipeline(&lookupArgs->pipeline, &localFieldValue, optimizationArgs->hasLet, &inlinedPipeline, &nonInlinedPipeline, &isPipelineValid); if (!isPipelineValid) { /* Invalid pipeline - just make it inlined to trigger the error */ inlinedLookupPipeline = lookupArgs->pipeline; nonInlinedLookupPipeline = (bson_value_t) { 0 }; } else if (canInlinePipelineCore) { /* The full pipeline can be inlined */ inlinedLookupPipeline = lookupArgs->pipeline; nonInlinedLookupPipeline = (bson_value_t) { 0 }; } else { pgbsonelement pipelineElement = { 0 }; if (!IsPgbsonEmptyDocument(inlinedPipeline)) { PgbsonToSinglePgbsonElement(inlinedPipeline, &pipelineElement); if (!IsBsonValueEmptyArray(&pipelineElement.bsonValue)) { inlinedLookupPipeline = pipelineElement.bsonValue; } } if (!IsPgbsonEmptyDocument(nonInlinedPipeline)) { PgbsonToSinglePgbsonElement(nonInlinedPipeline, &pipelineElement); if (!IsBsonValueEmptyArray(&pipelineElement.bsonValue)) { nonInlinedLookupPipeline = pipelineElement.bsonValue; } } } } optimizationArgs->isLookupJoinOnLeftId = false; if (optimizationArgs->isLookupJoinOnRightId && StringViewEquals(&lookupArgs->localField, &IdFieldStringView) && list_length(leftQuery->rtable) == 1 && list_length(leftQuery->targetList) == 1 && leftQueryContext->mongoCollection != NULL && leftQueryContext->mongoCollection->shardKey == NULL) { RangeTblEntry *entry = linitial(leftQuery->rtable); TargetEntry *firstEntry = linitial(leftQuery->targetList); if (entry->rtekind == RTE_RELATION && IsA(firstEntry->expr, Var)) { /* * These cases can't do lookup on _id on the left. * * Additionally, optimizationArgs->isLookupJoinOnLeftId also needs * to be set to `false` when collation is applicable. But, if that's * the case optimizationArgs->isLookupJoinOnRightId will be already * set to false and optimizationArgs->isLookupJoinOnLeftId will remain * at default `false`. */ optimizationArgs->isLookupJoinOnLeftId = true; } } /* Last check - nested $lookup with let not supported on sharded (citus limit) */ if (optimizationArgs->hasLet && leftQueryContext->mongoCollection != NULL && leftQueryContext->mongoCollection->shardKey != NULL && lookupArgs->pipeline.value_type != BSON_TYPE_EOD) { ValidatePipelineForShardedLookupWithLet(&lookupArgs->pipeline); } /* * Extract the inline and non inline pipeline stages after everythin is done. */ optimizationArgs->inlinedPipelineStages = ExtractAggregationStages( &inlinedLookupPipeline, &optimizationArgs->rightQueryContext); optimizationArgs->nonInlinedPipelineStages = ExtractAggregationStages( &nonInlinedLookupPipeline, &optimizationArgs->rightQueryContext); /* * If the first non-inline stages is a $match (which contains let and $expr), * and we don't have a better match plan e.g. join on righ collection _id then * we need to handle it similar to hasLookupMatch */ Stage firstNonInlineStage = GetAggregationStageAtPosition( optimizationArgs->nonInlinedPipelineStages, 0); if (!optimizationArgs->isLookupJoinOnRightId && firstNonInlineStage == Stage_Match) { optimizationArgs->nonInlinedMatchStage = (AggregationStage *) linitial( optimizationArgs->nonInlinedPipelineStages); optimizationArgs->nonInlinedPipelineStages = list_delete_first(optimizationArgs->nonInlinedPipelineStages); } } /* * Core JOIN building logic for $lookup. See comments within on logic * of each step within. */ static Query * ProcessLookupCoreWithLet(Query *query, AggregationPipelineBuildContext *context, LookupArgs *lookupArgs, LookupContext *lookupContext) { if (list_length(query->targetList) > 1) { /* if we have multiple projectors, push to a subquery (Lookup needs 1 projector) */ /* TODO: Can we do away with this */ query = MigrateQueryToSubQuery(query, context); } /* The left query is just the base query */ Query *leftQuery = query; LookupOptimizationArgs optimizationArgs = { 0 }; OptimizeLookup(lookupArgs, leftQuery, context, &optimizationArgs); /* Generate the lookup query */ /* Start with a fresh query */ Query *lookupQuery = makeNode(Query); lookupQuery->commandType = CMD_SELECT; lookupQuery->querySource = query->querySource; lookupQuery->canSetTag = true; lookupQuery->jointree = makeNode(FromExpr); /* Mark that we're adding a nesting level */ context->numNestedLevels++; const Index leftQueryRteIndex = 1; const Index rightQueryRteIndex = 2; const Index joinQueryRteIndex = 3; Query *rightQuery = optimizationArgs.rightBaseQuery; /* Create a parse_state for this session */ ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = 1; /* Process the right query where possible */ if (list_length(optimizationArgs.inlinedPipelineStages) > 0) { rightQuery = MutateQueryWithPipeline(rightQuery, optimizationArgs.inlinedPipelineStages, &optimizationArgs.rightQueryContext); } if (list_length(rightQuery->targetList) > 1 || optimizationArgs.rightQueryContext.requiresSubQueryAfterProject || optimizationArgs.rightQueryContext.requiresSubQuery) { rightQuery = MigrateQueryToSubQuery(rightQuery, &optimizationArgs.rightQueryContext); } /* Check if the pipeline can be pushed to the inner query (right collection) * If it can, then it's inlined. If not, we apply the pipeline post-join. */ if (lookupArgs->hasLookupMatch || optimizationArgs.nonInlinedMatchStage != NULL) { /* We can apply the optimization on this based on object_id if and only if * The right table is pointing directly to an actual table (not a view) * and we're an unsharded collection - or a view that just does a "filter" * match. */ if (optimizationArgs.isLookupJoinOnRightId) { PG_USED_FOR_ASSERTS_ONLY RangeTblEntry *entry = linitial(rightQuery->rtable); PG_USED_FOR_ASSERTS_ONLY TargetEntry *firstEntry = linitial( rightQuery->targetList); /* Add the document object_id projector as well, if there is no projection on the document && it's a base table * in the case of projections we can't be sure something like { "_id": "abc" } has been added */ Assert(entry->rtekind == RTE_RELATION && IsA(firstEntry->expr, Var)); /* Add the object_id targetEntry */ Var *objectIdVar = makeVar(1, DOCUMENT_DATA_TABLE_OBJECT_ID_VAR_ATTR_NUMBER, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *objectEntry = makeTargetEntry((Expr *) objectIdVar, list_length( rightQuery->targetList) + 1, "objectId", false); rightQuery->targetList = lappend(rightQuery->targetList, objectEntry); } CommonTableExpr *rightTableExpr = makeNode(CommonTableExpr); rightTableExpr->ctename = "lookup_right_query"; rightTableExpr->ctequery = (Node *) rightQuery; rightQuery = CreateCteSelectQuery(rightTableExpr, "lookup_right_query", context->nestedPipelineLevel, 0); if (lookupArgs->hasLookupMatch) { /* It's a join on a field, first add a TargetEntry for left for bson_dollar_lookup_extract_filter_expression */ TargetEntry *currentEntry = linitial(leftQuery->targetList); /* The extract query right arg is a simple bson of the form { "remoteField": "localField" } */ pgbson_writer filterWriter; PgbsonWriterInit(&filterWriter); PgbsonWriterAppendUtf8(&filterWriter, lookupArgs->foreignField.string, lookupArgs->foreignField.length, lookupArgs->localField.string); if (IsCollationApplicable(context->collationString)) { PgbsonWriterAppendUtf8(&filterWriter, "collation", 9, context->collationString); } pgbson *filterBson = PgbsonWriterGetPgbson(&filterWriter); /* Create the bson_dollar_lookup_extract_filter_expression(document, 'filter') */ List *extractFilterArgs = list_make2(currentEntry->expr, MakeBsonConst( filterBson)); Expr *projectorFunc; if (optimizationArgs.isLookupJoinOnLeftId) { /* If we can join on the left _id, then just use object_id */ projectorFunc = (Expr *) makeVar(1, DOCUMENT_DATA_TABLE_OBJECT_ID_VAR_ATTR_NUMBER, BsonTypeId(), -1, InvalidOid, 0); } else if (optimizationArgs.isLookupJoinOnRightId) { projectorFunc = (Expr *) makeFuncExpr( BsonLookupExtractFilterArrayFunctionOid(), GetBsonArrayTypeOid(), extractFilterArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } else { Oid extractFunctionOid = DocumentDBApiInternalBsonLookupExtractFilterExpressionFunctionOid(); projectorFunc = (Expr *) makeFuncExpr( extractFunctionOid, BsonTypeId(), extractFilterArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } AttrNumber newProjectorAttrNum = list_length(leftQuery->targetList) + 1; TargetEntry *extractFilterProjector = makeTargetEntry((Expr *) projectorFunc, newProjectorAttrNum, "lookup_filter", false); leftQuery->targetList = lappend(leftQuery->targetList, extractFilterProjector); /* now on the right query, add a filter referencing this projector */ List *rightQuals = NIL; if (rightQuery->jointree->quals != NULL) { rightQuals = make_ands_implicit((Expr *) rightQuery->jointree->quals); } /* add the WHERE bson_dollar_in(t2.document, t1.match) */ TargetEntry *currentRightEntry = linitial(rightQuery->targetList); Var *rightVar = (Var *) currentRightEntry->expr; int matchLevelsUp = 1; Node *inClause; if (optimizationArgs.isLookupJoinOnLeftId) { /* Do a direct equality against object_id */ Assert(list_length(rightQuery->targetList) == 2); TargetEntry *rightObjectIdEntry = (TargetEntry *) lsecond( rightQuery->targetList); rightQuery->targetList = list_make1(currentRightEntry); Var *matchVar = makeVar(leftQueryRteIndex, newProjectorAttrNum, BsonTypeId(), -1, InvalidOid, matchLevelsUp); inClause = (Node *) make_opclause(BsonEqualOperatorId(), BOOLOID, false, copyObject( rightObjectIdEntry->expr), (Expr *) matchVar, InvalidOid, InvalidOid); } else if (optimizationArgs.isLookupJoinOnRightId) { Assert(list_length(rightQuery->targetList) == 2); TargetEntry *rightObjectIdEntry = (TargetEntry *) lsecond( rightQuery->targetList); rightQuery->targetList = list_make1(currentRightEntry); ScalarArrayOpExpr *inOperator = makeNode(ScalarArrayOpExpr); inOperator->useOr = true; inOperator->opno = BsonEqualOperatorId(); Var *matchVar = makeVar(leftQueryRteIndex, newProjectorAttrNum, GetBsonArrayTypeOid(), -1, InvalidOid, matchLevelsUp); List *inArgs = list_make2(copyObject(rightObjectIdEntry->expr), matchVar); inOperator->args = inArgs; inClause = (Node *) inOperator; } else { Var *matchVar = makeVar(leftQueryRteIndex, newProjectorAttrNum, BsonTypeId(), -1, InvalidOid, matchLevelsUp); Const *textConst = MakeTextConst(lookupArgs->foreignField.string, lookupArgs->foreignField.length); List *inArgs = list_make3(copyObject(rightVar), matchVar, textConst); inClause = (Node *) makeFuncExpr(BsonDollarLookupJoinFilterFunctionOid(), BOOLOID, inArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } if (rightQuals == NIL) { rightQuery->jointree->quals = inClause; } else { rightQuals = lappend(rightQuals, inClause); rightQuery->jointree->quals = (Node *) make_ands_explicit(rightQuals); } } /* * Add the $match with $expr to the right query */ if (optimizationArgs.nonInlinedMatchStage != NULL) { HandleMatch(&optimizationArgs.nonInlinedMatchStage->stageValue, rightQuery, &optimizationArgs.rightQueryContext); } /* Add the bson_array_agg function */ bool requiresSubQuery = false; rightQuery = AddLookupRightQueryExpressionOrArrayAgg(rightQuery, &optimizationArgs. rightQueryContext, parseState, lookupArgs, lookupContext, requiresSubQuery); rightQuery->cteList = list_make1(rightTableExpr); } else { /* If lookup is purely a pipeline (uncorrelated subquery) then * modify the pipeline. */ bool migrateToSubQuery = false; rightQuery = AddLookupRightQueryExpressionOrArrayAgg(rightQuery, &optimizationArgs. rightQueryContext, parseState, lookupArgs, lookupContext, migrateToSubQuery); } /* Due to citus query_pushdown_planning.JoinTreeContainsSubqueryWalker * we can't just use SubQueries (however, CTEs work). So move the left * query is pushed to a CTE which seems to work (Similar to what the GW) * does. */ StringInfo cteStr = makeStringInfo(); appendStringInfo(cteStr, "lookupLeftCte_%d", context->nestedPipelineLevel); CommonTableExpr *cteExpr = makeNode(CommonTableExpr); cteExpr->ctename = cteStr->data; cteExpr->ctequery = (Node *) leftQuery; lookupQuery->cteList = lappend(lookupQuery->cteList, cteExpr); int stageNum = 1; RangeTblEntry *leftTree = CreateCteRte(cteExpr, "lookup", stageNum, 0); /* The "from collection" becomes another RTE */ bool includeAllColumns = true; RangeTblEntry *rightTree = MakeSubQueryRte(rightQuery, 1, context->nestedPipelineLevel, "lookupRight", includeAllColumns); /* Mark the Right RTE as a lateral join*/ rightTree->lateral = true; /* Build the JOIN RTE joining the left and right RTEs */ List *outputVars = NIL; List *outputColNames = NIL; List *leftJoinCols = NIL; List *rightJoinCols = NIL; MakeBsonJoinVarsFromQuery(leftQueryRteIndex, leftQuery, &outputVars, &outputColNames, &leftJoinCols); MakeBsonJoinVarsFromQuery(rightQueryRteIndex, rightQuery, &outputVars, &outputColNames, &rightJoinCols); bool useInnerJoin = !lookupContext->preserveNullAndEmptyArrays && EnableLookupInnerJoin; RangeTblEntry *joinRte = MakeLookupJoinRte(outputVars, outputColNames, leftJoinCols, rightJoinCols, useInnerJoin); lookupQuery->rtable = list_make3(leftTree, rightTree, joinRte); /* Now specify the "From" as a join */ /* The query has a single 'FROM' which is a Join */ JoinExpr *joinExpr = makeNode(JoinExpr); joinExpr->jointype = joinRte->jointype; joinExpr->rtindex = joinQueryRteIndex; /* Create RangeTblRef's to point to the left & right RTEs */ RangeTblRef *leftRef = makeNode(RangeTblRef); leftRef->rtindex = leftQueryRteIndex; RangeTblRef *rightRef = makeNode(RangeTblRef); rightRef->rtindex = rightQueryRteIndex; joinExpr->larg = (Node *) leftRef; joinExpr->rarg = (Node *) rightRef; /* Join ON TRUE */ joinExpr->quals = (Node *) makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); lookupQuery->jointree->fromlist = list_make1(joinExpr); /* Now add the lookup projector */ /* The lookup projector is an addFields on the left doc */ /* And the rightArg will be an addFieldsSpec already under a bson_array_agg(value, 'asField') */ Expr *leftOutput = (Expr *) makeVar(leftRef->rtindex, (AttrNumber) 1, BsonTypeId(), -1, InvalidOid, 0); Expr *rightOutput = (Expr *) makeVar(rightRef->rtindex, (AttrNumber) 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *leftTargetEntry = makeTargetEntry(leftOutput, 1, "left", false); TargetEntry *rightTargetEntry = makeTargetEntry(rightOutput, 2, "right", false); lookupQuery->targetList = list_make2(leftTargetEntry, rightTargetEntry); /* handle the post non-inlined query */ /* If there's a pipeline, run it here as a subquery only if we * couldn't inline it in the top level query. * We do it here since it's easier to deal with the pipeline * post join (fewer queries to think about and manage). */ if (list_length(optimizationArgs.nonInlinedPipelineStages) > 0) { resetStringInfo(cteStr); appendStringInfo(cteStr, "lookup_join_cte_%d", context->nestedPipelineLevel); CommonTableExpr *lookupCte = makeNode(CommonTableExpr); lookupCte->ctename = cteStr->data; lookupCte->ctequery = (Node *) lookupQuery; /* * Before creating the CTE - add the $let from left query to be used by post join pipeline * It's a deliberate choice to rebuild the let expression here instead of reusing the one that is available * because the expressions are not CONST and can pose problems if not handled properly. */ if (lookupArgs->let) { /* Evaluate the let against the leftExpr */ /* Let Expression Evaluation here */ Const *letConstValue = MakeBsonConst(lookupArgs->let); List *args; Oid funcOid; Expr *sourceVariableSpec = context->variableSpec; if (sourceVariableSpec == NULL) { sourceVariableSpec = (Expr *) MakeBsonConst(PgbsonInitEmpty()); } args = list_make3(leftOutput, letConstValue, sourceVariableSpec); funcOid = BsonDollarLookupExpressionEvalMergeOid(); Expr *letExpr = (Expr *) makeFuncExpr(funcOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *lookupLetEntry = makeTargetEntry(letExpr, 3, "let", false); lookupQuery->targetList = lappend(lookupQuery->targetList, lookupLetEntry); } Query *cteLookupQuery = CreateCteSelectQuery(lookupCte, "lookup_non_inlined", 1, 0); cteLookupQuery->cteList = list_make1(lookupCte); TargetEntry *firstEntry = linitial(cteLookupQuery->targetList); TargetEntry *secondEntry = lsecond(cteLookupQuery->targetList); Var *secondVar = (Var *) copyObject(secondEntry->expr); /* varlevelsup is set to 0 and once the complete pipeline building is done, levelsup is adjusted again. * If it is set to anything as a positive value here then we will end up with wrong expectation of levelsup while * creating $group Aggregate queries within pipeline. * Refer: check_agglevels_and_constraints in parse_aggs.c * https://github.com/postgres/postgres/blob/2e66cae935c2e0f7ce9bab6b65ddeb7806f4de7c/src/backend/parser/parse_agg.c#L347C2-L349C27 */ secondVar->varlevelsup = 0; secondVar->location = NESTED_PIPELINE_VAR_FLAG | context->nestedPipelineLevel; Expr *letExpr = NULL; Var *letVar = NULL; if (lookupArgs->let) { letExpr = copyObject(lthird_node(TargetEntry, cteLookupQuery->targetList)->expr); letVar = (Var *) letExpr; letVar->varlevelsup = 0; letVar->location = NESTED_PIPELINE_VAR_FLAG | context->nestedPipelineLevel; } else { letExpr = context->variableSpec; } /* * We need to do the apply the lookup pipeline. Before proceeding * if we have a "let" then project the evaluated let here. */ List *unwindArgs = list_make2(secondVar, MakeTextConst(lookupArgs->lookupAs.string, lookupArgs->lookupAs.length)); FuncExpr *funcExpr = makeFuncExpr(BsonLookupUnwindFunctionOid(), BsonTypeId(), unwindArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); funcExpr->funcretset = true; Query *subSelectQuery = CreateFunctionSelectorQuery(funcExpr, "lookup_subpipeline", context-> nestedPipelineLevel, query->querySource); AggregationPipelineBuildContext projectorQueryContext = { 0 }; projectorQueryContext.nestedPipelineLevel = context->nestedPipelineLevel + 1; projectorQueryContext.databaseNameDatum = optimizationArgs.rightQueryContext.databaseNameDatum; projectorQueryContext.collectionNameView = optimizationArgs.rightQueryContext.collectionNameView; projectorQueryContext.mongoCollection = optimizationArgs.rightQueryContext.mongoCollection; projectorQueryContext.variableSpec = letExpr; projectorQueryContext.parentStageName = ParentStageName_LOOKUP; strncpy((char *) projectorQueryContext.collationString, context->collationString, MAX_ICU_COLLATION_LENGTH); subSelectQuery = MutateQueryWithPipeline(subSelectQuery, optimizationArgs.nonInlinedPipelineStages, &projectorQueryContext); if (list_length(subSelectQuery->targetList) > 1) { projectorQueryContext.requiresSubQuery = true; } /* Readd the aggregate */ Aggref **aggrefPtr = NULL; subSelectQuery = AddBsonArrayAggFunction(subSelectQuery, &projectorQueryContext, parseState, lookupArgs->lookupAs.string, lookupArgs->lookupAs.length, projectorQueryContext. requiresSubQuery, aggrefPtr); /* Fix up levelsup for the subselect query */ WalkQueryAndSetLevelsUp(subSelectQuery, secondVar, 1); if (letVar) { WalkQueryAndSetLevelsUp(subSelectQuery, letVar, 1); } SubLink *subLink = makeNode(SubLink); subLink->subLinkType = EXPR_SUBLINK; subLink->subLinkId = 0; subLink->subselect = (Node *) subSelectQuery; secondEntry->expr = (Expr *) subLink; cteLookupQuery->hasSubLinks = true; lookupQuery = cteLookupQuery; leftOutput = firstEntry->expr; rightOutput = secondEntry->expr; } List *mergeDocumentsArgs = list_make2(leftOutput, rightOutput); Oid mergeDocumentsOid = BsonDollaMergeDocumentsFunctionOid(); if (lookupContext->isLookupUnwind) { /* * If we are processing a lookup unwind with `preserveNullAndEmptyArrays: true` * that means we are performing a LEFT JOIN but if the left documnets don't match with anything * on the right we still need to write the left documents. So we will need to replace the rightOutput * expression to a coalesce(rightOutput, {}) expression. * * Similarly, if `preserveNullAndEmptyArrays: false` we will need to filter out all the non-matching * NULL documents from the right query i.e. righQuery.document IS NOT NULL */ Expr *rightDocExpr = lsecond(mergeDocumentsArgs); if (lookupContext->preserveNullAndEmptyArrays) { #if PG_VERSION_NUM >= 160000 /* * Starting PG 16, if we are preserving nulls, then we need to set the varnullingrels * to the join RTE index so that document var can be replaced if NULL. */ if (IsA(rightDocExpr, Var)) { Bitmapset *nullValIngRel = NULL; nullValIngRel = bms_add_member(nullValIngRel, joinQueryRteIndex); ((Var *) rightDocExpr)->varnullingrels = nullValIngRel; } #endif Expr *coalesceExpr = GetEmptyBsonCoalesce(rightDocExpr); list_nth_cell(mergeDocumentsArgs, 1)->ptr_value = coalesceExpr; } else if (!useInnerJoin) { NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NOT_NULL; nullTest->arg = rightDocExpr; List *existingQuals = make_ands_implicit( (Expr *) lookupQuery->jointree->quals); existingQuals = lappend(existingQuals, nullTest); lookupQuery->jointree->quals = (Node *) make_ands_explicit(existingQuals); } mergeDocumentsArgs = lappend(mergeDocumentsArgs, MakeTextConst(lookupArgs->lookupAs.string, lookupArgs->lookupAs.length)); mergeDocumentsOid = BsonDollarMergeDocumentAtPathFunctionOid(); } else { bool overrideArrayInMerge = true; mergeDocumentsArgs = lappend(mergeDocumentsArgs, MakeBoolValueConst(overrideArrayInMerge)); } FuncExpr *addFields = makeFuncExpr(mergeDocumentsOid, BsonTypeId(), mergeDocumentsArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *topTargetEntry = makeTargetEntry((Expr *) addFields, 1, "document", false); lookupQuery->targetList = list_make1(topTargetEntry); pfree(parseState); /* TODO: is this needed? */ context->requiresSubQuery = true; return lookupQuery; } /* * Validate that for Sharded collections, we track that lookup wtih Let * Doesn't have nested lookup due to citus limitations. */ static void ValidatePipelineForShardedLookupWithLet(const bson_value_t *pipeline) { if (pipeline->value_type != BSON_TYPE_ARRAY) { return; } bson_iter_t pipelineIter; BsonValueInitIterator(pipeline, &pipelineIter); while (bson_iter_next(&pipelineIter)) { if (!BSON_ITER_HOLDS_DOCUMENT(&pipelineIter)) { return; } pgbsonelement element = { 0 }; if (!TryGetBsonValueToPgbsonElement(bson_iter_value(&pipelineIter), &element)) { return; } if (strcmp(element.path, "$lookup") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Nested lookup with let on sharded collections not supported yet"))); } if (strcmp(element.path, "$facet") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Nested facet with let on sharded collections not supported yet"))); } } } /* * Helper for a nested $lookup stage on whether it can be inlined for a $lookup. * This is valid as long as the lookupAs does not intersect with the local field. */ bool CanInlineLookupStageLookup(const bson_value_t *lookupStage, const StringView *lookupPath, bool hasLet) { if (hasLet) { return false; } /* A lookup can be inlined if */ LookupArgs nestedLookupArgs; memset(&nestedLookupArgs, 0, sizeof(LookupArgs)); ParseLookupStage(lookupStage, &nestedLookupArgs); if (StringViewStartsWithStringView(&nestedLookupArgs.lookupAs, lookupPath) || StringViewStartsWithStringView(lookupPath, &nestedLookupArgs.lookupAs)) { return false; } return true; } /* * Validates the pipeline for a $unionwith query. */ static void ValidateUnionWithPipeline(const bson_value_t *pipeline, bool hasCollection) { bson_iter_t pipelineIter; BsonValueInitIterator(pipeline, &pipelineIter); if (IsBsonValueEmptyArray(pipeline) && !hasCollection) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage."))); } bool isFirstStage = true; while (bson_iter_next(&pipelineIter)) { pgbsonelement stageElement = GetPipelineStage(&pipelineIter, "unionWith", "pipeline"); if (isFirstStage && !hasCollection) { if (strcmp(stageElement.path, "$documents") != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "A $unionWith stage without specifying a target collection must begin its pipeline with a $documents stage."))); } } isFirstStage = false; if (strcmp(stageElement.path, "$out") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31441), errmsg( "$out is prohibited inside a sub-pipeline of $unionWith"))); } else if (strcmp(stageElement.path, "$merge") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31441), errmsg( "Using the $merge is prohibited inside a sub-pipeline of $unionWith."))); } else if (strcmp(stageElement.path, "$changeStream") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31441), errmsg( "The use of $changeStream is prohibited inside the sub-pipeline of $unionWith."))); } } } /* * Parses & validates the input $graphLookup spec. * Parsed outputs are placed in the GraphLookupArgs struct. */ static void ParseGraphLookupStage(const bson_value_t *existingValue, GraphLookupArgs *args) { if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The $graphLookup stage specification is expected to be provided as an object, however, the system encountered %s instead.", BsonTypeName(existingValue->value_type)), errdetail_log( "The $graphLookup stage specification is expected to be provided as an object, however, the system encountered %s instead.", BsonTypeName(existingValue->value_type)))); } bson_iter_t lookupIter; BsonValueInitIterator(existingValue, &lookupIter); args->maxDepth = INT32_MAX; bool fromSpecified = false; while (bson_iter_next(&lookupIter)) { const char *key = bson_iter_key(&lookupIter); const bson_value_t *value = bson_iter_value(&lookupIter); if (strcmp(key, "as") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40103), errmsg( "graphlookup argument 'as' must be a string, is type %s", BsonTypeName(value->value_type)), errdetail_log( "graphlookup argument 'as' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->asField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; if (args->asField.length > 0 && args->asField.string[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "'as' field name cannot begin with '$'"), errdetail_log( "'as' field name cannot begin with '$'"))); } } else if (strcmp(key, "startWith") == 0) { args->inputExpression = *value; } else if (strcmp(key, "connectFromField") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40103), errmsg( "graphlookup argument 'connectFromField' must be a string, is type %s", BsonTypeName(value->value_type)), errdetail_log( "graphlookup argument 'connectFromField' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->connectFromField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; if (args->connectFromField.length > 0 && args->connectFromField.string[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "FieldPath field names cannot begin with symbol such as '$'"), errdetail_log( "FieldPath field names cannot begin with symbol such as '$'"))); } } else if (strcmp(key, "connectToField") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40103), errmsg( "graphlookup argument 'connectToField' must be a string, is type %s", BsonTypeName(value->value_type)), errdetail_log( "graphlookup argument 'connectToField' must be a string, is type %s", BsonTypeName(value->value_type)))); } args->connectToField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; if (args->connectToField.length > 0 && args->connectToField.string[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "connectToField: FieldPath field names cannot begin with the symbol '$'"), errdetail_log( "connectToField: FieldPath field names cannot begin with the symbol '$'"))); } } else if (strcmp(key, "from") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "graphlookup 'from' parameter must be provided as a string, but a value of type %s was given instead.", BsonTypeName(value->value_type)), errdetail_log( "graphlookup 'from' parameter must be provided as a string, but a value of type %s was given instead.", BsonTypeName(value->value_type)))); } args->fromCollection = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; fromSpecified = true; } else if (strcmp(key, "maxDepth") == 0) { if (!BsonValueIsNumber(value)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40100), errmsg( "The 'maxDepth' argument in graphlookup must be specified as a numeric value, but a value of type %s was provided instead.", BsonTypeName(value->value_type)), errdetail_log( "The 'maxDepth' argument in graphlookup must be specified as a numeric value, but a value of type %s was provided instead.", BsonTypeName(value->value_type)))); } if (!IsBsonValueFixedInteger(value)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40102), errmsg( "The value of graphlookup.maxDepth must always be a non‑negative integer number."), errdetail_log( "The value of graphlookup.maxDepth must always be a non‑negative integer number."))); } args->maxDepth = BsonValueAsInt32(value); if (args->maxDepth < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40101), errmsg( "The value of graphlookup.maxDepth must always be a non‑negative integer number."), errdetail_log( "The value of graphlookup.maxDepth must always be a non‑negative integer number."))); } } else if (strcmp(key, "depthField") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40103), errmsg( "The 'depthField' argument in graphlookup must be provided as a string, but a value of type %s was given instead.", BsonTypeName(value->value_type)), errdetail_log( "The 'depthField' argument in graphlookup must be provided as a string, but a value of type %s was given instead.", BsonTypeName(value->value_type)))); } args->depthField = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; if (args->depthField.length > 0 && args->depthField.string[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "depthField:FieldPath field names cannot begin with the symbol '$'"), errdetail_log( "depthField:FieldPath field names cannot begin with the symbol '$'"))); } } else if (strcmp(key, "restrictSearchWithMatch") == 0) { if (value->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40185), errmsg( "The 'restrictSearchWithMatch' argument in graphlookup must be provided as a document, but a value of type %s was received instead.", BsonTypeName(value->value_type)))); } args->restrictSearch = *value; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40104), errmsg( "Unrecognized parameter supplied to stage $graphlookup: %s", key), errdetail_log( "Unrecognized parameter supplied to stage $graphlookup: %s", key))); } } if (args->asField.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40105), errmsg("$graphLookup requires 'as' field to be specified"))); } if (!fromSpecified) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("$graphLookup requires 'from' field to be specified"))); } if (args->fromCollection.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("$graphLookup requires 'from' field to be specified"))); } if (args->inputExpression.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40105), errmsg( "You must provide a 'startWith' parameter when performing a $graphLookup operation"))); } if (args->connectFromField.length == 0 || args->connectToField.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40105), errmsg( "Both 'connectFrom' and 'connectTo' operators must be provided for a $graphLookup operation."))); } StringInfo connectExpr = makeStringInfo(); appendStringInfo(connectExpr, "$%.*s", args->connectFromField.length, args->connectFromField.string); args->connectFromFieldExpression.value_type = BSON_TYPE_UTF8; args->connectFromFieldExpression.value.v_utf8.len = strlen(connectExpr->data); args->connectFromFieldExpression.value.v_utf8.str = connectExpr->data; } /* * Builds the graph lookup FuncExpr bson_expression_get(document, '{ "connectToField": { "$makeArray": "$inputExpression" } }' ) * or bson_expression_get(document, '{ "connectToField": { "$makeArray": "$inputExpression" } }', collationString ), * if a valid collation string is provided. */ static FuncExpr * BuildInputExpressionForQuery(Expr *origExpr, const StringView *connectToField, const bson_value_t *inputExpression, AggregationPipelineBuildContext *context) { pgbson_writer expressionWriter; PgbsonWriterInit(&expressionWriter); pgbson_writer makeArrayWriter; PgbsonWriterStartDocument(&expressionWriter, connectToField->string, connectToField->length, &makeArrayWriter); /* { "$makeArray: $inputExpression } */ PgbsonWriterAppendValue(&makeArrayWriter, "$makeArray", 10, inputExpression); PgbsonWriterEndDocument(&expressionWriter, &makeArrayWriter); pgbson *inputExpr = PgbsonWriterGetPgbson(&expressionWriter); Const *falseConst = (Const *) MakeBoolValueConst(false); List *inputExprArgs; Oid functionOid; Const *collationConst = IsCollationApplicable(context->collationString) ? MakeTextConst(context->collationString, strlen(context->collationString)) : NULL; if (collationConst) { functionOid = BsonExpressionGetWithLetAndCollationFunctionOid(); inputExprArgs = list_make5(origExpr, MakeBsonConst(inputExpr), falseConst, context->variableSpec ? context->variableSpec : (Expr *) makeNullConst(BsonTypeId(), -1, InvalidOid), collationConst); } else if (context->variableSpec != NULL) { functionOid = BsonExpressionGetWithLetFunctionOid(); inputExprArgs = list_make4(origExpr, MakeBsonConst(inputExpr), falseConst, context->variableSpec); } else { functionOid = BsonExpressionGetFunctionOid(); inputExprArgs = list_make3(origExpr, MakeBsonConst(inputExpr), falseConst); } FuncExpr *inputFuncExpr = makeFuncExpr( functionOid, BsonTypeId(), inputExprArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); return inputFuncExpr; } /* * Adds input expression query to the input query projection list. This is the expression * for the inputExpression for the Graph lookup * bson_expression_get(document, '{ "connectToField": "$inputExpression" } ) AS "inputExpr" * or * bson_expression_get(document, '{ "connectToField": "$inputExpression" }', collationString ) * AS "inputExpr", * if a collation string is provided. */ static AttrNumber AddInputExpressionToQuery(Query *query, StringView *fieldName, const bson_value_t *inputExpression, AggregationPipelineBuildContext *context) { /* Now, add the expression value projector to the left query */ TargetEntry *origEntry = linitial(query->targetList); /* * Adds the projector bson_expression_get(document, '{ "connectToField": { "$makeArray": "$inputExpression" } }' ) * AS "inputExpr" into the left query. */ FuncExpr *inputFuncExpr = BuildInputExpressionForQuery(origEntry->expr, fieldName, inputExpression, context); bool resjunk = false; AttrNumber expressionResultNumber = 2; TargetEntry *entry = makeTargetEntry((Expr *) inputFuncExpr, expressionResultNumber, "inputExpr", resjunk); query->targetList = lappend(query->targetList, entry); return expressionResultNumber; } /* * Core handling for a graph lookup query. * This forms the query as follows: * * WITH basecte AS ( * SELECT * document, * bson_expression_get( * document, * '{ "*connectToField*": { "$makeArray": "$*inputExpression*" } }', * true * ) AS initialexpr * FROM inputCollection * ), * graphLookupStage AS ( * SELECT * document, * COALESCE( * ( * WITH RECURSIVE graphLookup AS ( * * -- anchor member * SELECT * coll.document AS doc, * '{ "depth": 0 }' as depth, * bson_expression_get(coll.document, '{ "_id": "$_id" }') as baseDocId * FROM *fromCollection* coll * WHERE bson_dollar_in(coll.document, basecte.initialexpr) * * UNION ALL * * -- recursive term * SELECT * document AS doc, * bson_expression_get(graphLookup.depth, '{ "depth": { "$add": [ "$depth", 1 ] }})') as depth, * bson_expression_get(coll.document, '{ "_id": "$_id" }') as baseDocId * FROM *fromCollection*, graphLookup -- join the recursive cte with the target collection * WHERE bson_dollar_in(document, bson_expression_get(graphLookup.doc, '{ "*connectToField*": { "$makeArray": "$*connectFromField*" } }', true)) * ) CYCLE baseDocId SET is_cycle USING path * SELECT bson_array_agg(doc, '*as*') FROM (SELECT DISTINCT ON (graphLookupStage.baseDocId) graphLookupStage.document FROM graphLookup ORDER BY depth) * ), * '{ "*as*": [] }' * ) AS addFields * FROM basecte * ) * * SELECT bson_dollar_add_fields(document, addFields) FROM graphLookupStage; * */ static Query * ProcessGraphLookupCore(Query *query, AggregationPipelineBuildContext *context, GraphLookupArgs *lookupArgs) { /* Similar to $lookup, if there's more than 1 projector push down */ if (list_length(query->targetList) > 1) { query = MigrateQueryToSubQuery(query, context); } /* First add the input expression to the input query */ AddInputExpressionToQuery(query, &lookupArgs->connectToField, &lookupArgs->inputExpression, context); /* Create the final query: Since the higher query is in a CTE - push this one down. */ context->numNestedLevels++; Query *graphLookupQuery = makeNode(Query); graphLookupQuery->commandType = CMD_SELECT; graphLookupQuery->querySource = query->querySource; graphLookupQuery->canSetTag = true; /* Push the input query a base CTE list */ StringInfo cteStr = makeStringInfo(); appendStringInfo(cteStr, "graphLookupBase_%d", context->nestedPipelineLevel); CommonTableExpr *baseCteExpr = makeNode(CommonTableExpr); baseCteExpr->ctename = cteStr->data; baseCteExpr->ctequery = (Node *) query; graphLookupQuery->cteList = lappend(graphLookupQuery->cteList, baseCteExpr); /* Create a graphLookupStage CTE */ StringInfo secondCteStr = makeStringInfo(); appendStringInfo(secondCteStr, "graphLookupStage_%d", context->nestedPipelineLevel); CommonTableExpr *graphCteExpr = makeNode(CommonTableExpr); graphCteExpr->ctename = secondCteStr->data; graphCteExpr->ctequery = (Node *) BuildGraphLookupCteQuery(query->querySource, baseCteExpr, lookupArgs, context); graphLookupQuery->cteList = lappend(graphLookupQuery->cteList, graphCteExpr); /* Make the graphLookupStage the RTE of the final query */ int stageNum = 1; RangeTblEntry *graphLookupStageRte = CreateCteRte(graphCteExpr, "graphLookup", stageNum, 0); graphLookupQuery->rtable = list_make1(graphLookupStageRte); RangeTblRef *graphLookupRef = makeNode(RangeTblRef); graphLookupRef->rtindex = 1; graphLookupQuery->jointree = makeFromExpr(list_make1(graphLookupRef), NULL); /* Add the add_fields on the targetEntry * SELECT bson_dollar_add_fields(document, addFields) FROM graphLookupStage; */ Var *documentVar = makeVar(graphLookupRef->rtindex, 1, BsonTypeId(), -1, InvalidOid, 0); Var *addFieldsVar = makeVar(graphLookupRef->rtindex, 2, BsonTypeId(), -1, InvalidOid, 0); /* $graphlookup override nested array in merge projections */ bool overrideArrayInProjection = true; FuncExpr *addFieldsExpr = makeFuncExpr( BsonDollaMergeDocumentsFunctionOid(), BsonTypeId(), list_make3(documentVar, addFieldsVar, MakeBoolValueConst(overrideArrayInProjection)), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *finalTargetEntry = makeTargetEntry((Expr *) addFieldsExpr, 1, "document", false); graphLookupQuery->targetList = list_make1(finalTargetEntry); return graphLookupQuery; } /* * This builds the the caller of the recursive CTE for a graphLookup * For the structure of this query, see ProcessGraphLookupCore */ static Query * BuildGraphLookupCteQuery(QuerySource parentSource, CommonTableExpr *baseCteExpr, GraphLookupArgs *args, AggregationPipelineBuildContext *parentContext) { Query *graphLookupQuery = makeNode(Query); graphLookupQuery->commandType = CMD_SELECT; graphLookupQuery->querySource = parentSource; graphLookupQuery->canSetTag = true; /* The base RTE is the base query */ /* This is now the SELECT ... FROM baseCte */ int stageNum = 1; int levelsUp = 1; RangeTblEntry *graphLookupStageRte = CreateCteRte(baseCteExpr, "graphLookupBase", stageNum, levelsUp); graphLookupQuery->rtable = list_make1(graphLookupStageRte); RangeTblRef *graphLookupRef = makeNode(RangeTblRef); graphLookupRef->rtindex = 1; graphLookupQuery->jointree = makeFromExpr(list_make1(graphLookupRef), NULL); /* The first projector is the document var from the CTE */ Var *firstVar = makeVar(graphLookupRef->rtindex, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *firstEntry = makeTargetEntry((Expr *) firstVar, 1, "document", false); /* The subquery for the recursive CTE goes here: * The CTE goes 2 levels up since it has to go through this graphLookupQuery (1) * to the parent query (2) */ int ctelevelsUp = 2; Query *recursiveSelectQuery = BuildRecursiveGraphLookupQuery(parentSource, args, parentContext, baseCteExpr, ctelevelsUp); SubLink *subLink = makeNode(SubLink); subLink->subLinkType = EXPR_SUBLINK; subLink->subLinkId = 0; subLink->subselect = (Node *) recursiveSelectQuery; graphLookupQuery->hasSubLinks = true; /* Coalesce to handle NULL entries */ /* COALESCE( recursiveQuery, '{ "*as*": [] }' ) */ Expr *coalesceExpr = GetArrayAggCoalesce((Expr *) subLink, args->asField.string, args->asField.length); TargetEntry *secondEntry = makeTargetEntry((Expr *) coalesceExpr, 2, "addFields", false); graphLookupQuery->targetList = list_make2(firstEntry, secondEntry); return graphLookupQuery; } /* * Creates an expression for bson_expression_get(document, '{ "_id": "$_id"}', true) */ static Expr * CreateIdProjectionExpr(Expr *baseExpr) { pgbsonelement expressionElement = { 0 }; expressionElement.path = "_id"; expressionElement.pathLength = 3; expressionElement.bsonValue.value_type = BSON_TYPE_UTF8; expressionElement.bsonValue.value.v_utf8.len = 4; expressionElement.bsonValue.value.v_utf8.str = "$_id"; return (Expr *) makeFuncExpr(BsonExpressionGetFunctionOid(), BsonTypeId(), list_make2(baseExpr, MakeBsonConst(PgbsonElementToPgbson( &expressionElement))), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } /* * This is the base case for the recursive CTE. This scans the from collection * with the equality match on the original table's rows. * SELECT * FROm from_collection WHERE document #= '{ "inputExpression" } */ static Query * GenerateBaseCaseQuery(AggregationPipelineBuildContext *parentContext, GraphLookupArgs *args, int baseCteLevelsUp) { AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = parentContext->nestedPipelineLevel + 2; subPipelineContext.databaseNameDatum = parentContext->databaseNameDatum; subPipelineContext.variableSpec = parentContext->variableSpec; strncpy((char *) subPipelineContext.collationString, parentContext->collationString, MAX_ICU_COLLATION_LENGTH); pg_uuid_t *collectionUuid = NULL; bson_value_t *indexHint = NULL; Query *baseCaseQuery = GenerateBaseTableQuery(parentContext->databaseNameDatum, &args->fromCollection, collectionUuid, indexHint, &subPipelineContext); /* Citus doesn't suppor this scenario: ERROR: recursive CTEs are not supported in distributed queries */ if (subPipelineContext.mongoCollection != NULL && subPipelineContext.mongoCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$graphLookup using 'from' on a sharded collection is currently unsupported"), errdetail_log( "$graphLookup using 'from' on a sharded collection is currently unsupported"))); } if (args->restrictSearch.value_type != BSON_TYPE_EOD) { baseCaseQuery = HandleMatch(&args->restrictSearch, baseCaseQuery, &subPipelineContext); if (baseCaseQuery->sortClause != NIL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5626500), errmsg( "$near, $nearSphere and $geoNear cannot be used here. Use $geoWithin instead."))); } } List *baseQuals = NIL; if (baseCaseQuery->jointree->quals != NULL) { baseQuals = make_ands_implicit((Expr *) baseCaseQuery->jointree->quals); } TargetEntry *firstEntry = linitial(baseCaseQuery->targetList); /* Match the Var of the top level input query: We're one level deeper (Since this is inside the SetOP) */ Var *rightVar = makeVar(1, 2, BsonTypeId(), -1, InvalidOid, baseCteLevelsUp); Const *textConst = MakeTextConst(args->connectToField.string, args->connectToField.length); FuncExpr *initialMatchFunc = makeFuncExpr(BsonDollarLookupJoinFilterFunctionOid(), BOOLOID, list_make3(firstEntry->expr, rightVar, textConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); baseQuals = lappend(baseQuals, initialMatchFunc); baseCaseQuery->jointree->quals = (Node *) make_ands_explicit(baseQuals); /* Add the depth field (base case is 0) */ pgbsonelement element = { .path = "depth", .pathLength = 5, .bsonValue = { .value_type = BSON_TYPE_INT32, .value.v_int32 = 0, .padding = 0 } }; if (args->depthField.length > 0) { element.path = args->depthField.string; element.pathLength = args->depthField.length; } Const *depthConst = MakeBsonConst(PgbsonElementToPgbson(&element)); baseCaseQuery->targetList = lappend(baseCaseQuery->targetList, makeTargetEntry((Expr *) depthConst, 2, "depth", false)); baseCaseQuery->targetList = lappend(baseCaseQuery->targetList, makeTargetEntry(CreateIdProjectionExpr( firstEntry->expr), 3, "baseDocId", false)); return baseCaseQuery; } /* * This is the recursive lookup case. This is equivalent to searching equality from the prior round * SELECT * FROm from_collection WHERE document #= '{ "previousFromExpr" } */ static Query * GenerateRecursiveCaseQuery(AggregationPipelineBuildContext *parentContext, CommonTableExpr *recursiveCte, GraphLookupArgs *args, int levelsUp) { AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = parentContext->nestedPipelineLevel + 2; subPipelineContext.databaseNameDatum = parentContext->databaseNameDatum; subPipelineContext.variableSpec = parentContext->variableSpec; strncpy((char *) subPipelineContext.collationString, parentContext->collationString, MAX_ICU_COLLATION_LENGTH); pg_uuid_t *collectionUuid = NULL; bson_value_t *indexHint = NULL; Query *recursiveQuery = GenerateBaseTableQuery(parentContext->databaseNameDatum, &args->fromCollection, collectionUuid, indexHint, &subPipelineContext); if (args->restrictSearch.value_type != BSON_TYPE_EOD) { recursiveQuery = HandleMatch(&args->restrictSearch, recursiveQuery, &subPipelineContext); if (recursiveQuery->sortClause != NIL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5626500), errmsg( "$near, $nearSphere and $geoNear cannot be used here. Use $geoWithin instead."))); } } List *baseQuals = NIL; if (recursiveQuery->jointree->quals != NULL) { baseQuals = make_ands_implicit((Expr *) recursiveQuery->jointree->quals); } RangeTblEntry *entry = CreateCteRte(recursiveCte, "lookupRecursive", 1, levelsUp); entry->self_reference = true; recursiveQuery->rtable = lappend(recursiveQuery->rtable, entry); RangeTblRef *rangeTblRef = makeNode(RangeTblRef); rangeTblRef->rtindex = 2; recursiveQuery->jointree->fromlist = lappend(recursiveQuery->jointree->fromlist, rangeTblRef); TargetEntry *firstEntry = linitial(recursiveQuery->targetList); /* Match the Var of the CTE level input query */ Var *leftDocVar = makeVar(rangeTblRef->rtindex, 1, BsonTypeId(), -1, InvalidOid, 0); FuncExpr *inputExpr = BuildInputExpressionForQuery((Expr *) leftDocVar, &args->connectToField, &args->connectFromFieldExpression, parentContext); Const *textConst = MakeTextConst(args->connectToField.string, args->connectToField.length); FuncExpr *initialMatchFunc = makeFuncExpr(BsonDollarLookupJoinFilterFunctionOid(), BOOLOID, list_make3(firstEntry->expr, inputExpr, textConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); baseQuals = lappend(baseQuals, initialMatchFunc); StringView depthPath = { .length = 5, .string = "depth" }; if (args->depthField.length > 0) { depthPath = args->depthField; } Var *priorDepthValue = makeVar(rangeTblRef->rtindex, 2, BsonTypeId(), -1, InvalidOid, 0); if (args->maxDepth >= 0 && args->maxDepth != INT32_MAX) { pgbsonelement depthQueryElement = { 0 }; depthQueryElement.path = depthPath.string; depthQueryElement.pathLength = depthPath.length; depthQueryElement.bsonValue.value_type = BSON_TYPE_INT32; depthQueryElement.bsonValue.value.v_int32 = args->maxDepth; Const *depthConst = MakeBsonConst(PgbsonElementToPgbson(&depthQueryElement)); depthConst->consttype = BsonQueryTypeId(); OpExpr *depthMatchFunc = (OpExpr *) make_opclause( BsonLessThanMatchRuntimeOperatorId(), BOOLOID, false, (Expr *) priorDepthValue, (Expr *) depthConst, InvalidOid, InvalidOid); depthMatchFunc->opfuncid = BsonLessThanMatchRuntimeFunctionId(); baseQuals = lappend(baseQuals, depthMatchFunc); } recursiveQuery->jointree->quals = (Node *) make_ands_explicit(baseQuals); /* Append the graph depth expression */ pgbson_writer depthFuncWriter; PgbsonWriterInit(&depthFuncWriter); pgbson_writer childWriter; PgbsonWriterStartDocument(&depthFuncWriter, depthPath.string, depthPath.length, &childWriter); pgbson_array_writer addWriter; PgbsonWriterStartArray(&childWriter, "$add", 4, &addWriter); PgbsonArrayWriterWriteUtf8(&addWriter, psprintf("$%.*s", depthPath.length, depthPath.string)); bson_value_t number1Value = { 0 }; number1Value.value_type = BSON_TYPE_INT32; number1Value.value.v_int32 = 1; PgbsonArrayWriterWriteValue(&addWriter, &number1Value); PgbsonWriterEndArray(&childWriter, &addWriter); PgbsonWriterEndDocument(&depthFuncWriter, &childWriter); Const *depthAddConst = MakeBsonConst(PgbsonWriterGetPgbson(&depthFuncWriter)); Expr *newDepthFuncExpr = (Expr *) makeFuncExpr(BsonDollarAddFieldsFunctionOid(), BsonTypeId(), list_make2(priorDepthValue, depthAddConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); recursiveQuery->targetList = lappend(recursiveQuery->targetList, makeTargetEntry(newDepthFuncExpr, 2, "depth", false)); recursiveQuery->targetList = lappend(recursiveQuery->targetList, makeTargetEntry(CreateIdProjectionExpr( firstEntry->expr), 3, "baseDocId", false)); return recursiveQuery; } /* * Walker to replace the recursive graph CTE post cycle rewrite. */ static bool RewriteGraphLookupRecursiveCteExprWalker(Node *node, CommonTableExpr *graphRecursiveCte) { CHECK_FOR_INTERRUPTS(); if (node == NULL) { return false; } if (IsA(node, Query)) { return query_tree_walker((Query *) node, RewriteGraphLookupRecursiveCteExprWalker, graphRecursiveCte, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY); } else if (IsA(node, RangeTblEntry)) { RangeTblEntry *tblEntry = (RangeTblEntry *) node; if (tblEntry->rtekind == RTE_CTE && strcmp(tblEntry->ctename, graphRecursiveCte->ctename) == 0) { UpdateCteRte(tblEntry, graphRecursiveCte); return true; } return false; } return false; } /* * This builds the core recursive CTE for a graphLookup * For the structure of this query, see ProcessGraphLookupCore */ static Query * BuildRecursiveGraphLookupQuery(QuerySource parentSource, GraphLookupArgs *args, AggregationPipelineBuildContext *parentContext, CommonTableExpr *baseCteExpr, int baseCteLevelsUp) { AggregationPipelineBuildContext subPipelineContext = { 0 }; subPipelineContext.nestedPipelineLevel = parentContext->nestedPipelineLevel + 1; subPipelineContext.databaseNameDatum = parentContext->databaseNameDatum; subPipelineContext.variableSpec = parentContext->variableSpec; strncpy((char *) subPipelineContext.collationString, parentContext->collationString, MAX_ICU_COLLATION_LENGTH); /* First build the recursive CTE object */ CommonTableExpr *graphCteExpr = makeNode(CommonTableExpr); graphCteExpr->ctename = "graphLookupRecurseStage"; graphCteExpr->cterecursive = true; /* Define the UNION ALL query step needed for the recursive CTE */ Query *unionAllQuery = makeNode(Query); unionAllQuery->commandType = CMD_SELECT; unionAllQuery->querySource = parentSource; unionAllQuery->canSetTag = true; unionAllQuery->jointree = makeFromExpr(NIL, NULL); /* We need to build the output of the UNION ALL first (since this is recursive )*/ /* The first var is the document */ Var *documentVar = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *docEntry = makeTargetEntry((Expr *) documentVar, 1, "document", false); /* Then comes the depth */ Var *depthVar = makeVar(1, 2, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *depthEntry = makeTargetEntry((Expr *) depthVar, 2, "depth", false); Var *baseVar = makeVar(1, 3, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *baseDocEntry = makeTargetEntry((Expr *) baseVar, 3, "baseDocId", false); List *unionTargetEntries = list_make3(docEntry, depthEntry, baseDocEntry); unionAllQuery->targetList = unionTargetEntries; graphCteExpr->ctequery = (Node *) unionAllQuery; CTECycleClause *cteCycleClause = makeNode(CTECycleClause); cteCycleClause->cycle_col_list = list_make1(makeString("baseDocId")); cteCycleClause->cycle_mark_collation = InvalidOid; cteCycleClause->cycle_mark_type = BOOLOID; cteCycleClause->cycle_mark_column = "is_cycle"; cteCycleClause->cycle_mark_default = MakeBoolValueConst(false); cteCycleClause->cycle_mark_value = MakeBoolValueConst(true); cteCycleClause->cycle_path_column = "path"; cteCycleClause->cycle_mark_typmod = -1; cteCycleClause->cycle_mark_neop = BooleanNotEqualOperator; graphCteExpr->cycle_clause = cteCycleClause; ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = 1; /* Build the base case query (non recursive entry)*/ /* CTE will move up 1 level because of the subquery after the group below. */ baseCteLevelsUp += 2; Query *baseSubQuery = GenerateBaseCaseQuery(parentContext, args, baseCteLevelsUp); /* Build the recursive case query: Not ethe actual graph CTE is 2 levels up: * One to get to the SetOpStatement query * Two to get to the parent GraphLookup query. */ int graphCteLevelsUp = 2; Query *recursiveSubQuery = GenerateRecursiveCaseQuery(parentContext, graphCteExpr, args, graphCteLevelsUp); /* To create a UNION ALL we need the left and right to be subquery RTEs */ bool includeAllColumns = true; int depth = 2; RangeTblEntry *baseQuery = MakeSubQueryRte(baseSubQuery, 1, depth, "baseQuery", includeAllColumns); baseQuery->inFromCl = false; RangeTblEntry *recursiveQuery = MakeSubQueryRte(recursiveSubQuery, 2, depth, "recursiveQuery", includeAllColumns); recursiveQuery->inFromCl = false; unionAllQuery->rtable = list_make2(baseQuery, recursiveQuery); RangeTblRef *baseReference = makeNode(RangeTblRef); baseReference->rtindex = 1; RangeTblRef *recursiveReference = makeNode(RangeTblRef); recursiveReference->rtindex = 2; /* For deduplication of _id, we use DISTINCT ON by _id. * This is more efficient for PostgreSQL scenarios. */ SetOperationStmt *setOpStatement = makeNode(SetOperationStmt); setOpStatement->all = true; setOpStatement->op = SETOP_UNION; setOpStatement->larg = (Node *) baseReference; setOpStatement->rarg = (Node *) recursiveReference; setOpStatement->colCollations = list_make3_oid(InvalidOid, InvalidOid, InvalidOid); setOpStatement->colTypes = list_make3_oid(BsonTypeId(), BsonTypeId(), BsonTypeId()); setOpStatement->colTypmods = list_make3_int(-1, -1, -1); graphCteExpr->ctecolnames = list_make3(makeString("document"), makeString("depth"), makeString("baseDocId")); graphCteExpr->ctecoltypes = setOpStatement->colTypes; graphCteExpr->ctecoltypmods = setOpStatement->colTypmods; graphCteExpr->ctecolcollations = setOpStatement->colCollations; /* Update the query with the SetOp statement */ unionAllQuery->setOperations = (Node *) setOpStatement; /* Now that the unionAllQuery is built, call the rewrite handler */ graphCteExpr = rewriteSearchAndCycle(graphCteExpr); /* Reset cycle path after rewrite */ graphCteExpr->cycle_clause = NULL; query_tree_walker((Query *) graphCteExpr->ctequery, RewriteGraphLookupRecursiveCteExprWalker, graphCteExpr, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY); /* Now form the top level Graph Lookup Recursive Query entry */ Query *graphLookupQuery = makeNode(Query); graphLookupQuery->commandType = CMD_SELECT; graphLookupQuery->querySource = parentSource; graphLookupQuery->canSetTag = true; /* WITH RECURSIVE */ graphLookupQuery->hasRecursive = true; graphLookupQuery->cteList = lappend(graphLookupQuery->cteList, graphCteExpr); /* Next build the RangeTables */ RangeTblEntry *rte = CreateCteRte(graphCteExpr, "graphLookup", 2, 0); graphLookupQuery->rtable = list_make1(rte); /* Next build the FromList for the final query */ RangeTblRef *singleRangeTableRef = makeNode(RangeTblRef); singleRangeTableRef->rtindex = 1; graphLookupQuery->jointree = makeFromExpr(list_make1(singleRangeTableRef), NULL); /* Build the final targetList: */ /* SELECT bson_array_agg(doc, 'asField') FROM graphLookup */ /* Build a base targetEntry that the arrayAgg will use */ Var *simpleVar = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *simpleTargetEntry = makeTargetEntry((Expr *) simpleVar, 1, "document", false); Var *distinctVar = makeVar(1, 3, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *distinctEntry = makeTargetEntry((Expr *) distinctVar, 2, "distinctOn", true); distinctEntry->ressortgroupref = 1; Var *finalDepthVar = makeVar(1, 2, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *finalDepthEntry = makeTargetEntry((Expr *) finalDepthVar, 3, "depthVar", true); finalDepthEntry->ressortgroupref = 2; /* If a depthField is specified, merge the depth value into the document. */ if (args->depthField.length > 0) { bool overrideArray = true; simpleTargetEntry->expr = (Expr *) makeFuncExpr( BsonDollaMergeDocumentsFunctionOid(), BsonTypeId(), list_make3(simpleVar, finalDepthVar, MakeBoolValueConst(overrideArray)), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } Assert(list_length(graphCteExpr->ctecoltypes) == 5); graphLookupQuery->targetList = list_make3(simpleTargetEntry, distinctEntry, finalDepthEntry); /* Add Distinct ON */ SortGroupClause *distinctonSortGroup = makeNode(SortGroupClause); distinctonSortGroup->eqop = BsonEqualOperatorId(); distinctonSortGroup->sortop = BsonLessThanOperatorId(); distinctonSortGroup->hashable = false; distinctonSortGroup->tleSortGroupRef = 1; graphLookupQuery->distinctClause = list_make1(distinctonSortGroup); graphLookupQuery->hasDistinctOn = true; /* Add a sort */ SortGroupClause *sortOnDepthGroup = makeNode(SortGroupClause); sortOnDepthGroup->eqop = BsonEqualOperatorId(); sortOnDepthGroup->sortop = BsonLessThanOperatorId(); sortOnDepthGroup->hashable = false; sortOnDepthGroup->tleSortGroupRef = 2; graphLookupQuery->sortClause = list_make2(distinctonSortGroup, sortOnDepthGroup); /* Add the bson_array_agg */ bool migrateToSubQuery = true; Aggref *arrayAggRef = NULL; graphLookupQuery = AddBsonArrayAggFunction(graphLookupQuery, &subPipelineContext, parseState, args->asField.string, args->asField.length, migrateToSubQuery, &arrayAggRef); pfree(parseState); return graphLookupQuery; } static Query * HandleLookupCore(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, LookupContext *lookupContext) { LookupArgs lookupArgs; memset(&lookupArgs, 0, sizeof(LookupArgs)); if (context->nestedPipelineLevel >= MaximumLookupPipelineDepth) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_MAXSUBPIPELINEDEPTHEXCEEDED), errmsg( "The allowed limit for nested sub-pipelines has been surpassed, exceeding the maximum of %d.", MaximumLookupPipelineDepth))); } ParseLookupStage(existingValue, &lookupArgs); /* Now build the base query for the lookup */ return ProcessLookupCoreWithLet(query, context, &lookupArgs, lookupContext); } static Node * ReplaceVariablesWithLevelsUpMutator(Node *node, LevelsUpQueryTreeWalkerState *state) { CHECK_FOR_INTERRUPTS(); if (node == NULL) { return NULL; } if (IsA(node, Query)) { state->numLevels++; Query *result = query_tree_mutator((Query *) node, ReplaceVariablesWithLevelsUpMutator, state, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY | QTW_EXAMINE_SORTGROUP); state->numLevels--; return (Node *) result; } else if (IsA(node, Var)) { Var *originalVar = (Var *) node; /* * If the location of the VAR >= NESTED_PIPELINE_VAR_FLAG, then this means this VAR needs varlevelsup adjustment */ if (originalVar->location >= NESTED_PIPELINE_VAR_FLAG && equal(node, state->originalVariable)) { Var *copyVar = copyObject(originalVar); copyVar->varlevelsup = state->numLevels; copyVar->location = -1; return (Node *) copyVar; } } return expression_tree_mutator(node, ReplaceVariablesWithLevelsUpMutator, state); } static void WalkQueryAndSetLevelsUp(Query *rightQuery, Var *varToCheck, int varLevelsUpBase) { LevelsUpQueryTreeWalkerState state = { 0 }; state.numLevels = varLevelsUpBase; state.originalVariable = varToCheck; query_tree_mutator((Query *) rightQuery, ReplaceVariablesWithLevelsUpMutator, &state, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY | QTW_EXAMINE_SORTGROUP); } static bool RangeTblEntryLevelsUpWalker(Node *expr, LevelsUpQueryTreeWalkerState *walkerState) { if (expr == NULL) { return false; } if (IsA(expr, Query)) { walkerState->numLevels++; query_tree_walker((Query *) expr, RangeTblEntryLevelsUpWalker, walkerState, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY); walkerState->numLevels--; return false; } else if (IsA(expr, RangeTblEntry)) { RangeTblEntry *tblEntry = (RangeTblEntry *) expr; if (tblEntry->rtekind == RTE_CTE && strcmp(tblEntry->ctename, walkerState->cteName) == 0) { tblEntry->ctelevelsup = walkerState->numLevels; } return false; } return expression_tree_walker(expr, RangeTblEntryLevelsUpWalker, walkerState); } static void WalkQueryAndSetCteLevelsUp(Query *rightQuery, const char *cteName, int varLevelsUpBase) { LevelsUpQueryTreeWalkerState state = { 0 }; state.numLevels = varLevelsUpBase; state.cteName = cteName; query_tree_walker((Query *) rightQuery, RangeTblEntryLevelsUpWalker, &state, QTW_EXAMINE_RTES_BEFORE | QTW_DONT_COPY_QUERY); } /* Function that is passed down to the expression tree when a let expression is found under a lookup to validate no variables are used to define other variables, * We only do this if it is the first level let on lookup. */ static void ValidateLetHasNoVariables(AggregationExpressionData *parsedExpression) { /* Only variables are disallowed in the variable spec, system variables are valid and should be considered at runtime * if it is available or not, i.e SEARCH_META is only available if a $search stage was defined. */ if (parsedExpression->kind == AggregationExpressionKind_Variable) { const char *nameWithoutPrefix = parsedExpression->value.value.v_utf8.str + 2; ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION17276), errmsg("Attempting to use an undefined variable: %s", nameWithoutPrefix))); } } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_output_pipeline.c000066400000000000000000002304021507310017400306530ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/planner/bson_aggregation_output_pipeline.c * * Implementation of the backend query generation for output pipelines that have (such as $out, $merge). * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "query/query_operator.h" #include "query/bson_compare.h" #include "planner/documentdb_planner.h" #include "aggregation/bson_aggregation_pipeline.h" #include "commands/insert.h" #include "commands/parse_error.h" #include "commands/commands_common.h" #include "utils/feature_counter.h" #include "operators/bson_expression.h" #include "metadata/index.h" #include "utils/hashset_utils.h" #include "aggregation/bson_tree.h" #include "aggregation/bson_tree_write.h" #include "optimizer/optimizer.h" #include "utils/query_utils.h" #include "utils/fmgr_utils.h" #include "schema_validation/schema_validation.h" #include "aggregation/bson_aggregation_pipeline_private.h" /* * $merge stage input field `WhenMatched` options */ typedef enum WhenMatchedAction { WhenMatched_MERGE = 0, WhenMatched_REPLACE = 1, WhenMatched_KEEPEXISTING = 2, WhenMatched_FAIL = 3, WhenMatched_PIPELINE = 4, WhenMatched_LET = 5 } WhenMatchedAction; /* * $merge stage input field `WhenNotMatched` options */ typedef enum WhenNotMatchedAction { WhenNotMatched_INSERT = 0, WhenNotMatched_DISCARD = 1, WhenNotMatched_FAIL = 2, } WhenNotMatchedAction; /* * Struct having parsed view of the * arguments to $merge stage. */ typedef struct MergeArgs { /* name of input target Databse */ StringView targetDB; /* name to the specified input target collection */ StringView targetCollection; /* input `on` field can be an array or string */ bson_value_t on; /* input `whenMatched` field */ WhenMatchedAction whenMatched; /* input `whenNotMatched` field */ WhenNotMatchedAction whenNotMatched; } MergeArgs; /* * Struct having parsed view of the arguments to $out stage. */ typedef struct OutArgs { /* name of input target Databse */ StringView targetDB; /* name to the specified input target collection */ StringView targetCollection; } OutArgs; /* GUC to enable $out aggregation stage */ extern bool EnableCollation; /* GUC to enable schema validation */ extern bool EnableSchemaValidation; static void ParseMergeStage(const bson_value_t *existingValue, const char *currentNameSpace, MergeArgs *args); static void ParseOutStage(const bson_value_t *existingValue, const char *currentNameSpace, OutArgs *args); static void VaildateMergeOnFieldValues(const bson_value_t *onArray, uint64 collectionId); static void RearrangeTargetListForMerge(Query *query, MongoCollection *targetCollection, bool isSourceAndTargetAreSame, const bson_value_t *onFields); static void WriteJoinConditionToQueryDollarMerge(Query *query, Var *sourceDocVar, Var *targetDocVar, Var *sourceShardKeyValueVar, Var *targetShardKeyValueVar, Var *targetObjectIdVar, const int sourceExtractedOnFieldsInitIndex, const int sourceCollectionVarNo, MergeArgs mergeArgs); static MergeAction * MakeActionWhenMatched(WhenMatchedAction whenMatched, Var *sourceDocVar, Var *targetDocVar, Const *schemaValidatorInfoConst, Const *validationLevelConst); static MergeAction * MakeActionWhenNotMatched(WhenNotMatchedAction whenNotMatched, Var *sourceDocVar, Var *generatedObjectIdVar, Var *sourceShardKeyVar, MongoCollection *targetCollection, Const *SchemaValidatorInfoConst); static bool IsCompoundUniqueIndexPresent(const bson_value_t *onValues, bson_iter_t *indexKeyDocumentIter, const int numElementsInMap); static void ValidateAndAddObjectIdToWriter(pgbson_writer *writer, pgbson *sourceDocument, pgbson *targetDocument); static inline bool IsSingleUniqueIndexPresent(const char *onValue, bson_iter_t *indexKeyDocumentIter); static inline void AddTargetCollectionRTEDollarMerge(Query *query, MongoCollection *targetCollection); static HTAB * InitHashTableFromStringArray(const bson_value_t *onValues, int onValuesArraySize); static inline void ValidatePreOutputStages(Query *query, char *stageName); static bool MergeQueryCTEWalker(Node *node, void *context); static inline void ValidateFinalPgbsonBeforeWriting(const pgbson *finalBson, const pgbson *targetDocument, ExprEvalState * stateForSchemaValidation, ValidationLevels validationLevel); static inline Expr * CreateSingleJoinExpr(const char *joinField, Var *sourceDocVar, Var *targetDocVar, Var *targetObjectIdVar, const int extractFieldResNumber, const int sourceCollectionVarNo); static inline TargetEntry * MakeExtractFuncExprForMergeTE(const char *onField, uint32 length, Var *sourceDocument, const int resNum); static void TruncateDataTable(int collectionId); static inline bool CheckSchemaValidationEnabledForDollarMergeOut(void); static inline void ValidateTargetNameSpaceForOutputStage(const StringView *targetDB, const StringView * targetCollection, bool isMergeStage); PG_FUNCTION_INFO_V1(bson_dollar_merge_handle_when_matched); PG_FUNCTION_INFO_V1(bson_dollar_merge_add_object_id); PG_FUNCTION_INFO_V1(bson_dollar_merge_fail_when_not_matched); PG_FUNCTION_INFO_V1(bson_dollar_merge_generate_object_id); PG_FUNCTION_INFO_V1(bson_dollar_extract_merge_filter); /* * This function extracts merge filter from source document to match against target document. */ Datum bson_dollar_extract_merge_filter(PG_FUNCTION_ARGS) { pgbson *sourceDocument = PG_GETARG_PGBSON_PACKED(0); char *joinField = text_to_cstring(PG_GETARG_TEXT_P(1)); bson_iter_t sourceIter; if (!PgbsonInitIteratorAtPath(sourceDocument, joinField, &sourceIter)) { /* If the source lacks an object ID, we return false and generate a new one during the document's insertion into the target. */ /* when it come's to join filter for _id field we create target.objectid = bson_get_value(agg_stage_1.document, '_id'::text)*/ if (strcmp(joinField, "_id") == 0) { PG_RETURN_NULL(); } ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51132), errmsg( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"), errdetail_log( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"))); } pgbsonelement filterElement; filterElement.path = joinField; filterElement.pathLength = strlen(joinField); filterElement.bsonValue = *bson_iter_value(&sourceIter); if (filterElement.bsonValue.value_type == BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51185), errmsg( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"), errdetail_log( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"))); } else if (filterElement.bsonValue.value_type == BSON_TYPE_NULL || filterElement.bsonValue.value_type == BSON_TYPE_UNDEFINED) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51132), errmsg( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"), errdetail_log( "Write operation for $merge failed: the 'on' field must be provided and cannot be null, undefined, or an array"))); } PG_RETURN_POINTER(PgbsonElementToPgbson(&filterElement)); } /* * In the `$merge` stage, this function is utilized to add the '_id' field to the source document if it is missing. * Stages such as $project have the potential to eliminate the _id field, which is essential for inserting into the target collection. */ Datum bson_dollar_merge_add_object_id(PG_FUNCTION_ARGS) { pgbson *sourceDocument = PG_GETARG_PGBSON_PACKED(0); pgbson *generatedObjectID = PG_GETARG_PGBSON(1); /* If evalStateBytea is not NULL, we need to parse it to get the schema validation state. */ ExprEvalState *stateForSchemaValidation = NULL; if (CheckSchemaValidationEnabledForDollarMergeOut() && PG_NARGS() > 2) { pgbson *schemaValidatorInfo = PG_GETARG_MAYBE_NULL_PGBSON(2); if (!IsPgbsonEmptyDocument(schemaValidatorInfo)) { int argPositions = 2; SetCachedFunctionState( stateForSchemaValidation, ExprEvalState, argPositions, AssignSchemaValidationState, schemaValidatorInfo, CurrentMemoryContext); if (stateForSchemaValidation == NULL) { stateForSchemaValidation = palloc0(sizeof(ExprEvalState)); AssignSchemaValidationState(stateForSchemaValidation, schemaValidatorInfo, CurrentMemoryContext); } } } /* Add and validate _id */ pgbson *outputBson = RewriteDocumentWithCustomObjectId(sourceDocument, generatedObjectID); ValidateFinalPgbsonBeforeWriting(outputBson, NULL, stateForSchemaValidation, ValidationLevel_Strict); /* Free only when outputBson is different from sourceDocument*/ if (sourceDocument != outputBson) { PG_FREE_IF_COPY(sourceDocument, 0); } PG_RETURN_POINTER(outputBson); } /* * In the `$merge` stage, this function is utilized to generate object id field. * we use generated object id in case source document does not have object id. */ Datum bson_dollar_merge_generate_object_id(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(PgbsonGenerateOidDocument()); } /* * In the `$merge` stage, this function is utilized to handle the `whenMatched` actions of the `$merge` stage. */ Datum bson_dollar_merge_handle_when_matched(PG_FUNCTION_ARGS) { pgbson *sourceDocument = PG_GETARG_PGBSON(0); pgbson *targetDocument = PG_GETARG_PGBSON(1); WhenMatchedAction action = PG_GETARG_INT32(2); pgbson *finalDocument = NULL; /* If evalStateBytea is not NULL, we need to parse it to get the schema validation state and set the validation level. */ ExprEvalState *stateForSchemaValidation = NULL; ValidationLevels validationLevel = ValidationLevel_Invalid; /* special case - Schema validation is not performed if the source document is the same as the target document. */ bool performSchemaValidation = false; bool needComparison = true; if (CheckSchemaValidationEnabledForDollarMergeOut() && PG_NARGS() > 3) { pgbson *schemaValidatorInfo = PG_GETARG_MAYBE_NULL_PGBSON(3); if (!IsPgbsonEmptyDocument(schemaValidatorInfo)) { performSchemaValidation = true; validationLevel = PG_ARGISNULL(4) ? ValidationLevel_Invalid : PG_GETARG_INT32( 4); } } switch (action) { case WhenMatched_REPLACE: { pgbson_writer writer; ValidateAndAddObjectIdToWriter(&writer, sourceDocument, targetDocument); bson_iter_t sourceDocumentIterator; PgbsonInitIterator(sourceDocument, &sourceDocumentIterator); while (bson_iter_next(&sourceDocumentIterator)) { const char *key = bson_iter_key(&sourceDocumentIterator); /* ensure we're not rewriting the _id to something else. */ if (strcmp(key, "_id") == 0) { continue; } uint32_t keyLength = bson_iter_key_len(&sourceDocumentIterator); PgbsonWriterAppendValue(&writer, key, keyLength, bson_iter_value( &sourceDocumentIterator)); } finalDocument = PgbsonWriterGetPgbson(&writer); break; } case WhenMatched_MERGE: { pgbson_writer writer; ValidateAndAddObjectIdToWriter(&writer, sourceDocument, targetDocument); bson_iter_t iter; PgbsonInitIterator(targetDocument, &iter); /* _id is already written to writer as first field of writer. so ignore for target document. */ if (!bson_iter_next(&iter) || strcmp(bson_iter_key(&iter), "_id") != 0) { /* In target document we expect _id to be first field. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "$merge write error: target document missing _id field as first field"), errdetail_log( "$merge write error: target document missing _id field as first field"))); } HTAB *hashTable = CreatePgbsonElementOrderedHashSet(); PgbsonElementHashEntryOrdered *head = NULL; PgbsonElementHashEntryOrdered *tail = NULL; /* step 1 : Add target document to the hashmap with values and maintain order using PgbsonElementHashEntryOrdered linked list */ while (bson_iter_next(&iter)) { pgbsonelement element = { .path = bson_iter_key(&iter), .pathLength = bson_iter_key_len(&iter), .bsonValue = *bson_iter_value(&iter) }; PgbsonElementHashEntryOrdered hashEntry = { .element = element, .next = NULL, }; bool found = false; PgbsonElementHashEntryOrdered *currNode = hash_search(hashTable, &hashEntry, HASH_ENTER, &found); if (head == NULL) { head = currNode; tail = currNode; } else { tail->next = currNode; tail = currNode; } } /* step 2 : let's add source document to hashmap with values and update the tail of the linked list if a new element is inserted */ PgbsonInitIterator(sourceDocument, &iter); while (bson_iter_next(&iter)) { /* _id is already written to writer as the first field, so ignore it here */ if (strcmp(bson_iter_key(&iter), "_id") == 0) { continue; } pgbsonelement element = { .path = bson_iter_key(&iter), .pathLength = bson_iter_key_len(&iter), .bsonValue = *bson_iter_value(&iter) }; PgbsonElementHashEntryOrdered hashEntry = { .element = element, .next = NULL, }; bool found = false; PgbsonElementHashEntryOrdered *currNode = hash_search(hashTable, &hashEntry, HASH_ENTER, &found); if (found) { /* Replace the existing value with the value from the source document */ currNode->element.bsonValue = element.bsonValue; } else if (head == NULL) { /* If the target document contains only the _id field, we reach here */ head = currNode; tail = currNode; needComparison = false; } else { tail->next = currNode; tail = currNode; needComparison = false; } } /* step 3: Iterate through the linked list to fetch elements in order and write them to the final BSON */ while (head != NULL) { PgbsonElementHashEntryOrdered *temp = head; PgbsonWriterAppendValue(&writer, temp->element.path, temp->element.pathLength, &temp->element.bsonValue); head = head->next; } hash_destroy(hashTable); finalDocument = PgbsonWriterGetPgbson(&writer); break; } case WhenMatched_KEEPEXISTING: { /* we are not suppose to reach here if action is `WhenMatched_KEEPEXISTING` we should set `DO NOTHING` Action of PG */ ereport(ERROR, errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), (errmsg( "whenMathed KeepEXISTING should not reach here"), errdetail_log( "whenMathed KeepEXISTING should not reach here"))); } case WhenMatched_FAIL: { /* * Compatibility Notice: The text in this error string is copied verbatim from MongoDB output to maintain * compatibility with existing tools and scripts that rely on specific error message formats. Modifying * this text may cause unexpected behavior in dependent systems. * * JsTest to resolve: mode_fail_insert.js */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_DUPLICATEKEY), errmsg( "$merge with whenMatched: fail found an existing document with the same values for the 'on' fields"), errdetail_log( "$merge with whenMatched: fail found an existing document with the same values for the 'on' fields"))); } case WhenMatched_PIPELINE: case WhenMatched_LET: { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "merge, pipeline and Let option not supported yet in whenMatched field of $merge aggreagtion stage"), errdetail_log( "merge, pipeline and Let option not supported yet in whenMatched field of $merge aggreagtion stage"))); } default: { ereport(ERROR, errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), (errmsg( "Unrecognized WhenMatched value"), errdetail_log( "Unrecognized WhenMatched value"))); } } /* needComparison = true means we need to compare source and target document to determine whether to skip schema validation or not. */ if (CheckSchemaValidationEnabledForDollarMergeOut()) { if (needComparison && performSchemaValidation) { performSchemaValidation = PgbsonEquals(sourceDocument, targetDocument) ? false : true; } if (performSchemaValidation) { pgbson *schemaValidatorInfo = PG_GETARG_PGBSON(3); int argPositions = 3; SetCachedFunctionState( stateForSchemaValidation, ExprEvalState, argPositions, AssignSchemaValidationState, schemaValidatorInfo, CurrentMemoryContext); if (stateForSchemaValidation == NULL) { stateForSchemaValidation = palloc0(sizeof(ExprEvalState)); AssignSchemaValidationState(stateForSchemaValidation, schemaValidatorInfo, CurrentMemoryContext); } } } /* let's validate final document before writing */ ValidateFinalPgbsonBeforeWriting(finalDocument, targetDocument, stateForSchemaValidation, validationLevel); PG_RETURN_POINTER(finalDocument); } /* * In the `$merge` stage, to handle `fail` action of `WhenNotMatched` case. * This function accepts dummy arguments and has return type to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely. */ Datum bson_dollar_merge_fail_when_not_matched(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_MERGESTAGENOMATCHINGDOCUMENT), errmsg( "$merge failed to locate a corresponding document in the target collection for one or more documents from the source collection"), errdetail_log( "$merge failed to locate a corresponding document in the target collection for one or more documents from the source collection"))); PG_RETURN_NULL(); } /* * Mutates the query for the $merge stage * * Example : { $merge: { into: <>, on: <>, whenMatched: <>, whenNotMatched: <> } } * target collection with schema validation `{ "a" : { "$type" : "int" } }` and validationLevel is `strict` * sql query : * * MERGE INTO ONLY ApiDataSchemaName.documents_2 documents_2 * USING ( * SELECT collection.document AS document, * '2'::bigint AS target_shard_key_value, -- (2 is collection_id of target collection) * bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id * FROM ApiDataSchemaName.documents_1 collection * WHERE collection.shard_key_value = '1'::bigint * ) agg_stage_0 * ON documents_2.shard_key_value OPERATOR(pg_catalog.=) agg_stage_0.target_shard_key_value * AND bson_dollar_merge_join(documents_2.document, agg_stage_0.document, '_id'::text) * WHEN MATCHED * THEN * UPDATE SET document = bson_dollar_merge_handle_when_matched(agg_stage_0.document, documents_2.document, 1, '{ "a" : { "$type" : "int" } }'::bson, 1) * WHEN NOT MATCHED * THEN * INSERT (shard_key_value, object_id, document, creation_time) * VALUES (agg_stage_0.target_shard_key_value, * COALESCE(bson_get_value(agg_stage_0.document, '_id'::text), agg_stage_0.generated_object_id), bson_dollar_merge_add_object_id(agg_stage_0.document, agg_stage_0.generated_object_id, '{ "a" : { "$type" : "int" } }'::bson), '2024-12-16 10:00:57.196789+00'::timestamp with time zone); * */ Query * HandleMerge(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_MERGE); if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "collation is not supported with $merge yet"))); } bool isTopLevel = true; if (IsInTransactionBlock(isTopLevel)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), errmsg( "$merge is not permitted within an active transaction"))); } /* if source table does not exist do not modify query */ if (context->mongoCollection == NULL) { return query; } ValidatePreOutputStages(query, "$merge"); MergeArgs mergeArgs; memset(&mergeArgs, 0, sizeof(mergeArgs)); ParseMergeStage(existingValue, context->namespaceName, &mergeArgs); /* Look for target collection details */ Datum databaseNameDatum = StringViewGetTextDatum(&mergeArgs.targetDB); Datum collectionNameDatum = StringViewGetTextDatum(&mergeArgs.targetCollection); MongoCollection *targetCollection = GetMongoCollectionOrViewByNameDatum( databaseNameDatum, collectionNameDatum, RowExclusiveLock); /* if target collection not exist create one */ if (targetCollection == NULL) { bool isMergeStage = true; ValidateTargetNameSpaceForOutputStage(&mergeArgs.targetDB, &mergeArgs.targetCollection, isMergeStage); int ignoreCollectionID = 0; VaildateMergeOnFieldValues(&mergeArgs.on, ignoreCollectionID); targetCollection = CreateCollectionForInsert(databaseNameDatum, collectionNameDatum); } else { if (targetCollection->viewDefinition != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTEDONVIEW), errmsg( "The namespace %s.%s refers to a view object rather than a collection", targetCollection->name.databaseName, targetCollection->name.collectionName), errdetail_log( "The namespace %s.%s refers to a view object rather than a collection", targetCollection->name.databaseName, targetCollection->name.collectionName))); } else if (targetCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$merge for sharded output collection not supported yet"), errdetail_log( "$merge for sharded output collection not supported yet"))); } VaildateMergeOnFieldValues(&mergeArgs.on, targetCollection->collectionId); } bool isSourceAndTargetAreSame = (targetCollection->collectionId == context->mongoCollection->collectionId); /* constant for target collection */ const int targetCollectionVarNo = 1; /* In merge query target table is 1st table */ const int targetShardKeyValueAttrNo = 1; /* From Target table we are just selecting 3 columns first one is shard_key_value */ const int targetObjectIdAttrNo = 2; /* From Target table we are just selecting 3 columns first one is shard_key_value */ const int targetDocAttrNo = 3; /* From Target table we are just selecting 3 columns third one is document */ /* Constant value assigned for source collection */ const int sourceCollectionVarNo = 2; /* In merge query source table is 2nd table */ const int sourceDocAttrNo = 1; /* In source table first projector is document */ const int sourceShardKeyValueAttrNo = 2; /* we will append shard_key_value in source query at 2nd position after document column */ const int generatedObjectIdAttrNo = 3; /* we will append generated object_id in source query at 3rd position after shard_key_value column */ const int sourceExtractedOnFieldsInitIndex = 4; /* We append all extracted source TEs starting from index 4 and repeat this process for all 'on' fields. */ if (targetCollection->shardKey == NULL) { RearrangeTargetListForMerge(query, targetCollection, isSourceAndTargetAreSame, &mergeArgs.on); } context->expandTargetList = true; query = MigrateQueryToSubQuery(query, context); query->commandType = CMD_MERGE; AddTargetCollectionRTEDollarMerge(query, targetCollection); Var *sourceDocVar = makeVar(sourceCollectionVarNo, sourceDocAttrNo, BsonTypeId(), -1, InvalidOid, 0); Var *targetObjectIdVar = makeVar(targetCollectionVarNo, targetObjectIdAttrNo, BsonTypeId(), -1, InvalidOid, 0); Var *targetDocVar = makeVar(targetCollectionVarNo, targetDocAttrNo, BsonTypeId(), -1, InvalidOid, 0); Var *targetShardKeyValueVar = makeVar(targetCollectionVarNo, targetShardKeyValueAttrNo, INT8OID, -1, 0, 0); Var *sourceShardKeyValueVar = makeVar(sourceCollectionVarNo, sourceShardKeyValueAttrNo, INT8OID, -1, 0, 0); Var *generatedObjectIdVar = makeVar(sourceCollectionVarNo, generatedObjectIdAttrNo, BsonTypeId(), -1, 0, 0); Const *schemaValidatorInfoConst = MakeBsonConst(PgbsonInitEmpty()); Const *validationLevelConst = makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(ValidationLevel_Invalid), false, true); bool bypassDocumentValidation = false; if (CheckSchemaValidationEnabled(targetCollection, bypassDocumentValidation)) { schemaValidatorInfoConst = MakeBsonConst( targetCollection->schemaValidator.validator); validationLevelConst = makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum( targetCollection->schemaValidator. validationLevel), false, true); } query->mergeActionList = list_make2(MakeActionWhenMatched(mergeArgs.whenMatched, sourceDocVar, targetDocVar, schemaValidatorInfoConst, validationLevelConst), MakeActionWhenNotMatched(mergeArgs.whenNotMatched, sourceDocVar, generatedObjectIdVar, sourceShardKeyValueVar, targetCollection, schemaValidatorInfoConst)); WriteJoinConditionToQueryDollarMerge(query, sourceDocVar, targetDocVar, sourceShardKeyValueVar, targetShardKeyValueVar, targetObjectIdVar, sourceExtractedOnFieldsInitIndex, sourceCollectionVarNo, mergeArgs); return query; } /* * create MergeAction for `whenMatched` case. * This function is responsible for constructing the following segment of the merge query : * WHEN MATCHED THEN * UPDATE SET document = bson_dollar_merge_handle_when_matched(agg_stage_4.document, documents_1.document, 0, '{ "a" : { "$type" : "int" } }'::bson, 1) */ static MergeAction * MakeActionWhenMatched(WhenMatchedAction whenMatched, Var *sourceDocVar, Var *targetDocVar, Const *schemaValidatorInfoConst, Const *validationLevelConst) { MergeAction *action = makeNode(MergeAction); #if PG_VERSION_NUM >= 170000 action->matchKind = MERGE_WHEN_MATCHED; #else action->matched = true; #endif if (whenMatched == WhenMatched_KEEPEXISTING) { action->commandType = CMD_NOTHING; return action; } action->commandType = CMD_UPDATE; Const *inputActionForWhenMathced = makeConst(INT4OID, -1, InvalidOid, sizeof(int32), Int32GetDatum(whenMatched), false, true); List *args = NIL; args = list_make5(sourceDocVar, targetDocVar, inputActionForWhenMathced, schemaValidatorInfoConst, validationLevelConst); FuncExpr *resultExpr = makeFuncExpr( BsonDollarMergeHandleWhenMatchedFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); action->targetList = list_make1( makeTargetEntry((Expr *) resultExpr, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_ATTR_NUMBER, "document", false) ); return action; } /* * create MergeAction for `whenNotMatched` case * This function is responsible for constructing the following segment of the merge query : * WHEN NOT MATCHED THEN * INSERT (shard_key_value, object_id, document, creation_time) * VALUE (source.target_shard_key_value, * COALESCE(bson_get_value(source.document, '_id'::text), * source.document), bson_dollar_merge_add_object_id(source.document, generated_object_id, schema_validator_info), * ) */ static MergeAction * MakeActionWhenNotMatched(WhenNotMatchedAction whenNotMatched, Var *sourceDocVar, Var *generatedObjectIdVar, Var *sourceShardKeyVar, MongoCollection *targetCollection, Const *schemaValidatorInfoConst) { MergeAction *action = makeNode(MergeAction); #if PG_VERSION_NUM >= 170000 action->matchKind = MERGE_WHEN_NOT_MATCHED_BY_TARGET; #else action->matched = false; #endif if (whenNotMatched == WhenNotMatched_DISCARD) { action->commandType = CMD_NOTHING; return action; } action->commandType = CMD_INSERT; TimestampTz nowValueTime = GetCurrentTimestamp(); Const *nowValue = makeConst(TIMESTAMPTZOID, -1, InvalidOid, 8, TimestampTzGetDatum(nowValueTime), false, true); /* let's build func expr for `object_id` column */ const char *objectIdField = "_id"; StringView objectIdFieldStringView = CreateStringViewFromString(objectIdField); Const *objectIdConst = MakeTextConst(objectIdFieldStringView.string, objectIdFieldStringView.length); List *argsBsonGetValueFunc = list_make2(sourceDocVar, objectIdConst); Oid functionOid = (whenNotMatched == WhenNotMatched_INSERT) ? BsonGetValueFunctionOid() : BsonDollarMergeFailWhenNotMatchedFunctionOid(); FuncExpr *bsonGetValueFuncExpr = makeFuncExpr( functionOid, BsonTypeId(), argsBsonGetValueFunc, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); CoalesceExpr *coalesce = makeNode(CoalesceExpr); coalesce->coalescetype = BsonTypeId(); coalesce->coalescecollid = InvalidOid; coalesce->args = list_make2(bsonGetValueFuncExpr, generatedObjectIdVar); /* let's build func expr for `document` column */ List *argsForAddObjecIdFunc = NIL; argsForAddObjecIdFunc = list_make3(sourceDocVar, generatedObjectIdVar, schemaValidatorInfoConst); FuncExpr *addObjecIdFuncExpr = makeFuncExpr( BsonDollarMergeAddObjectIdFunctionOid(), BsonTypeId(), argsForAddObjecIdFunc, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); /* for insert operation */ action->targetList = list_make3( makeTargetEntry((Expr *) sourceShardKeyVar, DOCUMENT_DATA_TABLE_SHARD_KEY_VALUE_VAR_ATTR_NUMBER, "target_shard_key_value", false), makeTargetEntry((Expr *) coalesce, DOCUMENT_DATA_TABLE_OBJECT_ID_VAR_ATTR_NUMBER, "object_id", false), makeTargetEntry((Expr *) addObjecIdFuncExpr, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_ATTR_NUMBER, "document", false)); if (targetCollection->mongoDataCreationTimeVarAttrNumber != -1) { action->targetList = lappend(action->targetList, makeTargetEntry((Expr *) nowValue, targetCollection-> mongoDataCreationTimeVarAttrNumber, "creation_time", false)); } return action; } /* * Parses & validates the input $merge spec. * * { $merge: { * into: <>, * on: <>, * let: <>, * whenMatched: <>, * whenNotMatched: <> * } } * * Parsed outputs are placed in the MergeArgs struct. */ static void ParseMergeStage(const bson_value_t *existingValue, const char *currentNameSpace, MergeArgs *args) { if (existingValue->value_type != BSON_TYPE_DOCUMENT && existingValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The $merge operator needs a string or object input, but received %s instead", BsonTypeName( existingValue->value_type)), errdetail_log( "The $merge operator needs a string or object input, but received %s instead", BsonTypeName( existingValue->value_type)))); } if (existingValue->value_type == BSON_TYPE_UTF8) { args->targetCollection = (StringView) { .length = existingValue->value.v_utf8.len, .string = existingValue->value.v_utf8.str }; args->on.value_type = BSON_TYPE_UTF8; args->on.value.v_utf8.len = 3; args->on.value.v_utf8.str = "_id"; StringView currentNameSpaceView = CreateStringViewFromString(currentNameSpace); args->targetDB = StringViewFindPrefix(¤tNameSpaceView, '.'); return; } /* parse when input is a document */ bson_iter_t mergeIter; BsonValueInitIterator(existingValue, &mergeIter); bool isOnSpecified = false; while (bson_iter_next(&mergeIter)) { const char *key = bson_iter_key(&mergeIter); const bson_value_t *value = bson_iter_value(&mergeIter); if (strcmp(key, "into") == 0) { if (value->value_type == BSON_TYPE_UTF8) { args->targetCollection = (StringView) { .length = value->value.v_utf8.len, .string = value->value.v_utf8.str }; } else if (value->value_type == BSON_TYPE_DOCUMENT) { bson_iter_t intoIter; BsonValueInitIterator(value, &intoIter); while (bson_iter_next(&intoIter)) { const char *innerKey = bson_iter_key(&intoIter); const bson_value_t *innerValue = bson_iter_value(&intoIter); if (innerValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "BSON field 'into.%s' has an incorrect type '%s'; the expected data type is 'string'", innerKey, BsonTypeName(value->value_type)), errdetail_log( "BSON field 'into.%s' has an incorrect type '%s'; the expected data type is 'string'", innerKey, BsonTypeName(value->value_type)))); } if (strcmp(innerKey, "db") == 0) { args->targetDB = (StringView) { .length = innerValue->value.v_utf8.len, .string = innerValue->value.v_utf8.str }; } else if (strcmp(innerKey, "coll") == 0) { args->targetCollection = (StringView) { .length = innerValue->value.v_utf8.len, .string = innerValue->value.v_utf8.str }; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "BSON field 'into.%s' is not recognized as a valid field", innerKey), errdetail_log( "BSON field 'into.%s' is not recognized as a valid field", innerKey))); } } if (args->targetCollection.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51178), errmsg( "The 'into' field of $merge must define a collection name that is neither empty, null, nor undefined."), errdetail_log( "The 'into' field of $merge must define a collection name that is neither empty, null, nor undefined."))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51178), errmsg( "$merge 'into' field must contain either a string value or an object, but was given %s instead", BsonTypeName(value->value_type)), errdetail_log( "$merge 'into' field must contain either a string value or an object, but was given %s instead", BsonTypeName(value->value_type)))); } StringView nameSpaceView = CreateStringViewFromString(currentNameSpace); StringView currentDBName = StringViewFindPrefix(&nameSpaceView, '.'); /* if target database name not mentioned in input let's use source database */ if (args->targetDB.length == 0) { args->targetDB = currentDBName; } } else if (strcmp(key, "on") == 0) { if (value->value_type != BSON_TYPE_UTF8 && value->value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51186), errmsg( "The $merge 'on' field must be provided as either a single string or an array containing multiple strings, but received %s instead.", BsonTypeName(value->value_type)), errdetail_log( "The $merge 'on' field must be provided as either a single string or an array containing multiple strings, but received %s instead.", BsonTypeName(value->value_type)))); } /* let's verify in parsing phase itself that values inside on array are of type string only and fail early if needed */ if (value->value_type == BSON_TYPE_ARRAY) { bson_iter_t onValuesIter; BsonValueInitIterator(value, &onValuesIter); bool atLeastOneElement = false; while (bson_iter_next(&onValuesIter)) { atLeastOneElement = true; const bson_value_t *onValuesElement = bson_iter_value(&onValuesIter); if (onValuesElement->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51134), errmsg( "Array elements for $merge 'on' must be strings, but a %s type was detected", BsonTypeName(onValuesElement->value_type)), errdetail_log( "Array elements for $merge 'on' must be strings, but a %s type was detected", BsonTypeName(onValuesElement->value_type)))); } } if (!atLeastOneElement) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51187), errmsg( "When you explicitly set the operators merge to 'on', you are required to include at least one field."), errdetail_log( "When you explicitly set the operators merge to 'on', you are required to include at least one field."))); } } args->on = *value; isOnSpecified = true; } else if (strcmp(key, "let") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("The let option is currently unsupported"), errdetail_log( "The let option is currently unsupported"))); } else if (strcmp(key, "whenMatched") == 0) { if (value->value_type == BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$merge 'whenMatched' with 'pipeline' not supported yet"), errdetail_log( "$merge 'whenMatched' with 'pipeline' not supported yet"))); } else if (value->value_type != BSON_TYPE_UTF8) { /* TODO : Modify error text when we support pipeline. Replace `must be string` with `must be either a string or array` */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51191), errmsg( "The 'whenMatched' field in $merge needs to be a string value, but a %s type was provided.", BsonTypeName( value->value_type)), errdetail_log( "The 'whenMatched' field in $merge needs to be a string value, but a %s type was provided.", BsonTypeName( value->value_type)))); } if (strcmp(value->value.v_utf8.str, "replace") == 0) { args->whenMatched = WhenMatched_REPLACE; } else if (strcmp(value->value.v_utf8.str, "keepExisting") == 0) { args->whenMatched = WhenMatched_KEEPEXISTING; } else if (strcmp(value->value.v_utf8.str, "merge") == 0) { args->whenMatched = WhenMatched_MERGE; } else if (strcmp(value->value.v_utf8.str, "fail") == 0) { args->whenMatched = WhenMatched_FAIL; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The enumeration value '%s' specified for the 'whenMatched' field is invalid.", value->value.v_utf8.str), errdetail_log( "The enumeration value '%s' specified for the 'whenMatched' field is invalid.", value->value.v_utf8.str))); } } else if (strcmp(key, "whenNotMatched") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "BSON field '$merge.whenNotMatched' has an incorrect type '%s', but it should be of type 'string'", BsonTypeName(value->value_type)), errdetail_log( "BSON field '$merge.whenNotMatched' has an incorrect type '%s', but it should be of type 'string'", BsonTypeName(value->value_type)))); } if (strcmp(value->value.v_utf8.str, "insert") == 0) { args->whenNotMatched = WhenNotMatched_INSERT; } else if (strcmp(value->value.v_utf8.str, "discard") == 0) { args->whenNotMatched = WhenNotMatched_DISCARD; } else if (strcmp(value->value.v_utf8.str, "fail") == 0) { args->whenNotMatched = WhenNotMatched_FAIL; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The enumeration value '%s' provided for the field operator '$merge.whenNotMatched' is invalid.", value->value.v_utf8.str), errdetail_log( "The enumeration value '%s' provided for the field operator '$merge.whenNotMatched' is invalid.", value->value.v_utf8.str))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The BSON field '$merge.%s' is not recognized as a valid field.", key), errdetail_log( "The BSON field '$merge.%s' is not recognized as a valid field.", key))); } } if (args->targetCollection.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40414), errmsg( "The required BSON field '$merge.into' is missing."), errdetail_log( "The required BSON field '$merge.into' is missing."))); } if (!isOnSpecified) { args->on.value_type = BSON_TYPE_UTF8; args->on.value.v_utf8.len = 3; args->on.value.v_utf8.str = "_id"; } } /* * Before $merge stage for existing query we need to modify target list for : * 1. Generate a object id and add it to the target list, if an object ID is missing during insertion, use the one generated one. * 2. Add target collection_id to source tuples so that we can achieve a TRUE equi-join condition. As Citus does not support joins without have equi-join condition on distributed table. * * After this function new targetList of query will be like : * SELECT collection.document AS document, * '2'::bigint AS target_shard_key_value, -- (2 is collection_id of target collection) * bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id * FROM ApiDataSchemaName.documents_1 collection * WHERE collection.shard_key_value = '1'::bigint * * TODO : if source and target collection are same we need to add actual shard_key_value column to the query but need to be careful when there are nested stages * this optimization will help when both collection are sharded so we should do when we support target sharded collection. */ static void RearrangeTargetListForMerge(Query *query, MongoCollection *targetCollection, bool isSourceAndTargetAreSame, const bson_value_t *onValues) { int resNumber = 0; /* Let's create a new target list */ /* 1. Start by adding the first 'TE' from the existing query, which is a document field. * target collection is unsharded so add target collection_id to source tuples so that we can achieve * a TRUE equi-join condition. As Citus does not support joins without have equi-join condition on distributed table. */ List *newTargetList = NIL; TargetEntry *sourceDocTE = (TargetEntry *) linitial(query->targetList); resNumber = sourceDocTE->resno; newTargetList = lappend(newTargetList, sourceDocTE); /* 2. append TE : target_shard_key_value. */ Expr *exprShardKeyValueCol = (Expr *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64), Int64GetDatum( targetCollection->collectionId), false, true); TargetEntry *dummySourceShardKeyValueTE = makeTargetEntry(exprShardKeyValueCol, ++resNumber, "target_shard_key_value", false); newTargetList = lappend(newTargetList, dummySourceShardKeyValueTE); /* 3. append TE : generated_object_id : we can use it while insertion */ Node *sourceDocVar = (Node *) sourceDocTE->expr; List *argsForAddObjectIdFuncExpr = list_make1(sourceDocVar); FuncExpr *addObjectIdFuncExpr = makeFuncExpr(BsonDollarMergeGenerateObjectId(), BsonTypeId(), argsForAddObjectIdFuncExpr, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *generatedObjectIdTE = makeTargetEntry((Expr *) addObjectIdFuncExpr, ++resNumber, "generated_object_id", false); newTargetList = lappend(newTargetList, generatedObjectIdTE); /* 4. append bson_dollar_extract_merge_filter function so all on fields so that we can use extracted source in join condition. * For the $out stage, we will have 'on' values, so this step will be skipped for $out. */ if (onValues) { if (onValues->value_type == BSON_TYPE_UTF8) { newTargetList = lappend(newTargetList, MakeExtractFuncExprForMergeTE( onValues->value.v_utf8.str, onValues->value.v_utf8.len, (Var *) sourceDocVar, ++resNumber)); } else if (onValues->value_type == BSON_TYPE_ARRAY) { bson_iter_t onValuesIter; BsonValueInitIterator(onValues, &onValuesIter); while (bson_iter_next(&onValuesIter)) { const bson_value_t *innerValue = bson_iter_value(&onValuesIter); newTargetList = lappend(newTargetList, MakeExtractFuncExprForMergeTE( innerValue->value.v_utf8.str, innerValue->value.v_utf8.len, (Var *) sourceDocVar, ++resNumber)); } } } /* 5. Move all Remaining entries from the existing target list to the new target list. */ int targetEntryIndex = 0; ListCell *cell; foreach(cell, query->targetList) { TargetEntry *entry = (TargetEntry *) lfirst(cell); if (targetEntryIndex == 0) { targetEntryIndex++; continue; } entry->resno = ++resNumber; newTargetList = lappend(newTargetList, entry); targetEntryIndex++; } query->targetList = newTargetList; } /* This function creates an target entry for bson_dollar_extract_merge_filter */ static inline TargetEntry * MakeExtractFuncExprForMergeTE(const char *onField, uint32 length, Var *sourceDocument, const int resNum) { char *resName = psprintf("extracted_%d", resNum); Const *onCondition = MakeTextConst(onField, length); List *argsForExtractFilterFunc = list_make2(sourceDocument, onCondition); FuncExpr *mergeExtractFunction = makeFuncExpr( BsonDollarMergeExtractFilterFunctionOid(), BsonTypeId(), argsForExtractFilterFunc, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); TargetEntry *extractFuncTE = makeTargetEntry((Expr *) mergeExtractFunction, resNum, resName, false); return extractFuncTE; } /* * Add target collection to the query for $merge aggregation stage. */ static inline void AddTargetCollectionRTEDollarMerge(Query *query, MongoCollection *targetCollection) { RangeTblEntry *rte = makeNode(RangeTblEntry); List *colNames = list_make3(makeString("shard_key_value"), makeString("object_id"), makeString("document")); rte->alias = rte->eref = makeAlias(targetCollection->tableName, colNames); rte->rtekind = RTE_RELATION; rte->relkind = RELKIND_RELATION; rte->self_reference = false; rte->lateral = false; rte->inh = false; rte->inFromCl = false; rte->rellockmode = RowExclusiveLock; RangeVar *rangeVar = makeRangeVar(ApiDataSchemaName, targetCollection->tableName, -1); rte->relid = RangeVarGetRelid(rangeVar, RowExclusiveLock, false); #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif RangeTblEntry *existingrte = list_nth(query->rtable, 0); query->rtable = list_make2(rte, existingrte); query->resultRelation = 1; #if PG_VERSION_NUM >= 170000 query->mergeTargetRelation = query->resultRelation; #else query->mergeUseOuterJoin = true; #endif query->targetList = NIL; } /* * write join condition to the query Tree for $merge aggregation stage. * * let's say `on` field is array : ["a", "b", "c"] * join condition in sql : * * ON target.shard_key_value OPERATOR(pg_catalog.=) source.target_shard_key_value * AND bson_dollar_merge_join(target.document, source.docuemnt, 'a'::text) * AND bson_dollar_merge_join(target.document, source.docuemnt, 'b'::text) */ static void WriteJoinConditionToQueryDollarMerge(Query *query, Var *sourceDocVar, Var *targetDocVar, Var *sourceShardKeyValueVar, Var *targetShardKeyValueVar, Var *targetObjectIdVar, const int sourceExtractedOnFieldsInitIndex, const int sourceCollectionVarNo, MergeArgs mergeArgs) { Expr *opexpr = make_opclause(PostgresInt4EqualOperatorOid(), BOOLOID, false, (Expr *) targetShardKeyValueVar, (Expr *) sourceShardKeyValueVar, InvalidOid, InvalidOid); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 2; query->jointree = makeFromExpr(list_make1(rtr), NULL); List *joinFilterList = NIL; joinFilterList = lappend(joinFilterList, opexpr); int extractFieldResNum = sourceExtractedOnFieldsInitIndex; if (mergeArgs.on.value_type == BSON_TYPE_UTF8) { Expr *singleJoinExpr = CreateSingleJoinExpr(mergeArgs.on.value.v_utf8.str, sourceDocVar, targetDocVar, targetObjectIdVar, extractFieldResNum, sourceCollectionVarNo); joinFilterList = lappend(joinFilterList, singleJoinExpr); } else if (mergeArgs.on.value_type == BSON_TYPE_ARRAY) { bson_iter_t onValuesIter; BsonValueInitIterator(&mergeArgs.on, &onValuesIter); while (bson_iter_next(&onValuesIter)) { const bson_value_t *onValuesElement = bson_iter_value(&onValuesIter); const char *onField = onValuesElement->value.v_utf8.str; Expr *singleJoinExpr = CreateSingleJoinExpr(onField, sourceDocVar, targetDocVar, targetObjectIdVar, extractFieldResNum, sourceCollectionVarNo); joinFilterList = lappend(joinFilterList, singleJoinExpr); extractFieldResNum++; } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The on field specified in the $merge stage should be a string or an array containing strings, but a value of type %s was provided instead.", BsonTypeName(mergeArgs.on.value_type)), errdetail_log( "The on field specified in the $merge stage should be a string or an array containing strings, but a value of type %s was provided instead.", BsonTypeName(mergeArgs.on.value_type)))); } #if PG_VERSION_NUM >= 170000 query->mergeJoinCondition = (Node *) make_ands_explicit(joinFilterList); #else query->jointree->quals = (Node *) make_ands_explicit(joinFilterList); #endif } /* * In the $merge query, users can specify multiple "on" conditions. We handle them in two ways: * 1. If the "on" field is "_id", we create an expression: targetDocument.ObjectID = BsonGetValueFunctionOid(sourceDocument, "_id"). * 2. For any other field, we create an expression: bson_dollar_merge_join(target.document, sourceDocVar.document, "joinfield"). * The bson_dollar_merge_join function is used to support function for index pushdown, which replaces the function expression with an operator expression. */ static inline Expr * CreateSingleJoinExpr(const char *joinField, Var *sourceDocVar, Var *targetDocVar, Var *targetObjectIdVar, const int extractFieldResNumber, const int sourceCollectionVarNo) { StringView onFieldStringView = CreateStringViewFromString(joinField); Const *onCondition = MakeTextConst(onFieldStringView.string, onFieldStringView.length); Expr *singleJoinExpr = NULL; if (strcmp(joinField, "_id") == 0) { List *argsforFuncExpr = list_make2(sourceDocVar, onCondition); FuncExpr *extractFuncExpr = makeFuncExpr( BsonGetValueFunctionOid(), BsonTypeId(), argsforFuncExpr, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); singleJoinExpr = make_opclause(BsonEqualOperatorId(), BOOLOID, false, (Expr *) targetObjectIdVar, (Expr *) extractFuncExpr, InvalidOid, InvalidOid); } else { Var *extractedSourceVar = makeVar(sourceCollectionVarNo, extractFieldResNumber, BsonTypeId(), -1, 0, 0); List *argsforFuncExpr = list_make3(copyObject(targetDocVar), extractedSourceVar, onCondition); singleJoinExpr = (Expr *) makeFuncExpr( BsonDollarMergeJoinFunctionOid(), BOOLOID, argsforFuncExpr, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } return singleJoinExpr; } /* * In the $merge stage, we want to fail if the `on` fields specified in the input do not have a unique index in the target collection. * If the target collection does not exist and the `on` field is anything other than `_id`, we also fail. * * The `on` value can be either a UTF8 string or an array of UTF8 strings. * If it is a UTF8 string, we check for a single unique index on that field in the target collection. * If it is an array of UTF8 strings, we check for a compound unique index on the specified fields in the target collection. * For example, if `on` is "a", we want to ensure that the target collection has a unique index on the field 'a'. * If `on` is "[a,b]", we want to ensure that the target collection has a compound unique index on the fields 'a' and 'b'. */ static void VaildateMergeOnFieldValues(const bson_value_t *onValues, uint64 collectionId) { Assert(onValues->value_type == BSON_TYPE_ARRAY || onValues->value_type == BSON_TYPE_UTF8); bool excludeIdIndex = false; bool enableNestedDistribution = false; List *indexesDetailList = NIL; bool foundRequiredIndex = false; int numKeysOnField = 1; char *keyNameIfSingleKeyJoin = NULL; if (onValues->value_type == BSON_TYPE_ARRAY) { numKeysOnField = BsonDocumentValueCountKeys(onValues); } if (numKeysOnField == 1) { if (onValues->value_type == BSON_TYPE_ARRAY) { bson_iter_t onValuesIter; BsonValueInitIterator(onValues, &onValuesIter); bson_iter_next(&onValuesIter); const bson_value_t *onValue = bson_iter_value(&onValuesIter); keyNameIfSingleKeyJoin = onValue->value.v_utf8.str; } else if (onValues->value_type == BSON_TYPE_UTF8) { keyNameIfSingleKeyJoin = onValues->value.v_utf8.str; } /* If the on field contains just the _id field, it's a valid unique index, so we can stop here. */ if (strcmp(keyNameIfSingleKeyJoin, "_id") == 0) { return; } } /* By design, collection IDs are always greater than 0. Therefore, if a caller passes a collection ID of 0, it implies that the collection does not exist. */ if (collectionId != 0) { indexesDetailList = CollectionIdGetValidIndexes(collectionId, excludeIdIndex, enableNestedDistribution); } ListCell *indexDetailCell = NULL; foreach(indexDetailCell, indexesDetailList) { const IndexDetails *indexDetail = (IndexDetails *) lfirst(indexDetailCell); /* The index is required to be unique and should not have any partial filters applied to it. */ if (indexDetail->indexSpec.indexUnique != BoolIndexOption_True || indexDetail->indexSpec.indexPFEDocument != NULL) { continue; } bson_iter_t indexKeyDocumentIter; pgbson *indexKeyDocument = indexDetail->indexSpec.indexKeyDocument; PgbsonInitIterator(indexKeyDocument, &indexKeyDocumentIter); if (keyNameIfSingleKeyJoin) { if (IsSingleUniqueIndexPresent(keyNameIfSingleKeyJoin, &indexKeyDocumentIter)) { foundRequiredIndex = true; break; } } else if (IsCompoundUniqueIndexPresent(onValues, &indexKeyDocumentIter, numKeysOnField)) { foundRequiredIndex = true; break; } } if (!foundRequiredIndex) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51183), errmsg( "Unable to locate index required to confirm join fields are unique"), errdetail_log( "Unable to locate index required to confirm join fields are unique"))); } } /* * Checks if a unique index is present for the given field. * * This function look into elements of indexKeyDocumentIter and checks if a unique index exists for the field specified in the 'onValue'. * If indexKeyDocumentIter has more than one document that means it is a compound unique index, so we should ignore that. * * Parameters: * - onValue: Index key string. * - indexKeyDocumentIter: An iterator for the index key document. * * example: * - onValue : "apple" * - indexKeyDocument : {"apple" : 1} * output : true * * Returns: * - true if a unique index is present for the given fields, false otherwise. */ static inline bool IsSingleUniqueIndexPresent(const char *onValue, bson_iter_t *indexKeyDocumentIter) { pgbsonelement uniqueIndexElement; /* if a document contains more than one element, it signifies a compound unique index, such as {"a" : 1, "b" : 1}. we should ignore that */ if (TryGetSinglePgbsonElementFromBsonIterator(indexKeyDocumentIter, &uniqueIndexElement)) { if (strcmp(uniqueIndexElement.path, onValue) == 0) { return true; } } return false; } /* * Checks if a compound unique index is present for the given fields. * * This function iterates over index key document and checks if a compound unique index exists for the fields specified in the 'onValues' array. * * Parameters: * - onValues: A bson_value_t of array type. * - indexKeyDocumentIter: An iterator for the index key document. * - numElementsInMap: Number of elements in the 'onValues' array from which we will built hashmap. * * example: * - onValues : ["a", "b", "c"] * - indexKeyDocument : {"b" : 1, "c" : 1, "a" : 1} * output : true (as all the element of onvalues are present in indexKeyDocument, so we can say that we found a compound unique index for key a,b,c) * * Returns: * - true if a compound unique index is present for the given fields, false otherwise. */ static bool IsCompoundUniqueIndexPresent(const bson_value_t *onValues, bson_iter_t *indexKeyDocumentIter, const int numElementsInMap) { HTAB *onValueHashTable = InitHashTableFromStringArray(onValues, numElementsInMap); int foundCount = 0; /* make sure alll the elements in index document present in hash map */ while (bson_iter_next(indexKeyDocumentIter)) { StringView currentKey = bson_iter_key_string_view(indexKeyDocumentIter); bool foundInMap = false; hash_search(onValueHashTable, ¤tKey, HASH_FIND, &foundInMap); if (!foundInMap) { hash_destroy(onValueHashTable); return false; } foundCount++; } hash_destroy(onValueHashTable); /* ensure that the map does not contain any elements beyond those in the index document */ if (foundCount < numElementsInMap) { return false; } return true; } /* * Initializes a hash table from a string array. * * This function creates a new hash table and populates it with the strings * from the provided array. * * Parameters: * - inputKeyArray: A bson_value_t which must be of BSON_TYPE_ARRAY of strings to be used as keys in the hash table. * - arraySize: The size of the inputKeyArray. * * Returns: * - A pointer to the newly created hash table. */ static HTAB * InitHashTableFromStringArray(const bson_value_t *inputKeyArray, int arraySize) { HTAB *hashTable = CreateStringViewHashSet(); bson_iter_t inputArrayIter; BsonValueInitIterator(inputKeyArray, &inputArrayIter); while (bson_iter_next(&inputArrayIter)) { const bson_value_t *inputArrayElement = bson_iter_value(&inputArrayIter); StringView value = CreateStringViewFromStringWithLength( inputArrayElement->value.v_utf8.str, inputArrayElement->value.v_utf8.len); bool found = false; hash_search(hashTable, &value, HASH_ENTER, &found); if (found) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31465), errmsg( "Duplicate field %s detected", value.string), errdetail_log( "Duplicate field %s detected", value.string))); } } return hashTable; } /* * ValidatePreOutputStages traverse query tree to fail early if $merge/$out is used with $graphLookup or contains any mutable function. */ static inline void ValidatePreOutputStages(Query *query, char *stageName) { /* First, walk the query tree to detect any constructs that disqualify merge support */ query_tree_walker(query, MergeQueryCTEWalker, stageName, 0); /* Already checked for known mutable functions; perform a recheck to ensure none were missed */ if (contain_mutable_functions((Node *) query)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "The `%s` stage currently does not have support for use with mutable functions.", stageName), errdetail_log( "MUTABLE functions are not yet in MERGE command by citus"))); } } /* * MergeQueryCTEWalker descends into the MERGE query to check for any subqueries */ static bool MergeQueryCTEWalker(Node *node, void *context) { if (node == NULL) { return false; } if (IsA(node, Query)) { Query *query = (Query *) node; char *stageName = (char *) context; if (query->hasRecursive) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$graphLookup is not supported with %s stage yet.", stageName), errdetail_log( "$graphLookup is not supported with $merge/$out stage yet."))); } query_tree_walker(query, MergeQueryCTEWalker, context, 0); /* we're done, no need to recurse anymore for this query */ return false; } else if (IsA(node, FuncExpr)) { FuncExpr *fexpr = (FuncExpr *) node; char *stageName = (char *) context; if (fexpr->funcid == ExtensionTableSampleSystemRowsFunctionId() || fexpr->funcid == PgRandomFunctionOid()) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "The %s stage is not yet supported with the $sample aggregation stage.", stageName), errdetail_log( "MUTABLE functions are not yet in MERGE command by citus"))); } else if (fexpr->funcid == BsonEmptyDataTableFunctionId()) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "The query references collections that do not exist. Create the missing collections and retry."), errdetail_log( "MUTABLE functions are not yet in MERGE command by citus"))); } } return expression_tree_walker(node, MergeQueryCTEWalker, context); } /* let's validate final pgbson before writing to collection */ static inline void ValidateFinalPgbsonBeforeWriting(const pgbson *finalBson, const pgbson *targetDocument, ExprEvalState *stateForSchemaValidation, ValidationLevels validationLevel) { /* let's validate final document before insert */ PgbsonValidateInputBson(finalBson, BSON_VALIDATE_NONE); if (finalBson != NULL) { uint32_t size = PgbsonGetBsonSize(finalBson); if (size > BSON_MAX_ALLOWED_SIZE) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BSONOBJECTTOOLARGE), errmsg("Size %u is larger than MaxDocumentSize %u", size, BSON_MAX_ALLOWED_SIZE))); } } /* if we have stateForSchemaValidation, we need to validate the final document; */ /* if validation level is moderate, final document could not match only if `targetDocument` also does not match */ if (EnableSchemaValidation && stateForSchemaValidation != NULL) { ValidateSchemaOnDocumentUpdate(validationLevel, stateForSchemaValidation, targetDocument, finalBson, FAILED_VALIDATION_PLAN_EXECUTOR_ERROR_MSG); } } /* * This function Validate the ObjectId fields and write it in the writer. * * During validation, it addresses the following behavior: * 1. If the ObjectId of the source and target documents differ, an error is thrown because the target ObjectId cannot be replaced with the source ObjectId, as the ObjectId field is immutable. * 2. If the ObjectId of the source and target documents are the same, the ObjectId field is written to the writer. * 3. If the source ObjectId is missing we write the target ObjectId to the writer. * * Parameters: * - writer: The pgbson_writer to which the "_id" field will be added. * - sourceDocument: The source pgbson document. * - targetDocument: The target pgbson document. */ static void ValidateAndAddObjectIdToWriter(pgbson_writer *writer, pgbson *sourceDocument, pgbson *targetDocument) { /* Here we expect _id to be the first field of the target document because while inserting we make sure to move _id to the first field and write to the table */ pgbsonelement objectIdFromTargetDocument; if (!TryGetSinglePgbsonElementFromPgbson(targetDocument, &objectIdFromTargetDocument) && strcmp(objectIdFromTargetDocument.path, "_id") != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Something went wrong, Expecting object ID to be the first field in the target document"), errdetail_log( "Something went wrong, Expecting object ID to be the first field in the target document of type %s", BsonTypeName( objectIdFromTargetDocument.bsonValue.value_type)))); } bson_iter_t sourceIter; if (PgbsonInitIteratorAtPath(sourceDocument, "_id", &sourceIter)) { const bson_value_t *value = bson_iter_value(&sourceIter); /* compare source _id value with target's _id value, As object id is Immutable both field should match */ bool ignoreIsCmpValid = true; if (CompareBsonValueAndType(value, &objectIdFromTargetDocument.bsonValue, &ignoreIsCmpValid) != 0) { /* We validate the object ID in failure scenarios to ensure that if the ID is incorrect, we return the appropriate error code initially. */ ValidateIdField(value); ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_IMMUTABLEFIELD), errmsg( "$merge could not update the target document as an immutable field (like '_id' or shardKey) was detected to be modified."))); } } /* Everything looks good, we can write the `_id` field to the writer */ PgbsonWriterInit(writer); PgbsonWriterAppendValue(writer, "_id", 3, &objectIdFromTargetDocument.bsonValue); } /* * Mutates the query for the $out stage * * Example command : { $out: { "db": <>, "coll" : <> } } * targetDb with schema validation enabled as `'{ "a" : { "$type" : "int" } }`, we need to apply schema validation to the final document. * sql query : * * MERGE INTO ONLY ApiDataSchemaName.documents_3 documents_3 * USING ( SELECT collection.document, * '3'::bigint AS target_shard_key_value, * ApiInternalSchemaName.bson_dollar_merge_generate_object_id(collection.document) AS generated_object_id * FROM ApiDataSchemaName.documents_2 collection * WHERE collection.shard_key_value = '2'::bigint) agg_stage_0 * ON documents_3.shard_key_value OPERATOR(pg_catalog.=) agg_stage_0.target_shard_key_value AND FALSE * WHEN NOT MATCHED * THEN INSERT (shard_key_value, object_id, document, creation_time) * VALUES (agg_stage_0.target_shard_key_value, COALESCE(bson_get_value(agg_stage_0.document, '_id'::text), agg_stage_0.generated_object_id), ApiInternalSchemaName.bson_dollar_merge_add_object_id(agg_stage_0.document, agg_stage_0.generated_object_id, '{ "a" : { "$type" : "int" } }'::bson), '2024-08-21 11:06:38.323204+00'::timestamp with time zone) */ Query * HandleOut(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_OUT); OutArgs outArgs = { 0 }; memset(&outArgs, 0, sizeof(outArgs)); ParseOutStage(existingValue, context->namespaceName, &outArgs); ValidatePreOutputStages(query, "$out"); MongoCollection *targetCollection = GetMongoCollectionOrViewByNameDatum(StringViewGetTextDatum(&outArgs.targetDB), StringViewGetTextDatum( &outArgs.targetCollection), RowExclusiveLock); if (targetCollection) { bool isSourceSameAsTarget = targetCollection->collectionId == context->mongoCollection->collectionId; if (targetCollection->viewDefinition != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTEDONVIEW), errmsg( "The namespace %s.%s refers to a view object rather than a collection", targetCollection->name.databaseName, targetCollection->name.collectionName), errdetail_log( "The namespace %s.%s refers to a view object rather than a collection", targetCollection->name.databaseName, targetCollection->name.collectionName))); } else if (targetCollection && targetCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28769), errmsg("%s.%s cannot be sharded", outArgs.targetDB.string, outArgs.targetCollection.string))); } else if (isSourceSameAsTarget) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "The target collection cannot be the same as the source collection in $out stage."))); } /* Truncate the target data table to delete all entries. This allows us to write new data into it */ TruncateDataTable(targetCollection->collectionId); } else { bool isMergeStage = false; ValidateTargetNameSpaceForOutputStage(&outArgs.targetDB, &outArgs.targetCollection, isMergeStage); targetCollection = CreateCollectionForInsert(StringViewGetTextDatum(&outArgs.targetDB), StringViewGetTextDatum(&outArgs.targetCollection)); } RearrangeTargetListForMerge(query, targetCollection, false, NULL); context->expandTargetList = true; query = MigrateQueryToSubQuery(query, context); query->commandType = CMD_MERGE; AddTargetCollectionRTEDollarMerge(query, targetCollection); /* If targetCollection enables schema validation, apply to target document*/ bool bypassDocumentValidation = false; Const *schemaValidatorInfoConst = MakeBsonConst(PgbsonInitEmpty()); if (CheckSchemaValidationEnabled(targetCollection, bypassDocumentValidation)) { schemaValidatorInfoConst = MakeBsonConst( targetCollection->schemaValidator.validator); } /* Constant value assigned for source collection */ const int sourceCollectionVarNo = 2; /* In merge query source table is 2nd table */ const int sourceDocAttrNo = 1; /* In source table first projector is document */ const int sourceShardKeyValueAttrNo = 2; /* we will append shard_key_value in source query at 2nd position after document column */ const int generatedObjectIdAttrNo = 3; /* we will append generated object_id in source query at 3rd position after shard_key_value column */ const int targetCollectionVarNo = 1; /* In merge query target table is 1st table */ const int targetShardKeyValueAttrNo = 1; /* From Target table we are just selecting 3 columns first one is shard_key_value */ Var *sourceDocVar = makeVar(sourceCollectionVarNo, sourceDocAttrNo, BsonTypeId(), -1, InvalidOid, 0); Var *sourceShardKeyValueVar = makeVar(sourceCollectionVarNo, sourceShardKeyValueAttrNo, INT8OID, -1, 0, 0); Var *generatedObjectIdVar = makeVar(sourceCollectionVarNo, generatedObjectIdAttrNo, BsonTypeId(), -1, 0, 0); Var *targetShardKeyValueVar = makeVar(targetCollectionVarNo, targetShardKeyValueAttrNo, INT8OID, -1, 0, 0); query->mergeActionList = list_make1(MakeActionWhenNotMatched(WhenNotMatched_INSERT, sourceDocVar, generatedObjectIdVar, sourceShardKeyValueVar, targetCollection, schemaValidatorInfoConst)); /* Write the join condition for $out, which will be in the form of * `ON target.shard_key_value = source.target_shard_key_value` * This is necessary because Citus requires the target's distributed column in the join condition. * In any case, for $out, we always write to an empty table, so it's always whenNotMatched. */ RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 2; query->jointree = makeFromExpr(list_make1(rtr), NULL); #if PG_VERSION_NUM >= 170000 query->mergeJoinCondition = (Node *) make_opclause(PostgresInt4EqualOperatorOid(), BOOLOID, false, (Expr *) targetShardKeyValueVar, (Expr *) sourceShardKeyValueVar, InvalidOid, InvalidOid); #else query->jointree->quals = (Node *) make_opclause(PostgresInt4EqualOperatorOid(), BOOLOID, false, (Expr *) targetShardKeyValueVar, (Expr *) sourceShardKeyValueVar, InvalidOid, InvalidOid); #endif return query; } /* * Truncate data table corresponding to the input collection id. */ static void TruncateDataTable(int collectionId) { StringInfo cmdStr = makeStringInfo(); appendStringInfo(cmdStr, "TRUNCATE TABLE %s.documents_%d", ApiDataSchemaName, collectionId); bool isNull = false; bool readOnly = false; ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_UTILITY, &isNull); } /* * Parses & validates the input $out spec. * first way : { $out : "collection-name" } * second way : { $out : {"db" : "database-name", "coll" : "collection-name"} } * * Parsed outputs are placed in the OutArgs struct. */ static void ParseOutStage(const bson_value_t *existingValue, const char *currentNameSpace, OutArgs *args) { if (existingValue->value_type != BSON_TYPE_DOCUMENT && existingValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16990), errmsg( "Expected 'string' or 'document' type but found '%s' type", BsonTypeName(existingValue->value_type)))); } if (existingValue->value_type == BSON_TYPE_UTF8) { char *dbName = NULL; char *dotPosition = strchr(currentNameSpace, '.'); if (dotPosition != NULL) { size_t dbNameLength = dotPosition - currentNameSpace; dbName = pnstrdup(currentNameSpace, dbNameLength); } args->targetCollection = (StringView) { .length = existingValue->value.v_utf8.len, .string = existingValue->value.v_utf8.str }; args->targetDB = CreateStringViewFromString(dbName); return; } /* parse when input is a document */ bson_iter_t mergeIter; BsonValueInitIterator(existingValue, &mergeIter); while (bson_iter_next(&mergeIter)) { const char *key = bson_iter_key(&mergeIter); const bson_value_t *bsonValue = bson_iter_value(&mergeIter); if (strcmp(key, "db") == 0) { if (bsonValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION13111), errmsg("wrong type for field (db) %s != string", BsonTypeName(bsonValue->value_type)))); } args->targetDB = (StringView) { .length = bsonValue->value.v_utf8.len, .string = bsonValue->value.v_utf8.str }; } else if (strcmp(key, "coll") == 0) { if (bsonValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION13111), errmsg( "Field type mismatch in (coll): %s expected string", BsonTypeName(bsonValue->value_type)))); } args->targetCollection = (StringView) { .length = bsonValue->value.v_utf8.len, .string = bsonValue->value.v_utf8.str }; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16990), errmsg( "If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll'"))); } } if (args->targetDB.length == 0 || args->targetCollection.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16994), errmsg( "If an object is passed to $out it must have exactly 2 fields: 'db' and 'coll'"))); } } /* check whether to perform schema validation in stage $merge/$out */ static inline bool CheckSchemaValidationEnabledForDollarMergeOut(void) { return EnableSchemaValidation; } /* * Output stages can not write into db name : `config`, `local`, `admin` * Output stages can not write into collections starts from `system.` */ static inline void ValidateTargetNameSpaceForOutputStage(const StringView *targetDB, const StringView *targetCollection, const bool isMergeStage) { const char *stageName = isMergeStage ? "$merge" : "$out"; if (StringViewEqualsCString(targetDB, "config") || StringViewEqualsCString(targetDB, "local") || StringViewEqualsCString(targetDB, "admin")) { int errorCode = isMergeStage ? ERRCODE_DOCUMENTDB_LOCATION31320 : ERRCODE_DOCUMENTDB_LOCATION31321; ereport(ERROR, (errcode(errorCode), errmsg("Unable to %s into internal database resource: %s", stageName, targetDB->string))); } const StringView SystemPrefix = { .length = 7, .string = "system." }; if (StringViewStartsWithStringView(targetCollection, &SystemPrefix)) { int errorCode = isMergeStage ? ERRCODE_DOCUMENTDB_LOCATION31319 : ERRCODE_DOCUMENTDB_LOCATION17385; ereport(ERROR, (errcode(errorCode), errmsg(" Unable to %s into designated special collection: %s", stageName, targetCollection->string))); } } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_pipeline.c000066400000000000000000007225651507310017400272530ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_pipeline.c * * Implementation of the backend query generation for pipelines. * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "query/query_operator.h" #include "planner/documentdb_planner.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_window_operators.h" #include "commands/parse_error.h" #include "commands/commands_common.h" #include "commands/defrem.h" #include "utils/feature_counter.h" #include "utils/version_utils.h" #include "aggregation/bson_query.h" #include "metadata/index.h" #include "aggregation/bson_aggregation_pipeline_private.h" #include "aggregation/bson_bucket_auto.h" #include "api_hooks.h" #include "vector/vector_common.h" #include "aggregation/bson_project.h" #include "operators/bson_expression.h" #include "operators/bson_expression_operators.h" #include "operators/bson_expression_bucket_operator.h" #include "geospatial/bson_geospatial_common.h" #include "geospatial/bson_geospatial_geonear.h" #include "aggregation/bson_densify.h" #include "collation/collation.h" #include "api_hooks.h" extern bool EnableCursorsOnAggregationQueryRewrite; extern bool EnableCollation; extern bool DefaultInlineWriteOperations; extern int MaxAggregationStagesAllowed; extern bool EnableIndexOrderbyPushdown; extern bool EnableIndexHintSupport; extern bool EnableIndexOrderbyPushdownLegacy; /* GUC to config tdigest compression */ extern int TdigestCompressionAccuracy; /* * The mutation function that modifies a given query with a pipeline stage's value. */ typedef Query *(*MutateQueryForStageFunc)(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); /* * This function checks the compatibility of stages in the pipeline. */ typedef void (*PipelineStagesPreCheckFunc)(const bson_value_t *existingValue, const AggregationPipelineBuildContext *context); /* * Whether or not the stage requires persistence on the cursor. */ typedef bool (*RequiresPersistentCursorFunc)(const bson_value_t *existingValue); /* * Whether or not the stage can be inlined for a lookup stage */ typedef bool (*CanInlineLookupStage)(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); /* * Declaration of a given aggregation pipeline stage. */ typedef struct AggregationStageDefinition { /* The stage name (e.g. $addFields, $project) */ const char *stage; /* The function that will modify the pipeline for that stage - NULL if unsupported */ MutateQueryForStageFunc mutateFunc; /* Whether or not the stage requires persistence on cursors */ RequiresPersistentCursorFunc requiresPersistentCursor; /* Optional function for whether lookup stages can be inlined in the substage */ CanInlineLookupStage canInlineLookupStageFunc; /* Does the stage maintain a stable sort order or modify the input stream */ bool preservesStableSortOrder; /* Whether or not the stage supports collection agnostic queries */ bool canHandleAgnosticQueries; /* Whether or not the stage is a linear transform of the prior stage. * i.e. whether or not the stage is purely a projection transform of its input. */ bool isProjectTransform; /* Check whether given pipeline stages are compatible. */ PipelineStagesPreCheckFunc pipelineCheckFunc; /* Whether or not the stage is an output stage. $merge and $out are output stages */ bool isOutputStage; /* Allow Base shard table pushdown */ bool allowBaseShardTablePushdown; Stage stageEnum; } AggregationStageDefinition; static void AddCursorFunctionsToQuery(Query *query, Query *baseQuery, QueryData *queryData, AggregationPipelineBuildContext *context, bool addCursorAsConst); static void AddQualifierForTailableQuery(Query *query, Query *baseQuery, QueryData *queryData, AggregationPipelineBuildContext * context); static void SetBatchSize(const char *fieldName, const bson_value_t *value, QueryData *queryData); static int CompareStageByStageName(const void *a, const void *b); static bool IsDefaultJoinTree(Node *node); static List * AddShardKeyAndIdFilters(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, TargetEntry *entry, List *existingQuals); /* Stage functions */ static Query * HandleAddFields(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleBucket(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleCount(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleFill(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleLimit(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleProject(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleProjectFind(const bson_value_t *existingValue, const bson_value_t *queryValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleRedact(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleReplaceRoot(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleReplaceWith(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleSample(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleSkip(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleSort(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleSortByCount(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleUnset(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleUnwind(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleDistinct(const StringView *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleGeoNear(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static Query * HandleMatchAggregationStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context); static bool RequiresPersistentCursorFalse(const bson_value_t *pipelineValue); static bool RequiresPersistentCursorTrue(const bson_value_t *pipelineValue); static bool RequiresPersistentCursorLimit(const bson_value_t *pipelineValue); static bool RequiresPersistentCursorSkip(const bson_value_t *pipelineValue); static bool CanInlineLookupStageProjection(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); static bool CanInlineLookupStageUnset(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); static bool CanInlineLookupStageUnwind(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); static bool CanInlineLookupStageTrue(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); static void PreCheckChangeStreamPipelineStages(const bson_value_t *pipelineValue, const AggregationPipelineBuildContext * context); static bool CanInlineLookupStageMatch(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet); static bool CheckFuncExprBsonDollarProjectGeonear(const FuncExpr *funcExpr); static void ValidateQueryTreeForMatchStage(const Query *query); static void RewriteFillToSetWindowFieldsSpec(const bson_value_t *fillSpec, bool *hasSortBy, bool *onlyHasValueFill, bson_value_t *sortSpec, bson_value_t *addFieldsForValueFill, bson_value_t *setWindowFieldsSpec, bson_value_t *partitionByFields); static void TryOptimizeAggregationPipelines(List **aggregationStages, AggregationPipelineBuildContext *context); #define COMPATIBLE_CHANGE_STREAM_STAGES_COUNT 8 const char *CompatibleChangeStreamPipelineStages[COMPATIBLE_CHANGE_STREAM_STAGES_COUNT] = { "$match", "$project", "$addFields", "$replaceRoot", "$replaceWith", "$set", "$unset", "$redact" }; static const AggregationStageDefinition LookupUnwindStageDefinition = { .stage = "$lookupUnwind", .mutateFunc = &HandleLookupUnwind, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = &CanInlineLookupStageLookup, /* Lookup preserves order of the Left collection */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_LookupUnwind, }; /* Stages and their definitions sorted by name. * Please keep this list sorted. */ static const AggregationStageDefinition StageDefinitions[] = { { .stage = "$_internalInhibitOptimization", .mutateFunc = &HandleInternalInhibitOptimization, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageTrue, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Internal_InhibitOptimization, }, { .stage = "$addFields", .mutateFunc = &HandleAddFields, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = &CanInlineLookupStageProjection, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_AddFields, }, { .stage = "$bucket", .mutateFunc = &HandleBucket, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Bucket, }, { .stage = "$bucketAuto", .mutateFunc = &HandleBucketAuto, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_BucketAuto, }, { .stage = "$changeStream", .mutateFunc = &HandleChangeStream, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = true, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = PreCheckChangeStreamPipelineStages, .allowBaseShardTablePushdown = false, .stageEnum = Stage_ChangeStream, }, { .stage = "$collStats", .mutateFunc = &HandleCollStats, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_CollStats, }, { .stage = "$count", .mutateFunc = &HandleCount, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* Changes the projector - can't be inlined */ .canInlineLookupStageFunc = NULL, /* Count changes the output format */ .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Count, }, { .stage = "$currentOp", .mutateFunc = &HandleCurrentOp, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* Changes the projector - can't be inlined */ .canInlineLookupStageFunc = NULL, /* currentOp changes the output format */ .preservesStableSortOrder = false, .canHandleAgnosticQueries = true, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_CurrentOp, }, { .stage = "$densify", .mutateFunc = &HandleDensify, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Densify, }, { .stage = "$documents", .mutateFunc = &HandleDocumentsStage, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = true, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_Documents, }, { .stage = "$facet", .mutateFunc = &HandleFacet, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* Changes the projector - can't be inlined */ .canInlineLookupStageFunc = NULL, /* Count changes the output format (object_agg) so no prior sorts */ .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_Facet, }, { .stage = "$fill", .mutateFunc = &HandleFill, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Fill, }, { .stage = "$geoNear", .mutateFunc = &HandleGeoNear, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_GeoNear, }, { .stage = "$graphLookup", .mutateFunc = &HandleGraphLookup, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_GraphLookup, }, { .stage = "$group", .mutateFunc = &HandleGroup, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* Changes the projector - can't be inlined */ .canInlineLookupStageFunc = NULL, /* Count changes the output format (group) so no prior sorts * are valid after this*/ .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Group, }, { .stage = "$indexStats", .mutateFunc = &HandleIndexStats, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_IndexStats, }, { .stage = "$inverseMatch", .mutateFunc = &HandleInverseMatch, .requiresPersistentCursor = &RequiresPersistentCursorFalse, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageTrue, /* inverse match does not change the output format */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_InverseMatch, }, { .stage = "$limit", .mutateFunc = &HandleLimit, .requiresPersistentCursor = &RequiresPersistentCursorLimit, /* Cannot be inlined - needs to happen *after* the join */ .canInlineLookupStageFunc = NULL, /* Limit does not change the output format */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Limit, }, { .stage = "$listLocalSessions", .mutateFunc = NULL, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = true, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_ListLocalSessions, }, { .stage = "$listSessions", .mutateFunc = NULL, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_ListSessions, }, { .stage = "$lookup", .mutateFunc = &HandleLookup, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = &CanInlineLookupStageLookup, /* Lookup preserves order of the Left collection */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_Lookup, }, { .stage = "$match", .mutateFunc = &HandleMatchAggregationStage, .requiresPersistentCursor = &RequiresPersistentCursorFalse, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageMatch, /* Match does not change the output format */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Match, }, { .stage = "$merge", .mutateFunc = &HandleMerge, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = true, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_Merge, }, { .stage = "$out", .mutateFunc = &HandleOut, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = true, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_Out, }, { .stage = "$project", .mutateFunc = &HandleProject, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = &CanInlineLookupStageProjection, /* Project does not change the output format */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Project, }, { .stage = "$redact", .mutateFunc = &HandleRedact, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Redact, }, { .stage = "$replaceRoot", .mutateFunc = &HandleReplaceRoot, .requiresPersistentCursor = &RequiresPersistentCursorFalse, /* Changes document structure - can never be inlined */ .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_ReplaceRoot, }, { .stage = "$replaceWith", .mutateFunc = &HandleReplaceWith, .requiresPersistentCursor = &RequiresPersistentCursorFalse, /* Changes document structure - can never be inlined */ .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_ReplaceWith, }, { .stage = "$sample", .mutateFunc = &HandleSample, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* Needs to be applied post-join - should not be inlined */ .canInlineLookupStageFunc = NULL, /* Sample is effectively a Random orderby - Prior sorts are invalid */ .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Sample, }, { .stage = "$search", .mutateFunc = &HandleSearch, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageTrue, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Search, }, { .stage = "$searchMeta", .mutateFunc = NULL, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_SearchMeta, }, { .stage = "$set", .mutateFunc = &HandleAddFields, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = &CanInlineLookupStageProjection, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Set, }, { .stage = "$setWindowFields", .mutateFunc = &HandleSetWindowFields, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_SetWindowFields, }, { .stage = "$skip", .mutateFunc = &HandleSkip, .requiresPersistentCursor = &RequiresPersistentCursorSkip, /* Cannot be inlined - needs to happen *after* the join */ .canInlineLookupStageFunc = NULL, /* Skip does not change the output format */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Skip, }, { .stage = "$sort", .mutateFunc = &HandleSort, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageTrue, /* Sorting determines the current ordering state */ .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Sort, }, { .stage = "$sortByCount", .mutateFunc = &HandleSortByCount, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_SortByCount, }, { .stage = "$unionWith", .mutateFunc = &HandleUnionWith, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = NULL, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = false, .stageEnum = Stage_UnionWith, }, { .stage = "$unset", .mutateFunc = &HandleUnset, .requiresPersistentCursor = &RequiresPersistentCursorFalse, .canInlineLookupStageFunc = &CanInlineLookupStageUnset, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = true, .isOutputStage = false, .pipelineCheckFunc = NULL, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Unset, }, { .stage = "$unwind", .mutateFunc = &HandleUnwind, .requiresPersistentCursor = &RequiresPersistentCursorTrue, .canInlineLookupStageFunc = &CanInlineLookupStageUnwind, .preservesStableSortOrder = true, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .allowBaseShardTablePushdown = true, .stageEnum = Stage_Unwind, }, { .stage = "$vectorSearch", .mutateFunc = &HandleNativeVectorSearch, .requiresPersistentCursor = &RequiresPersistentCursorTrue, /* can always be inlined since it doesn't change the projector */ .canInlineLookupStageFunc = &CanInlineLookupStageTrue, .preservesStableSortOrder = false, .canHandleAgnosticQueries = false, .isProjectTransform = false, .isOutputStage = false, .pipelineCheckFunc = NULL, /* $vectorSearch is needed to be executed withing custom scan boundaries see EvaluateMetaSearchScore in vector/vector_utilities.c */ .allowBaseShardTablePushdown = false, .stageEnum = Stage_VectorSearch, } }; static const int AggregationStageCount = sizeof(StageDefinitions) / sizeof(AggregationStageDefinition); static const int MaxEvenFunctionArguments = ((int) (FUNC_MAX_ARGS / 2)) * 2; PG_FUNCTION_INFO_V1(command_bson_aggregation_pipeline); PG_FUNCTION_INFO_V1(command_api_collection); PG_FUNCTION_INFO_V1(command_aggregation_support); PG_FUNCTION_INFO_V1(documentdb_core_bson_to_bson); inline static void EnsureTopLevelNumberFieldType(const char *fieldName, const bson_value_t *value) { if (!BsonValueIsNumber(value)) { ThrowTopLevelTypeMismatchError(fieldName, BsonTypeName( value->value_type), "number"); } } /* * Creates a Var in the query representing the 'document' column of a documentdb_data table. */ inline static Var * CreateDocumentVar(void) { /* the only Var in the Query context (if any) */ Index varno = 1; /* not lives in a subquery */ Index varlevelsup = 0; return makeVar(varno, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_ATTR_NUMBER, BsonTypeId(), DOCUMENT_DATA_TABLE_DOCUMENT_VAR_TYPMOD, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_COLLATION, varlevelsup); } /* * Creates a Var in the query representing the 'document' column of a documentdb_data table. */ inline static Var * CreateChangeStreamDocumentVar(void) { /* the only Var in the Query context (if any) */ Index varno = 1; /* not lives in a subquery */ Index varlevelsup = 0; return makeVar(varno, DOCUMENT_CHANGE_STREAM_TABLE_DOCUMENT_VAR_ATTR_NUMBER, BsonTypeId(), DOCUMENT_DATA_TABLE_DOCUMENT_VAR_TYPMOD, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_COLLATION, varlevelsup); } /* * Creates a Var in the query representing the 'document' column of a documentdb_data table. */ inline static Var * CreateChangeStreamContinuationtVar(void) { /* the only Var in the Query context (if any) */ Index varno = 1; /* not lives in a subquery */ Index varlevelsup = 0; return makeVar(varno, DOCUMENT_CHANGE_STREAM_TABLE_CONTINUATION_VAR_ATTR_NUMBER, BsonTypeId(), DOCUMENT_DATA_TABLE_DOCUMENT_VAR_TYPMOD, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_COLLATION, varlevelsup); } /* * Helper function to limit the number of aggregation stages in a pipeline. */ inline static void CheckMaxAllowedAggregationStages(int numberOfStages) { if (numberOfStages > MaxAggregationStagesAllowed) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION7749501), errmsg( "The pipeline length cannot exceed a maximum of %d stages.", MaxAggregationStagesAllowed))); } } /* * command_bson_aggregation_pipeline is a wrapper function that carries with it the * aggregation pipeline for a query. This is replaced in the planner and so shouldn't * ever be called in the runtime. */ Datum command_bson_aggregation_pipeline(PG_FUNCTION_ARGS) { /* dumbest possible implementation: assume 1% of rows are returned */ ereport(ERROR, (errmsg( "bson_aggregation function should have been processed by the planner. This is an internal error"))); PG_RETURN_BOOL(false); } /* * The core Collection function. Represents a query: * e.g. SELECT * from ApiSchema.collection(). */ Datum command_api_collection(PG_FUNCTION_ARGS) { ereport(ERROR, (errmsg( "Collection function should have been simplified during planning. " "Collection function should be only used in a FROM clause"))); } /* * This function currently is pseudo-deprecated */ Datum command_aggregation_support(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(NIL); } /* * Converts a documentdb_core.bson to a bson. */ Datum documentdb_core_bson_to_bson(PG_FUNCTION_ARGS) { return PG_GETARG_DATUM(0); } /* * Common utility function for parsing a batchSize argument for find/aggregate/getMore */ void SetBatchSize(const char *fieldName, const bson_value_t *value, QueryData *queryData) { EnsureTopLevelNumberFieldType(fieldName, value); /* Batchsize can be double - as long as it converts to int (which it treats as floor) */ queryData->batchSize = BsonValueAsInt32(value); if (queryData->batchSize < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("BatchSize value must be non-negative, but received: %d", queryData->batchSize))); } } /* * Common utility function for parsing a the namespace (Collection) argument for find/aggregate * Updates the cursor state with the namespaceName 'db.coll' */ const char * CreateNamespaceName(text *databaseName, const StringView *collectionName) { char *databaseString = VARDATA_ANY(databaseName); uint32_t databaseLength = VARSIZE_ANY_EXHDR(databaseName); /* Format for database.collection */ uint32_t totalLength = databaseLength + 1 + collectionName->length + 1; char *finalString = palloc(totalLength); memcpy(finalString, databaseString, databaseLength); finalString[databaseLength] = '.'; memcpy(&finalString[databaseLength + 1], collectionName->string, collectionName->length); finalString[totalLength - 1] = 0; return finalString; } static void ProcessIndexHint(bson_iter_t *iterator, bson_value_t *targetHintValue) { ReportFeatureUsage(FEATURE_INDEX_HINT); if (EnableIndexHintSupport) { const bson_value_t *value = bson_iter_value(iterator); if (value->value_type == BSON_TYPE_UTF8 || value->value_type == BSON_TYPE_DOCUMENT) { /* The mongo index is specified as a utf8 string index name */ *targetHintValue = *value; } else { EnsureTopLevelFieldType("hint", iterator, BSON_TYPE_UTF8); } } } /* * Validates the sanity of an aggregation pipeline. * For this we simply create the query from it and let the validation take place. */ void ValidateAggregationPipeline(text *databaseDatum, const StringView *baseCollection, const bson_value_t *pipelineValue) { AggregationPipelineBuildContext validationContext = { 0 }; validationContext.databaseNameDatum = databaseDatum; pg_uuid_t *collectionUuid = NULL; bson_value_t *indexHint = NULL; Query *validationQuery = GenerateBaseTableQuery(databaseDatum, baseCollection, collectionUuid, indexHint, &validationContext); List *stages = ExtractAggregationStages(pipelineValue, &validationContext); validationQuery = MutateQueryWithPipeline(validationQuery, stages, &validationContext); pfree(validationQuery); } /* * Core logic that takes a pipeline array specified by pipelineValue, * and updates the "query" with the pipeline stages' effects. * The mutated query is returned as an output. */ Query * MutateQueryWithPipeline(Query *query, List *aggregationStages, AggregationPipelineBuildContext *context) { /* Apply stage transformations now */ ListCell *stageCell = NULL; foreach(stageCell, aggregationStages) { AggregationStage *stage = (AggregationStage *) lfirst(stageCell); const AggregationStageDefinition *definition = stage->stageDefinition; const char *stageName = definition->stage; if (query->jointree->fromlist == NIL && !definition->canHandleAgnosticQueries) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg( "The value '{aggregate: 1}' is invalid for the '%s'; a collection input is necessary.", stageName), errdetail_log( "The value '{aggregate: 1}' is invalid for the '%s'; a collection input is necessary.", stageName))); } /* If the prior stage needed to be pushed to a sub-query before the next * stage is processed, then add a subquery stage */ if (context->requiresSubQuery) { query = MigrateQueryToSubQuery(query, context); } if (context->requiresSubQueryAfterProject) { context->requiresSubQueryAfterProject = false; if (definition->isProjectTransform) { /* Push to subquery on the next stage */ context->requiresSubQuery = true; } else { if (context->requiresTailableCursor) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Cannot use tailable cursor with stage %s", stageName))); } /* Not a project, so push to a subquery */ query = MigrateQueryToSubQuery(query, context); } } query = definition->mutateFunc(&stage->stageValue, query, context); context->requiresPersistentCursor = context->requiresPersistentCursor || definition->requiresPersistentCursor(&stage->stageValue); if (!definition->preservesStableSortOrder) { context->sortSpec.value_type = BSON_TYPE_EOD; } context->stageNum++; } /* Agnostic query with no stages */ if (context->stageNum == 0 && query->jointree->fromlist == NULL) { /* make the query Select NULL::bson LIMIT 0 */ query->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(0), false, true); } return query; } /* * Given a query and an aggregation pipeline mutates the query * to match the contents of the provided aggregation pipeline. */ Query * GenerateAggregationQuery(text *database, pgbson *aggregationSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = database; context.optimizePipelineStages = true; queryData->cursorKind = QueryCursorType_Unspecified; bson_iter_t aggregationIterator; PgbsonInitIterator(aggregationSpec, &aggregationIterator); StringView collectionName = { 0 }; bson_value_t pipelineValue = { 0 }; bson_value_t let = { 0 }; bson_value_t indexHint = { 0 }; pg_uuid_t *collectionUuid = NULL; bool explain = false; bool hasCursor = false; bool isCollectionAgnosticQuery = false; while (bson_iter_next(&aggregationIterator)) { StringView keyView = bson_iter_key_string_view(&aggregationIterator); const bson_value_t *value = bson_iter_value(&aggregationIterator); if (StringViewEqualsCString(&keyView, "aggregate")) { if (BSON_ITER_HOLDS_NUMBER(&aggregationIterator) && BsonValueAsDouble(value) == 1.0) { /* Collection agnostic aggregate */ isCollectionAgnosticQuery = true; } else { EnsureTopLevelFieldType("aggregate", &aggregationIterator, BSON_TYPE_UTF8); collectionName.string = bson_iter_utf8(&aggregationIterator, &collectionName.length); } } else if (StringViewEqualsCString(&keyView, "pipeline")) { EnsureTopLevelFieldType("pipeline", &aggregationIterator, BSON_TYPE_ARRAY); pipelineValue = *value; } else if (StringViewEqualsCString(&keyView, "cursor")) { hasCursor = true; ParseCursorDocument(&aggregationIterator, queryData); } else if (StringViewEqualsCString(&keyView, "allowDiskUse")) { /* We otherwise ignore this for now (TODO Support this) */ EnsureTopLevelFieldType("allowDiskUse", &aggregationIterator, BSON_TYPE_BOOL); } else if (StringViewEqualsCString(&keyView, "explain")) { /* We otherwise ignore this for now */ EnsureTopLevelFieldType("explain", &aggregationIterator, BSON_TYPE_BOOL); explain = bson_iter_bool(&aggregationIterator); } else if (StringViewEqualsCString(&keyView, "hint")) { ProcessIndexHint(&aggregationIterator, &indexHint); } else if (StringViewEqualsCString(&keyView, "let")) { ReportFeatureUsage(FEATURE_LET_TOP_LEVEL); bool hasValue = EnsureTopLevelFieldTypeNullOkUndefinedOK("let", &aggregationIterator, BSON_TYPE_DOCUMENT); if (hasValue) { let = *value; } } else if (StringViewEqualsCString(&keyView, "collectionUUID")) { EnsureTopLevelFieldType("collectionUUID", &aggregationIterator, BSON_TYPE_BINARY); if (value->value.v_binary.subtype != BSON_SUBTYPE_UUID || value->value.v_binary.data_len != 16) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "field collectionUUID must be a UUID"))); } collectionUuid = palloc(sizeof(pg_uuid_t)); memcpy(&collectionUuid->data, value->value.v_binary.data, 16); } else if (StringViewEqualsCString(&keyView, "collation")) { ReportFeatureUsage(FEATURE_COLLATION); if (EnableCollation) { /* Ignore collation until enabled for aggregate */ EnsureTopLevelFieldType("collation", &aggregationIterator, BSON_TYPE_DOCUMENT); ParseAndGetCollationString(value, context.collationString); } } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { EnsureTopLevelFieldIsNumberLike("find.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (StringViewEqualsCString(&keyView, "$db")) { /* BackCompat: Ignore if provided top level */ if (context.databaseNameDatum == NULL) { /* Extract the database out of $db */ EnsureTopLevelFieldType("$db", &aggregationIterator, BSON_TYPE_UTF8); uint32_t databaseLength = 0; const char *databaseName = bson_iter_utf8(&aggregationIterator, &databaseLength); context.databaseNameDatum = cstring_to_text_with_len(databaseName, databaseLength); database = context.databaseNameDatum; } } else if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("%*s is not a recognized field", keyView.length, keyView.string))); } } if (context.databaseNameDatum == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required field database must be valid"))); } if (pipelineValue.value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required variable pipeline must be valid"))); } if (collectionName.length == 0 && !isCollectionAgnosticQuery) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required variables aggregate must be valid"))); } bool isWriteCommand = false; pgbson *parsedVariables = ParseAndGetTopLevelVariableSpec(&let, &queryData-> timeSystemVariables, isWriteCommand); context.variableSpec = (Expr *) MakeBsonConst(parsedVariables); List *aggregationStages = ExtractAggregationStages(&pipelineValue, &context); Query *query; if (isCollectionAgnosticQuery) { query = GenerateBaseAgnosticQuery(context.databaseNameDatum, &context); } else { query = GenerateBaseTableQuery(context.databaseNameDatum, &collectionName, collectionUuid, &indexHint, &context); } /* Remember the base query - this will be needed since we need to update the cursor function on the base RTE */ Query *baseQuery = query; query = MutateQueryWithPipeline(query, aggregationStages, &context); if (context.requiresTailableCursor) { queryData->cursorKind = QueryCursorType_Tailable; /* * change stream is the only stage that requires a tailable cursor. * Since change stream manages the continuation handling by itself, * there is no need to add cursor params to the query. */ addCursorParams = false; } else if (query->commandType == CMD_MERGE) { /* CMD_MERGE is case when pipeline has output stage ($merge or $out) result will be always single batch. */ ThrowIfServerOrTransactionReadOnly(); queryData->cursorKind = QueryCursorType_SingleBatch; } else if (queryData->cursorKind == QueryCursorType_Unspecified) { queryData->cursorKind = context.requiresPersistentCursor || isCollectionAgnosticQuery ? QueryCursorType_Persistent : QueryCursorType_Streamable; } queryData->namespaceName = context.namespaceName; /* This is validated *after* the pipeline parsing happens */ if (!hasCursor && !explain && addCursorParams) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The 'cursor' option is required, except for aggregate with explain"))); } if (addCursorParams) { bool addCursorAsConst = false; AddCursorFunctionsToQuery(query, baseQuery, queryData, &context, addCursorAsConst); } else if (EnableCursorsOnAggregationQueryRewrite) { bool addCursorAsConst = true; AddCursorFunctionsToQuery(query, baseQuery, queryData, &context, addCursorAsConst); } else if (queryData->cursorKind == QueryCursorType_Tailable) { AddQualifierForTailableQuery(query, baseQuery, queryData, &context); } return query; } inline static bool IsNaturalSortHint(const bson_value_t *hintValue) { if (hintValue == NULL || hintValue->value_type != BSON_TYPE_DOCUMENT) { return false; } pgbsonelement indexHintElement; bson_iter_t indexHintIterator; BsonValueInitIterator(hintValue, &indexHintIterator); return hintValue->value_type == BSON_TYPE_DOCUMENT && TryGetSinglePgbsonElementFromBsonIterator(&indexHintIterator, &indexHintElement) && strcmp(indexHintElement.path, "$natural") == 0 && BsonValueAsInt32(&indexHintElement.bsonValue) != 0; } /* * Applies a find spec against a query and expands it into the underlying SQL AST. */ Query * GenerateFindQuery(text *databaseDatum, pgbson *findSpec, QueryData *queryData, bool addCursorParams, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = databaseDatum; /* Queries start out as persistent cursor */ queryData->cursorKind = QueryCursorType_Unspecified; bson_iter_t findIterator; PgbsonInitIterator(findSpec, &findIterator); StringView collectionName = { 0 }; bool hasFind = false; bool hasNtoreturn = false; bool hasBatchSize = false; bool isNtoReturnSupported = IsNtoReturnSupported(); bson_value_t filter = { 0 }; bson_value_t limit = { 0 }; bson_value_t projection = { 0 }; bson_value_t sort = { 0 }; bson_value_t skip = { 0 }; bson_value_t let = { 0 }; bson_value_t indexHint = { 0 }; pg_uuid_t *collectionUuid = NULL; /* For finds, we can generally query the shard directly if available. */ context.allowShardBaseTable = true; while (bson_iter_next(&findIterator)) { StringView keyView = bson_iter_key_string_view(&findIterator); const bson_value_t *value = bson_iter_value(&findIterator); /* * Key off of the first character to avoid the several "if/else" checks for every * key. If any letter becomes to long, we should add another lookup table * block to speed up the comparison. */ switch (keyView.string[0]) { case '$': { if (StringViewEqualsCString(&keyView, "$db")) { /* BackCompat: Ignore if provided top level */ if (context.databaseNameDatum == NULL) { /* Extract the database out of $db */ EnsureTopLevelFieldType("$db", &findIterator, BSON_TYPE_UTF8); uint32_t databaseLength = 0; const char *databaseName = bson_iter_utf8(&findIterator, &databaseLength); context.databaseNameDatum = cstring_to_text_with_len(databaseName, databaseLength); databaseDatum = context.databaseNameDatum; } continue; } goto default_find_case; } case 'a': { if (StringViewEqualsCString(&keyView, "allowDiskUse") || StringViewEqualsCString(&keyView, "allowPartialResults")) { /* We ignore this for now (TODO Support this?) */ continue; } goto default_find_case; } case 'b': { if (StringViewEqualsCString(&keyView, "batchSize")) { /* In case ntoreturn is present and has been parsed already we throw this error */ if (!isNtoReturnSupported && hasNtoreturn) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'limit' or 'batchSize' fields can not be set with 'ntoreturn' field"))); } SetBatchSize("batchSize", value, queryData); hasBatchSize = !isNtoReturnSupported; continue; } goto default_find_case; } case 'c': { if (StringViewEqualsCString(&keyView, "collation")) { ReportFeatureUsage(FEATURE_COLLATION); if (EnableCollation) { /* Ignore collation until enabled for find */ EnsureTopLevelFieldType("collation", &findIterator, BSON_TYPE_DOCUMENT); ParseAndGetCollationString(value, context.collationString); } continue; } goto default_find_case; } case 'f': { if (StringViewEqualsCString(&keyView, "find")) { hasFind = true; EnsureTopLevelFieldType("find", &findIterator, BSON_TYPE_UTF8); collectionName.string = bson_iter_utf8(&findIterator, &collectionName.length); continue; } else if (StringViewEqualsCString(&keyView, "filter")) { EnsureTopLevelFieldType("filter", &findIterator, BSON_TYPE_DOCUMENT); filter = *value; continue; } goto default_find_case; } case 'h': { if (StringViewEqualsCString(&keyView, "hint")) { ProcessIndexHint(&findIterator, &indexHint); continue; } goto default_find_case; } case 'l': { if (StringViewEqualsCString(&keyView, "limit")) { /* In case ntoreturn is present and has been parsed already we throw this error */ if (!isNtoReturnSupported && hasNtoreturn) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'limit' or 'batchSize' fields can not be set with 'ntoreturn' field"))); } /* Validation handled in the stage processing */ limit = *value; continue; } else if (StringViewEqualsCString(&keyView, "let")) { ReportFeatureUsage(FEATURE_LET_TOP_LEVEL); EnsureTopLevelFieldType("let", &findIterator, BSON_TYPE_DOCUMENT); let = *value; continue; } else if (StringViewEqualsCString(&keyView, "lsid")) { /* Commonly ignored spec, add here to not pay cost of bsearch for hotpaths */ continue; } goto default_find_case; } case 'm': { if (StringViewEqualsCString(&keyView, "min") || StringViewEqualsCString(&keyView, "max")) { /* We ignore this for now (TODO Support this?) */ continue; } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { EnsureTopLevelFieldIsNumberLike("find.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); continue; } goto default_find_case; } case 'n': { if (StringViewEqualsCString(&keyView, "ntoreturn")) { /* In case hook requests, we support ntoreturn */ if (isNtoReturnSupported) { SetBatchSize("ntoreturn", value, queryData); } /* In case ntoreturn is the last option in the find command we first check if batchSize or limit is present */ if (limit.value_type != BSON_TYPE_EOD || hasBatchSize) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "'limit' or 'batchSize' fields can not be set with 'ntoreturn' field"))); } hasNtoreturn = !isNtoReturnSupported; continue; } else if (StringViewEqualsCString(&keyView, "noCursorTimeout")) { /* We ignore this for now (TODO Support this?) */ continue; } goto default_find_case; } case 'p': { if (StringViewEqualsCString(&keyView, "projection")) { /* Validation handled in the stage processing */ /* TODO - Protocol behavior validates projection even if collection is not present */ /* to align with that we may need to validate projection here, like $elemMatch envolve $jsonSchema */ projection = *value; continue; } goto default_find_case; } case 'r': { if (StringViewEqualsCString(&keyView, "returnKey")) { if (BsonValueAsBool(value)) { /* fail if returnKey or showRecordId are present and with boolean value true, else ignore */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("The key %.*s is currently not supported", keyView.length, keyView.string), errdetail_log( "The key %.*s is currently not supported", keyView.length, keyView.string))); } continue; } goto default_find_case; } case 's': { if (StringViewEqualsCString(&keyView, "skip")) { /* Validation handled in the stage processing */ skip = *value; continue; } else if (StringViewEqualsCString(&keyView, "sort")) { EnsureTopLevelFieldType("sort", &findIterator, BSON_TYPE_DOCUMENT); sort = *value; continue; } else if (StringViewEqualsCString(&keyView, "singleBatch")) { EnsureTopLevelFieldType("singleBatch", &findIterator, BSON_TYPE_BOOL); if (value->value.v_bool) { queryData->cursorKind = QueryCursorType_SingleBatch; } continue; } else if (StringViewEqualsCString(&keyView, "showRecordId")) { if (BsonValueAsBool(value)) { /* fail if returnKey or showRecordId are present and with boolean value true, else ignore */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("The key %.*s is currently not supported", keyView.length, keyView.string), errdetail_log( "The key %.*s is currently not supported", keyView.length, keyView.string))); } continue; } goto default_find_case; } default_find_case: default: { if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("%.*s is an unknown field", keyView.length, keyView.string), errdetail_log("%.*s is an unknown field", keyView.length, keyView.string))); } } } } if (context.databaseNameDatum == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Required field database must be valid"))); } if (!hasFind) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Required element \"find\" missing."))); } else if (collectionName.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Collection name must not be left empty."))); } /* In case only ntoreturn is present we give a different error.*/ if (!isNtoReturnSupported && hasNtoreturn) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5746102), errmsg("Command is not supported for cluster version >= 5.1"))); } /* Find supports negative limit (as well as count) */ if (BsonValueIsNumber(&limit)) { int64_t intValue = BsonValueAsInt64(&limit); if (intValue < 0) { limit.value.v_int64 = labs(intValue); limit.value_type = BSON_TYPE_INT64; } else if (intValue == 0) { limit.value_type = BSON_TYPE_EOD; } } bool isWriteCommand = false; pgbson *parsedVariables = ParseAndGetTopLevelVariableSpec(&let, &queryData-> timeSystemVariables, isWriteCommand); context.variableSpec = (Expr *) MakeBsonConst(parsedVariables); if (sort.value_type != BSON_TYPE_EOD) { context.requiresPersistentCursor = true; } if (RequiresPersistentCursorSkip(&skip)) { context.requiresPersistentCursor = true; } if (RequiresPersistentCursorLimit(&limit)) { context.requiresPersistentCursor = true; } if (indexHint.value_type != BSON_TYPE_EOD) { /* Validate hint */ if (!IsNaturalSortHint(&indexHint) && IsNaturalSortHint(&sort)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Cannot provide natural sort with a non-natural index hint"))); } } Query *query = GenerateBaseTableQuery(context.databaseNameDatum, &collectionName, collectionUuid, &indexHint, &context); Query *baseQuery = query; /* First apply match */ if (filter.value_type != BSON_TYPE_EOD) { query = HandleMatch(&filter, query, &context); context.stageNum++; } /* Then apply sort */ if (sort.value_type != BSON_TYPE_EOD) { query = HandleSort(&sort, query, &context); context.stageNum++; } /* Then do skip and then limit */ if (skip.value_type != BSON_TYPE_EOD) { query = HandleSkip(&skip, query, &context); context.stageNum++; } if (limit.value_type != BSON_TYPE_EOD) { query = HandleLimit(&limit, query, &context); context.stageNum++; } /* finally update projection */ if (projection.value_type != BSON_TYPE_EOD) { query = HandleProjectFind(&projection, &filter, query, &context); } /* $near and $nearSphere add sort clause to query, for them we need persistent cursor. */ if (query->sortClause) { context.requiresPersistentCursor = true; } if (rt_fetch(1, query->rtable)->rtekind != RTE_RELATION) { /* Any attempts to push to a subquery should invalidate point read plans */ context.isPointReadQuery = false; } if (queryData->cursorKind == QueryCursorType_Unspecified) { queryData->cursorKind = context.requiresPersistentCursor ? QueryCursorType_Persistent : QueryCursorType_Streamable; } queryData->namespaceName = context.namespaceName; if (context.isPointReadQuery && context.allowShardBaseTable && queryData->batchSize >= 1) { /* If we're still targeting the local shard && we have a point read * Mark the query for a point read plan. */ queryData->cursorKind = QueryCursorType_PointRead; } if (addCursorParams) { bool addCursorAsConst = false; AddCursorFunctionsToQuery(query, baseQuery, queryData, &context, addCursorAsConst); } else if (EnableCursorsOnAggregationQueryRewrite) { bool addCursorAsConst = true; AddCursorFunctionsToQuery(query, baseQuery, queryData, &context, addCursorAsConst); } return query; } /* * Generates a query that is akin to $count command protocol. */ Query * GenerateCountQuery(text *databaseDatum, pgbson *countSpec, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = databaseDatum; bson_iter_t countIterator; PgbsonInitIterator(countSpec, &countIterator); StringView collectionName = { 0 }; bson_value_t filter = { 0 }; bson_value_t limit = { 0 }; bson_value_t skip = { 0 }; bson_value_t indexHint = { 0 }; pg_uuid_t *collectionUuid = NULL; bool hasQueryModifier = false; context.allowShardBaseTable = true; while (bson_iter_next(&countIterator)) { StringView keyView = bson_iter_key_string_view(&countIterator); const bson_value_t *value = bson_iter_value(&countIterator); if (StringViewEqualsCString(&keyView, "count")) { EnsureTopLevelFieldType("count", &countIterator, BSON_TYPE_UTF8); collectionName.string = bson_iter_utf8(&countIterator, &collectionName.length); } else if (StringViewEqualsCString(&keyView, "query")) { EnsureTopLevelFieldType("query", &countIterator, BSON_TYPE_DOCUMENT); filter = *value; hasQueryModifier = true; } else if (StringViewEqualsCString(&keyView, "limit")) { /* Validation handled in the stage processing */ limit = *value; hasQueryModifier = true; } else if (StringViewEqualsCString(&keyView, "skip")) { /* Validation handled in the stage processing */ skip = *value; hasQueryModifier = true; } else if (StringViewEqualsCString(&keyView, "hint")) { ProcessIndexHint(&countIterator, &indexHint); } else if (StringViewEqualsCString(&keyView, "fields")) { /* We ignore this for now (TODO Support this?) */ } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { EnsureTopLevelFieldIsNumberLike("distinct.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("%.*s is an unknown field", keyView.length, keyView.string))); } } if (collectionName.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Collection name must not be left empty."))); } Query *query = GenerateBaseTableQuery(databaseDatum, &collectionName, collectionUuid, &indexHint, &context); /* * the count() query which has no filter/skip/limit/etc can be done via an estimatedDocumentCount * In this case, we rewrite the query as a collStats aggregation query with a project to make it the appropriate output. */ if (!hasQueryModifier && context.mongoCollection != NULL) { /* Collection exists, get a collStats: { "count": {} } */ pgbson_writer collStatsWriter; pgbson_writer countWriter; PgbsonWriterInit(&collStatsWriter); PgbsonWriterStartDocument(&collStatsWriter, "count", 5, &countWriter); PgbsonWriterEndDocument(&collStatsWriter, &countWriter); pgbson *collStatsSpec = PgbsonWriterGetPgbson(&collStatsWriter); bson_value_t collStatsSpecValue = ConvertPgbsonToBsonValue(collStatsSpec); query = HandleCollStats(&collStatsSpecValue, query, &context); context.stageNum++; /* Add a $project where the count field is written as 'n' */ pgbson_writer projectWriter; PgbsonWriterInit(&projectWriter); PgbsonWriterAppendUtf8(&projectWriter, "n", 1, "$count"); pgbson *projectSpec = PgbsonWriterGetPgbson(&projectWriter); bson_value_t projectSpecValue = ConvertPgbsonToBsonValue(projectSpec); query = HandleProject(&projectSpecValue, query, &context); } else { /* First apply match */ if (filter.value_type != BSON_TYPE_EOD) { query = HandleMatch(&filter, query, &context); context.stageNum++; } /* Then do skip and then limit */ if (skip.value_type != BSON_TYPE_EOD) { if (skip.value_type != BSON_TYPE_NULL) { if (!BsonValueIsNumber(&skip)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH)), errmsg( "The BSON field 'skip' has an incorrect type '%s'; it should be one of the following types: [long, int, decimal, double].", BsonTypeName(skip.value_type)), errdetail_log( "The BSON field 'skip' has an incorrect type '%s'; it should be one of the following types: [long, int, decimal, double].", BsonTypeName(skip.value_type))); } int64_t skipValue = BsonValueAsInt64(&skip); if (skipValue < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51024)), errmsg( "The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '%ld'.", skipValue), errdetail_log( "The BSON field 'skip' requires a value greater than or equal to 0, but the given value is '%ld'.", skipValue)); } query = HandleSkip(&skip, query, &context); } context.stageNum++; context.requiresPersistentCursor = true; } /* Count supports negative limit */ if (BsonValueIsNumber(&limit)) { int64_t intValue = BsonValueAsInt64(&limit); if (intValue < 0) { limit.value.v_int64 = labs(intValue); limit.value_type = BSON_TYPE_INT64; } else if (intValue == 0) { limit.value_type = BSON_TYPE_EOD; } } if (limit.value_type != BSON_TYPE_EOD) { query = HandleLimit(&limit, query, &context); context.stageNum++; if (RequiresPersistentCursorLimit(&limit)) { context.requiresPersistentCursor = true; } } /* Now add a count stage that writes to the field "n" */ bson_value_t countValue = { 0 }; countValue.value_type = BSON_TYPE_UTF8; countValue.value.v_utf8.len = 1; countValue.value.v_utf8.str = "n"; query = HandleCount(&countValue, query, &context); } /* Now add the "ok": 1 as an add fields stage. */ pgbson_writer addFieldsWriter; PgbsonWriterInit(&addFieldsWriter); PgbsonWriterAppendDouble(&addFieldsWriter, "ok", 2, 1); pgbson *addFieldsSpec = PgbsonWriterGetPgbson(&addFieldsWriter); bson_value_t addFieldsValue = ConvertPgbsonToBsonValue(addFieldsSpec); query = HandleSimpleProjectionStage(&addFieldsValue, query, &context, "$addFields", BsonDollaMergeDocumentsFunctionOid(), NULL, NULL); return query; } /* * Generates a query that is akin to the $distinct command protocol. */ Query * GenerateDistinctQuery(text *databaseDatum, pgbson *distinctSpec, bool setStatementTimeout) { AggregationPipelineBuildContext context = { 0 }; context.databaseNameDatum = databaseDatum; bson_iter_t distinctIter; PgbsonInitIterator(distinctSpec, &distinctIter); StringView collectionName = { 0 }; bool hasDistinct = false; bson_value_t filter = { 0 }; bson_value_t indexHint = { 0 }; StringView distinctKey = { 0 }; pg_uuid_t *collectionUuid = NULL; while (bson_iter_next(&distinctIter)) { StringView keyView = bson_iter_key_string_view(&distinctIter); const bson_value_t *value = bson_iter_value(&distinctIter); if (StringViewEqualsCString(&keyView, "distinct")) { hasDistinct = true; EnsureTopLevelFieldType("distinct", &distinctIter, BSON_TYPE_UTF8); collectionName.string = bson_iter_utf8(&distinctIter, &collectionName.length); } else if (StringViewEqualsCString(&keyView, "query")) { if (!BSON_ITER_HOLDS_NULL(&distinctIter)) { EnsureTopLevelFieldType("query", &distinctIter, BSON_TYPE_DOCUMENT); filter = *value; } } else if (StringViewEqualsCString(&keyView, "key")) { /* Validation handled in the stage processing */ EnsureTopLevelFieldType("key", &distinctIter, BSON_TYPE_UTF8); distinctKey.string = bson_iter_utf8(&distinctIter, &distinctKey.length); } else if (setStatementTimeout && StringViewEqualsCString(&keyView, "maxTimeMS")) { EnsureTopLevelFieldIsNumberLike("distinct.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (!IsCommonSpecIgnoredField(keyView.string)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("%.*s is an unknown field", keyView.length, keyView.string))); } } if (!hasDistinct) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Required element \"distinct\" missing."))); } else if (collectionName.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Collection name must not be left empty."))); } if (distinctKey.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("A distinct key value must not be left empty."))); } if (strlen(distinctKey.string) != distinctKey.length) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_KEYCANNOTCONTAINNULLBYTE), errmsg( "A distinct key value cannot contain any embedded null characters"))); } Query *query = GenerateBaseTableQuery(databaseDatum, &collectionName, collectionUuid, &indexHint, &context); /* First apply match */ if (filter.value_type != BSON_TYPE_EOD) { query = HandleMatch(&filter, query, &context); context.stageNum++; } query = HandleDistinct(&distinctKey, query, &context); return query; } /* * Parses the GetMore wire protocol spec and returns the cursorId associated * with it. Also updates the queryData with cursor related information. */ int64_t ParseGetMore(text **databaseName, pgbson *getMoreSpec, QueryData *queryData, bool setStatementTimeout) { bson_iter_t cursorSpecIter; PgbsonInitIterator(getMoreSpec, &cursorSpecIter); int64_t cursorId = 0; StringView nameView = { 0 }; while (bson_iter_next(&cursorSpecIter)) { const char *pathKey = bson_iter_key(&cursorSpecIter); if (strcmp(pathKey, "getMore") == 0) { EnsureTopLevelFieldType("getMore", &cursorSpecIter, BSON_TYPE_INT64); const bson_value_t *value = bson_iter_value(&cursorSpecIter); cursorId = BsonValueAsInt64(value); } else if (strcmp(pathKey, "batchSize") == 0) { const bson_value_t *value = bson_iter_value(&cursorSpecIter); SetBatchSize("batchSize", value, queryData); } else if (strcmp(pathKey, "collection") == 0) { const bson_value_t *value = bson_iter_value(&cursorSpecIter); EnsureTopLevelFieldValueType("collection", value, BSON_TYPE_UTF8); nameView = (StringView) { .string = value->value.v_utf8.str, .length = value->value.v_utf8.len }; } else if (setStatementTimeout && strcmp(pathKey, "maxTimeMS") == 0) { const bson_value_t *value = bson_iter_value(&cursorSpecIter); EnsureTopLevelFieldIsNumberLike("getMore.maxTimeMS", value); SetExplicitStatementTimeout(BsonValueAsInt32(value)); } else if (strcmp(pathKey, "$db") == 0) { /* BackCompat: Ignore if provided top level */ if (*databaseName == NULL) { /* Extract the database out of $db */ EnsureTopLevelFieldType("$db", &cursorSpecIter, BSON_TYPE_UTF8); uint32_t databaseLength = 0; const char *databaseStr = bson_iter_utf8(&cursorSpecIter, &databaseLength); *databaseName = cstring_to_text_with_len(databaseStr, databaseLength); } } else if (!IsCommonSpecIgnoredField(pathKey)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("%s is an unrecognized field name", pathKey))); } } if (nameView.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), errmsg("Collection name must not be left empty."))); } if (*databaseName == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Required element \"$db\" missing."))); } queryData->namespaceName = CreateNamespaceName(*databaseName, &nameView); if (cursorId == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Required element \"getMore\" missing."))); } return cursorId; } /* * Given an aggregation pipeline that is specified for a * $lookup Stage, validates whether the stages can be * safely pulled up to the top level join. * This is true if there's no intersection between those * stages and the lookup's localField which is specified * on the right table. */ bool CanInlineLookupPipeline(const bson_value_t *pipeline, const StringView *lookupPath, bool hasLet, pgbson **inlinedPipeline, pgbson **nonInlinedPipeline, bool *pipelineIsValid) { bson_iter_t pipelineIter; BsonValueInitIterator(pipeline, &pipelineIter); bool canInline = true; pgbson_writer inlineWriter; pgbson_writer nonInlineWriter; PgbsonWriterInit(&inlineWriter); PgbsonWriterInit(&nonInlineWriter); pgbson_array_writer inlineArrayWriter; pgbson_array_writer nonInlineArrayWriter; PgbsonWriterStartArray(&inlineWriter, "", 0, &inlineArrayWriter); PgbsonWriterStartArray(&nonInlineWriter, "", 0, &nonInlineArrayWriter); int pipelineSize = 0; while (bson_iter_next(&pipelineIter)) { pipelineSize++; if (!BSON_ITER_HOLDS_DOCUMENT(&pipelineIter)) { canInline = false; *pipelineIsValid = false; continue; } const bson_value_t *stageValue = bson_iter_value(&pipelineIter); pgbsonelement stageElement; if (!TryGetBsonValueToPgbsonElement(stageValue, &stageElement)) { canInline = false; *pipelineIsValid = false; continue; } /* Now handle each stage */ AggregationStageDefinition *definition = (AggregationStageDefinition *) bsearch( stageElement.path, StageDefinitions, AggregationStageCount, sizeof(AggregationStageDefinition), CompareStageByStageName); if (definition == NULL) { canInline = false; *pipelineIsValid = false; continue; } /* Prior stage can't be inlined */ if (!canInline) { PgbsonArrayWriterWriteValue(&nonInlineArrayWriter, stageValue); continue; } /* The inline function is not specified for this stage, * We can't inline. */ if (definition->canInlineLookupStageFunc == NULL) { canInline = false; PgbsonArrayWriterWriteValue(&nonInlineArrayWriter, stageValue); continue; } if (!definition->canInlineLookupStageFunc(&stageElement.bsonValue, lookupPath, hasLet)) { canInline = false; PgbsonArrayWriterWriteValue(&nonInlineArrayWriter, stageValue); continue; } PgbsonArrayWriterWriteValue(&inlineArrayWriter, stageValue); } /* * Validate number of stages for lookup nested pipeline, because after this we divide it * into a set of inline and non-inlined pipelines. */ CheckMaxAllowedAggregationStages(pipelineSize); PgbsonWriterEndArray(&inlineWriter, &inlineArrayWriter); PgbsonWriterEndArray(&nonInlineWriter, &nonInlineArrayWriter); *pipelineIsValid = true; *inlinedPipeline = PgbsonWriterGetPgbson(&inlineWriter); *nonInlinedPipeline = PgbsonWriterGetPgbson(&nonInlineWriter); return canInline; } /* * Processes simple projections (dollar_project, dollar_add_fields etc). * This just updates the targetEntry with the new projector. * functionOidWithLet can be NULL if the stage doesn't support let */ Query * HandleSimpleProjectionStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, const char *stageName, Oid functionOid, Oid (*functionOidWithLet)(void), Oid (*functionOidWithLetAndCollation)(void)) { if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40272), errmsg("The %s specification stage must correspond to an object", stageName))); } /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; /* Projection followed by projection - try to inline */ if (TryInlineProjection((Node *) currentProjection, functionOid, existingValue)) { return query; } pgbson *docBson = PgbsonInitFromBuffer( (char *) existingValue->value.v_doc.data, existingValue->value.v_doc.data_len); Const *addFieldsProcessed = MakeBsonConst(docBson); List *args; /* if valid collation is specified, we use the function with both variables and collation support, if applicable */ /* else if only variableSpec is given, we use the function with let support, if applicable */ /* else the base function */ Const *collationConst = IsCollationApplicable(context->collationString) ? MakeTextConst(context->collationString, strlen(context->collationString)) : NULL; if (collationConst && functionOidWithLetAndCollation) { args = list_make4(currentProjection, addFieldsProcessed, context->variableSpec ? context->variableSpec : (Expr *) makeNullConst(BsonTypeId(), -1, InvalidOid), collationConst); functionOid = functionOidWithLetAndCollation(); } else if (context->variableSpec && functionOidWithLet) { args = list_make3(currentProjection, addFieldsProcessed, context->variableSpec); functionOid = functionOidWithLet(); } else { args = list_make2(currentProjection, addFieldsProcessed); if (functionOid == BsonDollaMergeDocumentsFunctionOid()) { bool overrideArrays = false; args = lappend(args, MakeBoolValueConst(overrideArrays)); } } FuncExpr *resultExpr = makeFuncExpr( functionOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) resultExpr; return query; } /** * Parses the input document for FirstN and LastN group expression operator and extracts the value for input and n. * @param inputDocument: input document for the $firstN operator * @param input: this is a pointer which after parsing will hold array expression * @param elementsToFetch: this is a pointer which after parsing will hold n i.e. how many elements to fetch for result * @param opName: this contains the name of the operator for error msg formatting purposes. This value is supposed to be $firstN/$lastN. */ void ParseInputForNGroupAccumulators(const bson_value_t *inputDocument, bson_value_t *input, bson_value_t *elementsToFetch, const char *opName) { if (inputDocument->value_type != BSON_TYPE_DOCUMENT) { if (strcmp(opName, "$maxN") == 0 || strcmp(opName, "$minN") == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787900), errmsg( "Specification should be an object type; encountered %s: %s", opName, BsonValueToJsonForLogging(inputDocument)), errdetail_log( "specification must be defined as an object; opname: %s type found: %s", opName, BsonTypeName(inputDocument->value_type)))); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787801), errmsg( "specification must be defined as an object, but the provided input was %s :%s", opName, BsonValueToJsonForLogging(inputDocument)), errdetail_log( "pecification must be defined as an object; opname: %s type found :%s", opName, BsonTypeName(inputDocument->value_type)))); } } bson_iter_t docIter; BsonValueInitIterator(inputDocument, &docIter); while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "input") == 0) { *input = *bson_iter_value(&docIter); } else if (strcmp(key, "n") == 0) { *elementsToFetch = *bson_iter_value(&docIter); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787901), errmsg("%s encountered an unrecognized argument value: %s", opName, key), errdetail_log( "%s encountered an unrecognized argument", opName))); } } /** * Validation check to see if input and elements to fetch are present otherwise throw error. */ if (input->value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787907), errmsg("%s needs to have an 'input' field", opName), errdetail_log( "%s needs to have an 'input' field", opName))); } if (elementsToFetch->value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787906), errmsg("%s requires an 'n' field", opName), errdetail_log( "%s requires an 'n' field", opName))); } } /** * Parses the input document for $top(N) and $bottom(N) group expression operator and extracts the value for output, sortBy and n. * @param inputDocument: input document for the operator * @param output: this is a pointer which after parsing will hold array expression * @param sortSpec: this is a pointer which after parsing will hold the sortBy expression * @param elementsToFetch: this is a pointer which after parsing will hold n i.e. how many elements to fetch for result * @param opName: this contains the name of the operator for error msg formatting purposes. This value is supposed to be $firstN/$lastN. */ void ParseInputDocumentForTopAndBottom(const bson_value_t *inputDocument, bson_value_t *output, bson_value_t *elementsToFetch, bson_value_t *sortSpec, const char *opName) { if (inputDocument->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788001), errmsg( "specification must be defined as an object, but the provided input was %s :%s", opName, BsonValueToJsonForLogging(inputDocument)), errdetail_log( "specification must be defined as an object; opname: %s type found :%s", opName, BsonTypeName(inputDocument->value_type)))); } bson_iter_t docIter; BsonValueInitIterator(inputDocument, &docIter); while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "output") == 0) { *output = *bson_iter_value(&docIter); } else if (strcmp(key, "n") == 0) { *elementsToFetch = *bson_iter_value(&docIter); } else if (strcmp(key, "sortBy") == 0) { *sortSpec = *bson_iter_value(&docIter); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788002), errmsg("Unrecognized argument passed to %s: '%s'", opName, key), errdetail_log( "%s found an unknown argument", opName))); } } /** * Validation check to see if input and elements to fetch are present otherwise throw error. */ if (elementsToFetch->value_type == BSON_TYPE_EOD && (strcmp(opName, "$topN") == 0 || strcmp(opName, "$bottomN") == 0)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788003), errmsg("Required value for 'n' is not provided"), errdetail_log( "%s requires an 'n' field", opName))); } if (elementsToFetch->value_type != BSON_TYPE_EOD && (strcmp(opName, "$top") == 0 || strcmp(opName, "$bottom") == 0)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788002), errmsg("Unrecognized argument provided to %s 'n'", opName), errdetail_log( "Unrecognized argument provided to %s 'n'", opName))); } if (output->value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788004), errmsg("The 'output' parameter is missing a required value"), errdetail_log( "%s requires an 'output' field", opName))); } if (sortSpec->value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788005), errmsg("No value provided for 'sortBy'"), errdetail_log( "%s needs a 'sortBy' parameter", opName))); } else if (sortSpec->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5788604), errmsg( "Expected 'sortBy' parameter to already contain an object within the provided arguments to %s", opName), errdetail_log( "Expected 'sortBy' parameter to already contain an object within the provided arguments to %s", opName))); } } /** * Parses the input document for $median and $percentile accumulator operator, extracts input, p and methods. * @param inputDocument: input document for the operator * @param input: this is a pointer which after parsing will hold input expression * @param p: this is a pointer which after parsing will hold the p, i.e. the percentile array value * @param method: this is a pointer which after parsing will hold method * @param isMedianOp: this contains the name of the operator for error msg formatting purposes. */ void ParseInputDocumentForMedianAndPercentile(const bson_value_t *inputDocument, bson_value_t *input, bson_value_t *p, bson_value_t *method, bool isMedianOp) { const char *opName = isMedianOp ? "$median" : "$percentile"; if (inputDocument->value_type != BSON_TYPE_DOCUMENT) { int errorcode = isMedianOp ? ERRCODE_DOCUMENTDB_LOCATION7436100 : ERRCODE_DOCUMENTDB_LOCATION7429703; ereport(ERROR, (errcode(errorcode), errmsg( "Specification must be an object type, but instead received %s with type: %s", opName, BsonTypeName(inputDocument->value_type)), errdetail_log( "The %s format requires an object", opName))); } bson_iter_t docIter; BsonValueInitIterator(inputDocument, &docIter); while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "input") == 0) { *input = *bson_iter_value(&docIter); } else if (strcmp(key, "method") == 0) { *method = *bson_iter_value(&docIter); } /* only evaluate p for $percentile */ else if (!isMedianOp && strcmp(key, "p") == 0) { *p = *bson_iter_value(&docIter); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field named with operators '$%s.%s' is not recognized.", opName, key), errdetail_log("%s found an unknown argument", opName))); } } /* Verify that all necessary fields exist */ char *keyName; if (((input->value_type == BSON_TYPE_EOD) && (keyName = "input")) || (!isMedianOp && (p->value_type == BSON_TYPE_EOD) && (keyName = "p")) || ((method->value_type == BSON_TYPE_EOD) && (keyName = "method"))) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40414), errmsg( "The BSON field '$%s.%s' is required but is currently missing from the data structure", opName, keyName))); } /* validate method: can only be 'approximate' for now */ if (method->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "BSON field %s.method has an incorrect type %s; it should be of type 'string'", opName, BsonTypeName(method->value_type)), errdetail_log( "BSON field '$%s.method' expects type 'string'", opName))); } if (strcmp(method->value.v_utf8.str, "approximate") != 0) { /* Same error message for both $median and $percentile */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Currently only 'approximate' can be used as percentile 'method'"))); } /* set p for $median to 0.5 */ if (isMedianOp) { p->value_type = BSON_TYPE_DOUBLE; p->value.v_double = 0.5; } } /** * This function validates and throws error in case bson type is not a numeric > 0 and less than max value of int64 i.e. 9223372036854775807 */ void ValidateElementForNGroupAccumulators(bson_value_t *elementsToFetch, const char *opName) { switch (elementsToFetch->value_type) { case BSON_TYPE_INT32: case BSON_TYPE_INT64: case BSON_TYPE_DOUBLE: case BSON_TYPE_DECIMAL128: { if (IsBsonValueNaN(elementsToFetch)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31109), errmsg( "Unable to convert out-of-range value %s into a long type", BsonValueToJsonForLogging(elementsToFetch)))); } if (IsBsonValueInfinity(elementsToFetch) != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31109), errmsg( "Unable to convert out-of-range value %s into a long type", BsonValueToJsonForLogging(elementsToFetch)))); } if (!IsBsonValueFixedInteger(elementsToFetch)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787903), errmsg( "Expected 'integer' type for 'n' but found '%s' for value '%s'", BsonTypeName(elementsToFetch->value_type), BsonValueToJsonForLogging(elementsToFetch)), errdetail_log( "Expected 'integer' type for 'n' but found '%s' for value '%s'", BsonTypeName(elementsToFetch->value_type), BsonValueToJsonForLogging(elementsToFetch)))); } /* This is done as elements to fetch must only be int64. */ bool throwIfFailed = true; elementsToFetch->value.v_int64 = BsonValueAsInt64WithRoundingMode( elementsToFetch, ConversionRoundingMode_Floor, throwIfFailed); elementsToFetch->value_type = BSON_TYPE_INT64; if (elementsToFetch->value.v_int64 <= 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787908), errmsg( "The value of 'n' must be strictly greater than 0, but the current value is %s", BsonValueToJsonForLogging(elementsToFetch)), errdetail_log( "'n' cannot be less than 0, but the current value is %ld", elementsToFetch->value.v_int64))); } if (elementsToFetch->value.v_int64 > 10) { if (strncmp(opName, "$lastN", 6) == 0) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_LASTN_GT10); } else if ((strncmp(opName, "$firstN", 7) == 0)) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_FIRSTN_GT10); } } break; } default: { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5787902), errmsg( "Expected 'integer' type for 'n' but found '%s' for value '%s'", BsonTypeName(elementsToFetch->value_type), BsonValueToJsonForLogging(elementsToFetch)), errdetail_log( "Expected 'integer' type for 'n' but found '%s' for value '%s'", BsonTypeName(elementsToFetch->value_type), BsonValueToJsonForLogging(elementsToFetch)))); } } } /* * Given valid aggregation pipeline stages, this function returns the stage enum at the given position. */ Stage GetAggregationStageAtPosition(const List *aggregationStages, int position) { if (list_length(aggregationStages) <= position) { return Stage_Invalid; } AggregationStage *stage = list_nth(aggregationStages, position); return stage->stageDefinition->stageEnum; } /* * Mutates the query for the $addFields stage */ static Query * HandleAddFields(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_ADD_FIELDS); return HandleSimpleProjectionStage(existingValue, query, context, "$addFields", BsonDollarAddFieldsFunctionOid(), BsonDollarAddFieldsWithLetFunctionOid, BsonDollarAddFieldsWithLetAndCollationFunctionOid); } /* * Handles the $bucket stage. * Converts to a $group stage with $_bucketInternal operator to handle bucket specific logics. */ static Query * HandleBucket(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg( "Collation is currently unsupported in the $bucket stage."))); } ReportFeatureUsage(FEATURE_STAGE_BUCKET); bson_value_t groupSpec = { 0 }; RewriteBucketGroupSpec(existingValue, &groupSpec); query = HandleGroup(&groupSpec, query, context); return query; } /** * Processes the $fill Pipeine stage. * $fill will be rewritten to $setWindowFields and $addFields. $setWindowFields will be used to process `linear` and `locf`; * $addFields will be used to process const based fill. The rewritten query will be divided into two cases: * * 1) If method-fill is specified in output, the query will be rewritten with $setWindowFields. * 2) If only value-fill is specified in output, the query will be rewritten with $addFields, $sort. * * Example 1: * * $fill: { * partitionBy: { part : "$part"}, * sortBy: { key: 1 }, * output: { * field1 : { method: "linear" }, * field2 : { method: "locf" }, * field3 : { value: ""} * } * } * * ==> * * [ * { * $setWindowFields: { * partitionBy: { part : "$part"}, * sortBy: { key: 1 }, * output: { * field1: { * $linearFill: "$field1" * }, * field2: { * $locf: "$field2" * } * field3: { * $_internal_constFill: { * path: "$field3", * value: "" * } * } * } * } * }, * ] * * Example 2: * * $fill: { * partitionBy: { part : "$part" }, * sortBy: { key : 1}, * output: { * field1 : { value: ""} * } * } * * ==> * [ * { $sort: { key : 1}}, * { $addFields: { field1: { $ifNull: ["$field1", ""]}}}, * ] * */ static Query * HandleFill(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_FILL); if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg( "collation is not supported in the $fill stage yet."))); } bool hasSortBy = false; bool onlyHasValueFill = true; bool enableInternalWindowOperator = true; bson_value_t sortSpec = { 0 }; bson_value_t addFieldsForValueFill = { 0 }; bson_value_t setWindowFieldsSpec = { 0 }; bson_value_t partitionByFields = { 0 }; RewriteFillToSetWindowFieldsSpec(existingValue, &hasSortBy, &onlyHasValueFill, &sortSpec, &addFieldsForValueFill, &setWindowFieldsSpec, &partitionByFields); /* if only const based fill exists, we rewrite it into $addFields directly */ if (onlyHasValueFill) { if (hasSortBy) { query = HandleSort(&sortSpec, query, context); } query = HandleAddFields(&addFieldsForValueFill, query, context); return query; } Expr *partitionByFieldsExpr = NULL; /* construct partitionByFieldsExpr if it exists */ if (partitionByFields.value_type != BSON_TYPE_EOD) { /* convert partitionByFields to pgbson */ pgbson *partitionByFieldsDoc = BsonValueToDocumentPgbson(&partitionByFields); TargetEntry *firstEntry = linitial(query->targetList); Expr *docExpr = (Expr *) firstEntry->expr; RangeTblEntry *rte = linitial(query->rtable); bool isRTEDataTable = (rte->rtekind == RTE_RELATION || rte->rtekind == RTE_FUNCTION); if (isRTEDataTable && IsPartitionByFieldsOnShardKey(partitionByFieldsDoc, context->mongoCollection)) { partitionByFieldsExpr = (Expr *) makeVar(((Var *) docExpr)->varno, DOCUMENT_DATA_TABLE_SHARD_KEY_VALUE_VAR_ATTR_NUMBER, INT8OID, -1, InvalidOid, 0); } else { Const *partitionConst = MakeBsonConst(partitionByFieldsDoc); partitionByFieldsExpr = (Expr *) makeFuncExpr( BsonExpressionPartitionByFieldsGetFunctionOid(), BsonTypeId(), list_make2( docExpr, partitionConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } } query = HandleSetWindowFieldsCore(&setWindowFieldsSpec, query, context, partitionByFieldsExpr, enableInternalWindowOperator); return query; } static void RewriteFillToSetWindowFieldsSpec(const bson_value_t *fillSpec, bool *hasSortBy, bool *onlyHasValueFill, bson_value_t *sortSpec, bson_value_t *addFieldsForValueFill, bson_value_t *setWindowFieldsSpec, bson_value_t *partitionByFields) { if (fillSpec->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40201), errmsg( "The operator $fill requires an object as its argument, but a value of type %s was provided instead.", BsonTypeName(fillSpec->value_type)), errdetail_log( "The operator $fill requires an object as its argument, but a value of type %s was provided instead.", BsonTypeName(fillSpec->value_type)))); } bson_iter_t fillIter; BsonValueInitIterator(fillSpec, &fillIter); bson_value_t partitionBy = { 0 }; bson_value_t sortBy = { 0 }; bson_value_t output = { 0 }; bool hasPartitionBy = false; bool hasPartitionByFields = false; while (bson_iter_next(&fillIter)) { const char *key = bson_iter_key(&fillIter); const bson_value_t *value = bson_iter_value(&fillIter); if (strcmp(key, "partitionBy") == 0) { partitionBy = *value; hasPartitionBy = true; } else if (strcmp(key, "partitionByFields") == 0) { *partitionByFields = *value; hasPartitionByFields = true; } else if (strcmp(key, "sortBy") == 0) { sortBy = *value; *hasSortBy = true; } else if (strcmp(key, "output") == 0) { output = *value; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field named '$fill.%s' is not recognized as a valid field.", key), errdetail_log( "The BSON field named '$fill.%s' is not recognized as a valid field.", key))); } } if (hasPartitionBy && hasPartitionByFields) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION6050204), errmsg( "Only one of 'partitionBy' or 'partitionByFields' is allowed when using the '$fill'."), errdetail_log( "Only one of 'partitionBy' or 'partitionByFields' is allowed when using the '$fill'."))); } /* output is a required field in $fill, check it */ /* Required fields check */ if (output.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40414), errmsg( "Required field '$fill.output' is missing"))); } /* validate partitionByFields spec */ if (hasPartitionByFields) { bson_iter_t partitionByFieldsIter; BsonValueInitIterator(partitionByFields, &partitionByFieldsIter); while (bson_iter_next(&partitionByFieldsIter)) { const bson_value_t *fieldBson = bson_iter_value(&partitionByFieldsIter); EnsureTopLevelFieldValueType("partitionByFields", fieldBson, BSON_TYPE_UTF8); EnsureStringValueNotDollarPrefixed(fieldBson->value.v_utf8.str, fieldBson->value.v_utf8.len); } } pgbson_writer swfWriter; PgbsonWriterInit(&swfWriter); if (partitionBy.value_type != BSON_TYPE_EOD) { PgbsonWriterAppendValue(&swfWriter, "partitionBy", 11, &partitionBy); } if (sortBy.value_type != BSON_TYPE_EOD) { PgbsonWriterAppendValue(&swfWriter, "sortBy", 6, &sortBy); } pgbson_writer addFieldsSpecWriter; PgbsonWriterInit(&addFieldsSpecWriter); pgbson_writer outputWriter; PgbsonWriterStartDocument(&swfWriter, "output", 6, &outputWriter); bson_iter_t outputIter; BsonValueInitIterator(&output, &outputIter); while (bson_iter_next(&outputIter)) { const char *fieldName = bson_iter_key(&outputIter); StringInfo dollarFieldName = makeStringInfo(); appendStringInfo(dollarFieldName, "$%s", fieldName); const bson_value_t *fieldSpec = bson_iter_value(&outputIter); bson_iter_t fieldSpecIter; BsonValueInitIterator(fieldSpec, &fieldSpecIter); while (bson_iter_next(&fieldSpecIter)) { const char *key = bson_iter_key(&fieldSpecIter); const bson_value_t *expr = bson_iter_value(&fieldSpecIter); pgbson_writer outputFieldSpecWriter; PgbsonWriterStartDocument(&outputWriter, fieldName, strlen(fieldName), &outputFieldSpecWriter); if (strcmp(key, "method") == 0) { *onlyHasValueFill = false; EnsureTopLevelFieldValueType("method", expr, BSON_TYPE_UTF8); if (strcmp(expr->value.v_utf8.str, "linear") == 0) { PgbsonWriterAppendUtf8(&outputFieldSpecWriter, "$linearFill", 11, dollarFieldName->data); } else if (strcmp(expr->value.v_utf8.str, "locf") == 0) { PgbsonWriterAppendUtf8(&outputFieldSpecWriter, "$locf", 5, dollarFieldName->data); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION6050202), errmsg( "The method must be specified as either locf or linear"), errdetail_log( "The method must be specified as either locf or linear"))); } } else if (strcmp(key, "value") == 0) { /** * convert into output of $setWindowFields. * We will do this in current iteration to avoid multiple iterations, even if it may not be used if only value fill exists. */ pgbson_writer constFillSpecWriter; PgbsonWriterStartDocument(&outputFieldSpecWriter, "$_internal_constFill", 20, &constFillSpecWriter); PgbsonWriterAppendUtf8(&constFillSpecWriter, "path", 4, dollarFieldName->data); PgbsonWriterAppendValue(&constFillSpecWriter, "value", 5, expr); PgbsonWriterEndDocument(&outputFieldSpecWriter, &constFillSpecWriter); /** * convert value fill to $addFields. * We will do this in current iteration to avoid multiple iterations, even if it may not be used if method fill exists as well. */ pgbson_writer addFieldItemWriter; PgbsonWriterStartDocument(&addFieldsSpecWriter, fieldName, strlen( fieldName), &addFieldItemWriter); pgbson_array_writer ifNullWriter; PgbsonWriterStartArray(&addFieldItemWriter, "$ifNull", 7, &ifNullWriter); PgbsonArrayWriterWriteUtf8(&ifNullWriter, dollarFieldName->data); PgbsonArrayWriterWriteValue(&ifNullWriter, expr); PgbsonWriterEndArray(&addFieldItemWriter, &ifNullWriter); PgbsonWriterEndDocument(&addFieldsSpecWriter, &addFieldItemWriter); } else { /* Field name is not supported */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "The BSON field named '$fill.%s' is not recognized as a valid field.", key), errdetail_log( "The BSON field named '$fill.%s' is not recognized as a valid field.", key))); } PgbsonWriterEndDocument(&outputWriter, &outputFieldSpecWriter); } pfree(dollarFieldName->data); } /** * construct $sort spec for sortBy if only value fill exists. * * Example: * * $fill: { * sortBy: { key1 : 1, key2 : 1 }, * } * * ==> * * "$sort": {"sortKey": { "key1": 1, "key2": 1 }} */ if (*onlyHasValueFill && *hasSortBy) { pgbson_writer sortSpecWriter; PgbsonWriterInit(&sortSpecWriter); /* iterator each field in sortBy and write to sortKey */ bson_iter_t sortByIter; BsonValueInitIterator(&sortBy, &sortByIter); while (bson_iter_next(&sortByIter)) { const char *fieldName = bson_iter_key(&sortByIter); const bson_value_t *fieldValue = bson_iter_value(&sortByIter); PgbsonWriterAppendValue(&sortSpecWriter, fieldName, strlen(fieldName), fieldValue); } *sortSpec = ConvertPgbsonToBsonValue(PgbsonWriterGetPgbson(&sortSpecWriter)); } PgbsonWriterEndDocument(&swfWriter, &outputWriter); *setWindowFieldsSpec = ConvertPgbsonToBsonValue(PgbsonWriterGetPgbson(&swfWriter)); *addFieldsForValueFill = ConvertPgbsonToBsonValue(PgbsonWriterGetPgbson( &addFieldsSpecWriter)); } /* * Mutates the query for the $project stage */ static Query * HandleProject(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_PROJECT); return HandleSimpleProjectionStage(existingValue, query, context, "$project", BsonDollarProjectFunctionOid(), BsonDollarProjectWithLetFunctionOid, BsonDollarProjectWithLetAndCollationFunctionOid); } /* * Mutates the query for the $redact stage */ static Query * HandleRedact(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_REDACT); Const *redactSpec; Const *redactSpecText; if (existingValue->value_type == BSON_TYPE_DOCUMENT) { redactSpec = MakeBsonConst(PgbsonInitFromDocumentBsonValue(existingValue)); redactSpecText = MakeTextConst("", 0); } else if (existingValue->value_type == BSON_TYPE_UTF8) { redactSpec = MakeBsonConst(PgbsonInitEmpty()); redactSpecText = MakeTextConst( existingValue->value.v_utf8.str, existingValue->value.v_utf8.len); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION17053), errmsg( "$redact's parameter must be an expression or string valued as $$KEEP, $$DESCEND, and $$PRUNE, but input as '%s'.", BsonValueToJsonForLogging(existingValue)), errdetail_log( "$redact's parameter must be an expression or string valued as $$KEEP, $$DESCEND, and $$PRUNE."))); } /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; /* * There is two kind of $redact parameters: * a. like "$redact: { $cond: { if: { $eq: ["$stuff", "valid"] }, then: "$$KEEP", else: "$$PRUNE" }" * existingValue->value_type is BSON_TYPE_DOCUMENT. * BsonDollarRedactWithLetFunctionOid() takes four parameters, currentProjection, redactSpec, redactSpecText, variableSpec. * redactSpec is the document and redactSpecText is empty * b. like "$redact: "$$PRUNE" * existingValue->value.value_type is BSON_TYPE_UTF8. * In this case, BsonDollarRedactWithLetFunctionOid() takes four parameters, currentProjection, redactSpec, redactSpecText, variableSpec. * redactSpec is set to empty document and redactSpecText is the string. * * If context->collationString is valid, we use BsonDollarRedactWithLetAndCollationFunctionOid() instead. * BsonDollarRedactWithLetAndCollationFunctionOid() takes five parameters, currentProjection, redactSpec, redactSpecText, variableSpec, * collationString. */ List *args = NIL; Oid funcOid = BsonDollarRedactWithLetFunctionOid(); Expr *variableSpecConst = context->variableSpec == NULL ? (Expr *) makeNullConst(BsonTypeId(), -1, InvalidOid) : context->variableSpec; if (IsCollationApplicable(context->collationString)) { Const *collationStringConst = MakeTextConst(context->collationString, strlen( context->collationString)); args = list_make5(currentProjection, redactSpec, redactSpecText, variableSpecConst, collationStringConst); funcOid = BsonDollarRedactWithLetAndCollationFunctionOid(); } else { args = list_make4(currentProjection, redactSpec, redactSpecText, variableSpecConst); } FuncExpr *resultExpr = makeFuncExpr( funcOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) resultExpr; /* The following code addresses nested redact handling. * The behavior of $lookup and $facet with nested redact differs from $unionWith: * $lookup and $facet result in unexpected null values, use COALESCE to return an empty value instead. * For $unionWith, it will still return null as redact does. */ if (context->nestedPipelineLevel > 0 && context->parentStageName != ParentStageName_UNIONWITH) { CoalesceExpr *coalesceExpr = makeNode(CoalesceExpr); coalesceExpr->args = list_make2(resultExpr, MakeBsonConst(PgbsonInitEmpty())); coalesceExpr->coalescetype = BsonTypeId(); coalesceExpr->coalescecollid = InvalidOid; firstEntry->expr = (Expr *) coalesceExpr; } return query; } static Query * HandleProjectFind(const bson_value_t *existingValue, const bson_value_t *queryValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_PROJECT_FIND); EnsureTopLevelFieldValueType("projection", existingValue, BSON_TYPE_DOCUMENT); if (IsBsonValueEmptyDocument(existingValue)) { return query; } /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; pgbson *docBson = PgbsonInitFromBuffer( (char *) existingValue->value.v_doc.data, existingValue->value.v_doc.data_len); Const *projectProcessed = MakeBsonConst(docBson); List *args; Oid funcOid = BsonDollarProjectFindFunctionOid(); Const *collationConst = IsCollationApplicable(context->collationString) ? MakeTextConst(context->collationString, strlen(context->collationString)) : NULL; if (collationConst) { pgbson *queryDoc = queryValue->value_type == BSON_TYPE_EOD ? PgbsonInitEmpty() : PgbsonInitFromDocumentBsonValue(queryValue); args = list_make5(currentProjection, projectProcessed, MakeBsonConst(queryDoc), context->variableSpec ? context->variableSpec : (Expr *) makeNullConst(BsonTypeId(), -1, InvalidOid), collationConst); funcOid = BsonDollarProjectFindWithLetAndCollationFunctionOid(); } else if (context->variableSpec) { pgbson *queryDoc = queryValue->value_type == BSON_TYPE_EOD ? PgbsonInitEmpty() : PgbsonInitFromDocumentBsonValue(queryValue); args = list_make4(currentProjection, projectProcessed, MakeBsonConst(queryDoc), context->variableSpec); funcOid = BsonDollarProjectFindWithLetFunctionOid(); } else if (queryValue->value_type == BSON_TYPE_EOD) { args = list_make2(currentProjection, projectProcessed); } else { pgbson *queryDoc = PgbsonInitFromDocumentBsonValue(queryValue); Const *queryDocProcessed = MakeBsonConst(queryDoc); args = list_make3(currentProjection, projectProcessed, queryDocProcessed); } FuncExpr *resultExpr = makeFuncExpr(funcOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) resultExpr; return query; } /* * Mutates the query for the $replaceRoot stage */ static Query * HandleReplaceRoot(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_REPLACE_ROOT); Oid (*replaceRootWithLetAndCollationFuncOid)(void) = BsonDollarReplaceRootWithLetAndCollationFunctionOid; return HandleSimpleProjectionStage(existingValue, query, context, "$replaceRoot", BsonDollarReplaceRootFunctionOid(), &BsonDollarReplaceRootWithLetFunctionOid, replaceRootWithLetAndCollationFuncOid); } /* * Mutates the query for the $skip stage. * If there is a limit, then injects a new subquery and sets the skip * since Skip is processed before limit in PG. */ static Query * HandleSkip(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_SKIP); if (!BsonValueIsNumber(existingValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15972), errmsg("$skip requires a numeric argument"))); } bool checkFixedInteger = true; if (!IsBsonValueUnquantized64BitInteger(existingValue, checkFixedInteger)) { double doubleValue = BsonValueAsDouble(existingValue); ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5107200), errmsg( "Invalid parameter provided to $skip stage: value cannot be expressed as a 64-bit integer $skip: %f", doubleValue))); } int64_t skipValue = BsonValueAsInt64(existingValue); if (skipValue < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5107200), errmsg( "Invalid argument provided to $skip stage: A non-negative numerical value was expected in $skip, but received %ld.", skipValue))); } if (skipValue == 0) { /* Skip 0 can be ignored */ return query; } if (query->limitCount != NULL) { /* Because skip is evaluated first, an existing limit implies a new stage */ query = MigrateQueryToSubQuery(query, context); } if (query->limitOffset != NULL) { Assert(IsA(query->limitOffset, Const)); Const *limitOffset = (Const *) query->limitOffset; /* We already have a skip: Sum up the skips */ limitOffset->constvalue = Int64GetDatum(skipValue + DatumGetInt64( limitOffset->constvalue)); } else { query->limitOffset = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(skipValue), false, true); } /* Postgres applies OFFSET after other layers. Protocol behavior applies it first. to emulate this we need to * Push down a subquery. */ context->requiresSubQuery = true; return query; } /* * Mutates the query for the $limit stage * Simply updates the limit in the current query. */ static Query * HandleLimit(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_LIMIT); if (!BsonValueIsNumber(existingValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15957), errmsg("the limit must be specified as a number"))); } bool checkFixedInteger = true; if (!IsBsonValue64BitInteger(existingValue, checkFixedInteger)) { double doubleValue = BsonValueAsDouble(existingValue); ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5107201), errmsg( "Invalid $limit stage argument: value cannot be represented as a 64-bit integer: $limit: %f", doubleValue))); } int64_t limitValue = BsonValueAsInt64(existingValue); if (limitValue < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5107201), errmsg( "Invalid argument passed to the $skip stage: a non-negative number was expected but received in $limit: %ld", limitValue))); } if (limitValue == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15958), errmsg("The specified limit value must always be positive"))); } if (query->limitCount != NULL) { Assert(IsA(query->limitCount, Const)); Const *limitConst = (Const *) query->limitCount; /* We just take the min of the two */ limitConst->constvalue = Int64GetDatum(Min(limitValue, DatumGetInt64( limitConst->constvalue))); } else { query->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(limitValue), false, true); } /* PG applies projection before LIMIT - consequently if there was an error in the 11th * document and you do limit 10, PG would error out. * This is a nuance that requires a subquery. */ context->requiresSubQuery = true; return query; } /* * Mutates the query for the $match stage. * Simply calls the ExpandQueryOperator similar to the @@ operator. * Also injects a new stage if ther is a LIMIT or a SKIP since the * match needs to apply post-limit. * Applies the match on the current projector. */ Query * HandleMatch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_MATCH); if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15959), errmsg( "The match filter must always be provided as an expression within a object."))); } if (query->limitOffset != NULL || query->limitCount != NULL) { query = MigrateQueryToSubQuery(query, context); } TargetEntry *entry = linitial(query->targetList); BsonQueryOperatorContext filterContext = { 0 }; filterContext.documentExpr = entry->expr; filterContext.inputType = MongoQueryOperatorInputType_Bson; filterContext.simplifyOperators = true; filterContext.coerceOperatorExprIfApplicable = true; filterContext.requiredFilterPathNameHashSet = context->requiredFilterPathNameHashSet; filterContext.variableContext = context->variableSpec; if (EnableCollation) { filterContext.collationString = context->collationString; } bson_iter_t queryDocIterator; BsonValueInitIterator(existingValue, &queryDocIterator); List *quals = CreateQualsFromQueryDocIterator(&queryDocIterator, &filterContext); UpdateQueryOperatorContextSortList(query, filterContext.sortClauses, filterContext.targetEntries); quals = AddShardKeyAndIdFilters(existingValue, query, context, entry, quals); if (query->jointree->quals != NULL) { quals = lappend(quals, query->jointree->quals); } query->jointree->quals = (Node *) make_ands_explicit(quals); return query; } /* * Builds a change stream aggregation query in the form of * SELECT document, continuation FROM changestream_aggregation(args); */ static Query * BuildChangeStreamFunctionQuery(Oid queryFunctionOid, List *queryArgs, bool isMultiRow) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; List *colNames = list_make2(makeString("document"), makeString("continuation")); RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_FUNCTION; rte->relid = InvalidOid; rte->eref = makeAlias("collection", colNames); rte->lateral = false; rte->inFromCl = true; rte->functions = NIL; rte->inh = false; #if PG_VERSION_NUM >= 160000 rte->perminfoindex = 0; #else rte->requiredPerms = ACL_SELECT; #endif rte->rellockmode = AccessShareLock; rte->coltypes = list_make2_oid(BsonTypeId(), BsonTypeId()); rte->coltypmods = list_make2_int(-1, -1); rte->colcollations = list_make2_oid(InvalidOid, InvalidOid); rte->ctename = NULL; rte->ctelevelsup = 0; Param *param = makeNode(Param); param->paramid = 1; param->paramkind = PARAM_EXTERN; param->paramtype = BsonTypeId(); param->paramtypmod = -1; queryArgs = lappend(queryArgs, param); /* Now create the rtfunc*/ FuncExpr *rangeFunc = makeFuncExpr(queryFunctionOid, RECORDOID, queryArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (isMultiRow) { rangeFunc->funcretset = true; } RangeTblFunction *rangeTableFunction = makeNode(RangeTblFunction); rangeTableFunction->funccolcount = 2; rangeTableFunction->funccolnames = colNames; rangeTableFunction->funccoltypes = list_make2_oid(BsonTypeId(), BsonTypeId()); rangeTableFunction->funccoltypmods = list_make2_int(-1, -1); rangeTableFunction->funccolcollations = list_make2_oid(InvalidOid, InvalidOid); rangeTableFunction->funcparams = NULL; rangeTableFunction->funcexpr = (Node *) rangeFunc; /* Add the RTFunc to the RTE */ rte->functions = list_make1(rangeTableFunction); query->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), NULL); Var *documentEntry = makeVar(1, 1, BsonTypeId(), -1, InvalidOid, 0); Var *continuationEntry = makeVar(1, 2, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *documentTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); TargetEntry *continuationTargetEntry = makeTargetEntry((Expr *) continuationEntry, 2, "continuation", false); query->targetList = list_make2(documentTargetEntry, continuationTargetEntry); return query; } /* * Checks if the given string is in the given array of strings. */ static bool StringArrayContains(const char *array[], size_t arraySize, const char *value) { for (size_t i = 0; i < arraySize; i++) { if (strcmp(array[i], value) == 0) { return true; } } return false; } /* * Pre-checks the $changeStream pipeline stages to ensure that only supported stages are added to * the $changestream pipeline, also ensures that $changeStream is the first stage in the pipeline. * This function is called before the pipeline is mutated. It also checks if the feature is enabled. */ static void PreCheckChangeStreamPipelineStages(const bson_value_t *pipelineValue, const AggregationPipelineBuildContext *context) { bson_iter_t pipelineIterator; BsonValueInitIterator(pipelineValue, &pipelineIterator); int stageNum = 0; while (bson_iter_next(&pipelineIterator)) { bson_iter_t documentIterator; /* Any errors here will be handled in MutateQueryWithPipeline*/ if (!BSON_ITER_HOLDS_DOCUMENT(&pipelineIterator) || !bson_iter_recurse(&pipelineIterator, &documentIterator)) { continue; } /* Any errors here will be handled in MutateQueryWithPipeline*/ pgbsonelement stageElement; if (!TryGetSinglePgbsonElementFromBsonIterator(&documentIterator, &stageElement)) { continue; } const char *stageName = stageElement.path; /* The first change should be $changeStream. */ if (stageNum == 0 && strcmp(stageName, "$changeStream") == 0) { continue; } /* Check the next stages to be one of the allowed stages. */ else if (!StringArrayContains(CompatibleChangeStreamPipelineStages, COMPATIBLE_CHANGE_STREAM_STAGES_COUNT, stageName)) { /* * Compatibility Notice: The text in this error string is copied verbatim from MongoDB output * to maintain compatibility with existing tools and scripts that rely on specific error message formats. * Modifying this text may cause unexpected behavior in dependent systems. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_ILLEGALOPERATION), errmsg( "Stage %s is not permitted in a $changeStream pipeline", stageName))); } stageNum++; } } /* * Modifies the query to handle the $changeStream stage. * It forma a query that calls the $changeStream function. * SELECT document, continuation * FROM changestream_aggregation(args); */ Query * HandleChangeStream(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_CHANGE_STREAM); /* Check if change stream feature is available enabled by GUC. */ if (!IsChangeStreamFeatureAvailableAndCompatible()) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Stage $changeStream is not supported yet in native pipeline"), errdetail_log( "Stage $changeStream is not supported yet in native pipeline"))); } EnsureTopLevelFieldValueType("$changeStream", existingValue, BSON_TYPE_DOCUMENT); if (context->mongoCollection != NULL && !StringViewEqualsCString(&context->collectionNameView, context->mongoCollection->name.collectionName)) { /* This represents a view */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTEDONVIEW), errmsg( "$changeStream cannot be used on views."))); } /*Check the first stage and make sure it is $changestream. */ if (context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40602), errmsg( "$changeStream can only be used as the initial stage in the pipeline."))); } Const *databaseConst = makeConst(TEXTOID, -1, InvalidOid, -1, PointerGetDatum(context->databaseNameDatum), false, false); Const *collectionConst = MakeTextConst(context->collectionNameView.string, context->collectionNameView.length); pgbson *bson = PgbsonInitFromDocumentBsonValue(existingValue); List *changeStreamArgs = list_make3(databaseConst, collectionConst, MakeBsonConst(bson)); query = BuildChangeStreamFunctionQuery(ApiChangeStreamAggregationFunctionOid(), changeStreamArgs, true); /* $changeStream pipeline requires a tailable cursor. */ context->requiresTailableCursor = true; return query; } /* * Generates the projection functions expression for grouping stages e.g. $group, $setWindowFields * where the maximum number of arguments can be larger than MaxEvenFunctionArguments. */ Expr * GenerateMultiExpressionRepathExpression(List *repathArgs, bool overrideArrayInProjection) { Assert(repathArgs != NIL && list_length(repathArgs) % 2 == 0); CHECK_FOR_INTERRUPTS(); check_stack_depth(); int numOfArguments = list_length(repathArgs); if (numOfArguments <= MaxEvenFunctionArguments) { return (Expr *) makeFuncExpr(BsonRepathAndBuildFunctionOid(), BsonTypeId(), repathArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } /* * need to create multiple bson_merge_documents(bson_repath_and_build(...), bson_repath_and_build(...)) expressions * for each MaxEvenFunctionArguments number of arguments. * e.g. If 220 arguments are provided then 110 group by accumulators are present in the query. * which translates to: * bson_dollar_merge_documents( * bson_dollar_merge_documents( * bson_repath_and_build(<50 group by exprs>), * bson_dollar_merge_documents( * bson_repath_and_build(<50 group by exprs>), * bson_repath_and_build(<10 group by exprs>) * ), * ) */ List *args = list_copy_head(repathArgs, MaxEvenFunctionArguments); List *remainingArgs = list_copy_tail(repathArgs, MaxEvenFunctionArguments); Expr *argsRepathExpression = (Expr *) makeFuncExpr(BsonRepathAndBuildFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); Expr *remainingArgsExprs = GenerateMultiExpressionRepathExpression(remainingArgs, overrideArrayInProjection); return (Expr *) makeFuncExpr(BsonDollaMergeDocumentsFunctionOid(), BsonTypeId(), list_make3(argsRepathExpression, remainingArgsExprs, MakeBoolValueConst( overrideArrayInProjection)), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } static List * AddShardKeyAndIdFilters(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context, TargetEntry *entry, List *existingQuals) { if (context->mongoCollection == NULL || !IsA(entry->expr, Var)) { return existingQuals; } Var *var = (Var *) entry->expr; if (var->varlevelsup != 0) { return existingQuals; } RangeTblEntry *rtable = rt_fetch(var->varno, query->rtable); /* Verify still on base RTE */ if (rtable->rtekind != RTE_RELATION || rtable->relid != context->mongoCollection->relationId) { return existingQuals; } /* If we have a shardkey, add it */ bool hasShardKeyFilters = false; if (context->mongoCollection->shardKey != NULL) { bool shardKeyFiltersCollationAware = false; Expr *shardKeyFilters = CreateShardKeyFiltersForQuery(existingValue, context->mongoCollection->shardKey, context->mongoCollection->collectionId, var->varno, &shardKeyFiltersCollationAware); if (shardKeyFilters != NULL) { /* add the shard key filter if the query's shard key value is */ /* not collation-sensitive. */ /* If it is, we ignore the filter and distribute the execution. */ if (!shardKeyFiltersCollationAware || !IsCollationApplicable(context->collationString)) { hasShardKeyFilters = true; existingQuals = lappend(existingQuals, shardKeyFilters); } } } else { hasShardKeyFilters = true; } if (hasShardKeyFilters) { /* Protocol behavior allows collation on _id field. We need to make sure we do that as well. We can't * push the Id filter to primary key index if the type needs to be collation aware (e.g., _id contains UTF8 )*/ bool isCollationAware; bool isPointRead = false; Expr *idFilter = CreateIdFilterForQuery(existingQuals, var->varno, &isCollationAware, &isPointRead); if (idFilter != NULL && !(isCollationAware && IsCollationApplicable(context->collationString))) { existingQuals = lappend(existingQuals, idFilter); context->isPointReadQuery = isPointRead; } } return existingQuals; } /* * Applies the $unset operator to the query. * Converts to a $project exclude. */ static Query * HandleUnset(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_UNSET); if (existingValue->value_type != BSON_TYPE_UTF8 && existingValue->value_type != BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31002), errmsg( "Expected 'string' or 'array' type for $unset but found '%s' type", BsonTypeName(existingValue->value_type)))); } pgbson_writer writer; PgbsonWriterInit(&writer); if (existingValue->value_type == BSON_TYPE_UTF8) { if (existingValue->value.v_utf8.len == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40352), errmsg("FieldPath cannot be created from an empty string"))); } if (existingValue->value.v_utf8.str[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "FieldPath field names cannot begin with the operators symbol '$'."))); } /* Add it as an exclude path */ PgbsonWriterAppendInt32(&writer, existingValue->value.v_utf8.str, existingValue->value.v_utf8.len, 0); } else { bson_iter_t valueIterator; BsonValueInitIterator(existingValue, &valueIterator); while (bson_iter_next(&valueIterator)) { const bson_value_t *arrayValue = bson_iter_value(&valueIterator); if (arrayValue->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31120), errmsg( "Expected 'string' or 'array' type for $unset but found '%s' type", BsonTypeName(arrayValue->value_type)))); } if (arrayValue->value.v_utf8.len == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40352), errmsg( "FieldPath cannot be created from an empty string"))); } if (arrayValue->value.v_utf8.str[0] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "FieldPath field names cannot begin with the operators symbol '$'."))); } /* Add it as an exclude path */ PgbsonWriterAppendInt32(&writer, arrayValue->value.v_utf8.str, arrayValue->value.v_utf8.len, 0); } } pgbson *excludeBson = PgbsonWriterGetPgbson(&writer); if (IsPgbsonEmptyDocument(excludeBson)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION31119), errmsg( "The $unset operator requires input as either a string or an array containing at least one specified field."))); } Const *addFieldsProcessed = MakeBsonConst(excludeBson); TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; List *args = list_make2(currentProjection, addFieldsProcessed); FuncExpr *resultExpr = makeFuncExpr( BsonDollarProjectFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) resultExpr; return query; } /* * Applies the Unwind operator to the query. * Requests a new subquery stage (since we process unwind as an SRF) * after the unwind to ensure subsequent stages can process it on a * per tuple basis. */ static Query * HandleUnwind(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_UNWIND); bson_value_t pathValue = { 0 }; bool hasOptions = false; switch (existingValue->value_type) { case BSON_TYPE_UTF8: { pathValue = *existingValue; break; } case BSON_TYPE_DOCUMENT: { hasOptions = true; bson_iter_t optionsDocIter; BsonValueInitIterator(existingValue, &optionsDocIter); while (bson_iter_next(&optionsDocIter)) { const char *key = bson_iter_key(&optionsDocIter); const bson_value_t *value = bson_iter_value(&optionsDocIter); if (strcmp(key, "path") == 0) { pathValue = *value; } else if (strcmp(key, "includeArrayIndex") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28810), errmsg( "A non-empty string value was expected for the includeArrayIndex option in the $unwind stage."))); } StringView includeArrayIndexView = (StringView) { .string = value->value.v_utf8.str, .length = value->value.v_utf8.len }; if (includeArrayIndexView.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28810), errmsg( "A non-empty string value was expected for the includeArrayIndex option in the $unwind stage."))); } if (StringViewStartsWith(&includeArrayIndexView, '$')) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28822), errmsg( "The includeArrayIndex option used in the $unwind stage must not have a '$' operator at the beginning: %s", includeArrayIndexView.string))); } } else if (strcmp(key, "preserveNullAndEmptyArrays") == 0) { if (value->value_type != BSON_TYPE_BOOL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28809), errmsg( "A boolean value was expected for the preserveNullAndEmptyArrays option used in the $unwind stage."))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28811), errmsg( "Invalid option specified for $unwind stage"))); } } break; } default: { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15981), errmsg( "A string or an object was expected as the specification for the $unwind stage, but instead received %s.", BsonTypeName(existingValue->value_type)))); } } if (pathValue.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28812), errmsg("No path provided for $unwind stage"))); } if (pathValue.value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28808), errmsg( "A string value was expected as the path in the $unwind stage, but received %s.", BsonTypeName(pathValue.value_type)))); } StringView pathView = { .string = pathValue.value.v_utf8.str, .length = pathValue.value.v_utf8.len }; if (pathView.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28812), errmsg("No path provided for $unwind stage"))); } if (!StringViewStartsWith(&pathView, '$') || pathView.length == 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28818), errmsg( "The path option provided to the $unwind stage must start with the '$' symbol: %.*s", pathView.length, pathView.string))); } if (pathView.string[1] == '$') { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION16410), errmsg( "FieldPath field names cannot begin with the symbol '$'."))); } FuncExpr *resultExpr; /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; if (hasOptions) { Const *unwindValue = MakeBsonConst(PgbsonInitFromDocumentBsonValue( existingValue)); List *args = list_make2(currentProjection, unwindValue); resultExpr = makeFuncExpr( BsonDollarUnwindWithOptionsFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } else { Const *unwindValue = MakeTextConst(existingValue->value.v_utf8.str, existingValue->value.v_utf8.len); List *args = list_make2(currentProjection, unwindValue); resultExpr = makeFuncExpr( BsonDollarUnwindFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } resultExpr->funcretset = true; firstEntry->expr = (Expr *) resultExpr; query->hasTargetSRFs = true; /* Since this is an SRF, we need a child CTE if anyone comes after an unwind */ context->requiresSubQuery = true; return query; } /* * Helper function to handle making an aggregate function projector with a single * argument. e.g. BSONMAX(document), BSONSUM(document) * borrows code from the pg parser (ParseFuncOrColumn in parse_func.c) */ static Aggref * CreateSingleArgAggregate(Oid aggregateFunctionId, Expr *argument, ParseState *parseState) { List *aggregateArgs = list_make1(argument); Aggref *aggref = makeNode(Aggref); aggref->aggfnoid = aggregateFunctionId; aggref->aggtype = BsonTypeId(); aggref->aggtranstype = InvalidOid; /* set by planner later */ aggref->aggdirectargs = NIL; /* count has no direct args */ aggref->aggkind = AGGKIND_NORMAL; /* reset by planner */ /* aggref->agglevelsup = 0 / * > 0 if agg belongs to outer query * / */ aggref->aggsplit = AGGSPLIT_SIMPLE; aggref->aggno = -1; /* planner will set aggno and aggtransno */ aggref->aggtransno = -1; aggref->location = -1; aggref->aggargtypes = list_make1_oid(BsonTypeId()); bool aggDistinct = false; transformAggregateCall(parseState, aggref, aggregateArgs, NIL, aggDistinct); return aggref; } static Query * HandleDistinct(const StringView *distinctKey, Query *query, AggregationPipelineBuildContext *context) { FuncExpr *resultExpr; /* If there are existing sort clauses in the query, can happen with $near / $nearSphere query operators * push the query down as a subquery. */ if (query->sortClause != NULL) { query = MigrateQueryToSubQuery(query, context); } /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); Expr *currentProjection = firstEntry->expr; Const *unwindValue = MakeTextConst(distinctKey->string, distinctKey->length); List *args = list_make2(currentProjection, unwindValue); /* Create a distinct unwind - to expand arrays and such */ resultExpr = makeFuncExpr( BsonDistinctUnwindFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); resultExpr->funcretset = true; firstEntry->expr = (Expr *) resultExpr; query->hasTargetSRFs = true; /* Add the distinct */ SortGroupClause *distinctSortGroup = makeNode(SortGroupClause); distinctSortGroup->eqop = BsonEqualOperatorId(); distinctSortGroup->sortop = BsonLessThanOperatorId(); distinctSortGroup->tleSortGroupRef = assignSortGroupRef(firstEntry, query->targetList); query->distinctClause = list_make1(distinctSortGroup); /* Add the bson_distinct_agg function */ ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = firstEntry->resno + 1; query = MigrateQueryToSubQuery(query, context); firstEntry = linitial(query->targetList); Aggref *aggref = CreateSingleArgAggregate(BsonDistinctAggregateFunctionOid(), firstEntry->expr, parseState); firstEntry->expr = (Expr *) aggref; query->hasAggs = true; return query; } static Query * HandleGeoNear(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_GEONEAR); if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg( "collation is not supported in the $geoNear stage yet."))); } if (context->stageNum != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40603), errmsg( "$geoNear stage must be present before any other stage in the pipeline"))); } RangeTblEntry *rte = linitial(query->rtable); if (rte->rtekind != RTE_RELATION) { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("$geoNear can only be used with specific collections."), errdetail_log( "$geoNear can only be used with specific collections. RTE KIND: %d", rte->rtekind))); } if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_LOCATION10065), errmsg( "Invalid parameter: an object was expected for $geoNear."))); } pgbson *geoNearQueryDoc = EvaluateGeoNearConstExpression(existingValue, context->variableSpec); /* * Create a $geoNear query of this form: * * For 2dsphere index: * SELECT bson_dollar_project_geonear(document, ) AS document * FROM WHERE bson_validate_geography(document, ) IS NOT NULL AND * [optional] document <|-|> <= maxDistance AND document <|-|> >= minDistance * ORDER BY bson_validate_geography(document, ) <|-|> ; * * For 2d index: * SELECT bson_dollar_project_geonear(document, ) AS document * FROM WHERE bson_validate_geometry(document, ) IS NOT NULL * [optional] document <|-|> <= maxDistance AND document <|-|> >= minDistance * ORDER BY bson_validate_geometry(document, ) <|-|> ; * * The <|-|> operator is a custom operator that compares the distance between two geometries/geographies * based on the geoNear requirements. * */ Const *queryConst = makeConst(BsonTypeId(), -1, InvalidOid, -1, PointerGetDatum( geoNearQueryDoc), false, false); TargetEntry *firstEntry = linitial(query->targetList); Var *docExpr = (Var *) firstEntry->expr; GeonearRequest *request = ParseGeonearRequest(geoNearQueryDoc); /* Add any query filters available */ if (request->query.value_type != BSON_TYPE_EOD) { query = HandleMatch(&(request->query), query, context); ValidateQueryOperatorsForGeoNear((Node *) query->jointree->quals, NULL); if (TargetListContainsGeonearOp(query->targetList)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("Excessive number of geoNear query expressions"))); } } TargetEntry *sortTargetEntry; SortGroupClause *sortGroupClause; List *quals = CreateExprForGeonearAndNearSphere(geoNearQueryDoc, (Expr *) docExpr, request, &sortTargetEntry, &sortGroupClause); /* Update the resno and sortgroup ref based on the query */ UpdateQueryOperatorContextSortList(query, list_make1(sortGroupClause), list_make1(sortTargetEntry)); if (query->jointree->quals != NULL) { quals = lappend(quals, query->jointree->quals); } query->jointree->quals = (Node *) make_ands_explicit(quals); /* Add the geoNear projection function */ FuncExpr *projectionExpr = makeFuncExpr( BsonDollarProjectGeonearFunctionOid(), BsonTypeId(), list_make2(docExpr, queryConst), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) projectionExpr; if (context->nestedPipelineLevel > 0) { /* For nested pipelines this will require a subquery */ context->requiresSubQueryAfterProject = true; } return query; } /* * Creates a multi-argument aggregate based on the provided function id. * e.g. BSON_ARRAY_AGG(bson, text) */ Aggref * CreateMultiArgAggregate(Oid aggregateFunctionId, List *args, List *argTypes, ParseState *parseState) { Aggref *aggref = makeNode(Aggref); aggref->aggfnoid = aggregateFunctionId; aggref->aggtype = BsonTypeId(); aggref->aggtranstype = InvalidOid; /* set by planner later */ aggref->aggdirectargs = NIL; /* count has no direct args */ aggref->aggkind = AGGKIND_NORMAL; /* reset by planner */ /* aggref->agglevelsup = 0 / * > 0 if agg belongs to outer query * / */ aggref->aggsplit = AGGSPLIT_SIMPLE; aggref->aggno = -1; /* planner will set aggno and aggtransno */ aggref->aggtransno = -1; aggref->location = -1; aggref->aggargtypes = argTypes; bool aggDistinct = false; parseState->p_hasAggs = true; transformAggregateCall(parseState, aggref, args, NIL, aggDistinct); return aggref; } /* * Handles the $count stage. Injects an aggregate of * bsonsum('{ "": 1 }'); * First moves existing query to a subquery. * Then injects the aggregate projector. * We request a new subquery for subsequent stages, but it * may not be needed. */ static Query * HandleCount(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_COUNT); StringView countField = { 0 }; if (existingValue->value_type == BSON_TYPE_UTF8) { countField.string = existingValue->value.v_utf8.str; countField.length = existingValue->value.v_utf8.len; } if (countField.length == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40156), errmsg( "count cannot be empty"))); } if (StringViewStartsWith(&countField, '$')) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40158), errmsg( "The count field is not allowed to be a $-prefixed path"))); } if (StringViewContains(&countField, '.')) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40160), errmsg( "The count field is not allowed to contain '.'."))); } /* Count requires the existing query to move to subquery */ query = MigrateQueryToSubQuery(query, context); /* The first projector is the document */ TargetEntry *firstEntry = linitial(query->targetList); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; parseState->p_next_resno = firstEntry->resno + 1; pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendInt32(&writer, "", 0, 1); Expr *constValue = (Expr *) MakeBsonConst(PgbsonWriterGetPgbson(&writer)); Aggref *aggref = CreateSingleArgAggregate(BsonSumAggregateFunctionOid(), constValue, parseState); pfree(parseState); query->hasAggs = true; /* We wrap the count in a bson_repath_and_build */ Const *countFieldText = MakeTextConst(countField.string, countField.length); List *args = list_make2(countFieldText, aggref); FuncExpr *expression = makeFuncExpr(BsonRepathAndBuildFunctionOid(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); firstEntry->expr = (Expr *) expression; /* Having count means the next stage must be a new outer query */ context->requiresSubQuery = true; return query; } /* * Handles the $replaceWith stage. Converts to a $replaceRoot stage * and calls $replaceRoot */ static Query * HandleReplaceWith(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_REPLACE_WITH); /* Convert to replaceRoot */ pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendValue(&writer, "newRoot", 7, existingValue); pgbson *bson = PgbsonWriterGetPgbson(&writer); bson_value_t currentValue = ConvertPgbsonToBsonValue(bson); return HandleReplaceRoot(¤tValue, query, context); } /* * Checks if a sort can be pushed to an index explicitly. Typically * index selection happens based on filters. But in the case where there * are no filters, sorts can never be pushed to the index: * e.g. * find('collection: foo, sort: { a.b: 1 })' * In this case, given our sort is bson_orderby() it'll never go through picking * the index. However, we do want the ability to push orderby to available indexes * if possible. So we add a fullscan filter *iff* the sort is against a base table * and it has no filters. If there are any filters, we let the filters determine * index pushdown. */ static bool CanPushSortFilterToIndex(Query *query) { if (list_length(query->jointree->fromlist) != 1) { return false; } RangeTblRef *rtref = linitial(query->jointree->fromlist); RangeTblEntry *entry = rt_fetch(rtref->rtindex, query->rtable); if (entry->rtekind != RTE_RELATION) { return false; } if (!EnableIndexOrderbyPushdownLegacy) { return true; } /* If there's no quals, we can push a full scan order by */ if (query->jointree->quals == NULL) { return true; } if (!IsA(query->jointree->quals, OpExpr)) { return false; } OpExpr *opExpr = (OpExpr *) query->jointree->quals; if (opExpr->opno != BigintEqualOperatorId()) { return false; } if (IsA(linitial(opExpr->args), Var) && castNode(Var, linitial(opExpr->args))->varattno == DOCUMENT_DATA_TABLE_SHARD_KEY_VALUE_VAR_ATTR_NUMBER) { return true; } /* Unknown case */ return false; } /* * Handles the $sort stage. * Creates a subquery if there's a skip/limit (Since those need to be * applied first). * Parses the sort spec and takes the current projector and applies the sort * function on it. Injects the tle_sort_group similiar to the parser phase. */ static Query * HandleSort(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_SORT); if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("Expected document for sort specification"))); } /* If there's an existing skip/limit we need to push those down */ if (query->limitOffset != NULL || query->limitCount != NULL || query->sortClause != NULL) { query = MigrateQueryToSubQuery(query, context); } /* Store the sort in the context (used for downstream groups) */ context->sortSpec = *existingValue; bson_iter_t sortSpec; BsonValueInitIterator(existingValue, &sortSpec); /* Take the current output (That's to be sorted)*/ TargetEntry *entry = linitial(query->targetList); /* Grab a copy of the targetList */ List *targetEntryList = list_copy(query->targetList); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(query->targetList) + 1; List *sortlist = NIL; bool isNaturalSort = false; bool isNaturalReverseSort = false; int naturalCount = 0; int nonNaturalCount = 0; while (bson_iter_next(&sortSpec)) { pgbsonelement element; BsonIterToPgbsonElement(&sortSpec, &element); if (strcmp(element.path, "$natural") == 0) { if (!BsonValueIsNumber(&element.bsonValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("Sort direction value %s is not valid", BsonValueToJsonForLogging( &element.bsonValue)))); } int64_t naturalValue = BsonValueAsInt64(&element.bsonValue); isNaturalSort = false; isNaturalReverseSort = false; if (naturalValue == 1) { isNaturalSort = true; } else if (naturalValue == -1) { isNaturalReverseSort = true; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$natural sort cannot be set to a value other than -1 or 1."))); } naturalCount++; } else { nonNaturalCount++; Expr *sortInput = entry->expr; pgbsonelement subOrderingElement; bool isSortByMeta = false; if (element.bsonValue.value_type == BSON_TYPE_DOCUMENT && TryGetBsonValueToPgbsonElement(&element.bsonValue, &subOrderingElement) && subOrderingElement.pathLength == 5 && strncmp(subOrderingElement.path, "$meta", 5) == 0) { RangeTblEntry *rte = linitial(query->rtable); isSortByMeta = true; if (rte->rtekind == RTE_RELATION || rte->rtekind == RTE_FUNCTION) { /* This is a base table */ sortInput = (Expr *) MakeSimpleDocumentVar(); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("Sort direction value %s is not valid", BsonValueToJsonForLogging( &element.bsonValue)))); } } Expr *expr = NULL; pgbson *sortDoc = PgbsonElementToPgbson(&element); Const *sortBson = MakeBsonConst(sortDoc); bool isAscending = ValidateOrderbyExpressionAndGetIsAscending(sortDoc); bool hasSortById = strcmp(element.path, "_id") == 0; if (hasSortById) { ReportFeatureUsage(FEATURE_STAGE_SORT_BY_ID); } SortBy *sortBy = makeNode(SortBy); SortByNulls sortByNulls = SORTBY_NULLS_DEFAULT; SortByDir sortByDirection = isAscending ? SORTBY_ASC : SORTBY_DESC; sortBy->location = -1; Oid funcOid = BsonOrderByFunctionOid(); List *args = NIL; /* apply collation to the sort comparison */ if (IsCollationApplicable(context->collationString) && IsClusterVersionAtleast(DocDB_V0, 104, 0)) { funcOid = BsonOrderByWithCollationFunctionOid(); Const *collationConst = MakeTextConst(context->collationString, strlen( context->collationString)); args = list_make3(sortInput, sortBson, collationConst); /* * For ascending order: ORDER BY USING ApiInternalSchemaNameV2.<<< * For descending order: ORDER BY USING ApiInternalSchemaNameV2.>>> */ sortByDirection = SORTBY_USING; sortBy->useOp = isAscending ? list_make2(makeString(ApiInternalSchemaNameV2), makeString("<<<")) : list_make2(makeString(ApiInternalSchemaNameV2), makeString(">>>")); } else { args = list_make2(sortInput, sortBson); } sortByNulls = isAscending ? SORTBY_NULLS_FIRST : SORTBY_NULLS_LAST; expr = (Expr *) makeFuncExpr(funcOid, BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (EnableIndexOrderbyPushdown && !isSortByMeta) { /* * If there's an orderby pushdown to the index, add a full scan clause iff * the query has no filters yet. */ if (CanPushSortFilterToIndex(query) && ( IsClusterVersionAtLeastPatch(DocDB_V0, 103, 1) || IsClusterVersionAtLeastPatch(DocDB_V0, 104, 1) || IsClusterVersionAtleast(DocDB_V0, 105, 0))) { List *rangeArgs = list_make2(sortInput, sortBson); Expr *fullScanExpr = (Expr *) makeFuncExpr( BsonFullScanFunctionOid(), BOOLOID, rangeArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); List *currentQuals = make_ands_implicit( (Expr *) query->jointree->quals); currentQuals = lappend(currentQuals, fullScanExpr); query->jointree->quals = (Node *) make_ands_explicit( currentQuals); } /* If sort by is descending use the new operators: this allows for * customization of reverse scan. */ if (IsClusterVersionAtleast(DocDB_V0, 104, 0) && !isAscending) { sortByDirection = SORTBY_USING; sortBy->useOp = list_make2(makeString(ApiInternalSchemaNameV2), makeString(">>>")); } } sortBy->sortby_dir = sortByDirection; sortBy->sortby_nulls = sortByNulls; sortBy->node = (Node *) expr; bool resjunk = true; TargetEntry *sortEntry = makeTargetEntry((Expr *) expr, (AttrNumber) parseState->p_next_resno ++, "?sort?", resjunk); targetEntryList = lappend(targetEntryList, sortEntry); sortlist = addTargetToSortList(parseState, sortEntry, sortlist, targetEntryList, sortBy); } } /* if there is other operator exist with $natural, should throw exception, example like db.coll.find().sort({$size:1, $natural: -1}) */ if (naturalCount > 0 && nonNaturalCount > 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$natural sort cannot be set to a value other than -1 or 1."))); } if (isNaturalReverseSort || isNaturalSort) { /* server would throw exception Exception while reading from stream if collection is null, * directly return query when collection is null */ if (context->mongoCollection == NULL) { return query; } Var *ctid_var = makeVar(1, SelfItemPointerAttributeNumber, TIDOID, -1, 0, 0); TargetEntry *tle_ctid = makeTargetEntry((Expr *) ctid_var, (AttrNumber) parseState->p_next_resno++, "?ctid?", true); SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = isNaturalSort ? SORTBY_ASC : SORTBY_DESC; sortBy->sortby_nulls = isNaturalSort ? SORTBY_NULLS_FIRST : SORTBY_NULLS_LAST; sortBy->node = (Node *) ctid_var; targetEntryList = lappend(targetEntryList, tle_ctid); sortlist = addTargetToSortList(parseState, tle_ctid, sortlist, targetEntryList, sortBy); query->targetList = targetEntryList; query->sortClause = sortlist; pfree(parseState); return query; } pfree(parseState); if (sortlist == NIL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15976), errmsg( "The $sort stage requires specifying at least one sorting key to proceed"))); } query->targetList = targetEntryList; query->sortClause = sortlist; return query; } /* * Handles the $sortByCount stage. * Creates a group followed by a sort and calls each handler */ static Query * HandleSortByCount(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_SORT_BY_COUNT); if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg( "collation is not supported in the $sortByCount stage yet."))); } /* Do validations */ bool isInvalidSpec = false; if (existingValue->value_type == BSON_TYPE_UTF8) { isInvalidSpec = (existingValue->value.v_utf8.len == 0 || existingValue->value.v_utf8.str[0] != '$'); } else if (existingValue->value_type == BSON_TYPE_DOCUMENT) { pgbsonelement expressionElement; isInvalidSpec = !TryGetBsonValueToPgbsonElement(existingValue, &expressionElement) || expressionElement.pathLength == 0 || expressionElement.path[0] != '$'; } else { isInvalidSpec = true; } if (isInvalidSpec) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40147), errmsg( "The sortByCount field must be specified either as a $-prefixed path or as a valid expression contained within an object."))); } /* Convert to * { $group: { _id: , count: { $sum: 1 } } }, * { $sort: { count: -1 } } */ pgbson_writer groupWriter; PgbsonWriterInit(&groupWriter); PgbsonWriterAppendValue(&groupWriter, "_id", 3, existingValue); pgbson_writer countWriter; PgbsonWriterStartDocument(&groupWriter, "count", 5, &countWriter); PgbsonWriterAppendInt32(&countWriter, "$sum", 4, 1); PgbsonWriterEndDocument(&groupWriter, &countWriter); pgbson *group = PgbsonWriterGetPgbson(&groupWriter); bson_value_t groupValue = ConvertPgbsonToBsonValue(group); query = HandleGroup(&groupValue, query, context); if (context->requiresSubQuery) { query = MigrateQueryToSubQuery(query, context); } /* Add sort */ pgbson_writer sortWriter; PgbsonWriterInit(&sortWriter); PgbsonWriterAppendInt32(&sortWriter, "count", 5, -1); pgbson *sort = PgbsonWriterGetPgbson(&sortWriter); bson_value_t sortValue = ConvertPgbsonToBsonValue(sort); query = HandleSort(&sortValue, query, context); return query; } /* * Helper method that adds a group expression projection to the query's targetList. * Creates a VAR that can be used in the projector of the higher level sub-query. * Used with GROUP to ensure that we can split the group into * generate projectors/generate bson_repath_and_build in the second stage. */ inline static Var * AddGroupExpression(Expr *expression, ParseState *parseState, char *identifiers, Query *query, Oid outputOid, TargetEntry **createdEntry) { int identifierInt = parseState->p_next_resno++; identifiers[0] = 'c'; pg_ltoa(identifierInt, &identifiers[1]); bool resjunk = false; TargetEntry *entry = makeTargetEntry(expression, identifierInt, pstrdup(identifiers), resjunk); query->targetList = lappend(query->targetList, entry); if (createdEntry) { *createdEntry = entry; } query->hasAggs = true; parseState->p_hasAggs = true; Index childIndex = 1; return makeVar(childIndex, entry->resno, outputOid, -1, InvalidOid, 0); } /* * Given an accumulator expression, checks whether it can be statically * evaluated to a const. If it can, then returns a const "Expr". * If not, returns the original docExpr. */ static Expr * GetDocumentExprForGroupAccumulatorValue(const bson_value_t *accumulatorValue, Expr *docExpr) { ParseAggregationExpressionContext parseContext = { 0 }; AggregationExpressionData expressionData; memset(&expressionData, 0, sizeof(AggregationExpressionData)); ParseAggregationExpressionData(&expressionData, accumulatorValue, &parseContext); if (expressionData.kind == AggregationExpressionKind_Constant) { /* Expression evaluates to a const, we don't need to pass in the input documentExpr */ return (Expr *) MakeBsonConst(PgbsonInitEmpty()); } return docExpr; } /* * Simple helper method that has logic to insert a Group accumulator to a query. * This adds the group aggregate to the TargetEntry (for projection) * and also adds the necessary data to the bson_repath_and_build arguments. */ inline static List * AddSimpleGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, Expr *variableSpec) { Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson( accumulatorValue)); documentExpr = GetDocumentExprForGroupAccumulatorValue(accumulatorValue, documentExpr); Const *trueConst = makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); List *groupArgs; Oid functionId; if (variableSpec != NULL) { groupArgs = list_make4(documentExpr, constValue, trueConst, variableSpec); functionId = BsonExpressionGetWithLetFunctionOid(); } else { groupArgs = list_make3(documentExpr, constValue, trueConst); functionId = BsonExpressionGetFunctionOid(); } FuncExpr *accumFunc = makeFuncExpr( functionId, BsonTypeId(), groupArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (BsonTypeId() != DocumentDBCoreBsonTypeId()) { accumFunc = makeFuncExpr( DocumentDBCoreBsonToBsonFunctionOId(), BsonTypeId(), list_make1(accumFunc), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } Aggref *aggref = CreateSingleArgAggregate(aggregateFunctionOid, (Expr *) accumFunc, parseState); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) aggref, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Simple helper method that has logic to insert a BSON_ARRAY_AGG accumulator to a query. * This adds the group aggregate to the TargetEntry (for projection) * and also adds the necessary data to the bson_repath_and_build arguments. */ inline static List * AddArrayAggGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, char *fieldPath, bool handleSingleValue, Expr *variableSpec) { Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson( accumulatorValue)); /* isNullOnEmpty is set to false for $push */ Const *isNullOnEmptyConst = (Const *) MakeBoolValueConst(false); List *funcArgs; Oid functionOid; if (variableSpec != NULL) { funcArgs = list_make4(documentExpr, constValue, isNullOnEmptyConst, variableSpec); functionOid = BsonExpressionGetWithLetFunctionOid(); } else { funcArgs = list_make3(documentExpr, constValue, isNullOnEmptyConst); functionOid = BsonExpressionGetFunctionOid(); } FuncExpr *accumFunc = makeFuncExpr(functionOid, BsonTypeId(), funcArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); List *aggregateArgs = list_make3( (Expr *) accumFunc, MakeTextConst(fieldPath, strlen(fieldPath)), MakeBoolValueConst(handleSingleValue)); List *argTypesList = list_make3_oid(BsonTypeId(), TEXTOID, BOOLOID); Aggref *aggref = CreateMultiArgAggregate(aggregateFunctionOid, aggregateArgs, argTypesList, parseState); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) aggref, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Simple helper method that has logic to insert a BSON_MERGE_OBJECTS accumulator to a query. * This adds the group aggregate to the TargetEntry (for projection) * and also adds the necessary data to the bson_repath_and_build arguments. */ inline static List * AddMergeObjectsGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, const bson_value_t *sortSpec, Expr *variableSpec) { /* First apply the sorted aggs */ int nelems = BsonDocumentValueCountKeys(sortSpec); Datum *sortDatumArray = palloc(sizeof(Datum) * nelems); bson_iter_t sortIter; BsonValueInitIterator(sortSpec, &sortIter); int i = 0; while (bson_iter_next(&sortIter)) { pgbsonelement sortElement = { 0 }; sortElement.path = bson_iter_key(&sortIter); sortElement.pathLength = strlen(sortElement.path); sortElement.bsonValue = *bson_iter_value(&sortIter); sortDatumArray[i] = PointerGetDatum(PgbsonElementToPgbson(&sortElement)); i++; } /* Here we use INT_MAX to sort the whole array regardless of its length. */ Const *nConst = makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(INT_MAX), false, true); ArrayType *arrayValue = construct_array(sortDatumArray, nelems, BsonTypeId(), -1, false, TYPALIGN_INT); Const *sortArrayConst = makeConst(GetBsonArrayTypeOid(), -1, InvalidOid, -1, PointerGetDatum(arrayValue), false, false); if (variableSpec != NULL) { /* If variableSpec only contains the time system variables, do not fail. */ Node *specNode = (Node *) variableSpec; Const *specConst = (Const *) specNode; pgbson *specBson = DatumGetPgBson(specConst->constvalue); bson_iter_t iter; if (PgbsonInitIteratorAtPath(specBson, "let", &iter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg("let with $mergeObjects is not supported yet"))); } } /* * Here we add a parameter with the input expression. The reason is we need * to evaluate it against the document after the sort takes place. */ Expr *inputExpression = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson( accumulatorValue)); Aggref *aggref = CreateMultiArgAggregate(BsonMergeObjectsFunctionOid(), list_make4(documentExpr, nConst, sortArrayConst, inputExpression), list_make4_oid(BsonTypeId(), nConst->consttype, sortArrayConst->consttype, BsonTypeId()), parseState); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) aggref, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Simple helper method that has logic to insert a Group accumulator to a query. * This adds the group aggregate to the TargetEntry (for projection) * and also adds the necessary data to the bson_expression_map arguments. */ inline static List * AddSimpleNGroupAccumulator(Query *query, const bson_value_t *input, bson_value_t *elementsToFetch, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, StringView *accumulatorName, Expr *variableSpec) { ValidateElementForNGroupAccumulators(elementsToFetch, accumulatorName->string); /* First add the agg function */ Const *nConst = makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(elementsToFetch->value.v_int64), false, true); Aggref *aggref = CreateMultiArgAggregate(aggregateFunctionOid, list_make2((Expr *) documentExpr, nConst), list_make2_oid(BsonTypeId(), nConst->consttype), parseState); /* First apply the map function to the document */ Const *fieldConst = makeConst(TEXTOID, -1, InvalidOid, -1, CStringGetTextDatum(""), false, false); Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(input)); Const *trueConst = makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); List *groupArgs; Oid functionOid; if (variableSpec != NULL) { functionOid = BsonExpressionMapWithLetFunctionOid(); groupArgs = list_make5(aggref, fieldConst, constValue, trueConst, variableSpec); } else { functionOid = BsonExpressionMapFunctionOid(); groupArgs = list_make4(aggref, fieldConst, constValue, trueConst); } FuncExpr *accumFunc = makeFuncExpr( functionOid, BsonTypeId(), groupArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumFunc, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Add a sorted group accumulator e.g. BSONFIRST/BSONLAST */ inline static List * AddSortedGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, const bson_value_t *sortSpec, Expr *variableSpec) { /* First apply the sorted agg (FIRST/LAST) */ int nelems = BsonDocumentValueCountKeys(sortSpec); Datum *sortDatumArray = palloc(sizeof(Datum) * nelems); bson_iter_t sortIter; BsonValueInitIterator(sortSpec, &sortIter); int i = 0; while (bson_iter_next(&sortIter)) { pgbsonelement sortElement = { 0 }; sortElement.path = bson_iter_key(&sortIter); sortElement.pathLength = strlen(sortElement.path); sortElement.bsonValue = *bson_iter_value(&sortIter); sortDatumArray[i] = PointerGetDatum(PgbsonElementToPgbson(&sortElement)); i++; } ArrayType *arrayValue = construct_array(sortDatumArray, nelems, BsonTypeId(), -1, false, TYPALIGN_INT); Const *sortArrayConst = makeConst(GetBsonArrayTypeOid(), -1, InvalidOid, -1, PointerGetDatum(arrayValue), false, false); /* Cast documentExpr from CoreSchemaName.bson to bson to ensure type */ /* correctness for accumulators that require bson. */ if (BsonTypeId() != DocumentDBCoreBsonTypeId()) { documentExpr = (Expr *) makeRelabelType(documentExpr, BsonTypeId(), -1, InvalidOid, COERCE_IMPLICIT_CAST); } Aggref *aggref = CreateMultiArgAggregate(aggregateFunctionOid, list_make2(documentExpr, sortArrayConst), list_make2_oid(BsonTypeId(), sortArrayConst->consttype), parseState); /* Now apply the bson_expression_get */ Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson( accumulatorValue)); Const *trueConst = makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); List *groupArgs; Oid expressionGetFunction; if (variableSpec != NULL) { groupArgs = list_make4(aggref, constValue, trueConst, variableSpec); expressionGetFunction = BsonExpressionGetWithLetFunctionOid(); } else { groupArgs = list_make3(aggref, constValue, trueConst); expressionGetFunction = BsonExpressionGetFunctionOid(); } FuncExpr *accumFunc = makeFuncExpr( expressionGetFunction, BsonTypeId(), groupArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumFunc, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Add a sorted group accumulator e.g. BSONFIRSTN/BSONLASTN */ inline static List * AddSortedNGroupAccumulator(Query *query, const bson_value_t *input, bson_value_t *elementsToFetch, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, const bson_value_t *sortSpec, StringView *accumulatorName, Expr *variableSpec) { ValidateElementForNGroupAccumulators(elementsToFetch, accumulatorName->string); /* First apply the sorted agg (FIRSTN/LASTN) */ int nelems = BsonDocumentValueCountKeys(sortSpec); Datum *sortDatumArray = palloc(sizeof(Datum) * nelems); bson_iter_t sortIter; BsonValueInitIterator(sortSpec, &sortIter); int i = 0; while (bson_iter_next(&sortIter)) { pgbsonelement sortElement = { 0 }; sortElement.path = bson_iter_key(&sortIter); sortElement.pathLength = strlen(sortElement.path); sortElement.bsonValue = *bson_iter_value(&sortIter); sortDatumArray[i] = PointerGetDatum(PgbsonElementToPgbson(&sortElement)); i++; } Const *nConst = makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(elementsToFetch->value.v_int64), false, true); ArrayType *arrayValue = construct_array(sortDatumArray, nelems, BsonTypeId(), -1, false, TYPALIGN_INT); Const *sortArrayConst = makeConst(GetBsonArrayTypeOid(), -1, InvalidOid, -1, PointerGetDatum(arrayValue), false, false); Aggref *aggref = CreateMultiArgAggregate(aggregateFunctionOid, list_make3(documentExpr, nConst, sortArrayConst), list_make3_oid(BsonTypeId(), nConst->consttype, sortArrayConst->consttype), parseState); /* Now apply the bson_expression_map */ Const *fieldConst = makeConst(TEXTOID, -1, InvalidOid, -1, CStringGetTextDatum(""), false, false); Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(input)); Const *trueConst = makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); List *groupArgs; Oid functionOid; if (variableSpec != NULL) { functionOid = BsonExpressionMapWithLetFunctionOid(); groupArgs = list_make5(aggref, fieldConst, constValue, trueConst, variableSpec); } else { functionOid = BsonExpressionMapFunctionOid(); groupArgs = list_make4(aggref, fieldConst, constValue, trueConst); } FuncExpr *accumFunc = makeFuncExpr( functionOid, BsonTypeId(), groupArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumFunc, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Function used to support maxN/minN accumulator. */ inline static List * AddMaxMinNGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, Oid aggregateFunctionOid, StringView *accumulatorName, Expr *variableSpec) { bson_value_t input = { 0 }; bson_value_t elementsToFetch = { 0 }; /*check the syntax of maxN/minN */ ParseInputForNGroupAccumulators(accumulatorValue, &input, &elementsToFetch, accumulatorName->string); return AddSimpleGroupAccumulator(query, accumulatorValue, repathArgs, accumulatorText, parseState, identifiers, documentExpr, aggregateFunctionOid, variableSpec); } /* * Function used to support percentile/median accumulator. */ inline static List * AddPercentileMedianGroupAccumulator(Query *query, const bson_value_t *accumulatorValue, List *repathArgs, Const *accumulatorText, ParseState *parseState, char *identifiers, Expr *documentExpr, StringView *accumulatorName, Expr *variableSpec, bool isMedianOp) { bson_value_t input = { 0 }; bson_value_t p = { 0 }; bson_value_t method = { 0 }; ParseInputDocumentForMedianAndPercentile(accumulatorValue, &input, &p, &method, isMedianOp); /* construct expression to get input and p */ List *inputFuncArgs; List *pFuncArgs; Oid bsonExpressionGetFunction; Expr *inputConstValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(&input)); Const *accuracyConstValue = makeConst(INT4OID, -1, InvalidOid, sizeof(int32_t), Int32GetDatum(TdigestCompressionAccuracy), false, true); Expr *pConstValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(&p)); Const *trueConst = makeConst(BOOLOID, -1, InvalidOid, 1, BoolGetDatum(true), false, true); if (variableSpec != NULL) { bsonExpressionGetFunction = BsonExpressionGetWithLetFunctionOid(); inputFuncArgs = list_make4(documentExpr, inputConstValue, trueConst, variableSpec); pFuncArgs = list_make4(documentExpr, pConstValue, trueConst, variableSpec); } else { bsonExpressionGetFunction = BsonExpressionGetFunctionOid(); inputFuncArgs = list_make3(documentExpr, inputConstValue, trueConst); pFuncArgs = list_make3(documentExpr, pConstValue, trueConst); } FuncExpr *inputAccumFunc = makeFuncExpr(bsonExpressionGetFunction, BsonTypeId(), inputFuncArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); FuncExpr *pAccumFunc = makeFuncExpr(bsonExpressionGetFunction, BsonTypeId(), pFuncArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (BsonTypeId() != DocumentDBCoreBsonTypeId()) { inputAccumFunc = makeFuncExpr( DocumentDBCoreBsonToBsonFunctionOId(), BsonTypeId(), list_make1( inputAccumFunc), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); pAccumFunc = makeFuncExpr( DocumentDBCoreBsonToBsonFunctionOId(), BsonTypeId(), list_make1(pAccumFunc), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); } Oid aggregateFunctionOid = isMedianOp ? BsonMedianAggregateFunctionOid() : BsonPercentileAggregateFunctionOid(); Aggref *aggref = CreateMultiArgAggregate(aggregateFunctionOid, list_make3( (Expr *) inputAccumFunc, accuracyConstValue, (Expr *) pAccumFunc), list_make3_oid( BsonTypeId(), accuracyConstValue->consttype, BsonTypeId()), parseState); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) accumulatorText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) aggref, parseState, identifiers, query, BsonTypeId(), NULL)); return repathArgs; } /* * Handles the $group stage. * Creates a subquery. * Then creates a grouping specified by the _id expression. * Then creates accumulators in the projectors. * * The raw accumulators/group are in the first query * The aggregates are then pushed to a subquery and then an outer query * with the bson_repath_and_build is added as part of the group. * This is done because without this, sharded multi-node group by fails * due to a quirk in the distribution layer's worker query generation. * * TODO: Support n(elementsToFetch) as an expression for firstN, lastN, topN, bottomN */ Query * HandleGroup(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { if (IsCollationApplicable(context->collationString)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("collation is not supported in $group stage yet."))); } ReportFeatureUsage(FEATURE_STAGE_GROUP); /* Part 1, let's do the group */ if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15947), errmsg( "The fields of a group must be explicitly defined within an object"))); } /* Push prior stuff to a subquery first since we're gonna aggregate our way */ if (list_length(query->targetList) > 1 || query->hasAggs || list_length(query->groupClause) > 0 || list_length(query->sortClause) > 0 || !EnableIndexOrderbyPushdown) { query = MigrateQueryToSubQuery(query, context); } /* Take the current output (That's to be grouped)*/ TargetEntry *origEntry = linitial(query->targetList); /* Clear the group's output */ query->targetList = NIL; bson_iter_t groupIter; BsonValueInitIterator(existingValue, &groupIter); /* First get the _id */ bson_value_t idValue = { 0 }; while (bson_iter_next(&groupIter)) { StringView keyView = bson_iter_key_string_view(&groupIter); if (StringViewEquals(&keyView, &IdFieldStringView)) { idValue = *bson_iter_value(&groupIter); break; } } if (idValue.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15955), errmsg("_id is missing from group specification"))); } pgbson *groupValue = BsonValueToDocumentPgbson(&idValue); ParseState *parseState = make_parsestate(NULL); parseState->p_next_resno = 1; parseState->p_expr_kind = EXPR_KIND_GROUP_BY; List *groupArgs; Oid bsonExpressionGetFunction; Expr *groupIdDocumentExpr = GetDocumentExprForGroupAccumulatorValue(&idValue, origEntry->expr); if (context->variableSpec != NULL) { bsonExpressionGetFunction = BsonExpressionGetWithLetFunctionOid(); groupArgs = list_make4(groupIdDocumentExpr, MakeBsonConst(groupValue), MakeBoolValueConst(true), context->variableSpec); } else { bsonExpressionGetFunction = BsonExpressionGetFunctionOid(); groupArgs = list_make3(groupIdDocumentExpr, MakeBsonConst(groupValue), MakeBoolValueConst(true)); } FuncExpr *groupFunc = makeFuncExpr( bsonExpressionGetFunction, BsonTypeId(), groupArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); /* Now do the projector / accumulators * We do this in 2 stages to handle citus query generation. * In the first phase we just project out the group and accumulators * Identifiers are basically 'c' + some number. * We set aside characters to "tostring" the number such that * (c + + \0). Note this is a temporary buffer - we * pstrdup it after creating it. */ char identifiers[UINT32_MAX_STR_LEN + 2]; Const *idFieldText = MakeTextConst("_id", 3); List *repathArgs = NIL; TargetEntry *groupEntry; repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) idFieldText, parseState, identifiers, query, TEXTOID, NULL)); repathArgs = lappend(repathArgs, AddGroupExpression((Expr *) groupFunc, parseState, identifiers, query, BsonTypeId(), &groupEntry)); /* Now add accumulators */ parseState->p_expr_kind = EXPR_KIND_SELECT_TARGET; BsonValueInitIterator(existingValue, &groupIter); while (bson_iter_next(&groupIter)) { StringView keyView = bson_iter_key_string_view(&groupIter); if (StringViewEquals(&keyView, &IdFieldStringView)) { continue; } if (StringViewContains(&keyView, '.')) { /* Paths here cannot be dotted paths */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40235), errmsg( "The specified field name %.*s is not allowed to include the '.' character.", keyView.length, keyView.string))); } Const *accumulatorText = MakeTextConst(keyView.string, keyView.length); bson_iter_t accumulatorIterator; if (!BSON_ITER_HOLDS_DOCUMENT(&groupIter) || !bson_iter_recurse(&groupIter, &accumulatorIterator)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40234), errmsg( "The field '%.*s' is required to be an accumulator-type object", keyView.length, keyView.string))); } pgbsonelement accumulatorElement; if (!TryGetSinglePgbsonElementFromBsonIterator(&accumulatorIterator, &accumulatorElement)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40238), errmsg( "The field '%.*s' is required to define exactly one accumulator", keyView.length, keyView.string))); } StringView accumulatorName = { .length = accumulatorElement.pathLength, .string = accumulatorElement.path }; if (StringViewEqualsCString(&accumulatorName, "$avg")) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonAvgAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$sum")) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonSumAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$max")) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonMaxAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$min")) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonMinAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$count")) { bson_value_t countValue = { 0 }; countValue.value_type = BSON_TYPE_INT32; countValue.value.v_int32 = 1; repathArgs = AddSimpleGroupAccumulator(query, &countValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonSumAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$first")) { if (context->sortSpec.value_type == BSON_TYPE_EOD) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstOnSortedAggregateFunctionOid(), context->variableSpec); } else { repathArgs = AddSortedGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstAggregateFunctionOid(), &context->sortSpec, context->variableSpec); } } else if (StringViewEqualsCString(&accumulatorName, "$last")) { if (context->sortSpec.value_type == BSON_TYPE_EOD) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastOnSortedAggregateFunctionOid(), context->variableSpec); } else { repathArgs = AddSortedGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastAggregateFunctionOid(), &context->sortSpec, context->variableSpec); } } else if (StringViewEqualsCString(&accumulatorName, "$firstN")) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_FIRSTN); bson_value_t input = { 0 }; bson_value_t elementsToFetch = { 0 }; ParseInputForNGroupAccumulators(&accumulatorElement.bsonValue, &input, &elementsToFetch, accumulatorName.string); if (context->sortSpec.value_type == BSON_TYPE_EOD) { repathArgs = AddSimpleNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstNOnSortedAggregateFunctionOid(), &accumulatorName, context->variableSpec); } else { repathArgs = AddSortedNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstNAggregateFunctionOid(), &context->sortSpec, &accumulatorName, context->variableSpec); } } else if (StringViewEqualsCString(&accumulatorName, "$lastN")) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_LASTN); bson_value_t input = { 0 }; bson_value_t elementsToFetch = { 0 }; ParseInputForNGroupAccumulators(&accumulatorElement.bsonValue, &input, &elementsToFetch, accumulatorName.string); if (context->sortSpec.value_type == BSON_TYPE_EOD) { repathArgs = AddSimpleNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastNOnSortedAggregateFunctionOid(), &accumulatorName, context->variableSpec); } else { repathArgs = AddSortedNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastNAggregateFunctionOid(), &context->sortSpec, &accumulatorName, context->variableSpec); } } else if (StringViewEqualsCString(&accumulatorName, "$maxN")) { repathArgs = AddMaxMinNGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonMaxNAggregateFunctionOid(), &accumulatorName, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$minN")) { repathArgs = AddMaxMinNGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonMinNAggregateFunctionOid(), &accumulatorName, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$addToSet")) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonAddToSetAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$mergeObjects")) { if (context->sortSpec.value_type == BSON_TYPE_EOD) { repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonMergeObjectsOnSortedFunctionOid(), context->variableSpec); } else { repathArgs = AddMergeObjectsGroupAccumulator(query, &accumulatorElement. bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, &context->sortSpec, context->variableSpec); } } else if (StringViewEqualsCString(&accumulatorName, "$push")) { char *fieldPath = ""; bool handleSingleValue = true; repathArgs = AddArrayAggGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonArrayAggregateAllArgsFunctionOid(), fieldPath, handleSingleValue, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$stdDevSamp")) { if (accumulatorElement.bsonValue.value_type == BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40237), errmsg( "The %s accumulator functions as a single-operand operator", accumulatorName.string)), errdetail_log( "The %s accumulator functions as a single-operand operator", accumulatorName.string)); } repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonStdDevSampAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$stdDevPop")) { if (accumulatorElement.bsonValue.value_type == BSON_TYPE_ARRAY) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40237), errmsg( "The %s accumulator functions as a single-operand operator", accumulatorName.string)), errdetail_log( "The %s accumulator functions as a single-operand operator", accumulatorName.string)); } repathArgs = AddSimpleGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonStdDevPopAggregateFunctionOid(), context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$top")) { bson_value_t output = { 0 }; bson_value_t elementsToFetch = { 0 }; bson_value_t sortSpec = { 0 }; ParseInputDocumentForTopAndBottom(&accumulatorElement.bsonValue, &output, &elementsToFetch, &sortSpec, accumulatorName.string); repathArgs = AddSortedGroupAccumulator(query, &output, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstAggregateFunctionOid(), &sortSpec, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$bottom")) { bson_value_t output = { 0 }; bson_value_t elementsToFetch = { 0 }; bson_value_t sortSpec = { 0 }; ParseInputDocumentForTopAndBottom(&accumulatorElement.bsonValue, &output, &elementsToFetch, &sortSpec, accumulatorName.string); repathArgs = AddSortedGroupAccumulator(query, &output, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastAggregateFunctionOid(), &sortSpec, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$topN")) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_TOPN); /* Parse accumulatorValue to pull output, n and sortBy*/ bson_value_t input = { 0 }; bson_value_t elementsToFetch = { 0 }; bson_value_t sortSpec = { 0 }; ParseInputDocumentForTopAndBottom(&accumulatorElement.bsonValue, &input, &elementsToFetch, &sortSpec, accumulatorName.string); repathArgs = AddSortedNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonFirstNAggregateFunctionOid(), &sortSpec, &accumulatorName, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$bottomN")) { ReportFeatureUsage(FEATURE_STAGE_GROUP_ACC_BOTTOMN); /* Parse accumulatorValue to pull output, n and sortBy*/ bson_value_t input = { 0 }; bson_value_t elementsToFetch = { 0 }; bson_value_t sortSpec = { 0 }; ParseInputDocumentForTopAndBottom(&accumulatorElement.bsonValue, &input, &elementsToFetch, &sortSpec, accumulatorName.string); repathArgs = AddSortedNGroupAccumulator(query, &input, &elementsToFetch, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, BsonLastNAggregateFunctionOid(), &sortSpec, &accumulatorName, context->variableSpec); } else if (StringViewEqualsCString(&accumulatorName, "$median")) { repathArgs = AddPercentileMedianGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, &accumulatorName, context->variableSpec, true); } else if (StringViewEqualsCString(&accumulatorName, "$percentile")) { repathArgs = AddPercentileMedianGroupAccumulator(query, &accumulatorElement.bsonValue, repathArgs, accumulatorText, parseState, identifiers, origEntry->expr, &accumulatorName, context->variableSpec, false); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15952), errmsg("Unrecognized group operator %s", accumulatorElement.path), errdetail_log("Unrecognized group operator %s", accumulatorElement.path))); } } /* Assign the _id clause as what we're grouping on */ SortGroupClause *grpcl = makeNode(SortGroupClause); grpcl->tleSortGroupRef = assignSortGroupRef(groupEntry, query->targetList); grpcl->eqop = BsonEqualOperatorId(); grpcl->sortop = BsonLessThanOperatorId(); grpcl->nulls_first = false; /* OK with or without sortop */ grpcl->hashable = true; query->groupClause = list_make1(grpcl); if (EnableIndexOrderbyPushdown) { /* Group by is valid for pushdown iff it's a string expression of a path that's not a variable */ bool isGroupByValidForIndexPushdown = idValue.value_type == BSON_TYPE_UTF8 && idValue.value.v_utf8.len > 1 && idValue.value.v_utf8.str[0] == '$' && idValue.value.v_utf8.str[1] != '$'; /* * If there's an orderby pushdown to the index, add a full scan clause iff * the query has no filters yet. */ if (isGroupByValidForIndexPushdown && CanPushSortFilterToIndex(query) && ( IsClusterVersionAtLeastPatch(DocDB_V0, 103, 1) || IsClusterVersionAtLeastPatch(DocDB_V0, 104, 1) || IsClusterVersionAtleast(DocDB_V0, 105, 0))) { pgbsonelement sortElement = { 0 }; sortElement.path = idValue.value.v_utf8.str + 1; sortElement.pathLength = idValue.value.v_utf8.len - 1; sortElement.bsonValue.value_type = BSON_TYPE_INT32; sortElement.bsonValue.value.v_int32 = 1; pgbson *sortSpec = PgbsonElementToPgbson(&sortElement); Const *sortConst = MakeBsonConst(sortSpec); List *rangeArgs = list_make2(origEntry->expr, sortConst); Expr *fullScanExpr = (Expr *) makeFuncExpr( BsonFullScanFunctionOid(), BOOLOID, rangeArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); List *currentQuals = make_ands_implicit( (Expr *) query->jointree->quals); currentQuals = lappend(currentQuals, fullScanExpr); query->jointree->quals = (Node *) make_ands_explicit( currentQuals); } } /* Now that the group + accumulators are done, push to a subquery * Request preserving the N-entry T-list */ context->expandTargetList = true; query = MigrateQueryToSubQuery(query, context); /* Take the output and replace it with the repath_and_build */ TargetEntry *entry = linitial(query->targetList); /* $group doesn't allow dotted path so no need to override */ bool overrideArrayInProjection = false; Expr *repathExpression = GenerateMultiExpressionRepathExpression(repathArgs, overrideArrayInProjection); entry->expr = repathExpression; entry->resname = origEntry->resname; /* Mark new stages to push a new subquery */ context->requiresSubQuery = true; return query; } /* * Pushes the current query into a subquery. * Then creates a brand new query that projects the 'document' value * from the underlying subquery. */ Query * MigrateQueryToSubQuery(Query *parse, AggregationPipelineBuildContext *context) { context->numNestedLevels++; TargetEntry *tle = (TargetEntry *) linitial(parse->targetList); RangeTblEntry *rte = MakeSubQueryRte(parse, context->stageNum, context->nestedPipelineLevel, "agg", context->expandTargetList); context->expandTargetList = false; Index childIndex = 1; Var *newQueryOutput = makeVar(childIndex, tle->resno, BsonTypeId(), -1, InvalidOid, 0); TargetEntry *upperEntry = makeTargetEntry((Expr *) newQueryOutput, 1, tle->resname, tle->resjunk); Query *newquery = makeNode(Query); newquery->commandType = CMD_SELECT; newquery->querySource = parse->querySource; newquery->canSetTag = true; newquery->targetList = list_make1(upperEntry); newquery->rtable = list_make1(rte); RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; newquery->jointree = makeFromExpr(list_make1(rtr), NULL); context->requiresSubQuery = false; return newquery; } /* * Creates an RTE for a Subquery provided given the prefixed stage name */ RangeTblEntry * MakeSubQueryRte(Query *subQuery, int stageNum, int pipelineDepth, const char *prefix, bool includeAllColumns) { RangeTblEntry *rte = makeNode(RangeTblEntry); rte->rtekind = RTE_SUBQUERY; rte->subquery = subQuery; rte->lateral = false; rte->inh = false; rte->inFromCl = true; StringInfo s = makeStringInfo(); if (pipelineDepth > 0) { appendStringInfo(s, "%s_stage_sub_%d_%d", prefix, pipelineDepth, stageNum); } else { appendStringInfo(s, "%s_stage_%d", prefix, stageNum); } rte->alias = makeAlias(s->data, NIL); if (includeAllColumns) { ListCell *cell; List *colnames = NIL; foreach(cell, subQuery->targetList) { TargetEntry *tle = lfirst(cell); /* append only non-junk columns */ if (!tle->resjunk) { colnames = lappend(colnames, makeString(tle->resname ? tle->resname : "")); } } rte->eref = makeAlias(s->data, colnames); } else { TargetEntry *tle = linitial(subQuery->targetList); List *colnames = list_make1(makeString(tle->resname ? tle->resname : "")); rte->eref = makeAlias(s->data, colnames); } return rte; } /* * Checks if partitionByFields expression of $densify stage is on the shard key * of the collection * * `partitionByFields`: { "": ["a", "b", "c"]} * `shardkey`: {"a": "hashed", "b": "hashed", "c": "hashed"} * * These 2 are same */ bool IsPartitionByFieldsOnShardKey(const pgbson *partitionByFields, const MongoCollection *collection) { if (collection == NULL || collection->shardKey == NULL || partitionByFields == NULL) { return false; } pgbson_writer shardKeyWriter; pgbson_array_writer arrayWriter; PgbsonWriterInit(&shardKeyWriter); PgbsonWriterStartArray(&shardKeyWriter, "", 0, &arrayWriter); bson_iter_t shardKeyIter; PgbsonInitIterator(collection->shardKey, &shardKeyIter); while (bson_iter_next(&shardKeyIter)) { PgbsonArrayWriterWriteUtf8(&arrayWriter, bson_iter_key(&shardKeyIter)); } PgbsonWriterEndArray(&shardKeyWriter, &arrayWriter); if (PgbsonEquals(PgbsonWriterGetPgbson(&shardKeyWriter), partitionByFields)) { return true; } return false; } /* * A simple function that never requires persistent cursors */ static bool RequiresPersistentCursorFalse(const bson_value_t *pipelineValue) { return false; } /* * A simple function that always requires persistent cursors */ static bool RequiresPersistentCursorTrue(const bson_value_t *pipelineValue) { return true; } /* * Checks that the limit stage requires persistence (true if it's not limit 1). */ static bool RequiresPersistentCursorLimit(const bson_value_t *pipelineValue) { if (pipelineValue->value_type != BSON_TYPE_EOD && BsonValueIsNumber(pipelineValue)) { int32_t limit = BsonValueAsInt32(pipelineValue); return limit != 1 && limit != 0; } return pipelineValue->value_type != BSON_TYPE_EOD; } /* * Checks that the skip stage requires persistence (true if it's not skip 0). */ static bool RequiresPersistentCursorSkip(const bson_value_t *pipelineValue) { if (pipelineValue->value_type != BSON_TYPE_EOD && BsonValueIsNumber(pipelineValue)) { int32_t skip = BsonValueAsInt32(pipelineValue); return skip != 0; } return pipelineValue->value_type != BSON_TYPE_EOD; } /* * Given a database, and a view definition, recursively extracts the * views pointed to by the view definition until a base collection (or non-existent) * collection is found. Also appends the pipeline stages associated with it to the * List of pipeline stages. */ static MongoCollection * ExtractViewDefinitionAndPipeline(Datum databaseDatum, pgbson *viewDefinition, List **pipelineStages, AggregationPipelineBuildContext *context) { int viewDepth = 0; bool canViewUseShardTable = context->allowShardBaseTable; while (true) { CHECK_FOR_INTERRUPTS(); check_stack_depth(); if (viewDepth > MAX_VIEW_DEPTH) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_VIEWDEPTHLIMITEXCEEDED), errmsg("View depth exceeded limit %d", MAX_VIEW_DEPTH))); } viewDepth++; ViewDefinition definition = { 0 }; DecomposeViewDefinition(viewDefinition, &definition); if (definition.pipeline.value_type != BSON_TYPE_EOD) { bson_value_t *valueCopy = palloc(sizeof(bson_value_t)); *valueCopy = definition.pipeline; List *stages = ExtractAggregationStages(valueCopy, context); if (!context->allowShardBaseTable) { /* If any nested view uses stage that can't use shard base table then * we will not use shard base tables. */ canViewUseShardTable = context->allowShardBaseTable; } *pipelineStages = lappend(*pipelineStages, stages); } MongoCollection *collection = GetMongoCollectionOrViewByNameDatum( databaseDatum, CStringGetTextDatum(definition.viewSource), NoLock); if (collection == NULL) { /* It's a non-existent table - we can stop the search */ return collection; } else if (collection->viewDefinition == NULL) { /* It's a base table - lock the table and stop the search */ GetRelationIdForCollectionId(collection->collectionId, AccessShareLock); context->allowShardBaseTable = canViewUseShardTable; return collection; } else { /* It's a view redo the check */ viewDefinition = collection->viewDefinition; } } } /* * Given the pipeline definition extract the stages as a list of `AggregationStage`. * Performs basic validation in the structure of the pipeline. * If `context->optimizePipelines` is set to true, the function will optimize the pipelines. */ List * ExtractAggregationStages(const bson_value_t *pipelineValue, AggregationPipelineBuildContext *context) { if (pipelineValue->value_type != BSON_TYPE_ARRAY || IsBsonValueEmptyArray(pipelineValue)) { return NIL; } bson_iter_t pipelineIterator; BsonValueInitIterator(pipelineValue, &pipelineIterator); const char *lastEncounteredOutputStage = NULL; List *aggregationStages = NIL; while (bson_iter_next(&pipelineIterator)) { bson_iter_t documentIterator; if (!BSON_ITER_HOLDS_DOCUMENT(&pipelineIterator) || !bson_iter_recurse(&pipelineIterator, &documentIterator)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "Every item within the 'pipeline' array is required to be an object."))); } pgbsonelement stageElement; if (!TryGetSinglePgbsonElementFromBsonIterator(&documentIterator, &stageElement)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40323), errmsg( "A pipeline stage specification object is required to have one and only one field."))); } /* If lastEncounteredOutputStage isn't NULL, it means we've seen an output stage like $out or $merge before this. * Since the output stage was expected to be last, encountering it earlier leads to failure. */ if (lastEncounteredOutputStage != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40601), errmsg( "%s must appear exclusively as the last stage in the pipeline", lastEncounteredOutputStage), errdetail_log( "%s must appear exclusively as the last stage in the pipeline", lastEncounteredOutputStage))); } /* Get the definition of the stage */ AggregationStageDefinition *definition = (AggregationStageDefinition *) bsearch( stageElement.path, StageDefinitions, AggregationStageCount, sizeof(AggregationStageDefinition), CompareStageByStageName); if (definition == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNRECOGNIZEDCOMMAND), errmsg("Pipeline stage name not recognized: %s", stageElement.path), errdetail_log("Pipeline stage name not recognized: %s", stageElement.path))); } if (definition->pipelineCheckFunc != NULL) { definition->pipelineCheckFunc(pipelineValue, context); } if (definition->mutateFunc == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Stage %s is not supported yet in native pipeline", definition->stage), errdetail_log( "Stage %s is not supported yet in native pipeline", definition->stage))); } if (definition->isOutputStage) { lastEncounteredOutputStage = definition->stage; } AggregationStage *stage = palloc0(sizeof(AggregationStage)); stage->stageDefinition = definition; stage->stageValue = stageElement.bsonValue; aggregationStages = lappend(aggregationStages, stage); } /* * Validate number of stages in the pipeline, we purposefully do it here because * it saves a few CPU cycles to not check the length everytime for each stage * * But, because of this large pipelines will not fail as soon as they exceed the limit but eventually * fail. This is a tradeoff for perf b/w most of the valid cases v/s the rare invalid ones. */ CheckMaxAllowedAggregationStages(list_length(aggregationStages)); if (context->optimizePipelineStages) { TryOptimizeAggregationPipelines(&aggregationStages, context); } return aggregationStages; } /* * Updates the base table */ Query * GenerateBaseTableQuery(text *databaseDatum, const StringView *collectionNameView, pg_uuid_t *collectionUuid, const bson_value_t *indexHint, AggregationPipelineBuildContext *context) { Query *query = makeNode(Query); query->commandType = CMD_SELECT; query->querySource = QSRC_ORIGINAL; query->canSetTag = true; context->collectionNameView = *collectionNameView; context->namespaceName = CreateNamespaceName(databaseDatum, collectionNameView); Datum collectionNameDatum = PointerGetDatum( cstring_to_text_with_len(collectionNameView->string, collectionNameView->length)); MongoCollection *collection = GetMongoCollectionOrViewByNameDatum(PointerGetDatum( databaseDatum), collectionNameDatum, AccessShareLock); /* CollectionUUID mismatch when collection doesn't exist */ if (collectionUuid != NULL) { if (collection == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COLLECTIONUUIDMISMATCH), errmsg( "Namespace %s contains a mismatch in the collectionUUID identifier: Collection does not exist", context->namespaceName))); } if (memcmp(collectionUuid->data, collection->collectionUUID.data, 16) != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COLLECTIONUUIDMISMATCH), errmsg( "Namespace %s contains a mismatch in the collectionUUID identifier", context->namespaceName))); } } List *pipelineStages = NIL; if (collection != NULL && collection->viewDefinition != NULL) { collection = ExtractViewDefinitionAndPipeline(PointerGetDatum(databaseDatum), collection->viewDefinition, &pipelineStages, context); } context->mongoCollection = collection; /* First step - create the RTE. * This is either a RTE for a table, or the empty table RTE. * (Note that sample can modify this later in the sample stage). */ RangeTblEntry *rte = makeNode(RangeTblEntry); /* Match spec for ApiSchema.collection() function */ List *colNames = list_make3(makeString("shard_key_value"), makeString("object_id"), makeString("document")); const char *collectionAlias = "collection"; if (context->numNestedLevels > 0 || context->nestedPipelineLevel > 0) { StringInfo s = makeStringInfo(); appendStringInfo(s, "collection_%d_%d", context->numNestedLevels, context->nestedPipelineLevel); collectionAlias = s->data; } if (collection == NULL) { /* Here: Special case, if the database is config, try to see if we can create a base * table out of the system metadata. */ StringView databaseView = CreateStringViewFromText(databaseDatum); if (StringViewEqualsCString(&databaseView, "config")) { Query *returnedQuery = GenerateConfigDatabaseQuery(context); if (returnedQuery != NULL) { return returnedQuery; } } rte->rtekind = RTE_FUNCTION; rte->relid = InvalidOid; rte->lateral = false; rte->inFromCl = true; rte->functions = NIL; rte->inh = false; #if PG_VERSION_NUM >= 160000 rte->perminfoindex = 0; #else rte->requiredPerms = ACL_SELECT; #endif rte->rellockmode = AccessShareLock; /* Now create the rtfunc*/ FuncExpr *rangeFunc = makeFuncExpr(BsonEmptyDataTableFunctionId(), RECORDOID, NIL, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); rangeFunc->funcretset = true; RangeTblFunction *rangeTableFunction = makeNode(RangeTblFunction); rangeTableFunction->funccolcount = 3; rangeTableFunction->funcparams = NULL; rangeTableFunction->funcexpr = (Node *) rangeFunc; rte->alias = makeAlias(collectionAlias, NIL); rte->eref = makeAlias(collectionAlias, colNames); /* Add the RTFunc to the RTE */ rte->functions = list_make1(rangeTableFunction); } else { rte->rtekind = RTE_RELATION; rte->relid = collection->relationId; if (collection->mongoDataCreationTimeVarAttrNumber != -1) { colNames = lappend(colNames, makeString("creation_time")); } if (context->allowShardBaseTable) { Oid shardOid = TryGetCollectionShardTable(collection, AccessShareLock); if (shardOid != InvalidOid) { /* Mark on our copy of the collection that we're using the shard */ collection->relationId = shardOid; rte->relid = shardOid; } else if (DefaultInlineWriteOperations) { context->allowShardBaseTable = true; } else { /* Signal that shard table pushdown didn't succeed */ context->allowShardBaseTable = false; } } rte->alias = makeAlias(collectionAlias, NIL); rte->eref = makeAlias(collectionAlias, colNames); rte->lateral = false; rte->inFromCl = true; rte->relkind = RELKIND_RELATION; rte->functions = NIL; rte->inh = true; #if PG_VERSION_NUM >= 160000 RTEPermissionInfo *permInfo = addRTEPermissionInfo(&query->rteperminfos, rte); permInfo->requiredPerms = ACL_SELECT; #else rte->requiredPerms = ACL_SELECT; #endif rte->rellockmode = AccessShareLock; } query->rtable = list_make1(rte); /* Now register the RTE in the "FROM" clause with no filters */ RangeTblRef *rtr = makeNode(RangeTblRef); rtr->rtindex = 1; query->jointree = makeFromExpr(list_make1(rtr), NULL); /* Create the projector. We only project the 'document' column in this type of query */ Var *documentEntry = CreateDocumentVar(); TargetEntry *baseTargetEntry = makeTargetEntry((Expr *) documentEntry, 1, "document", false); query->targetList = list_make1(baseTargetEntry); /* Now do filters - if there's no shard key we inject a default shard key of 'collectionId' */ if (collection != NULL && collection->shardKey == NULL) { /* construct a shard_key_value = filter */ Expr *zeroShardKeyFilter = CreateNonShardedShardKeyValueFilter( documentEntry->varno, collection); /* add the filter to WHERE */ query->jointree->quals = (Node *) zeroShardKeyFilter; } /* Before applying the view stages, apply the hint on the base table */ if (collection != NULL && indexHint != NULL && indexHint->value_type != BSON_TYPE_EOD && IsClusterVersionAtleast(DocDB_V0, 106, 0)) { const char *indexName = NULL; bool isSparse = false; pgbson *indexKeyDocument = NULL; if (indexHint->value_type == BSON_TYPE_UTF8) { indexName = indexHint->value.v_utf8.str; IndexDetails *details = IndexNameGetReadyIndexDetails( collection->collectionId, indexName); if (details == NULL) { /* * Compatibility Notice: The text in this error string is copied verbatim from MongoDB output to maintain * compatibility with existing tools and scripts that rely on specific error message formats. * Modifying this text may cause unexpected behavior in dependent systems. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "index specified by index hint is not found: hint provided does not correspond to an existing index"))); } indexKeyDocument = details->indexSpec.indexKeyDocument; isSparse = details->indexSpec.indexSparse; } else if (indexHint->value_type == BSON_TYPE_DOCUMENT) { indexKeyDocument = PgbsonInitFromDocumentBsonValue(indexHint); if (IsNaturalSortHint(indexHint)) { /* Index hint is $natural, in this case */ indexName = "_id_"; } else { List *indexDocs = IndexKeyGetReadyMatchingIndexes( collection->collectionId, indexKeyDocument); if (list_length(indexDocs) == 0) { /* * Compatibility Notice: The text in this error string is copied verbatim from MongoDB output to maintain * compatibility with existing tools and scripts that rely on specific error message formats. * Modifying this text may cause unexpected behavior in dependent systems. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "index specified by index hint is not found: hint provided does not correspond to an existing index"))); } else if (list_length(indexDocs) > 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "index specified by index hint is ambiguous. please specify hint by name"))); } IndexDetails *detail = linitial(indexDocs); indexName = pstrdup(detail->indexSpec.indexName); isSparse = detail->indexSpec.indexSparse; list_free_deep(indexDocs); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS), errmsg( "Index hint should be provided as either a string or a document"))); } FuncExpr *indexHintExpr = makeFuncExpr( BsonIndexHintFunctionOid(), BOOLOID, list_make4(documentEntry, MakeTextConst(indexName, strlen(indexName)), MakeBsonConst(indexKeyDocument), makeBoolConst(isSparse, false)), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (query->jointree->quals == NULL) { query->jointree->quals = (Node *) indexHintExpr; } else { List *currentQuals = make_ands_implicit((Expr *) query->jointree->quals); currentQuals = lappend(currentQuals, indexHintExpr); query->jointree->quals = (Node *) make_ands_explicit(currentQuals); } } /* Now if there's pipeline stages, apply the stages in reverse (innermost first) */ for (int i = list_length(pipelineStages) - 1; i >= 0; i--) { List *stages = list_nth(pipelineStages, i); query = MutateQueryWithPipeline(query, stages, context); } return query; } /* * Given a query, adds the cursor based functions to the query if it's a streaming query * and updates the queryData with the appropriate information. */ static void AddCursorFunctionsToQuery(Query *query, Query *baseQuery, QueryData *queryData, AggregationPipelineBuildContext *context, bool addCursorAsConst) { if (queryData->cursorKind != QueryCursorType_Streamable) { return; } /* Add the projector and percolate it down */ if (baseQuery != query) { /* * Technically we can support this for narrow scenarios like: * {"$match"}{"$limit": 1 } {"$addFields"} * We can just mark this as non-streamable. * Note that this typically wont add any actual persistent state * since it'll likely drain in 1 shot due to the $limit: 1 */ elog(LOG_SERVER_ONLY, "Query has more than 1 level with streaming mode."); queryData->cursorKind = QueryCursorType_Persistent; return; } /* Add a parameter for the cursor state */ Node *cursorNode; if (addCursorAsConst) { cursorNode = (Node *) MakeBsonConst(PgbsonInitEmpty()); } else { context->currentParamCount++; queryData->cursorStateParamNumber = context->currentParamCount; Param *param = makeNode(Param); param->paramid = queryData->cursorStateParamNumber; param->paramkind = PARAM_EXTERN; param->paramtype = BsonTypeId(); param->paramtypmod = -1; cursorNode = (Node *) param; } /* Create the WHERE cursor_state(document, continuationParam) and add it to the WHERE */ List *cursorArgs = list_make2(CreateDocumentVar(), cursorNode); FuncExpr *cursorQual = makeFuncExpr(ApiCursorStateFunctionId(), BOOLOID, cursorArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (baseQuery->jointree->quals != NULL) { List *ands = make_ands_implicit((Expr *) baseQuery->jointree->quals); ands = lappend(ands, cursorQual); baseQuery->jointree->quals = (Node *) make_ands_explicit(ands); } else { baseQuery->jointree->quals = (Node *) cursorQual; } /* Add the cursor projector */ TargetEntry *entry = llast(query->targetList); List *projectorArgs = list_make1(CreateDocumentVar()); FuncExpr *projectionExpr = makeFuncExpr(ApiCurrentCursorStateFunctionId(), BsonTypeId(), projectorArgs, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); bool resjunk = false; TargetEntry *newEntry = makeTargetEntry((Expr *) projectionExpr, entry->resno + 1, "continuation", resjunk); query->targetList = lappend(query->targetList, newEntry); } /* * This function adds the continuation condition to the query for change stream, * to make sure the continuation token is always returned to the caller event if * the change document doesn't match the $match condition in the aggregation pipeline. * An example query after the modification here will be: * SELECT document, continuation * FROM change_stream_aggregation() * WHERE * document IS NULL // This condition is added to make sure the continuation token is always returned * // even if the change document doesn't match the $match condition in the aggregation pipeline. * OR * */ static void AddQualifierForTailableQuery(Query *query, Query *baseQuery, QueryData *queryData, AggregationPipelineBuildContext *context) { Assert(queryData->cursorKind == QueryCursorType_Tailable); /* Make sure that continuation is still projected after all mutations. */ TargetEntry *entry = llast(query->targetList); if (entry->resname == NULL || strcmp(entry->resname, "continuation") != 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS), errmsg( "The last target entry in the query must be the document"))); } /* * If there are some WHERE clause qualifiers, in a change stream query, then prepend * the condition document IS NULL OR to the WHERE clause. * This is needed becuase, when document IS NULL, change stream aggregation still * needs to provide the continuation doc for the tailable cursor to continue the * change stream query next time. So any other qualifiers should be ORed with this * NULL check so that they don't filter out the document IS NULL condition. * * Before transformation: * SELECT doc, continuation FROM change_stream_aggregation() * WHERE bson_dollor_match(doc) //doc.full_document.operationtype == "insert" * * After transformation: * SELECT doc, continuation FROM change_stream_aggregation() * (document IS NULL) OR * (WHERE bson_dollor_match(doc) //doc.full_document.operationtype == "insert") */ if (query->jointree->quals != NULL) { Var *documentVar = CreateChangeStreamDocumentVar(); NullTest *nullTest = makeNode(NullTest); nullTest->argisrow = false; nullTest->nulltesttype = IS_NULL; nullTest->arg = (Expr *) documentVar; /* Create the new OR clause including cursorQual */ List *qualifierList = list_make1(query->jointree->quals); /* Prepend the document == NULL condition first before any other qualifiers. */ qualifierList = lcons(nullTest, qualifierList); /* Add the new OR clause to the query */ query->jointree->quals = (Node *) make_orclause(qualifierList); } } /* * Processes the Sample stage for the aggregation pipeline. * If the sample is against the base RTE - injects the Sample TSM. * If it's on a downstream stage, injects an ORDER BY Random(). */ static Query * HandleSample(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { ReportFeatureUsage(FEATURE_STAGE_SAMPLE); if (existingValue->value_type != BSON_TYPE_DOCUMENT) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28745), errmsg( "The $sample stage specification is required to be provided as an object."))); } bson_iter_t sampleIter; BsonValueInitIterator(existingValue, &sampleIter); bson_value_t sizeValue = { 0 }; while (bson_iter_next(&sampleIter)) { if (strcmp(bson_iter_key(&sampleIter), "size") == 0) { sizeValue = *bson_iter_value(&sampleIter); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28748), errmsg("Option not recognized for $sample"))); } } if (sizeValue.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28749), errmsg("The $sample stage must explicitly define a size value"))); } if (!BsonValueIsNumber(&sizeValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28746), errmsg( "The size parameter provided to $sample must be a valid numeric value"))); } double sizeDouble = BsonValueAsDouble(&sizeValue); if (sizeDouble < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION28747), errmsg( "The size parameter provided to $sample must be a valid numeric value"))); } /* If the sample is against the base RTE - convert to a sample CTE */ RangeTblEntry *rte = linitial(query->rtable); /* If there is a filter that's not the default filter then we can't push down sample */ /* TOOD: Pushdown sample to base RTE for $lookup. */ if (rte->rtekind == RTE_RELATION && IsDefaultJoinTree(query->jointree->quals)) { /* Then just convert this to a Sample RTE */ if (rte->tablesample != NULL) { Node *sampleArg = linitial(rte->tablesample->args); if (!IsA(sampleArg, Const)) { ereport(PANIC, (errmsg("Expected tample sample to be a const"))); } Const *constVal = (Const *) sampleArg; int64_t finalSize = DatumGetInt64(constVal->constvalue); finalSize = Min(finalSize, sizeDouble); constVal->constvalue = Int64GetDatum(finalSize); } else { TableSampleClause *tablesample_sys_rows = makeNode(TableSampleClause); tablesample_sys_rows->tsmhandler = ExtensionTableSampleSystemRowsFunctionId(); Node *rowCountArg = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(sizeDouble), false, true); tablesample_sys_rows->args = list_make1(rowCountArg); rte->tablesample = tablesample_sys_rows; } } /* Add an order by Random(), Limit N */ ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(query->targetList) + 1; Expr *expr = (Expr *) makeFuncExpr(PgRandomFunctionOid(), FLOAT8OID, NIL, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_DEFAULT; /* reset later */ sortBy->node = (Node *) expr; bool resjunk = true; TargetEntry *sortEntry = makeTargetEntry((Expr *) expr, (AttrNumber) parseState->p_next_resno++, "?sort?", resjunk); query->targetList = lappend(query->targetList, sortEntry); List *sortlist = addTargetToSortList(parseState, sortEntry, NIL, query->targetList, sortBy); pfree(parseState); if (sortlist == NIL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION15976), errmsg( "The $sort stage requires specifying at least one sorting key to proceed"))); } query->sortClause = sortlist; query->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(sizeDouble), false, true); /* Push next stage to a new subquery (since we did a sort) */ context->requiresSubQuery = true; return query; } /* * Helper method used by MutateStageWithPipeline to extract the appropriate * Stage information. Compares the aggregation stage by the ordinal comparison * of its name. */ static int CompareStageByStageName(const void *a, const void *b) { const char *key = (const char *) a; AggregationStageDefinition *stage = (AggregationStageDefinition *) b; return strcmp(key, stage->stage); } /* * Whether or not the quals is the default * shard_key_value = 'int' */ static bool IsDefaultJoinTree(Node *node) { if (node == NULL) { return true; } if (!IsA(node, OpExpr)) { return false; } OpExpr *opExpr = (OpExpr *) node; return opExpr->opno == BigintEqualOperatorId(); } /* * Default helper for a stage that can always be inlined for a $lookup such as $match */ static bool CanInlineLookupStageTrue(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet) { return true; } static bool QueryDocumentHasExpr(bson_iter_t *queryIter) { check_stack_depth(); while (bson_iter_next(queryIter)) { const char *key = bson_iter_key(queryIter); if (strcmp(key, "$expr") == 0) { return true; } if (strcmp(key, "$and") == 0 || strcmp(key, "$or") == 0) { if (!BSON_ITER_HOLDS_ARRAY(queryIter)) { continue; } bson_iter_t andOrIter; if (bson_iter_recurse(queryIter, &andOrIter)) { while (bson_iter_next(&andOrIter)) { if (!BSON_ITER_HOLDS_DOCUMENT(&andOrIter)) { continue; } bson_iter_t andElementIter; if (bson_iter_recurse(&andOrIter, &andElementIter) && QueryDocumentHasExpr(&andElementIter)) { return true; } } } } } return false; } /* * Checks if $match can be inlined for $lookup */ static bool CanInlineLookupStageMatch(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet) { if (!hasLet) { /* Without let $match can always be inlined */ return true; } if (stageValue->value_type != BSON_TYPE_DOCUMENT) { return false; } /* With let $match can be inlined if there's no $expr */ bson_iter_t queryIter; BsonValueInitIterator(stageValue, &queryIter); return !QueryDocumentHasExpr(&queryIter); } /* * Helper for a projection stage on whether it can be inlined for a $lookup. * Can be inlined if all the projection functions are not prefixes or suffixes * of the lookup local path. * We can probably do better but that is left as an exercise for later. */ static bool CanInlineLookupStageProjection(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet) { if (stageValue->value_type != BSON_TYPE_DOCUMENT) { return false; } if (hasLet) { return false; } bson_iter_t projectIter; BsonValueInitIterator(stageValue, &projectIter); while (bson_iter_next(&projectIter)) { const StringView keyView = bson_iter_key_string_view(&projectIter); if (StringViewStartsWithStringView(&keyView, lookupPath) || StringViewStartsWithStringView(lookupPath, &keyView)) { return false; } } return true; } /* * Helper for an unset stage on whether it can be inlined for a $lookup. */ static bool CanInlineLookupStageUnset(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet) { /* An unset can be pushed up if */ if (stageValue->value_type == BSON_TYPE_UTF8) { /* a) it is a string and it's not equal to or a suffix of the lookup path */ StringView unsetStr = { .string = stageValue->value.v_utf8.str, .length = stageValue->value.v_utf8.len }; return !StringViewStartsWithStringView(&unsetStr, lookupPath); } else if (stageValue->value_type == BSON_TYPE_ARRAY) { /* or b) it's an array, and none of the unset paths intersect with the lookup path */ bson_iter_t unsetArrayIter; BsonValueInitIterator(stageValue, &unsetArrayIter); bool allIndependentOfLookup = true; while (bson_iter_next(&unsetArrayIter) && allIndependentOfLookup) { if (BSON_ITER_HOLDS_UTF8(&unsetArrayIter)) { StringView unsetStr = { 0 }; unsetStr.string = bson_iter_utf8(&unsetArrayIter, &unsetStr.length); allIndependentOfLookup = !StringViewStartsWithStringView(&unsetStr, lookupPath); } else { allIndependentOfLookup = false; } } return allIndependentOfLookup; } return false; } /* * Helper for an unwind stage on whether it can be inlined for a $lookup. */ static bool CanInlineLookupStageUnwind(const bson_value_t *stageValue, const StringView *lookupPath, bool hasLet) { /* An unwind can be pushed up if */ if (stageValue->value_type == BSON_TYPE_UTF8) { /* a) it is a string and it's not equal to or a suffix of the lookup path */ StringView unwindStr = { .string = stageValue->value.v_utf8.str, .length = stageValue->value.v_utf8.len }; return !StringViewStartsWithStringView(&unwindStr, lookupPath); } else if (stageValue->value_type == BSON_TYPE_DOCUMENT) { /* or b) it's an object, and the unwind path here is a suffix of the lookup path */ bson_iter_t optionsDocIter; BsonValueInitIterator(stageValue, &optionsDocIter); if (bson_iter_find(&optionsDocIter, "path") && BSON_ITER_HOLDS_UTF8(&optionsDocIter)) { StringView unwindStr = { 0 }; unwindStr.string = bson_iter_utf8(&optionsDocIter, &unwindStr.length); return !StringViewStartsWithStringView(&unwindStr, lookupPath); } } return false; } /* * parses the 'cursor' field in a query or aggregation spec. */ void ParseCursorDocument(bson_iter_t *iterator, QueryData *queryData) { EnsureTopLevelFieldType("cursor", iterator, BSON_TYPE_DOCUMENT); bson_iter_t cursorDocIter; if (!bson_iter_recurse(iterator, &cursorDocIter)) { return; } while (bson_iter_next(&cursorDocIter)) { const char *path = bson_iter_key(&cursorDocIter); const bson_value_t *value = bson_iter_value(&cursorDocIter); if (strcmp(path, "batchSize") == 0) { SetBatchSize("cursor.batchSize", value, queryData); } else if (strcmp(path, "singleBatch") == 0) { EnsureTopLevelFieldType("cursor.singleBatch", &cursorDocIter, BSON_TYPE_BOOL); if (value->value.v_bool) { queryData->cursorKind = QueryCursorType_SingleBatch; } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Field not recognized: %s", path))); } } } /* Check $match stage for sort clause. If there is one, $near or $nearSphere was used which is not allowed. */ static void ValidateQueryTreeForMatchStage(const Query *query) { if (!query->sortClause) { return; } bool isGeoNear = false; ListCell *cell; foreach(cell, query->sortClause) { SortGroupClause *sortClause = (SortGroupClause *) lfirst(cell); TargetEntry *tle = get_sortgroupclause_tle(sortClause, query->targetList); if (tle->resjunk && IsA(tle->expr, OpExpr) && ((OpExpr *) tle->expr)->opno == BsonGeonearDistanceOperatorId()) { if (isGeoNear) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg("Too many geoNear expressions"))); } isGeoNear = true; } } if (!isGeoNear) { return; } TargetEntry *targetEntry = linitial(query->targetList); Node *node = (Node *) targetEntry->expr; if (!(IsA(node, FuncExpr) && CheckFuncExprBsonDollarProjectGeonear( (FuncExpr *) node))) { ThrowGeoNearNotAllowedInContextError(); } } /* * Recursively check all func project func expression to check if it has $geoNear project * bson_dollar_add(bson_dollar_project...) */ static bool CheckFuncExprBsonDollarProjectGeonear(const FuncExpr *funcExpr) { CHECK_FOR_INTERRUPTS(); check_stack_depth(); bool isGeoNearProject = false; if (funcExpr->funcid == BsonDollarProjectGeonearFunctionOid()) { isGeoNearProject = true; } else { /* loop all args */ ListCell *cell; foreach(cell, funcExpr->args) { Expr *expr = (Expr *) lfirst(cell); if (IsA(expr, FuncExpr)) { isGeoNearProject = CheckFuncExprBsonDollarProjectGeonear((FuncExpr *) expr); if (isGeoNearProject) { break; } } } } return isGeoNearProject; } /* * Handles $match aggregation stage and validates the query tree for geospatial queries. */ static Query * HandleMatchAggregationStage(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { query = HandleMatch(existingValue, query, context); ValidateQueryTreeForMatchStage(query); return query; } /* * We will try to optimize the aggregation stages here. Currently this method checks * if all the stages are referring to a single collection that is not sharded then we * can convert the query to push it down to the particular shard (single node) * TODO: Other optimizations to be followed * 1- Merge consecutive projection stages to be merged. * 2- Improve match stage if preceded by a projection stage and the filter is on a renamed field which could * potentially use index. */ static void TryOptimizeAggregationPipelines(List **aggregationStages, AggregationPipelineBuildContext *context) { List *stagesList = *aggregationStages; if (stagesList == NIL || list_length(stagesList) == 0) { return; } /* Whether or not we can safely push the aggregation pipeline query to the shard table directly depends on * if all the stages refer to a single collection and it is not sharded, only in this case it is feasible to push * these queries directly to shard table. */ bool allowShardBaseTable = true; int nextIndex = 0; int currentIndex = 0; ListCell *cell; foreach(cell, stagesList) { currentIndex = foreach_current_index(cell); if (currentIndex < nextIndex) { continue; } AggregationStage *stage = (AggregationStage *) lfirst(cell); const AggregationStageDefinition *definition = stage->stageDefinition; if (!definition->allowBaseShardTablePushdown) { /* If any stage doesn't support it the final value is not supported */ allowShardBaseTable = false; } if (definition->stageEnum == Stage_Lookup) { /* Optimization for $lookup stage */ if (currentIndex < list_length(stagesList) - 1) { AggregationStage *nextStage = (AggregationStage *) lfirst(list_nth_cell(stagesList, currentIndex + 1)); if (nextStage->stageDefinition->stageEnum == Stage_Unwind) { /* If the next stage is $unwind, we can merge the $lookup and $unwind stages into a single stage. * This is because $lookup followed by $unwind is a common pattern and can be optimized to a single stage, * if $unwind is requested on the same field which is the "as" field in lookup stage. */ bool preserveEmptyArrays = false; if (CanInlineLookupWithUnwind(&stage->stageValue, &nextStage->stageValue, &preserveEmptyArrays)) { *aggregationStages = foreach_delete_current(stagesList, cell); AggregationStage *lookupUnwindStage = nextStage; /* merge preserve empty arrays and the lookup spec */ pgbson_writer writer; PgbsonWriterInit(&writer); PgbsonWriterAppendBool(&writer, "preserveNullAndEmptyArrays", 26, preserveEmptyArrays); PgbsonWriterAppendValue(&writer, "lookup", 6, &stage->stageValue); lookupUnwindStage->stageValue = ConvertPgbsonToBsonValue( PgbsonWriterGetPgbson(&writer)); lookupUnwindStage->stageDefinition = (AggregationStageDefinition *) &LookupUnwindStageDefinition; } } } } nextIndex = currentIndex + 1; } context->allowShardBaseTable = allowShardBaseTable; } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_statistics.c000066400000000000000000002255151507310017400276310ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_statistics.c * * Implementation of the aggregate functions typically used in * statistical analysis (such as covariance, standard deviation, etc.) * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include "utils/documentdb_errors.h" #include "types/decimal128.h" /* --------------------------------------------------------- */ /* Data-types */ /* --------------------------------------------------------- */ /* state used for pop and sample variance/covariance both */ /* for variance calculation x = y */ typedef struct BsonCovarianceAndVarianceAggState { bson_value_t sx; bson_value_t sy; bson_value_t sxy; int64_t count; /* number of decimal values in current window, used to determine if we need to return decimal128 value */ int decimalCount; } BsonCovarianceAndVarianceAggState; typedef struct BsonExpMovingAvg { bool init; bool isAlpha; bson_value_t weight; bson_value_t preValue; } BsonExpMovingAvg; enum InputValidFlags { InputValidFlags_Unknown = 0, InputValidFlags_N = 1, InputValidFlags_Alpha = 2, InputValidFlags_Input = 4 }; typedef struct BsonIntegralAndDerivativeAggState { /* The result value of current window */ bson_value_t result; /* anchorX/anchorY is an anchor point for calculating integral or derivative. * For $integral, anchorX is updated to the previous document of the window, * For $derivative, anchorX is always updated to the first document of the window. */ bson_value_t anchorX; bson_value_t anchorY; } BsonIntegralAndDerivativeAggState; /* * ArithmeticOperation is used to determine which operation to perform. * The operations are: * ArithmeticOperation_Add, i.e. AddNumberToBsonValue, * ArithmeticOperation_Subtract, i.e. SubtractNumberFromBsonValue, * ArithmeticOperation_Multiply, i.e. MultiplyWithFactorAndUpdate, or * ArithmeticOperation_Divide, i.e. DivideBsonValueNumbers. */ typedef enum ArithmeticOperation { ArithmeticOperation_Add = 0, ArithmeticOperation_Subtract = 1, ArithmeticOperation_Multiply = 2, ArithmeticOperation_Divide = 3 } ArithmeticOperation; typedef enum ArithmeticOperationErrorSource { OperationSource_CovariancePopFinal = 0, OperationSource_CovarianceSampFinal = 1, OperationSource_StdDevPopFinal = 2, OperationSource_StdDevSampFinal = 3, OperationSource_StdDevPopWinfuncFinal = 4, OperationSource_StdDevSampWinfuncFinal = 5, OperationSource_InvYCAlgr = 6, OperationSource_CombineYCAlgr = 7, OperationSource_SFuncYCAlgr = 8, OperationSource_ExpMovingAvg = 9, } ArithmeticOperationErrorSource; /* --------------------------------------------------------- */ /* Forward declaration */ /* --------------------------------------------------------- */ bool ParseInputWeightForExpMovingAvg(const bson_value_t *opValue, bson_value_t *inputExpression, bson_value_t *weightExpression, bson_value_t *decimalWeightValue); static bytea * AllocateBsonCovarianceOrVarianceAggState(void); static void CalculateCombineFuncForCovarianceOrVarianceWithYCAlgr(const BsonCovarianceAndVarianceAggState *leftState, const BsonCovarianceAndVarianceAggState *rightState, BsonCovarianceAndVarianceAggState *currentState); static void CalculateInvFuncForCovarianceOrVarianceWithYCAlgr(const bson_value_t *newXValue, const bson_value_t * newYValue, BsonCovarianceAndVarianceAggState *currentState); static void CalculateSFuncForCovarianceOrVarianceWithYCAlgr(const bson_value_t *newXValue, const bson_value_t *newYValue, BsonCovarianceAndVarianceAggState *currentState); static void CalculateExpMovingAvg(bson_value_t *currentValue, bson_value_t *perValue, bson_value_t *weightValue, bool isAlpha, bson_value_t *resultValue); static bytea * AllocateBsonIntegralAndDerivativeAggState(void); static void HandleIntegralDerivative(bson_value_t *xBsonValue, bson_value_t *yBsonValue, long timeUnitInMs, BsonIntegralAndDerivativeAggState *currentState, const bool isIntegralOperator); static void RunTimeCheckForIntegralAndDerivative(bson_value_t *xBsonValue, bson_value_t *yBsonValue, long timeUnitInMs, const bool isIntegralOperator); static bool IntegralOfTwoPointsByTrapezoidalRule(bson_value_t *xValue, bson_value_t *yValue, BsonIntegralAndDerivativeAggState * currentState, bson_value_t *timeUnitInMs); static bool DerivativeOfTwoPoints(bson_value_t *xValue, bson_value_t *yValue, BsonIntegralAndDerivativeAggState *currentState, bson_value_t *timeUnitInMs); static void CalculateSqrtForStdDev(const bson_value_t *inputValue, bson_value_t *outputResult); static void ArithmeticOperationFunc(ArithmeticOperation op, bson_value_t *state, const bson_value_t *number, ArithmeticOperationErrorSource errSource); static void HandleArithmeticOperationError(const char *opName, bson_value_t *state, const bson_value_t *number, ArithmeticOperationErrorSource errSource); /* --------------------------------------------------------- */ /* Top level exports */ /* --------------------------------------------------------- */ PG_FUNCTION_INFO_V1(bson_covariance_pop_samp_transition); PG_FUNCTION_INFO_V1(bson_covariance_pop_samp_combine); PG_FUNCTION_INFO_V1(bson_covariance_pop_samp_invtransition); PG_FUNCTION_INFO_V1(bson_covariance_pop_final); PG_FUNCTION_INFO_V1(bson_covariance_samp_final); PG_FUNCTION_INFO_V1(bson_std_dev_pop_samp_transition); PG_FUNCTION_INFO_V1(bson_std_dev_pop_samp_combine); PG_FUNCTION_INFO_V1(bson_std_dev_pop_final); PG_FUNCTION_INFO_V1(bson_std_dev_samp_final); PG_FUNCTION_INFO_V1(bson_exp_moving_avg); PG_FUNCTION_INFO_V1(bson_derivative_transition); PG_FUNCTION_INFO_V1(bson_integral_transition); PG_FUNCTION_INFO_V1(bson_integral_derivative_final); PG_FUNCTION_INFO_V1(bson_std_dev_pop_samp_winfunc_invtransition); PG_FUNCTION_INFO_V1(bson_std_dev_pop_winfunc_final); PG_FUNCTION_INFO_V1(bson_std_dev_samp_winfunc_final); /* * Transition function for the BSONCOVARIANCEPOP and BSONCOVARIANCESAMP aggregate. * Use the Youngs-Cramer algorithm to incorporate the new value into the * transition values. * If calculating variance, we use X and Y as the same value. */ Datum bson_covariance_pop_samp_transition(PG_FUNCTION_ARGS) { bytea *bytes; BsonCovarianceAndVarianceAggState *currentState; /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function is invoked outside a valid window aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytes = AllocateBsonCovarianceOrVarianceAggState(); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA(bytes); currentState->sx.value_type = BSON_TYPE_DOUBLE; currentState->sx.value.v_double = 0.0; currentState->sy.value_type = BSON_TYPE_DOUBLE; currentState->sy.value.v_double = 0.0; currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = 0.0; currentState->count = 0; currentState->decimalCount = 0; MemoryContextSwitchTo(oldContext); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(bytes); } pgbson *currentXValue = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *currentYValue = PG_GETARG_MAYBE_NULL_PGBSON(2); if (currentXValue == NULL || IsPgbsonEmptyDocument(currentXValue) || currentYValue == NULL || IsPgbsonEmptyDocument(currentYValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentXValueElement; PgbsonToSinglePgbsonElement(currentXValue, ¤tXValueElement); pgbsonelement currentYValueElement; PgbsonToSinglePgbsonElement(currentYValue, ¤tYValueElement); /* we should ignore numeric values */ if (BsonValueIsNumber(¤tXValueElement.bsonValue) && BsonValueIsNumber(¤tYValueElement.bsonValue)) { CalculateSFuncForCovarianceOrVarianceWithYCAlgr(¤tXValueElement.bsonValue, ¤tYValueElement.bsonValue, currentState); } PG_RETURN_POINTER(bytes); } /* * Applies the "combine function" (COMBINEFUNC) for BSONCOVARIANCEPOP and BSONCOVARIANCESAMP. * takes two of the aggregate state structures (BsonCovarianceAndVarianceAggState) * and combines them to form a new BsonCovarianceAndVarianceAggState that has the combined * sum and count. */ Datum bson_covariance_pop_samp_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytea *combinedStateBytes = AllocateBsonCovarianceOrVarianceAggState(); BsonCovarianceAndVarianceAggState *currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(combinedStateBytes); MemoryContextSwitchTo(oldContext); /* Handle either left or right being null. A new state needs to be allocated regardless */ currentState->sx.value_type = BSON_TYPE_DOUBLE; currentState->sx.value.v_double = 0.0; currentState->sy.value_type = BSON_TYPE_DOUBLE; currentState->sy.value.v_double = 0.0; currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = 0.0; currentState->count = 0; currentState->decimalCount = 0; /* handle left or right being null */ /* It's worth handling the special cases N1 = 0 and N2 = 0 separately */ /* since those cases are trivial, and we then don't need to worry about */ /* division-by-zero errors in the general case. */ if (PG_ARGISNULL(0)) { if (PG_ARGISNULL(1)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(1)), sizeof(BsonCovarianceAndVarianceAggState)); } else if (PG_ARGISNULL(1)) { if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(0)), sizeof(BsonCovarianceAndVarianceAggState)); } else { BsonCovarianceAndVarianceAggState *leftState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(PG_GETARG_BYTEA_P(0)); BsonCovarianceAndVarianceAggState *rightState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(PG_GETARG_BYTEA_P(1)); CalculateCombineFuncForCovarianceOrVarianceWithYCAlgr(leftState, rightState, currentState); } PG_RETURN_POINTER(combinedStateBytes); } /* * Applies the "inverse transition function" (MINVFUNC) for BSONCOVARIANCEPOP and BSONCOVARIANCESAMP. * takes one aggregate state structures (BsonCovarianceAndVarianceAggState) * and single data point. Remove the single data from BsonCovarianceAndVarianceAggState */ Datum bson_covariance_pop_samp_invtransition(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } bytea *bytes; BsonCovarianceAndVarianceAggState *currentState; if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(bytes); } pgbson *currentXValue = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *currentYValue = PG_GETARG_MAYBE_NULL_PGBSON(2); if (currentXValue == NULL || IsPgbsonEmptyDocument(currentXValue) || currentYValue == NULL || IsPgbsonEmptyDocument(currentYValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentXValueElement; PgbsonToSinglePgbsonElement(currentXValue, ¤tXValueElement); pgbsonelement currentYValueElement; PgbsonToSinglePgbsonElement(currentYValue, ¤tYValueElement); if (!BsonTypeIsNumber(currentXValueElement.bsonValue.value_type) || !BsonTypeIsNumber(currentYValueElement.bsonValue.value_type)) { PG_RETURN_POINTER(bytes); } /* restart aggregate if NaN or Infinity in current state or current values */ /* or count is 0 */ if (IsBsonValueNaN(¤tState->sxy) || IsBsonValueInfinity(¤tState->sxy) || IsBsonValueNaN(¤tXValueElement.bsonValue) || IsBsonValueInfinity(¤tXValueElement.bsonValue) || IsBsonValueNaN(¤tYValueElement.bsonValue) || IsBsonValueInfinity(¤tYValueElement.bsonValue) || currentState->count == 0) { PG_RETURN_NULL(); } CalculateInvFuncForCovarianceOrVarianceWithYCAlgr(¤tXValueElement.bsonValue, ¤tYValueElement.bsonValue, currentState); PG_RETURN_POINTER(bytes); } /* * Applies the "final calculation" (FINALFUNC) for BSONCOVARIANCEPOP. * This takes the final value created and outputs a bson covariance pop * with the appropriate type. */ Datum bson_covariance_pop_final(PG_FUNCTION_ARGS) { bytea *covarianceIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (covarianceIntermediateState != NULL) { bson_value_t bsonResult = { 0 }; BsonCovarianceAndVarianceAggState *covarianceState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY( covarianceIntermediateState); if (IsBsonValueNaN(&covarianceState->sxy) || IsBsonValueInfinity(&covarianceState->sxy) != 0) { bsonResult = covarianceState->sxy; } else if (covarianceState->count == 0) { /* Returns null for empty sets or wrong input field count */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else if (covarianceState->count == 1) { /* Returns 0 for single numeric value */ /* Return double even if the value is decimal128 */ finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = 0; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bsonResult = covarianceState->sxy; /* bsonCount = covarianceState->count */ bson_value_t bsonCount = { .value_type = BSON_TYPE_INT64, .value.v_int64 = covarianceState->count }; ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonResult, &bsonCount, OperationSource_CovariancePopFinal); } finalValue.bsonValue = bsonResult; /* if there is at least one decimal value in current window, we should return decimal128; otherwise, return double */ if (covarianceState->decimalCount > 0) { finalValue.bsonValue.value_type = BSON_TYPE_DECIMAL128; finalValue.bsonValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &bsonResult); } else { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = BsonValueAsDouble(&bsonResult); } } else { /* Returns null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for BSONCOVARIANCESAMP. * This takes the final value created and outputs a bson covariance samp * with the appropriate type. */ Datum bson_covariance_samp_final(PG_FUNCTION_ARGS) { bytea *covarianceIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (covarianceIntermediateState != NULL) { bson_value_t bsonResult = { 0 }; BsonCovarianceAndVarianceAggState *covarianceState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY( covarianceIntermediateState); if (IsBsonValueNaN(&covarianceState->sxy) || IsBsonValueInfinity(&covarianceState->sxy)) { bsonResult = covarianceState->sxy; } else if (covarianceState->count == 0 || covarianceState->count == 1) { /* Returns null for empty sets, single numeric value or wrong input field count */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bson_value_t countMinus1 = { .value_type = BSON_TYPE_INT64, .value.v_int64 = covarianceState->count - 1 }; bsonResult = covarianceState->sxy; ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonResult, &countMinus1, OperationSource_CovarianceSampFinal); } /* if there is at least one decimal value in current window, we should return decimal128; otherwise, return double */ finalValue.bsonValue = bsonResult; /* if there is at least one decimal value in current window, we should return decimal128; otherwise, return double */ if (covarianceState->decimalCount > 0) { finalValue.bsonValue.value_type = BSON_TYPE_DECIMAL128; finalValue.bsonValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &bsonResult); } else { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = BsonValueAsDouble(&bsonResult); } } else { /* Returns null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Transition function for the BSON_STD_DEV_POP and BSON_STD_DEV_SAMP aggregate. * Implementation refer to https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/float.c#L2950 */ Datum bson_std_dev_pop_samp_transition(PG_FUNCTION_ARGS) { bytea *bytes; BsonCovarianceAndVarianceAggState *currentState; /* If the intermediate state has never been initialized, create it */ if (PG_ARGISNULL(0)) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "aggregate function std dev pop sample transition called in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytes = AllocateBsonCovarianceOrVarianceAggState(); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA(bytes); currentState->sx.value_type = BSON_TYPE_DOUBLE; currentState->sx.value.v_double = 0.0; currentState->sy.value_type = BSON_TYPE_DOUBLE; currentState->sy.value.v_double = 0.0; currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = 0.0; currentState->count = 0; currentState->decimalCount = 0; MemoryContextSwitchTo(oldContext); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue == NULL || IsPgbsonEmptyDocument(currentValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); /* Skip non-numeric values */ if (BsonValueIsNumber(¤tValueElement.bsonValue)) { CalculateSFuncForCovarianceOrVarianceWithYCAlgr(¤tValueElement.bsonValue, ¤tValueElement.bsonValue, currentState); } PG_RETURN_POINTER(bytes); } /* * Applies the "combine function" (COMBINEFUNC) for std_dev_pop and std_dev_samp. * takes two of the aggregate state structures (bson_std_dev_agg_state) * and combines them to form a new bson_std_dev_agg_state that has the combined * sum and count. */ Datum bson_std_dev_pop_samp_combine(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (!AggCheckCallContext(fcinfo, &aggregateContext)) { ereport(ERROR, errmsg( "Aggregate function invoked in non-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytea *combinedStateBytes = AllocateBsonCovarianceOrVarianceAggState(); BsonCovarianceAndVarianceAggState *currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(combinedStateBytes); MemoryContextSwitchTo(oldContext); /* Handle either left or right being null. A new state needs to be allocated regardless */ currentState->sx.value_type = BSON_TYPE_DOUBLE; currentState->sx.value.v_double = 0.0; currentState->sy.value_type = BSON_TYPE_DOUBLE; currentState->sy.value.v_double = 0.0; currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = 0.0; currentState->count = 0; currentState->decimalCount = 0; /*-------------------- * The transition values combine using a generalization of the * Youngs-Cramer algorithm as follows: * * N = N1 + N2 * Sx = Sx1 + Sx2 * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N; * * It's worth handling the special cases N1 = 0 and N2 = 0 separately * since those cases are trivial, and we then don't need to worry about * division-by-zero errors in the general case. *-------------------- */ if (PG_ARGISNULL(0)) { if (PG_ARGISNULL(1)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(1)), sizeof(BsonCovarianceAndVarianceAggState)); } else if (PG_ARGISNULL(1)) { if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); } memcpy(VARDATA(combinedStateBytes), VARDATA_ANY(PG_GETARG_BYTEA_P(0)), sizeof(BsonCovarianceAndVarianceAggState)); } else { BsonCovarianceAndVarianceAggState *leftState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY( PG_GETARG_BYTEA_P(0)); BsonCovarianceAndVarianceAggState *rightState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY( PG_GETARG_BYTEA_P(1)); CalculateCombineFuncForCovarianceOrVarianceWithYCAlgr(leftState, rightState, currentState); } PG_RETURN_POINTER(combinedStateBytes); } /* * Applies the "final calculation" (FINALFUNC) for std_dev_pop. * This takes the final value created and outputs a bson "std_dev_pop" * with the appropriate type. */ Datum bson_std_dev_pop_final(PG_FUNCTION_ARGS) { bytea *stdDevIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (stdDevIntermediateState != NULL) { BsonCovarianceAndVarianceAggState *stdDevState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(stdDevIntermediateState); if (IsBsonValueNaN(&stdDevState->sxy) || IsBsonValueInfinity(&stdDevState->sxy)) { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = NAN; } else if (stdDevState->count == 0) { /* Returns $null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } else if (stdDevState->count == 1) { /* Returns 0 for single numeric value */ finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = 0.0; } else { bson_value_t result = stdDevState->sxy; bson_value_t bsonCount = { .value_type = BSON_TYPE_INT64, .value.v_int64 = stdDevState->count }; ArithmeticOperationFunc(ArithmeticOperation_Divide, &result, &bsonCount, OperationSource_StdDevPopFinal); /* The value type of finalValue.bsonValue is set to BSON_TYPE_DOUBLE inside the function*/ CalculateSqrtForStdDev(&result, &finalValue.bsonValue); } } else { /* Returns $null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for std_dev_samp. * This takes the final value created and outputs a bson "std_dev_samp" * with the appropriate type. */ Datum bson_std_dev_samp_final(PG_FUNCTION_ARGS) { bytea *stdDevIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (stdDevIntermediateState != NULL) { BsonCovarianceAndVarianceAggState *stdDevState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(stdDevIntermediateState); if (stdDevState->count == 0 || stdDevState->count == 1) { /* Returns $null for empty sets or single numeric value */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } else if (IsBsonValueInfinity(&stdDevState->sxy)) { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = NAN; } else { bson_value_t countMinus1 = { .value_type = BSON_TYPE_INT64, .value.v_int64 = stdDevState->count - 1 }; bson_value_t result = stdDevState->sxy; ArithmeticOperationFunc(ArithmeticOperation_Divide, &result, &countMinus1, OperationSource_StdDevSampFinal); /* The value type of finalValue.bsonValue is set to BSON_TYPE_DOUBLE inside the function*/ CalculateSqrtForStdDev(&result, &finalValue.bsonValue); } } else { /* Returns $null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Function that calculate expMovingAvg value one by one. */ Datum bson_exp_moving_avg(PG_FUNCTION_ARGS) { WindowObject winobj = PG_WINDOW_OBJECT(); BsonExpMovingAvg *stateData; stateData = (BsonExpMovingAvg *) WinGetPartitionLocalMemory(winobj, sizeof(BsonExpMovingAvg)); bool isnull = false; pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isnull)); pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); bson_value_t bsonCurrentValue = currentValueElement.bsonValue; pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; /* if currentValue is not a numeric type, return null. */ if (BsonValueIsNumber(&bsonCurrentValue)) { /* first call, init stateData. */ if (!stateData->init) { /* get weight value, if isAlpha == true, the weightValue is Alpha, if isAlpha == false, the weightValue is N. */ pgbson *weightValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 1, &isnull)); bool isAlpha = DatumGetBool(WinGetFuncArgCurrent(winobj, 2, &isnull)); pgbsonelement weightValueElement; PgbsonToSinglePgbsonElement(weightValue, &weightValueElement); bson_value_t bsonWeightValue = weightValueElement.bsonValue; stateData->init = true; stateData->isAlpha = isAlpha; stateData->preValue = bsonCurrentValue; stateData->weight = bsonWeightValue; finalValue.bsonValue = bsonCurrentValue; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bson_value_t bsonPerValue = stateData->preValue; bson_value_t bsonResultValue; /* * CalculateExpMovingAvg will compute the result of expMovingAvg. * * If the parameter is N, * the calculation is: current result = current value * ( 2 / ( N + 1 ) ) + previous result * ( 1 - ( 2 / ( N + 1 ) ) ) * To improve calculation accuracy, we need to convert the calculation to: (currentValue * 2 + preValue * ( N - 1 ) ) / ( N + 1 ) * * If the parameter is alpha, * the calculation is: current result = current value * alpha + previous result * ( 1 - alpha ) */ CalculateExpMovingAvg(&bsonCurrentValue, &bsonPerValue, &stateData->weight, stateData->isAlpha, &bsonResultValue); /* If currentValue is of type decimal128, then expMovingResult will also be of type decimal128, */ /* and all subsequent expMoving results will also be of type decimal128. */ if (bsonCurrentValue.value_type == BSON_TYPE_DECIMAL128 || stateData->preValue.value_type == BSON_TYPE_DECIMAL128) { stateData->preValue = bsonResultValue; } else { /* If result can be represented as an integer, we need to keep only the integer part. : 5.0 -> 5 */ /* If result overflows int32, IsBsonValue32BitInteger will return false. */ bool checkFixedInteger = true; if (IsBsonValue32BitInteger(&bsonResultValue, checkFixedInteger)) { stateData->preValue.value_type = BSON_TYPE_INT32; stateData->preValue.value.v_int32 = BsonValueAsInt32( &bsonResultValue); } else { /* If result can be represented as an integer, we need to keep only the integer part. : 5.0 -> 5 */ if (IsBsonValue64BitInteger(&bsonResultValue, checkFixedInteger)) { stateData->preValue.value_type = BSON_TYPE_INT64; stateData->preValue.value.v_int64 = BsonValueAsInt64( &bsonResultValue); } else { stateData->preValue.value_type = BSON_TYPE_DOUBLE; stateData->preValue.value.v_double = BsonValueAsDouble( &bsonResultValue); } } } finalValue.bsonValue = stateData->preValue; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } } else { finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } } /* transition function for the BSON_INTEGRAL aggregate * use the trapzoidal rule to calculate the integral */ Datum bson_integral_transition(PG_FUNCTION_ARGS) { bytea *bytes; bool isIntegral = true; BsonIntegralAndDerivativeAggState *currentState; pgbson *xValue = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *yValue = PG_GETARG_MAYBE_NULL_PGBSON(2); long timeUnitInt64 = PG_GETARG_INT64(3); pgbsonelement xValueElement, yValueElement; PgbsonToSinglePgbsonElement(xValue, &xValueElement); PgbsonToSinglePgbsonElement(yValue, &yValueElement); if (IsPgbsonEmptyDocument(xValue) || IsPgbsonEmptyDocument(yValue)) { PG_RETURN_NULL(); } RunTimeCheckForIntegralAndDerivative(&xValueElement.bsonValue, &yValueElement.bsonValue, timeUnitInt64, isIntegral); if (PG_ARGISNULL(0)) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytes = AllocateBsonIntegralAndDerivativeAggState(); currentState = (BsonIntegralAndDerivativeAggState *) VARDATA(bytes); currentState->result.value_type = BSON_TYPE_DOUBLE; /* update the anchor point with current document in window */ currentState->anchorX = xValueElement.bsonValue; currentState->anchorY = yValueElement.bsonValue; /* if xValue is a date, convert it to double */ if (xValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) { currentState->anchorX.value_type = BSON_TYPE_DOUBLE; currentState->anchorX.value.v_double = BsonValueAsDouble( &xValueElement.bsonValue); } MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonIntegralAndDerivativeAggState *) VARDATA_ANY(bytes); } HandleIntegralDerivative(&xValueElement.bsonValue, &yValueElement.bsonValue, timeUnitInt64, currentState, isIntegral); /* update the anchor point with current document in window */ currentState->anchorX = xValueElement.bsonValue; currentState->anchorY = yValueElement.bsonValue; /* if xValue is a date, convert it to double */ if (xValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) { currentState->anchorX.value_type = BSON_TYPE_DOUBLE; currentState->anchorX.value.v_double = BsonValueAsDouble( &xValueElement.bsonValue); } PG_RETURN_POINTER(bytes); } /* transition function for the BSON_DERIVATIVE aggregate * use dy/dx to calculate the derivative */ Datum bson_derivative_transition(PG_FUNCTION_ARGS) { pgbson *xValue = PG_GETARG_MAYBE_NULL_PGBSON(1); pgbson *yValue = PG_GETARG_MAYBE_NULL_PGBSON(2); long timeUnitInt64 = PG_GETARG_INT64(3); pgbsonelement xValueElement, yValueElement; PgbsonToSinglePgbsonElement(xValue, &xValueElement); PgbsonToSinglePgbsonElement(yValue, &yValueElement); bytea *bytes; bool isIntegral = false; BsonIntegralAndDerivativeAggState *currentState; if (IsPgbsonEmptyDocument(xValue) || IsPgbsonEmptyDocument(yValue)) { PG_RETURN_NULL(); } RunTimeCheckForIntegralAndDerivative(&xValueElement.bsonValue, &yValueElement.bsonValue, timeUnitInt64, isIntegral); if (PG_ARGISNULL(0)) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } /* Create the aggregate state in the aggregate context. */ MemoryContext oldContext = MemoryContextSwitchTo(aggregateContext); bytes = AllocateBsonIntegralAndDerivativeAggState(); currentState = (BsonIntegralAndDerivativeAggState *) VARDATA(bytes); currentState->result.value_type = BSON_TYPE_NULL; /* anchor points are always the first document in the window for $derivative*/ /* if xValue is a date, convert it to double */ if (xValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) { currentState->anchorX.value_type = BSON_TYPE_DOUBLE; currentState->anchorX.value.v_double = BsonValueAsDouble( &xValueElement.bsonValue); } else { currentState->anchorX = xValueElement.bsonValue; } if (yValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) { currentState->anchorY.value_type = BSON_TYPE_DOUBLE; currentState->anchorY.value.v_double = BsonValueAsDouble( &yValueElement.bsonValue); } else { currentState->anchorY = yValueElement.bsonValue; } /* We have the first document in state and the second incoming document * it's ready to calculate the derivative */ MemoryContextSwitchTo(oldContext); PG_RETURN_POINTER(bytes); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonIntegralAndDerivativeAggState *) VARDATA_ANY(bytes); } if (IsPgbsonEmptyDocument(xValue) || IsPgbsonEmptyDocument(yValue)) { PG_RETURN_POINTER(bytes); } HandleIntegralDerivative(&xValueElement.bsonValue, &yValueElement.bsonValue, timeUnitInt64, currentState, isIntegral); PG_RETURN_POINTER(bytes); } /* final function for the BSON_INTEGRAL and BSON_DERIVATIVE aggregate * This takes the final value created and outputs a bson "integral" or "derivative" * with the appropriate type. */ Datum bson_integral_derivative_final(PG_FUNCTION_ARGS) { bytea *currentState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (currentState != NULL) { BsonIntegralAndDerivativeAggState *state = (BsonIntegralAndDerivativeAggState *) VARDATA_ANY( currentState); if (state->result.value_type != BSON_TYPE_NULL) { finalValue.bsonValue = state->result; } else if (state->result.value_type == BSON_TYPE_NULL) { finalValue.bsonValue.value_type = BSON_TYPE_NULL; } } else { finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for BSONSTDDEVPOP window aggregate operator. * This takes the final value created and outputs a bson stddev pop * with the appropriate type. */ Datum bson_std_dev_pop_winfunc_final(PG_FUNCTION_ARGS) { bytea *stdDevIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (stdDevIntermediateState != NULL) { BsonCovarianceAndVarianceAggState *stdDevState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(stdDevIntermediateState); if (IsBsonValueNaN(&stdDevState->sxy) || IsBsonValueInfinity(&stdDevState->sxy) != 0) { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = NAN; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else if (stdDevState->count == 0) { /* we return null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else if (stdDevState->count == 1) { /* we returns 0 for single numeric value */ /* return double even if the value is decimal128 */ finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = 0.0; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bson_value_t result = stdDevState->sxy; bson_value_t bsonCount = { .value_type = BSON_TYPE_INT64, .value.v_int64 = stdDevState->count }; ArithmeticOperationFunc(ArithmeticOperation_Divide, &result, &bsonCount, OperationSource_StdDevPopWinfuncFinal); /* The value type of finalValue.bsonValue is set to BSON_TYPE_DOUBLE inside the function*/ CalculateSqrtForStdDev(&result, &finalValue.bsonValue); } } else { /* we return null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "final calculation" (FINALFUNC) for BSONSTDDEVSAMP window function. * This takes the final value created and outputs a bson stddev samp * with the appropriate type. */ Datum bson_std_dev_samp_winfunc_final(PG_FUNCTION_ARGS) { bytea *stdDevIntermediateState = PG_ARGISNULL(0) ? NULL : PG_GETARG_BYTEA_P(0); pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; if (stdDevIntermediateState != NULL) { BsonCovarianceAndVarianceAggState *stdDevState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(stdDevIntermediateState); if (IsBsonValueNaN(&stdDevState->sxy) || IsBsonValueInfinity(&stdDevState->sxy)) { finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = NAN; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else if (stdDevState->count == 0 || stdDevState->count == 1) { /* we returns null for empty sets or single numeric value */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bson_value_t countMinus1 = { .value_type = BSON_TYPE_INT64, .value.v_int64 = stdDevState->count - 1 }; bson_value_t result = stdDevState->sxy; ArithmeticOperationFunc(ArithmeticOperation_Divide, &result, &countMinus1, OperationSource_StdDevSampWinfuncFinal); /* The value type of finalValue.bsonValue is set to BSON_TYPE_DOUBLE inside the function*/ CalculateSqrtForStdDev(&result, &finalValue.bsonValue); } } else { /* we return null for empty sets */ finalValue.bsonValue.value_type = BSON_TYPE_NULL; } PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* * Applies the "inverse transition function" (MINVFUNC) for BSONSTDDEVPOP and BSONSTDDEVSAMP. * takes one aggregate state structures (BsonCovarianceAndVarianceAggState) * and single data point. Remove the single data from BsonCovarianceAndVarianceAggState */ Datum bson_std_dev_pop_samp_winfunc_invtransition(PG_FUNCTION_ARGS) { MemoryContext aggregateContext; if (AggCheckCallContext(fcinfo, &aggregateContext) != AGG_CONTEXT_WINDOW) { ereport(ERROR, errmsg( "window aggregate function called in non-window-aggregate context")); } bytea *bytes; BsonCovarianceAndVarianceAggState *currentState; if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); } else { bytes = PG_GETARG_BYTEA_P(0); currentState = (BsonCovarianceAndVarianceAggState *) VARDATA_ANY(bytes); } pgbson *currentValue = PG_GETARG_MAYBE_NULL_PGBSON(1); if (currentValue == NULL || IsPgbsonEmptyDocument(currentValue)) { PG_RETURN_POINTER(bytes); } pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); if (!BsonTypeIsNumber(currentValueElement.bsonValue.value_type)) { PG_RETURN_POINTER(bytes); } /* restart aggregate if NaN or Infinity in current state or current values */ /* or count is 0 */ if (IsBsonValueNaN(¤tState->sxy) || IsBsonValueInfinity(¤tState->sxy) || IsBsonValueNaN(¤tValueElement.bsonValue) || IsBsonValueInfinity(¤tValueElement.bsonValue) || currentState->count == 0) { PG_RETURN_NULL(); } CalculateInvFuncForCovarianceOrVarianceWithYCAlgr(¤tValueElement.bsonValue, ¤tValueElement.bsonValue, currentState); PG_RETURN_POINTER(bytes); } /* --------------------------------------------------------- */ /* Private helper methods */ /* --------------------------------------------------------- */ static bytea * AllocateBsonCovarianceOrVarianceAggState() { int bson_size = sizeof(BsonCovarianceAndVarianceAggState) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); return combinedStateBytes; } static bytea * AllocateBsonIntegralAndDerivativeAggState() { int bson_size = sizeof(BsonIntegralAndDerivativeAggState) + VARHDRSZ; bytea *combinedStateBytes = (bytea *) palloc0(bson_size); SET_VARSIZE(combinedStateBytes, bson_size); return combinedStateBytes; } /* * Function to calculate variance/covariance state for inverse function. * If calculating variance, we use X and Y as the same value. * * According to a generalization of the * Youngs-Cramer algorithm formular, we update the state data like this * ``` * N^ = N - 1 * Sx^ = Sx - X * Sy^ = Sy - Y * Sxy^ = Sxy - N^/N * (Sx^/N^ - X) * (Sy^/N^ - Y) * ``` */ static void CalculateInvFuncForCovarianceOrVarianceWithYCAlgr(const bson_value_t *newXValue, const bson_value_t *newYValue, BsonCovarianceAndVarianceAggState * currentState) { /* update the count of decimal values accordingly */ if (newXValue->value_type == BSON_TYPE_DECIMAL128 || newYValue->value_type == BSON_TYPE_DECIMAL128) { currentState->decimalCount--; } bson_value_t bsonCurrentXValue = *newXValue; bson_value_t bsonCurrentYValue = *newYValue; /* bsonN = currentState->count */ bson_value_t bsonN = { .value_type = BSON_TYPE_INT64, .value.v_int64 = currentState->count }; /* currentState->count -= 1.0 */ currentState->count--; bson_value_t bsonNMinusOne = { .value_type = BSON_TYPE_INT64, .value.v_int64 = currentState->count }; /* currentState->sx -= bsonCurrentXValue */ ArithmeticOperationFunc(ArithmeticOperation_Subtract, ¤tState->sx, &bsonCurrentXValue, OperationSource_InvYCAlgr); /* currentState->sy -= bsonCurrentYValue */ ArithmeticOperationFunc(ArithmeticOperation_Subtract, ¤tState->sy, &bsonCurrentYValue, OperationSource_InvYCAlgr); bson_value_t bsonXTmp = bsonCurrentXValue; bson_value_t bsonYTmp = bsonCurrentYValue; /* bsonXTmp = currentState->sx - bsonCurrentXValue * currentState->count */ /* X * N^ */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonXTmp, &bsonNMinusOne, OperationSource_InvYCAlgr); /* Sx^ - X * N^ */ bson_value_t bsonTmp = currentState->sx; ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonTmp, &bsonXTmp, OperationSource_InvYCAlgr); bsonXTmp = bsonTmp; /* bsonYTmp = currentState->sy - bsonCurrentYValue * bsonNMinusOne(currentState->count) */ /* Y * N^ */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonYTmp, &bsonNMinusOne, OperationSource_InvYCAlgr); /* Sy^ - Y * N^ */ bsonTmp = currentState->sy; ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonTmp, &bsonYTmp, OperationSource_InvYCAlgr); bsonYTmp = bsonTmp; bson_value_t bsonXYTmp; /* bsonXYTmp = bsonXTmp * bsonYTmp */ /* (Sx^ - X * N^) * (Sy^ - Y * N^) */ bsonXYTmp = bsonXTmp; ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonXYTmp, &bsonYTmp, OperationSource_InvYCAlgr); bson_value_t bsonTmpNxx = bsonN; /* bsonTmpNxx = bsonN * bsonNMinusOne(currentState->count) */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonTmpNxx, &bsonNMinusOne, OperationSource_InvYCAlgr); bsonTmp = bsonXYTmp; /* bsonTmp = bsonXYTmp / bsonTmpNxx */ /* (Sx^ - X * N^) * (Sy^ - Y * N^) / (N * N^) = N^/N * (Sx^/N^ - X) * (Sy^/N^ - Y) */ ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonTmp, &bsonTmpNxx, OperationSource_InvYCAlgr); /* currentState->sxy -= bsonTmp */ ArithmeticOperationFunc(ArithmeticOperation_Subtract, ¤tState->sxy, &bsonTmp, OperationSource_InvYCAlgr); } /* * Function to calculate variance/covariance state for combine function. * If calculating variance, we use X and Y as the same value. * * The transition values combine using a generalization of the * Youngs-Cramer algorithm as follows: * * N = N1 + N2 * Sx = Sx1 + Sx2 * Sy = Sy1 + Sy2 * Sxy = Sxy1 + Sxy2 + N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N; */ static void CalculateCombineFuncForCovarianceOrVarianceWithYCAlgr(const BsonCovarianceAndVarianceAggState * leftState, const BsonCovarianceAndVarianceAggState * rightState, BsonCovarianceAndVarianceAggState * currentState) { /* If either of left or right node's count is 0, we can just copy the other node's state and return */ if (leftState->count == 0) { memcpy(currentState, rightState, sizeof(BsonCovarianceAndVarianceAggState)); return; } else if (rightState->count == 0) { memcpy(currentState, leftState, sizeof(BsonCovarianceAndVarianceAggState)); return; } /* update the count of decimal values */ currentState->decimalCount = leftState->decimalCount + rightState->decimalCount; /* currentState->count = leftState->count + rightState->count */ currentState->count = leftState->count + rightState->count; /* handle infinities first */ /* if infinity values from left and right node with different signs, return NaN */ /* if with the same sign, return the infinity value */ /* if no infinity values, continue to calculate the covariance/variance */ int isInfinityLeft = IsBsonValueInfinity(&leftState->sxy); int isInfinityRight = IsBsonValueInfinity(&rightState->sxy); if (isInfinityLeft * isInfinityRight == -1) { if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { SetDecimal128NaN(¤tState->sxy); } else { currentState->sxy.value.v_double = NAN; } return; } else if (isInfinityLeft + isInfinityRight != 0) { if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { if (isInfinityLeft + isInfinityRight > 0) { SetDecimal128PositiveInfinity(¤tState->sxy); } else { SetDecimal128NegativeInfinity(¤tState->sxy); } } else { currentState->sxy.value_type = BSON_TYPE_DOUBLE; if (isInfinityLeft + isInfinityRight > 0) { currentState->sxy.value.v_double = (double) INFINITY; } else { currentState->sxy.value.v_double = (double) -INFINITY; } } return; } /* currentState->sx = leftState->sx + rightState->sx */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sx, &leftState->sx, OperationSource_CombineYCAlgr); ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sx, &rightState->sx, OperationSource_CombineYCAlgr); /* currentState->sy = leftState->sy + rightState->sy */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sy, &leftState->sy, OperationSource_CombineYCAlgr); ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sy, &rightState->sy, OperationSource_CombineYCAlgr); bson_value_t bsonTmpLeft = leftState->sx; bson_value_t bsonTmpRight = rightState->sx; bson_value_t bsonXTmp; /* bsonXTmp = leftState->sx / leftState->count - rightState->sx / rightState->count; */ /* leftState->count and rightState->count won't be 0 as we have checked outside */ bson_value_t leftN = { .value_type = BSON_TYPE_INT64, .value.v_int64 = leftState->count }; bson_value_t rightN = { .value_type = BSON_TYPE_INT64, .value.v_int64 = rightState->count }; /* Sx1/N1 */ ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonTmpLeft, &leftN, OperationSource_CombineYCAlgr); /* Sx2/N2 */ ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonTmpRight, &rightN, OperationSource_CombineYCAlgr); /* Sx1/N1 - Sx2/N2 */ bsonXTmp = bsonTmpLeft; ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonXTmp, &bsonTmpRight, OperationSource_CombineYCAlgr); bsonTmpLeft = leftState->sy; bsonTmpRight = rightState->sy; bson_value_t bsonYTmp; /* bsonYTmp = leftState->sy / leftState->count - rightState->sy / rightState->count; */ /* Sy1/N1 */ ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonTmpLeft, &leftN, OperationSource_CombineYCAlgr); /* Sy2/N2 */ ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonTmpRight, &rightN, OperationSource_CombineYCAlgr); /* Sy1/N1 - Sy2/N2 */ bsonYTmp = bsonTmpLeft; ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonYTmp, &bsonTmpRight, OperationSource_CombineYCAlgr); bson_value_t bsonNxx = leftN; /* bsonNxx = leftState->count * rightState->count; */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonNxx, &rightN, OperationSource_CombineYCAlgr); bson_value_t bsonXYTmp = bsonXTmp; /* bsonXYTmp = bsonXTmp * bsonYTmp; */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonXYTmp, &bsonYTmp, OperationSource_CombineYCAlgr); bson_value_t bsonTmp = bsonNxx; /* bsonTmp = bsonNxx * bsonXYTmp; */ /* N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonTmp, &bsonXYTmp, OperationSource_CombineYCAlgr); bson_value_t bsonD = bsonTmp; /* bsonD = bsonTmp / N; */ /* N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N; */ /* didn't check if N is 0, as we should not meet that case */ bson_value_t currentN = { .value_type = BSON_TYPE_INT64, .value.v_int64 = currentState->count }; ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonD, ¤tN, OperationSource_CombineYCAlgr); /* Sxy1 + Sxy2 */ currentState->sxy = leftState->sxy; ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sxy, &rightState->sxy, OperationSource_CombineYCAlgr); /* Sxy1 + Sxy2 + N1 * N2 * (Sx1/N1 - Sx2/N2) * (Sy1/N1 - Sy2/N2) / N */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sxy, &bsonD, OperationSource_CombineYCAlgr); } /* * Function to calculate variance/covariance state for transition function. * Use the Youngs-Cramer algorithm to incorporate the new value into the * transition values. * If calculating variance, we use X and Y as the same value. * * N = N + 1 * Sx = Sx + X * Sy = Sy + Y * Sxy = Sxy + (N - 1) / N * (X - Sx / N) * (Y - Sy / N) * */ static void CalculateSFuncForCovarianceOrVarianceWithYCAlgr(const bson_value_t *newXValue, const bson_value_t *newYValue, BsonCovarianceAndVarianceAggState * currentState) { bson_value_t intOne; intOne.value_type = BSON_TYPE_INT32; intOne.value.v_int32 = (int32_t) 1; bson_value_t bsonXTmp; bson_value_t bsonYTmp; bson_value_t bsonXYTmp; bson_value_t bsonNxx; bson_value_t bsonCurrentXValue = *newXValue; bson_value_t bsonCurrentYValue = *newYValue; /* bsonN = currentState->count */ bson_value_t bsonN, bsonNTmp; bsonN.value_type = BSON_TYPE_INT64; bsonN.value.v_int64 = currentState->count; bsonNTmp.value_type = BSON_TYPE_INT64; bsonNTmp.value.v_int64 = currentState->count; /* update the count of decimal values accordingly */ if (newXValue->value_type == BSON_TYPE_DECIMAL128 || newYValue->value_type == BSON_TYPE_DECIMAL128) { currentState->decimalCount++; } ArithmeticOperationFunc(ArithmeticOperation_Add, &bsonN, &intOne, OperationSource_SFuncYCAlgr); /* NAN will be addressed in subsequent sections */ /* focus on infinities first */ /* We will check all the infinity values (if any) from Sxy(didn't update yet), X, Y */ /* If all the infinity values have the same sign, we will return the infinity value */ /* If any of the infinity values have different signs, we will return the NaN value */ /* If no infinity values, we will continue the calculation */ /* The return value of IsBsonValueInfinity */ /* 0: finite number, 1: positive infinity, -1: negative infinity */ int isInfinityX = IsBsonValueInfinity(newXValue); int isInfinityY = IsBsonValueInfinity(newYValue); int isInfinitySxy = IsBsonValueInfinity(¤tState->sxy); /* the product of two values is -1 means they are infinity values with different signs */ if (isInfinityX * isInfinityY == -1 || isInfinityX * isInfinitySxy == -1 || isInfinityY * isInfinitySxy == -1) /* infinities with different signs, return nan */ { currentState->count++; if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { SetDecimal128NaN(¤tState->sxy); } else { currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = NAN; } return; } else if (isInfinityX || isInfinityY || isInfinitySxy) /* infinities with the same sign, return infinity */ { currentState->count++; if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { if ((isInfinityX > 0) || (isInfinityY > 0) || (isInfinitySxy > 0)) { SetDecimal128PositiveInfinity(¤tState->sxy); } else { SetDecimal128NegativeInfinity(¤tState->sxy); } } else { currentState->sxy.value_type = BSON_TYPE_DOUBLE; if ((isInfinityX > 0) || (isInfinityY > 0) || (isInfinitySxy > 0)) { currentState->sxy.value.v_double = (double) INFINITY; } else { currentState->sxy.value.v_double = (double) -INFINITY; } } return; } /* currentState->sx += bsonCurrentXValue */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sx, &bsonCurrentXValue, OperationSource_SFuncYCAlgr); /* currentState->sy += bsonCurrentYValue */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sy, &bsonCurrentYValue, OperationSource_SFuncYCAlgr); if (currentState->count > 0) { /* bsonXTmp = bsonCurrentXValue * bsonN - currentState->sx; */ bsonXTmp = bsonCurrentXValue; ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonXTmp, &bsonN, OperationSource_SFuncYCAlgr); ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonXTmp, ¤tState->sx, OperationSource_SFuncYCAlgr); /* bsonYTmp = bsonCurrentYValue * bsonN - currentState->sy; */ bsonYTmp = bsonCurrentYValue; ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonYTmp, &bsonN, OperationSource_SFuncYCAlgr); ArithmeticOperationFunc(ArithmeticOperation_Subtract, &bsonYTmp, ¤tState->sy, OperationSource_SFuncYCAlgr); /* currentState->sxy += bsonXTmp * bsonYTmp / (bsonN * currentState->count); */ bsonXYTmp = bsonXTmp; ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonXYTmp, &bsonYTmp, OperationSource_SFuncYCAlgr); bsonNxx = bsonN; ArithmeticOperationFunc(ArithmeticOperation_Multiply, &bsonNxx, &bsonNTmp, OperationSource_SFuncYCAlgr); ArithmeticOperationFunc(ArithmeticOperation_Divide, &bsonXYTmp, &bsonNxx, OperationSource_SFuncYCAlgr); /* currentState->sxy += bsonXYTmp */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tState->sxy, &bsonXYTmp, OperationSource_SFuncYCAlgr); } else { /* * At the first input, we normally can leave currentState->sxy as 0. * However, if the first input is Inf or NaN, we'd better force currentState->sxy * to Inf or NaN. */ if (IsBsonValueNaN(newXValue) || IsBsonValueNaN(newYValue) || isInfinityX * isInfinityY == -1) { if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { currentState->sxy.value_type = BSON_TYPE_DECIMAL128; SetDecimal128NaN(¤tState->sxy); } else { currentState->sxy.value_type = BSON_TYPE_DOUBLE; currentState->sxy.value.v_double = NAN; } } else if (isInfinityX + isInfinityY != 0) { if (currentState->sxy.value_type == BSON_TYPE_DECIMAL128) { currentState->sxy.value_type = BSON_TYPE_DECIMAL128; if (isInfinityX + isInfinityY > 0) { SetDecimal128PositiveInfinity(¤tState->sxy); } else { SetDecimal128NegativeInfinity(¤tState->sxy); } } else { currentState->sxy.value_type = BSON_TYPE_DOUBLE; if (isInfinityX + isInfinityY > 0) { currentState->sxy.value.v_double = (double) INFINITY; } else { currentState->sxy.value.v_double = (double) -INFINITY; } } } } currentState->count++; } bool ParseInputWeightForExpMovingAvg(const bson_value_t *opValue, bson_value_t *inputExpression, bson_value_t *weightExpression, bson_value_t *decimalWeightValue) { bson_iter_t docIter; BsonValueInitIterator(opValue, &docIter); /* * The $expMovingAvg accumulator expects a document in the form of * { "input": , "alpha": } or { "input": , "N": } * input is required parameter, both N and alpha are optional, but must specify either N or alpha, cannot specify both. * paramsValid is initially 0 and is used to check if params are valid: * if N is available, paramsValid |= 1; * if Alpha is available, paramsValid |= 2; * if input is available, paramsValid |= 4; * * So the opValue is only valid when paramsValid is equal to 5 (101) or 6(101). */ int32 paramsValid = InputValidFlags_Unknown; while (bson_iter_next(&docIter)) { const char *key = bson_iter_key(&docIter); if (strcmp(key, "input") == 0) { *inputExpression = *bson_iter_value(&docIter); paramsValid |= InputValidFlags_Input; } else if (strcmp(key, "alpha") == 0) { /* * Alpha is a float number, must be between 0 and 1 (exclusive). */ *weightExpression = *bson_iter_value(&docIter); if (BsonValueAsDouble(weightExpression) <= 0 || BsonValueAsDouble( weightExpression) >= 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The value of 'alpha' must lie strictly between 0 and 1 (not inclusive), but the provided alpha is: %lf", BsonValueAsDouble(weightExpression)))); } decimalWeightValue->value_type = BSON_TYPE_DECIMAL128; decimalWeightValue->value.v_decimal128 = GetBsonValueAsDecimal128Quantized( weightExpression); paramsValid |= InputValidFlags_Alpha; } else if (strcmp(key, "N") == 0) { /* * N must be an integer greater than one. */ *weightExpression = *bson_iter_value(&docIter); if (BsonTypeIsNumber(weightExpression->value_type)) { bool checkFixedInteger = true; if (!IsBsonValue64BitInteger(weightExpression, checkFixedInteger) && !IsBsonValueNegativeNumber(weightExpression)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The 'N' field is required to be an integer value, but instead a floating-point number was provided as N: %lf; to specify a non-integer, please use the 'alpha' argument.", BsonValueAsDouble(weightExpression)))); } else if (IsBsonValueNegativeNumber(weightExpression)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "'N' cannot be less than or equal to 0. Received %d", BsonValueAsInt32(weightExpression)))); } } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Expected 'integer' type for 'N' field but found '%s' type.", BsonTypeName(weightExpression->value_type)))); } decimalWeightValue->value_type = BSON_TYPE_DECIMAL128; decimalWeightValue->value.v_decimal128 = GetBsonValueAsDecimal128( weightExpression); paramsValid |= InputValidFlags_N; } else { /*incorrect parameter,like "alpah" */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Got unrecognized field in $expMovingAvg, The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'."))); } } if (paramsValid <= InputValidFlags_Input || paramsValid == (InputValidFlags_Input | InputValidFlags_N | InputValidFlags_Alpha)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The $expMovingAvg sub-object must contain exactly two specific fields: one labeled 'input', and the other either labeled 'N' or 'alpha'."))); } return (paramsValid & InputValidFlags_Alpha) ? true : false; } /* * Function to calculate expMovingAvg. * * If the parameter is N, * the calculation is: current result = current value * ( 2 / ( N + 1 ) ) + previous result * ( 1 - ( 2 / ( N + 1 ) ) ) * To improve calculation accuracy, we need to convert the calculation to: (currentValue * 2 + preValue * ( N - 1 ) ) / ( N + 1 ) * * If the parameter is alpha, * the calculation is: current result = current value * alpha + previous result * ( 1 - alpha ) */ static void CalculateExpMovingAvg(bson_value_t *bsonCurrentValue, bson_value_t *bsonPreValue, bson_value_t *bsonWeightValue, bool isAlpha, bson_value_t *bsonResultValue) { bson_value_t currentValue = *bsonCurrentValue; bson_value_t preValue = *bsonPreValue; bson_value_t weightValue = *bsonWeightValue; bson_value_t intOne = { .value_type = BSON_TYPE_INT32, .value.v_int32 = 1 }; if (isAlpha) { /* * current result = current value * alpha + previous result * ( 1 - alpha ) */ /* 1 - alpha */ ArithmeticOperationFunc(ArithmeticOperation_Subtract, &intOne, &weightValue, OperationSource_ExpMovingAvg); /* previous result * ( 1 - alpha ) */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &preValue, &intOne, OperationSource_ExpMovingAvg); /* current value * alpha */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, ¤tValue, &weightValue, OperationSource_ExpMovingAvg); /* preValue = previous result * ( 1 - alpha ) */ /* currentValue = current value * alpha */ /* currentValue = currentValue + preValue */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tValue, &preValue, OperationSource_ExpMovingAvg); } else { /* * current result = current value * ( 2 / ( N + 1 ) ) + previous result * ( 1 - ( 2 / ( N + 1 ) ) ) * To improve calculation accuracy, we need to convert the calculation: * (currentValue * 2 + preValue * ( N - 1 ) ) / ( N + 1 ) */ bson_value_t intTwo = { .value_type = BSON_TYPE_INT32, .value.v_int32 = 2 }; /* currentValue = currentValue * 2 */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, ¤tValue, &intTwo, OperationSource_ExpMovingAvg); /* weightValue = weightValue - 1 */ ArithmeticOperationFunc(ArithmeticOperation_Subtract, &weightValue, &intOne, OperationSource_ExpMovingAvg); /* preValue = preValue * weightValue */ /* wightValue was updated before (line: 2049) */ ArithmeticOperationFunc(ArithmeticOperation_Multiply, &preValue, &weightValue, OperationSource_ExpMovingAvg); /* currentValue = currentValue + preValue */ ArithmeticOperationFunc(ArithmeticOperation_Add, ¤tValue, &preValue, OperationSource_ExpMovingAvg); /*bsonWeightValue = N; */ /* N + 1 */ /* add 2 here due to weightValue substract 1 before (line: 2052) */ ArithmeticOperationFunc(ArithmeticOperation_Add, &weightValue, &intTwo, OperationSource_ExpMovingAvg); /* currentValue = currentValue / weightValue */ ArithmeticOperationFunc(ArithmeticOperation_Divide, ¤tValue, &weightValue, OperationSource_ExpMovingAvg); } *bsonResultValue = currentValue; } /* This function is used to handle the $integral and $derivative operators * 1. Calculate the integral or derivative value * 2. Update the result value in the currentState */ static void HandleIntegralDerivative(bson_value_t *xBsonValue, bson_value_t *yBsonValue, long timeUnitInt64, BsonIntegralAndDerivativeAggState *currentState, const bool isIntegralOperator) { /* Intermidiate variables for calculation */ bson_value_t timeUnitInMs, yValue, xValue; timeUnitInMs.value_type = BSON_TYPE_DOUBLE; timeUnitInMs.value.v_double = timeUnitInt64; yValue = *yBsonValue; xValue = *xBsonValue; /* Convert date time to double to avoid calucation error*/ if (xBsonValue->value_type == BSON_TYPE_DATE_TIME) { xValue.value_type = BSON_TYPE_DOUBLE; xValue.value.v_double = BsonValueAsDouble(xBsonValue); } if (yBsonValue->value_type == BSON_TYPE_DATE_TIME) { yValue.value_type = BSON_TYPE_DOUBLE; yValue.value.v_double = BsonValueAsDouble(yBsonValue); } /* Calculation status */ bool success = isIntegralOperator ? IntegralOfTwoPointsByTrapezoidalRule(&xValue, &yValue, currentState, &timeUnitInMs) : DerivativeOfTwoPoints(&xValue, &yValue, currentState, &timeUnitInMs); /* If calculation failed, throw an error */ if (!success) { char *opName = isIntegralOperator ? "$integral" : "$derivative"; ereport(ERROR, errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( "Handling %s: yValue = %f, xValue = %f, currentState->anchorX = %f, currentState->anchorY = %f, currentState->result = %f", opName, BsonValueAsDouble(&yValue), BsonValueAsDouble(&xValue), BsonValueAsDouble(¤tState->anchorX), BsonValueAsDouble( ¤tState->anchorY), BsonValueAsDouble( ¤tState->result)), errdetail_log( "Handling %s: yValue = %f, xValue = %f, currentState->anchorX = %f, currentState->anchorY = %f, currentState->result = %f", opName, BsonValueAsDouble(&yValue), BsonValueAsDouble(&xValue), BsonValueAsDouble(¤tState->anchorX), BsonValueAsDouble( ¤tState->anchorY), BsonValueAsDouble( ¤tState->result))); } } /* This function is used to check the runtime syntax, input, and unit for $integral and $derivative operators */ static void RunTimeCheckForIntegralAndDerivative(bson_value_t *xBsonValue, bson_value_t *yBsonValue, long timeUnitInt64, bool isIntegralOperator) { const char *opName = isIntegralOperator ? "$integral" : "$derivative"; /* if xBsonValue is not a date and unit is specified, throw an error */ if (IsBsonValueDateTimeFormat(xBsonValue->value_type) || xBsonValue->value_type == BSON_TYPE_NULL) { if (!timeUnitInt64) { int errorCode = isIntegralOperator ? ERRCODE_DOCUMENTDB_LOCATION5423902 : ERRCODE_DOCUMENTDB_LOCATION5624901; const char *errorMsg = isIntegralOperator ? "%s (with no 'unit') expects the sortBy field to be numeric" : "%s with sortBy set to Date needs a specified 'unit'"; ereport(ERROR, errcode(errorCode), errmsg(errorMsg, opName), errdetail_log(errorMsg, opName)); } } /* if xBsonValue is a number and unit is specified, throw an error */ else if (BsonTypeIsNumber(xBsonValue->value_type)) { if (timeUnitInt64) { int errorCode = isIntegralOperator ? ERRCODE_DOCUMENTDB_LOCATION5423901 : ERRCODE_DOCUMENTDB_LOCATION5624900; const char *errorMsg = "%s with 'unit' requires that the sortBy field needs to be a Date value"; ereport(ERROR, errcode(errorCode), errmsg(errorMsg, opName), errdetail_log(errorMsg, opName)); } } /* if unit is specifed but x is not a date, throw an error */ if (timeUnitInt64 && xBsonValue->value_type != BSON_TYPE_DATE_TIME) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5429513), errmsg( "Expected 'Date' type for 'sortBy' field but found '%s' type", BsonTypeName( xBsonValue->value_type)))); } /* if unit is not specified and x is a date, throw an error */ else if (!timeUnitInt64 && xBsonValue->value_type == BSON_TYPE_DATE_TIME) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5429413), errmsg( "When specifying windows that cover a range of dates or times, it is necessary to include a corresponding unit."))); } /* y must be a number or valid date time*/ if (!(BsonTypeIsNumber(yBsonValue->value_type) || yBsonValue->value_type == BSON_TYPE_DATE_TIME)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5423900), errmsg( "The input value of %s window function must be a vector" " of 2 value, the first value must be numeric or date type " "and the second must be numeric.", opName), errdetail_log("Input value is: %s", BsonTypeName(yBsonValue->value_type)))); } } /* This function is used to calculate the integral * of current state and current document in window by Trapezoidal Rule. * The result will be promoted to decimal if one of the input is decimal. */ bool IntegralOfTwoPointsByTrapezoidalRule(bson_value_t *xValue, bson_value_t *yValue, BsonIntegralAndDerivativeAggState *currentState, bson_value_t *timeUnitInMs) { bool success = true; bson_value_t stateXValue = currentState->anchorX; const bson_value_t stateYValue = currentState->anchorY; bool overflowedFromInt64, convertInt64OverflowToDouble = false; /* get time delta */ success &= SubtractNumberFromBsonValue(xValue, &stateXValue, &overflowedFromInt64); /* add anchorY axis */ success &= AddNumberToBsonValue(yValue, &stateYValue, &overflowedFromInt64); /* get area */ success &= MultiplyWithFactorAndUpdate(yValue, xValue, convertInt64OverflowToDouble); bson_value_t bsonValueTwo; bsonValueTwo.value_type = BSON_TYPE_DOUBLE; bsonValueTwo.value.v_double = 2.0; success &= DivideBsonValueNumbers(yValue, &bsonValueTwo); if (timeUnitInMs->value.v_double != 0.0) { success &= DivideBsonValueNumbers(yValue, timeUnitInMs); } success &= AddNumberToBsonValue(¤tState->result, yValue, &overflowedFromInt64); return success; } /* This function is used to calculate the derivative * of current state and current document in window by derivative rule. * The result will be promoted to decimal if one of the input is decimal. */ bool DerivativeOfTwoPoints(bson_value_t *xValue, bson_value_t *yValue, BsonIntegralAndDerivativeAggState *currentState, bson_value_t *timeUnitInMs) { bool success = true; bson_value_t stateXValue = currentState->anchorX; const bson_value_t stateYValue = currentState->anchorY; bool overflowedFromInt64 = false; /* get time delta */ success &= SubtractNumberFromBsonValue(xValue, &stateXValue, &overflowedFromInt64); if (timeUnitInMs->value.v_double != 0.0) { success &= DivideBsonValueNumbers(xValue, timeUnitInMs); } /* get value delta */ success &= SubtractNumberFromBsonValue(yValue, &stateYValue, &overflowedFromInt64); /* get derivative */ if ((xValue->value_type == BSON_TYPE_DOUBLE && xValue->value.v_double == 0.0) || (xValue->value_type == BSON_TYPE_DECIMAL128 && IsDecimal128Zero(xValue))) { currentState->result.value_type = BSON_TYPE_NULL; return success; } success &= DivideBsonValueNumbers(yValue, xValue); currentState->result = *yValue; return success; } /* This function is used to calculate the square root of input value. * The output result is double. */ static void CalculateSqrtForStdDev(const bson_value_t *inputValue, bson_value_t *outputResult) { outputResult->value_type = BSON_TYPE_DOUBLE; double resultForSqrt = 0; if (inputValue->value_type == BSON_TYPE_DECIMAL128) { if (IsDecimal128InDoubleRange(inputValue)) { resultForSqrt = BsonValueAsDouble(inputValue); if (resultForSqrt < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR)), errmsg("CalculateSqrtForStdDev: *inputValue = %f", BsonValueAsDouble(inputValue)), errdetail_log( "CalculateSqrtForStdDev: *inputResult = %f", BsonValueAsDouble(inputValue))); } else { outputResult->value.v_double = sqrt(resultForSqrt); } } else { outputResult->value.v_double = NAN; } } else { resultForSqrt = BsonValueAsDouble(inputValue); outputResult->value.v_double = sqrt(resultForSqrt); } } /* This function is to execute the arithmetic functions. * such as AddNumberToBsonValue, SubtractNumberFromBsonValue, MultiplyWithFactorAndUpdate, DivideBsonValueNumbers * return void as the individual operation return error directly if failed. */ static void ArithmeticOperationFunc(ArithmeticOperation op, bson_value_t *state, const bson_value_t *number, ArithmeticOperationErrorSource errSource) { bool opResult = false; bool overflowedFromInt64 = false; char *opName = "AddNumberToBsonValue"; switch (op) { case ArithmeticOperation_Add: { opResult = AddNumberToBsonValue(state, number, &overflowedFromInt64); break; } case ArithmeticOperation_Subtract: { opName = "SubtractNumberFromBsonValue"; opResult = SubtractNumberFromBsonValue(state, number, &overflowedFromInt64); break; } case ArithmeticOperation_Multiply: { opName = "MultiplyWithFactorAndUpdate"; bool convertInt64OverflowToDouble = false; opResult = MultiplyWithFactorAndUpdate(state, number, convertInt64OverflowToDouble); break; } case ArithmeticOperation_Divide: { opName = "DivideBsonValueNumbers"; opResult = DivideBsonValueNumbers(state, number); break; } default: ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR)), errmsg("Unknown arithmetic operation: %d", op)); } if (!opResult) { HandleArithmeticOperationError(opName, state, number, errSource); } } /* This function is to handle error of arithmetic operations * from ArithmeticOperationFunc. */ static void HandleArithmeticOperationError(const char *opName, bson_value_t *state, const bson_value_t *number, ArithmeticOperationErrorSource errSource) { char *errMsg = "An internal error occurred during the calculation of %s."; char *errMsgSource = "variance/covariance"; char *errMsgDetails = "Failed while calculating %s result: opName = %s, state = %s, number = %s."; char *calculateFunc = ""; switch (errSource) { case OperationSource_CovariancePopFinal: { calculateFunc = "bson_covariance_pop_final"; break; } case OperationSource_CovarianceSampFinal: { calculateFunc = "bson_covariance_samp_final"; break; } case OperationSource_StdDevPopFinal: { calculateFunc = "bson_std_dev_pop_final"; break; } case OperationSource_StdDevSampFinal: { calculateFunc = "bson_std_dev_samp_final"; break; } case OperationSource_StdDevPopWinfuncFinal: { calculateFunc = "bson_std_dev_pop_winfunc_final"; break; } case OperationSource_StdDevSampWinfuncFinal: { calculateFunc = "bson_std_dev_samp_winfunc_final"; break; } case OperationSource_CombineYCAlgr: { calculateFunc = "CalculateCombineFuncForCovarianceOrVarianceWithYCAlgr"; break; } case OperationSource_InvYCAlgr: { calculateFunc = "CalculateInvFuncForCovarianceOrVarianceWithYCAlgr"; break; } case OperationSource_SFuncYCAlgr: { calculateFunc = "CalculateSFuncForCovarianceOrVarianceWithYCAlgr"; break; } case OperationSource_ExpMovingAvg: { calculateFunc = "CalculateExpMovingAvg"; errMsgSource = "expMovingAvg"; break; } } ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR)), errmsg(errMsg, errMsgSource), errdetail_log( errMsgDetails, calculateFunc, opName, BsonValueToJsonForLogging(state), BsonValueToJsonForLogging(number))); } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_vector_search.c000066400000000000000000001717671507310017400302770ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_vector_search.c * * Implementation of the backend query generation for pipelines * containing vector search stages. * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io/bson_core.h" #include "metadata/metadata_cache.h" #include "query/query_operator.h" #include "commands/parse_error.h" #include "commands/defrem.h" #include "opclass/bson_gin_index_mgmt.h" #include "utils/version_utils.h" #include "aggregation/bson_aggregation_pipeline.h" #include "aggregation/bson_aggregation_pipeline_private.h" #include "utils/feature_counter.h" #include "utils/hashset_utils.h" #include "vector/vector_common.h" #include "vector/vector_configs.h" #include "vector/vector_spec.h" #include "vector/vector_utilities.h" #include "api_hooks.h" #include "index_am/index_am_utils.h" /* --------------------------------------------------------- */ /* Data-types */ /* --------------------------------------------------------- */ typedef enum VectorSearchSpecType { VectorSearchSpecType_Unknown = 0, VectorSearchSpecType_CosmosSearch = 1, VectorSearchSpecType_KnnBeta = 2, VectorSearchSpecType_Native = 3 } VectorSearchSpecType; /* Context used in replacing the expressions on filtered vector search */ typedef struct { /* The source orderby var to replace */ Var *sourceExpr; /* The target expression to replace it with */ Expr *targetExpr; } ReplaceDocumentVarOnSortContext; /* --------------------------------------------------------- */ /* Forward declaration */ /* --------------------------------------------------------- */ static bool IsPgvectorIterativeScanAvailable(); static pgbson * SetIterativeScanToSearchParam(pgbson *searchParamPgbson); static char * GetVectorIterativeScanModeName(VectorIterativeScanMode iterativeScanMode); static void AddSearchParamFunctionToQuery(Query *query, pgbson *searchParamPgbson); static Expr * AddScoreFieldToDocumentEntry(TargetEntry *documentEntry, Expr *vectorSortExpr, VectorIndexDistanceMetric distanceMetric); static TargetEntry * AddCtidToQueryTargetList(Query *query, bool replaceTargetList); static Query * JoinVectorSearchQueryWithFilterQuery(Query *leftQuery, Query *rightQuery, TargetEntry *leftJoinEntry, TargetEntry *rightJoinEntry); static void AddPathStringToHashset(List *indexIdList, HTAB *stringHashSet); static Query * GeneratePrefilteringVectorSearchQuery(Query *searchQuery, AggregationPipelineBuildContext * context, VectorSearchOptions * vectorSearchOptions, TargetEntry *sortEntry, Expr *processedSortExpr, Node *limitCount); static void AddNullVectorCheckToQuery(Query *query, const Expr *vectorSortExpr); static TargetEntry * AddSortByToQuery(Query *query, const Expr *vectorSortExpr); static void ParseAndValidateNativeVectorSearchSpec(const bson_value_t * nativeVectorSearchSpec, VectorSearchOptions * vectorSearchOptions); static void ParseAndValidateIndexSpecificOptions( VectorSearchOptions *vectorSearchOptions); static Query * HandleVectorSearchCore(Query *query, VectorSearchOptions *vectorSearchOptions, AggregationPipelineBuildContext *context); static Expr * CheckVectorIndexAndGenerateSortExpr(Query *query, VectorSearchOptions *vectorSearchOptions, AggregationPipelineBuildContext *context); static VectorIndexCompressionType GetIndexCompressionType( VectorSearchOptions *vectorSearchOptions, Relation indexRelation, FuncExpr *vectorCastFunc); static void ParseAndValidateKnnBetaQuerySpec(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOption); static void ParseAndValidateCosmosSearchQuerySpec(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOptions); static void ParseAndValidateVectorQuerySpecCore(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOptions); static Expr * GenerateScoreExpr(const Expr *orderVar, VectorIndexDistanceMetric distanceMetric); static Query * ReorderResultsForFilter(Query *joinQuery, AggregationPipelineBuildContext *context); static Query * ReorderResultsForCompression(Query *joinQuery, AggregationPipelineBuildContext *context, Expr *scoreExpr); static Node * ReplaceDocumentVarOnSort(Node *input, ReplaceDocumentVarOnSortContext *context); static Query * AddFilterToQuery(Query *query, AggregationPipelineBuildContext *context, VectorSearchOptions *vectorSearchOptions); /* --------------------------------------------------------- */ /* Top level exports */ /* --------------------------------------------------------- */ PG_FUNCTION_INFO_V1(command_bson_document_add_score_field); PG_FUNCTION_INFO_V1(command_bson_search_param); /* * bson_document_add_meta_field adds new fields to the base document. * document: { ... , "__cosmos_meta__" : { "score" : { "$numberDouble" : "0.9" } } } */ Datum command_bson_document_add_score_field(PG_FUNCTION_ARGS) { pgbson *document = PG_GETARG_PGBSON(0); float8 scoreField = PG_GETARG_FLOAT8(1); pgbson_writer finalDocWriter; PgbsonWriterInit(&finalDocWriter); /* Add the document */ PgbsonWriterConcat(&finalDocWriter, document); pgbson_writer nestedWriter; PgbsonWriterInit(&nestedWriter); PgbsonWriterStartDocument(&finalDocWriter, VECTOR_METADATA_FIELD_NAME, VECTOR_METADATA_FIELD_NAME_STR_LEN, &nestedWriter); /* Include the score field */ PgbsonWriterAppendDouble(&nestedWriter, VECTOR_METADATA_SCORE_FIELD_NAME, VECTOR_METADATA_SCORE_FIELD_NAME_STR_LEN, scoreField); PgbsonWriterEndDocument(&finalDocWriter, &nestedWriter); PG_RETURN_POINTER(PgbsonWriterGetPgbson(&finalDocWriter)); } /* * Dummy function used to send search parameters to the workers. */ Datum command_bson_search_param(PG_FUNCTION_ARGS) { PG_RETURN_BOOL(true); } /* * Parses and handles the $search stage in the aggregation pipeline. * Converts the query to an * ORDER BY bson_extract_vector(document, 'spec') <=> bson_extract_vector(query, 'spec') * For additional details see query_operator.c */ Query * HandleSearch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { RangeTblEntry *rte = linitial(query->rtable); if (rte->rtekind != RTE_RELATION || rte->tablesample != NULL || query->limitCount != NULL || context->stageNum != 0) { /* This is incompatible.vector search needs the base relation. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$search must appear as the initial stage in the pipeline sequence."))); } ReportFeatureUsage(FEATURE_STAGE_SEARCH); EnsureTopLevelFieldValueType("$search", existingValue, BSON_TYPE_DOCUMENT); /* The top level $search spec, parsing and validating */ VectorSearchSpecType searchSpecType = VectorSearchSpecType_Unknown; pgbson *vectorSearchSpecPgbson = NULL; bson_iter_t searchIterator; BsonValueInitIterator(existingValue, &searchIterator); while (bson_iter_next(&searchIterator)) { const char *key = bson_iter_key(&searchIterator); if (strcmp(key, "cosmosSearch") == 0) { /* parse search options search */ EnsureTopLevelFieldType(key, &searchIterator, BSON_TYPE_DOCUMENT); vectorSearchSpecPgbson = PgbsonInitFromDocumentBsonValue(bson_iter_value( &searchIterator)); searchSpecType = VectorSearchSpecType_CosmosSearch; } else if (strcmp(key, "knnBeta") == 0) { /* parse search options search */ EnsureTopLevelFieldType(key, &searchIterator, BSON_TYPE_DOCUMENT); vectorSearchSpecPgbson = PgbsonInitFromDocumentBsonValue(bson_iter_value( &searchIterator)); searchSpecType = VectorSearchSpecType_KnnBeta; } else if (strcmp(key, "index") == 0 || strcmp(key, "returnStoredSource") == 0) { /* We ignore these options */ } else { /* What are these options today? */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNRECOGNIZEDCOMMAND), errmsg( "Unrecognized $search option: %s, should be one of: cosmosSearch, knnBeta.", key))); } } if (searchSpecType == VectorSearchSpecType_Unknown) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Invalid search spec provided with one or more unsupported options, should be one of: cosmosSearch, knnBeta."))); } /* The vector search spec, parsing and validating */ VectorSearchOptions vectorSearchOptions = { 0 }; vectorSearchOptions.searchSpecPgbson = vectorSearchSpecPgbson; vectorSearchOptions.resultCount = -1; vectorSearchOptions.queryVectorLength = -1; if (searchSpecType == VectorSearchSpecType_CosmosSearch) { ParseAndValidateCosmosSearchQuerySpec(vectorSearchSpecPgbson, &vectorSearchOptions); } else if (searchSpecType == VectorSearchSpecType_KnnBeta) { /* TODO: Track the usage of the knnBeta, if there is no usage, we will remove knnBeta later */ ReportFeatureUsage(FEATURE_STAGE_VECTOR_SEARCH_KNN); ParseAndValidateKnnBetaQuerySpec(vectorSearchSpecPgbson, &vectorSearchOptions); } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "Invalid search spec provided with one or more unsupported options, should be one of: cosmosSearch, knnBeta."))); } /* Handle the vector search spec */ return HandleVectorSearchCore(query, &vectorSearchOptions, context); } /* * Parses and handles the $vectorSearch stage in the aggregation pipeline. * Converts the query to an * ORDER BY bson_extract_vector(document, 'spec') <=> bson_extract_vector(query, 'spec') * For additional details see query_operator.c */ Query * HandleNativeVectorSearch(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { RangeTblEntry *rte = linitial(query->rtable); if (rte->rtekind != RTE_RELATION || rte->tablesample != NULL || query->limitCount != NULL || context->stageNum != 0) { /* This is incompatible.vector search needs the base relation. */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The $vectorSearch needs to appear as the initial stage in the processing pipeline."))); } ReportFeatureUsage(FEATURE_STAGE_VECTOR_SEARCH_NATIVE); VectorSearchOptions vectorSearchOptions = { 0 }; vectorSearchOptions.resultCount = -1; vectorSearchOptions.queryVectorLength = -1; ParseAndValidateNativeVectorSearchSpec(existingValue, &vectorSearchOptions); return HandleVectorSearchCore(query, &vectorSearchOptions, context); } /* --------------------------------------------------------- */ /* Private methods */ /* --------------------------------------------------------- */ /* * The pgvector iterative scan is available from 0.8.0, */ static bool IsPgvectorIterativeScanAvailable() { /* array_to_sparsevec function is introduced in 0.8.0 */ /* so we can check the function is available or not to indicate the iterative scan is available */ bool missingOK = true; return OidIsValid(PgDoubleToSparseVecFunctionOid(missingOK)); } static pgbson * SetIterativeScanToSearchParam(pgbson *searchParamPgbson) { if (!IsPgvectorIterativeScanAvailable()) { return searchParamPgbson; } pgbson_writer docWriter; PgbsonWriterInit(&docWriter); if (searchParamPgbson != NULL) { PgbsonWriterConcat(&docWriter, searchParamPgbson); } PgbsonWriterAppendUtf8(&docWriter, VECTOR_PARAMETER_NAME_ITERATIVE_SCAN, VECTOR_PARAMETER_NAME_ITERATIVE_SCAN_STR_LEN, GetVectorIterativeScanModeName( VectorPreFilterIterativeScanMode)); return PgbsonWriterGetPgbson(&docWriter); } static char * GetVectorIterativeScanModeName(VectorIterativeScanMode iterativeScanMode) { switch (iterativeScanMode) { case VectorIterativeScan_RELAXED_ORDER: { return "relaxed_order"; } case VectorIterativeScan_STRICT_ORDER: { return "strict_order"; } case VectorIterativeScan_OFF: default: { break; } } return "off"; } /* * Adds a wrapper function(bson_search_param) which includes the search parameters to the query. * If the incoming query does not have search parameters, * In custom scan, we will dynamically calculate search param depend on the number of vectors in the collection. * * The example of the search param: * ivfflat: { "nProbes": 4, "iterativeScan": "strict_order"} * hnsw: { "efSearch": 16, "iterativeScan": "relaxed_order" } * e.g. * WHERE bson_search_param(document, { "nProbes": 4 }) or WHERE bson_search_param(document, { "efSearch": 16 }) */ static void AddSearchParamFunctionToQuery(Query *query, pgbson *searchParamPgbson) { if (searchParamPgbson != NULL) { /* Add the search param function to the query */ Const *searchParam = MakeBsonConst(searchParamPgbson); List *args = list_make2(MakeSimpleDocumentVar(), searchParam); FuncExpr *searchQual = makeFuncExpr(ApiBsonSearchParamFunctionId(), BOOLOID, args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); if (query->jointree->quals != NULL) { List *quals = lappend(make_ands_implicit((Expr *) query->jointree->quals), searchQual); query->jointree->quals = (Node *) make_ands_explicit(quals); } else { query->jointree->quals = (Node *) searchQual; } } } /* * Adds ctid to the query target list. */ static TargetEntry * AddCtidToQueryTargetList(Query *query, bool replaceTargetList) { bool resjunk = false; Index varno = 1; Var *ctidVar = makeVar(varno, SelfItemPointerAttributeNumber, TIDOID, -1, InvalidOid, 0); const char *ctidname = "ctid"; TargetEntry *ctid = NULL; if (replaceTargetList) { ctid = makeTargetEntry((Expr *) ctidVar, 1, pstrdup(ctidname), resjunk); query->targetList = list_make1(ctid); } else { ctid = makeTargetEntry((Expr *) ctidVar, list_length(query->targetList) + 1, pstrdup(ctidname), resjunk); query->targetList = lappend(query->targetList, ctid); } return ctid; } /* * Generates a join query that joins the left and right queries on the leftJoinEntry and rightJoinEntry. * Example: * JOIN c1 ON c1.ctid = c2.ctid * SELECT * c1.document * FROM c1 JOIN c2 ON c2.ctid = c1.ctid * ORDER BY c1.orderVal */ static Query * JoinVectorSearchQueryWithFilterQuery(Query *leftQuery, Query *rightQuery, TargetEntry *leftJoinEntry, TargetEntry *rightJoinEntry) { Query *finalQuery = makeNode(Query); finalQuery->commandType = CMD_SELECT; finalQuery->querySource = leftQuery->querySource; finalQuery->canSetTag = true; finalQuery->jointree = makeNode(FromExpr); const Index leftQueryRteIndex = 1; const Index rightQueryRteIndex = 2; const Index joinQueryRteIndex = 3; RangeTblEntry *leftTree = makeNode(RangeTblEntry); leftTree->rtekind = RTE_SUBQUERY; leftTree->subquery = leftQuery; leftTree->self_reference = false; leftTree->lateral = false; leftTree->inh = false; leftTree->inFromCl = true; List *colnames = NIL; ListCell *cell; foreach(cell, leftQuery->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(cell); colnames = lappend(colnames, makeString(tle->resname)); } leftTree->alias = makeAlias("c1", NIL); leftTree->eref = makeAlias("c1", colnames); RangeTblEntry *rightTree = makeNode(RangeTblEntry); rightTree->rtekind = RTE_SUBQUERY; rightTree->subquery = rightQuery; rightTree->self_reference = false; rightTree->lateral = false; rightTree->inh = false; rightTree->inFromCl = true; colnames = NIL; foreach(cell, rightQuery->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(cell); colnames = lappend(colnames, makeString(tle->resname)); } rightTree->alias = makeAlias("c2", NIL); rightTree->eref = makeAlias("c2", colnames); List *outputVars = NIL; List *outputColNames = NIL; List *leftJoinCols = NIL; foreach(cell, leftQuery->targetList) { TargetEntry *entry = lfirst(cell); Var *outputVar = makeVar(leftQueryRteIndex, entry->resno, ((Var *) entry->expr)->vartype, -1, InvalidOid, 0); outputVars = lappend(outputVars, outputVar); outputColNames = lappend(outputColNames, makeString(entry->resname)); leftJoinCols = lappend_int(leftJoinCols, entry->resno); } List *rightJoinCols = NIL; foreach(cell, rightQuery->targetList) { TargetEntry *entry = lfirst(cell); Var *outputVar = makeVar(rightQueryRteIndex, entry->resno, ((Var *) entry->expr)->vartype, -1, InvalidOid, 0); outputVars = lappend(outputVars, outputVar); outputColNames = lappend(outputColNames, makeString(entry->resname)); rightJoinCols = lappend_int(rightJoinCols, entry->resno); } /* Add an RTE for the JoinExpr */ RangeTblEntry *joinRte = makeNode(RangeTblEntry); joinRte->rtekind = RTE_JOIN; joinRte->relid = InvalidOid; joinRte->subquery = NULL; joinRte->jointype = JOIN_INNER; joinRte->joinmergedcols = 0; /* No using clause */ joinRte->joinaliasvars = outputVars; joinRte->joinleftcols = leftJoinCols; joinRte->joinrightcols = rightJoinCols; joinRte->join_using_alias = NULL; joinRte->alias = makeAlias("final_join", NIL); joinRte->eref = makeAlias("final_join", outputColNames); joinRte->inh = false; /* never true for joins */ joinRte->inFromCl = true; #if PG_VERSION_NUM >= 160000 joinRte->perminfoindex = 0; #else joinRte->requiredPerms = 0; joinRte->checkAsUser = InvalidOid; joinRte->selectedCols = NULL; joinRte->insertedCols = NULL; joinRte->updatedCols = NULL; joinRte->extraUpdatedCols = NULL; #endif finalQuery->rtable = list_make3(leftTree, rightTree, joinRte); /* Now specify the "From" as a join */ /* The query has a single 'FROM' which is a Join */ JoinExpr *joinExpr = makeNode(JoinExpr); joinExpr->jointype = joinRte->jointype; joinExpr->rtindex = joinQueryRteIndex; /* Create RangeTblRef's to point to the left & right RTEs */ RangeTblRef *leftRef = makeNode(RangeTblRef); leftRef->rtindex = leftQueryRteIndex; RangeTblRef *rightRef = makeNode(RangeTblRef); rightRef->rtindex = rightQueryRteIndex; joinExpr->larg = (Node *) leftRef; joinExpr->rarg = (Node *) rightRef; Var *lCtidVar = makeVar(leftQueryRteIndex, leftJoinEntry->resno, TIDOID, -1, InvalidOid, 0); Var *rCtidVar = makeVar(rightQueryRteIndex, rightJoinEntry->resno, TIDOID, -1, InvalidOid, 0); joinExpr->quals = (Node *) make_opclause( (Oid) TIDEqualOperator, BOOLOID, false, (Expr *) rCtidVar, (Expr *) lCtidVar, InvalidOid, InvalidOid); finalQuery->jointree->fromlist = list_make1(joinExpr); /* Add the document projector for the joined query */ bool resjunk = false; Var *documentVar = makeVar(leftQueryRteIndex, 1, BsonTypeId(), DOCUMENT_DATA_TABLE_DOCUMENT_VAR_TYPMOD, DOCUMENT_DATA_TABLE_DOCUMENT_VAR_COLLATION, 0); TargetEntry *documentEntry = makeTargetEntry((Expr *) documentVar, 1, "document", resjunk); finalQuery->targetList = list_make1(documentEntry); /* Add the sort clause for the joined query */ Var *orderVar = makeVar(leftQueryRteIndex, 2, FLOAT8OID, -1, InvalidOid, 0); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(finalQuery->targetList) + 1; SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_DEFAULT; /* reset later */ sortBy->node = (Node *) orderVar; resjunk = false; TargetEntry *topSortEntry = makeTargetEntry((Expr *) orderVar, (AttrNumber) parseState->p_next_resno++, pstrdup("sortScore"), resjunk); finalQuery->targetList = lappend(finalQuery->targetList, topSortEntry); List *sortlist = addTargetToSortList(parseState, topSortEntry, NIL, finalQuery->targetList, sortBy); pfree(parseState); finalQuery->sortClause = sortlist; return finalQuery; } /* Add the similarity score field to the metadata in the document * bson_document_add_score_field(document, similarityScore) * Result: "document": { ... , "$__cosmos_meta__.score": { "score": 0.9 } } */ static Expr * AddScoreFieldToDocumentEntry(TargetEntry *documentEntry, Expr *vectorSortExpr, VectorIndexDistanceMetric distanceMetric) { ReplaceDocumentVarOnSortContext sortContext = { .sourceExpr = MakeSimpleDocumentVar(), .targetExpr = documentEntry->expr, }; /* Use expression_tree_mutator so we copy the orderby Expr before changing it */ Expr *sortExprInput = (Expr *) expression_tree_mutator((Node *) vectorSortExpr, ReplaceDocumentVarOnSort, &sortContext); /* For half vector index, we need to use full vector to re-calculate the score */ List *orderArgs = NIL; if (IsA(sortExprInput, OpExpr)) { OpExpr *orderOpExpr = (OpExpr *) sortExprInput; orderArgs = orderOpExpr->args; } else if (IsA(sortExprInput, FuncExpr)) { FuncExpr *orderFuncExpr = (FuncExpr *) sortExprInput; orderArgs = orderFuncExpr->args; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "unsupported vector search operator/function type"))); } FuncExpr *leftArgFuncWithCast = (FuncExpr *) linitial(orderArgs); FuncExpr *rightArgFuncWithCast = (FuncExpr *) lsecond(orderArgs); if (IsHalfVectorCastFunction(leftArgFuncWithCast)) { /* The half compressed orderExpr example: * public.vector_to_halfvec(bson_extract_vector(document, 'v'::text), 3, true) * OPERATOR(public.<->) * public.vector_to_halfvec(bson_extract_vector('{ "vector" : [ 1, 2, 3 ] }'::bson, 'vector'::text), 3, true))) * 1. replace the cast function "vector_to_halfvec" with "vector"" * 2. replace the operator "<->" with the full-vector version */ /* Replace the cast function "vector_to_halfvec" with "vector" */ Expr *fullLeftArgFuncWithCast = (Expr *) makeFuncExpr( VectorAsVectorFunctionOid(), VectorTypeId(), leftArgFuncWithCast->args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); Expr *fullRightArgFuncWithCast = (Expr *) makeFuncExpr( VectorAsVectorFunctionOid(), VectorTypeId(), rightArgFuncWithCast->args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); List *newArgs = list_make2(fullLeftArgFuncWithCast, fullRightArgFuncWithCast); /* Replace the operator "<->" with the full-vector version */ Oid similarityOpOid = GetFullVectorOperatorId(distanceMetric); if (similarityOpOid == InvalidOid) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "unknown vector search operator type"))); } if (IsA(sortExprInput, FuncExpr)) { FuncExpr *orderFuncExpr = (FuncExpr *) sortExprInput; orderFuncExpr->funcid = get_opcode(similarityOpOid); orderFuncExpr->args = newArgs; } else /* OpExpr */ { OpExpr *orderOpExpr = (OpExpr *) sortExprInput; orderOpExpr->opno = similarityOpOid; orderOpExpr->args = newArgs; } } /* Include the field 'score' to the document */ Expr *scoreExpr = GenerateScoreExpr((Expr *) sortExprInput, distanceMetric); List *args = list_make2(documentEntry->expr, scoreExpr); FuncExpr *resultExpr = makeFuncExpr( ApiBsonDocumentAddScoreFieldFunctionId(), BsonTypeId(), args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); documentEntry->expr = (Expr *) resultExpr; return sortExprInput; } /* * Generates similar score expression based on the similarity search operator. * cos: 1.0 - orderScore * ip: -1.0 * orderScore * l2: orderScore */ static Expr * GenerateScoreExpr(const Expr *orderVar, VectorIndexDistanceMetric distanceMetric) { Expr *scoreExpr = NULL; if (distanceMetric == VectorIndexDistanceMetric_CosineDistance) { /* Similarity search score is 1.0 - orderVar */ Const *oneConst = makeConst(FLOAT8OID, -1, InvalidOid, sizeof(float8), Float8GetDatum(1.0), false, true); scoreExpr = make_opclause( Float8MinusOperatorId(), FLOAT8OID, false, (Expr *) oneConst, (Expr *) orderVar, InvalidOid, InvalidOid); } else if (distanceMetric == VectorIndexDistanceMetric_IPDistance) { /* Similarity search score is -1.0 * orderVar */ Const *minusOneConst = makeConst(FLOAT8OID, -1, InvalidOid, sizeof(float8), Float8GetDatum(-1.0), false, true); scoreExpr = (Expr *) make_opclause( Float8MultiplyOperatorId(), FLOAT8OID, false, (Expr *) minusOneConst, (Expr *) orderVar, InvalidOid, InvalidOid); } else if (distanceMetric == VectorIndexDistanceMetric_L2Distance) { /* Similarity search score is orderVar */ scoreExpr = (Expr *) orderVar; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "unsupported vector search operator type"))); } return (Expr *) scoreExpr; } /* * Adds a wrapper select query to the join query and re-order by the orderVar. * To force the planner to re-order the query, we use orderVar + 0 for order by. * e.g. * SELECT document FROM (JOIN c1 ON c1.ctid = c2.ctid limit k) ORDER BY c1.orderVal + 0 */ static Query * ReorderResultsForFilter(Query *joinQuery, AggregationPipelineBuildContext *context) { context->expandTargetList = true; Query *wrapperQuery = MigrateQueryToSubQuery(joinQuery, context); /* document var is added by the MigrateQueryToSubQuery */ /* orderScore var is the second target entry of subquery*/ /* Add the sort clause for the re-order query */ Var *orderVar = makeVar(1, 2, FLOAT8OID, -1, InvalidOid, 0); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(wrapperQuery->targetList) + 1; SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_DEFAULT; /* reset later */ /* order by orderVar + 0 */ Const *zeroConst = makeConst(FLOAT8OID, -1, InvalidOid, sizeof(float8), Float8GetDatum(0), false, true); Expr *scoreExpr = make_opclause( Float8PlusOperatorId(), FLOAT8OID, false, (Expr *) orderVar, (Expr *) zeroConst, InvalidOid, InvalidOid); sortBy->node = (Node *) scoreExpr; /* Hide the orderVar*/ bool resjunk = true; TargetEntry *topSortEntry = makeTargetEntry((Expr *) scoreExpr, (AttrNumber) parseState->p_next_resno++, pstrdup("orderScore"), resjunk); wrapperQuery->targetList = lappend(wrapperQuery->targetList, topSortEntry); List *sortlist = addTargetToSortList(parseState, topSortEntry, NIL, wrapperQuery->targetList, sortBy); pfree(parseState); wrapperQuery->sortClause = sortlist; return wrapperQuery; } /* * Adds a wrapper select query to the query and re-order by the full-vector distance. */ static Query * ReorderResultsForCompression(Query *query, AggregationPipelineBuildContext *context, Expr *fullScoreExpr) { TargetEntry *scoreEntry = makeTargetEntry(fullScoreExpr, 2, "fullScoreVal", false); query->targetList = lappend(query->targetList, scoreEntry); context->expandTargetList = true; Query *wrapperQuery = MigrateQueryToSubQuery(query, context); /* document var is added by the MigrateQueryToSubQuery */ /* orderScore var is the second target entry of subquery*/ /* Add the sort clause for the re-order query */ Var *orderVar = makeVar(1, 2, FLOAT8OID, -1, InvalidOid, 0); ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(wrapperQuery->targetList) + 1; SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_DEFAULT; /* reset later */ sortBy->node = (Node *) orderVar; /* Hide the orderScore*/ bool resjunk = true; TargetEntry *topSortEntry = makeTargetEntry((Expr *) orderVar, (AttrNumber) parseState->p_next_resno++, pstrdup("scoreValue"), resjunk); wrapperQuery->targetList = lappend(wrapperQuery->targetList, topSortEntry); List *sortlist = addTargetToSortList(parseState, topSortEntry, NIL, wrapperQuery->targetList, sortBy); pfree(parseState); wrapperQuery->sortClause = sortlist; return wrapperQuery; } /* * Retrieves all the path strings from the indexIdList and adds it to the hash set. */ static void AddPathStringToHashset(List *indexIdList, HTAB *stringHashSet) { ListCell *indexId; foreach(indexId, indexIdList) { Relation indexRelation = RelationIdGetRelation(lfirst_oid(indexId)); if (IsBsonRegularIndexAm(indexRelation->rd_rel->relam)) { int numberOfKeyAttributes = IndexRelationGetNumberOfKeyAttributes( indexRelation); for (int i = 0; i < numberOfKeyAttributes; i++) { /* Check if the index is a single path index */ if (indexRelation->rd_opcoptions[i] != NULL && IsSinglePathOpFamilyOid(indexRelation->rd_rel->relam, indexRelation->rd_opfamily[i])) { bytea *optBytea = indexRelation->rd_opcoptions[i]; BsonGinSinglePathOptions *indexOption = (BsonGinSinglePathOptions *) optBytea; uint32_t pathCount = 0; const char *pathStr; Get_Index_Path_Option(indexOption, path, pathStr, pathCount); char *copiedPathStr = palloc(pathCount + 1); strcpy(copiedPathStr, pathStr); /* Add the index path to the hash set */ StringView hashEntry = CreateStringViewFromStringWithLength( copiedPathStr, pathCount); bool found = false; hash_search(stringHashSet, &hashEntry, HASH_ENTER, &found); } } } RelationClose(indexRelation); } } static Query * AddFilterToQuery(Query *query, AggregationPipelineBuildContext *context, VectorSearchOptions *vectorSearchOptions) { RangeTblEntry *rte = linitial(query->rtable); Relation collectionRelation = RelationIdGetRelation(rte->relid); List *indexIdList = RelationGetIndexList(collectionRelation); RelationClose(collectionRelation); /* Before we can do prefiltering we need to make sure that * the collection has the appropriate index. * Retrieve the path string of SinglePath index path from the collection */ HTAB *indexPathNameHashSet = CreateStringViewHashSet(); AddPathStringToHashset(indexIdList, indexPathNameHashSet); context->requiredFilterPathNameHashSet = indexPathNameHashSet; /* Add a match expression into where clause * checking that the collection has the appropriate index keys * Example: where document @@ '{ "value": {$regex: /^bb/}' */ Query *filterQuery = HandleMatch(&vectorSearchOptions->filterBson, query, context); context->requiredFilterPathNameHashSet = NULL; hash_destroy(indexPathNameHashSet); return filterQuery; } /* * Generates a query based on the vector search query and user specified filters. * The query is generated as follows: * * 1. Search query: * SELECT * document, * (public.vector(ApiCatalogSchema.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(ApiCatalogSchema.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::CoreSchema.bson, 'vector'::text), 3, true)) AS orderVal, * ctid * FROM * ApiDataSchemaName.documents_1 collection * WHERE * shard_key_value = 0 * AND ((ApiCatalogSchema.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL)) * ORDER BY * (public.vector(ApiCatalogSchema.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(ApiCatalogSchema.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::CoreSchema.bson, 'vector'::text), 3, true)) * * 2. Filter query: * SELECT * ctid * FROM * ApiDataSchemaName.documents_1 * WHERE * shard_key_value = 0 * AND document @@ '{ "a": "some sentence" }' * * 3. JOIN c1 ON c1.ctid = c2.ctid * SELECT * c1.document * FROM c1 JOIN c2 ON c2.ctid = c1.ctid * ORDER BY c1.orderVal */ static Query * GeneratePrefilteringVectorSearchQuery(Query *searchQuery, AggregationPipelineBuildContext *context, VectorSearchOptions *vectorSearchOptions, TargetEntry *sortEntry, Expr *processedSortExpr, Node *limitCount) { /* choose enn or ann for the filter query */ if (vectorSearchOptions->exactSearch) { /* * Add filters to the search query, use filter index scan + runtime sort * e.g. * SELECT * API_CATALOG_SCHEMA_NAME.bson_document_add_score_field(document, {order by expr}) AS document * FROM ( * SELECT document * FROM API_DATA_SCHEMA_NAME.documents_2_102046 collection * WHERE ((document OPERATOR(API_CATALOG_SCHEMA_NAME.#=) '{ "attr" : { "$numberInt" : "1000002" } }'::API_CATALOG_SCHEMA_NAME.bsonquery) * AND (shard_key_value OPERATOR(pg_catalog.=) '2'::bigint) * AND (API_CATALOG_SCHEMA_NAME.bson_extract_vector(document, 'vect'::text) IS NOT NULL)) * ORDER BY ( * public.cosine_similarity( * public.vector(API_CATALOG_SCHEMA_NAME.bson_extract_vector(document, 'vect'::text), 1536, true), * public.vector(API_CATALOG_SCHEMA_NAME.bson_extract_vector('{ "vector" : [...], "k" : 1, "path" : "vect", "filter" : { "attr" : { "$eq" : 1000002 } }, "lSearch" : 40 }'::API_CATALOG_SCHEMA_NAME.bson, 'vector'::text), 1536, true)) * ) * LIMIT '1'::bigint; * ) */ /* Add filters to the search query */ searchQuery = AddFilterToQuery(searchQuery, context, vectorSearchOptions); /* Add limit before push to subquery */ searchQuery->limitCount = limitCount; /* Wrapper query */ context->expandTargetList = false; Query *wrapperQuery = MigrateQueryToSubQuery(searchQuery, context); return wrapperQuery; } else { /* * 1. construct searchQuery: add sort entry and ctid to targetList */ /* add the sort entry with the alias "orderVal" to the targetList */ const char *sortAlias = "orderVal"; sortEntry->resname = pstrdup(sortAlias); sortEntry->resjunk = false; /* append ctid to targetList */ bool replaceTargetList = false; TargetEntry *leftCtidEntry = AddCtidToQueryTargetList(searchQuery, replaceTargetList); /* * 2. construct filterQuery: add match expression into where clause */ pg_uuid_t *collectionUuid = NULL; const bson_value_t *indexHint = NULL; Query *filterQuery = GenerateBaseTableQuery(context->databaseNameDatum, &context->collectionNameView, collectionUuid, indexHint, context); /* Add filters to the filter query */ filterQuery = AddFilterToQuery(filterQuery, context, vectorSearchOptions); /* replace targetList with ctid */ replaceTargetList = true; TargetEntry *rightCtidEntry = AddCtidToQueryTargetList(filterQuery, replaceTargetList); /* 3. JOIN c1 ON c1.ctid = c2.ctid * SELECT * c1.document * FROM c1 JOIN c2 ON c2.ctid = c1.ctid * ORDER BY c1.orderVal */ Query *joinedQuery = JoinVectorSearchQueryWithFilterQuery(searchQuery, filterQuery, leftCtidEntry, rightCtidEntry); /* Include a limit clause within the sub-query */ joinedQuery->limitCount = limitCount; if (VectorPreFilterIterativeScanMode == VectorIterativeScan_RELAXED_ORDER && vectorSearchOptions->compressionType == VectorIndexCompressionType_None) { /* Search result by iterative search may be disordered, so we need to reorder the result */ /* If index is compressed, we will recalculate and then reorder the results, so skip here */ joinedQuery = ReorderResultsForFilter(joinedQuery, context); } else { /* Wrapper query */ context->expandTargetList = false; joinedQuery = MigrateQueryToSubQuery(joinedQuery, context); } return joinedQuery; } } /* * Create WHERE bson_extract_vector(document, path) IS NOT NULL * and add it to the WHERE clause. */ static void AddNullVectorCheckToQuery(Query *query, const Expr *vectorSortExpr) { Assert(IsA(vectorSortExpr, OpExpr) || IsA(vectorSortExpr, FuncExpr)); FuncExpr *castFunctionExpr = NULL; if (IsA(vectorSortExpr, OpExpr)) { castFunctionExpr = (FuncExpr *) linitial( ((OpExpr *) vectorSortExpr)->args); } else { castFunctionExpr = (FuncExpr *) linitial( ((FuncExpr *) vectorSortExpr)->args); } Expr *extractVectorFunctionExpr = linitial(castFunctionExpr->args); NullTest *vectorNullTest = makeNode(NullTest); vectorNullTest->nulltesttype = IS_NOT_NULL; vectorNullTest->arg = (Expr *) extractVectorFunctionExpr; vectorNullTest->argisrow = false; if (query->jointree->quals != NULL) { List *qualsWithVectorNullTest = lappend(make_ands_implicit( (Expr *) query->jointree->quals), (Node *) vectorNullTest); query->jointree->quals = (Node *) make_ands_explicit(qualsWithVectorNullTest); } else { query->jointree->quals = (Node *) vectorNullTest; } } /* * Add vectorSortExpr as target entry to the query target list, resjunk is true. * Add sort by to the query, sort by the target entry. * returns the target entry that was added. */ static TargetEntry * AddSortByToQuery(Query *query, const Expr *vectorSortExpr) { ParseState *parseState = make_parsestate(NULL); parseState->p_expr_kind = EXPR_KIND_ORDER_BY; /* set after what is already taken */ parseState->p_next_resno = list_length(query->targetList) + 1; SortBy *sortBy = makeNode(SortBy); sortBy->location = -1; sortBy->sortby_dir = SORTBY_DEFAULT; /* reset later */ sortBy->node = (Node *) vectorSortExpr; bool resjunk = true; TargetEntry *sortEntry = makeTargetEntry((Expr *) vectorSortExpr, (AttrNumber) parseState->p_next_resno++, "?sort?", resjunk); query->targetList = lappend(query->targetList, sortEntry); List *sortlist = addTargetToSortList(parseState, sortEntry, NIL, query->targetList, sortBy); pfree(parseState); query->sortClause = sortlist; return sortEntry; } /** * parse the native search spec to cosmos search spec * And generate equivalent cosmos search query spec from the native search spec. * Set the vectorSearchOptions with the generated cosmos search query spec. */ static void ParseAndValidateNativeVectorSearchSpec(const bson_value_t *nativeVectorSearchSpec, VectorSearchOptions *vectorSearchOptions) { EnsureTopLevelFieldValueType("vectorSearch", nativeVectorSearchSpec, BSON_TYPE_DOCUMENT); bson_iter_t nativeVectorSearchIter; BsonValueInitIterator(nativeVectorSearchSpec, &nativeVectorSearchIter); pgbson_writer writer; PgbsonWriterInit(&writer); while (bson_iter_next(&nativeVectorSearchIter)) { const char *key = bson_iter_key(&nativeVectorSearchIter); const bson_value_t *value = bson_iter_value(&nativeVectorSearchIter); if (strcmp(key, "queryVector") == 0) { if (!BsonValueHoldsNumberArray(value, &vectorSearchOptions->queryVectorLength)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vectorSearch.queryVector must be an array of numbers."))); } if (vectorSearchOptions->queryVectorLength == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vectorSearch.queryVector cannot be an empty array."))); } if (vectorSearchOptions->queryVectorLength > VECTOR_MAX_DIMENSIONS) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Length of the query vector cannot exceed %d", VECTOR_MAX_DIMENSIONS))); } vectorSearchOptions->queryVectorValue = *value; PgbsonWriterAppendValue(&writer, "vector", 6, value); } else if (strcmp(key, "numCandidates") == 0) { EnsureTopLevelFieldValueType("numCandidates", value, BSON_TYPE_INT32); if (value->value.v_int32 < HNSW_MIN_EF_SEARCH) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The vectorSearch.numCandidates should have a value that is not less than %d.", HNSW_MIN_EF_SEARCH), errdetail_log( "The vectorSearch.numCandidates should have a value that is not less than %d.", HNSW_MIN_EF_SEARCH))); } if (value->value.v_int32 > HNSW_MAX_EF_SEARCH) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vectorSearch.numCandidates must be less than or equal to %d.", HNSW_MAX_EF_SEARCH), errdetail_log( "$vectorSearch.numCandidates must be less than or equal to %d.", HNSW_MAX_EF_SEARCH))); } PgbsonWriterAppendInt32(&writer, "efSearch", 8, value->value.v_int32); } else if (strcmp(key, "path") == 0) { EnsureTopLevelFieldValueType("path", value, BSON_TYPE_UTF8); vectorSearchOptions->searchPath = pstrdup(value->value.v_utf8.str); if (vectorSearchOptions->searchPath == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vectorSearch.path cannot be empty."))); } PgbsonWriterAppendUtf8(&writer, "path", 4, value->value.v_utf8.str); } else if (strcmp(key, "limit") == 0) { EnsureTopLevelFieldValueType("limit", value, BSON_TYPE_INT32); if (value->value.v_int32 < 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vectorSearch.limit must be provided as a positive integer value."))); } PgbsonWriterAppendInt32(&writer, "k", 1, value->value.v_int32); vectorSearchOptions->resultCount = BsonValueAsInt32(value); } else if (strcmp(key, "index") == 0) { /* Specifying index is not yet supported*/ continue; } else if (strcmp(key, "filter") == 0) { if (!EnableVectorPreFilter && !EnableVectorPreFilterV2) { /* Safe guard against the enableVectorPreFilter GUC */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("$filter is not supported for vector search yet."), errdetail_log( "vector pre-filter is disabled. Set ApiGucPrefix.enableVectorPreFilter to true to enable vector pre filter."))); } EnsureTopLevelFieldValueType("filter", value, BSON_TYPE_DOCUMENT); PgbsonWriterAppendValue(&writer, "filter", 6, value); vectorSearchOptions->filterBson = *value; } else { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD), errmsg( "BSON field '$vectorSearch.%s' is an unknown field", key))); } } if (vectorSearchOptions->searchPath == NULL || vectorSearchOptions->queryVectorValue.value_type == BSON_TYPE_EOD || vectorSearchOptions->resultCount < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$path, $queryVector, and $limit are all required fields for using a vector index."))); } vectorSearchOptions->searchSpecPgbson = PgbsonWriterGetPgbson(&writer); } static VectorIndexCompressionType GetIndexCompressionType(VectorSearchOptions *vectorSearchOptions, Relation indexRelation, FuncExpr *vectorCastFunc) { if (IsHalfVectorCastFunction(vectorCastFunc)) { return VectorIndexCompressionType_Half; } else if (vectorSearchOptions->vectorIndexDef != NULL && indexRelation->rd_options != NULL) { return vectorSearchOptions->vectorIndexDef->extractIndexCompressionTypeFunc( indexRelation->rd_options); } return VectorIndexCompressionType_None; } static Expr * CheckVectorIndexAndGenerateSortExpr(Query *query, VectorSearchOptions *vectorSearchOptions, AggregationPipelineBuildContext *context) { RangeTblEntry *rte = linitial(query->rtable); Relation collectionRelation = RelationIdGetRelation(rte->relid); List *indexIdList = RelationGetIndexList(collectionRelation); RelationClose(collectionRelation); Expr *processedSortExpr = NULL; ListCell *indexId; Node *queryNode = (Node *) MakeBsonConst(vectorSearchOptions->searchSpecPgbson); foreach(indexId, indexIdList) { FuncExpr *vectorCastFunc = NULL; Relation indexRelation = RelationIdGetRelation(lfirst_oid(indexId)); if (IsMatchingVectorIndex(indexRelation, vectorSearchOptions->searchPath, &vectorCastFunc)) { /* Vector search is on the doc even if there's projectors etc. */ processedSortExpr = GenerateVectorSortExpr( vectorSearchOptions, vectorCastFunc, indexRelation, (Node *) MakeSimpleDocumentVar(), queryNode); /* Set the vector access method */ vectorSearchOptions->vectorAccessMethodOid = indexRelation->rd_rel->relam; /* Set the vector index definition */ vectorSearchOptions->vectorIndexDef = GetVectorIndexDefinitionByIndexAmOid( vectorSearchOptions->vectorAccessMethodOid); if (vectorSearchOptions->vectorIndexDef == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg("Vector index type not supported"))); } /* Set the vector compression type */ vectorSearchOptions->compressionType = GetIndexCompressionType(vectorSearchOptions, indexRelation, vectorCastFunc); } RelationClose(indexRelation); if (processedSortExpr != NULL) { break; } } if (processedSortExpr == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Similarity index was not found for a vector similarity search query."))); } if (vectorSearchOptions->vectorAccessMethodOid == InvalidOid) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Similarity index was not found for a vector similarity search query."))); } return processedSortExpr; } static void ParseAndValidateIndexSpecificOptions(VectorSearchOptions *vectorSearchOptions) { Assert(vectorSearchOptions->vectorAccessMethodOid != InvalidOid); /* Parse the index specific options */ pgbson *searchParamPgbson = vectorSearchOptions->vectorIndexDef->parseIndexSearchSpecFunc( vectorSearchOptions); if (searchParamPgbson != NULL) { vectorSearchOptions->searchParamPgbson = searchParamPgbson; } } /* * Given a node, if it matches the source expression, then * it's replaced with the targetExpression. */ static Node * ReplaceDocumentVarOnSort(Node *input, ReplaceDocumentVarOnSortContext *context) { if (input == NULL) { return NULL; } if (IsA(input, Var)) { if (equal(input, context->sourceExpr)) { return (Node *) context->targetExpr; } } return expression_tree_mutator(input, ReplaceDocumentVarOnSort, context); } /* core logic for vector search*/ static Query * HandleVectorSearchCore(Query *query, VectorSearchOptions *vectorSearchOptions, AggregationPipelineBuildContext *context) { /* check vector index and generate sort expr */ /* Also check the vector access method, vector index definition and compression type */ Expr *processedSortExpr = CheckVectorIndexAndGenerateSortExpr(query, vectorSearchOptions, context); /* Parse and validate the index specific options */ ParseAndValidateIndexSpecificOptions(vectorSearchOptions); /* Add the search param wrapper function to the query */ /* Create the WHERE bson_search_param(document, searchParamPgbson) and add it to the WHERE */ if (!vectorSearchOptions->exactSearch) { /* set iterative parameter for filtering */ /* e.g. Search param: { "iterativeScan": "relaxed_order" } */ bson_value_t filterBson = vectorSearchOptions->filterBson; if (filterBson.value_type != BSON_TYPE_EOD && !IsBsonValueEmptyDocument(&filterBson)) { vectorSearchOptions->searchParamPgbson = SetIterativeScanToSearchParam( vectorSearchOptions->searchParamPgbson); } AddSearchParamFunctionToQuery(query, vectorSearchOptions->searchParamPgbson); } else { ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_EXACT); } /* Add the null vector check to the query, so that we don't return documents that don't have the vector field */ AddNullVectorCheckToQuery(query, processedSortExpr); /* Add the sort by to the query */ TargetEntry *sortEntry = AddSortByToQuery(query, processedSortExpr); /* Calculate the limit for oversampling */ int innerLimit = vectorSearchOptions->resultCount; if (vectorSearchOptions->oversampling > 1) { if (vectorSearchOptions->exactSearch) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "oversampling is not allowed for exact search."))); } else if (vectorSearchOptions->compressionType == VectorIndexCompressionType_None) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "oversampling is not allowed for non-compressed vector index."))); } /* ceiling the inner limit to resultCount * oversampling */ innerLimit = ceil(vectorSearchOptions->resultCount * vectorSearchOptions->oversampling); } /* feature usage of compression type */ if (vectorSearchOptions->compressionType == VectorIndexCompressionType_Half) { ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_HALF); } else if (vectorSearchOptions->compressionType == VectorIndexCompressionType_PQ) { ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_PQ); } Node *limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum(innerLimit), false, true); Expr *sortExpr = NULL; /* If there's a filter, add it to the query */ if (EnableVectorPreFilterV2 && vectorSearchOptions->filterBson.value_type != BSON_TYPE_EOD && !IsBsonValueEmptyDocument(&vectorSearchOptions->filterBson)) { ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_PRE_FILTER); /* Validate whether the collection is sharded or not */ if (context->mongoCollection != NULL && context->mongoCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Filter is not supported for vector search on sharded collection."))); } /* Just add the match directly to the query */ query = HandleMatch(&vectorSearchOptions->filterBson, query, context); /* Add the limit to the query before reordering */ query->limitCount = limitCount; /* After the limit is applied, push to a subquery */ query = MigrateQueryToSubQuery(query, context); /* Now we have the first arg as the document. Add a second projector for * the score. We do this so we only add the score for the subset of docs * matching the filter. */ TargetEntry *documentEntry = linitial(query->targetList); sortExpr = AddScoreFieldToDocumentEntry(documentEntry, sortEntry->expr, vectorSearchOptions->distanceMetric); TargetEntry *scoreEntry = makeTargetEntry(sortExpr, 2, "sortVal", false); query->targetList = lappend(query->targetList, scoreEntry); /* now reorder to ensure it matches the score order by */ query = ReorderResultsForFilter(query, context); } else if (EnableVectorPreFilter && vectorSearchOptions->filterBson.value_type != BSON_TYPE_EOD && !IsBsonValueEmptyDocument(&vectorSearchOptions->filterBson)) { ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_PRE_FILTER); /* Validate whether the collection is sharded or not */ if (context->mongoCollection != NULL && context->mongoCollection->shardKey != NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "Filter is not supported for vector search on sharded collection."))); } query = GeneratePrefilteringVectorSearchQuery(query, context, vectorSearchOptions, sortEntry, processedSortExpr, limitCount); /* Include the field 'score' */ TargetEntry *documentEntry = linitial(query->targetList); sortExpr = AddScoreFieldToDocumentEntry(documentEntry, sortEntry->expr, vectorSearchOptions->distanceMetric); } else { /* Add the limit to the query from k in the search spec */ query->limitCount = limitCount; /* After the limit is applied, push to a subquery */ query = MigrateQueryToSubQuery(query, context); /* Include the field 'score' */ TargetEntry *documentEntry = linitial(query->targetList); sortExpr = AddScoreFieldToDocumentEntry(documentEntry, sortEntry->expr, vectorSearchOptions->distanceMetric); } /* Reorder for the compression index */ if (vectorSearchOptions->compressionType != VectorIndexCompressionType_None && sortExpr != NULL && vectorSearchOptions->exactSearch == false) { /* reorder the results by the full vector distance */ /* Exact search doesn't need to reorder */ query = ReorderResultsForCompression(query, context, sortExpr); } /* Add k limit to the top level query if oversampling is specified */ if (vectorSearchOptions->oversampling > 1) { query->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid, sizeof(int64_t), Int64GetDatum( vectorSearchOptions->resultCount), false, true); } /* Push next stage to a new subquery (since we did a sort) */ context->requiresSubQueryAfterProject = true; return query; } /* * This method is for common validation of knnBeta and cosmosSearch * NULL values are passed for parameters that are not needed to be validated */ static void ParseAndValidateVectorQuerySpecCore(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOptions) { bson_iter_t specIter; PgbsonInitIterator(vectorSearchSpecPgbson, &specIter); while (bson_iter_next(&specIter)) { const char *key = bson_iter_key(&specIter); const bson_value_t *value = bson_iter_value(&specIter); if (strcmp(key, "path") == 0) { if (value->value_type != BSON_TYPE_UTF8) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$path must be a text value"))); } vectorSearchOptions->searchPath = pstrdup(value->value.v_utf8.str); if (vectorSearchOptions->searchPath == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The parameter $path must not be left empty."))); } } else if (strcmp(key, "vector") == 0) { vectorSearchOptions->queryVectorValue = *value; if (!BsonValueHoldsNumberArray(&vectorSearchOptions->queryVectorValue, &vectorSearchOptions->queryVectorLength)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vector must be an array of numbers."))); } if (vectorSearchOptions->queryVectorLength == 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vector cannot be an empty array."))); } if (vectorSearchOptions->queryVectorLength > VECTOR_MAX_DIMENSIONS) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "Length of the query vector cannot exceed %d", VECTOR_MAX_DIMENSIONS))); } } else if (strcmp(key, "k") == 0) { if (!BSON_ITER_HOLDS_NUMBER(&specIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The parameter $k should always hold a valid integer value."))); } vectorSearchOptions->resultCount = BsonValueAsInt32(value); if (vectorSearchOptions->resultCount < 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "The $k should always be a positive integer value."))); } } else if (strcmp(key, "filter") == 0) { if (!EnableVectorPreFilter && !EnableVectorPreFilterV2) { /* Safe guard against the enableVectorPreFilter GUC */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("$filter is not supported for vector search yet."), errdetail_log( "vector pre-filter is disabled. Set ApiGucPrefix.enableVectorPreFilter to true to enable vector pre filter."))); } if (!BSON_ITER_HOLDS_DOCUMENT(&specIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$filter must be a document value."))); } vectorSearchOptions->filterBson = *value; } else if (strcmp(key, "exact") == 0) { if (!BSON_ITER_HOLDS_BOOL(&specIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$exact must represent a valid boolean value."))); } vectorSearchOptions->exactSearch = BsonValueAsBool(value); } else if (strcmp(key, "oversampling") == 0) { if (!BSON_ITER_HOLDS_NUMBER(&specIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$oversampling must be a number value."))); } vectorSearchOptions->oversampling = BsonValueAsDouble(value); if (vectorSearchOptions->oversampling < 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$oversampling must be set to a value that is greater or equal to 1."))); } } else if (strcmp(key, "score") == 0) { if (!BSON_ITER_HOLDS_DOCUMENT(&specIter)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$score must be a document value."))); } vectorSearchOptions->scoreBson = *value; } else { /* Custom hook for parsing and validating vector query spec */ TryCustomParseAndValidateVectorQuerySpec(key, value, vectorSearchOptions); } } if (vectorSearchOptions->searchPath == NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$path is required field for using a vector index."))); } if (vectorSearchOptions->queryVectorValue.value_type == BSON_TYPE_EOD) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$vector is required field for using a vector index."))); } if (vectorSearchOptions->resultCount < 0) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg( "$k is required field for using a vector index."))); } /* Set default values for optional parameters */ if (vectorSearchOptions->oversampling == 0) { vectorSearchOptions->oversampling = 1; } } /* * Validate that a cosmosSearch query with vector index has all the required options with valid datatypes, namely * 1. path: a string denoting the path that was indexed. * 2. vector: a non-empty number array. * 3. k : an integer denoting the number of requested results. * 4. nProbes: an integer denoting the number of probes to use for the ivfflat search. * 5. efSearch: an integer denoting the number of efSearch to use for the hnsw search. * 6. filter: match expression that compares an indexed field with a boolean, number (not decimals), or string to use as a prefilter, which can help narrow down the scope of vector search. * 7. exact: a boolean denoting whether to use exact search or ann search. * * "cosmosSearch": { * "vector": [], * "path": "", * "filter": {}, * "k": , * "exact": , * } * * Example query spec of ivfflat index * '{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10, "nProbes": 4 }'::ApiCatalogSchemaName.bson * * Example query spec of hnsw index * '{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10, "efSearch": 4 }'::ApiCatalogSchemaName.bson * * Example filter spec * '{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10, "nProbes": 4, "filter": { "meta.value": {$regex: /^bb/} } }'::ApiCatalogSchemaName.bson * */ static void ParseAndValidateCosmosSearchQuerySpec(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOptions) { ParseAndValidateVectorQuerySpecCore(vectorSearchSpecPgbson, vectorSearchOptions); } /* * Validate that a knnBeta query with vector index has all the required options with valid datatypes, namely * 1. path: a string denoting the path that was indexed. * 2. vector: a non-empty number array. * 3. k : an integer denoting the number of requested results. * 4. filter: Not supported * 5. score: Not supported * * "knnBeta": { * "vector": [], * "path": "", * "filter": {}, * "k": , * "score": {} * } * * Example query spec: '{ "path" : "myvector", "vector": [8.0, 1.0, 9.0], "k": 10 }'::ApiCatalogSchemaName.bson * * */ static void ParseAndValidateKnnBetaQuerySpec(const pgbson *vectorSearchSpecPgbson, VectorSearchOptions *vectorSearchOptions) { ParseAndValidateVectorQuerySpecCore(vectorSearchSpecPgbson, vectorSearchOptions); bson_value_t filterBson = vectorSearchOptions->filterBson; if (filterBson.value_type != BSON_TYPE_EOD && !IsBsonValueEmptyDocument(&filterBson)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$filter is not supported for knnBeta queries."))); } bson_value_t scoreBson = vectorSearchOptions->scoreBson; if (scoreBson.value_type != BSON_TYPE_EOD && !IsBsonValueEmptyDocument(&scoreBson)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), errmsg( "$score is not supported for knnBeta queries."))); } } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_window_functions.c000066400000000000000000000363421507310017400310340ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_window_functions.c * * Implementation of Window function based accumulator for $setWindowFields. * *------------------------------------------------------------------------- */ #include #include #include #include "io/bson_core.h" #include "types/decimal128.h" #include "utils/documentdb_errors.h" #include "windowapi.h" typedef struct BsonLocfFillState { bool init; bool hasPre; pgbson *preValue; } BsonLocfFillState; typedef struct BsonLinearFillState { bool init; bool hasPre; bson_value_t preValue; /* previous non-null value for filled field */ bson_value_t preSortKeyValue; /* the value of sortKey of previous non-null value */ bool hasNext; bson_value_t nextValue; /* next non-null value for filled field */ bson_value_t nextSortKeyValue; /* the value of sortKey of next non-null value */ int64 nextPos; /* the position of next non-null value */ bool sortKeyIsNumeric; /* if sort key is numeric */ bool sortKeyIsDate; /* if sort key is date */ bool isOut; /* if all rows in current partition has been scanned */ } BsonLinearFillState; /* --------------------------------------------------------- */ /* Forward declaration */ /* --------------------------------------------------------- */ static void CheckDecimal128Result(Decimal128Result result); static void CheckSortKeyBsonValue(bool isnull, pgbsonelement *sortKeyElement); /* --------------------------------------------------------- */ /* Top level exports */ /* --------------------------------------------------------- */ PG_FUNCTION_INFO_V1(bson_rank); PG_FUNCTION_INFO_V1(bson_dense_rank); PG_FUNCTION_INFO_V1(bson_linear_fill); PG_FUNCTION_INFO_V1(bson_locf_fill); PG_FUNCTION_INFO_V1(bson_document_number); PG_FUNCTION_INFO_V1(bson_shift); PG_FUNCTION_INFO_V1(bson_const_fill); Datum bson_rank(PG_FUNCTION_ARGS) { Datum rank = window_rank(fcinfo); bson_value_t finalValue = { .value_type = BSON_TYPE_INT32 }; finalValue.value.v_int32 = DatumGetInt64(rank); PG_RETURN_POINTER(BsonValueToDocumentPgbson(&finalValue)); } Datum bson_dense_rank(PG_FUNCTION_ARGS) { Datum rank = window_dense_rank(fcinfo); bson_value_t finalValue = { .value_type = BSON_TYPE_INT32 }; finalValue.value.v_int32 = DatumGetInt64(rank); PG_RETURN_POINTER(BsonValueToDocumentPgbson(&finalValue)); } Datum bson_linear_fill(PG_FUNCTION_ARGS) { WindowObject winobj = PG_WINDOW_OBJECT(); BsonLinearFillState *stateData; stateData = (BsonLinearFillState *) WinGetPartitionLocalMemory(winobj, sizeof(BsonLinearFillState)); if (!stateData->init) { /* first call */ stateData->init = true; stateData->hasPre = false; stateData->hasNext = false; stateData->sortKeyIsDate = false; stateData->sortKeyIsNumeric = false; stateData->isOut = false; } Datum nextDatum; Datum nextSortKeyDatum; pgbsonelement nextValueElement; pgbsonelement nextSortKeyElement; bool isnull = true; bool isout = false; bool isValueNull = true; bool isSortKeyNull = true; int64 current_pos = WinGetCurrentPosition(winobj); /** * We need to verify the sortBy value when using linearFill. The restrictions are: * 1) Value of the sortBy field must be numeric or a date * 2) No repeated values in the sortBy field in a single partition */ pgbson *sortByValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 1, &isnull)); pgbsonelement sortByValueElement; PgbsonToSinglePgbsonElement(sortByValue, &sortByValueElement); CheckSortKeyBsonValue(isnull, &sortByValueElement); if (sortByValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) { stateData->sortKeyIsDate = true; } else { stateData->sortKeyIsNumeric = true; } if (stateData->sortKeyIsDate && stateData->sortKeyIsNumeric) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The sortBy field should contain either numeric values or dates, but cannot include both types simultaneously"), errdetail_log( "The sortBy field should contain either numeric values or dates, but cannot include both types simultaneously"))); } /* Verify presence of duplicate values within the sortBy field for an individual partition */ if (current_pos != 0 && WinRowsArePeers(winobj, current_pos - 1, current_pos)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION6050106), errmsg("The sort field must not contain any duplicate values"), errdetail_log( "The sort field must not contain any duplicate values"))); } /* Move forward winobj's mark position to release unnecessary tuples in TupleStore */ WinSetMarkPosition(winobj, current_pos - 1); pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isnull)); pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); if (!isnull && currentValueElement.bsonValue.value_type != BSON_TYPE_NULL) { /* The filled value should be numeric or nullish. */ if (!BsonValueIsNumber(¤tValueElement.bsonValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( " The value provided must be either a numeric type or explicitly null"), errdetail_log( "The value provided must be either a numeric type or explicitly null"))); } stateData->hasPre = true; /* In linearFill, only numeric type is allowed, so we can directly use `=` to copy the value to state. */ stateData->preValue = currentValueElement.bsonValue; stateData->preSortKeyValue = sortByValueElement.bsonValue; PG_RETURN_POINTER(currentValue); } pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; /* return null if no pre non-null value or no next non-null value in current partition*/ if (!stateData->hasPre || stateData->isOut) { finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /* In this case, cur is null and hasPre is true. get next non-null value */ if (!stateData->hasNext || (current_pos >= stateData->nextPos)) { int64 start_offset = 0; isout = false; isnull = true; isValueNull = true; isSortKeyNull = true; while (!isout && (isnull || isValueNull)) { start_offset++; nextDatum = WinGetFuncArgInPartition(winobj, 0, start_offset, WINDOW_SEEK_CURRENT, false, &isnull, &isout); if (isnull || isout) { continue; } PgbsonToSinglePgbsonElement(DatumGetPgBson(nextDatum), &nextValueElement); isValueNull = nextValueElement.bsonValue.value_type == BSON_TYPE_NULL; /* As we didn't change the offset, we can reuse the `isout` and its value should be same as previous call */ nextSortKeyDatum = WinGetFuncArgInPartition(winobj, 1, start_offset, WINDOW_SEEK_CURRENT, false, &isSortKeyNull, &isout); PgbsonToSinglePgbsonElement(DatumGetPgBson(nextSortKeyDatum), &nextSortKeyElement); CheckSortKeyBsonValue(isSortKeyNull, &nextSortKeyElement); } if (!isnull && !isValueNull) { stateData->hasNext = true; stateData->nextValue = nextValueElement.bsonValue; stateData->nextSortKeyValue = nextSortKeyElement.bsonValue; stateData->nextPos = current_pos + start_offset; } else { /* if this branch hit, current partiton reaches the end and has no more non-null value */ stateData->hasNext = false; stateData->isOut = true; } } if (!stateData->hasNext) { finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } /** * The filled value should be numeric or nullish. */ if (!BsonValueIsNumber(&stateData->nextValue)) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( " The value provided must be either a numeric type or explicitly null"), errdetail_log( "The value provided must be either a numeric type or explicitly null"))); } /** * If both values are not Deciaml128, double will be returned; otherwise, Decimal128 will be returned. */ if (stateData->preValue.value_type != BSON_TYPE_DECIMAL128 && stateData->nextValue.value_type != BSON_TYPE_DECIMAL128) { double preValue = BsonValueAsDouble(&stateData->preValue); double nextValue = BsonValueAsDouble(&stateData->nextValue); double currentSortKeyValue = BsonValueAsDouble(&sortByValueElement.bsonValue); double preSortKeyValue = BsonValueAsDouble(&stateData->preSortKeyValue); double nextSortKeyValue = BsonValueAsDouble(&stateData->nextSortKeyValue); double filledValue = preValue + (nextValue - preValue) * (currentSortKeyValue - preSortKeyValue) / (nextSortKeyValue - preSortKeyValue); finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; finalValue.bsonValue.value.v_double = filledValue; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { bson_value_t preValue; preValue.value_type = BSON_TYPE_DECIMAL128; preValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &stateData->preValue); bson_value_t nextValue; nextValue.value_type = BSON_TYPE_DECIMAL128; nextValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &stateData->nextValue); bson_value_t filledValue; bson_value_t preSortKeyValue; preSortKeyValue.value_type = BSON_TYPE_DECIMAL128; preSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &stateData->preSortKeyValue); bson_value_t nextSortKeyValue; nextSortKeyValue.value_type = BSON_TYPE_DECIMAL128; nextSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &stateData->nextSortKeyValue); bson_value_t currentSortKeyValue; currentSortKeyValue.value_type = BSON_TYPE_DECIMAL128; currentSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( &sortByValueElement.bsonValue); CheckDecimal128Result(SubtractDecimal128Numbers(&nextSortKeyValue, &preSortKeyValue, &nextSortKeyValue)); CheckDecimal128Result(SubtractDecimal128Numbers(¤tSortKeyValue, &preSortKeyValue, ¤tSortKeyValue)); CheckDecimal128Result(SubtractDecimal128Numbers(&nextValue, &preValue, &filledValue)); CheckDecimal128Result(MultiplyDecimal128Numbers(&filledValue, ¤tSortKeyValue, &filledValue)); CheckDecimal128Result(DivideDecimal128Numbers(&filledValue, &nextSortKeyValue, &filledValue)); CheckDecimal128Result(AddDecimal128Numbers(&preValue, &filledValue, &filledValue)); finalValue.bsonValue.value_type = BSON_TYPE_DECIMAL128; finalValue.bsonValue.value.v_decimal128 = filledValue.value.v_decimal128; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } } Datum bson_locf_fill(PG_FUNCTION_ARGS) { WindowObject winobj = PG_WINDOW_OBJECT(); BsonLocfFillState *stateData; stateData = (BsonLocfFillState *) WinGetPartitionLocalMemory(winobj, sizeof(BsonLocfFillState)); if (!stateData->init) { /* first call */ stateData->init = true; stateData->hasPre = false; stateData->preValue = NULL; } bool isnull = true; /* bool isout = true; */ int64 current_pos = WinGetCurrentPosition(winobj); pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isnull)); pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); /* switch to partition level memory context */ if (!isnull && currentValueElement.bsonValue.value_type != BSON_TYPE_NULL) { /* release memory of pre value because we will replaced it with current value by new memory allocation */ if (stateData->preValue != NULL) { pfree(stateData->preValue); } stateData->hasPre = true; stateData->preValue = CopyPgbsonIntoMemoryContext(currentValue, fcinfo->flinfo->fn_mcxt); /** * Once we get current value, the values before current value won't be used in locf fill. * Thus we can move the winobj's mark position forward to `current_pos - 1` to reduce the memory usage of TupleStore in NodeWindowAgg. */ WinSetMarkPosition(winobj, current_pos - 1); PG_RETURN_POINTER(currentValue); } /* return null if cur is null and no pre non-null value*/ if (!stateData->hasPre) { pgbsonelement finalValue; finalValue.path = ""; finalValue.pathLength = 0; finalValue.bsonValue.value_type = BSON_TYPE_NULL; PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); } else { PG_RETURN_POINTER(stateData->preValue); } } /** * Fill the missing values with the const based value. * The const value is the second argument of the function. */ Datum bson_const_fill(PG_FUNCTION_ARGS) { WindowObject winobj = PG_WINDOW_OBJECT(); bool isCurrentNull; bool isFilledNull; pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isCurrentNull)); pgbsonelement currentValueElement; PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); if (!isCurrentNull && currentValueElement.bsonValue.value_type != BSON_TYPE_NULL) { PG_RETURN_POINTER(currentValue); } pgbson *filledValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 1, &isFilledNull)); PG_RETURN_POINTER(filledValue); } static void CheckSortKeyBsonValue(bool isnull, pgbsonelement *sortKeyElement) { if (isnull || sortKeyElement->bsonValue.value_type == BSON_TYPE_NULL) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The sortBy parameter should contain either a numeric value or a date, but a null value was provided instead."), errdetail_log( "The sortBy parameter should contain either a numeric value or a date, but a null value was provided instead."))); } if (!BsonValueIsNumber(&sortKeyElement->bsonValue) && sortKeyElement->bsonValue.value_type != BSON_TYPE_DATE_TIME) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_TYPEMISMATCH), errmsg( "The sortBy parameter must contain either a numeric value or a date, but instead received %s", BsonTypeName(sortKeyElement->bsonValue.value_type)), errdetail_log( "The sortBy parameter must contain either a numeric value or a date, but instead received %s", BsonTypeName( sortKeyElement->bsonValue.value_type)))); } } /** * Check the result of Decimal128 operation. If the result is Decimal128Result_Unknown, throw an error. * $linearFill will return Infinity, -Infinity or NaN if the result is overflow, underflow or NaN. */ static void CheckDecimal128Result(Decimal128Result result) { if (result == Decimal128Result_Unknown) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg( " Unknown error when processing Decimal128 numbers in $linearFill"), errdetail_log( " Unknown error when processing Decimal128 numbers in $linearFill"))); } } Datum bson_document_number(PG_FUNCTION_ARGS) { Datum rank = window_row_number(fcinfo); bson_value_t finalValue = { .value_type = BSON_TYPE_INT32 }; finalValue.value.v_int32 = DatumGetInt64(rank); PG_RETURN_POINTER(BsonValueToDocumentPgbson(&finalValue)); } /* * Aggregation function for $shift. * Calls postgres function Lead() which can inherently handle positive and negative offsets. */ Datum bson_shift(PG_FUNCTION_ARGS) { Datum shift = window_lead_with_offset_and_default(fcinfo); return shift; } documentdb-0.108-0/pg_documentdb/src/aggregation/bson_aggregation_window_operators.c000066400000000000000000002657341507310017400310530ustar00rootroot00000000000000/*------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * * src/aggregation/bson_aggregation_window_operators.c * * Support functions for all the window operators used by $setWindowFields * *------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include "aggregation/bson_aggregation_window_operators.h" #include "aggregation/bson_aggregation_statistics.h" #include "commands/parse_error.h" #include "operators/bson_expression_operators.h" #include "query/bson_compare.h" #include "query/query_operator.h" #include "types/decimal128.h" #include "utils/date_utils.h" #include "utils/feature_counter.h" #include "utils/documentdb_errors.h" /* --------------------------------------------------------- */ /* Data types */ /* --------------------------------------------------------- */ /* * Custom FRAMEOPTION flags relevant to $setWindowFields stage. * * Note: Make sure these flag values adhere to the existing FRAMEOPTION flags defined in PG * nodes/parsenodes.h and no flag should overlap with existing flags. */ typedef enum FRAMEOPTION_DOCUMENTDB { FRAMEOPTION_DOCUMENTDB_INVALID = 0x0, FRAMEOPTION_DOCUMENTDB_RANGE_UNITS = 0x1000000, FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS = 0x2000000 } FRAMEOPTION_DOCUMENTDB; #define FRAMEOPTION_DOCUMENTDB_ONLY (FRAMEOPTION_DOCUMENTDB_RANGE_UNITS | \ FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) /* Default Frame options for DocumentDB - documents window with unbounded preceding and unboudnded following */ #define FRAMEOPTION_DOCUMENTDB_SETWINDOWFIELDS_DEFAULT (FRAMEOPTION_NONDEFAULT | \ FRAMEOPTION_ROWS | \ FRAMEOPTION_START_UNBOUNDED_PRECEDING \ | \ FRAMEOPTION_BETWEEN | \ FRAMEOPTION_END_UNBOUNDED_FOLLOWING) /* $setWindowFields `sort` options, required for the validation against different combinations * with range/documents based windows or window aggregation operators. */ typedef struct SetWindowFieldSortOption { /* The pgbson const of the sort spec */ Const *sortSpecConst; /* Whether the sort is ascending or not */ bool isAscending; } SetWindowFieldSortOption; typedef struct { /* Index of the window clause for this window operator function, the number should be unique for windowclauses * and map exactly to one window operator */ Index winRef; /* ParseState required to add the target entries, mostly for the resno */ ParseState *pstate; /* The document Var expression */ Expr *docExpr; /* Output field name of the operator results */ const char *outputFieldName; /* Sort options list */ List *sortOptions; /* Variable context for operators */ Expr *variableContext; /* boolean to check if the window is present */ bool isWindowPresent; /* whether internal window operator is enabled or not */ bool enableInternalWindowOperator; } WindowOperatorContext; typedef WindowFunc *(*WindowOperatorFunc)(const bson_value_t *opValue, WindowOperatorContext *context); typedef struct { /* The operator name e.g. $addToSet, $avg, $denseRank etc */ const char *operatorName; /* The function that will create WindowClause for the window operator */ WindowOperatorFunc windowOperatorFunc; } WindowOperatorDefinition; /* --------------------------------------------------------- */ /* Forward declaration */ /* --------------------------------------------------------- */ static void ParseAndSetFrameOption(const bson_value_t *value, WindowClause *windowClause, DateUnit timeUnit, int *frameOptions); static WindowFunc * HandleDollarIntegralWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarDerivativeWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static void ParseIntegralDerivativeExpression(const bson_value_t *opValue, WindowOperatorContext *context, Expr **xExpr, Expr **yExpr, long *unitInMs, bool isIntegralOperator); static WindowFunc * GetIntegralDerivativeWindowFunc(const bson_value_t *opValue, WindowOperatorContext *context, bool isIntegral); static Datum EnsureValidUnitOffsetAndGetInterval(const bson_value_t *value, DateUnit dateUnit); static TargetEntry * UpdateWindowOperatorAndFrameOptions(const bson_value_t *windowOpValue, WindowOperatorContext *context, WindowClause *windowClause, int *allFrameOptions); static void UpdatePartitionAndSortClauses(Query *query, Expr *docExpr, Expr *partitionByExpr, List *sortByClauses, int allFrameOptions, ParseState *pstate, const char *collationString); static bool IsPartitionByOnShardKey(const bson_value_t *partitionByValue, const MongoCollection *collection); static void ThrowInvalidFrameOptions(void); static void ThrowExtraInvalidFrameOptions(const char *str1, const char *str2); static void ThrowInvalidWindowValue(const char *windowType, const bson_value_t *value); static void UpdateWindowOptions(const pgbsonelement *element, WindowClause *windowClause, WindowOperatorContext *context, int *frameOptions); static void UpdateWindowAggregationOperator(const pgbsonelement *element, WindowOperatorContext *context, TargetEntry **entry); static WindowFunc * GetSimpleBsonExpressionGetWindowFunc(const bson_value_t *opValue, WindowOperatorContext *context, Oid aggregateFunctionOid); static inline void ValidateInputForRankFunctions(const bson_value_t *opValue, WindowOperatorContext *context, char *opName); static void ParseInputDocumentForDollarShift(const bson_value_t *opValue, bson_value_t *output, bson_value_t *by, bson_value_t *defaultValue); static void ParseInputDocumentForDollarShift(const bson_value_t *opValue, bson_value_t *output, bson_value_t *by, bson_value_t *defaultValue); static WindowFunc * HandleDollarTopBottomOperators(const bson_value_t *opValue, WindowOperatorContext *context, const char *opName, Oid aggregateFunctionOid, bool isNOperator); static WindowFunc * HandleDollarFirstLastOperators(const bson_value_t *opValue, WindowOperatorContext *context, const char *opName, Oid aggregateFunctionOid, bool isNOperator); /*===================================*/ /* Window Operator Handler functions */ /*===================================*/ static WindowFunc * HandleDollarAddToSetWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarAvgWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarCountWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarCovariancePopWindowOperator(const bson_value_t *opValue, WindowOperatorContext * context); static WindowFunc * HandleDollarCovarianceSampWindowOperator(const bson_value_t *opValue, WindowOperatorContext * context); static WindowFunc * HandleDollarDenseRankWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarDocumentNumberWindowOperator(const bson_value_t *opValue, WindowOperatorContext * context); static WindowFunc * HandleDollarPushWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarRankWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarSumWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarExpMovingAvgWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarLinearFillWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarLocfFillWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarConstFillWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarShiftWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarTopNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarBottomNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarTopWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarBottomWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarStdDevPopWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarStdDevSampWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarFirstWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarLastWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarFirstNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarLastNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarMaxNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarMinNWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarMinWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarMaxWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); /* * Window operators definitions. * * Note: Please keep the list in alphabetical order for better readability. */ static const WindowOperatorDefinition WindowOperatorDefinitions[] = { { .operatorName = "$_internal_constFill", .windowOperatorFunc = &HandleDollarConstFillWindowOperator }, { .operatorName = "$addToSet", .windowOperatorFunc = &HandleDollarAddToSetWindowOperator }, { .operatorName = "$avg", .windowOperatorFunc = &HandleDollarAvgWindowOperator }, { .operatorName = "$bottom", .windowOperatorFunc = &HandleDollarBottomWindowOperator }, { .operatorName = "$bottomN", .windowOperatorFunc = &HandleDollarBottomNWindowOperator }, { .operatorName = "$count", .windowOperatorFunc = &HandleDollarCountWindowOperator }, { .operatorName = "$covariancePop", .windowOperatorFunc = &HandleDollarCovariancePopWindowOperator }, { .operatorName = "$covarianceSamp", .windowOperatorFunc = &HandleDollarCovarianceSampWindowOperator }, { .operatorName = "$denseRank", .windowOperatorFunc = &HandleDollarDenseRankWindowOperator }, { .operatorName = "$derivative", .windowOperatorFunc = HandleDollarDerivativeWindowOperator }, { .operatorName = "$documentNumber", .windowOperatorFunc = &HandleDollarDocumentNumberWindowOperator }, { .operatorName = "$expMovingAvg", .windowOperatorFunc = &HandleDollarExpMovingAvgWindowOperator }, { .operatorName = "$first", .windowOperatorFunc = &HandleDollarFirstWindowOperator }, { .operatorName = "$firstN", .windowOperatorFunc = &HandleDollarFirstNWindowOperator }, { .operatorName = "$integral", .windowOperatorFunc = HandleDollarIntegralWindowOperator }, { .operatorName = "$last", .windowOperatorFunc = &HandleDollarLastWindowOperator }, { .operatorName = "$lastN", .windowOperatorFunc = &HandleDollarLastNWindowOperator }, { .operatorName = "$linearFill", .windowOperatorFunc = &HandleDollarLinearFillWindowOperator }, { .operatorName = "$locf", .windowOperatorFunc = &HandleDollarLocfFillWindowOperator }, { .operatorName = "$max", .windowOperatorFunc = &HandleDollarMaxWindowOperator }, { .operatorName = "$maxN", .windowOperatorFunc = &HandleDollarMaxNWindowOperator }, { .operatorName = "$median", .windowOperatorFunc = NULL }, { .operatorName = "$min", .windowOperatorFunc = &HandleDollarMinWindowOperator }, { .operatorName = "$minN", .windowOperatorFunc = &HandleDollarMinNWindowOperator }, { .operatorName = "$percentile", .windowOperatorFunc = NULL }, { .operatorName = "$push", .windowOperatorFunc = &HandleDollarPushWindowOperator }, { .operatorName = "$rank", .windowOperatorFunc = &HandleDollarRankWindowOperator }, { .operatorName = "$shift", .windowOperatorFunc = &HandleDollarShiftWindowOperator }, { .operatorName = "$stdDevPop", .windowOperatorFunc = &HandleDollarStdDevPopWindowOperator }, { .operatorName = "$stdDevSamp", .windowOperatorFunc = &HandleDollarStdDevSampWindowOperator }, { .operatorName = "$sum", .windowOperatorFunc = &HandleDollarSumWindowOperator }, { .operatorName = "$top", .windowOperatorFunc = &HandleDollarTopWindowOperator }, { .operatorName = "$topN", .windowOperatorFunc = &HandleDollarTopNWindowOperator } }; static const int WindowOperatorsCount = sizeof(WindowOperatorDefinitions) / sizeof(WindowOperatorDefinition); /* * Ensures the given window spec of $setWindowFields' output is valid combination */ static inline void EnsureValidWindowSpec(int frameOptions) { if ((frameOptions & FRAMEOPTION_ROWS) != FRAMEOPTION_ROWS && (frameOptions & FRAMEOPTION_RANGE) != FRAMEOPTION_RANGE && (frameOptions & FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) == FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) { /* Only unknwon fields are provided */ ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "'window' field can only contain 'documents' as the only argument " "or 'range' with an optional 'unit' field"))); } if ((frameOptions & FRAMEOPTION_ROWS) == FRAMEOPTION_ROWS && (frameOptions & FRAMEOPTION_RANGE) == FRAMEOPTION_RANGE) { /* Both range and document are provided */ ThrowInvalidFrameOptions(); } if ((frameOptions & FRAMEOPTION_ROWS) == FRAMEOPTION_ROWS && (frameOptions & FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) == FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) { /* Document window with unknown fields */ ThrowExtraInvalidFrameOptions("documents", ""); } if ((frameOptions & FRAMEOPTION_RANGE) == FRAMEOPTION_RANGE && (frameOptions & FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) == FRAMEOPTION_DOCUMENTDB_UNKNOWN_FIELDS) { /* Range window with unknown field */ ThrowExtraInvalidFrameOptions("range", "besides 'unit'"); } if ((frameOptions & FRAMEOPTION_DOCUMENTDB_RANGE_UNITS) == FRAMEOPTION_DOCUMENTDB_RANGE_UNITS && (frameOptions & FRAMEOPTION_RANGE) != FRAMEOPTION_RANGE) { /* Units without range */ ereport(ERROR, ( errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg( "The 'unit' parameter is valid only when bounds are defined using a range-based specification."))); } } /* * Returns whether the query target list contains resjunk entries */ inline static bool HasResJunkEntries(Query *query) { return query && query->targetList != NIL && count_nonjunk_tlist_entries(query->targetList) != list_length( query->targetList); } /* * Ensures the given window spec of $setWindowFields' is compliant with sortBy field * requirement */ static inline void EnsureSortRequirements(int frameOptions, WindowOperatorContext *context) { int sortByLength = list_length(context->sortOptions); if ((frameOptions & FRAMEOPTION_RANGE) == FRAMEOPTION_RANGE) { /* Must be supplied for a range window */ if (sortByLength != 1) { ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5339902), errmsg( "Expected a single sort by field for range-based window"))); } SetWindowFieldSortOption *sortField = (SetWindowFieldSortOption *) linitial( context->sortOptions); if (!sortField->isAscending) { /* TODO: Actual error code for this is 8947401 which is beyond our current error limit * Fix later to extend the error code range to accomodate this, for now throwing * generic failed to parse */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), errmsg("Expected ascending sortBy field definition"))); } } else if (sortByLength == 0) { bool isUnbounded = ((frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING) && (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING)); if (!isUnbounded) { /* Must be supplied for a bounded document window */ ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION5339901), errmsg("Missing sortBy field for document-based window"))); } } } Query * HandleSetWindowFields(const bson_value_t *existingValue, Query *query, AggregationPipelineBuildContext *context) { bool enableInternalWindowOperator = false; Expr *partitionByExpr = NULL; return HandleSetWindowFieldsCore(existingValue, query, context, partitionByExpr, enableInternalWindowOperator); } /* * $setWindowFields aggregation stage handler. * This function constructs the query AST for Window aggregation operators over a partition defined by the $setWindowFields spec. * The spec is of the form: * { * $setWindowFields:{ * partitionBy: , * sortBy : , * output: { * : { * : , * window: { * documents: [], * : [], // either `window` or `range` * :